Skip to content

ENH-004 — Prevent Double-Booking a Container 🟠 #8

Description

@hajk1

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 departureTimearrivalTime, 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:

  • Cannot book a container on overlapping voyages
  • Cancelled/delivered orders don't block new bookings
  • Returns 409 with a descriptive error message
  • At least two tests: one blocked, one allowed after cancellation
  • Code is formatted

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions