Files
Koda d4b0b90502
linter / quality (pull_request) Successful in 1m23s
tests / ci (8.4) (pull_request) Successful in 1m40s
Expose suggested branch name in ticket responses
2026-05-24 20:50:09 +00:00

90 lines
3.6 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Actions\Git\BuildSuggestedTicketBranchName;
use App\Actions\Tickets\Support\AcceptanceCriteriaChecklistMapper;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'acceptance_criteria' => AcceptanceCriteriaChecklistMapper::fromModelsWithIds(
$this->relationLoaded('acceptanceCriteria')
? $this->acceptanceCriteria
: $this->acceptanceCriteria()->get(),
),
'assignee' => $this->whenLoaded(
'assignee',
fn (): ?array => $this->assignee === null
? null
: UserResource::make($this->assignee)->resolve(),
),
'assignee_user_id' => $this->assignee_user_id,
'author' => $this->whenLoaded(
'author',
fn (): ?array => $this->author === null
? null
: UserResource::make($this->author)->resolve(),
),
'author_user_id' => $this->author_user_id,
'blocked_comment' => $this->blocked_comment,
'description' => $this->description,
'field_values' => $this->whenLoaded(
'fieldValues',
fn (): array => TicketFieldValueResource::collection($this->fieldValues)->resolve(),
),
'is_blocked' => $this->is_blocked,
'parent_ticket' => $this->whenLoaded(
'parentTicket',
fn (): ?array => $this->parentTicket === null
? null
: TicketReferenceResource::make($this->parentTicket)->resolve(),
),
'parent_ticket_id' => $this->parent_ticket_id,
'project_id' => $this->project_id,
'sequence_number' => $this->sequence_number,
'story_points' => $this->story_points,
'suggested_branch_name' => app(BuildSuggestedTicketBranchName::class)->handle($this->resource),
'ticket_key' => $this->ticket_key,
'ticket_priority' => $this->whenLoaded(
'ticketPriority',
fn (): ?array => $this->ticketPriority === null
? null
: TicketPriorityResource::make($this->ticketPriority)->resolve(),
),
'ticket_priority_id' => $this->ticket_priority_id,
'ticket_status' => $this->whenLoaded(
'ticketStatus',
fn (): ?array => $this->ticketStatus === null
? null
: TicketStatusResource::make($this->ticketStatus)->resolve(),
),
'ticket_status_id' => $this->ticket_status_id,
'ticket_type' => $this->whenLoaded(
'ticketType',
fn (): ?array => $this->ticketType === null
? null
: TicketTypeResource::make($this->ticketType)->resolve(),
),
'ticket_type_id' => $this->ticket_type_id,
'title' => $this->title,
'worklog_entries' => $this->whenLoaded(
'worklogEntries',
fn (): array => TicketWorklogEntryResource::collection($this->worklogEntries)->resolve(),
),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}