Include active room numbers in booking list
All checks were successful
build-and-deploy / build-deploy (push) Successful in 35s

This commit is contained in:
androidlover5842
2026-01-29 20:05:55 +05:30
parent 62f2cc5aaa
commit 26b7392806
3 changed files with 26 additions and 0 deletions

View File

@@ -159,6 +159,14 @@ class BookingFlow(
} else {
bookingRepo.findByPropertyIdAndStatusInOrderByCreatedAtDesc(propertyId, statuses)
}
val bookingIds = bookings.mapNotNull { it.id }
val roomNumbersByBooking = if (bookingIds.isEmpty()) {
emptyMap()
} else {
roomStayRepo.findActiveRoomNumbersByBookingIds(bookingIds)
.groupBy { it.bookingId }
.mapValues { (_, rows) -> rows.map { it.roomNumber }.distinct().sorted() }
}
return bookings.map { booking ->
val guest = booking.primaryGuest
BookingListItem(
@@ -167,6 +175,7 @@ class BookingFlow(
guestId = guest?.id,
guestName = guest?.name,
guestPhone = guest?.phoneE164,
roomNumbers = roomNumbersByBooking[booking.id] ?: emptyList(),
source = booking.source,
expectedCheckInAt = booking.expectedCheckinAt?.toString(),
expectedCheckOutAt = booking.expectedCheckoutAt?.toString(),

View File

@@ -60,6 +60,7 @@ data class BookingListItem(
val guestId: UUID?,
val guestName: String?,
val guestPhone: String?,
val roomNumbers: List<Int>,
val source: String?,
val expectedCheckInAt: String?,
val expectedCheckOutAt: String?,

View File

@@ -89,4 +89,20 @@ interface RoomStayRepo : JpaRepository<RoomStay, UUID> {
where rs.room.id = :roomId
""")
fun existsByRoomId(@Param("roomId") roomId: UUID): Boolean
@Query("""
select rs.booking.id as bookingId, r.roomNumber as roomNumber
from RoomStay rs
join rs.room r
where rs.booking.id in :bookingIds
and rs.toAt is null
""")
fun findActiveRoomNumbersByBookingIds(
@Param("bookingIds") bookingIds: List<UUID>
): List<BookingRoomNumberRow>
}
interface BookingRoomNumberRow {
val bookingId: UUID
val roomNumber: Int
}