Add application API and OpenAPI docs
This commit is contained in:
@@ -3,15 +3,12 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use App\Actions\Tickets\CreateTicketWorklogEntry;
|
||||
use App\Actions\Projects\BuildProjectBoardPayload;
|
||||
use App\Actions\Tickets\MoveProjectTicket;
|
||||
use App\Enums\Permission;
|
||||
use App\Enums\TicketWorklogEntryType;
|
||||
use App\Http\Requests\MoveProjectTicketRequest;
|
||||
use App\Http\Resources\BoardColumnResource;
|
||||
use App\Http\Resources\ProjectResource;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketStatus;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
@@ -21,7 +18,8 @@ use Inertia\Response;
|
||||
class ProjectBoardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CreateTicketWorklogEntry $createTicketWorklogEntry,
|
||||
private readonly BuildProjectBoardPayload $buildProjectBoardPayload,
|
||||
private readonly MoveProjectTicket $moveProjectTicket,
|
||||
private readonly PermissionService $permissionService,
|
||||
) {}
|
||||
|
||||
@@ -34,28 +32,10 @@ class ProjectBoardController extends Controller
|
||||
403,
|
||||
);
|
||||
|
||||
$canManageTickets = $this->permissionService->allows($user, Permission::ProjectWrite, $project);
|
||||
|
||||
return Inertia::render('projects/Board', [
|
||||
'boardColumns' => BoardColumnResource::collection(
|
||||
$project->boardColumns()
|
||||
->with([
|
||||
'ticketStatuses',
|
||||
'tickets' => fn ($query) => $query
|
||||
->with([
|
||||
'ticketPriority',
|
||||
'ticketStatus.allowedTargetStatuses.boardColumn',
|
||||
'ticketStatus.boardColumn',
|
||||
'ticketType',
|
||||
]),
|
||||
])
|
||||
->get(),
|
||||
)->resolve(),
|
||||
'canCreateTickets' => $canManageTickets,
|
||||
'canEditTickets' => $canManageTickets,
|
||||
'project' => ProjectResource::make($project)->resolve(),
|
||||
'status' => session('status'),
|
||||
]);
|
||||
return Inertia::render(
|
||||
'projects/Board',
|
||||
$this->buildProjectBoardPayload->handle($project, $user, session('status')),
|
||||
);
|
||||
}
|
||||
|
||||
public function move(
|
||||
@@ -71,65 +51,18 @@ class ProjectBoardController extends Controller
|
||||
);
|
||||
|
||||
$validated = $request->validated();
|
||||
$ticketStatusId = (int) Arr::get($validated, 'ticket_status_id');
|
||||
$redirectRoute = Arr::get($validated, 'redirect_to') === 'backlog'
|
||||
? 'projects.backlog.index'
|
||||
: 'projects.board.index';
|
||||
|
||||
$destinationStatus = $project->ticketStatuses()
|
||||
->with('boardColumn')
|
||||
->findOrFail($ticketStatusId);
|
||||
$result = $this->moveProjectTicket->handle($project, $ticket, $user, $validated);
|
||||
|
||||
$ticket->loadMissing('ticketStatus.boardColumn');
|
||||
|
||||
$originStatusId = $ticket->ticket_status_id;
|
||||
$originLabel = $this->statusLabel($ticket->ticketStatus);
|
||||
$destinationLabel = $this->statusLabel($destinationStatus);
|
||||
|
||||
if ($ticket->ticket_status_id === $ticketStatusId) {
|
||||
if (! $result['moved']) {
|
||||
return to_route($redirectRoute, $project)
|
||||
->with('status', "{$ticket->ticket_key} already belongs to {$destinationLabel}.");
|
||||
->with('status', "{$ticket->ticket_key} already belongs to {$result['destination_label']}.");
|
||||
}
|
||||
|
||||
$ticket->update([
|
||||
'ticket_status_id' => $destinationStatus->id,
|
||||
]);
|
||||
|
||||
$this->createTicketWorklogEntry->handle(
|
||||
$ticket->fresh(),
|
||||
$user,
|
||||
TicketWorklogEntryType::StatusChanged,
|
||||
"Moved from {$originLabel} to {$destinationLabel}.",
|
||||
[
|
||||
'from' => [
|
||||
'label' => $originLabel,
|
||||
'ticket_status_id' => $originStatusId,
|
||||
],
|
||||
'to' => [
|
||||
'label' => $destinationLabel,
|
||||
'ticket_status_id' => $destinationStatus->id,
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
return to_route($redirectRoute, $project)
|
||||
->with('status', "{$ticket->ticket_key} moved to {$destinationLabel}.");
|
||||
}
|
||||
|
||||
private function statusLabel(?TicketStatus $ticketStatus): string
|
||||
{
|
||||
if ($ticketStatus === null) {
|
||||
return 'Unknown status';
|
||||
}
|
||||
|
||||
if ($ticketStatus->boardColumn === null) {
|
||||
return $ticketStatus->name;
|
||||
}
|
||||
|
||||
if ($ticketStatus->boardColumn->name === $ticketStatus->name) {
|
||||
return $ticketStatus->name;
|
||||
}
|
||||
|
||||
return "{$ticketStatus->boardColumn->name} / {$ticketStatus->name}";
|
||||
->with('status', "{$ticket->ticket_key} moved to {$result['destination_label']}.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user