Skip to content

Commit

Permalink
Merge pull request #133 from Hoang-Nguyen-Huy/PBS-66-Manage-Room
Browse files Browse the repository at this point in the history
[PBS-66][HuyNBQ] feat: change api for get room for staff
  • Loading branch information
nguyenhcp2004 authored Oct 31, 2024
2 parents 10d596b + a95ff92 commit d9b64e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ ApiResponse<RoomResponse> createRoom(@RequestBody RoomCreationRequest request) {

@GetMapping
PaginationResponse<List<Room>> getRooms(@RequestParam(required = false) String searchParams,
@RequestParam(required = false,defaultValue = "0") int buildingId,
@RequestParam(defaultValue = "1", name = "page") int page,
@RequestParam(defaultValue = "10", name = "take") int take) {
RoomPaginationDTO dto = new RoomPaginationDTO(page, take);
Page<Room> roomPage = roomService.getRooms(searchParams, dto.page, dto.take);
Page<Room> roomPage = roomService.getRooms(buildingId,searchParams, dto.page, dto.take);

return PaginationResponse.<List<Room>>builder()
.data(roomPage.getContent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,13 @@ List<SlotDTO> getSlotsByRoomAndDate(@Param("roomId")Integer roomId,
@Query("SELECT r FROM Room r WHERE r.name LIKE %:searchParams% OR r.roomType.name LIKE %:searchParams% " +
"ORDER BY r.createdAt DESC")
Page<Room> findFilteredManagementRoom(@Param("searchParams") String searchParams, Pageable pageable);

@Query ("SELECT r FROM Room r " +
"JOIN r.roomType rt " +
"JOIN rt.building b " +
"WHERE b.id = :buildingId " +
"AND (r.name LIKE %:searchParams% OR r.roomType.name LIKE %:searchParams%) " +
"ORDER BY r.createdAt DESC")
Page<Room> findFilteredManagementRoomByBuildingId(@Param("buildingId") Integer buildingId,
@Param("searchParams") String searchParams, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ public RoomResponse createRoom(RoomCreationRequest request) {
/*
[GET]: /rooms/page&take
*/
public Page<Room> getRooms(String searchParams, int page, int take) {
public Page<Room> getRooms(int buildingId, String searchParams, int page, int take) {
Pageable pageable = PageRequest.of(page - 1, take);
return roomRepository.findFilteredManagementRoom(searchParams, pageable);
if(buildingId == 0) {
return roomRepository.findFilteredManagementRoom(searchParams, pageable);
}
return roomRepository.findFilteredManagementRoomByBuildingId(buildingId,searchParams, pageable);
}

public List<Room> getRoomsByType(int typeId) {
Expand Down

0 comments on commit d9b64e0

Please sign in to comment.