Class Booking
java.lang.Object
com.equipmentrental.equipment_rental_system.model.Booking
Represents a reservation of an equipment item for a specific date range.
Each booking is linked to one
Equipment item and one User.
Business rules enforced through this entity and the service layer:
- BR-01: cannot book equipment in MAINTENANCE or UNAVAILABLE status
- BR-02: date ranges must not overlap with other confirmed bookings for the same item
- BR-03: every booking must reference a registered staff member
- BR-05: end date must be equal to or later than start date
- BR-08: equipment status is updated when bookings are created or cancelled
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels this booking by setting its status toBookingStatus.CANCELLED.intCalculates the duration of this booking in days (inclusive of both start and end dates).booleanhasConflictWith(Booking otherBooking) Checks whether this booking's date range overlaps with another booking.booleanisActive()Checks whether this booking is currently active (confirmed and not cancelled).protected voidonCreate()Automatically sets the creation timestamp when the booking is first persisted.
-
Constructor Details
-
Booking
public Booking(LocalDate dateFrom, LocalDate dateTo, String purpose, BookingStatus status, Equipment equipment, User user) Creates a new booking with all required fields.- Parameters:
dateFrom- the first day of the reservation (inclusive)dateTo- the last day of the reservation (inclusive)purpose- reason for the bookingstatus- initial booking status (typically CONFIRMED)equipment- the equipment item being reserveduser- the staff member creating the booking
-
-
Method Details
-
onCreate
protected void onCreate()Automatically sets the creation timestamp when the booking is first persisted. -
hasConflictWith
Checks whether this booking's date range overlaps with another booking. Both start and end dates are treated as inclusive, so a booking ending on 10 April conflicts with one starting on 10 April.This method only compares dates. It does not check whether the bookings refer to the same equipment or whether either booking is cancelled. Those checks are the responsibility of the service layer.
- Parameters:
otherBooking- the booking to compare against- Returns:
trueif the date ranges overlap
-
cancel
public void cancel()Cancels this booking by setting its status toBookingStatus.CANCELLED. -
isActive
public boolean isActive()Checks whether this booking is currently active (confirmed and not cancelled).- Returns:
trueif the status isBookingStatus.CONFIRMED
-
getDurationDays
public int getDurationDays()Calculates the duration of this booking in days (inclusive of both start and end dates). A same-day booking returns 1.- Returns:
- the number of days in the booking period
-