Link new guest to booking
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s

This commit is contained in:
androidlover5842
2026-01-29 04:05:29 +05:30
parent 36e18f9649
commit ffe26a4739
2 changed files with 15 additions and 2 deletions

View File

@@ -44,6 +44,15 @@ class Guests(
if (phone.isBlank()) { if (phone.isBlank()) {
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "phoneE164 required") 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) val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
if (existing != null) { if (existing != null) {
throw ResponseStatusException(HttpStatus.CONFLICT, "Guest already exists") throw ResponseStatusException(HttpStatus.CONFLICT, "Guest already exists")
@@ -58,8 +67,11 @@ class Guests(
addressText = request.addressText?.trim()?.ifBlank { null }, addressText = request.addressText?.trim()?.ifBlank { null },
updatedAt = now updatedAt = now
) )
guestRepo.save(guest) val saved = guestRepo.save(guest)
return setOf(guest).toResponse(guestVehicleRepo, guestRatingRepo).first() booking.primaryGuest = saved
booking.updatedAt = now
bookingRepo.save(booking)
return setOf(saved).toResponse(guestVehicleRepo, guestRatingRepo).first()
} }
@GetMapping("/search") @GetMapping("/search")

View File

@@ -51,6 +51,7 @@ data class GuestResponse(
data class GuestCreateRequest( data class GuestCreateRequest(
val phoneE164: String, val phoneE164: String,
val bookingId: UUID,
val name: String? = null, val name: String? = null,
val nationality: String? = null, val nationality: String? = null,
val addressText: String? = null val addressText: String? = null