Skip to content

Commit

Permalink
Merge pull request #130 from Hoang-Nguyen-Huy/PBS-66-Manage-Room
Browse files Browse the repository at this point in the history
[PBS-66][HuyNBQ] feat: finish get roomtype by building id
  • Loading branch information
nguyenhcp2004 authored Oct 31, 2024
2 parents 3565763 + 442886c commit 1925898
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ ApiResponse<List<RoomType>> getRoomTypeByBuildingAddress(@RequestParam (required
.data(roomTypeResponse)
.build();
}
@GetMapping("/get-by-building-id")
ApiResponse<List<RoomType>> getRoomTypeByBuildingId(@RequestParam (required = false) Integer buildingId) {
List<RoomType> roomTypeResponse = roomTypeService.getRoomTypeByBuildingId(buildingId);
return ApiResponse.<List<RoomType>>builder()
.message("Lấy loại phòng theo id chi nhánh thành công")
.data(roomTypeResponse)
.build();
}

@PutMapping("/{roomTypeId}")
ApiResponse<RoomTypeResponse> updatedRoomType(@PathVariable("roomTypeId") int roomTypeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ Page<RoomType> findFilteredRoomTypes(@Param("address") String address,
"FROM RoomType rt " +
"WHERE rt.building.address = :buildingAddress")
List<RoomType> findByBuildingAddress(String buildingAddress);

@Query("SELECT rt " +
"FROM RoomType rt " +
"WHERE rt.building.id = :buildingId")
List<RoomType> findByBuildingId(Integer buildingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@ public String deleteRoomType(int roomTypeId) {
roomTypeRepository.deleteById(roomTypeId);
return "Delete room type " + roomTypeId + " successfully";
}

public List<RoomType> getRoomTypeByBuildingId(Integer buildingId) {
if (buildingId == null) {
return roomTypeRepository.findAll();
}
return roomTypeRepository.findByBuildingId(buildingId);
}
}

0 comments on commit 1925898

Please sign in to comment.