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
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class AvailableGitRepositorySourceResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'user_git_connection_id' => Arr::get($this->resource, 'user_git_connection_id'),
'provider' => Arr::get($this->resource, 'provider'),
'provider_label' => Arr::get($this->resource, 'provider_label'),
'base_url' => Arr::get($this->resource, 'base_url'),
'account_login' => Arr::get($this->resource, 'account_login'),
'account_name' => Arr::get($this->resource, 'account_name'),
'error' => Arr::get($this->resource, 'error'),
'repositories' => GitRepositoryOptionResource::collection(
collect(Arr::get($this->resource, 'repositories', [])),
)->resolve(),
];
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BoardColumnResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'position' => $this->position,
'project_id' => $this->project_id,
'ticket_statuses' => $this->whenLoaded(
'ticketStatuses',
fn (): array => TicketStatusResource::collection($this->ticketStatuses)->resolve(),
),
'tickets' => $this->whenLoaded(
'tickets',
fn (): array => TicketResource::collection($this->tickets)->resolve(),
),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class FieldTypeOptionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$fieldType = is_string($this->resource)
? $this->resource
: Arr::get($this->resource, 'value');
return [
'label' => is_string($this->resource)
? ucfirst($fieldType)
: Arr::get($this->resource, 'label'),
'value' => $fieldType,
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class GitRepositoryOptionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'provider_repository_id' => Arr::get($this->resource, 'provider_repository_id'),
'owner_name' => Arr::get($this->resource, 'owner_name'),
'repository_name' => Arr::get($this->resource, 'repository_name'),
'full_name' => Arr::get($this->resource, 'full_name'),
'repository_url' => Arr::get($this->resource, 'repository_url'),
'visibility_label' => Arr::get($this->resource, 'visibility_label'),
];
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class PermissionOptionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'label' => Arr::get($this->resource, 'label'),
'value' => Arr::get($this->resource, 'value'),
];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProjectResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'key' => $this->key,
'show_author' => $this->show_author,
'show_story_points' => $this->show_story_points,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Http\Resources;
use App\Models\RepositoryConnection;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class RepositoryConnectionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$provider = $this->resource instanceof RepositoryConnection
? $this->provider
: null;
return [
'id' => $this->resource instanceof RepositoryConnection ? $this->id : Arr::get($this->resource, 'id'),
'project_id' => $this->resource instanceof RepositoryConnection ? $this->project_id : Arr::get($this->resource, 'project_id'),
'provider' => $provider?->value ?? Arr::get($this->resource, 'provider'),
'provider_label' => $provider?->label() ?? Arr::get($this->resource, 'provider_label'),
'base_url' => $this->resource instanceof RepositoryConnection ? $this->base_url : Arr::get($this->resource, 'base_url'),
'provider_repository_id' => $this->resource instanceof RepositoryConnection
? $this->provider_repository_id
: Arr::get($this->resource, 'provider_repository_id'),
'owner_name' => $this->resource instanceof RepositoryConnection ? $this->owner_name : Arr::get($this->resource, 'owner_name'),
'repository_name' => $this->resource instanceof RepositoryConnection
? $this->repository_name
: Arr::get($this->resource, 'repository_name'),
'repository_full_name' => $this->resource instanceof RepositoryConnection
? $this->repository_full_name
: Arr::get($this->resource, 'repository_full_name'),
'repository_url' => $this->resource instanceof RepositoryConnection ? $this->repository_url : Arr::get($this->resource, 'repository_url'),
'has_personal_access' => $this->resource instanceof RepositoryConnection
? (bool) ($this->resource->getAttribute('has_personal_access') ?? false)
: (bool) Arr::get($this->resource, 'has_personal_access', false),
'created_at' => $this->resource instanceof RepositoryConnection
? $this->created_at?->toISOString()
: Arr::get($this->resource, 'created_at'),
'updated_at' => $this->resource instanceof RepositoryConnection
? $this->updated_at?->toISOString()
: Arr::get($this->resource, 'updated_at'),
];
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TeamResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'user_ids' => $this->whenLoaded('users', fn (): array => $this->users->modelKeys()),
'users' => $this->whenLoaded('users', fn (): array => UserResource::collection($this->users)->resolve()),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class TicketBranchResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'name' => Arr::get($this->resource, 'name'),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketFieldDefinitionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'field_type' => $this->field_type,
'label' => $this->label,
'position' => $this->position,
'project_id' => $this->project_id,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketFieldValueResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'ticket_field_definition_id' => $this->ticket_field_definition_id,
'ticket_field_definition' => $this->whenLoaded(
'ticketFieldDefinition',
fn (): ?array => $this->ticketFieldDefinition === null
? null
: TicketFieldDefinitionResource::make($this->ticketFieldDefinition)->resolve(),
),
'ticket_id' => $this->ticket_id,
'user_value' => $this->whenLoaded(
'userValue',
fn (): ?array => $this->userValue === null
? null
: UserResource::make($this->userValue)->resolve(),
),
'value_number' => $this->value_number,
'value_user_id' => $this->value_user_id,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Http\Resources;
use App\Models\TicketLink;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class TicketLinkResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
if ($this->resource instanceof TicketLink) {
$currentTicketId = (int) ($this->resource->getAttribute('current_ticket_id') ?? 0);
$linkedTicket = $this->source_ticket_id === $currentTicketId
? $this->targetTicket
: $this->sourceTicket;
return [
'id' => $this->id,
'linked_ticket' => TicketReferenceResource::make($linkedTicket)->resolve(),
'source_ticket_id' => $this->source_ticket_id,
'target_ticket_id' => $this->target_ticket_id,
'ticket_link_type' => TicketLinkTypeResource::make($this->ticketLinkType)->resolve(),
'ticket_link_type_id' => $this->ticket_link_type_id,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
return [
'id' => Arr::get($this->resource, 'id'),
'linked_ticket' => TicketReferenceResource::make(Arr::get($this->resource, 'linked_ticket'))->resolve(),
'source_ticket_id' => Arr::get($this->resource, 'source_ticket_id'),
'target_ticket_id' => Arr::get($this->resource, 'target_ticket_id'),
'ticket_link_type' => TicketLinkTypeResource::make(Arr::get($this->resource, 'ticket_link_type'))->resolve(),
'ticket_link_type_id' => Arr::get($this->resource, 'ticket_link_type_id'),
'created_at' => Arr::get($this->resource, 'created_at'),
'updated_at' => Arr::get($this->resource, 'updated_at'),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketLinkTypeResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'label' => $this->label,
'position' => $this->position,
'project_id' => $this->project_id,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketPriorityResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'position' => $this->position,
'project_id' => $this->project_id,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class TicketPullRequestResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'html_url' => Arr::get($this->resource, 'html_url'),
'number' => Arr::get($this->resource, 'number'),
'source_branch' => Arr::get($this->resource, 'source_branch'),
'status' => Arr::get($this->resource, 'status'),
'title' => Arr::get($this->resource, 'title'),
];
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use App\Models\Ticket;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class TicketReferenceResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->resource instanceof Ticket ? $this->id : Arr::get($this->resource, 'id'),
'ticket_key' => $this->resource instanceof Ticket ? $this->ticket_key : Arr::get($this->resource, 'ticket_key'),
'title' => $this->resource instanceof Ticket ? $this->title : Arr::get($this->resource, 'title'),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class TicketRepositoryBranchResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'branches' => TicketBranchResource::collection(collect(Arr::get($this->resource, 'branches', [])))->resolve(),
'error' => Arr::get($this->resource, 'error'),
'repository_connection' => RepositoryConnectionResource::make(
Arr::get($this->resource, 'repository_connection'),
)->resolve(),
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class TicketRepositoryPullRequestResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'error' => Arr::get($this->resource, 'error'),
'pull_requests' => TicketPullRequestResource::collection(
collect(Arr::get($this->resource, 'pull_requests', [])),
)->resolve(),
'repository_connection' => RepositoryConnectionResource::make(
Arr::get($this->resource, 'repository_connection'),
)->resolve(),
];
}
}
+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(),
];
}
}
@@ -0,0 +1,38 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketStatusResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'allowed_target_statuses' => $this->whenLoaded(
'allowedTargetStatuses',
fn (): array => TicketStatusResource::collection($this->allowedTargetStatuses)->resolve(),
),
'board_column' => $this->whenLoaded(
'boardColumn',
fn (): ?array => $this->boardColumn === null
? null
: BoardColumnResource::make($this->boardColumn)->resolve(),
),
'board_column_id' => $this->board_column_id,
'name' => $this->name,
'position' => $this->position,
'project_id' => $this->project_id,
'slug' => $this->slug,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,41 @@
<?php
namespace App\Http\Resources;
use App\Models\Ticket;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class TicketTreeNodeResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
if ($this->resource instanceof Ticket) {
return [
'children' => TicketTreeNodeResource::collection(
$this->resource->childTickets()
->with('ticketType')
->get(),
)->resolve(),
'id' => $this->id,
'ticket_key' => $this->ticket_key,
'ticket_type_name' => $this->ticketType?->name,
'title' => $this->title,
];
}
return [
'children' => TicketTreeNodeResource::collection(collect(Arr::get($this->resource, 'children', [])))->resolve(),
'id' => Arr::get($this->resource, 'id'),
'ticket_key' => Arr::get($this->resource, 'ticket_key'),
'ticket_type_name' => Arr::get($this->resource, 'ticket_type_name'),
'title' => Arr::get($this->resource, 'title'),
];
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketTypeResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'is_parent' => $this->is_parent,
'name' => $this->name,
'position' => $this->position,
'project_id' => $this->project_id,
'tickets_count' => $this->when(isset($this->tickets_count), (int) $this->tickets_count),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketWorklogEntryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'actor' => $this->whenLoaded(
'actor',
fn (): ?array => $this->actor === null
? null
: UserResource::make($this->actor)->resolve(),
),
'actor_id' => $this->actor_id,
'changes' => $this->changes,
'created_at' => $this->created_at?->toISOString(),
'entry_type' => $this->entry_type?->value,
'summary' => $this->summary,
'ticket_id' => $this->ticket_id,
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UserGitConnectionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'user_id' => $this->user_id,
'provider' => $this->provider->value,
'provider_label' => $this->provider->label(),
'base_url' => $this->base_url,
'provider_user_id' => $this->provider_user_id,
'account_login' => $this->account_login,
'account_name' => $this->account_name,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'email_verified_at' => $this->email_verified_at?->toISOString(),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}