Skip to content

Commit

Permalink
[#83] test : 식당 이름으로 고정 메뉴 조회를 테스트 한다
Browse files Browse the repository at this point in the history
  • Loading branch information
packdev937 committed Jan 18, 2024
1 parent 2cd2361 commit 65720be
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ssu/eatssu/domain/menu/dto/MenuResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static MealInformationResponse from(Meal meal) {
.map(BriefMenuInformation::new).toList();

return new MealInformationResponse(meal.getId(),
meal.getRestaurant().getRestaurantName().getPrice(),
meal.getRestaurant().getRestaurantPrice(),
meal.getAverateMainRating(), menusInformation);
} else {
return null;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/ssu/eatssu/domain/menu/entity/Meal.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import ssu.eatssu.domain.restaurant.entity.Restaurant;
import ssu.eatssu.domain.restaurant.entity.TemporalRestaurant;

import java.util.*;

@Entity
Expand Down
21 changes: 3 additions & 18 deletions src/main/java/ssu/eatssu/domain/menu/entity/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.persistence.*;
import lombok.*;
import ssu.eatssu.domain.restaurant.entity.Restaurant;
import ssu.eatssu.domain.restaurant.entity.TemporalRestaurant;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -24,13 +23,12 @@ public class Menu {

private Integer price;

@Enumerated(EnumType.STRING)
private MenuType menuType;
// @Enumerated(EnumType.STRING)
// private MenuType menuType;

@OneToMany(mappedBy = "menu", cascade = CascadeType.ALL)
private List<MealMenu> mealMenus = new ArrayList<>();

@Embedded
private Restaurant restaurant;

@Embedded
Expand All @@ -42,27 +40,14 @@ private Menu(String name, Restaurant restaurant, Integer price) {
this.price = price;
}

private Menu(String name, Integer price) {
this.name = name;
this.price = price;
}

/**
* 변동 메뉴를 생성합니다.
* todo: 변동메뉴 식당이 아니라 고정 메뉴 식당으로 잘못 들어온다면 어떻게 처리?
*/
public static Menu createVariable(String name, Restaurant restaurant) {
int price = 0;
if (restaurant.isVariable()) {
price = restaurant.getPrice();
price = restaurant.getRestaurantPrice();
}
return new Menu(name, restaurant, price);
}

/**
* 고정 메뉴를 생성합니다.
* todo: 고정메뉴 식당이 아니라 변동 메뉴 식당으로 잘못 들어온다면 어떻게 처리?
*/
public static Menu createFixed(String name, Restaurant restaurant, Integer price) {
return new Menu(name, restaurant, price);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public class MenuController {
})
@GetMapping("")
public BaseResponse<List<MenuInformationResponse>> getMenus(
@RequestParam("restaurant") Restaurant restaurantName) {
if (restaurantName.isVariable()) {
@RequestParam("restaurant") Restaurant restaurant) {
if (restaurant.isVariable()) {
throw new BaseException(NOT_SUPPORT_RESTAURANT);
}
return BaseResponse.success(menuService.findMenusByRestaurant(restaurantName));
return BaseResponse.success(menuService.findMenusByRestaurant(restaurant));
}

@Operation(summary = "메뉴 정보 리스트 조회", description = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.springframework.data.jpa.repository.JpaRepository;
import ssu.eatssu.domain.menu.entity.Meal;
import ssu.eatssu.domain.restaurant.entity.Restaurant;
import ssu.eatssu.domain.restaurant.entity.TemporalRestaurant;
import ssu.eatssu.domain.menu.entity.TimePart;

import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.springframework.data.jpa.repository.JpaRepository;
import ssu.eatssu.domain.menu.entity.Menu;
import ssu.eatssu.domain.restaurant.entity.Restaurant;
import ssu.eatssu.domain.restaurant.entity.TemporalRestaurant;

import java.util.List;
import java.util.Optional;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/ssu/eatssu/domain/menu/service/MenuService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
import ssu.eatssu.domain.menu.entity.MealMenu;
import ssu.eatssu.domain.menu.entity.Menu;
import ssu.eatssu.domain.restaurant.entity.Restaurant;
import ssu.eatssu.domain.restaurant.entity.TemporalRestaurant;
import ssu.eatssu.domain.menu.entity.TimePart;
import ssu.eatssu.domain.menu.repository.MealMenuRepository;
import ssu.eatssu.domain.menu.repository.MealRepository;
import ssu.eatssu.domain.menu.repository.MenuRepository;
import ssu.eatssu.domain.restaurant.repository.RestaurantRepository;
import ssu.eatssu.global.handler.response.BaseException;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ssu.eatssu.global.handler.response.BaseException;
import ssu.eatssu.global.handler.response.BaseResponseStatus;


@Getter
public enum Restaurant {
DODAM(RestaurantType.VARIABLE, "도담 식당", 6000),
Expand All @@ -17,7 +18,7 @@ public enum Restaurant {

private RestaurantType restaurantType;
private String restaurantName;
private Integer price;
private Integer restaurantPrice;

@JsonCreator
public static Restaurant from(String restaurantName) {
Expand All @@ -30,7 +31,7 @@ public static Restaurant from(String restaurantName) {
Restaurant(RestaurantType restaurantType, String description, Integer price) {
this.restaurantType = restaurantType;
this.restaurantName = description;
this.price = price;
this.restaurantPrice = price;
}

public boolean isFixed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package ssu.eatssu.domain.restaurant.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;
import ssu.eatssu.domain.menu.entity.Meal;
import ssu.eatssu.domain.menu.entity.Menu;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class TemporalRestaurant {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "restaurant_id")
private Long id;

@Enumerated(EnumType.STRING)
private Restaurant restaurantName;

@OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL)
private List<Menu> menus;

@OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL)
private List<Meal> meals;
}
//package ssu.eatssu.domain.restaurant.entity;
//
//import jakarta.persistence.*;
//import lombok.AccessLevel;
//import lombok.Getter;
//import lombok.NoArgsConstructor;
//
//import java.util.List;
//import ssu.eatssu.domain.menu.entity.Meal;
//import ssu.eatssu.domain.menu.entity.Menu;
//
//@Entity
//@Getter
//@NoArgsConstructor(access = AccessLevel.PROTECTED)
//public class TemporalRestaurant {
//
// @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
// @Column(name = "restaurant_id")
// private Long id;
//
// @Enumerated(EnumType.STRING)
// private Restaurant restaurantName;
//
// @OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL)
// private List<Menu> menus;
//
// @OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL)
// private List<Meal> meals;
//}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ssu.eatssu.domain.restaurant.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import ssu.eatssu.domain.restaurant.entity.Restaurant;
import ssu.eatssu.domain.restaurant.entity.TemporalRestaurant;

import java.util.Optional;

public interface RestaurantRepository extends JpaRepository<TemporalRestaurant, Long> {

Optional<TemporalRestaurant> findByRestaurantName(Restaurant restaurantName);

}
//package ssu.eatssu.domain.restaurant.repository;
//
//import org.springframework.data.jpa.repository.JpaRepository;
//import ssu.eatssu.domain.restaurant.entity.Restaurant;
//import ssu.eatssu.domain.restaurant.entity.TemporalRestaurant;
//
//import java.util.Optional;
//
//public interface RestaurantRepository extends JpaRepository<TemporalRestaurant, Long> {
//
// Optional<TemporalRestaurant> findByRestaurantName(Restaurant restaurantName);
//
//}
38 changes: 38 additions & 0 deletions src/test/java/ssu/eatssu/domain/menu/service/MenuServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ssu.eatssu.domain.menu.service;

import java.util.ArrayList;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import ssu.eatssu.domain.menu.dto.MenuResponse.MenuInformationResponse;
import ssu.eatssu.domain.menu.entity.Menu;
import ssu.eatssu.domain.menu.repository.MenuRepository;
import ssu.eatssu.domain.restaurant.entity.Restaurant;

@SpringBootTest
class MenuServiceTest {

@Autowired
private MenuService menuService;

@Autowired
private MenuRepository menuRepository;

@Test
void 식당_이름으로_고정_메뉴를_조회한다() {
// given
List<Menu> menus = new ArrayList<>();
Restaurant foodCourt = Restaurant.from("푸드 코트");
menus.add(Menu.createFixed("라면", foodCourt, 3000));
menus.add(Menu.createFixed("떡볶이", foodCourt, 5000));
menus.add(Menu.createFixed("짜게치", foodCourt, 4000));
menuRepository.saveAll(menus);

// when & then
Assertions.assertThat(menuService.findMenusByRestaurant(foodCourt))
.extracting(MenuInformationResponse::getName)
.containsExactly("라면", "떡볶이", "짜게치");
}
}

0 comments on commit 65720be

Please sign in to comment.