Project/MangoPlate Clone

리뷰 및 메뉴 페이징 목록 구현

혀눅짱 2023. 2. 27. 15:45

특정 식당의 리뷰 및 메뉴 목록을 페이징으로 구현하는 api를 만드는데

 

이건그냥 해당 식당 id를 파라미터로 넘겨서 셀렉트하면 되는 부분이라 딱히 동적쿼리가 들어갈것도없기 때문에 querydsl이 아닌 그냥

data-jpa로 처리하면 된다.

 

@Query(value = "select f from Food f where f.restaurant.id =:restaurantId order by f.price asc",
        countQuery = "select count(f) from Food f where f.restaurant.id =:restaurantId")
Page<Food> getFoodList(@Param("restaurantId") Long restaurantId, Pageable pageable);

 

@Query( value = "select rv from Review rv where rv.restaurant.id =:restaurantId order by rv.id desc",
        countQuery = "select count(rv) from Review rv where rv.restaurant.id =:restaurantId")
Page<Review> getReviewList(@Param("restaurantId") Long restaurantId, Pageable pageable);

 

그냥 해당조건에 맞는 쿼리를 작성하고 그에 해당하는 카운트쿼리를 명시하면 data-jpa가 알아서 페이징처리를 해준다.

 

pageable은 서비스 레이어에서 직접 PageRequest 객체를 생성해서 넘겨준다.

 

대충 이제 인증없이 조회가능한 api는 러프하게는 다 만들어진것같다.

 

이제 인증에 필요한 시큐리티 및 jwt설정을 해야겠다. 끝