-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#83] refactor : Restaurant Entity를 Enum 클래스로 변경한다
- Loading branch information
1 parent
8bdb950
commit 2cd2361
Showing
13 changed files
with
101 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 32 additions & 18 deletions
50
src/main/java/ssu/eatssu/domain/restaurant/entity/Restaurant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
package ssu.eatssu.domain.restaurant.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import java.util.Arrays; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import ssu.eatssu.domain.menu.entity.Meal; | ||
import ssu.eatssu.domain.menu.entity.Menu; | ||
import ssu.eatssu.global.handler.response.BaseException; | ||
import ssu.eatssu.global.handler.response.BaseResponseStatus; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Restaurant { | ||
public enum Restaurant { | ||
DODAM(RestaurantType.VARIABLE, "도담 식당", 6000), | ||
DORMITORY(RestaurantType.VARIABLE, "기숙사 식당", 5000), | ||
FOOD_COURT(RestaurantType.FIXED, "푸드 코트", null), | ||
SNACK_CORNER(RestaurantType.FIXED, "스낵 코너", null), | ||
HAKSIK(RestaurantType.VARIABLE, "학생 식당", 5000); | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "restaurant_id") | ||
private Long id; | ||
private RestaurantType restaurantType; | ||
private String restaurantName; | ||
private Integer price; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private RestaurantName restaurantName; | ||
@JsonCreator | ||
public static Restaurant from(String restaurantName) { | ||
return Arrays.stream(Restaurant.values()) | ||
.filter(r -> r.getRestaurantName().equals(restaurantName)) | ||
.findAny() | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.NOT_FOUND_RESTAURANT)); | ||
} | ||
|
||
@OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL) | ||
private List<Menu> menus; | ||
Restaurant(RestaurantType restaurantType, String description, Integer price) { | ||
this.restaurantType = restaurantType; | ||
this.restaurantName = description; | ||
this.price = price; | ||
} | ||
|
||
@OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL) | ||
private List<Meal> meals; | ||
public boolean isFixed() { | ||
return this.restaurantType == RestaurantType.FIXED; | ||
} | ||
|
||
public boolean isVariable() { | ||
return this.restaurantType == RestaurantType.VARIABLE; | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
src/main/java/ssu/eatssu/domain/restaurant/entity/RestaurantName.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.