Skip to content

Commit

Permalink
[#83] Feat : RestaurantType을 생성하고 RestaurantName에서 식단을 제공 하는 식당인지 고정 …
Browse files Browse the repository at this point in the history
…메뉴를 제공하는 식당인지 확인한다
  • Loading branch information
packdev937 committed Jan 15, 2024
1 parent 838938e commit 54eed6e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ssu.eatssu.domain.menu.exception;

public class RestaurantNotFoundException extends IllegalArgumentException {

public RestaurantNotFoundException() {
super("해당 식당이 존재하지 않습니다.");
}

public RestaurantNotFoundException(String s) {
super(s);
}

public RestaurantNotFoundException(String message, Throwable cause) {
super(message, cause);
}
}
4 changes: 2 additions & 2 deletions src/main/java/ssu/eatssu/domain/restaurant/Restaurant.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import lombok.NoArgsConstructor;

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

@Entity
@Getter
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/ssu/eatssu/domain/restaurant/RestaurantName.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
package ssu.eatssu.domain.restaurant;

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

import java.util.Locale;
import ssu.eatssu.domain.menu.exception.RestaurantNotFoundException;

@Getter
public enum RestaurantName {
DODAM("도담 식당", 6000),
DORMITORY("기숙사 식당", 5000),
FOOD_COURT("푸드 코트", 0),
SNACK_CORNER("스낵 코너", 0),
HAKSIK("학생 식당", 5000);
DODAM(RestaurantType.VARIABLE, "도담 식당", 6000),
DORMITORY(RestaurantType.VARIABLE, "기숙사 식당", 5000),
FOOD_COURT(RestaurantType.FIXED, "푸드 코트", 0),
SNACK_CORNER(RestaurantType.FIXED, "스낵 코너", 0),
HAKSIK(RestaurantType.VARIABLE, "학생 식당", 5000);

private RestaurantType restaurantType;
private String description;
private Integer price;

@JsonCreator
public static RestaurantName from(String description) {
return RestaurantName.valueOf(description.toUpperCase(Locale.ROOT));
return Arrays.stream(RestaurantName.values())
.filter(d -> d.getDescription().equals(description))
.findAny()
.orElseThrow(RestaurantNotFoundException::new);
}

RestaurantName(String description, Integer price) {
RestaurantName(RestaurantType restaurantType, String description, Integer price) {
this.restaurantType = restaurantType;
this.description = description;
this.price = price;
}

public static boolean isFixed(RestaurantName restaurantName) {
return restaurantName.getRestaurantType() == RestaurantType.FIXED;
}

public static boolean isVariable(RestaurantName restaurantName) {
return restaurantName.getRestaurantType() == RestaurantType.VARIABLE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ssu.eatssu.domain.restaurant;

public enum RestaurantType {
FIXED,
VARIABLE
}

0 comments on commit 54eed6e

Please sign in to comment.