Refactor Inertia responses to use resources
linter / quality (pull_request) Successful in 1m15s
tests / ci (8.4) (pull_request) Successful in 1m29s

This commit is contained in:
Eric Peters
2026-04-15 18:09:08 +02:00
parent 5a7972df7c
commit 017cff5437
38 changed files with 1125 additions and 382 deletions
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace App\Http\Resources;
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' => $this->acceptance_criteria,
'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_id' => $this->parent_ticket_id,
'project_id' => $this->project_id,
'sequence_number' => $this->sequence_number,
'story_points' => $this->story_points,
'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(),
];
}
}