Add booking guest link endpoint
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:
@@ -7,16 +7,20 @@ import com.android.trisolarisserver.controller.dto.BookingCheckInRequest
|
||||
import com.android.trisolarisserver.controller.dto.BookingCheckOutRequest
|
||||
import com.android.trisolarisserver.controller.dto.BookingCreateRequest
|
||||
import com.android.trisolarisserver.controller.dto.BookingCreateResponse
|
||||
import com.android.trisolarisserver.controller.dto.BookingLinkGuestRequest
|
||||
import com.android.trisolarisserver.controller.dto.BookingNoShowRequest
|
||||
import com.android.trisolarisserver.controller.dto.RoomStayPreAssignRequest
|
||||
import com.android.trisolarisserver.db.repo.BookingRepo
|
||||
import com.android.trisolarisserver.db.repo.GuestDocumentRepo
|
||||
import com.android.trisolarisserver.db.repo.GuestRepo
|
||||
import com.android.trisolarisserver.db.repo.GuestRatingRepo
|
||||
import com.android.trisolarisserver.models.booking.BookingStatus
|
||||
import com.android.trisolarisserver.models.booking.TransportMode
|
||||
import com.android.trisolarisserver.models.room.RoomStay
|
||||
import com.android.trisolarisserver.models.room.RateSource
|
||||
import com.android.trisolarisserver.models.property.Role
|
||||
import com.android.trisolarisserver.repo.AppUserRepo
|
||||
import com.android.trisolarisserver.repo.GuestVehicleRepo
|
||||
import com.android.trisolarisserver.repo.PropertyRepo
|
||||
import com.android.trisolarisserver.repo.RoomRepo
|
||||
import com.android.trisolarisserver.repo.RoomStayRepo
|
||||
@@ -44,7 +48,10 @@ class BookingFlow(
|
||||
private val roomStayRepo: RoomStayRepo,
|
||||
private val appUserRepo: AppUserRepo,
|
||||
private val propertyRepo: PropertyRepo,
|
||||
private val roomBoardEvents: RoomBoardEvents
|
||||
private val roomBoardEvents: RoomBoardEvents,
|
||||
private val guestVehicleRepo: GuestVehicleRepo,
|
||||
private val guestRatingRepo: GuestRatingRepo,
|
||||
private val guestDocumentRepo: GuestDocumentRepo
|
||||
) {
|
||||
|
||||
@PostMapping
|
||||
@@ -111,6 +118,32 @@ class BookingFlow(
|
||||
)
|
||||
}
|
||||
|
||||
@PostMapping("/{bookingId}/link-guest")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@Transactional
|
||||
fun linkGuest(
|
||||
@PathVariable propertyId: UUID,
|
||||
@PathVariable bookingId: UUID,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||
@RequestBody request: BookingLinkGuestRequest
|
||||
) {
|
||||
requireMember(propertyAccess, propertyId, principal)
|
||||
val booking = requireBooking(propertyId, bookingId)
|
||||
val guest = guestRepo.findById(request.guestId).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Guest not found")
|
||||
}
|
||||
if (guest.property.id != propertyId) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Guest not in property")
|
||||
}
|
||||
val previous = booking.primaryGuest
|
||||
booking.primaryGuest = guest
|
||||
booking.updatedAt = OffsetDateTime.now()
|
||||
bookingRepo.save(booking)
|
||||
if (previous != null && previous.id != guest.id && isPlaceholderGuest(previous) && isSafeToDelete(previous)) {
|
||||
guestRepo.delete(previous)
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/{bookingId}/check-in")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@Transactional
|
||||
@@ -345,4 +378,21 @@ class BookingFlow(
|
||||
return allowed.contains(mode)
|
||||
}
|
||||
|
||||
private fun isPlaceholderGuest(guest: com.android.trisolarisserver.models.booking.Guest): Boolean {
|
||||
return guest.phoneE164.isNullOrBlank() &&
|
||||
guest.name.isNullOrBlank() &&
|
||||
guest.nationality.isNullOrBlank() &&
|
||||
guest.addressText.isNullOrBlank() &&
|
||||
guest.signaturePath.isNullOrBlank()
|
||||
}
|
||||
|
||||
private fun isSafeToDelete(guest: com.android.trisolarisserver.models.booking.Guest): Boolean {
|
||||
val id = guest.id ?: return false
|
||||
if (bookingRepo.countByPrimaryGuestId(id) > 0) return false
|
||||
if (guestVehicleRepo.existsByGuestId(id)) return false
|
||||
if (guestDocumentRepo.existsByGuestId(id)) return false
|
||||
if (guestRatingRepo.existsByGuestId(id)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ data class BookingCreateResponse(
|
||||
val expectedCheckOutAt: String?
|
||||
)
|
||||
|
||||
data class BookingLinkGuestRequest(
|
||||
val guestId: UUID
|
||||
)
|
||||
|
||||
data class BookingCheckOutRequest(
|
||||
val checkOutAt: String? = null,
|
||||
val notes: String? = null
|
||||
|
||||
Reference in New Issue
Block a user