Add application API and OpenAPI docs
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Tickets;
|
||||
|
||||
use App\Enums\TicketWorklogEntryType;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class MoveProjectTicket
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CreateTicketWorklogEntry $createTicketWorklogEntry,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param array{ticket_status_id: int} $validated
|
||||
* @return array{destination_label: string, moved: bool}
|
||||
*/
|
||||
public function handle(Project $project, Ticket $ticket, User $user, array $validated): array
|
||||
{
|
||||
$ticketStatusId = (int) Arr::get($validated, 'ticket_status_id');
|
||||
|
||||
$destinationStatus = $project->ticketStatuses()
|
||||
->with('boardColumn')
|
||||
->findOrFail($ticketStatusId);
|
||||
|
||||
$ticket->loadMissing('ticketStatus.boardColumn');
|
||||
|
||||
$originStatusId = $ticket->ticket_status_id;
|
||||
$originLabel = $this->statusLabel($ticket->ticketStatus);
|
||||
$destinationLabel = $this->statusLabel($destinationStatus);
|
||||
|
||||
if ($ticket->ticket_status_id === $ticketStatusId) {
|
||||
return [
|
||||
'destination_label' => $destinationLabel,
|
||||
'moved' => false,
|
||||
];
|
||||
}
|
||||
|
||||
$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 [
|
||||
'destination_label' => $destinationLabel,
|
||||
'moved' => true,
|
||||
];
|
||||
}
|
||||
|
||||
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}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user