refactor: align codebase with EventCrew domain and trim legacy band stack
- Update API: events, users, policies, routes, resources, migrations - Remove deprecated models/resources (customers, setlists, invitations, etc.) - Refresh admin app and docs; remove apps/band Made-with: Cursor
This commit is contained in:
@@ -4,151 +4,55 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Enums\RsvpStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\V1\InviteToEventRequest;
|
||||
use App\Http\Requests\Api\V1\RsvpEventRequest;
|
||||
use App\Http\Requests\Api\V1\StoreEventRequest;
|
||||
use App\Http\Requests\Api\V1\UpdateEventRequest;
|
||||
use App\Http\Resources\Api\V1\EventCollection;
|
||||
use App\Http\Resources\Api\V1\EventInvitationResource;
|
||||
use App\Http\Resources\Api\V1\EventResource;
|
||||
use App\Models\Event;
|
||||
use App\Models\EventInvitation;
|
||||
use App\Models\Organisation;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
final class EventController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of events.
|
||||
*/
|
||||
public function index(): EventCollection
|
||||
public function index(Organisation $organisation): AnonymousResourceCollection
|
||||
{
|
||||
Gate::authorize('viewAny', Event::class);
|
||||
Gate::authorize('viewAny', [Event::class, $organisation]);
|
||||
|
||||
$events = Event::query()
|
||||
->with(['location', 'customer'])
|
||||
->latest('event_date')
|
||||
$events = $organisation->events()
|
||||
->latest('start_date')
|
||||
->paginate();
|
||||
|
||||
return new EventCollection($events);
|
||||
return EventResource::collection($events);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created event.
|
||||
*/
|
||||
public function store(StoreEventRequest $request): JsonResponse
|
||||
{
|
||||
Gate::authorize('create', Event::class);
|
||||
|
||||
$data = $request->validated();
|
||||
$data['created_by'] = auth()->id();
|
||||
$data['currency'] = $data['currency'] ?? 'EUR';
|
||||
|
||||
$event = Event::create($data);
|
||||
|
||||
return $this->created(
|
||||
new EventResource($event->load(['location', 'customer'])),
|
||||
'Event created successfully'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified event.
|
||||
*/
|
||||
public function show(Event $event): EventResource
|
||||
public function show(Organisation $organisation, Event $event): JsonResponse
|
||||
{
|
||||
Gate::authorize('view', $event);
|
||||
|
||||
return new EventResource(
|
||||
$event->load(['location', 'customer', 'setlist.items.musicNumber', 'invitations.user', 'creator'])
|
||||
);
|
||||
abort_unless($event->organisation_id === $organisation->id, 404);
|
||||
|
||||
return $this->success(new EventResource($event->load('organisation')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified event.
|
||||
*/
|
||||
public function update(UpdateEventRequest $request, Event $event): JsonResponse
|
||||
public function store(StoreEventRequest $request, Organisation $organisation): JsonResponse
|
||||
{
|
||||
Gate::authorize('create', [Event::class, $organisation]);
|
||||
|
||||
$event = $organisation->events()->create($request->validated());
|
||||
|
||||
return $this->created(new EventResource($event));
|
||||
}
|
||||
|
||||
public function update(UpdateEventRequest $request, Organisation $organisation, Event $event): JsonResponse
|
||||
{
|
||||
Gate::authorize('update', $event);
|
||||
|
||||
abort_unless($event->organisation_id === $organisation->id, 404);
|
||||
|
||||
$event->update($request->validated());
|
||||
|
||||
return $this->success(
|
||||
new EventResource($event->load(['location', 'customer'])),
|
||||
'Event updated successfully'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified event.
|
||||
*/
|
||||
public function destroy(Event $event): JsonResponse
|
||||
{
|
||||
Gate::authorize('delete', $event);
|
||||
|
||||
$event->delete();
|
||||
|
||||
return $this->success(null, 'Event deleted successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
* Invite members to an event.
|
||||
*/
|
||||
public function invite(InviteToEventRequest $request, Event $event): JsonResponse
|
||||
{
|
||||
Gate::authorize('invite', $event);
|
||||
|
||||
$userIds = $request->validated()['user_ids'];
|
||||
$invitedCount = 0;
|
||||
|
||||
foreach ($userIds as $userId) {
|
||||
// Skip if already invited
|
||||
if ($event->invitations()->where('user_id', $userId)->exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$event->invitations()->create([
|
||||
'user_id' => $userId,
|
||||
'rsvp_status' => RsvpStatus::Pending,
|
||||
'invited_at' => now(),
|
||||
]);
|
||||
|
||||
$invitedCount++;
|
||||
}
|
||||
|
||||
return $this->success(
|
||||
EventInvitationResource::collection(
|
||||
$event->invitations()->with('user')->get()
|
||||
),
|
||||
"{$invitedCount} member(s) invited successfully"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to an event invitation (RSVP).
|
||||
*/
|
||||
public function rsvp(RsvpEventRequest $request, Event $event): JsonResponse
|
||||
{
|
||||
Gate::authorize('rsvp', $event);
|
||||
|
||||
$invitation = EventInvitation::where('event_id', $event->id)
|
||||
->where('user_id', auth()->id())
|
||||
->firstOrFail();
|
||||
|
||||
$data = $request->validated();
|
||||
|
||||
$invitation->update([
|
||||
'rsvp_status' => $data['status'],
|
||||
'rsvp_note' => $data['note'] ?? null,
|
||||
'rsvp_responded_at' => now(),
|
||||
]);
|
||||
|
||||
return $this->success(
|
||||
new EventInvitationResource($invitation->load('user')),
|
||||
'RSVP updated successfully'
|
||||
);
|
||||
return $this->success(new EventResource($event->fresh()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user