Link new guest to booking
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
This commit is contained in:
@@ -44,6 +44,15 @@ class Guests(
|
||||
if (phone.isBlank()) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "phoneE164 required")
|
||||
}
|
||||
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) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Booking already linked to guest")
|
||||
}
|
||||
val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
|
||||
if (existing != null) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Guest already exists")
|
||||
@@ -58,8 +67,11 @@ class Guests(
|
||||
addressText = request.addressText?.trim()?.ifBlank { null },
|
||||
updatedAt = now
|
||||
)
|
||||
guestRepo.save(guest)
|
||||
return setOf(guest).toResponse(guestVehicleRepo, guestRatingRepo).first()
|
||||
val saved = guestRepo.save(guest)
|
||||
booking.primaryGuest = saved
|
||||
booking.updatedAt = now
|
||||
bookingRepo.save(booking)
|
||||
return setOf(saved).toResponse(guestVehicleRepo, guestRatingRepo).first()
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
|
||||
@@ -51,6 +51,7 @@ data class GuestResponse(
|
||||
|
||||
data class GuestCreateRequest(
|
||||
val phoneE164: String,
|
||||
val bookingId: UUID,
|
||||
val name: String? = null,
|
||||
val nationality: String? = null,
|
||||
val addressText: String? = null
|
||||
|
||||
Reference in New Issue
Block a user