-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from Hoang-Nguyen-Huy/refactor/PBS-36/room-typ…
…e-filter [PBS-40][HoangHN] feat: 🍑 get filtered room types
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/main/java/com/swp/PodBookingSystem/repository/RoomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/swp/PodBookingSystem/repository/RoomTypeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
package com.swp.PodBookingSystem.repository; | ||
|
||
import com.swp.PodBookingSystem.entity.RoomType; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public interface RoomTypeRepository extends JpaRepository<RoomType, Integer> { | ||
@Query("SELECT rt FROM RoomType rt " + | ||
"JOIN rt.building b " + | ||
"LEFT JOIN Room r ON r.roomType.id = rt.id " + | ||
"LEFT JOIN OrderDetail od ON r.id = od.room.id " + | ||
"WHERE (:address IS NULL OR b.address LIKE %:address%) " + | ||
"AND (:capacity IS NULL OR rt.capacity = :capacity) " + | ||
"AND ((:startTime IS NULL AND :endTime IS NULL) " + | ||
" OR NOT EXISTS (SELECT 1 FROM OrderDetail od2 " + | ||
" WHERE od2.room.id = r.id " + | ||
" AND ((od2.startTime BETWEEN :startTime AND :endTime) " + | ||
" OR (od2.endTime BETWEEN :startTime AND :endTime)))) " + | ||
"GROUP BY rt.id " + | ||
"HAVING (:startTime IS NOT NULL AND :endTime IS NOT NULL AND COUNT(r.id) >= 1) " + | ||
" OR (:startTime IS NULL AND :endTime IS NULL)") | ||
Page<RoomType> findFilteredRoomTypes(@Param("address") String address, | ||
@Param("capacity") Integer capacity, | ||
@Param("startTime") LocalDateTime startTime, | ||
@Param("endTime") LocalDateTime endTime, | ||
Pageable pageable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters