Add non-null vehicleNumbers to booking list response
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:
@@ -189,6 +189,7 @@ class BookingFlow(
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Transactional(readOnly = true)
|
||||
fun listBookings(
|
||||
@PathVariable propertyId: UUID,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||
@@ -238,6 +239,14 @@ class BookingFlow(
|
||||
chargeRepo.sumAmountByBookingIds(bookingIds)
|
||||
.associate { it.bookingId to it.total }
|
||||
}
|
||||
val guestIds = bookings.mapNotNull { it.primaryGuest?.id }.distinct()
|
||||
val vehicleNumbersByGuest = if (guestIds.isEmpty()) {
|
||||
emptyMap()
|
||||
} else {
|
||||
guestVehicleRepo.findRowsByGuestIds(guestIds)
|
||||
.groupBy { it.guestId }
|
||||
.mapValues { (_, rows) -> rows.map { it.vehicleNumber }.distinct().sorted() }
|
||||
}
|
||||
return bookings.map { booking ->
|
||||
val guest = booking.primaryGuest
|
||||
val stays = staysByBooking[booking.id].orEmpty()
|
||||
@@ -261,6 +270,7 @@ class BookingFlow(
|
||||
guestId = guest?.id,
|
||||
guestName = guest?.name,
|
||||
guestPhone = guest?.phoneE164,
|
||||
vehicleNumbers = guest?.id?.let { vehicleNumbersByGuest[it] } ?: emptyList(),
|
||||
roomNumbers = roomNumbersByBooking[booking.id] ?: emptyList(),
|
||||
source = booking.source,
|
||||
billingMode = booking.billingMode.name,
|
||||
|
||||
Reference in New Issue
Block a user