Skip to content

Commit

Permalink
#90 feat : MenuCategoryRepository를 생성한다
Browse files Browse the repository at this point in the history
  • Loading branch information
packdev937 committed Mar 4, 2024
1 parent 60ec083 commit 2ec85c6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,46 @@ public class LoadFixMenuRepository {

public List<BriefMenu> findBriefMenusByCategoryId(Long categoryId) {
return queryFactory
.select(Projections.constructor(BriefMenu.class,
menu.id,
menu.name,
menu.price))
.from(menu)
.join(menu.category, category)
.where(
menuCategoryIdEq(categoryId)
)
.orderBy(menu.name.asc())
.fetch();
.select(Projections.constructor(BriefMenu.class,
menu.id,
menu.name,
menu.price))
.from(menu)
.join(menu.category, category)
.where(
menuCategoryIdEq(categoryId)
)
.orderBy(menu.name.asc())
.fetch();
}

public boolean existsMenu(String name, Restaurant restaurant) {
return queryFactory
.select(menu.id)
.from(menu)
.where(
menuNameEq(name),
restaurantNameEq(restaurant)
)
.fetchFirst() != null;
.select(menu.id)
.from(menu)
.where(
menuNameEq(name),
restaurantNameEq(restaurant)
)
.fetchFirst() != null;
}

public Restaurant getRestaurant(Long menuId) {
return queryFactory
.select(menu.restaurant)
.from(menu)
.where(
menu.id.eq(menuId)
)
.fetchFirst();
.select(menu.restaurant)
.from(menu)
.where(
menu.id.eq(menuId)
)
.fetchFirst();
}

public List<MenuCategory> findMenuCategoriesByRestaurant(Restaurant restaurant) {
return queryFactory
.selectFrom(category)
.where(
categoryRestaurantNameEq(restaurant)
).fetch();
.selectFrom(category)
.where(
categoryRestaurantNameEq(restaurant)
).fetch();
}

private BooleanExpression menuNameEq(String menuName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ public class MenuCategory {
@Column(name = "menu_category_id")
private Long id;

private String name; // 여기에 카테고리가 들어가는건가?
private String name;

@Enumerated(EnumType.STRING)
private Restaurant restaurant;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ssu.eatssu.domain.menu.repository;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import ssu.eatssu.domain.menu.entity.MenuCategory;
import ssu.eatssu.domain.restaurant.entity.Restaurant;

public interface MenuCategoryRepository extends JpaRepository<MenuCategory, Long> {

List<MenuCategory> findAllByRestaurant(Restaurant restaurant);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ssu.eatssu.domain.restaurant.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.Arrays;
import lombok.Getter;

Expand Down

0 comments on commit 2ec85c6

Please sign in to comment.