Compare commits

...

2 Commits

Author SHA1 Message Date
Daan Meijer
8d95e4ee53 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
2026-06-23 17:56:40 +02:00
Daan Meijer
ae925c7173 fill id with uuid everywhere 2026-06-23 17:17:47 +02:00
21 changed files with 64 additions and 233 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace App\Concerns;
trait SerializesIdToUuid
{
/**
* Convert the model's attributes to an array.
* Overrides the default model toArray method to replace 'id' with 'uuid'.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$array = parent::toArray();
if (isset($this->uuid)) {
$array['id'] = $this->uuid;
}
return $array;
}
}

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

@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Models\Chat; use App\Models\Chat;
use App\Concerns\SerializesIdToUuid;
class Dynamic extends Model class Dynamic extends Model
{ {
/** @use HasFactory<DynamicFactory> */ /** @use HasFactory<DynamicFactory> */
use HasFactory; use HasFactory, SerializesIdToUuid;
protected $fillable = [ protected $fillable = [
'name', 'name',

View File

@ -9,11 +9,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class Ledger extends Model class Ledger extends Model
{ {
/** @use HasFactory<LedgerFactory> */ /** @use HasFactory<LedgerFactory> */
use HasFactory; use HasFactory, SerializesIdToUuid;
protected $fillable = [ protected $fillable = [
'dynamic_id', 'dynamic_id',

View File

@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class Mutation extends Model class Mutation extends Model
{ {
/** @use HasFactory<MutationFactory> */ /** @use HasFactory<MutationFactory> */
use HasFactory; use HasFactory, SerializesIdToUuid;
protected $fillable = [ protected $fillable = [
'ledger_id', 'ledger_id',
@ -104,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

@ -6,10 +6,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class PredefinedMutation extends Model class PredefinedMutation extends Model
{ {
use HasFactory; use HasFactory, SerializesIdToUuid;
protected $fillable = [ protected $fillable = [
'ledger_id', 'ledger_id',

View File

@ -15,6 +15,7 @@ use Laravel\Fortify\Contracts\PasskeyUser;
use Laravel\Fortify\PasskeyAuthenticatable; use Laravel\Fortify\PasskeyAuthenticatable;
use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Fortify\TwoFactorAuthenticatable;
use NotificationChannels\WebPush\HasPushSubscriptions; use NotificationChannels\WebPush\HasPushSubscriptions;
use App\Concerns\SerializesIdToUuid;
/** /**
* @property int $id * @property int $id
@ -34,7 +35,7 @@ use NotificationChannels\WebPush\HasPushSubscriptions;
class User extends Authenticatable implements PasskeyUser class User extends Authenticatable implements PasskeyUser
{ {
/** @use HasFactory<UserFactory> */ /** @use HasFactory<UserFactory> */
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable; use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable, SerializesIdToUuid;
public function dynamics() public function dynamics()
{ {

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')

View File

@ -25,8 +25,8 @@ test('owner can view predefined mutations for ledger', function () {
$response->assertOk(); $response->assertOk();
$response->assertInertia(fn ($page) => $page $response->assertInertia(fn ($page) => $page
->component('Ledgers/PredefinedMutations/Index') ->component('Ledgers/PredefinedMutations/Index')
->where('dynamic.id', $dynamic->id) ->where('dynamic.id', $dynamic->uuid)
->where('ledger.id', $ledger->id) ->where('ledger.id', $ledger->uuid)
->has('predefined_mutations', 1) ->has('predefined_mutations', 1)
->where('predefined_mutations.0.name', 'Weekly Room Cleaning') ->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
); );
@ -112,7 +112,7 @@ test('owner can view edit form for predefined mutation', function () {
$response->assertOk(); $response->assertOk();
$response->assertInertia(fn ($page) => $page $response->assertInertia(fn ($page) => $page
->component('Ledgers/PredefinedMutations/Edit') ->component('Ledgers/PredefinedMutations/Edit')
->where('predefined_mutation.id', $predefined->id) ->where('predefined_mutation.id', $predefined->uuid)
); );
}); });