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:
|
What it does:
|
||||||
|
|
||||||
- Lists bookings with summary and computed pending amount.
|
- Lists bookings with summary and computed pending amount.
|
||||||
|
- Each booking item includes `vehicleNumbers` (always non-null: empty list or values).
|
||||||
|
|
||||||
Request body:
|
Request body:
|
||||||
|
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ class BookingFlow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Transactional(readOnly = true)
|
||||||
fun listBookings(
|
fun listBookings(
|
||||||
@PathVariable propertyId: UUID,
|
@PathVariable propertyId: UUID,
|
||||||
@AuthenticationPrincipal principal: MyPrincipal?,
|
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||||
@@ -238,6 +239,14 @@ class BookingFlow(
|
|||||||
chargeRepo.sumAmountByBookingIds(bookingIds)
|
chargeRepo.sumAmountByBookingIds(bookingIds)
|
||||||
.associate { it.bookingId to it.total }
|
.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 ->
|
return bookings.map { booking ->
|
||||||
val guest = booking.primaryGuest
|
val guest = booking.primaryGuest
|
||||||
val stays = staysByBooking[booking.id].orEmpty()
|
val stays = staysByBooking[booking.id].orEmpty()
|
||||||
@@ -261,6 +270,7 @@ class BookingFlow(
|
|||||||
guestId = guest?.id,
|
guestId = guest?.id,
|
||||||
guestName = guest?.name,
|
guestName = guest?.name,
|
||||||
guestPhone = guest?.phoneE164,
|
guestPhone = guest?.phoneE164,
|
||||||
|
vehicleNumbers = guest?.id?.let { vehicleNumbersByGuest[it] } ?: emptyList(),
|
||||||
roomNumbers = roomNumbersByBooking[booking.id] ?: emptyList(),
|
roomNumbers = roomNumbersByBooking[booking.id] ?: emptyList(),
|
||||||
source = booking.source,
|
source = booking.source,
|
||||||
billingMode = booking.billingMode.name,
|
billingMode = booking.billingMode.name,
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ data class BookingListItem(
|
|||||||
val guestId: UUID?,
|
val guestId: UUID?,
|
||||||
val guestName: String?,
|
val guestName: String?,
|
||||||
val guestPhone: String?,
|
val guestPhone: String?,
|
||||||
|
val vehicleNumbers: List<String>,
|
||||||
val roomNumbers: List<Int>,
|
val roomNumbers: List<Int>,
|
||||||
val source: String?,
|
val source: String?,
|
||||||
val billingMode: String,
|
val billingMode: String,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.android.trisolarisserver.repo.guest
|
|||||||
|
|
||||||
import com.android.trisolarisserver.models.booking.GuestVehicle
|
import com.android.trisolarisserver.models.booking.GuestVehicle
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
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
|
import java.util.UUID
|
||||||
|
|
||||||
interface GuestVehicleRepo : JpaRepository<GuestVehicle, UUID> {
|
interface GuestVehicleRepo : JpaRepository<GuestVehicle, UUID> {
|
||||||
@@ -9,4 +11,18 @@ interface GuestVehicleRepo : JpaRepository<GuestVehicle, UUID> {
|
|||||||
fun findByGuestIdIn(guestIds: List<UUID>): List<GuestVehicle>
|
fun findByGuestIdIn(guestIds: List<UUID>): List<GuestVehicle>
|
||||||
fun existsByPropertyIdAndVehicleNumberIgnoreCase(propertyId: UUID, vehicleNumber: String): Boolean
|
fun existsByPropertyIdAndVehicleNumberIgnoreCase(propertyId: UUID, vehicleNumber: String): Boolean
|
||||||
fun existsByGuestId(guestId: UUID): 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