Validate room-stay bounds on booking expected-date updates
All checks were successful
build-and-deploy / build-deploy (push) Successful in 39s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 39s
This commit is contained in:
@@ -578,12 +578,65 @@ class BookingFlow(
|
||||
if (expectedIn != null && expectedOut != null && !expectedOut.isAfter(expectedIn)) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid date range")
|
||||
}
|
||||
validateRoomStayBoundsForExpectedDatesUpdate(booking, expectedIn, expectedOut)
|
||||
|
||||
booking.updatedAt = OffsetDateTime.now()
|
||||
bookingRepo.save(booking)
|
||||
bookingEvents.emit(propertyId, bookingId)
|
||||
}
|
||||
|
||||
private fun validateRoomStayBoundsForExpectedDatesUpdate(
|
||||
booking: com.android.trisolarisserver.models.booking.Booking,
|
||||
expectedIn: OffsetDateTime?,
|
||||
expectedOut: OffsetDateTime?
|
||||
) {
|
||||
if (expectedIn == null || expectedOut == null) return
|
||||
val bookingId = booking.id ?: return
|
||||
val stays = roomStayRepo.findByBookingId(bookingId)
|
||||
when (booking.status) {
|
||||
BookingStatus.OPEN -> {
|
||||
stays.forEach { stay ->
|
||||
if (stay.fromAt.isBefore(expectedIn) || stay.fromAt.isAfter(expectedOut)) {
|
||||
throw ResponseStatusException(
|
||||
HttpStatus.CONFLICT,
|
||||
"Room stay start must be within expected check-in/check-out window for OPEN booking"
|
||||
)
|
||||
}
|
||||
val toAt = stay.toAt
|
||||
if (toAt != null && (toAt.isBefore(expectedIn) || toAt.isAfter(expectedOut))) {
|
||||
throw ResponseStatusException(
|
||||
HttpStatus.CONFLICT,
|
||||
"Room stay end must be within expected check-in/check-out window for OPEN booking"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
BookingStatus.CHECKED_IN -> {
|
||||
val checkInAt = booking.checkinAt ?: expectedIn
|
||||
stays.forEach { stay ->
|
||||
if (stay.fromAt.isBefore(checkInAt) || !stay.fromAt.isBefore(expectedOut)) {
|
||||
throw ResponseStatusException(
|
||||
HttpStatus.CONFLICT,
|
||||
"Room stay start must be >= check-in and < expected check-out for CHECKED_IN booking"
|
||||
)
|
||||
}
|
||||
val toAt = stay.toAt
|
||||
if (toAt != null && toAt.isAfter(expectedOut)) {
|
||||
throw ResponseStatusException(
|
||||
HttpStatus.CONFLICT,
|
||||
"Room stay end cannot be after expected check-out for CHECKED_IN booking"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
BookingStatus.CHECKED_OUT,
|
||||
BookingStatus.CANCELLED,
|
||||
BookingStatus.NO_SHOW -> {
|
||||
// Already blocked by status guard in updateExpectedDates.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/{bookingId}/billing-policy")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@Transactional
|
||||
|
||||
Reference in New Issue
Block a user