- Crowd Types + Persons CRUD (73 tests) - Festival Sections + Time Slots + Shifts CRUD met assign/claim flow (84 tests) - Invite Flow + Member Management met InvitationService (109 tests) - Schema v1.6 migraties volledig uitgevoerd - DevSeeder bijgewerkt met crowd types voor testorganisatie
55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\V1\StoreCompanyRequest;
|
|
use App\Http\Requests\Api\V1\UpdateCompanyRequest;
|
|
use App\Http\Resources\Api\V1\CompanyResource;
|
|
use App\Models\Company;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class CompanyController extends Controller
|
|
{
|
|
public function index(Organisation $organisation): AnonymousResourceCollection
|
|
{
|
|
Gate::authorize('viewAny', [Company::class, $organisation]);
|
|
|
|
$companies = $organisation->companies()->get();
|
|
|
|
return CompanyResource::collection($companies);
|
|
}
|
|
|
|
public function store(StoreCompanyRequest $request, Organisation $organisation): JsonResponse
|
|
{
|
|
Gate::authorize('create', [Company::class, $organisation]);
|
|
|
|
$company = $organisation->companies()->create($request->validated());
|
|
|
|
return $this->created(new CompanyResource($company));
|
|
}
|
|
|
|
public function update(UpdateCompanyRequest $request, Organisation $organisation, Company $company): JsonResponse
|
|
{
|
|
Gate::authorize('update', [$company, $organisation]);
|
|
|
|
$company->update($request->validated());
|
|
|
|
return $this->success(new CompanyResource($company->fresh()));
|
|
}
|
|
|
|
public function destroy(Organisation $organisation, Company $company): JsonResponse
|
|
{
|
|
Gate::authorize('delete', [$company, $organisation]);
|
|
|
|
$company->delete();
|
|
|
|
return response()->json(null, 204);
|
|
}
|
|
}
|