Skip to content

Commit

Permalink
[#17] feature: Add custom query at DishRepository
Browse files Browse the repository at this point in the history
- DishRepository::findById, DishRepository::findAll 메소드를 오버라이드
  - 커스텀 쿼리를 사용하여, 클라이언트의 요청에 맞는 데이터(ItemDTO)를 추출
  • Loading branch information
jihye-woo committed Apr 22, 2021
1 parent 2962327 commit d1532bc
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
import java.util.List;
import java.util.Optional;

public interface DishRepository extends CrudRepository<Dish, String> {
Optional<Dish> findById(String hash);
//List<Dish> findAllBySectionName(String sectionName);
public interface DishRepository extends CrudRepository<ItemDTO, String> {

@Query("SELECT di.`hash` AS `detail_hash`, di.`top_image` AS `image`, di.`title` AS `alt`, de.`delivery_type`, di.`title`, di.`description`, di.`n_price`, di.`s_price`, e.`badge` from dish di JOIN delivery de on di.`hash` = de.`dish_hash` LEFT OUTER JOIN `event` e on e.`dish_hash` = di.`hash` where e.`dish_hash`=:hash")
@Override
Optional<ItemDTO> findById(String hash);

@Query("select di.`hash` AS `detail_hash`, di.`top_image` AS `image`, di.`title` AS `alt`, de.`delivery_type`, di.`title`, di.`description`, di.`n_price`, di.`s_price`, e.`badge` from dish di JOIN delivery de on di.`hash` = de.`dish_hash` LEFT OUTER JOIN `event` e on e.`dish_hash` = di.`hash`")
@Override
List<ItemDTO> findAll();

}

0 comments on commit d1532bc

Please sign in to comment.