From 2407aa3b7a23a3ec41649c5d8005ad8fc0c912c0 Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Wed, 28 Jan 2026 05:25:43 +0530 Subject: [PATCH] Add available rooms and room type room list endpoints --- .../trisolarisserver/controller/Rooms.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/Rooms.kt b/src/main/kotlin/com/android/trisolarisserver/controller/Rooms.kt index c3ae6ef..c1c780e 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/Rooms.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/Rooms.kt @@ -127,6 +127,48 @@ class Rooms( }.sortedBy { it.roomTypeName } } + @GetMapping("/available") + fun availableRooms( + @PathVariable propertyId: UUID, + @AuthenticationPrincipal principal: MyPrincipal? + ): List { + requirePrincipal(principal) + propertyAccess.requireMember(propertyId, principal!!.userId) + + val rooms = roomRepo.findByPropertyIdOrderByRoomNumber(propertyId) + val occupiedRoomIds = roomStayRepo.findOccupiedRoomIds(propertyId).toHashSet() + return rooms + .filter { it.active && !it.maintenance && !occupiedRoomIds.contains(it.id) } + .map { it.toRoomResponse() } + } + + @GetMapping("/by-type/{roomTypeCode}") + fun roomsByType( + @PathVariable propertyId: UUID, + @PathVariable roomTypeCode: String, + @AuthenticationPrincipal principal: MyPrincipal?, + @org.springframework.web.bind.annotation.RequestParam("availableOnly", required = false, defaultValue = "false") + availableOnly: Boolean + ): List { + requirePrincipal(principal) + propertyAccess.requireMember(propertyId, principal!!.userId) + + val roomType = roomTypeRepo.findByPropertyIdAndCodeIgnoreCase(propertyId, roomTypeCode) + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room type not found") + + val roles = propertyUserRepo.findRolesByPropertyAndUser(propertyId, principal.userId) + val rooms = roomRepo.findByPropertyIdOrderByRoomNumber(propertyId) + .filter { it.roomType.id == roomType.id } + + if (availableOnly || isAgentOnly(roles)) { + val occupiedRoomIds = roomStayRepo.findOccupiedRoomIds(propertyId).toHashSet() + return rooms + .filter { it.active && !it.maintenance && !occupiedRoomIds.contains(it.id) } + .map { it.toRoomResponse() } + } + return rooms.map { it.toRoomResponse() } + } + @GetMapping("/availability-range") fun roomAvailabilityRange( @PathVariable propertyId: UUID,