1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Http/Controllers/TaskStatusController.php
2024-06-16 08:30:25 +10:00

184 lines
5.2 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers;
use App\Factory\TaskStatusFactory;
use App\Filters\TaskStatusFilters;
use App\Http\Requests\TaskStatus\ActionTaskStatusRequest;
use App\Http\Requests\TaskStatus\CreateTaskStatusRequest;
use App\Http\Requests\TaskStatus\DestroyTaskStatusRequest;
use App\Http\Requests\TaskStatus\EditTaskStatusRequest;
use App\Http\Requests\TaskStatus\ShowTaskStatusRequest;
use App\Http\Requests\TaskStatus\StoreTaskStatusRequest;
use App\Http\Requests\TaskStatus\UpdateTaskStatusRequest;
use App\Models\TaskStatus;
use App\Repositories\TaskStatusRepository;
use App\Transformers\TaskStatusTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
class TaskStatusController extends BaseController
{
use MakesHash;
protected $entity_type = TaskStatus::class;
protected $entity_transformer = TaskStatusTransformer::class;
/**
* @var TaskStatusRepository
*/
protected $task_status_repo;
/**
* TaskStatusController constructor.
*
* @param TaskStatusRepository $task_status_repo The payment term repo
*/
public function __construct(TaskStatusRepository $task_status_repo)
{
parent::__construct();
$this->task_status_repo = $task_status_repo;
}
/**
* index
*
* @param TaskStatusFilters $filters
* @return Response| \Illuminate\Http\JsonResponse
*/
public function index(TaskStatusFilters $filters)
{
$task_status = TaskStatus::filter($filters);
return $this->listResponse($task_status);
}
/**
* create
*
* @param CreateTaskStatusRequest $request
* @return Response| \Illuminate\Http\JsonResponse
*/
public function create(CreateTaskStatusRequest $request)
{
/** @var \App\Models\User $user */
$user = auth()->user();
$task_status = TaskStatusFactory::create($user->company()->id, auth()->user()->id);
return $this->itemResponse($task_status);
}
/**
* Store a newly created resource in storage.
*
* @param StoreTaskStatusRequest $request The request
* @return Response| \Illuminate\Http\JsonResponse
*
*/
public function store(StoreTaskStatusRequest $request)
{
/** @var \App\Models\User $user */
$user = auth()->user();
$task_status = TaskStatusFactory::create($user->company()->id, auth()->user()->id);
$task_status->fill($request->all());
$task_status->save();
return $this->itemResponse($task_status->fresh());
}
/**
* @param ShowTaskStatusRequest $request
* @param TaskStatus $task_status
* @return Response| \Illuminate\Http\JsonResponse|mixed
*/
public function show(ShowTaskStatusRequest $request, TaskStatus $task_status)
{
return $this->itemResponse($task_status);
}
/**
* @param EditTaskStatusRequest $request
* @param TaskStatus $payment
* @return Response| \Illuminate\Http\JsonResponse|mixed
*/
public function edit(EditTaskStatusRequest $request, TaskStatus $payment)
{
return $this->itemResponse($payment);
}
/**
* Update the specified resource in storage.
*
* @param UpdateTaskStatusRequest $request The request
* @param TaskStatus $task_status The payment term
* @return Response| \Illuminate\Http\JsonResponse
*/
public function update(UpdateTaskStatusRequest $request, TaskStatus $task_status)
{
$task_status->fill($request->all());
$reorder = $task_status->isDirty('status_order');
$task_status->save();
if ($reorder) {
$this->task_status_repo->reorder($task_status);
}
return $this->itemResponse($task_status->fresh());
}
/**
* Remove the specified resource from storage.
*
* @param DestroyTaskStatusRequest $request
* @param TaskStatus $task_status
* @return Response| \Illuminate\Http\JsonResponse
*
* @throws \Exception
*/
public function destroy(DestroyTaskStatusRequest $request, TaskStatus $task_status)
{
$task_status = $this->task_status_repo->delete($task_status);
return $this->itemResponse($task_status);
}
/**
* Perform bulk actions on the list view.
* @param ActionTaskStatusRequest $request
* @return Response| \Illuminate\Http\JsonResponse
*/
public function bulk(ActionTaskStatusRequest $request)
{
$action = $request->input('action');
$ids = $request->input('ids');
TaskStatus::withTrashed()
->company()
->whereIn('id', $this->transformKeys($ids))
->cursor()
->each(function ($task_status, $key) use ($action) {
$this->task_status_repo->{$action}($task_status);
});
return $this->listResponse(TaskStatus::withTrashed()->whereIn('id', $this->transformKeys($ids)));
}
}