Add application API and OpenAPI docs
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\ProjectTicketMetadata;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\TicketPriority;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StoreProjectTicketPriority
|
||||
{
|
||||
use ReordersProjectMetadata;
|
||||
|
||||
/**
|
||||
* @param array{name: string, position?: int|null} $validated
|
||||
*/
|
||||
public function handle(Project $project, array $validated): TicketPriority
|
||||
{
|
||||
$name = Arr::get($validated, 'name');
|
||||
$position = Arr::get($validated, 'position');
|
||||
|
||||
return DB::transaction(function () use ($project, $name, $position): TicketPriority {
|
||||
$ticketPriority = $project->ticketPriorities()->create([
|
||||
'name' => $name,
|
||||
'position' => $project->ticketPriorities()->count() + 1,
|
||||
]);
|
||||
|
||||
$this->reorderModels(
|
||||
$project->ticketPriorities()->whereKeyNot($ticketPriority->id)->get()->values(),
|
||||
$ticketPriority,
|
||||
$position ?? $project->ticketPriorities()->count(),
|
||||
);
|
||||
|
||||
return $ticketPriority;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user