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>
71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1\Artist;
|
|
|
|
use App\Exceptions\Artist\GenreInUseException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\V1\Artist\CreateGenreRequest;
|
|
use App\Http\Requests\Api\V1\Artist\UpdateGenreRequest;
|
|
use App\Http\Resources\Api\V1\Artist\GenreResource;
|
|
use App\Models\Genre;
|
|
use App\Models\Organisation;
|
|
use App\Services\Artist\GenreService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class GenreController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly GenreService $service,
|
|
) {}
|
|
|
|
public function index(Organisation $organisation): AnonymousResourceCollection
|
|
{
|
|
Gate::authorize('viewAny', [Genre::class, $organisation]);
|
|
|
|
$genres = Genre::query()
|
|
->where('organisation_id', $organisation->id)
|
|
->orderBy('sort_order')
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
return GenreResource::collection($genres);
|
|
}
|
|
|
|
public function store(CreateGenreRequest $request, Organisation $organisation): JsonResponse
|
|
{
|
|
Gate::authorize('create', [Genre::class, $organisation]);
|
|
|
|
$genre = $this->service->create($organisation, $request->validated());
|
|
|
|
return $this->created(GenreResource::make($genre));
|
|
}
|
|
|
|
public function update(UpdateGenreRequest $request, Organisation $organisation, Genre $genre): JsonResponse
|
|
{
|
|
Gate::authorize('update', $genre);
|
|
|
|
$genre = $this->service->update($genre, $request->validated());
|
|
|
|
return $this->success(GenreResource::make($genre));
|
|
}
|
|
|
|
public function destroy(Organisation $organisation, Genre $genre): JsonResponse
|
|
{
|
|
Gate::authorize('delete', $genre);
|
|
|
|
try {
|
|
$this->service->delete($genre);
|
|
} catch (GenreInUseException $e) {
|
|
return $this->error($e->getMessage(), 409, [
|
|
'referencing_artists_count' => $e->referencingArtistsCount,
|
|
]);
|
|
}
|
|
|
|
return response()->json(null, 204);
|
|
}
|
|
}
|