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>
110 lines
3.6 KiB
PHP
110 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1\Artist;
|
|
|
|
use App\Exceptions\Artist\DuplicateArtistException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\V1\Artist\CreateArtistRequest;
|
|
use App\Http\Requests\Api\V1\Artist\UpdateArtistRequest;
|
|
use App\Http\Resources\Api\V1\Artist\ArtistResource;
|
|
use App\Models\Artist;
|
|
use App\Models\Organisation;
|
|
use App\Services\Artist\ArtistService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class ArtistController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly ArtistService $service,
|
|
) {}
|
|
|
|
public function index(Request $request, Organisation $organisation): AnonymousResourceCollection
|
|
{
|
|
Gate::authorize('viewAny', [Artist::class, $organisation]);
|
|
|
|
$query = Artist::query()
|
|
->where('organisation_id', $organisation->id)
|
|
->with(['defaultGenre', 'agentCompany']);
|
|
|
|
if ($request->boolean('with_trashed')) {
|
|
$query->withTrashed();
|
|
}
|
|
if ($request->boolean('trashed_only')) {
|
|
$query->onlyTrashed();
|
|
}
|
|
|
|
if ($request->filled('search')) {
|
|
$term = '%'.$request->string('search').'%';
|
|
$query->where(function ($q) use ($term): void {
|
|
$q->where('name', 'like', $term)->orWhere('slug', 'like', $term);
|
|
});
|
|
}
|
|
if ($request->filled('genre_id')) {
|
|
$query->where('default_genre_id', $request->string('genre_id'));
|
|
}
|
|
if ($request->filled('agent_company_id')) {
|
|
$query->where('agent_company_id', $request->string('agent_company_id'));
|
|
}
|
|
|
|
return ArtistResource::collection($query->orderBy('name')->paginate(50));
|
|
}
|
|
|
|
public function show(Organisation $organisation, Artist $artist): JsonResponse
|
|
{
|
|
Gate::authorize('view', $artist);
|
|
$artist->loadMissing(['defaultGenre', 'agentCompany', 'contacts']);
|
|
|
|
return $this->success(ArtistResource::make($artist));
|
|
}
|
|
|
|
public function store(CreateArtistRequest $request, Organisation $organisation): JsonResponse
|
|
{
|
|
Gate::authorize('create', [Artist::class, $organisation]);
|
|
|
|
try {
|
|
$artist = $this->service->create($organisation, $request->validated());
|
|
} catch (DuplicateArtistException $e) {
|
|
return $this->error('Duplicate artist name.', 409, [
|
|
'duplicate_artist_id' => $e->existing->id,
|
|
]);
|
|
}
|
|
|
|
return $this->created(ArtistResource::make($artist->load(['defaultGenre', 'agentCompany'])));
|
|
}
|
|
|
|
public function update(UpdateArtistRequest $request, Organisation $organisation, Artist $artist): JsonResponse
|
|
{
|
|
Gate::authorize('update', $artist);
|
|
|
|
$artist = $this->service->update($artist, $request->validated());
|
|
|
|
return $this->success(ArtistResource::make($artist->load(['defaultGenre', 'agentCompany'])));
|
|
}
|
|
|
|
public function destroy(Organisation $organisation, Artist $artist): JsonResponse
|
|
{
|
|
if (! Gate::check('delete', $artist)) {
|
|
return $this->forbidden('Cannot delete artist with active engagements.');
|
|
}
|
|
|
|
$this->service->softDelete($artist);
|
|
|
|
return response()->json(null, 204);
|
|
}
|
|
|
|
public function restore(Organisation $organisation, string $artist): JsonResponse
|
|
{
|
|
$model = Artist::withTrashed()->findOrFail($artist);
|
|
Gate::authorize('restore', $model);
|
|
|
|
$this->service->restore($model);
|
|
|
|
return $this->success(ArtistResource::make($model->fresh()));
|
|
}
|
|
}
|