Add available rooms and room type room list endpoints
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:
@@ -127,6 +127,48 @@ class Rooms(
|
||||
}.sortedBy { it.roomTypeName }
|
||||
}
|
||||
|
||||
@GetMapping("/available")
|
||||
fun availableRooms(
|
||||
@PathVariable propertyId: UUID,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?
|
||||
): List<RoomResponse> {
|
||||
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<RoomResponse> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user