Currently nothing stops the same container from being booked on overlapping voyages. Add a validation rule.
Rule: A container cannot be assigned to two voyages whose time ranges overlap. Specifically, if a container is already booked on a voyage with departureTime → arrivalTime, it cannot be booked on another voyage that overlaps that time window.
Where to add this: FreightOrderService.createOrder() — before saving.
Hints:
- Add a custom query in
FreightOrderRepository (or VoyageRepository) to check for overlapping voyages for a given container
- Consider only
PENDING, CONFIRMED, and IN_TRANSIT orders (ignore CANCELLED and DELIVERED)
- Return 409 Conflict with a clear message if there's an overlap
Acceptance criteria:
Currently nothing stops the same container from being booked on overlapping voyages. Add a validation rule.
Rule: A container cannot be assigned to two voyages whose time ranges overlap. Specifically, if a container is already booked on a voyage with
departureTime→arrivalTime, it cannot be booked on another voyage that overlaps that time window.Where to add this:
FreightOrderService.createOrder()— before saving.Hints:
FreightOrderRepository(orVoyageRepository) to check for overlapping voyages for a given containerPENDING,CONFIRMED, andIN_TRANSITorders (ignoreCANCELLEDandDELIVERED)Acceptance criteria: