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:
@@ -1574,6 +1574,7 @@ BOOKING APIS
|
||||
What it does:
|
||||
|
||||
- Lists bookings with summary and computed pending amount.
|
||||
- Each booking item includes `vehicleNumbers` (always non-null: empty list or values).
|
||||
|
||||
Request body:
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -56,6 +56,7 @@ data class BookingListItem(
|
||||
val guestId: UUID?,
|
||||
val guestName: String?,
|
||||
val guestPhone: String?,
|
||||
val vehicleNumbers: List<String>,
|
||||
val roomNumbers: List<Int>,
|
||||
val source: String?,
|
||||
val billingMode: String,
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.android.trisolarisserver.repo.guest
|
||||
|
||||
import com.android.trisolarisserver.models.booking.GuestVehicle
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.query.Param
|
||||
import java.util.UUID
|
||||
|
||||
interface GuestVehicleRepo : JpaRepository<GuestVehicle, UUID> {
|
||||
@@ -9,4 +11,18 @@ interface GuestVehicleRepo : JpaRepository<GuestVehicle, UUID> {
|
||||
fun findByGuestIdIn(guestIds: List<UUID>): List<GuestVehicle>
|
||||
fun existsByPropertyIdAndVehicleNumberIgnoreCase(propertyId: UUID, vehicleNumber: String): Boolean
|
||||
fun existsByGuestId(guestId: UUID): Boolean
|
||||
|
||||
@Query(
|
||||
"""
|
||||
select gv.guest.id as guestId, gv.vehicleNumber as vehicleNumber
|
||||
from GuestVehicle gv
|
||||
where gv.guest.id in :guestIds
|
||||
"""
|
||||
)
|
||||
fun findRowsByGuestIds(@Param("guestIds") guestIds: List<UUID>): List<GuestVehicleRow>
|
||||
}
|
||||
|
||||
interface GuestVehicleRow {
|
||||
val guestId: UUID
|
||||
val vehicleNumber: String
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user