resources er uit gesloopt
Some checks failed
linter / quality (push) Failing after 1m4s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m5s
tests / ci (8.5) (push) Failing after 1m5s

This commit is contained in:
Daan Meijer 2026-06-23 17:56:40 +02:00
parent ae925c7173
commit 8d95e4ee53
15 changed files with 28 additions and 225 deletions

View File

@ -3,10 +3,6 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Requests\UpdateDynamicRequest; use App\Http\Requests\UpdateDynamicRequest;
use App\Http\Resources\DynamicResource;
use App\Http\Resources\LedgerResource;
use App\Http\Resources\MessageResource;
use App\Http\Resources\UserResource;
use App\Models\Dynamic; use App\Models\Dynamic;
use App\Services\ActivityService; use App\Services\ActivityService;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
@ -23,7 +19,7 @@ class DynamicController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
return Inertia::render('Dynamics/Index', [ return Inertia::render('Dynamics/Index', [
'dynamics' => DynamicResource::collection($request->user()->dynamics()->get()), 'dynamics' => $request->user()->dynamics()->get(),
]); ]);
} }
@ -59,10 +55,10 @@ class DynamicController extends Controller
$dynamic->load(['ledgers.media', 'participants', 'chat']); $dynamic->load(['ledgers.media', 'participants', 'chat']);
return Inertia::render('Dynamics/Show', [ return Inertia::render('Dynamics/Show', [
'dynamic' => new DynamicResource($dynamic), 'dynamic' => $dynamic,
'ledgers' => LedgerResource::collection($dynamic->ledgers), 'ledgers' => $dynamic->ledgers,
'participants' => UserResource::collection($dynamic->participants), 'participants' => $dynamic->participants,
'messages' => MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)), 'messages' => $dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
'can' => [ 'can' => [
'update' => $request->user()->can('update', $dynamic), 'update' => $request->user()->can('update', $dynamic),
], ],
@ -73,7 +69,7 @@ class DynamicController extends Controller
{ {
$this->authorize('view', $dynamic); $this->authorize('view', $dynamic);
return MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)); return $dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
} }
/** /**
@ -84,7 +80,7 @@ class DynamicController extends Controller
$this->authorize('update', $dynamic); $this->authorize('update', $dynamic);
return Inertia::render('Dynamics/Settings', [ return Inertia::render('Dynamics/Settings', [
'dynamic' => new DynamicResource($dynamic), 'dynamic' => $dynamic,
]); ]);
} }

View File

@ -3,11 +3,6 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Requests\StoreLedgerRequest; use App\Http\Requests\StoreLedgerRequest;
use App\Http\Resources\DynamicResource;
use App\Http\Resources\LedgerResource;
use App\Http\Resources\MessageResource;
use App\Http\Resources\MutationResource;
use App\Http\Resources\UserResource;
use App\Models\Dynamic; use App\Models\Dynamic;
use App\Models\Ledger; use App\Models\Ledger;
use App\Services\ActivityService; use App\Services\ActivityService;
@ -35,7 +30,7 @@ class LedgerController extends Controller
$this->authorize('update', $dynamic); $this->authorize('update', $dynamic);
return Inertia::render('Ledgers/Create', [ return Inertia::render('Ledgers/Create', [
'dynamic' => new DynamicResource($dynamic), 'dynamic' => $dynamic,
]); ]);
} }
@ -83,9 +78,9 @@ class LedgerController extends Controller
]); ]);
return Inertia::render('Ledgers/Show', [ return Inertia::render('Ledgers/Show', [
'dynamic' => new DynamicResource($dynamic), 'dynamic' => $dynamic,
'ledger' => new LedgerResource($ledger), 'ledger' => $ledger,
'messages' => MessageResource::collection($dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)), 'messages' => $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
'can' => [ 'can' => [
'update' => $request->user()->can('update', $ledger), 'update' => $request->user()->can('update', $ledger),
'close' => $request->user()->can('close', $ledger), 'close' => $request->user()->can('close', $ledger),
@ -97,7 +92,7 @@ class LedgerController extends Controller
{ {
$this->authorize('view', $ledger); $this->authorize('view', $ledger);
return MessageResource::collection($dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)); return $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
} }
/** /**
@ -108,8 +103,8 @@ class LedgerController extends Controller
$this->authorize('update', $ledger); $this->authorize('update', $ledger);
return Inertia::render('Ledgers/Edit', [ return Inertia::render('Ledgers/Edit', [
'dynamic' => new DynamicResource($dynamic), 'dynamic' => $dynamic,
'ledger' => new LedgerResource($ledger), 'ledger' => $ledger,
]); ]);
} }

View File

@ -6,7 +6,6 @@ use App\Events\MessageSent;
use App\Events\MutationCreated; use App\Events\MutationCreated;
use App\Events\MutationUpdated; use App\Events\MutationUpdated;
use App\Http\Requests\StoreMutationRequest; use App\Http\Requests\StoreMutationRequest;
use App\Http\Resources\MutationResource;
use App\Models\Dynamic; use App\Models\Dynamic;
use App\Models\Ledger; use App\Models\Ledger;
use App\Models\Mutation; use App\Models\Mutation;
@ -81,7 +80,7 @@ class MutationController extends Controller
{ {
$this->authorize('view', $mutation); $this->authorize('view', $mutation);
return new MutationResource($mutation); return $mutation;
} }
/** /**

View File

@ -2,7 +2,6 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Resources\DynamicResource;
use App\Models\Dynamic; use App\Models\Dynamic;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
@ -45,9 +44,9 @@ class ParticipantController extends Controller
->get(); ->get();
return Inertia::render('Dynamics/Participants/Show', [ return Inertia::render('Dynamics/Participants/Show', [
'dynamic' => new DynamicResource($dynamic), 'dynamic' => $dynamic,
'participant' => [ 'participant' => [
'id' => $user->id, 'id' => $user->uuid,
'name' => $user->name, 'name' => $user->name,
'display_name' => $participant->pivot->display_name, 'display_name' => $participant->pivot->display_name,
'role' => $participant->pivot->role, 'role' => $participant->pivot->role,

View File

@ -1,25 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BaseResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = parent::toArray($request);
if (isset($data['id']) && isset($this->uuid)) {
$data['id'] = $this->uuid;
}
return $data;
}
}

View File

@ -1,24 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class ChatResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = parent::toArray($request);
if ($this->whenLoaded('messages')) {
$data['messages'] = MessageResource::collection($this->messages);
}
return $data;
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class DynamicResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$result = parent::toArray($request);
if ($this->ledgers) {
$result['ledgers'] = LedgerResource::collection($this->ledgers);
}
if ($this->whenLoaded('participants')) {
$result['participants'] = ParticipantResource::collection($this->participants);
}
if ($this->whenLoaded('chat')) {
$result['chat'] = new ChatResource($this->chat);
}
return $result;
}
}

View File

@ -1,22 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class LedgerResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = parent::toArray($request);
$data['mutations'] = MutationResource::collection($this->whenLoaded('mutations'));
return $data;
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class MessageResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}

View File

@ -1,25 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class MutationResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = parent::toArray($request);
$data['can'] = [
'update' => $request->user()?->can('update', $this->resource) ?? false,
'void' => $request->user()?->can('void', $this->resource) ?? false,
];
return $data;
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class ParticipantResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class PredefinedMutationResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class UserResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}

View File

@ -105,6 +105,16 @@ class Mutation extends Model
}); });
} }
protected $appends = ['can'];
public function getCanAttribute(): array
{
return [
'update' => auth()->user()?->can('update', $this) ?? false,
'void' => auth()->user()?->can('void', $this) ?? false,
];
}
public function getRouteKeyName() public function getRouteKeyName()
{ {
return 'uuid'; return 'uuid';

View File

@ -21,7 +21,7 @@ test('authenticated participant can view another participant detail page in dyna
$response->assertInertia(fn ($page) => $page $response->assertInertia(fn ($page) => $page
->component('Dynamics/Participants/Show') ->component('Dynamics/Participants/Show')
->has('dynamic') ->has('dynamic')
->where('participant.id', $participant->id) ->where('participant.id', $participant->uuid)
->where('participant.name', $participant->name) ->where('participant.name', $participant->name)
->where('participant.display_name', null) ->where('participant.display_name', null)
->where('participant.role', 'participant') ->where('participant.role', 'participant')