-
Notifications
You must be signed in to change notification settings - Fork 5
[크리스마스이벤트] 박진현 리뷰용 PR #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
이름, 카테고리, 금액을 저장
크리스마스 디데이 , 평일, 주말, 특별할인
Dompoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다! 스터디에서 봬요!
| if (orderItems.stream().anyMatch(item -> item.getMenu().getCategory().equals("음료") && orderItems.size() == 1)) { | ||
| throw new IllegalArgumentException("[ERROR] 음료만 주문할 수 없습니다."); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음료를 1개만 주문했을 때는 잘 걸릴 것 같은데, 음료만 2개 주문하면 통과될 것 같아요!
| CHAMPAGNE("샴페인", "음료", BigDecimal.valueOf(25_000)); | ||
|
|
||
| private final String name; | ||
| private final String category; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
카테고리는 분류가 정해져있으니까, Enum으로 관리하면 더 좋을 것 같아요!
| public BigDecimal applyDiscount(Order order, int date) { | ||
| if (date >= 1 && date <= 25) { | ||
| BigDecimal discountAmount = BigDecimal.valueOf(1000 + (date - 1) * 100); | ||
| return discountAmount.min(order.getTotalPriceBeforeDiscount()); | ||
| } | ||
| return BigDecimal.ZERO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어디서 봤는지 기억은 안나는데, 이런 if 구조에서
1~25일 사이인게 메인이잖아요? 그러면 그 외의 것을 if문 안에 넣어서 탈출시키는 방식으로 주요 코드를 indent 1에 계속 두는 것이 더 읽기 좋은 코드를 짠다고 들은 적이 있어요.
if (date < 1 || date > 25) {
return BigDecimal.ZERO;
}
BigDecimal discountAmount = BigDecimal.valueOf(1000 + (date - 1) * 100);
return discountAmount.min(order.getTotalPriceBeforeDiscount());그래야 if문이 많이 중첩되는 경우에도 흐름을 따라가기 쉽다고 하더라고요!
| private static final int GIFT_THRESHOLD = 120_000; | ||
|
|
||
| public Menu checkGiftEligibility(Order order) { | ||
| if (order.getTotalPriceBeforeDiscount().compareTo(new java.math.BigDecimal(GIFT_THRESHOLD)) >= 0) { | ||
| return Menu.CHAMPAGNE; | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gift도 DiscountPolicy처럼 관리했으면 더 좋았을 것 같아요!
지금은 너무 하드코딩 되어서 나중에 다른 Gift를 추가하고 싶어도 고칠 것이 많아 보입니닷.
| private Badge assignBadge(BigDecimal totalDiscount, Menu gift) { | ||
| BigDecimal totalBenefit = totalDiscount; | ||
| if (gift != null) { | ||
| totalBenefit = totalBenefit.add(gift.getPrice()); | ||
| } | ||
|
|
||
| if (totalBenefit.compareTo(new BigDecimal("20000")) >= 0) { | ||
| return Badge.SANTA; | ||
| } | ||
| if (totalBenefit.compareTo(new BigDecimal("10000")) >= 0) { | ||
| return Badge.TREE; | ||
| } | ||
| if (totalBenefit.compareTo(new BigDecimal("5000")) >= 0) { | ||
| return Badge.STAR; | ||
| } | ||
| return Badge.NONE; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요 로직은 Badge의 내부 구현이라고 생각해서, Badge가 직접 처리해도 좋을 것 같은데, 어떻게 생각하시나요?
| public String readDate() { | ||
| System.out.println("안녕하세요! 우테코 식당 12월 이벤트 플래너입니다."); | ||
| System.out.println("12월 중 식당 예상 방문 날짜는 언제인가요? (숫자만 입력해 주세요!)"); | ||
| return Console.readLine(); | ||
| } | ||
| public String readOrder() { | ||
| System.out.println("주문하실 메뉴와 개수를 입력해 주세요. (e.g. 해산물파스타-2,레드와인-1,초코케이크-1)"); | ||
| return Console.readLine(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요구사항을 잘 보시면, 1월에도 이벤트를 계속 진행할 것 처럼 적혀있어요.
12월로 하드코딩하지 않고, 값을 외부에서 주입받도록 하는 것이 좋아 보입니다!
No description provided.