Adjust booking create and link guest vehicles to booking
All checks were successful
build-and-deploy / build-deploy (push) Successful in 35s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 35s
This commit is contained in:
@@ -65,13 +65,15 @@ class BookingFlow(
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid date range")
|
||||
}
|
||||
|
||||
val now = OffsetDateTime.now()
|
||||
val now = nowForProperty(property.timezone)
|
||||
val shouldCheckIn = !expectedCheckInAt.isBefore(now)
|
||||
val booking = com.android.trisolarisserver.models.booking.Booking(
|
||||
property = property,
|
||||
status = BookingStatus.OPEN,
|
||||
status = if (shouldCheckIn) BookingStatus.CHECKED_IN else BookingStatus.OPEN,
|
||||
source = request.source?.trim().takeIf { !it.isNullOrBlank() } ?: "WALKIN",
|
||||
expectedCheckinAt = expectedCheckInAt,
|
||||
expectedCheckoutAt = expectedCheckOutAt,
|
||||
checkinAt = if (shouldCheckIn) expectedCheckInAt else null,
|
||||
expectedCheckinAt = if (shouldCheckIn) null else expectedCheckInAt,
|
||||
expectedCheckoutAt = if (shouldCheckIn) null else expectedCheckOutAt,
|
||||
transportMode = request.transportMode?.let {
|
||||
val mode = parseTransportMode(it)
|
||||
if (!isTransportModeAllowed(property, mode)) {
|
||||
@@ -79,7 +81,6 @@ class BookingFlow(
|
||||
}
|
||||
mode
|
||||
},
|
||||
transportVehicleNumber = request.transportVehicleNumber,
|
||||
adultCount = request.adultCount,
|
||||
totalGuestCount = request.totalGuestCount,
|
||||
notes = request.notes,
|
||||
@@ -91,8 +92,9 @@ class BookingFlow(
|
||||
return BookingCreateResponse(
|
||||
id = saved.id!!,
|
||||
status = saved.status.name,
|
||||
expectedCheckInAt = expectedCheckInAt.toString(),
|
||||
expectedCheckOutAt = expectedCheckOutAt.toString()
|
||||
checkInAt = saved.checkinAt?.toString(),
|
||||
expectedCheckInAt = saved.expectedCheckinAt?.toString(),
|
||||
expectedCheckOutAt = saved.expectedCheckoutAt?.toString()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.android.trisolarisserver.controller.dto.GuestResponse
|
||||
import com.android.trisolarisserver.controller.dto.GuestVehicleRequest
|
||||
import com.android.trisolarisserver.models.booking.Guest
|
||||
import com.android.trisolarisserver.models.booking.GuestVehicle
|
||||
import com.android.trisolarisserver.db.repo.BookingRepo
|
||||
import com.android.trisolarisserver.db.repo.GuestRepo
|
||||
import com.android.trisolarisserver.db.repo.GuestRatingRepo
|
||||
import com.android.trisolarisserver.repo.GuestVehicleRepo
|
||||
@@ -22,6 +23,7 @@ class Guests(
|
||||
private val propertyAccess: PropertyAccess,
|
||||
private val propertyRepo: PropertyRepo,
|
||||
private val guestRepo: GuestRepo,
|
||||
private val bookingRepo: BookingRepo,
|
||||
private val guestVehicleRepo: GuestVehicleRepo,
|
||||
private val guestRatingRepo: GuestRatingRepo
|
||||
) {
|
||||
@@ -64,16 +66,32 @@ class Guests(
|
||||
requireMember(propertyAccess, propertyId, principal)
|
||||
|
||||
val (property, guest) = requirePropertyGuest(propertyRepo, guestRepo, propertyId, guestId)
|
||||
if (guestVehicleRepo.existsByPropertyIdAndVehicleNumberIgnoreCase(property.id!!, request.vehicleNumber)) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Vehicle number already exists")
|
||||
val booking = bookingRepo.findById(request.bookingId).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Booking not found")
|
||||
}
|
||||
if (booking.property.id != property.id) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Booking not in property")
|
||||
}
|
||||
if (booking.primaryGuest != null && booking.primaryGuest?.id != guest.id) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Booking linked to different guest")
|
||||
}
|
||||
|
||||
val vehicle = GuestVehicle(
|
||||
property = property,
|
||||
guest = guest,
|
||||
vehicleNumber = request.vehicleNumber.trim()
|
||||
)
|
||||
guestVehicleRepo.save(vehicle)
|
||||
val existing = guestVehicleRepo.findByPropertyIdAndVehicleNumberIgnoreCase(property.id!!, request.vehicleNumber)
|
||||
if (existing != null) {
|
||||
if (existing.guest.id != guest.id) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Vehicle number already exists")
|
||||
}
|
||||
existing.booking = booking
|
||||
guestVehicleRepo.save(existing)
|
||||
} else {
|
||||
val vehicle = GuestVehicle(
|
||||
property = property,
|
||||
guest = guest,
|
||||
booking = booking,
|
||||
vehicleNumber = request.vehicleNumber.trim()
|
||||
)
|
||||
guestVehicleRepo.save(vehicle)
|
||||
}
|
||||
return setOf(guest).toResponse(guestVehicleRepo, guestRatingRepo).first()
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ data class BookingCreateRequest(
|
||||
val expectedCheckInAt: String,
|
||||
val expectedCheckOutAt: String,
|
||||
val transportMode: String? = null,
|
||||
val transportVehicleNumber: String? = null,
|
||||
val adultCount: Int? = null,
|
||||
val totalGuestCount: Int? = null,
|
||||
val notes: String? = null
|
||||
@@ -24,8 +23,9 @@ data class BookingCreateRequest(
|
||||
data class BookingCreateResponse(
|
||||
val id: UUID,
|
||||
val status: String,
|
||||
val expectedCheckInAt: String,
|
||||
val expectedCheckOutAt: String
|
||||
val checkInAt: String?,
|
||||
val expectedCheckInAt: String?,
|
||||
val expectedCheckOutAt: String?
|
||||
)
|
||||
|
||||
data class BookingCheckOutRequest(
|
||||
|
||||
@@ -50,7 +50,8 @@ data class GuestResponse(
|
||||
)
|
||||
|
||||
data class GuestVehicleRequest(
|
||||
val vehicleNumber: String
|
||||
val vehicleNumber: String,
|
||||
val bookingId: UUID
|
||||
)
|
||||
|
||||
data class TransportModeStatusResponse(
|
||||
|
||||
Reference in New Issue
Block a user