Implement ticket creation and backlog
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Tickets;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateProjectTicket
|
||||
{
|
||||
/**
|
||||
* @param array{
|
||||
* acceptance_criteria: string|null,
|
||||
* description: string|null,
|
||||
* ticket_priority_id: int,
|
||||
* ticket_type_id: int,
|
||||
* title: string
|
||||
* } $attributes
|
||||
*/
|
||||
public function handle(Project $project, array $attributes): Ticket
|
||||
{
|
||||
return DB::transaction(function () use ($attributes, $project): Ticket {
|
||||
$nextSequenceNumber = (int) Ticket::query()
|
||||
->where('project_id', $project->id)
|
||||
->max('sequence_number') + 1;
|
||||
|
||||
return Ticket::query()->create([
|
||||
'acceptance_criteria' => $attributes['acceptance_criteria'],
|
||||
'board_column_id' => null,
|
||||
'description' => $attributes['description'],
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => $nextSequenceNumber,
|
||||
'ticket_key' => "{$project->key}-{$nextSequenceNumber}",
|
||||
'ticket_priority_id' => $attributes['ticket_priority_id'],
|
||||
'ticket_type_id' => $attributes['ticket_type_id'],
|
||||
'title' => $attributes['title'],
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user