Six thin controllers under app/Http/Controllers/Api/V1/Artist/. Zero
business logic: every mutation routes through a service from
app/Services/Artist/. Authorization via Gate::authorize matching
PersonController convention (request authorize() returns true; gates
fire in the controller).
ArtistController — org-scoped CRUD + restore. Catches
DuplicateArtistException → 409 with
duplicate_artist_id so the dialog can
offer "use existing".
GenreController — org-scoped CRUD; catches GenreInUseException
→ 409 with referencing_artists_count.
ArtistEngagementController — event-scoped CRUD; catches
InvalidStatusTransitionException → 422
with a Dutch-readable message.
StageController — event-scoped CRUD + reorder + replaceDays;
catches StageDaysOrphanedPerformancesException
→ 409 with the orphaned performance ids
and the removed event ids per RFC §10.5.
destroy returns the parked performance
count (cascade-park).
PerformanceController — event-scoped CRUD with index filters
`?day={subevent}` and `?stage_id=null`
(wachtrij). update is non-placement only.
TimetableMoveController — single __invoke for POST /timetable/move.
Catches VersionMismatchException → 409
with current_version + server_data per
RFC D14.
Routes wired into api/routes/api.php nested under the existing
organisations/{organisation}/events/{event} prefix group, matching
PersonController and ShiftController structure. The move endpoint
gets the new `idempotency.60s` middleware alias for R1. `stages/order`
and `stages/{stage}/days` registered before the apiResource so the
literal path wins over the wildcard.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
103 lines
3.5 KiB
PHP
103 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1\Artist;
|
|
|
|
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\V1\Artist\CreatePerformanceRequest;
|
|
use App\Http\Requests\Api\V1\Artist\UpdatePerformanceRequest;
|
|
use App\Http\Resources\Api\V1\Artist\PerformanceResource;
|
|
use App\Models\ArtistEngagement;
|
|
use App\Models\Event;
|
|
use App\Models\Organisation;
|
|
use App\Models\Performance;
|
|
use App\Services\Artist\PerformanceService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class PerformanceController extends Controller
|
|
{
|
|
use VerifiesOrganisationEvent;
|
|
|
|
public function __construct(
|
|
private readonly PerformanceService $service,
|
|
) {}
|
|
|
|
public function index(Request $request, Organisation $organisation, Event $event): AnonymousResourceCollection
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('viewAny', [Performance::class, $event]);
|
|
|
|
$query = Performance::query()
|
|
->whereHas('engagement', fn ($q) => $q->where('event_id', $event->id))
|
|
->with(['engagement.artist.defaultGenre', 'stage']);
|
|
|
|
if ($request->filled('day')) {
|
|
$query->where('event_id', $request->string('day'));
|
|
}
|
|
if ($request->query('stage_id') === 'null') {
|
|
$query->whereNull('stage_id');
|
|
} elseif ($request->filled('stage_id')) {
|
|
$query->where('stage_id', $request->string('stage_id'));
|
|
}
|
|
|
|
return PerformanceResource::collection($query->orderBy('start_at')->get());
|
|
}
|
|
|
|
public function show(Organisation $organisation, Event $event, Performance $performance): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('view', [$performance, $event]);
|
|
|
|
$performance->loadMissing(['engagement.artist.defaultGenre', 'stage']);
|
|
|
|
return $this->success(PerformanceResource::make($performance));
|
|
}
|
|
|
|
public function store(CreatePerformanceRequest $request, Organisation $organisation, Event $event): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('create', [Performance::class, $event]);
|
|
|
|
$data = $request->validated();
|
|
$engagement = ArtistEngagement::query()->findOrFail($data['engagement_id']);
|
|
|
|
$performance = $this->service->create($engagement, $data);
|
|
|
|
return $this->created(
|
|
PerformanceResource::make($performance->load(['engagement.artist.defaultGenre', 'stage'])),
|
|
);
|
|
}
|
|
|
|
public function update(
|
|
UpdatePerformanceRequest $request,
|
|
Organisation $organisation,
|
|
Event $event,
|
|
Performance $performance,
|
|
): JsonResponse {
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('update', [$performance, $event]);
|
|
|
|
$performance = $this->service->update($performance, $request->validated());
|
|
|
|
return $this->success(PerformanceResource::make($performance));
|
|
}
|
|
|
|
public function destroy(
|
|
Organisation $organisation,
|
|
Event $event,
|
|
Performance $performance,
|
|
): JsonResponse {
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('delete', [$performance, $event]);
|
|
|
|
$this->service->delete($performance);
|
|
|
|
return response()->json(null, 204);
|
|
}
|
|
}
|