Add Booking module: model, create/read/cancel API, Filament resource (T4.1-T4.7)

- Booking model with booking_vehicle_options line items (supports mixing
  vehicle options like front_seat + back_seat in one booking), price
  snapshot, status machine, and driver/car assignment fields
- BookingService: front-seat max, disabled-option toggles, duplicate-option
  and whole-vehicle-exclusivity guards
- CreateBookingAction, CancelBookingAction, AssignDriverAction
- BookingRefGenerator: sequential EVB-AAAAA1-style refs via row lock
- POST/GET/cancel booking API endpoints (Sanctum, ownership + admin policy)
- BookingPlugin + Filament BookingResource: list, detail view, Cancel and
  Assign Driver actions (shared between table and detail page)
- domain.md updated for multi-vehicle-option bookings (§2) and driver/
  vehicle assignment (§5a)
This commit is contained in:
Nyan Lin Paing
2026-08-08 21:43:15 +07:00
parent 4da9ecfe7d
commit 5b68f4fa38
51 changed files with 2698 additions and 42 deletions
@@ -0,0 +1,38 @@
<?php
use Modules\Booking\Actions\CancelBookingAction;
use Modules\Booking\Enums\BookingStatus;
use Modules\Booking\Exceptions\BookingCannotBeCancelledException;
use Modules\Booking\Models\Booking;
test('it cancels a pending_payment booking', function () {
$booking = Booking::factory()->create(['status' => BookingStatus::PendingPayment]);
$cancelled = (new CancelBookingAction)->handle($booking);
expect($cancelled->status)->toBe(BookingStatus::Cancelled)
->and($booking->refresh()->status)->toBe(BookingStatus::Cancelled);
});
test('it guards against cancelling a confirmed booking', function () {
$booking = Booking::factory()->create(['status' => BookingStatus::Confirmed]);
expect(fn () => (new CancelBookingAction)->handle($booking))
->toThrow(BookingCannotBeCancelledException::class);
expect($booking->refresh()->status)->toBe(BookingStatus::Confirmed);
});
test('it guards against cancelling an already cancelled booking', function () {
$booking = Booking::factory()->create(['status' => BookingStatus::Cancelled]);
expect(fn () => (new CancelBookingAction)->handle($booking))
->toThrow(BookingCannotBeCancelledException::class);
});
test('it guards against cancelling an expired booking', function () {
$booking = Booking::factory()->create(['status' => BookingStatus::Expired]);
expect(fn () => (new CancelBookingAction)->handle($booking))
->toThrow(BookingCannotBeCancelledException::class);
});