Allow guest creation without phone; auto-create guest on booking
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:
@@ -10,6 +10,7 @@ import com.android.trisolarisserver.controller.dto.BookingCreateResponse
|
|||||||
import com.android.trisolarisserver.controller.dto.BookingNoShowRequest
|
import com.android.trisolarisserver.controller.dto.BookingNoShowRequest
|
||||||
import com.android.trisolarisserver.controller.dto.RoomStayPreAssignRequest
|
import com.android.trisolarisserver.controller.dto.RoomStayPreAssignRequest
|
||||||
import com.android.trisolarisserver.db.repo.BookingRepo
|
import com.android.trisolarisserver.db.repo.BookingRepo
|
||||||
|
import com.android.trisolarisserver.db.repo.GuestRepo
|
||||||
import com.android.trisolarisserver.models.booking.BookingStatus
|
import com.android.trisolarisserver.models.booking.BookingStatus
|
||||||
import com.android.trisolarisserver.models.booking.TransportMode
|
import com.android.trisolarisserver.models.booking.TransportMode
|
||||||
import com.android.trisolarisserver.models.room.RoomStay
|
import com.android.trisolarisserver.models.room.RoomStay
|
||||||
@@ -38,6 +39,7 @@ import java.util.UUID
|
|||||||
class BookingFlow(
|
class BookingFlow(
|
||||||
private val propertyAccess: PropertyAccess,
|
private val propertyAccess: PropertyAccess,
|
||||||
private val bookingRepo: BookingRepo,
|
private val bookingRepo: BookingRepo,
|
||||||
|
private val guestRepo: GuestRepo,
|
||||||
private val roomRepo: RoomRepo,
|
private val roomRepo: RoomRepo,
|
||||||
private val roomStayRepo: RoomStayRepo,
|
private val roomStayRepo: RoomStayRepo,
|
||||||
private val appUserRepo: AppUserRepo,
|
private val appUserRepo: AppUserRepo,
|
||||||
@@ -90,6 +92,15 @@ class BookingFlow(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val saved = bookingRepo.save(booking)
|
val saved = bookingRepo.save(booking)
|
||||||
|
val guest = com.android.trisolarisserver.models.booking.Guest(
|
||||||
|
property = property,
|
||||||
|
createdBy = actor,
|
||||||
|
updatedAt = now
|
||||||
|
)
|
||||||
|
val savedGuest = guestRepo.save(guest)
|
||||||
|
saved.primaryGuest = savedGuest
|
||||||
|
saved.updatedAt = now
|
||||||
|
bookingRepo.save(saved)
|
||||||
return BookingCreateResponse(
|
return BookingCreateResponse(
|
||||||
id = saved.id!!,
|
id = saved.id!!,
|
||||||
status = saved.status.name,
|
status = saved.status.name,
|
||||||
|
|||||||
@@ -48,10 +48,7 @@ class Guests(
|
|||||||
requireMember(propertyAccess, propertyId, principal)
|
requireMember(propertyAccess, propertyId, principal)
|
||||||
val property = requireProperty(propertyRepo, propertyId)
|
val property = requireProperty(propertyRepo, propertyId)
|
||||||
|
|
||||||
val phone = request.phoneE164.trim()
|
val phone = request.phoneE164?.trim()?.takeIf { it.isNotBlank() }
|
||||||
if (phone.isBlank()) {
|
|
||||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "phoneE164 required")
|
|
||||||
}
|
|
||||||
val booking = bookingRepo.findById(request.bookingId).orElseThrow {
|
val booking = bookingRepo.findById(request.bookingId).orElseThrow {
|
||||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Booking not found")
|
ResponseStatusException(HttpStatus.NOT_FOUND, "Booking not found")
|
||||||
}
|
}
|
||||||
@@ -61,6 +58,7 @@ class Guests(
|
|||||||
if (booking.primaryGuest != null) {
|
if (booking.primaryGuest != null) {
|
||||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Booking already linked to guest")
|
throw ResponseStatusException(HttpStatus.CONFLICT, "Booking already linked to guest")
|
||||||
}
|
}
|
||||||
|
if (phone != null) {
|
||||||
val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
|
val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
booking.primaryGuest = existing
|
booking.primaryGuest = existing
|
||||||
@@ -68,6 +66,7 @@ class Guests(
|
|||||||
bookingRepo.save(booking)
|
bookingRepo.save(booking)
|
||||||
return setOf(existing).toResponse(propertyId, guestVehicleRepo, guestRatingRepo).first()
|
return setOf(existing).toResponse(propertyId, guestVehicleRepo, guestRatingRepo).first()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val now = OffsetDateTime.now()
|
val now = OffsetDateTime.now()
|
||||||
val actor = appUserRepo.findById(principal!!.userId).orElse(null)
|
val actor = appUserRepo.findById(principal!!.userId).orElse(null)
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ data class GuestResponse(
|
|||||||
)
|
)
|
||||||
|
|
||||||
data class GuestCreateRequest(
|
data class GuestCreateRequest(
|
||||||
val phoneE164: String,
|
|
||||||
val bookingId: UUID,
|
val bookingId: UUID,
|
||||||
|
val phoneE164: String? = null,
|
||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
val nationality: String? = null,
|
val nationality: String? = null,
|
||||||
val addressText: String? = null
|
val addressText: String? = null
|
||||||
|
|||||||
Reference in New Issue
Block a user