code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,57 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.dto.OrderDTO;
+import christmas.util.IntParser;
+import christmas.util.OrderParser;
+import christmas.util.RetryExecutor;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.List;
+
+public class EventController {
+ private Bill bill;
+ private EventHandler eventHandler;
+ private final InputView inputView;
+ private final OutputView outputView;
+
+ public EventController(InputView inputView, OutputView outputView) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ }
+
+ public void run() {
+ outputView.printHelloMessage();
+ RetryExecutor.execute(this::setBill, outputView::printErrorMessage);
+ RetryExecutor.execute(this::setOrder, error -> {
+ outputView.printErrorMessage(error);
+ bill.clearOrder();
+ });
+ printResult();
+ }
+
+ private void setBill() {
+ String input = inputView.inputDate().trim();
+ bill = Bill.from(IntParser.parseIntOrThrow(input));
+ eventHandler = EventHandler.from(bill);
+ }
+
+ private void setOrder() {
+ String input = inputView.inputOrder();
+ List<OrderDTO> orders = OrderParser.parseOrderOrThrow(input);
+ orders.forEach(it -> bill.add(Order.create(it.menuName(), it.count())));
+ bill.validateOnlyDrink();
+ }
+
+ private void printResult() {
+ outputView.printEventPreviewTitle(bill.getDateValue());
+ outputView.printOrder(bill.getAllOrders());
+ outputView.printTotalPrice(bill.getTotalPrice());
+ outputView.printGift(eventHandler.hasChampagneGift());
+ outputView.printAllBenefit(eventHandler.getAllBenefit());
+ outputView.printBenefitPrice(eventHandler.getTotalBenefitPrice());
+ outputView.printAfterDiscountPrice(bill.getTotalPrice() - eventHandler.getTotalDiscountPrice());
+ outputView.printBadge(Badge.getBadgeNameWithBenefitPrice(eventHandler.getTotalBenefitPrice()));
+ }
+} | Java | ์ ๋ ํจ์ํ ์ธํฐํ์ด์ค๋ผ๋ ๊ฑธ ์ฒ์ ์จ๋ดค๋ต๋๋ค! 3์ฃผ์ฐจ ์ฝ๋๋ฆฌ๋ทฐ๋ฅผ ํ๋ฉด์ ์ด๊นจ๋๋จธ๋ก ๋ฐฐ์ด๊ฑฐ๋ผ, @HongYeseul ๋๋ ์ด๋ฒ ์ฝ๋๋ฆฌ๋ทฐ๋ฅผ ๊ธฐํ๋ก ํ๋ฒ ๊ณต๋ถํด๋ณด์๋๊ฑด ์ด๋จ๊น์? ๐ |
@@ -0,0 +1,26 @@
+package christmas.domain;
+
+import java.util.Arrays;
+
+public enum Badge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NOTHING("์์", 0);
+
+ private final String badgeName;
+ private final int threshold;
+
+ Badge(String badgeName, int threshold) {
+ this.badgeName = badgeName;
+ this.threshold = threshold;
+ }
+
+ public static String getBadgeNameWithBenefitPrice(int benefitPrice) {
+ return Arrays.stream(Badge.values())
+ .filter(it -> it.threshold <= benefitPrice)
+ .map(it -> it.badgeName)
+ .findFirst()
+ .orElse(NOTHING.badgeName);
+ }
+} | Java | ์ ๋ง ๋๋๊ฒ๋ ์ ๋ 1์ฃผ์ฐจ์ 2์ฃผ์ฐจ ์ฝ๋ ๋ฆฌ๋ทฐ๋ฅผ ํ๋ฉด์ ๋๋ถ๋ถ์ ๋ฆฌ๋ทฐ์ `stream`์ฌ์ฉ์ ์ ํ์๋๊ฒ ๋ถ๋ฝ๋ค! ๋ผ๋์์ผ๋ก ๋ง์ด ๋ฆฌ๋ทฐ๋ฅผ ๋จ๊ธฐ๊ณ ๋ค๋
์ด์. ๊ทธ๋ ๊ฒ ๋ง์ ๋ถ๋ค์ ์ฝ๋๋ฅผ ๋ณด๋ฉด์ `stream`๊ณผ ์ ์ ์น์ํด์ง๋ค ๋ณด๋ ์ ๋ `stream`์ ํ๋ฒ ์จ๋ณผ๊น? ๋ผ๋ ์๊ฐ์ด ๋ค์๊ณ , ๊ทธ๋ ๊ฒ ์ ์ ์ต์ํด์ง ๊ฒ ๊ฐ์์! ๐
4์ฃผ์ฐจ๊ฐ ๋๋ ์ง๊ธ์ ํ๊ต ๋์๊ด์์ '์ด๊ฒ์ด ์๋ฐ๋ค'๋ผ๋ ์ฑ
์ ๋น๋ ค์ ์ฝ๊ณ ์์ด์. ์๋ฐ์ ์ต์ํด์ง๊ธด ํ์ง๋ง, ๊ทธ๋๋ ์ปฌ๋ ์
์ด๋ ์คํธ๋ฆผ๊ณผ ๊ฐ์ ๋ถ๋ถ์ ์ ๋๋ก ๊ณต๋ถํ๊ณ ์ถ์ด์์. ์ด๋ฐ ์๋ฐ ์์ ์ ํ๋ ์ ํ์
์ ๊ธฐ๋ณธ ๋ฌธ๋ฒ์ ์ ๋ฆฌํ์๋ ์๊ฐ์ ๊ฐ์ง๋ ๊ฒ๋ ์ข์๋ณด์
๋๋ค! ๐ |
@@ -0,0 +1,38 @@
+package christmas.util;
+
+import christmas.config.ErrorMessage;
+
+public class IntParser {
+ private static final int MAX_STRING_LENGTH = 11;
+
+ private IntParser() {
+ // ์ธ์คํด์ค ์์ฑ ๋ฐฉ์ง
+ }
+
+ public static int parseIntOrThrow(String numeric) {
+ validateNumericStringLength(numeric);
+ long parsed = parseLongOrThrow(numeric);
+ validateIntRange(parsed);
+ return Integer.parseInt(numeric);
+ }
+
+ private static long parseLongOrThrow(String numeric) {
+ try {
+ return Long.parseLong(numeric);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage());
+ }
+ }
+
+ private static void validateNumericStringLength(String numeric) {
+ if (numeric.length() > MAX_STRING_LENGTH) {
+ throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage());
+ }
+ }
+
+ private static void validateIntRange(long number) {
+ if (number > Integer.MAX_VALUE || number < Integer.MIN_VALUE) {
+ throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage());
+ }
+ }
+} | Java | ๋ชจ๋ ๋ฉ์๋๊ฐ `static`์ธ ์ ํธ๋ฆฌํฐ์ฑ ํด๋์ค์ ๊ฒฝ์ฐ `new` ํค์๋๋ฅผ ์ฌ์ฉํด ๊ฐ์ฒด๋ฅผ ์์ฑํ ํ์๊ฐ ์ ํ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค. ๊ทธ๋์ ํน์๋ผ๋ ์๋์น ์๊ฒ ๊ฐ์ฒด๊ฐ ์์ฑ๋ ๊ฒฝ์ฐ๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด ์์ฑ์๋ฅผ `private`์ผ๋ก ์ ์ธํ๊ณ , ๋น ์์ฑ์๋ก ๊ทธ๋ฅ ๋๊ธด ์ข ๋ฐ๋ฐํด์ ์ฃผ์์ ์ด์ง ๋ฌ์๋ดค์ต๋๋ค! ๐ |
@@ -0,0 +1,91 @@
+package christmas.view;
+
+import christmas.dto.BenefitDTO;
+import christmas.dto.OrderDTO;
+
+import java.util.List;
+
+public class OutputView {
+ private void printMessage(ViewMessage message) {
+ System.out.println(message.getMessage());
+ }
+
+ private void printFormat(ViewMessage message, Object... args) {
+ System.out.printf(message.getMessage(), args);
+ newLine();
+ }
+
+ private void printTitle(ViewTitle title) {
+ System.out.println(title.getTitle());
+ }
+
+ public void printHelloMessage() {
+ printMessage(ViewMessage.HELLO);
+ }
+
+ public void printEventPreviewTitle(int date) {
+ printFormat(ViewMessage.EVENT_PREVIEW_TITLE, date);
+ newLine();
+ }
+
+ public void printOrder(List<OrderDTO> orders) {
+ printTitle(ViewTitle.ORDER_MENU);
+ orders.forEach(it -> printFormat(ViewMessage.ORDER_FORMAT, it.menuName(), it.count()));
+ newLine();
+ }
+
+ public void printTotalPrice(int price) {
+ printTitle(ViewTitle.TOTAL_PRICE);
+ printFormat(ViewMessage.PRICE_FORMAT, price);
+ newLine();
+ }
+
+ public void printGift(boolean hasGift) {
+ printTitle(ViewTitle.GIFT_MENU);
+ if (hasGift) {
+ printMessage(ViewMessage.CHAMPAGNE);
+ newLine();
+ return;
+ }
+ printMessage(ViewMessage.NOTHING);
+ newLine();
+ }
+
+ public void printAllBenefit(List<BenefitDTO> benefits) {
+ printTitle(ViewTitle.BENEFIT_LIST);
+ if (benefits.isEmpty()) {
+ printMessage(ViewMessage.NOTHING);
+ newLine();
+ return;
+ }
+ benefits.forEach(it -> printFormat(ViewMessage.BENEFIT_FORMAT, it.EventName(), it.price()));
+ newLine();
+ }
+
+ public void printBenefitPrice(int price) {
+ printTitle(ViewTitle.BENEFIT_PRICE);
+ printFormat(ViewMessage.PRICE_FORMAT, -price);
+ newLine();
+ }
+
+ public void printAfterDiscountPrice(int price) {
+ printTitle(ViewTitle.AFTER_DISCOUNT_PRICE);
+ printFormat(ViewMessage.PRICE_FORMAT, price);
+ newLine();
+ }
+
+ public void printBadge(String badge) {
+ printTitle(ViewTitle.BADGE);
+ System.out.println(badge);
+ }
+
+ public void printErrorMessage(IllegalArgumentException error) {
+ newLine();
+ System.out.println(error.getMessage());
+ newLine();
+ }
+
+ public void newLine() {
+ System.out.println();
+ }
+} | Java | ์ข์ ์ง์ ๊ฐ์ฌํฉ๋๋ค! `lineSeperator()`์ ๋ํด์ ๊ณต๋ถํด๋ด์ผ๊ฒ ๋ค์! ๐ |
@@ -0,0 +1,94 @@
+package christmas.domain;
+
+import christmas.config.Constant;
+import christmas.dto.OrderDTO;
+import christmas.config.ErrorMessage;
+import christmas.config.MenuType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Bill implements CheckEventDate {
+ private final List<Order> orders = new ArrayList<>();
+ private final Date date;
+
+ private Bill(Date date) {
+ this.date = date;
+ }
+
+ public static Bill from(int date) {
+ return new Bill(Date.from(date));
+ }
+
+ public Bill add(Order order) {
+ validateDuplicates(order);
+ orders.add(order);
+ validateMaxOrder();
+ return this;
+ }
+
+ private void validateDuplicates(Order newOrder) {
+ long duplicated = orders.stream()
+ .filter(it -> it.isSameMenu(newOrder))
+ .count();
+ if (duplicated != Constant.FILTER_CONDITION) {
+ throw new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage());
+ }
+ }
+
+ private void validateMaxOrder() {
+ if (Order.accumulateCount(orders) > Constant.MAX_ORDER) {
+ throw new IllegalArgumentException(ErrorMessage.OVER_MAX_ORDER.getMessage());
+ }
+ }
+
+ public void validateOnlyDrink() {
+ if (Order.accumulateCount(orders) == getTypeCount(MenuType.DRINK)) {
+ throw new IllegalArgumentException(ErrorMessage.ONLY_DRINK_ORDER.getMessage());
+ }
+ }
+
+ public void clearOrder() {
+ orders.clear();
+ }
+
+ public int getTotalPrice() {
+ return orders.stream()
+ .map(Order::getPrice)
+ .reduce(Constant.INIT_VALUE, Integer::sum);
+ }
+
+ public int getTypeCount(MenuType type) {
+ return Order.accumulateCount(orders, type);
+ }
+
+ public List<OrderDTO> getAllOrders() {
+ return orders.stream().map(Order::getOrder).toList();
+ }
+
+ // ์๋๋ Date ๊ด๋ จ method
+
+ @Override
+ public boolean isWeekend() {
+ return date.isWeekend();
+ }
+
+ @Override
+ public boolean isSpecialDay() {
+ return date.isSpecialDay();
+ }
+
+ @Override
+ public boolean isNotPassedChristmas() {
+ return date.isNotPassedChristmas();
+ }
+
+ @Override
+ public int timePassedSinceFirstDay() {
+ return date.timePassedSinceFirstDay();
+ }
+
+ public int getDateValue() {
+ return date.getDateValue();
+ }
+} | Java | ๊ทธ๋ ๊ฒ๋ ํ ์ ์๊ฒ ๋ค์! ์์ `Orders`๋ผ๋ ํด๋์ค๋ฅผ ๋ง๋ค์ด ๋ฆฌ์คํธ๋ฅผ ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ๋ ์ข์๋ณด์
๋๋ค!
๋ฆฌํฉํ ๋ง ํ ๋งํ ๋ถ๋ถ๋ค์ ์ง์ด์ฃผ์
์ ์ข์ต๋๋ค!! ๐ |
@@ -0,0 +1,456 @@
+# ์ด๋ฉ์ผ ๋ต์ฅ
+
+> ์ ๋ชฉ: 12์ ์ด๋ฒคํธ ๊ฐ๋ฐ ๋ณด๊ณ
+
+> ๋ณด๋ธ ์ฌ๋: ๊ฐ๋ฐํ <`dev@woowacourse.io`>
+>
+> ๋ฐ๋ ์ฌ๋: ๋น์ฆ๋์คํ <`biz@woowacourse.io`>
+
+์๋
ํ์ธ์. ๊ฐ๋ฐํ์
๋๋ค!
+
+12์ ์ด๋ฒคํธ ํ๋๋ ๊ฐ๋ฐ ์์ฒญ ์ฌํญ์ ์ ๋ฐ์ ๋ณด์์ต๋๋ค.
+์์ฒญํ์ ๋ด์ฉ๋ค์ ๋ชจ๋ ์ ์ฉํด๋ณด์๋๋ฐ์. ํน์ ๋๋ฝ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด ๋ฐ๋ก ๋ง์ํด์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.
+
+#### ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ
+
+- ๋ฐฉ๋ฌธ ๋ ์ง๋ 1 ์ด์ 31 ์ดํ์ ์ซ์๋ก๋ง ์
๋ ฅ๋ฐ๊ฒ ํ์ต๋๋ค.
+- ๋จ, ์ฌ์ฉ์์ ๋ถ์ฃผ์๋ก ์
๋ ฅ ์๋ค๋ก ๊ณต๋ฐฑ์ด ์๊ธฐ๋ ๊ฒฝ์ฐ๊ฐ ์ข
์ข
์๋๋ฐ, ์ด๋ ํ๋ก๊ทธ๋จ ๋ด๋ถ์์ ์๋ ์ฒ๋ฆฌํ๊ฒ ํ์ต๋๋ค.
+ - " 12 " (O)
+ - " 1 2" (X)
+- ์ด์ธ์ ๋ชจ๋ ์๋ชป๋ ์
๋ ฅ์ ์์ฒญํ์ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ์๋ฌ ๋ฉ์์ง๊ฐ ๋์จ ๋ค์์๋ ๋ค์ ์ฌ์
๋ ฅ ๋ฐ์ ์ ์๊ฒ ํ์ต๋๋ค.
+
+#### ์ฃผ๋ฌธ ์
๋ ฅ
+
+- ๋ชจ๋ ์ฃผ๋ฌธ์ "ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1" ์ ๊ฐ์ ํ์์ผ๋ก๋ง ์
๋ ฅ๋ฐ๊ฒ ํ์ต๋๋ค.
+- ๋จ, ์ฌ์ฉ์์ ๋ถ์ฃผ์๋ก ์
๋ ฅ ์ฌ์ด์ ๊ณต๋ฐฑ์ด ์๊ธฐ๋ ๊ฒฝ์ฐ๊ฐ ์ข
์ข
์๋๋ฐ, ์ด๋ ํ๋ก๊ทธ๋จ ๋ด๋ถ์์ ์๋ ์ฒ๋ฆฌํ๊ฒ ํ์ต๋๋ค.
+ - ๋์์ฐ๊ธฐ๊ฐ ํฌํจ๋ ๋ฉ๋ด๊ฐ ์์ด์ ์
๋ ฅ์ ๋ชจ๋ ๊ณต๋ฐฑ์ ํ์ฉํ๊ฒ ํ์ต๋๋ค.
+ - "ํด์ฐ๋ฌผํ์คํ - 2, ๋ ๋์์ธ - 3" (O)
+ - "ํด ์ฐ ๋ฌผ ํ ์ค ํ - 1 2 , ๋ ๋์์ธ-3" (O)
+- ๋ฉ๋ด ํ์์ด ์์์ ๋ค๋ฅธ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - "ํด์ฐ๋ฌผํ์คํ 2, ๋ ๋์์ธ 3" (X)
+ - "ํด์ฐ๋ฌผํ์คํ: 2, ๋ ๋์์ธ: 3" (X)
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ๋ฉ๋ด์ ๊ฐ์๋ฅผ 0 ์ดํ์ ์ซ์๋ก ์
๋ ฅํ๋ฉด ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ๋ฉ๋ด์ ๊ฐ์๊ฐ ํฉ์ณ์ 20๊ฐ๋ฅผ ์ด๊ณผํ๋ฉด ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์ถ๊ฐ)
+- ์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์ถ๊ฐ)
+- ์๋ฌ ๋ฉ์์ง๊ฐ ๋์จ ๋ค์์๋ ๋ค์ ์ฃผ๋ฌธ์ ์ฌ์
๋ ฅ ๋ฐ์ ์ ์๊ฒ ํ์ต๋๋ค.
+
+#### ์ด๋ฒคํธ
+
+- ๋ชจ๋ ์ด๋ฒคํธ๋ 10,000์ ์ด์๋ถํฐ ์ ์ฉ๋๋๋ก ํ์ต๋๋ค.
+- ๋ชจ๋ ์ด๋ฒคํธ๋ ์ ์ฉ ๊ฐ๋ฅํ๋ค๋ฉด ์ค๋ณต์ผ๋ก ์ ์ฉ๋๋๋ก ํ์ต๋๋ค.
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.25
+ - ํ ์ธ ๊ธ์ก: 2023.12.01 1,000์์ผ๋ก ์์ํ์ฌ, ๋งค์ผ ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+ - ํ ์ธ ๋ฐฉ๋ฒ: ์ด ์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+- ํ์ผ ํ ์ธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ์ผ์์ผ ~ ๋ชฉ์์ผ
+ - ํ ์ธ ๊ธ์ก: 2,023์
+ - ํ ์ธ ๋ฐฉ๋ฒ: ๋์ ํธ ๋ฉ๋ด๋ฅผ ๊ฐ๋น ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ๊ธ์์ผ, ํ ์์ผ
+ - ํ ์ธ ๊ธ์ก: 2,023์
+ - ํ ์ธ ๋ฐฉ๋ฒ: ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๊ฐ๋น ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+- ํน๋ณ ํ ์ธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ์ผ์์ผ, 12์ 25์ผ
+ - ํ ์ธ ๊ธ์ก: 1,000์
+ - ํ ์ธ ๋ฐฉ๋ฒ: ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31
+ - ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์ (25,000์)
+- ์ฆ์ ์ด๋ฒคํธ๋ ์ดํํ ๊ธ์ก์๋ ํฌํจ๋์ง๋ง, ์ค์ ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์๋ ์ ์ฉ๋์ง ์๊ฒ ํ์ต๋๋ค.
+- ๋๋จธ์ง ์ด๋ฒคํธ๋ ์ดํํ ๊ธ์ก์๋ ํฌํจ๋๊ณ ์ค์ ํ ์ธ์๋ ์ ์ฉ๋ฉ๋๋ค.
+
+#### ์ด๋ฒคํธ ๋ฐฐ์ง
+
+- 5์ฒ์ ๋ฏธ๋ง: ์์
+- 5์ฒ์ ์ด์: ๋ณ
+- 1๋ง์ ์ด์: ํธ๋ฆฌ
+- 2๋ง์ ์ด์: ์ฐํ
+
+#### ๊ฒฐ๊ณผ ์ถ๋ ฅ
+
+- ์
๋ ฅํ ์ฃผ๋ฌธ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
+- ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ ์ถ๋ ฅํฉ๋๋ค.
+- ์ฆ์ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅํฉ๋๋ค. ์ฆ์ ๋ฉ๋ด๊ฐ ์์ผ๋ฉด "์์"์ ์ถ๋ ฅํฉ๋๋ค.
+- ํํ ๋ด์ญ์ ์ถ๋ ฅํฉ๋๋ค. ํํ์ด ์์ผ๋ฉด "์์"์ ์ถ๋ ฅํฉ๋๋ค.
+- ์ดํํ ๊ธ์ก์ ์ถ๋ ฅํฉ๋๋ค. ํํ์ด ์์ผ๋ฉด 0์ ์ถ๋ ฅํฉ๋๋ค.
+- ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์ ์ถ๋ ฅํฉ๋๋ค.
+- 12์ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅํฉ๋๋ค. ๋ฐ์ ๋ฐฐ์ง๊ฐ ์์ผ๋ฉด "์์"์ ์ถ๋ ฅํฉ๋๋ค.
+
+๊ฐ๋ฐํ ๋ด๋ถ์์ ์ฌ๋ฌ ์ํฉ์ ๊ณ ๋ คํด์ ๋ง์ ํ
์คํธ๋ฅผ ์งํํ์ต๋๋ค.
+ํ์ง๋ง ๊ทธ๋ผ์๋ ๋ฒ๊ทธ๊ฐ ์๊ฑฐ๋ ์๋กญ๊ฒ ์ถ๊ฐํ๊ณ ์ถ์ ๊ธฐ๋ฅ์ด ์์ผ์๋ค๋ฉด ๋ฐ๋ก ๋ง์ํด์ฃผ์ธ์.
+
+ํนํ ์๋ก์ด ์ด๋ฒคํธ๋ฅผ ์ถ๊ฐํ๊ฑฐ๋, ์๋ก์ด ๋ฉ๋ด๋ฅผ ์ถ๊ฐํ๋ ๊ฑด ์ธ์ ๋ ํ์์
๋๋ค!
+ํ์ฅ์ฑ์๊ฒ ์ค๊ณ๋ฅผ ํด๋์๊ธฐ ๋๋ฌธ์ ํธํ๊ฒ ์์ฒญํ์
๋ ๊ด์ฐฎ์ต๋๋ค!
+
+๊ฐ์ฌํฉ๋๋ค :)
+
+---
+
+# ์ด๋ฒคํธ ๋ด์ฉ
+
+## ์ด๋ฒคํธ ์ข
๋ฅ
+
+### ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.25
+
+ํ ์ธ ๊ธ์ก: 2023.12.01 1,000์์ผ๋ก ์์ํ์ฌ, ๋งค์ผ ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+
+ํ ์ธ ๋ฐฉ๋ฒ: ์ด ์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+
+### ํ์ผ ํ ์ธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ์ผ์์ผ ~ ๋ชฉ์์ผ
+
+ํ ์ธ ๊ธ์ก: 2,023์
+
+ํ ์ธ ๋ฐฉ๋ฒ: ๋์ ํธ ๋ฉ๋ด๋ฅผ ๊ฐ๋น ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+
+### ์ฃผ๋ง ํ ์ธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ๊ธ์์ผ, ํ ์์ผ
+
+ํ ์ธ ๊ธ์ก: 2,023์
+
+ํ ์ธ ๋ฐฉ๋ฒ: ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๊ฐ๋น ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+
+### ํน๋ณ ํ ์ธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ์ผ์์ผ, 12์ 25์ผ
+
+ํ ์ธ ๊ธ์ก: 1,000์
+
+ํ ์ธ ๋ฐฉ๋ฒ: ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+
+### ์ฆ์ ์ด๋ฒคํธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31
+
+์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์ (25,000์)
+
+## ์ด๋ฒคํธ ๋ฐฐ์ง
+
+์ด๋ฒคํธ๋ก ๋ฐ์ ์ดํํ ๊ธ์ก์ ๋ฐ๋ผ ๊ฐ๊ธฐ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ๋ถ์ฌ
+(์ด๋ `์ดํํ ๊ธ์ก = ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ`์ผ๋ก ๊ณ์ฐ)
+
+- 5์ฒ์ ์ด์: ๋ณ
+- 1๋ง์ ์ด์: ํธ๋ฆฌ
+- 2๋ง์ ์ด์: ์ฐํ
+
+## ์ด๋ฒคํธ ์ฃผ์ ์ฌํญ
+
+- ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์๋ถํฐ ์ด๋ฒคํธ๊ฐ ์ ์ฉ
+- ์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์ฃผ๋ฌธํ ์ ์์
+- ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ (์ข
๋ฅ๊ฐ ์๋ ๊ฐ์)
+
+# ๊ฐ๋ฐ ์์ฒญ ์ฌํญ
+
+- [x] ๋ฐฉ๋ฌธํ ๋ ์ง ์
๋ ฅ
+ - [x] 1 ์ด์ 31 ์ดํ์ ์ซ์๋ง ์
๋ ฅ๋ฐ์
+- [x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ
+ - [x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ง ์
๋ ฅ๋ฐ์
+ - [x] ์ ํด์ง ํ์์ ๋ฉ๋ด๋ง ์
๋ ฅ๋ฐ์
+ - [x] ๋ฉ๋ด์ ๊ฐ์๋ 1 ์ด์์ ์ซ์๋ง ์
๋ ฅ๋ฐ์
+ - [x] ์ค๋ณต๋์ง ์์ ๋ฉ๋ด๋ง ์
๋ ฅ๋ฐ์
+- [x] ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ
+ - [x] ์ถ๋ ฅ ์์๋ ์์ ๋กญ๊ฒ ์ถ๋ ฅ
+- [x] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ์ฆ์ ๋ฉ๋ด ์ถ๋ ฅ
+ - [x] ์ฆ์ ์ด๋ฒคํธ์ ํด๋นํ์ง ์๋ ๊ฒฝ์ฐ `์์` ์ถ๋ ฅ
+- [x] ํํ ๋ด์ญ ์ถ๋ ฅ
+ - [x] ๊ณ ๊ฐ์๊ฒ ์ ์ฉ๋ ์ด๋ฒคํธ ๋ด์ญ๋ง ์ถ๋ ฅ
+ - [x] ์ ์ฉ๋ ์ด๋ฒคํธ๊ฐ ์๋ ๊ฒฝ์ฐ `์์` ์ถ๋ ฅ
+ - [x] ์ด๋ฒคํธ ์ถ๋ ฅ ์์๋ ์์ ๋กญ๊ฒ ์ถ๋ ฅ
+- [x] ์ดํํ ๊ธ์ก ์ถ๋ ฅ
+ - [x] `์ดํํ ๊ธ์ก = ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ`
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ
+ - [x] `ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก = ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก - ํ ์ธ๊ธ์ก`
+- [x] 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ
+ - [x] ์ด๋ฒคํธ ๋ฐฐ์ง๊ฐ ๋ถ์ฌ๋์ง ์๋ ๊ฒฝ์ฐ `์์` ์ถ๋ ฅ
+
+# ์
๋ ฅ ์์ธ ์ฌํญ
+
+- [x] ๋ฐฉ๋ฌธํ ๋ ์ง ์
๋ ฅ ์์ธ
+ - [x] 1 ์ด์ 31 ์ดํ์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ
+ - `[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- [x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ
+ - [x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+ - [x] ๋ฉ๋ด์ ๊ฐ์๊ฐ 1 ์ด์์ ์ ์๊ฐ ์๋ ๊ฒฝ์ฐ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+ - [x] ๋ฉ๋ด์ ํ์์ด ์ ํด์ง ํ์์ ๋ฒ์ด๋ ๊ฒฝ์ฐ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+ - [x] ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+ - [x] ๋ฉ๋ด ๊ฐ์๊ฐ 20๊ฐ๋ฅผ ์ด๊ณผํ ๊ฒฝ์ฐ
+ - `[ERROR] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์ถ๊ฐ)
+ - [x] ์๋ฃ๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ
+ - `[ERROR] ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์ถ๊ฐ)
+- ์ด์ธ ๋ชจ๋ ์์ธ ์ฌํญ์ `[ERROR]` Prefix ์ฌ์ฉ
+
+# ๊ธฐ๋ฅ ๋ช
์ธ
+
+## Config
+
+- [x] Menu
+ - [x] ๋ฉ๋ด ์ด๋ฆ์ผ๋ก Menu ์ฐพ์ ๋ฐํ
+- [x] MenuType
+- [x] ErrorMessage
+
+## Controller
+
+- [x] EventController
+ - [x] ๋ ์ง๋ฅผ ์
๋ ฅ๋ฐ์ `Bill`์ ์์ฑ
+ - [x] ์ฃผ๋ฌธ์ ์
๋ ฅ๋ฐ์ `Bill`์ ์ถ๊ฐ
+ - [x] ์ ๋ ๊ณผ์ ์ค ์์ธ๊ฐ ๋ฐ์ํ ๊ฒฝ์ฐ ๋ฐ๋ณตํ์ฌ ์
๋ ฅ๋ฐ์
+ - [x] ํ์ํ ๋ชจ๋ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅ
+
+## Domain
+
+- [x] Order
+ - [x] ์ฃผ๋ฌธ ๋ฉ๋ด์ ์ฃผ๋ฌธ ์๋์ ์ ์ฅ
+ - [x] 1์ด์์ ์ฃผ๋ฌธ ์๋๋ง ์ฌ์ฉํ๋๋ก ๊ฒ์ฆ
+ - [x] ๊ฐ๊ฒฉ(`๋ฉ๋ด ๊ฐ๊ฒฉ x ์ฃผ๋ฌธ ์๋`)์ ๋ฐํ
+ - [x] ํน์ `Order`์ ๊ฐ์ ๋ฉ๋ด์ธ์ง ํ์ธ
+ - [x] `OrderDTO` ๋ฐํ
+ - [x] `List<Order>`์ ๋ชจ๋ ์ฃผ๋ฌธ ์๋์ ๋์ ํ์ฌ ํฉ์ฐ
+ - [x] `MenuType`์ ์กฐ๊ฑด์ผ๋ก ์ฌ์ฉํ ์ ์๋๋ก ์ค๋ฒ๋ก๋ฉ
+- [x] Bill
+ - [x] ์ฃผ๋ฌธ ๋ฆฌ์คํธ์ ๋ ์ง๋ฅผ ์ ์ฅ
+ - [x] ์ฃผ๋ฌธ์ ์ถ๊ฐ
+ - [x] ์ค๋ณต๋๋ ๋ฉ๋ด๊ฐ ์๋ ์ฃผ๋ฌธ์ธ์ง ๊ฒ์ฆ
+ - [x] ์ต๋ ์ฃผ๋ฌธ์๋ฅผ ๋์ง ์๋์ง ๊ฒ์ฆ
+ - [x] ์๋ฃ๋ง ์ฃผ๋ฌธํ๋์ง ๊ฒ์ฆ
+ - [x] ์ฃผ๋ฌธ์ ์ด๊ธฐํ
+ - [x] ์ ์ฒด ์ฃผ๋ฌธ ๊ธ์ก์ ๊ณ์ฐ
+ - [x] ํน์ ํ์
์ ๋ฉ๋ด ์ฃผ๋ฌธ๋์ ๋ฐํ
+ - [x] `CheckEventDate`์ ๋ฉ์๋ ์ค๋ฒ๋ก๋ฉ
+ - [x] ์ฃผ๋ฌธ ๋ ์ง๋ฅผ ๋ฐํ
+- [x] Date
+ - [x] ์์ฑ์ ์ํ ๋ ์ง๊ฐ 1 ~ 31 ๋ฒ์์ ๊ฐ์ธ์ง ๊ฒ์ฆ
+ - [x] ์์ผ์ ํ์ธ
+ - [x] ์ฃผ๋ง์ธ์ง ํ์ธ -> ํ์ผ ํ ์ธ, ์ฃผ๋ง ํ ์ธ
+ - [x] ๋ฌ๋ ฅ์ ๋ณ์ด ์๋ ํน๋ณํ ๋ ์ธ์ง ํ์ธ -> ํน๋ณ ํ ์ธ
+ - [x] ํฌ๋ฆฌ์ค๋ง์ค ์ด์ ์ธ์ง ํ์ธ -> ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - [x] ์ฒซ์งธ๋ ๋ก๋ถํฐ ์ผ๋ง๋ ์ง๋ฌ๋์ง ํ์ธ -> ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - [x] ๋ ์ง๋ฅผ ๋ฐํ
+- [x] EventHandler
+ - [x] ์ฆ์ ๋ฉ๋ด(์ดํ์ธ) ์กด์ฌ ์ฌ๋ถ
+ - [x] ํํ ๋ด์ญ
+ - [x] ํ ์ธ ๊ธ์ก
+ - [x] ์ดํํ ๊ธ์ก
+- [x] Event
+ - [x] ์ด๋ฒคํธ ์กฐ๊ฑด์ ๋ง๋์ง ํ์ธ
+ - [x] ์ด๋ฒคํธ ํํ์ ๋ฐํ
+- [x] Badge
+ - [x] ๊ฐ๊ฒฉ์ ๋ง๋ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ๋ฐํ
+
+## DTO
+
+- [x] BenefitDTO -> ํํ ์ด๋ฆ, ํํ ๊ธ์ก์ ์ ๋ฌํ๋ ๊ฐ์ฒด
+- [x] OrderDTO -> ๋ฉ๋ด ์ด๋ฆ, ์ฃผ๋ฌธ ๊ฐ์๋ฅผ ์ ๋ฌํ๋ ๊ฐ์ฒด
+
+## View
+
+- [x] InputView
+ - [x] ๋ ์ง ์
๋ ฅ
+ - [x] ์ฃผ๋ฌธ ์
๋ ฅ
+- [x] OutputView
+ - [x] ๊ฐ ์ ๋ชฉ ์ถ๋ ฅ
+ - [x] ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ
+ - [x] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+ - [x] ์ฆ์ ๋ฉ๋ด ์ถ๋ ฅ
+ - [x] ํํ ๋ด์ญ ์ถ๋ ฅ
+ - [x] ์ดํํ ๊ธ์ก ์ถ๋ ฅ
+ - [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ
+ - [x] ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ
+- [x] ViewMessage
+- [x] ViewTitle
+
+## Util
+
+- [x] IntParser
+- [x] OrderParser
+- [x] RetryExecutor
+
+# ํ
์คํธ ์ฝ๋
+
+- [x] Badge
+ - [x] `getBadgeNameWithBenefitPrice` ๋์ ํ์ธ
+ - [x] 0 -> ์์
+ - [x] 2500 -> ์์
+ - [x] 5000 -> ๋ณ
+ - [x] 9000 -> ๋ณ
+ - [x] 10000 -> ํธ๋ฆฌ
+ - [x] 17000 -> ํธ๋ฆฌ
+ - [x] 20000 -> ์ฐํ
+ - [x] 50000 -> ์ฐํ
+- [x] Bill
+ - [x] `from` ๋์ ํ์ธ
+ - [x] ์๋ชป๋ date ๊ฐ ์ฌ์ฉ์ ์์ธ ๋ฐ์ -> Date ํด๋์ค์์ ํ
์คํธ
+ - [x] `add` ๋์ ํ์ธ
+ - [x] `add` ์ค๋ณต๋ ๋ฉ๋ด ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] `add` 20๊ฐ ์ด์ ๋ฉ๋ด ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] ์ฌ๋ฌ ๋ฉ๋ด์ ์ด ์๋์ด 20๊ฐ ์ด์์ธ ๊ฒฝ์ฐ
+ - [x] ํ ๋ฉ๋ด์ ์๋์ด 20๊ฐ ์ด์์ธ ๊ฒฝ์ฐ
+ - [x] `clearOrder` ๋์ ํ์ธ
+ - [x] `getTotalPrice` ๋์ ํ์ธ
+ - [x] `getTypeCount` ๋์ ํ์ธ
+ - [x] DESSERT ํ์
ํ์ธ
+ - [x] MAIN ํ์
ํ์ธ
+ - [x] `getDateValue` ๋์ ํ์ธ
+ - [x] ์๋ฃ๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ ์์ธ ๋ฐ์
+ - [x] ์ด์ธ์ Date ๊ด๋ จ ๋ฉ์๋๋ Date ํด๋์ค์์ ํ
์คํธ
+- [x] Date
+ - [x] ์์ฑ ์ `validate` ๋์ ํ์ธ
+ - [x] 1 -> ๋์
+ - [x] 25 -> ๋์
+ - [x] 31 -> ๋์
+ - [x] ์์ฑ ์ `validate` ์์ธ ๋ฐ์
+ - [x] -5 -> ์์ธ ๋ฐ์
+ - [x] 0 -> ์์ธ ๋ฐ์
+ - [x] 32 -> ์์ธ ๋ฐ์
+ - [x] 75 -> ์์ธ ๋ฐ์
+ - [x] `isWeekend` ๋์ ํ์ธ
+ - [x] 1 -> true
+ - [x] 8 -> true
+ - [x] 16 -> true
+ - [x] 17 -> false
+ - [x] 25 -> false
+ - [x] 28 -> false
+ - [x] `isSpecialDay` ๋์ ํ์ธ
+ - [x] 3 -> true
+ - [x] 25 -> true
+ - [x] 31 -> true
+ - [x] 13 -> false
+ - [x] 22 -> false
+ - [x] `isNotPassedChristmas` ๋์ ํ์ธ
+ - [x] 1 -> true
+ - [x] 14 -> true
+ - [x] 25 -> true
+ - [x] 26 -> false
+ - [x] 31 -> false
+ - [x] `timePassedSinceFirstDay` ๋์ ํ์ธ
+ - [x] 1 -> 0
+ - [x] 18 -> 17
+ - [x] 25 -> 24
+- [x] Event
+ - [x] `getEventName` ๋์ ํ์ธ
+ - [x] `isDiscount` ๋์ ํ์ธ
+ - [x] `checkCondition` ๋์ ํ์ธ
+ - [x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ -> `isNotPassedChristmas`์์ ํ
์คํธ
+ - [x] ํ์ผ ํ ์ธ -> `isWeekend`์์ ํ
์คํธ
+ - [x] ์ฃผ๋ง ํ ์ธ -> `isWeekend`์์ ํ
์คํธ
+ - [x] ํน๋ณ ํ ์ธ -> `isSpecialDay`์์ ํ
์คํธ
+ - [x] ์ฆ์ ์ด๋ฒคํธ
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) = 120,000 -> true
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ ์๋ฌ๋(5) = 150,000 -> true
+ - [x] ๋ฐ๋นํ๋ฆฝ(1) + ์์ก์ด์ํ(1) = 60,000 -> false
+ - [x] `getBenefit` ๋์ ํ์ธ
+ - [x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - [x] 1 -> 1000
+ - [x] 11 -> 2000
+ - [x] 25 -> 3400
+ - [x] ํ์ผ ํ ์ธ
+ - [x] ์์ก์ด์ํ(1) + ๋ฐ๋นํ๋ฆฝ(1) -> 0
+ - [x] ํํ์ค(1) + ํด์ฐ๋ฌผํ์คํ(1) + ์ด์ฝ์ผ์ดํฌ(2) -> 4046
+ - [x] ๋ฐ๋นํ๋ฆฝ(2) + ์ด์ฝ์ผ์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(3) -> 10115
+ - [x] ์ฃผ๋ง ํ ์ธ
+ - [x] ์์ก์ด์ํ(2) + ์ ๋ก์ฝ๋ผ(2) -> 0
+ - [x] ํํ์ค(1) + ํฐ๋ณธ์คํ
์ดํฌ(1) -> 2023
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ(1) + ๋ฐ๋นํ๋ฆฝ(2) + ํด์ฐ๋ฌผํ์คํ(3) + ์ ๋ก์ฝ๋ผ(6) -> 12138
+ - [x] ํน๋ณ ํ ์ธ -> ํญ์ 1000
+ - [x] ์ฆ์ ์ด๋ฒคํธ -> ํญ์ 25000
+ - [x] ๋ชจ๋ ์ด๋ฒคํธ์์ ์ด์ฃผ๋ฌธ๊ธ์ก 10000์ ์ด์๋ถํฐ ์ด๋ฒคํธ ์ ์ฉ
+- [x] EventHandler
+ - [x] `hasChampagneGift` ๋์ ํ์ธ -> Event `checkCondition`์์ ํ
์คํธ
+ - [x] `getTotalDiscountPrice` ๋์ ํ์ธ
+ - [x] 1์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) -> 5046
+ - [x] 3์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) -> 10292
+ - [x] 13์ผ, ํด์ฐ๋ฌผํ์คํ(10) + ์ด์ฝ์ผ์ดํฌ(1) + ์์ด์คํฌ๋ฆผ(2) -> 8269
+ - [x] 25์ผ, ํฌ๋ฆฌ์ค๋ง์คํ์คํ(2) + ์ดํ์ธ(2) -> 4400
+ - [x] 30์ผ, ์์ ์๋ฌ๋(5) + ๋ฐ๋นํ๋ฆฝ(2) + ํฐ๋ณธ์คํ
์ดํฌ(1) + ๋ ๋์์ธ(2) -> 6069
+ - [x] `getTotalBenefitPrice` ๋์ ํ์ธ
+ - [x] 1์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) -> 30046
+ - [x] 3์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) -> 10292
+ - [x] 13์ผ, ํด์ฐ๋ฌผํ์คํ(10) + ์ด์ฝ์ผ์ดํฌ(1) + ์์ด์คํฌ๋ฆผ(2) -> 33269
+ - [x] 25์ผ, ํฌ๋ฆฌ์ค๋ง์คํ์คํ(2) + ์ดํ์ธ(2) -> 4400
+ - [x] 30์ผ, ์์ ์๋ฌ๋(5) + ๋ฐ๋นํ๋ฆฝ(2) + ํฐ๋ณธ์คํ
์ดํฌ(1) + ๋ ๋์์ธ(2) -> 31069
+ - [x] `getAllBenefit` ๋์ ํ์ธ
+ - [x] 1์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(1) -> ํฌ๋ฆฌ์ค๋ง์ค(1000), ์ฃผ๋ง(4046)
+ - [x] 3์ผ, ํฐ๋ณธ์คํ
์ดํฌ(1) + ์์ด์คํฌ๋ฆผ(4) -> ํฌ๋ฆฌ์ค๋ง์ค(1200), ํ์ผ(8092), ํน๋ณ(1000)
+ - [x] 13์ผ, ํด์ฐ๋ฌผํ์คํ(10) + ์ด์ฝ์ผ์ดํฌ(1) + ์์ด์คํฌ๋ฆผ(2) -> ํฌ๋ฆฌ์ค๋ง์ค(2200), ํ์ผ(6069), ์ฆ์ (25000)
+ - [x] 25์ผ, ํฌ๋ฆฌ์ค๋ง์คํ์คํ(2) + ์ดํ์ธ(2) -> ํฌ๋ฆฌ์ค๋ง์ค(3400), ํน๋ณ(1000)
+ - [x] 30์ผ, ์์ ์๋ฌ๋(5) + ๋ฐ๋นํ๋ฆฝ(2) + ํฐ๋ณธ์คํ
์ดํฌ(1) + ๋ ๋์์ธ(2) -> ์ฃผ๋ง(6069), ์ฆ์ (25000)
+- [x] Order
+ - [x] `create` ๋์ ํ์ธ
+ - [x] ์๋ชป๋ ๋ฉ๋ด ์ด๋ฆ ์ฌ์ฉ์ ์์ธ ๋ฐ์ -> Menu ํด๋์ค์์ ํ
์คํธ
+ - [x] ์๋ชป๋ count ์ฌ์ฉ์ ์์ธ ๋ฐ์
+ - [x] `getPrice` ๋์ ํ์ธ
+ - [x] ํํ์ค(2) -> 11000
+ - [x] ๋ฐ๋นํ๋ฆฝ(3) -> 162000
+ - [x] ์์ด์คํฌ๋ฆผ(5) -> 25000
+ - [x] `isSameMenu` ๋์ ํ์ธ
+ - [x] ํํ์ค, ํํ์ค -> true
+ - [x] ๋ ๋์์ธ, ๋ ๋์์ธ -> true
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ, ์์ด์คํฌ๋ฆผ -> false
+ - [x] ์ด์ฝ์ผ์ดํฌ, ๋ฐ๋นํ๋ฆฝ -> false
+ - [x] `accumulateCount` ๋์ ํ์ธ
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ(5) -> 5
+ - [x] ์์ก์ด์ํ(3) + ๋ฐ๋นํ๋ฆฝ(1) + ์์ด์คํฌ๋ฆผ(3) -> 7
+ - [x] `accumulateCount` type ์ฌ์ฉํ์ฌ ๋์ ํ์ธ
+ - [x] DESSERT, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์ ๋ก์ฝ๋ผ(4) -> 0
+ - [x] MAIN, ์์ก์ด์คํ(3) + ๋ฐ๋นํ๋ฆฝ(1) + ํด์ฐ๋ฌผํ์คํ(2) + ์์ด์คํฌ๋ฆผ(5) -> 3
+- [x] Menu
+ - [x] `from` ๋์ ํ์ธ
+ - [x] ์์ก์ด์ํ -> Menu.SOUP
+ - [x] ํด์ฐ๋ฌผํ์คํ -> Menu.SEAFOOD_PASTA
+ - [x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด ์
๋ ฅ์ ์์ธ ํ์ธ
+- [x] IntParser
+ - [x] `parseIntOrThrow` ๋์ ํ์ธ
+ - [x] "123" -> 123
+ - [x] "-123" -> -123
+ - [x] "2147483647" -> 2147483647 (์ต๋๊ฐ)
+ - [x] "-2147483648" -> -2147483648 (์ต์๊ฐ)
+ - [x] ์ ์ํํ๊ฐ ์๋ ๋ฌธ์์ด ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] ABC
+ - [x] 12L
+ - [x] 13.5
+ - [x] Integer ๋ฒ์๋ฅผ ๋ฒ์ด๋ ๋ฌธ์์ด ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] 2147483648
+ - [x] -2147483649
+ - [x] 999999999999999
+- [x] OrderParser
+ - [x] `parseOrderOrThrow` ๋์ ํ์ธ
+ - [x] "ํํ์ค-1,์ ๋ก์ฝ๋ผ-2,ํฐ๋ณธ์คํ
์ดํฌ-5" -> ํํ์ค(1) + ์ ๋ก์ฝ๋ผ(2) + ํฐ๋ณธ์คํ
์ดํฌ(5)
+ - [x] "ํํ์ค - 1, ์ ๋ก์ฝ๋ผ- 2, ํฐ๋ณธ ์คํ
์ดํฌ -5" -> ํํ์ค(1) + ์ ๋ก์ฝ๋ผ(2) + ํฐ๋ณธ์คํ
์ดํฌ(5)
+ - [x] "ํฐ๋ณธ์คํ
์ดํฌ-1" -> ํฐ๋ณธ์คํ
์ดํฌ(1)
+ - [x] "ํด์ฐ๋ฌผํ์คํ-3 , " -> ํด์ฐ๋ฌผํ์คํ(3)
+ - [x] ์๋ชป๋ ํ์์ ์ฃผ๋ฌธ์ ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] "ํํ์ค: 1, ์ ๋ก์ฝ๋ผ: 2"
+ - [x] "ํํ์ค-1 ์ ๋ก์ฝ๋ผ-2 ํ์คํ-3"
+ - [x] "ํํ์ค 1 ์ ๋ก์ฝ๋ผ 2 ํ์คํ 3"
+ - [x] "ํํ์ค, ์ ๋ก์ฝ๋ผ, ํ์คํ"
+ - [x] "ํํ์ค -"
+ - [x] "- 3"
+- [x] OutputView
+ - [x] `printHelloMessage` ๋์ ํ์ธ
+ - [x] `printEventPreviewTitle` ๋์ ํ์ธ
+ - [x] `printOrder` ๋์ ํ์ธ
+ - [x] `printTotalPrice` ๋์ ํ์ธ
+ - [x] `printGift` ๋์ ํ์ธ
+ - [x] `printAllBenefit` ๋์ ํ์ธ
+ - [x] `printBenefitPrice` ๋์ ํ์ธ
+ - [x] `printAfterDiscountPrice` ๋์ ํ์ธ
+ - [x] `printBadge` ๋์ ํ์ธ | Unknown | Readme.md ๋ฅผ ๊ผผ๊ผผํ ์ ์์ฑํ์ ๊ฒ ๊ฐ์์๐ |
@@ -0,0 +1,47 @@
+package christmas.config;
+
+import java.util.Arrays;
+
+public enum Menu {
+ SOUP("์์ก์ด์ํ", 6000, MenuType.APPETIZER),
+ TAPAS("ํํ์ค", 5500, MenuType.APPETIZER),
+ SALAD("์์ ์๋ฌ๋", 8000, MenuType.APPETIZER),
+ STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55000, MenuType.MAIN),
+ BARBECUE("๋ฐ๋นํ๋ฆฝ", 54000, MenuType.MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35000, MenuType.MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000, MenuType.MAIN),
+ CAKE("์ด์ฝ์ผ์ดํฌ", 15000, MenuType.DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5000, MenuType.DESSERT),
+ COLA("์ ๋ก์ฝ๋ผ", 3000, MenuType.DRINK),
+ WINE("๋ ๋์์ธ", 60000, MenuType.DRINK),
+ CHAMPAGNE("์ดํ์ธ", 25000, MenuType.DRINK);
+
+ private final String menuName;
+ private final int price;
+ private final MenuType type;
+
+ Menu(String menuName, int price, MenuType type) {
+ this.menuName = menuName;
+ this.price = price;
+ this.type = type;
+ }
+
+ public static Menu from(String menuName) {
+ return Arrays.stream(Menu.values())
+ .filter(it -> menuName.equals(it.menuName))
+ .findAny()
+ .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage()));
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public MenuType getType() {
+ return type;
+ }
+} | Java | ์ ๋ ๊ฐ์ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๋๋ฐ
Menu์ ํ์ฅ์ฑ์ ์๊ฐํด์ ์ฌ๋ฌ๊ฐ์ง ์นดํ
๊ณ ๋ฆฌ์ ํฌํจ๋ ์๋ ์๋ ์ ์ ์๊ฐํ์ฌ
์นดํ
๊ณ ๋ฆฌ๋ ๋ฐ๋ก ๋นผ๋๊ฒ ์ข๋ค๋ ์๊ฒฌ์ ๋ดค์ต๋๋ค!
์ฟ ํค๋์ ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,18 @@
+package christmas.util;
+
+import java.util.function.Consumer;
+
+public class RetryExecutor {
+ private RetryExecutor() {
+ // ์ธ์คํด์ค ์์ฑ ๋ฐฉ์ง
+ }
+
+ public static void execute(Runnable action, Consumer<IllegalArgumentException> onError) {
+ try {
+ action.run();
+ } catch (IllegalArgumentException error) {
+ onError.accept(error);
+ execute(action, onError);
+ }
+ }
+} | Java | Retry๋ฅผ ์ ๋ Controller์์ while๋ฌธ์ผ๋ก ํ์ฌ ์ง์ ๋ถํ ๊ฒ์ด ๊ณ ๋ฏผ์ด์๋๋ฐ
์ด๋ฐ ๋ฐฉ๋ฒ์ด ์์๋ค์! ๋ฐฐ์ ๊ฐ๋๋ค!! |
@@ -0,0 +1,91 @@
+package christmas.view;
+
+import christmas.dto.BenefitDTO;
+import christmas.dto.OrderDTO;
+
+import java.util.List;
+
+public class OutputView {
+ private void printMessage(ViewMessage message) {
+ System.out.println(message.getMessage());
+ }
+
+ private void printFormat(ViewMessage message, Object... args) {
+ System.out.printf(message.getMessage(), args);
+ newLine();
+ }
+
+ private void printTitle(ViewTitle title) {
+ System.out.println(title.getTitle());
+ }
+
+ public void printHelloMessage() {
+ printMessage(ViewMessage.HELLO);
+ }
+
+ public void printEventPreviewTitle(int date) {
+ printFormat(ViewMessage.EVENT_PREVIEW_TITLE, date);
+ newLine();
+ }
+
+ public void printOrder(List<OrderDTO> orders) {
+ printTitle(ViewTitle.ORDER_MENU);
+ orders.forEach(it -> printFormat(ViewMessage.ORDER_FORMAT, it.menuName(), it.count()));
+ newLine();
+ }
+
+ public void printTotalPrice(int price) {
+ printTitle(ViewTitle.TOTAL_PRICE);
+ printFormat(ViewMessage.PRICE_FORMAT, price);
+ newLine();
+ }
+
+ public void printGift(boolean hasGift) {
+ printTitle(ViewTitle.GIFT_MENU);
+ if (hasGift) {
+ printMessage(ViewMessage.CHAMPAGNE);
+ newLine();
+ return;
+ }
+ printMessage(ViewMessage.NOTHING);
+ newLine();
+ }
+
+ public void printAllBenefit(List<BenefitDTO> benefits) {
+ printTitle(ViewTitle.BENEFIT_LIST);
+ if (benefits.isEmpty()) {
+ printMessage(ViewMessage.NOTHING);
+ newLine();
+ return;
+ }
+ benefits.forEach(it -> printFormat(ViewMessage.BENEFIT_FORMAT, it.EventName(), it.price()));
+ newLine();
+ }
+
+ public void printBenefitPrice(int price) {
+ printTitle(ViewTitle.BENEFIT_PRICE);
+ printFormat(ViewMessage.PRICE_FORMAT, -price);
+ newLine();
+ }
+
+ public void printAfterDiscountPrice(int price) {
+ printTitle(ViewTitle.AFTER_DISCOUNT_PRICE);
+ printFormat(ViewMessage.PRICE_FORMAT, price);
+ newLine();
+ }
+
+ public void printBadge(String badge) {
+ printTitle(ViewTitle.BADGE);
+ System.out.println(badge);
+ }
+
+ public void printErrorMessage(IllegalArgumentException error) {
+ newLine();
+ System.out.println(error.getMessage());
+ newLine();
+ }
+
+ public void newLine() {
+ System.out.println();
+ }
+} | Java | ์ ๋ ์์ฃผ ์ฌ์ฉ๋๋ newLine()์ static์ผ๋ก ์ ์ธํ๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค๊ณ ๋ง์๋๋ฆฌ๋ ค ํ๋๋ฐ
lineSeperator() ๋ผ๋๊ฒ ์์๊ตฐ์! ์ ๋ ๋ฐฐ์๊ฐ๊ฒ ์ต๋๋ค๐ |
@@ -0,0 +1,12 @@
+package christmas.config;
+
+public class Constant {
+ public static final int INIT_VALUE = 0;
+ public static final int FILTER_CONDITION = 0;
+ public static final int MIN_ORDER = 1;
+ public static final int MAX_ORDER = 20;
+
+ private Constant() {
+ // ์ธ์คํด์ค ์์ฑ ๋ฐฉ์ง
+ }
+} | Java | ๊ฐ์ธ์ ์ผ๋ก Constant ํด๋์ค์ ์์๋ค์ ๋ชจ์๋ฃ๋ ๊ฒ ๋ณด๋ค๋
๊ฐ ํด๋์ค์ ํ์ํ Constant ํด๋์ค๋ฅผ ๊ฐ๊ฐ ๋ง๋ค์ด์ ๋ง๋๋ ๊ฒ์ด ์๋ฏธ๋ฅผ ๋ ๋ช
ํํํ๊ณ ์์๋ณด๊ธฐ ์ฌ์ด ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,145 @@
+package christmas.domain;
+
+import christmas.dto.OrderDTO;
+import christmas.config.ErrorMessage;
+import christmas.config.MenuType;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class BillTest {
+ @DisplayName("์๋ชป๋ date ๊ฐ ์ฌ์ฉ ์ ์์ธ ๋ฐ์")
+ @ParameterizedTest
+ @ValueSource(ints = {-5, 0, 32, 75})
+ void checkCreateFromWrongDate(int date) {
+ assertThatThrownBy(() -> Bill.from(date))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ErrorMessage.WRONG_DATE.getMessage());
+ }
+
+ @DisplayName("add ๋์ ํ์ธ")
+ @Test
+ void checkAddMethod() {
+ Bill bill = Bill.from(1)
+ .add(Order.create("์์ ์๋ฌ๋", 3))
+ .add(Order.create("ํด์ฐ๋ฌผํ์คํ", 1))
+ .add(Order.create("์ ๋ก์ฝ๋ผ", 2));
+
+ List<OrderDTO> answer = List.of(
+ new OrderDTO("์์ ์๋ฌ๋", 3),
+ new OrderDTO("ํด์ฐ๋ฌผํ์คํ", 1),
+ new OrderDTO("์ ๋ก์ฝ๋ผ", 2)
+ );
+
+ assertThat(bill.getAllOrders()).isEqualTo(answer);
+ }
+
+ @DisplayName("์ค๋ณต๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅ์ ์์ธ ๋ฐ์")
+ @Test
+ void checkDuplicatedMenu() {
+ assertThatThrownBy(() -> Bill.from(1)
+ .add(Order.create("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 2))
+ .add(Order.create("๋ฐ๋นํ๋ฆฝ", 1))
+ .add(Order.create("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 3))
+ ).isInstanceOf(IllegalArgumentException.class).hasMessage(ErrorMessage.WRONG_ORDER.getMessage());
+ }
+
+ @DisplayName("๋ฉ๋ด๊ฐ 20๊ฐ๋ฅผ ์ด๊ณผํ๋ ๊ฒฝ์ฐ ์์ธ ๋ฐ์")
+ @ParameterizedTest
+ @MethodSource("overedOrder")
+ void checkOverOrder(List<Order> orders) {
+ Bill bill = Bill.from(1);
+
+ assertThatThrownBy(() -> orders.forEach(bill::add))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ErrorMessage.OVER_MAX_ORDER.getMessage());
+ }
+
+ static Stream<Arguments> overedOrder() {
+ return Stream.of(
+ Arguments.of(List.of(
+ Order.create("ํด์ฐ๋ฌผํ์คํ", 7),
+ Order.create("์ ๋ก์ฝ๋ผ", 15)
+ )),
+ Arguments.of(List.of(
+ Order.create("์์ด์คํฌ๋ฆผ", 25)
+ ))
+ );
+ }
+
+ @DisplayName("clearOrder ๋์ ํ์ธ")
+ @Test
+ void checkClearOrder() {
+ Bill bill = Bill.from(1)
+ .add(Order.create("์์ ์๋ฌ๋", 3))
+ .add(Order.create("ํด์ฐ๋ฌผํ์คํ", 1))
+ .add(Order.create("์ ๋ก์ฝ๋ผ", 2));
+ bill.clearOrder();
+ assertThat(bill.getAllOrders()).isEqualTo(List.of());
+ }
+
+ @DisplayName("getTotalPrice ๋์ ํ์ธ")
+ @Test
+ void checkTotalPrice() {
+ Bill bill = Bill.from(1)
+ .add(Order.create("ํํ์ค", 2))
+ .add(Order.create("ํฐ๋ณธ์คํ
์ดํฌ", 1))
+ .add(Order.create("์ ๋ก์ฝ๋ผ", 2));
+ assertThat(bill.getTotalPrice()).isEqualTo(72000);
+ }
+
+ @DisplayName("getTypeCount ๋์ ํ์ธ")
+ @ParameterizedTest
+ @MethodSource("typedBill")
+ void checkTypeCount(Bill bill, MenuType type, int answer) {
+ assertThat(bill.getTypeCount(type)).isEqualTo(answer);
+ }
+
+ static Stream<Arguments> typedBill() {
+ return Stream.of(
+ Arguments.of(
+ Bill.from(1)
+ .add(Order.create("์์ก์ด์ํ", 3))
+ .add(Order.create("ํฐ๋ณธ์คํ
์ดํฌ", 1))
+ .add(Order.create("๋ฐ๋นํ๋ฆฝ", 2)),
+ MenuType.MAIN,
+ 3
+ ),
+ Arguments.of(
+ Bill.from(1)
+ .add(Order.create("ํฐ๋ณธ์คํ
์ดํฌ", 2))
+ .add(Order.create("์ด์ฝ์ผ์ดํฌ", 2))
+ .add(Order.create("์์ด์คํฌ๋ฆผ", 3))
+ .add(Order.create("์ ๋ก์ฝ๋ผ", 7)),
+ MenuType.DESSERT,
+ 5
+ )
+ );
+ }
+
+ @DisplayName("getDateValue ๋์ ํ์ธ")
+ @ParameterizedTest
+ @ValueSource(ints = {1, 17, 25, 31})
+ void checkDateValue(int date) {
+ assertThat(Bill.from(date).getDateValue()).isEqualTo(date);
+ }
+
+ @DisplayName("์๋ฃ๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ ์์ธ ๋ฐ์")
+ @Test
+ void checkOnlyDrinkOrder() {
+ assertThatThrownBy(() -> Bill.from(1)
+ .add(Order.create("์ ๋ก์ฝ๋ผ", 3))
+ .add(Order.create("๋ ๋์์ธ", 1))
+ .validateOnlyDrink()
+ ).isInstanceOf(IllegalArgumentException.class).hasMessage(ErrorMessage.ONLY_DRINK_ORDER.getMessage());
+ }
+} | Java | ๋์ ํ์ธ ๋ณด๋ค๋ ์๋๋ฆฌ์ค๋ฅผ ์ ์ด์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์์
ํํ์ค 2๊ฐ, ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ, ์ ๋ก์ฝ๋ผ 2๊ฐ์ ํ ํ ์ฃผ๋ฌธ ๊ธ์ก 72000์์ ๋ฐํํ๋ค . ์ฝ๊ฐ ์ด๋ฐ์์ผ๋ก? |
@@ -0,0 +1,456 @@
+# ์ด๋ฉ์ผ ๋ต์ฅ
+
+> ์ ๋ชฉ: 12์ ์ด๋ฒคํธ ๊ฐ๋ฐ ๋ณด๊ณ
+
+> ๋ณด๋ธ ์ฌ๋: ๊ฐ๋ฐํ <`dev@woowacourse.io`>
+>
+> ๋ฐ๋ ์ฌ๋: ๋น์ฆ๋์คํ <`biz@woowacourse.io`>
+
+์๋
ํ์ธ์. ๊ฐ๋ฐํ์
๋๋ค!
+
+12์ ์ด๋ฒคํธ ํ๋๋ ๊ฐ๋ฐ ์์ฒญ ์ฌํญ์ ์ ๋ฐ์ ๋ณด์์ต๋๋ค.
+์์ฒญํ์ ๋ด์ฉ๋ค์ ๋ชจ๋ ์ ์ฉํด๋ณด์๋๋ฐ์. ํน์ ๋๋ฝ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด ๋ฐ๋ก ๋ง์ํด์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.
+
+#### ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ
+
+- ๋ฐฉ๋ฌธ ๋ ์ง๋ 1 ์ด์ 31 ์ดํ์ ์ซ์๋ก๋ง ์
๋ ฅ๋ฐ๊ฒ ํ์ต๋๋ค.
+- ๋จ, ์ฌ์ฉ์์ ๋ถ์ฃผ์๋ก ์
๋ ฅ ์๋ค๋ก ๊ณต๋ฐฑ์ด ์๊ธฐ๋ ๊ฒฝ์ฐ๊ฐ ์ข
์ข
์๋๋ฐ, ์ด๋ ํ๋ก๊ทธ๋จ ๋ด๋ถ์์ ์๋ ์ฒ๋ฆฌํ๊ฒ ํ์ต๋๋ค.
+ - " 12 " (O)
+ - " 1 2" (X)
+- ์ด์ธ์ ๋ชจ๋ ์๋ชป๋ ์
๋ ฅ์ ์์ฒญํ์ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ์๋ฌ ๋ฉ์์ง๊ฐ ๋์จ ๋ค์์๋ ๋ค์ ์ฌ์
๋ ฅ ๋ฐ์ ์ ์๊ฒ ํ์ต๋๋ค.
+
+#### ์ฃผ๋ฌธ ์
๋ ฅ
+
+- ๋ชจ๋ ์ฃผ๋ฌธ์ "ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1" ์ ๊ฐ์ ํ์์ผ๋ก๋ง ์
๋ ฅ๋ฐ๊ฒ ํ์ต๋๋ค.
+- ๋จ, ์ฌ์ฉ์์ ๋ถ์ฃผ์๋ก ์
๋ ฅ ์ฌ์ด์ ๊ณต๋ฐฑ์ด ์๊ธฐ๋ ๊ฒฝ์ฐ๊ฐ ์ข
์ข
์๋๋ฐ, ์ด๋ ํ๋ก๊ทธ๋จ ๋ด๋ถ์์ ์๋ ์ฒ๋ฆฌํ๊ฒ ํ์ต๋๋ค.
+ - ๋์์ฐ๊ธฐ๊ฐ ํฌํจ๋ ๋ฉ๋ด๊ฐ ์์ด์ ์
๋ ฅ์ ๋ชจ๋ ๊ณต๋ฐฑ์ ํ์ฉํ๊ฒ ํ์ต๋๋ค.
+ - "ํด์ฐ๋ฌผํ์คํ - 2, ๋ ๋์์ธ - 3" (O)
+ - "ํด ์ฐ ๋ฌผ ํ ์ค ํ - 1 2 , ๋ ๋์์ธ-3" (O)
+- ๋ฉ๋ด ํ์์ด ์์์ ๋ค๋ฅธ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - "ํด์ฐ๋ฌผํ์คํ 2, ๋ ๋์์ธ 3" (X)
+ - "ํด์ฐ๋ฌผํ์คํ: 2, ๋ ๋์์ธ: 3" (X)
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ๋ฉ๋ด์ ๊ฐ์๋ฅผ 0 ์ดํ์ ์ซ์๋ก ์
๋ ฅํ๋ฉด ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- ๋ฉ๋ด์ ๊ฐ์๊ฐ ํฉ์ณ์ 20๊ฐ๋ฅผ ์ด๊ณผํ๋ฉด ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์ถ๊ฐ)
+- ์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด์ด๊ฒ ํ์ต๋๋ค.
+ - `[ERROR] ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์ถ๊ฐ)
+- ์๋ฌ ๋ฉ์์ง๊ฐ ๋์จ ๋ค์์๋ ๋ค์ ์ฃผ๋ฌธ์ ์ฌ์
๋ ฅ ๋ฐ์ ์ ์๊ฒ ํ์ต๋๋ค.
+
+#### ์ด๋ฒคํธ
+
+- ๋ชจ๋ ์ด๋ฒคํธ๋ 10,000์ ์ด์๋ถํฐ ์ ์ฉ๋๋๋ก ํ์ต๋๋ค.
+- ๋ชจ๋ ์ด๋ฒคํธ๋ ์ ์ฉ ๊ฐ๋ฅํ๋ค๋ฉด ์ค๋ณต์ผ๋ก ์ ์ฉ๋๋๋ก ํ์ต๋๋ค.
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.25
+ - ํ ์ธ ๊ธ์ก: 2023.12.01 1,000์์ผ๋ก ์์ํ์ฌ, ๋งค์ผ ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+ - ํ ์ธ ๋ฐฉ๋ฒ: ์ด ์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+- ํ์ผ ํ ์ธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ์ผ์์ผ ~ ๋ชฉ์์ผ
+ - ํ ์ธ ๊ธ์ก: 2,023์
+ - ํ ์ธ ๋ฐฉ๋ฒ: ๋์ ํธ ๋ฉ๋ด๋ฅผ ๊ฐ๋น ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ๊ธ์์ผ, ํ ์์ผ
+ - ํ ์ธ ๊ธ์ก: 2,023์
+ - ํ ์ธ ๋ฐฉ๋ฒ: ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๊ฐ๋น ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+- ํน๋ณ ํ ์ธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ์ผ์์ผ, 12์ 25์ผ
+ - ํ ์ธ ๊ธ์ก: 1,000์
+ - ํ ์ธ ๋ฐฉ๋ฒ: ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ
+ - ๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31
+ - ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์ (25,000์)
+- ์ฆ์ ์ด๋ฒคํธ๋ ์ดํํ ๊ธ์ก์๋ ํฌํจ๋์ง๋ง, ์ค์ ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์๋ ์ ์ฉ๋์ง ์๊ฒ ํ์ต๋๋ค.
+- ๋๋จธ์ง ์ด๋ฒคํธ๋ ์ดํํ ๊ธ์ก์๋ ํฌํจ๋๊ณ ์ค์ ํ ์ธ์๋ ์ ์ฉ๋ฉ๋๋ค.
+
+#### ์ด๋ฒคํธ ๋ฐฐ์ง
+
+- 5์ฒ์ ๋ฏธ๋ง: ์์
+- 5์ฒ์ ์ด์: ๋ณ
+- 1๋ง์ ์ด์: ํธ๋ฆฌ
+- 2๋ง์ ์ด์: ์ฐํ
+
+#### ๊ฒฐ๊ณผ ์ถ๋ ฅ
+
+- ์
๋ ฅํ ์ฃผ๋ฌธ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
+- ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ ์ถ๋ ฅํฉ๋๋ค.
+- ์ฆ์ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅํฉ๋๋ค. ์ฆ์ ๋ฉ๋ด๊ฐ ์์ผ๋ฉด "์์"์ ์ถ๋ ฅํฉ๋๋ค.
+- ํํ ๋ด์ญ์ ์ถ๋ ฅํฉ๋๋ค. ํํ์ด ์์ผ๋ฉด "์์"์ ์ถ๋ ฅํฉ๋๋ค.
+- ์ดํํ ๊ธ์ก์ ์ถ๋ ฅํฉ๋๋ค. ํํ์ด ์์ผ๋ฉด 0์ ์ถ๋ ฅํฉ๋๋ค.
+- ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์ ์ถ๋ ฅํฉ๋๋ค.
+- 12์ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅํฉ๋๋ค. ๋ฐ์ ๋ฐฐ์ง๊ฐ ์์ผ๋ฉด "์์"์ ์ถ๋ ฅํฉ๋๋ค.
+
+๊ฐ๋ฐํ ๋ด๋ถ์์ ์ฌ๋ฌ ์ํฉ์ ๊ณ ๋ คํด์ ๋ง์ ํ
์คํธ๋ฅผ ์งํํ์ต๋๋ค.
+ํ์ง๋ง ๊ทธ๋ผ์๋ ๋ฒ๊ทธ๊ฐ ์๊ฑฐ๋ ์๋กญ๊ฒ ์ถ๊ฐํ๊ณ ์ถ์ ๊ธฐ๋ฅ์ด ์์ผ์๋ค๋ฉด ๋ฐ๋ก ๋ง์ํด์ฃผ์ธ์.
+
+ํนํ ์๋ก์ด ์ด๋ฒคํธ๋ฅผ ์ถ๊ฐํ๊ฑฐ๋, ์๋ก์ด ๋ฉ๋ด๋ฅผ ์ถ๊ฐํ๋ ๊ฑด ์ธ์ ๋ ํ์์
๋๋ค!
+ํ์ฅ์ฑ์๊ฒ ์ค๊ณ๋ฅผ ํด๋์๊ธฐ ๋๋ฌธ์ ํธํ๊ฒ ์์ฒญํ์
๋ ๊ด์ฐฎ์ต๋๋ค!
+
+๊ฐ์ฌํฉ๋๋ค :)
+
+---
+
+# ์ด๋ฒคํธ ๋ด์ฉ
+
+## ์ด๋ฒคํธ ์ข
๋ฅ
+
+### ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.25
+
+ํ ์ธ ๊ธ์ก: 2023.12.01 1,000์์ผ๋ก ์์ํ์ฌ, ๋งค์ผ ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+
+ํ ์ธ ๋ฐฉ๋ฒ: ์ด ์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+
+### ํ์ผ ํ ์ธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ์ผ์์ผ ~ ๋ชฉ์์ผ
+
+ํ ์ธ ๊ธ์ก: 2,023์
+
+ํ ์ธ ๋ฐฉ๋ฒ: ๋์ ํธ ๋ฉ๋ด๋ฅผ ๊ฐ๋น ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+
+### ์ฃผ๋ง ํ ์ธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ๊ธ์์ผ, ํ ์์ผ
+
+ํ ์ธ ๊ธ์ก: 2,023์
+
+ํ ์ธ ๋ฐฉ๋ฒ: ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๊ฐ๋น ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+
+### ํน๋ณ ํ ์ธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31 ์ค ๋งค์ฃผ ์ผ์์ผ, 12์ 25์ผ
+
+ํ ์ธ ๊ธ์ก: 1,000์
+
+ํ ์ธ ๋ฐฉ๋ฒ: ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก๋งํผ ํ ์ธ
+
+### ์ฆ์ ์ด๋ฒคํธ
+
+๊ธฐ๊ฐ: 2023.12.01 ~ 2023.12.31
+
+์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์ (25,000์)
+
+## ์ด๋ฒคํธ ๋ฐฐ์ง
+
+์ด๋ฒคํธ๋ก ๋ฐ์ ์ดํํ ๊ธ์ก์ ๋ฐ๋ผ ๊ฐ๊ธฐ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ๋ถ์ฌ
+(์ด๋ `์ดํํ ๊ธ์ก = ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ`์ผ๋ก ๊ณ์ฐ)
+
+- 5์ฒ์ ์ด์: ๋ณ
+- 1๋ง์ ์ด์: ํธ๋ฆฌ
+- 2๋ง์ ์ด์: ์ฐํ
+
+## ์ด๋ฒคํธ ์ฃผ์ ์ฌํญ
+
+- ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์๋ถํฐ ์ด๋ฒคํธ๊ฐ ์ ์ฉ
+- ์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์ฃผ๋ฌธํ ์ ์์
+- ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ (์ข
๋ฅ๊ฐ ์๋ ๊ฐ์)
+
+# ๊ฐ๋ฐ ์์ฒญ ์ฌํญ
+
+- [x] ๋ฐฉ๋ฌธํ ๋ ์ง ์
๋ ฅ
+ - [x] 1 ์ด์ 31 ์ดํ์ ์ซ์๋ง ์
๋ ฅ๋ฐ์
+- [x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ
+ - [x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ง ์
๋ ฅ๋ฐ์
+ - [x] ์ ํด์ง ํ์์ ๋ฉ๋ด๋ง ์
๋ ฅ๋ฐ์
+ - [x] ๋ฉ๋ด์ ๊ฐ์๋ 1 ์ด์์ ์ซ์๋ง ์
๋ ฅ๋ฐ์
+ - [x] ์ค๋ณต๋์ง ์์ ๋ฉ๋ด๋ง ์
๋ ฅ๋ฐ์
+- [x] ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ
+ - [x] ์ถ๋ ฅ ์์๋ ์์ ๋กญ๊ฒ ์ถ๋ ฅ
+- [x] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ์ฆ์ ๋ฉ๋ด ์ถ๋ ฅ
+ - [x] ์ฆ์ ์ด๋ฒคํธ์ ํด๋นํ์ง ์๋ ๊ฒฝ์ฐ `์์` ์ถ๋ ฅ
+- [x] ํํ ๋ด์ญ ์ถ๋ ฅ
+ - [x] ๊ณ ๊ฐ์๊ฒ ์ ์ฉ๋ ์ด๋ฒคํธ ๋ด์ญ๋ง ์ถ๋ ฅ
+ - [x] ์ ์ฉ๋ ์ด๋ฒคํธ๊ฐ ์๋ ๊ฒฝ์ฐ `์์` ์ถ๋ ฅ
+ - [x] ์ด๋ฒคํธ ์ถ๋ ฅ ์์๋ ์์ ๋กญ๊ฒ ์ถ๋ ฅ
+- [x] ์ดํํ ๊ธ์ก ์ถ๋ ฅ
+ - [x] `์ดํํ ๊ธ์ก = ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ`
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ
+ - [x] `ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก = ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก - ํ ์ธ๊ธ์ก`
+- [x] 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ
+ - [x] ์ด๋ฒคํธ ๋ฐฐ์ง๊ฐ ๋ถ์ฌ๋์ง ์๋ ๊ฒฝ์ฐ `์์` ์ถ๋ ฅ
+
+# ์
๋ ฅ ์์ธ ์ฌํญ
+
+- [x] ๋ฐฉ๋ฌธํ ๋ ์ง ์
๋ ฅ ์์ธ
+ - [x] 1 ์ด์ 31 ์ดํ์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ
+ - `[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+- [x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ
+ - [x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+ - [x] ๋ฉ๋ด์ ๊ฐ์๊ฐ 1 ์ด์์ ์ ์๊ฐ ์๋ ๊ฒฝ์ฐ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+ - [x] ๋ฉ๋ด์ ํ์์ด ์ ํด์ง ํ์์ ๋ฒ์ด๋ ๊ฒฝ์ฐ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+ - [x] ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์์ฒญ ์ฌํญ)
+ - [x] ๋ฉ๋ด ๊ฐ์๊ฐ 20๊ฐ๋ฅผ ์ด๊ณผํ ๊ฒฝ์ฐ
+ - `[ERROR] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์ถ๊ฐ)
+ - [x] ์๋ฃ๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ
+ - `[ERROR] ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.` (์ถ๊ฐ)
+- ์ด์ธ ๋ชจ๋ ์์ธ ์ฌํญ์ `[ERROR]` Prefix ์ฌ์ฉ
+
+# ๊ธฐ๋ฅ ๋ช
์ธ
+
+## Config
+
+- [x] Menu
+ - [x] ๋ฉ๋ด ์ด๋ฆ์ผ๋ก Menu ์ฐพ์ ๋ฐํ
+- [x] MenuType
+- [x] ErrorMessage
+
+## Controller
+
+- [x] EventController
+ - [x] ๋ ์ง๋ฅผ ์
๋ ฅ๋ฐ์ `Bill`์ ์์ฑ
+ - [x] ์ฃผ๋ฌธ์ ์
๋ ฅ๋ฐ์ `Bill`์ ์ถ๊ฐ
+ - [x] ์ ๋ ๊ณผ์ ์ค ์์ธ๊ฐ ๋ฐ์ํ ๊ฒฝ์ฐ ๋ฐ๋ณตํ์ฌ ์
๋ ฅ๋ฐ์
+ - [x] ํ์ํ ๋ชจ๋ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅ
+
+## Domain
+
+- [x] Order
+ - [x] ์ฃผ๋ฌธ ๋ฉ๋ด์ ์ฃผ๋ฌธ ์๋์ ์ ์ฅ
+ - [x] 1์ด์์ ์ฃผ๋ฌธ ์๋๋ง ์ฌ์ฉํ๋๋ก ๊ฒ์ฆ
+ - [x] ๊ฐ๊ฒฉ(`๋ฉ๋ด ๊ฐ๊ฒฉ x ์ฃผ๋ฌธ ์๋`)์ ๋ฐํ
+ - [x] ํน์ `Order`์ ๊ฐ์ ๋ฉ๋ด์ธ์ง ํ์ธ
+ - [x] `OrderDTO` ๋ฐํ
+ - [x] `List<Order>`์ ๋ชจ๋ ์ฃผ๋ฌธ ์๋์ ๋์ ํ์ฌ ํฉ์ฐ
+ - [x] `MenuType`์ ์กฐ๊ฑด์ผ๋ก ์ฌ์ฉํ ์ ์๋๋ก ์ค๋ฒ๋ก๋ฉ
+- [x] Bill
+ - [x] ์ฃผ๋ฌธ ๋ฆฌ์คํธ์ ๋ ์ง๋ฅผ ์ ์ฅ
+ - [x] ์ฃผ๋ฌธ์ ์ถ๊ฐ
+ - [x] ์ค๋ณต๋๋ ๋ฉ๋ด๊ฐ ์๋ ์ฃผ๋ฌธ์ธ์ง ๊ฒ์ฆ
+ - [x] ์ต๋ ์ฃผ๋ฌธ์๋ฅผ ๋์ง ์๋์ง ๊ฒ์ฆ
+ - [x] ์๋ฃ๋ง ์ฃผ๋ฌธํ๋์ง ๊ฒ์ฆ
+ - [x] ์ฃผ๋ฌธ์ ์ด๊ธฐํ
+ - [x] ์ ์ฒด ์ฃผ๋ฌธ ๊ธ์ก์ ๊ณ์ฐ
+ - [x] ํน์ ํ์
์ ๋ฉ๋ด ์ฃผ๋ฌธ๋์ ๋ฐํ
+ - [x] `CheckEventDate`์ ๋ฉ์๋ ์ค๋ฒ๋ก๋ฉ
+ - [x] ์ฃผ๋ฌธ ๋ ์ง๋ฅผ ๋ฐํ
+- [x] Date
+ - [x] ์์ฑ์ ์ํ ๋ ์ง๊ฐ 1 ~ 31 ๋ฒ์์ ๊ฐ์ธ์ง ๊ฒ์ฆ
+ - [x] ์์ผ์ ํ์ธ
+ - [x] ์ฃผ๋ง์ธ์ง ํ์ธ -> ํ์ผ ํ ์ธ, ์ฃผ๋ง ํ ์ธ
+ - [x] ๋ฌ๋ ฅ์ ๋ณ์ด ์๋ ํน๋ณํ ๋ ์ธ์ง ํ์ธ -> ํน๋ณ ํ ์ธ
+ - [x] ํฌ๋ฆฌ์ค๋ง์ค ์ด์ ์ธ์ง ํ์ธ -> ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - [x] ์ฒซ์งธ๋ ๋ก๋ถํฐ ์ผ๋ง๋ ์ง๋ฌ๋์ง ํ์ธ -> ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - [x] ๋ ์ง๋ฅผ ๋ฐํ
+- [x] EventHandler
+ - [x] ์ฆ์ ๋ฉ๋ด(์ดํ์ธ) ์กด์ฌ ์ฌ๋ถ
+ - [x] ํํ ๋ด์ญ
+ - [x] ํ ์ธ ๊ธ์ก
+ - [x] ์ดํํ ๊ธ์ก
+- [x] Event
+ - [x] ์ด๋ฒคํธ ์กฐ๊ฑด์ ๋ง๋์ง ํ์ธ
+ - [x] ์ด๋ฒคํธ ํํ์ ๋ฐํ
+- [x] Badge
+ - [x] ๊ฐ๊ฒฉ์ ๋ง๋ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ๋ฐํ
+
+## DTO
+
+- [x] BenefitDTO -> ํํ ์ด๋ฆ, ํํ ๊ธ์ก์ ์ ๋ฌํ๋ ๊ฐ์ฒด
+- [x] OrderDTO -> ๋ฉ๋ด ์ด๋ฆ, ์ฃผ๋ฌธ ๊ฐ์๋ฅผ ์ ๋ฌํ๋ ๊ฐ์ฒด
+
+## View
+
+- [x] InputView
+ - [x] ๋ ์ง ์
๋ ฅ
+ - [x] ์ฃผ๋ฌธ ์
๋ ฅ
+- [x] OutputView
+ - [x] ๊ฐ ์ ๋ชฉ ์ถ๋ ฅ
+ - [x] ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ
+ - [x] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+ - [x] ์ฆ์ ๋ฉ๋ด ์ถ๋ ฅ
+ - [x] ํํ ๋ด์ญ ์ถ๋ ฅ
+ - [x] ์ดํํ ๊ธ์ก ์ถ๋ ฅ
+ - [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ
+ - [x] ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ
+- [x] ViewMessage
+- [x] ViewTitle
+
+## Util
+
+- [x] IntParser
+- [x] OrderParser
+- [x] RetryExecutor
+
+# ํ
์คํธ ์ฝ๋
+
+- [x] Badge
+ - [x] `getBadgeNameWithBenefitPrice` ๋์ ํ์ธ
+ - [x] 0 -> ์์
+ - [x] 2500 -> ์์
+ - [x] 5000 -> ๋ณ
+ - [x] 9000 -> ๋ณ
+ - [x] 10000 -> ํธ๋ฆฌ
+ - [x] 17000 -> ํธ๋ฆฌ
+ - [x] 20000 -> ์ฐํ
+ - [x] 50000 -> ์ฐํ
+- [x] Bill
+ - [x] `from` ๋์ ํ์ธ
+ - [x] ์๋ชป๋ date ๊ฐ ์ฌ์ฉ์ ์์ธ ๋ฐ์ -> Date ํด๋์ค์์ ํ
์คํธ
+ - [x] `add` ๋์ ํ์ธ
+ - [x] `add` ์ค๋ณต๋ ๋ฉ๋ด ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] `add` 20๊ฐ ์ด์ ๋ฉ๋ด ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] ์ฌ๋ฌ ๋ฉ๋ด์ ์ด ์๋์ด 20๊ฐ ์ด์์ธ ๊ฒฝ์ฐ
+ - [x] ํ ๋ฉ๋ด์ ์๋์ด 20๊ฐ ์ด์์ธ ๊ฒฝ์ฐ
+ - [x] `clearOrder` ๋์ ํ์ธ
+ - [x] `getTotalPrice` ๋์ ํ์ธ
+ - [x] `getTypeCount` ๋์ ํ์ธ
+ - [x] DESSERT ํ์
ํ์ธ
+ - [x] MAIN ํ์
ํ์ธ
+ - [x] `getDateValue` ๋์ ํ์ธ
+ - [x] ์๋ฃ๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ ์์ธ ๋ฐ์
+ - [x] ์ด์ธ์ Date ๊ด๋ จ ๋ฉ์๋๋ Date ํด๋์ค์์ ํ
์คํธ
+- [x] Date
+ - [x] ์์ฑ ์ `validate` ๋์ ํ์ธ
+ - [x] 1 -> ๋์
+ - [x] 25 -> ๋์
+ - [x] 31 -> ๋์
+ - [x] ์์ฑ ์ `validate` ์์ธ ๋ฐ์
+ - [x] -5 -> ์์ธ ๋ฐ์
+ - [x] 0 -> ์์ธ ๋ฐ์
+ - [x] 32 -> ์์ธ ๋ฐ์
+ - [x] 75 -> ์์ธ ๋ฐ์
+ - [x] `isWeekend` ๋์ ํ์ธ
+ - [x] 1 -> true
+ - [x] 8 -> true
+ - [x] 16 -> true
+ - [x] 17 -> false
+ - [x] 25 -> false
+ - [x] 28 -> false
+ - [x] `isSpecialDay` ๋์ ํ์ธ
+ - [x] 3 -> true
+ - [x] 25 -> true
+ - [x] 31 -> true
+ - [x] 13 -> false
+ - [x] 22 -> false
+ - [x] `isNotPassedChristmas` ๋์ ํ์ธ
+ - [x] 1 -> true
+ - [x] 14 -> true
+ - [x] 25 -> true
+ - [x] 26 -> false
+ - [x] 31 -> false
+ - [x] `timePassedSinceFirstDay` ๋์ ํ์ธ
+ - [x] 1 -> 0
+ - [x] 18 -> 17
+ - [x] 25 -> 24
+- [x] Event
+ - [x] `getEventName` ๋์ ํ์ธ
+ - [x] `isDiscount` ๋์ ํ์ธ
+ - [x] `checkCondition` ๋์ ํ์ธ
+ - [x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ -> `isNotPassedChristmas`์์ ํ
์คํธ
+ - [x] ํ์ผ ํ ์ธ -> `isWeekend`์์ ํ
์คํธ
+ - [x] ์ฃผ๋ง ํ ์ธ -> `isWeekend`์์ ํ
์คํธ
+ - [x] ํน๋ณ ํ ์ธ -> `isSpecialDay`์์ ํ
์คํธ
+ - [x] ์ฆ์ ์ด๋ฒคํธ
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) = 120,000 -> true
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ ์๋ฌ๋(5) = 150,000 -> true
+ - [x] ๋ฐ๋นํ๋ฆฝ(1) + ์์ก์ด์ํ(1) = 60,000 -> false
+ - [x] `getBenefit` ๋์ ํ์ธ
+ - [x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - [x] 1 -> 1000
+ - [x] 11 -> 2000
+ - [x] 25 -> 3400
+ - [x] ํ์ผ ํ ์ธ
+ - [x] ์์ก์ด์ํ(1) + ๋ฐ๋นํ๋ฆฝ(1) -> 0
+ - [x] ํํ์ค(1) + ํด์ฐ๋ฌผํ์คํ(1) + ์ด์ฝ์ผ์ดํฌ(2) -> 4046
+ - [x] ๋ฐ๋นํ๋ฆฝ(2) + ์ด์ฝ์ผ์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(3) -> 10115
+ - [x] ์ฃผ๋ง ํ ์ธ
+ - [x] ์์ก์ด์ํ(2) + ์ ๋ก์ฝ๋ผ(2) -> 0
+ - [x] ํํ์ค(1) + ํฐ๋ณธ์คํ
์ดํฌ(1) -> 2023
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ(1) + ๋ฐ๋นํ๋ฆฝ(2) + ํด์ฐ๋ฌผํ์คํ(3) + ์ ๋ก์ฝ๋ผ(6) -> 12138
+ - [x] ํน๋ณ ํ ์ธ -> ํญ์ 1000
+ - [x] ์ฆ์ ์ด๋ฒคํธ -> ํญ์ 25000
+ - [x] ๋ชจ๋ ์ด๋ฒคํธ์์ ์ด์ฃผ๋ฌธ๊ธ์ก 10000์ ์ด์๋ถํฐ ์ด๋ฒคํธ ์ ์ฉ
+- [x] EventHandler
+ - [x] `hasChampagneGift` ๋์ ํ์ธ -> Event `checkCondition`์์ ํ
์คํธ
+ - [x] `getTotalDiscountPrice` ๋์ ํ์ธ
+ - [x] 1์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) -> 5046
+ - [x] 3์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) -> 10292
+ - [x] 13์ผ, ํด์ฐ๋ฌผํ์คํ(10) + ์ด์ฝ์ผ์ดํฌ(1) + ์์ด์คํฌ๋ฆผ(2) -> 8269
+ - [x] 25์ผ, ํฌ๋ฆฌ์ค๋ง์คํ์คํ(2) + ์ดํ์ธ(2) -> 4400
+ - [x] 30์ผ, ์์ ์๋ฌ๋(5) + ๋ฐ๋นํ๋ฆฝ(2) + ํฐ๋ณธ์คํ
์ดํฌ(1) + ๋ ๋์์ธ(2) -> 6069
+ - [x] `getTotalBenefitPrice` ๋์ ํ์ธ
+ - [x] 1์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) -> 30046
+ - [x] 3์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(2) -> 10292
+ - [x] 13์ผ, ํด์ฐ๋ฌผํ์คํ(10) + ์ด์ฝ์ผ์ดํฌ(1) + ์์ด์คํฌ๋ฆผ(2) -> 33269
+ - [x] 25์ผ, ํฌ๋ฆฌ์ค๋ง์คํ์คํ(2) + ์ดํ์ธ(2) -> 4400
+ - [x] 30์ผ, ์์ ์๋ฌ๋(5) + ๋ฐ๋นํ๋ฆฝ(2) + ํฐ๋ณธ์คํ
์ดํฌ(1) + ๋ ๋์์ธ(2) -> 31069
+ - [x] `getAllBenefit` ๋์ ํ์ธ
+ - [x] 1์ผ, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์์ด์คํฌ๋ฆผ(1) -> ํฌ๋ฆฌ์ค๋ง์ค(1000), ์ฃผ๋ง(4046)
+ - [x] 3์ผ, ํฐ๋ณธ์คํ
์ดํฌ(1) + ์์ด์คํฌ๋ฆผ(4) -> ํฌ๋ฆฌ์ค๋ง์ค(1200), ํ์ผ(8092), ํน๋ณ(1000)
+ - [x] 13์ผ, ํด์ฐ๋ฌผํ์คํ(10) + ์ด์ฝ์ผ์ดํฌ(1) + ์์ด์คํฌ๋ฆผ(2) -> ํฌ๋ฆฌ์ค๋ง์ค(2200), ํ์ผ(6069), ์ฆ์ (25000)
+ - [x] 25์ผ, ํฌ๋ฆฌ์ค๋ง์คํ์คํ(2) + ์ดํ์ธ(2) -> ํฌ๋ฆฌ์ค๋ง์ค(3400), ํน๋ณ(1000)
+ - [x] 30์ผ, ์์ ์๋ฌ๋(5) + ๋ฐ๋นํ๋ฆฝ(2) + ํฐ๋ณธ์คํ
์ดํฌ(1) + ๋ ๋์์ธ(2) -> ์ฃผ๋ง(6069), ์ฆ์ (25000)
+- [x] Order
+ - [x] `create` ๋์ ํ์ธ
+ - [x] ์๋ชป๋ ๋ฉ๋ด ์ด๋ฆ ์ฌ์ฉ์ ์์ธ ๋ฐ์ -> Menu ํด๋์ค์์ ํ
์คํธ
+ - [x] ์๋ชป๋ count ์ฌ์ฉ์ ์์ธ ๋ฐ์
+ - [x] `getPrice` ๋์ ํ์ธ
+ - [x] ํํ์ค(2) -> 11000
+ - [x] ๋ฐ๋นํ๋ฆฝ(3) -> 162000
+ - [x] ์์ด์คํฌ๋ฆผ(5) -> 25000
+ - [x] `isSameMenu` ๋์ ํ์ธ
+ - [x] ํํ์ค, ํํ์ค -> true
+ - [x] ๋ ๋์์ธ, ๋ ๋์์ธ -> true
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ, ์์ด์คํฌ๋ฆผ -> false
+ - [x] ์ด์ฝ์ผ์ดํฌ, ๋ฐ๋นํ๋ฆฝ -> false
+ - [x] `accumulateCount` ๋์ ํ์ธ
+ - [x] ํฐ๋ณธ์คํ
์ดํฌ(5) -> 5
+ - [x] ์์ก์ด์ํ(3) + ๋ฐ๋นํ๋ฆฝ(1) + ์์ด์คํฌ๋ฆผ(3) -> 7
+ - [x] `accumulateCount` type ์ฌ์ฉํ์ฌ ๋์ ํ์ธ
+ - [x] DESSERT, ํฐ๋ณธ์คํ
์ดํฌ(2) + ์ ๋ก์ฝ๋ผ(4) -> 0
+ - [x] MAIN, ์์ก์ด์คํ(3) + ๋ฐ๋นํ๋ฆฝ(1) + ํด์ฐ๋ฌผํ์คํ(2) + ์์ด์คํฌ๋ฆผ(5) -> 3
+- [x] Menu
+ - [x] `from` ๋์ ํ์ธ
+ - [x] ์์ก์ด์ํ -> Menu.SOUP
+ - [x] ํด์ฐ๋ฌผํ์คํ -> Menu.SEAFOOD_PASTA
+ - [x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด ์
๋ ฅ์ ์์ธ ํ์ธ
+- [x] IntParser
+ - [x] `parseIntOrThrow` ๋์ ํ์ธ
+ - [x] "123" -> 123
+ - [x] "-123" -> -123
+ - [x] "2147483647" -> 2147483647 (์ต๋๊ฐ)
+ - [x] "-2147483648" -> -2147483648 (์ต์๊ฐ)
+ - [x] ์ ์ํํ๊ฐ ์๋ ๋ฌธ์์ด ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] ABC
+ - [x] 12L
+ - [x] 13.5
+ - [x] Integer ๋ฒ์๋ฅผ ๋ฒ์ด๋ ๋ฌธ์์ด ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] 2147483648
+ - [x] -2147483649
+ - [x] 999999999999999
+- [x] OrderParser
+ - [x] `parseOrderOrThrow` ๋์ ํ์ธ
+ - [x] "ํํ์ค-1,์ ๋ก์ฝ๋ผ-2,ํฐ๋ณธ์คํ
์ดํฌ-5" -> ํํ์ค(1) + ์ ๋ก์ฝ๋ผ(2) + ํฐ๋ณธ์คํ
์ดํฌ(5)
+ - [x] "ํํ์ค - 1, ์ ๋ก์ฝ๋ผ- 2, ํฐ๋ณธ ์คํ
์ดํฌ -5" -> ํํ์ค(1) + ์ ๋ก์ฝ๋ผ(2) + ํฐ๋ณธ์คํ
์ดํฌ(5)
+ - [x] "ํฐ๋ณธ์คํ
์ดํฌ-1" -> ํฐ๋ณธ์คํ
์ดํฌ(1)
+ - [x] "ํด์ฐ๋ฌผํ์คํ-3 , " -> ํด์ฐ๋ฌผํ์คํ(3)
+ - [x] ์๋ชป๋ ํ์์ ์ฃผ๋ฌธ์ ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [x] "ํํ์ค: 1, ์ ๋ก์ฝ๋ผ: 2"
+ - [x] "ํํ์ค-1 ์ ๋ก์ฝ๋ผ-2 ํ์คํ-3"
+ - [x] "ํํ์ค 1 ์ ๋ก์ฝ๋ผ 2 ํ์คํ 3"
+ - [x] "ํํ์ค, ์ ๋ก์ฝ๋ผ, ํ์คํ"
+ - [x] "ํํ์ค -"
+ - [x] "- 3"
+- [x] OutputView
+ - [x] `printHelloMessage` ๋์ ํ์ธ
+ - [x] `printEventPreviewTitle` ๋์ ํ์ธ
+ - [x] `printOrder` ๋์ ํ์ธ
+ - [x] `printTotalPrice` ๋์ ํ์ธ
+ - [x] `printGift` ๋์ ํ์ธ
+ - [x] `printAllBenefit` ๋์ ํ์ธ
+ - [x] `printBenefitPrice` ๋์ ํ์ธ
+ - [x] `printAfterDiscountPrice` ๋์ ํ์ธ
+ - [x] `printBadge` ๋์ ํ์ธ | Unknown | ํด๋์ค๋ณ๋ก ์์ธ์ฌํญ ์์๋ ๊ธฐ๋ฅ์ ๊ผผ๊ผผํ ์์ฑํด์ ์ข์์ต๋๋ค! ํ๋ก๊ทธ๋จ์ ์กฐ๊ธ ์์ฝํด์ ์ ๋ฆฌํ ์ ๋ณด๋ ์์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,12 @@
+package christmas.config;
+
+public class Constant {
+ public static final int INIT_VALUE = 0;
+ public static final int FILTER_CONDITION = 0;
+ public static final int MIN_ORDER = 1;
+ public static final int MAX_ORDER = 20;
+
+ private Constant() {
+ // ์ธ์คํด์ค ์์ฑ ๋ฐฉ์ง
+ }
+} | Java | ์ฃผ๋ฌธ ์๋์ ๋ํ ์์๋ค์ ์ ์ฅํ์
จ๋๋ฐ, ํด๋์ค๋ช
์ด Constant์ฌ์ init value ๋ filter condition ์์๋ช
์ ์๋ฏธ๊ฐ ์ข ๋ช
ํํ์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค. ํ์ธ์ด ์ฝ๊ธฐ์ ์ฉ๋๊ฐ ๋ช
ํํ์ง ์์๊ฒ ๊ฐ์ต๋๋ค!
ํด๋์ค๋ช
์ OrderConstatns ์ ๊ฐ์ด ํ๋ฉด ์ข์๊ฒ ๊ฐ๋ค์.
์ต๋ ์ฃผ๋ฌธ ๊ฐฏ์๋ฅผ ์ธ์ ๋ ์ ์ฑ
๋ณ๊ฒฝ์ ๋ฐ๋ผ ๋ฐ๊พธ์๋ ค๊ณ ๋นผ๋ ๊ฒ์ด๋ผ๋ฉด ํจํค์ง ์์น๋ฅผ ๊ณ ๋ คํด๋ณด๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,22 @@
+package christmas.config;
+
+public enum ErrorMessage {
+ WRONG_DATE("์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค."),
+ WRONG_ORDER("์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค."),
+ OVER_MAX_ORDER("๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค."),
+ ONLY_DRINK_ORDER("์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.");
+
+ private static final String PREFIX = "[ERROR]";
+ private static final String SUFFIX = "๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String DELIMITER = " ";
+
+ private final String message;
+
+ ErrorMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return String.join(DELIMITER, PREFIX, message, SUFFIX);
+ }
+} | Java | ์ ๋ `class`๋ก ๊ตฌํํ๋๋ฐ ๋ค๋ฅธ ๋ถ๋ค ๋ณด๊ณ `enum`์ผ๋ก ๊ตฌํํด๋ณด๋ ค๊ตฌ์! ์ด๊ฑฐํ์ผ๋ก ๊ตฌํํ์ ๋๋ง์ ์ฅ์ ์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค! "์๋ฌ ๋ชจ์์ง์์ ์ด๋ฐ ์๋ฌ๋ฅผ ๊ฐ์ ธ์ค๋ ๊ตฌ๋~" ๋ผ๊ณ ์ฝ๊ธฐ ๋ ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,47 @@
+package christmas.config;
+
+import java.util.Arrays;
+
+public enum Menu {
+ SOUP("์์ก์ด์ํ", 6000, MenuType.APPETIZER),
+ TAPAS("ํํ์ค", 5500, MenuType.APPETIZER),
+ SALAD("์์ ์๋ฌ๋", 8000, MenuType.APPETIZER),
+ STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55000, MenuType.MAIN),
+ BARBECUE("๋ฐ๋นํ๋ฆฝ", 54000, MenuType.MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35000, MenuType.MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000, MenuType.MAIN),
+ CAKE("์ด์ฝ์ผ์ดํฌ", 15000, MenuType.DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5000, MenuType.DESSERT),
+ COLA("์ ๋ก์ฝ๋ผ", 3000, MenuType.DRINK),
+ WINE("๋ ๋์์ธ", 60000, MenuType.DRINK),
+ CHAMPAGNE("์ดํ์ธ", 25000, MenuType.DRINK);
+
+ private final String menuName;
+ private final int price;
+ private final MenuType type;
+
+ Menu(String menuName, int price, MenuType type) {
+ this.menuName = menuName;
+ this.price = price;
+ this.type = type;
+ }
+
+ public static Menu from(String menuName) {
+ return Arrays.stream(Menu.values())
+ .filter(it -> menuName.equals(it.menuName))
+ .findAny()
+ .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage()));
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public MenuType getType() {
+ return type;
+ }
+} | Java | ```suggestion
SOUP("์์ก์ด์ํ", 6_000, MenuType.APPETIZER),
```
๋ณ๊ฑฐ ์๋์ง๋ง ๊ฐ๊ฒฉ์ 3์๋ฆฌ ์ซ์ ๋ง๋ค '-' ์ธ๋๋ฐ ๋ฃ์ด์ฃผ์๋ฉด ๊ฐ๋
์ฑ์ ์ข์๊ฒ๊ฐ์ต๋๋ค. ์ค์๋ ์ค์ฌ์ฃผ๊ณ ์ |
@@ -0,0 +1,47 @@
+package christmas.config;
+
+import java.util.Arrays;
+
+public enum Menu {
+ SOUP("์์ก์ด์ํ", 6000, MenuType.APPETIZER),
+ TAPAS("ํํ์ค", 5500, MenuType.APPETIZER),
+ SALAD("์์ ์๋ฌ๋", 8000, MenuType.APPETIZER),
+ STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55000, MenuType.MAIN),
+ BARBECUE("๋ฐ๋นํ๋ฆฝ", 54000, MenuType.MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35000, MenuType.MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000, MenuType.MAIN),
+ CAKE("์ด์ฝ์ผ์ดํฌ", 15000, MenuType.DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5000, MenuType.DESSERT),
+ COLA("์ ๋ก์ฝ๋ผ", 3000, MenuType.DRINK),
+ WINE("๋ ๋์์ธ", 60000, MenuType.DRINK),
+ CHAMPAGNE("์ดํ์ธ", 25000, MenuType.DRINK);
+
+ private final String menuName;
+ private final int price;
+ private final MenuType type;
+
+ Menu(String menuName, int price, MenuType type) {
+ this.menuName = menuName;
+ this.price = price;
+ this.type = type;
+ }
+
+ public static Menu from(String menuName) {
+ return Arrays.stream(Menu.values())
+ .filter(it -> menuName.equals(it.menuName))
+ .findAny()
+ .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage()));
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public MenuType getType() {
+ return type;
+ }
+} | Java | ```suggestion
public static Menu getMenuBy(String menuName) {
```
์ ๋ง ๊ฐ์ ์คํ์ผ์ด ๋ฌ๋ผ์ ์ ๊ฐ ๊ผญ ์ ๋ต์ ์๋์ง๋ง ๋ฉ์๋๋ช
์ถ์ฒ๋๋ฆฝ๋๋ค! |
@@ -0,0 +1,5 @@
+package christmas.config;
+
+public enum MenuType {
+ APPETIZER, MAIN, DESSERT, DRINK
+} | Java | ์นดํ
๊ณ ๋ฆฌ ๋ฐ๋ก ์ด๊ฑฐํด์ ๊ตฌ๋ถํ์ ๊ฒ ๋์ค์ ๋ฌธ์๋ก ๋น๊ตํ๋ ๊ฒ๋ณด๋ค ์์ ์ฑ ์๊ฒ ๊ตฌํํ์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,26 @@
+package christmas.domain;
+
+import java.util.Arrays;
+
+public enum Badge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NOTHING("์์", 0);
+
+ private final String badgeName;
+ private final int threshold;
+
+ Badge(String badgeName, int threshold) {
+ this.badgeName = badgeName;
+ this.threshold = threshold;
+ }
+
+ public static String getBadgeNameWithBenefitPrice(int benefitPrice) {
+ return Arrays.stream(Badge.values())
+ .filter(it -> it.threshold <= benefitPrice)
+ .map(it -> it.badgeName)
+ .findFirst()
+ .orElse(NOTHING.badgeName);
+ }
+} | Java | ์ ๋ ์ด๋ ๊ฒ ๊ตฌํํ๋๋ฐ ๊ณ ๋ฏผํ๋ค๋ณด๋
๋ฑ์ง๊ฐ ๊ฐ์ง ๊ฐ๋
์ด `๊ฐ๊ฒฉ` ์ธ์ง `๋ฒ์`์ธ์ง ์ทจํฅ ์ฐจ์ด๋ผ๊ณ ์๊ฐํ๋๋ฐ ์ ๋ `๋ฒ์`๊ฐ ์กฐ๊ธ๋ ๋ฑ์ง๊ฐ ๊ฐ์ง ๊ฐ๋
์ด๋ผ๊ณ ์๊ฐ์ด ๋ค๋๋ผ๊ตฌ์ ๊ทธ๋์ ์์ ๊ธฐ์ค ๊ฐ๊ฒฉ๋์ ๋ฒ์๋ฅผ ๋ฃ์ด๋ณด๋ ๊ณ ๋ฏผ๋ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,81 @@
+package christmas.domain;
+
+import christmas.config.ErrorMessage;
+
+import java.util.Arrays;
+
+public class Date implements CheckEventDate {
+ private static final int WEEK_NUM = 7;
+ private static final int WEEK_DIFF = 4;
+ private static final int FIRST_DAY = 1;
+ private static final int LAST_DAY = 31;
+ private static final int CHRISTMAS = 25;
+
+ private final int date;
+
+ private Date(int date) {
+ validate(date);
+ this.date = date;
+ }
+
+ public static Date from(int date) {
+ return new Date(date);
+ }
+
+ private void validate(int date) {
+ if (date < FIRST_DAY || date > LAST_DAY) {
+ throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage());
+ }
+ }
+
+ private enum DayOfWeek {
+ SUN(0), MON(1), TUE(2), WED(3), THU(4), FRI(5), SAT(6);
+
+ private final int value;
+
+ DayOfWeek(int value) {
+ this.value = value;
+ }
+
+ public static DayOfWeek from(int value) {
+ return Arrays.stream(DayOfWeek.values())
+ .filter(it -> value == it.value)
+ .findAny()
+ .orElse(null);
+ }
+ }
+
+ /**
+ * 2023๋
12์์ ๊ธฐ์ค์ผ๋ก ํ์ฌ ๋ ์ง์ ๋ง๋ ์์ผ์ ๋ฐํํฉ๋๋ค.
+ * @return DayOfWeek (0: ์ผ์์ผ ~ 6: ํ ์์ผ)
+ */
+ private DayOfWeek getDayOfWeek() {
+ int dayValue = (date + WEEK_DIFF) % WEEK_NUM;
+ return DayOfWeek.from(dayValue);
+ }
+
+ @Override
+ public boolean isWeekend() {
+ DayOfWeek dayOfWeek = getDayOfWeek();
+ return dayOfWeek == DayOfWeek.FRI || dayOfWeek == DayOfWeek.SAT;
+ }
+
+ @Override
+ public boolean isSpecialDay() {
+ return getDayOfWeek() == DayOfWeek.SUN || date == CHRISTMAS;
+ }
+
+ @Override
+ public boolean isNotPassedChristmas() {
+ return date <= CHRISTMAS;
+ }
+
+ @Override
+ public int timePassedSinceFirstDay() {
+ return date - FIRST_DAY;
+ }
+
+ public int getDateValue() {
+ return date;
+ }
+} | Java | ์ด ํด๋์ค ๊ต์ฅํ ์ข์ ๊ฒ ๊ฐ์์ Date๋ผ๋ ๊ฐ๋
๋ ์ ๋ด๊ฒจ์๊ณ ํฌ๋ฆฌ์ค๋ง์ค๋ ์์ ์์ผ์ ๋ค๋ฅธ ๊ณณ์์ ๋ฐ์์ค๋ ๋ฐฉ์์ผ๋ก ๋ฐ๊พผ๋ค๋ฉด ํด๋น ์ ๋ณด๋ง ๊ฐ์๋ผ์ฐ๋ฉด ๊ณ์ ๋์๋๋ ํด๋์ค ๊ฐ์์.
java.time ์ด๋ผ๋ ์๋ฐ ํจํค์ง๋ฅผ ํ๋ ์ถ์ฒํด๋๋ฆด๊ฒ์
```
import java.time.LocalDate;
import java.time.DayOfWeek;
import java.time.format.TextStyle;
import java.util.Locale;
public class Main {
public static void main(String[] args) {
// ํน์ ๋ ์ง ์ค์
LocalDate date = LocalDate.of(2023, 11, 24); // ์: 2023๋
11์ 24์ผ
// ํด๋น ๋ ์ง์ ์์ผ์ ๊ฐ์ ธ์ด
DayOfWeek dayOfWeek = date.getDayOfWeek();
// ์์ผ์ ๋ฌธ์์ด๋ก ์ถ๋ ฅ (์: ํ๊ตญ์ด๋ก ์งง์ ํ์)
String dayOfWeekInKorean = dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.KOREAN);
System.out.println("์์ผ (ํ๊ตญ์ด): " + dayOfWeekInKorean);
}
}
``` |
@@ -0,0 +1,75 @@
+package christmas.domain;
+
+import christmas.config.Menu;
+import christmas.config.MenuType;
+
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+public enum Event {
+ CHRISTMAS(
+ "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ",
+ true,
+ Bill::isNotPassedChristmas,
+ bill -> bill.timePassedSinceFirstDay() * 100 + 1000
+ ),
+ WEEKDAY(
+ "ํ์ผ ํ ์ธ",
+ true,
+ bill -> !bill.isWeekend(),
+ bill -> bill.getTypeCount(MenuType.DESSERT) * 2023
+ ),
+ WEEKEND(
+ "์ฃผ๋ง ํ ์ธ",
+ true,
+ Bill::isWeekend,
+ bill -> bill.getTypeCount(MenuType.MAIN) * 2023
+ ),
+ SPECIAL(
+ "ํน๋ณ ํ ์ธ",
+ true,
+ Bill::isSpecialDay,
+ bill -> 1000
+ ),
+ CHAMPAGNE(
+ "์ฆ์ ์ด๋ฒคํธ",
+ false,
+ bill -> bill.getTotalPrice() >= 120000,
+ bill -> Menu.CHAMPAGNE.getPrice()
+ );
+
+ private static final int ALL_EVENT_THRESHOLD = 10000;
+
+ private final String eventName;
+ private final boolean isDiscount;
+ private final Predicate<Bill> condition;
+ private final Function<Bill, Integer> benefit;
+
+ Event(
+ String eventName,
+ boolean isDiscount,
+ Predicate<Bill> condition,
+ Function<Bill, Integer> benefit
+ ) {
+ this.eventName = eventName;
+ this.isDiscount = isDiscount;
+ this.condition = condition;
+ this.benefit = benefit;
+ }
+
+ public String getEventName() {
+ return eventName;
+ }
+
+ public boolean isDiscount() {
+ return isDiscount;
+ }
+
+ public boolean checkCondition(Bill bill) {
+ return condition.test(bill) && bill.getTotalPrice() >= ALL_EVENT_THRESHOLD;
+ }
+
+ public int getBenefit(Bill bill) {
+ return benefit.apply(bill);
+ }
+} | Java | ์ค ํ ์ธ์ด ์ ์ฉ ๋์๋์ง ๋ถ๋ฆฐ๊ฐ์ ๋ฃ์ด๋์ ๊ฒ์ด ๋งค์ฐ ์ข์๋ณด์
๋๋ค! ๋ฐฐ์๊ฐ๋๋ค.
ํด๋น ๋ด์ฉ์ ๋ฑ์ง์๋ ์ ์ฉํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,52 @@
+package christmas.util;
+
+import christmas.dto.OrderDTO;
+import christmas.config.ErrorMessage;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+public class OrderParser {
+ private static final String SEQUENCE_DELIMITER = ",";
+ private static final String ORDER_DELIMITER = "-";
+ private static final String ORDER_PATTERN = "[^-]+-[0-9]+";
+ private static final String REPLACE_TARGET = " ";
+ private static final String REPLACEMENT = "";
+
+ private OrderParser() {
+ // ์ธ์คํด์ค ์์ฑ ๋ฐฉ์ง
+ }
+
+ public static List<OrderDTO> parseOrderOrThrow(String orderSequence) {
+ List<OrderDTO> result = new ArrayList<>();
+ for (String order : splitOrder(trimAll(orderSequence))) {
+ result.add(parseOrderDTO(order));
+ }
+ return result;
+ }
+
+ private static List<String> splitOrder(String orderSequence) {
+ return List.of(orderSequence.split(SEQUENCE_DELIMITER));
+ }
+
+ private static OrderDTO parseOrderDTO(String order) {
+ validateOrderPattern(order);
+ String[] split = order.split(ORDER_DELIMITER);
+ try {
+ return new OrderDTO(split[0], IntParser.parseIntOrThrow(split[1]));
+ } catch (IndexOutOfBoundsException e) {
+ throw new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage());
+ }
+ }
+
+ private static String trimAll(String target) {
+ return target.replaceAll(REPLACE_TARGET, REPLACEMENT);
+ }
+
+ private static void validateOrderPattern(String order) {
+ if (!Pattern.matches(ORDER_PATTERN, order)) {
+ throw new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage());
+ }
+ }
+} | Java | ```suggestion
private static final Pattern ORDER_PATTERN = Pattern.compile("[^-]+-[0-9]+"); // ์ปดํ์ผ๋ ํจํด
``` |
@@ -0,0 +1,110 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.utils.EventSettings;
+import christmas.parser.EventDetailsParser;
+import christmas.view.EventView;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+public class ChristmasEventController implements EventController {
+ private static final String WEEKDAY_DISCOUNT_TYPE = "dessert";
+ private static final String WEEKEND_DISCOUNT_TYPE = "main";
+ private static final DecemberCalendar decemberCalendar = new DecemberCalendar();
+
+ private boolean canPresent = false;
+ private BigDecimal totalBenefitAmount = new BigDecimal(0);
+ private Map<Menu, Integer> orderDetails;
+ private Badge badge;
+ private String eventResultDetails = "";
+ private BigDecimal beforeEventApplied;
+
+ public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) {
+ beforeEventApplied = bill.getTotalPrice();
+ if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) {
+ this.orderDetails = order.getOrderDetails();
+ presentEvent(bill);
+ dDayDiscountEvent(reservationDay, bill);
+ weekdayDiscountEvent(reservationDay, bill);
+ weekendDiscountEvent(reservationDay, bill);
+ specialDayDiscountEvent(reservationDay, bill);
+ badgeEvent(totalBenefitAmount);
+ }
+ }
+
+ public void presentEvent(Bill bill) {
+ if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) {
+ canPresent = true;
+ BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount();
+
+ totalBenefitAmount = totalBenefitAmount.add(benefitValue);
+ eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue);
+ }
+ }
+
+ public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) {
+ if (reservationDay.dDayDiscountEventPeriod()) {
+ BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1);
+ BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount().
+ add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay)));
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekdayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekday(day.getDay())) {
+ long dessertCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(dessertCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekendDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekend(day.getDay())) {
+ long mainDishCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(mainDishCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void specialDayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isSpecialDay(day.getDay())) {
+ BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount();
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void badgeEvent(BigDecimal totalBenefitAmount) {
+ badge = Badge.getBadge(totalBenefitAmount);
+ }
+
+ public void showEventDiscountDetails(Bill bill) {
+ EventView.printPriceBeforeDiscount(beforeEventApplied);
+ EventView.printPresentDetails(canPresent);
+ EventView.printEventResultDetails(eventResultDetails);
+ EventView.printTotalBenefitAmount(totalBenefitAmount);
+ EventView.printPriceAfterDiscount(bill);
+ EventView.printBadge(badge);
+ }
+} | Java | 3์ฃผ ์ฐจ ์น ๋ฐฑ์๋ ๊ณตํต ํผ๋๋ฐฑ์ผ๋ก ํ๋(์ธ์คํด์ค ๋ณ์)์ ์๋ฅผ ์ค์ด๊ธฐ ์ํด ๋
ธ๋ ฅํ๋ค๋ผ๋ ํญ๋ชฉ์ด ์์๋๋ฐ์ ์ค๋ณต๋๋ ํญ๋ชฉ๋ค์ ํ๋์ result๋ก ๋ฌถ์ด์ ํ๋ฒ ๊ด๋ฆฌ๋ฅผ ํด๋ณด๋ ๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,110 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.utils.EventSettings;
+import christmas.parser.EventDetailsParser;
+import christmas.view.EventView;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+public class ChristmasEventController implements EventController {
+ private static final String WEEKDAY_DISCOUNT_TYPE = "dessert";
+ private static final String WEEKEND_DISCOUNT_TYPE = "main";
+ private static final DecemberCalendar decemberCalendar = new DecemberCalendar();
+
+ private boolean canPresent = false;
+ private BigDecimal totalBenefitAmount = new BigDecimal(0);
+ private Map<Menu, Integer> orderDetails;
+ private Badge badge;
+ private String eventResultDetails = "";
+ private BigDecimal beforeEventApplied;
+
+ public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) {
+ beforeEventApplied = bill.getTotalPrice();
+ if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) {
+ this.orderDetails = order.getOrderDetails();
+ presentEvent(bill);
+ dDayDiscountEvent(reservationDay, bill);
+ weekdayDiscountEvent(reservationDay, bill);
+ weekendDiscountEvent(reservationDay, bill);
+ specialDayDiscountEvent(reservationDay, bill);
+ badgeEvent(totalBenefitAmount);
+ }
+ }
+
+ public void presentEvent(Bill bill) {
+ if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) {
+ canPresent = true;
+ BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount();
+
+ totalBenefitAmount = totalBenefitAmount.add(benefitValue);
+ eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue);
+ }
+ }
+
+ public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) {
+ if (reservationDay.dDayDiscountEventPeriod()) {
+ BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1);
+ BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount().
+ add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay)));
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekdayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekday(day.getDay())) {
+ long dessertCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(dessertCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekendDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekend(day.getDay())) {
+ long mainDishCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(mainDishCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void specialDayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isSpecialDay(day.getDay())) {
+ BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount();
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void badgeEvent(BigDecimal totalBenefitAmount) {
+ badge = Badge.getBadge(totalBenefitAmount);
+ }
+
+ public void showEventDiscountDetails(Bill bill) {
+ EventView.printPriceBeforeDiscount(beforeEventApplied);
+ EventView.printPresentDetails(canPresent);
+ EventView.printEventResultDetails(eventResultDetails);
+ EventView.printTotalBenefitAmount(totalBenefitAmount);
+ EventView.printPriceAfterDiscount(bill);
+ EventView.printBadge(badge);
+ }
+} | Java | ๊ฐ์ธ์ ์ธ ์๊ฐ์ผ๋ก๋ ์ปจํธ๋กค๋ฌ์์ ๋๋ฉ์ธ์์ ํด์ผ ํ ์ญํ ๋ค์ ๋ง์ด ๊ฐ์ง๊ณ ์๋ ๊ฒ ๊ฐ์์ ์ด๋ฐ ๊ณ์ฐ์ด๋ ํ ์ธ์ ๋ํ ๋ด์ฉ๋ค์ ๋ฐ๋ก ์ด ์ญํ ์ ๋ด๋นํ๋ ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด์ ๊ทธ๊ณณ์์ ์ค์ค๋ก ์ผ์ ํ ์ ์๋๋ก ๊ฐ์ฒด์งํฅ์ ์ผ๋ก ์ค๊ณํด ๋ณด๋ ๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,110 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.utils.EventSettings;
+import christmas.parser.EventDetailsParser;
+import christmas.view.EventView;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+public class ChristmasEventController implements EventController {
+ private static final String WEEKDAY_DISCOUNT_TYPE = "dessert";
+ private static final String WEEKEND_DISCOUNT_TYPE = "main";
+ private static final DecemberCalendar decemberCalendar = new DecemberCalendar();
+
+ private boolean canPresent = false;
+ private BigDecimal totalBenefitAmount = new BigDecimal(0);
+ private Map<Menu, Integer> orderDetails;
+ private Badge badge;
+ private String eventResultDetails = "";
+ private BigDecimal beforeEventApplied;
+
+ public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) {
+ beforeEventApplied = bill.getTotalPrice();
+ if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) {
+ this.orderDetails = order.getOrderDetails();
+ presentEvent(bill);
+ dDayDiscountEvent(reservationDay, bill);
+ weekdayDiscountEvent(reservationDay, bill);
+ weekendDiscountEvent(reservationDay, bill);
+ specialDayDiscountEvent(reservationDay, bill);
+ badgeEvent(totalBenefitAmount);
+ }
+ }
+
+ public void presentEvent(Bill bill) {
+ if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) {
+ canPresent = true;
+ BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount();
+
+ totalBenefitAmount = totalBenefitAmount.add(benefitValue);
+ eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue);
+ }
+ }
+
+ public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) {
+ if (reservationDay.dDayDiscountEventPeriod()) {
+ BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1);
+ BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount().
+ add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay)));
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekdayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekday(day.getDay())) {
+ long dessertCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(dessertCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekendDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekend(day.getDay())) {
+ long mainDishCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(mainDishCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void specialDayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isSpecialDay(day.getDay())) {
+ BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount();
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void badgeEvent(BigDecimal totalBenefitAmount) {
+ badge = Badge.getBadge(totalBenefitAmount);
+ }
+
+ public void showEventDiscountDetails(Bill bill) {
+ EventView.printPriceBeforeDiscount(beforeEventApplied);
+ EventView.printPresentDetails(canPresent);
+ EventView.printEventResultDetails(eventResultDetails);
+ EventView.printTotalBenefitAmount(totalBenefitAmount);
+ EventView.printPriceAfterDiscount(bill);
+ EventView.printBadge(badge);
+ }
+} | Java | ํ๋์ ํจ์์์ ๋ค์ํ ์ผ์ ํ๊ณ ์๋ ๊ฒ ๊ฐ์๋ฐ ๊ธฐ๋ฅ์ ๋ถ๋ฆฌํด ๋ณด๋ ๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,26 @@
+package christmas.controller;
+
+import christmas.domain.Bill;
+import christmas.domain.Order;
+import christmas.domain.ReservationDay;
+
+import java.math.BigDecimal;
+
+public interface EventController {
+
+ void applyEvent(ReservationDay day, Order order, Bill bill);
+
+ void showEventDiscountDetails(Bill bill);
+
+ void presentEvent(Bill bill);
+
+ void dDayDiscountEvent(ReservationDay reservationDay, Bill bill);
+
+ void weekdayDiscountEvent(ReservationDay day, Bill bill);
+
+ void weekendDiscountEvent(ReservationDay day, Bill bill);
+
+ void specialDayDiscountEvent(ReservationDay day, Bill bill);
+
+ void badgeEvent(BigDecimal totalBenefitAmount);
+} | Java | EventController๋ฅผ interface๋ก ๋ง๋ค์ด์ ์ด๋ฒคํธ์ ๋ํ ๋ก์ง์ ๊ด๋ฆฌํ๋ ๊ฒ๋ณด๋ค ์ด๋ฒคํธ ๊ด๋ จ ๋๋ฉ์ธ์ interface๋ก ๋ง๋ค์ด์ ์ฌ์ฉํด ๋ณด๋ ๊ฑด ์ด๋จ๊น์? ๊ฐ์ฒด์งํฅ์ ๋ค๋ฃฌ ์ค๋ธ์ ํธ ์์ ์์ ๋น์ทํ ๋ด์ฉ์ด ์์ด์ ๋งํฌ ๋จ๊น๋๋ค. https://github.com/eternity-oop/object/tree/master/chapter13/src/main/java/org/eternity/movie/step02 |
@@ -0,0 +1,32 @@
+package christmas.domain;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.math.BigDecimal;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class BadgeTest {
+
+ @Test
+ @DisplayName("์ฐํ_๋ฑ์ง_๊ฒฝ๊ณ๊ฐ_ํ
์คํธ")
+ void getBadge_SantaBadgeAmount_ShouldReturnSantaBadge() {
+ BigDecimal santaBadgeAmount = new BigDecimal(20000);
+ assertEquals(Badge.SANTA_BADGE, Badge.getBadge(santaBadgeAmount));
+ }
+
+ @Test
+ @DisplayName("ํธ๋ฆฌ_๋ฑ์ง_๊ฒฝ๊ณ๊ฐ_ํ
์คํธ")
+ void getBadge_BetweenTreeAndSantaAmount_ShouldReturnTreeBadge() {
+ BigDecimal betweenTreeAndSantaAmount = new BigDecimal(15000);
+ assertEquals(Badge.TREE_BADGE, Badge.getBadge(betweenTreeAndSantaAmount));
+ }
+
+ @Test
+ @DisplayName("๋ณ_๋ฑ์ง_๊ฒฝ๊ณ๊ฐ_ํ
์คํธ")
+ void getBadge_StarBadgeAmount_ShouldReturnStarBadge() {
+ BigDecimal starBadgeAmount = new BigDecimal(5000);
+ assertEquals(Badge.STAR_BADGE, Badge.getBadge(starBadgeAmount));
+ }
+} | Java | import static org.junit.jupiter.api.Assertions.*; ๋ฅผ ์ฌ์ฉํ๊ธฐ๋ณด๋ค ๋ ๊ฐํธํ๊ฒ ํ
์คํธ๋ฅผ ํ ์ ์๋ import static org.junit.jupiter.api.Assertions.*;๋ฅผ ์ฌ์ฉํด ๋ณด๋ ๊ฑด ์ด๋จ๊น์?
https://jwkim96.tistory.com/168 |
@@ -0,0 +1,36 @@
+package christmas.domain;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.math.BigDecimal;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class BillTest {
+ Order testOrder = new Order();
+
+ @Test
+ @DisplayName("์ ์ฒด_๊ฐ๊ฒฉ_๊ณ์ฐ_ํ
์คํธ")
+ public void testBillTotalPriceCalculation() {
+ testOrder.takeOrder("์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-2,์ด์ฝ์ผ์ดํฌ-3");
+ Bill bill = new Bill(testOrder);
+
+ BigDecimal expectedTotalPrice = BigDecimal
+ .valueOf(1).multiply(Menu.APPETIZER_MUSHROOM_SOUP.getPrice())
+ .add(BigDecimal.valueOf(2).multiply(Menu.MAIN_T_BONE_STEAK.getPrice()))
+ .add(BigDecimal.valueOf(3).multiply(Menu.DESSERT_CHOCO_CAKE.getPrice()));
+
+ assertEquals(expectedTotalPrice, bill.getTotalPrice());
+ }
+
+ @Test
+ @DisplayName("๊ฐ๊ฒฉ_ํ ์ธ_์ ์ฉ_ํ
์คํธ")
+ public void testBillDiscountPrice() {
+ testOrder.takeOrder("์์ก์ด์ํ-5"); //30,000์
+ Bill bill = new Bill(testOrder);
+ bill.discountPrice(new BigDecimal(10000)); //30,000 - 10,000 ์
+
+ assertEquals(bill.getTotalPrice(), new BigDecimal(20000));
+ }
+} | Java | given when then ํจํด์ ์ฌ์ฉํด์ ํ
์คํธ์ฝ๋๋ฅผ ๋๋ ๋ณด๋ ๊ฑด ์ด๋จ๊น์?
https://brunch.co.kr/@springboot/292 |
@@ -0,0 +1,89 @@
+package christmas.domain;
+
+import christmas.utils.ErrorMessage;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class OrderTest {
+ String validInput = "ํฐ๋ณธ์คํ
์ดํฌ-2,์์ก์ด์ํ-2";
+
+ @Test
+ @DisplayName("์ฃผ๋ฌธ_์ ํจ๊ฐ_์
๋ ฅ_ํ
์คํธ")
+ void takeOrder_ValidInput_ShouldNotThrowException() {
+ Order order = new Order();
+ assertDoesNotThrow(() -> order.takeOrder(validInput));
+ }
+
+ @Test
+ @DisplayName("์ฃผ๋ฌธ_์ค๋ณต_์์ธ_ํ
์คํธ")
+ void takeOrder_DuplicateMenu_ShouldThrowException() {
+ Order order = new Order();
+ String duplicateMenuInput = "ํฐ๋ณธ์คํ
์ดํฌ-2,ํฐ๋ณธ์คํ
์ดํฌ-2";
+
+ IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, ()
+ -> order.takeOrder(duplicateMenuInput));
+ assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage());
+ }
+
+ @Test
+ @DisplayName("์ฃผ๋ฌธ_์
๋ ฅํ์_์์ธ_ํ
์คํธ")
+ void takeOrder_InvalidOrderFormat_ShouldThrowException() {
+ Order order = new Order();
+ String invalidFormatInput = "ํฐ๋ณธ์คํ
์ดํฌ+2";
+
+ IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, ()
+ -> order.takeOrder(invalidFormatInput));
+ assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage());
+ }
+
+ @Test
+ @DisplayName("์ฃผ๋ฌธ_๊ฐ์์ด๊ณผ_์์ธ_ํ
์คํธ")
+ void takeOrder_ExceedMaximumQuantity_ShouldThrowException() {
+ Order order = new Order();
+ String exceedQuantityInput = "ํฐ๋ณธ์คํ
์ดํฌ-20,์์ก์ด์ํ-10";
+
+ IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, ()
+ -> order.takeOrder(exceedQuantityInput));
+ assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage());
+ }
+
+ @Test
+ @DisplayName("์ฃผ๋ฌธ_์๋ฃ_์์ธ_ํ
์คํธ")
+ void takeOrder_OnlyBeverage_ValidInput_ShouldNotThrowException() {
+ Order order = new Order();
+ String onlyBeverageInput = "์ ๋ก์ฝ๋ผ-10";
+
+ IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, ()
+ -> order.takeOrder(onlyBeverageInput));
+ assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage());
+ }
+
+ @Test
+ @DisplayName("์ฃผ๋ฌธ_๊ณต๋ฐฑ_์์ธ_ํ
์คํธ")
+ void toString_OrderDetailsEmpty_ShouldReturnEmptyString() {
+ Order order = new Order();
+
+ IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, ()
+ -> order.takeOrder(""));
+ assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage());
+ assertEquals("", order.toString());
+ }
+
+ @Test
+ @DisplayName("์ฃผ๋ฌธ_๋ด์ญ_์ถ๋ ฅ_ํ
์คํธ")
+ void getOrderDetails_OrderDetailsNotEmpty_ShouldReturnOrderDetails() {
+ Order order = new Order();
+ order.takeOrder(validInput);
+
+ Map<Menu, Integer> expectedOrderDetails = new HashMap<>();
+ expectedOrderDetails.put(Menu.findMenu("ํฐ๋ณธ์คํ
์ดํฌ"), 2);
+ expectedOrderDetails.put(Menu.findMenu("์์ก์ด์ํ"), 2);
+
+ assertEquals(expectedOrderDetails, order.getOrderDetails());
+ }
+} | Java | ๋ฐ๋ณต๋๋ Order order = new Order(); ๋ @BeforeAll void setUp()์ ํ์ฉํ์ฌ์ ๋ฏธ๋ฆฌ ์์ฑํด ์ฃผ๋ ๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,110 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.utils.EventSettings;
+import christmas.parser.EventDetailsParser;
+import christmas.view.EventView;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+public class ChristmasEventController implements EventController {
+ private static final String WEEKDAY_DISCOUNT_TYPE = "dessert";
+ private static final String WEEKEND_DISCOUNT_TYPE = "main";
+ private static final DecemberCalendar decemberCalendar = new DecemberCalendar();
+
+ private boolean canPresent = false;
+ private BigDecimal totalBenefitAmount = new BigDecimal(0);
+ private Map<Menu, Integer> orderDetails;
+ private Badge badge;
+ private String eventResultDetails = "";
+ private BigDecimal beforeEventApplied;
+
+ public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) {
+ beforeEventApplied = bill.getTotalPrice();
+ if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) {
+ this.orderDetails = order.getOrderDetails();
+ presentEvent(bill);
+ dDayDiscountEvent(reservationDay, bill);
+ weekdayDiscountEvent(reservationDay, bill);
+ weekendDiscountEvent(reservationDay, bill);
+ specialDayDiscountEvent(reservationDay, bill);
+ badgeEvent(totalBenefitAmount);
+ }
+ }
+
+ public void presentEvent(Bill bill) {
+ if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) {
+ canPresent = true;
+ BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount();
+
+ totalBenefitAmount = totalBenefitAmount.add(benefitValue);
+ eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue);
+ }
+ }
+
+ public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) {
+ if (reservationDay.dDayDiscountEventPeriod()) {
+ BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1);
+ BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount().
+ add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay)));
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekdayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekday(day.getDay())) {
+ long dessertCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(dessertCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekendDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekend(day.getDay())) {
+ long mainDishCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(mainDishCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void specialDayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isSpecialDay(day.getDay())) {
+ BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount();
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void badgeEvent(BigDecimal totalBenefitAmount) {
+ badge = Badge.getBadge(totalBenefitAmount);
+ }
+
+ public void showEventDiscountDetails(Bill bill) {
+ EventView.printPriceBeforeDiscount(beforeEventApplied);
+ EventView.printPresentDetails(canPresent);
+ EventView.printEventResultDetails(eventResultDetails);
+ EventView.printTotalBenefitAmount(totalBenefitAmount);
+ EventView.printPriceAfterDiscount(bill);
+ EventView.printBadge(badge);
+ }
+} | Java | ํน์ ๋ฉ์๋์์๋ง ์ฌ์ฉ๋๋ ํ๋๋ ๋ก์ปฌํํ๊ณ ๋๋จธ์ง ๊ฐ์ฒดํํ์ฌ ํ๋ ์๋ฅผ ์ค์ฌ๋ณด๋ ๊ฑด ์ด๋จ๊น์?
์ถ๊ฐ๋ก `final` ํค์๋๋ฅผ ์๋ตํ์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,69 @@
+package christmas.controller;
+
+import christmas.domain.Bill;
+import christmas.domain.Order;
+import christmas.domain.ReservationDay;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+public class PlannerController {
+ private final Order order;
+ private final ReservationDay reservationDay;
+ private final EventController eventController;
+
+ private Bill bill;
+
+ public PlannerController(EventController eventController) {
+ this.eventController = eventController;
+ this.reservationDay = new ReservationDay();
+ this.order = new Order();
+ }
+
+ public void run() {
+ OutputView.printStartMessage();
+
+ try {
+ inputDay();
+ inputOrder();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+
+ processEvent();
+ }
+
+ private void inputDay() {
+ while (true) {
+ try {
+ String dayInput = InputView.inputDate();
+ reservationDay.reserveDay(dayInput);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private void inputOrder() {
+ while (true) {
+ try {
+ String orderInput = InputView.inputOrder();
+ order.takeOrder(orderInput.replace(" ", ""));
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private void processEvent() {
+ OutputView.printEventPreviewMessage(reservationDay.getDay());
+ OutputView.printOrderDetails(order);
+
+ bill = new Bill(order);
+
+ eventController.applyEvent(reservationDay, order, bill);
+ eventController.showEventDiscountDetails(bill);
+ }
+} | Java | ์์ธ ๋ฉ์์ง ์ถ๋ ฅ๋ `OutputView` ์์ ์ฒ๋ฆฌํ๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,69 @@
+package christmas.controller;
+
+import christmas.domain.Bill;
+import christmas.domain.Order;
+import christmas.domain.ReservationDay;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+public class PlannerController {
+ private final Order order;
+ private final ReservationDay reservationDay;
+ private final EventController eventController;
+
+ private Bill bill;
+
+ public PlannerController(EventController eventController) {
+ this.eventController = eventController;
+ this.reservationDay = new ReservationDay();
+ this.order = new Order();
+ }
+
+ public void run() {
+ OutputView.printStartMessage();
+
+ try {
+ inputDay();
+ inputOrder();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+
+ processEvent();
+ }
+
+ private void inputDay() {
+ while (true) {
+ try {
+ String dayInput = InputView.inputDate();
+ reservationDay.reserveDay(dayInput);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private void inputOrder() {
+ while (true) {
+ try {
+ String orderInput = InputView.inputOrder();
+ order.takeOrder(orderInput.replace(" ", ""));
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private void processEvent() {
+ OutputView.printEventPreviewMessage(reservationDay.getDay());
+ OutputView.printOrderDetails(order);
+
+ bill = new Bill(order);
+
+ eventController.applyEvent(reservationDay, order, bill);
+ eventController.showEventDiscountDetails(bill);
+ }
+} | Java | ํ๋๊ฐ ์์ฑ์๊ฐ ์๋ ๋ค๋ฅธ ๋ฉ์๋์์ ์ด๊ธฐํ๋๋๊ฒ ์ด์ํ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,35 @@
+package christmas.domain;
+
+import java.math.BigDecimal;
+
+public enum Badge {
+ SANTA_BADGE("์ฐํ", new BigDecimal(20000)),
+ TREE_BADGE("ํธ๋ฆฌ", new BigDecimal(10000)),
+ STAR_BADGE("๋ณ", new BigDecimal(5000));
+
+ private final String name;
+ private final BigDecimal standardAmount;
+
+ Badge(String name, BigDecimal standardAmount) {
+ this.name = name;
+ this.standardAmount = standardAmount;
+ }
+
+ public String getName() {
+ if (this == null) return "";
+ return name;
+ }
+
+ public static Badge getBadge(BigDecimal totalBenefit) {
+ if (totalBenefit.compareTo(SANTA_BADGE.standardAmount) >= 0) {
+ return SANTA_BADGE;
+ }
+ if (totalBenefit.compareTo(TREE_BADGE.standardAmount) >= 0) {
+ return TREE_BADGE;
+ }
+ if (totalBenefit.compareTo(STAR_BADGE.standardAmount) >= 0) {
+ return STAR_BADGE;
+ }
+ return null;
+ }
+} | Java | ์ด๋ฆ์ด `null`์ด ๋๋ ๊ฒฝ์ฐ๊ฐ ์์๊น์? |
@@ -0,0 +1,110 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.utils.EventSettings;
+import christmas.parser.EventDetailsParser;
+import christmas.view.EventView;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+public class ChristmasEventController implements EventController {
+ private static final String WEEKDAY_DISCOUNT_TYPE = "dessert";
+ private static final String WEEKEND_DISCOUNT_TYPE = "main";
+ private static final DecemberCalendar decemberCalendar = new DecemberCalendar();
+
+ private boolean canPresent = false;
+ private BigDecimal totalBenefitAmount = new BigDecimal(0);
+ private Map<Menu, Integer> orderDetails;
+ private Badge badge;
+ private String eventResultDetails = "";
+ private BigDecimal beforeEventApplied;
+
+ public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) {
+ beforeEventApplied = bill.getTotalPrice();
+ if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) {
+ this.orderDetails = order.getOrderDetails();
+ presentEvent(bill);
+ dDayDiscountEvent(reservationDay, bill);
+ weekdayDiscountEvent(reservationDay, bill);
+ weekendDiscountEvent(reservationDay, bill);
+ specialDayDiscountEvent(reservationDay, bill);
+ badgeEvent(totalBenefitAmount);
+ }
+ }
+
+ public void presentEvent(Bill bill) {
+ if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) {
+ canPresent = true;
+ BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount();
+
+ totalBenefitAmount = totalBenefitAmount.add(benefitValue);
+ eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue);
+ }
+ }
+
+ public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) {
+ if (reservationDay.dDayDiscountEventPeriod()) {
+ BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1);
+ BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount().
+ add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay)));
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekdayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekday(day.getDay())) {
+ long dessertCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(dessertCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void weekendDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isWeekend(day.getDay())) {
+ long mainDishCount = orderDetails.entrySet().stream()
+ .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType()))
+ .mapToLong(Map.Entry::getValue)
+ .sum();
+ BigDecimal discountValue = new BigDecimal(mainDishCount)
+ .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount());
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void specialDayDiscountEvent(ReservationDay day, Bill bill) {
+ if (decemberCalendar.isSpecialDay(day.getDay())) {
+ BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount();
+
+ bill.discountPrice(discountValue);
+ totalBenefitAmount = totalBenefitAmount.add(discountValue);
+ eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue);
+ }
+ }
+
+ public void badgeEvent(BigDecimal totalBenefitAmount) {
+ badge = Badge.getBadge(totalBenefitAmount);
+ }
+
+ public void showEventDiscountDetails(Bill bill) {
+ EventView.printPriceBeforeDiscount(beforeEventApplied);
+ EventView.printPresentDetails(canPresent);
+ EventView.printEventResultDetails(eventResultDetails);
+ EventView.printTotalBenefitAmount(totalBenefitAmount);
+ EventView.printPriceAfterDiscount(bill);
+ EventView.printBadge(badge);
+ }
+} | Java | `BigDecimal` ์ ๊ฒฝ์ฐ ์ผ๋ถ ๊ฐ์ ์บ์ฑํ๊ณ ์์ด ์์ฑ์ ๋์ `valueOf()` ๋ฉ์๋๋ฅผ ํตํด ๊ฐ์ฒด๋ฅผ ์ป๋๊ฒ ๋ ํจ์จ์ ์
๋๋ค! |
@@ -0,0 +1,35 @@
+package christmas.domain;
+
+import java.math.BigDecimal;
+
+public enum Badge {
+ SANTA_BADGE("์ฐํ", new BigDecimal(20000)),
+ TREE_BADGE("ํธ๋ฆฌ", new BigDecimal(10000)),
+ STAR_BADGE("๋ณ", new BigDecimal(5000));
+
+ private final String name;
+ private final BigDecimal standardAmount;
+
+ Badge(String name, BigDecimal standardAmount) {
+ this.name = name;
+ this.standardAmount = standardAmount;
+ }
+
+ public String getName() {
+ if (this == null) return "";
+ return name;
+ }
+
+ public static Badge getBadge(BigDecimal totalBenefit) {
+ if (totalBenefit.compareTo(SANTA_BADGE.standardAmount) >= 0) {
+ return SANTA_BADGE;
+ }
+ if (totalBenefit.compareTo(TREE_BADGE.standardAmount) >= 0) {
+ return TREE_BADGE;
+ }
+ if (totalBenefit.compareTo(STAR_BADGE.standardAmount) >= 0) {
+ return STAR_BADGE;
+ }
+ return null;
+ }
+} | Java | `null` ๋ฐํ์ด ์ํํ ๊ฒ ๊ฐ์์! `NONE` ๊ณผ ๊ฐ์ ์ธ์คํด์ค๋ฅผ ์ถ๊ฐํ์ฌ ์ด๋ฅผ ๋ฐํํ๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,32 @@
+package christmas.domain;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+public class Bill {
+ private final Map<Menu, Integer> orderDetails;
+
+ private BigDecimal totalPrice = new BigDecimal(0);
+
+ public Bill(Order order) {
+ this.orderDetails = order.getOrderDetails();
+ calculateTotalPrice();
+ }
+
+ private void calculateTotalPrice() {
+ for (Map.Entry<Menu, Integer> entry : orderDetails.entrySet()) {
+ Menu menu = entry.getKey();
+ int count = entry.getValue();
+ BigDecimal price = menu.getPrice().multiply(BigDecimal.valueOf(count));
+ totalPrice = totalPrice.add(price);
+ }
+ }
+
+ public void discountPrice(BigDecimal discountValue) {
+ totalPrice = totalPrice.subtract(discountValue);
+ }
+
+ public BigDecimal getTotalPrice() {
+ return totalPrice;
+ }
+} | Java | ๋ฉ๋ด ์
๋ ฅ ์ ์ด๋ฆ, ์๋ ์ธ์ ๋ค๋ฅธ ๊ฐ์ด ์ถ๊ฐ๋๋๊ฑธ ๊ฐ์ํ์ฌ `Map<K, V>` ๋์ ๋ณ๋์ ํด๋์ค ์ฌ์ฉ์ ์ด๋จ๊น์? |
@@ -0,0 +1,29 @@
+package christmas.domain;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class DecemberCalendar {
+ private final List<Integer> weekdays = Stream.of(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31)
+ .collect(Collectors.toList());
+ private final List<Integer> weekends = Stream.of(1, 2, 8, 9, 15, 16, 22, 23, 29, 30)
+ .collect(Collectors.toList());
+ private final List<Integer> specialDays = Stream.of(3, 10, 17, 24, 25, 31)
+ .collect(Collectors.toList());
+
+ public boolean isWeekday(int day) {
+ if (weekdays.contains(day)) return true;
+ return false;
+ }
+
+ public boolean isWeekend(int day) {
+ if (weekends.contains(day)) return true;
+ return false;
+ }
+
+ public boolean isSpecialDay(int day) {
+ if (specialDays.contains(day)) return true;
+ return false;
+ }
+} | Java | `Arrays.asList()` ๋์ Stream์ ์ฌ์ฉํ์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,62 @@
+package christmas.domain;
+
+import christmas.utils.ErrorMessage;
+import christmas.parser.Parser;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static christmas.domain.validator.OrderValidator.*;
+
+public class Order {
+ private final Map<Menu, Integer> orderDetails = new HashMap<>();
+ private int quantity = 0;
+
+ public void takeOrder(String input) {
+ List<String> eachOrderedMenu = Parser.inputToEachOrderedMenu(input);
+ try {
+ eachOrderedMenu.forEach(menuInformation -> processOrderedMenu(menuInformation));
+
+ calculateMenuQuantity();
+ validateOnlyBeverage(orderDetails);
+ validateMaximumQuantity(quantity);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage());
+ }
+ }
+
+ private void processOrderedMenu(String menuInformation) {
+ String[] menuNameAndNumber = Parser.inputToMenu(menuInformation);
+ String menuName = menuNameAndNumber[0];
+ int menuNumber = Parser.stringToIntPaser(menuNameAndNumber[1]);
+ Menu orderedMenu = Menu.findMenu(menuName);
+
+ validateDuplicateMenu(orderDetails, orderedMenu);
+ validateOrderFormat(menuNameAndNumber);
+ orderDetails.put(orderedMenu, menuNumber);
+ }
+
+ private void calculateMenuQuantity() {
+ for (int count : orderDetails.values()) {
+ quantity += count;
+ }
+ }
+
+ public String toString() {
+ StringBuilder output = new StringBuilder();
+ for (Map.Entry<Menu, Integer> entry : orderDetails.entrySet()) {
+ Menu menu = entry.getKey();
+ int count = entry.getValue();
+ output.append(menu.getMenuItem().getName())
+ .append(" ")
+ .append(count)
+ .append("๊ฐ\n");
+ }
+ return output.toString();
+ }
+
+ public Map<Menu, Integer> getOrderDetails() {
+ return orderDetails;
+ }
+} | Java | `int`์ ๊ฒฝ์ฐ ํ๋์์ ๊ฐ์ ๋์
ํ์ง ์์๋ ๊ฐ์ฒด ์์ฑ์ 0์ผ๋ก ์ด๊ธฐํ ๋ฉ๋๋ค! |
@@ -0,0 +1,62 @@
+package christmas.domain;
+
+import christmas.utils.ErrorMessage;
+import christmas.parser.Parser;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static christmas.domain.validator.OrderValidator.*;
+
+public class Order {
+ private final Map<Menu, Integer> orderDetails = new HashMap<>();
+ private int quantity = 0;
+
+ public void takeOrder(String input) {
+ List<String> eachOrderedMenu = Parser.inputToEachOrderedMenu(input);
+ try {
+ eachOrderedMenu.forEach(menuInformation -> processOrderedMenu(menuInformation));
+
+ calculateMenuQuantity();
+ validateOnlyBeverage(orderDetails);
+ validateMaximumQuantity(quantity);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage());
+ }
+ }
+
+ private void processOrderedMenu(String menuInformation) {
+ String[] menuNameAndNumber = Parser.inputToMenu(menuInformation);
+ String menuName = menuNameAndNumber[0];
+ int menuNumber = Parser.stringToIntPaser(menuNameAndNumber[1]);
+ Menu orderedMenu = Menu.findMenu(menuName);
+
+ validateDuplicateMenu(orderDetails, orderedMenu);
+ validateOrderFormat(menuNameAndNumber);
+ orderDetails.put(orderedMenu, menuNumber);
+ }
+
+ private void calculateMenuQuantity() {
+ for (int count : orderDetails.values()) {
+ quantity += count;
+ }
+ }
+
+ public String toString() {
+ StringBuilder output = new StringBuilder();
+ for (Map.Entry<Menu, Integer> entry : orderDetails.entrySet()) {
+ Menu menu = entry.getKey();
+ int count = entry.getValue();
+ output.append(menu.getMenuItem().getName())
+ .append(" ")
+ .append(count)
+ .append("๊ฐ\n");
+ }
+ return output.toString();
+ }
+
+ public Map<Menu, Integer> getOrderDetails() {
+ return orderDetails;
+ }
+} | Java | ๋๋ฉ์ธ์ด View์ ์์กดํ๋ ๊ฒ ๊ฐ์ต๋๋ค! `OutputView`์์ `Order`์ ๋ํ ๊ฐ์ ๊ฐ์ ธ์จ ํ ์ถ๋ ฅํ๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,18 @@
+package com.codesquad.baseball09.controller;
+
+import java.text.SimpleDateFormat;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("hcheck")
+public class HealthCheckRestController {
+
+ private final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ @GetMapping
+ public String healthCheck() {
+ return dateFormat.format(System.currentTimeMillis());
+ }
+} | Java | Spring Boot Actuator ์ฌ์ฉ ๊ฒํ ํด๋ด
๋๋ค.
https://supawer0728.github.io/2018/05/12/spring-actuator/ |
@@ -0,0 +1,99 @@
+package com.codesquad.baseball09.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class BattingLog {
+
+ private Long id;
+ private Long gameId;
+ private Long playerId;
+ private int inning;
+ private Status status;
+
+ private BattingLog(Long id, Long gameId, Long playerId, int inning,
+ Status status) {
+ this.id = id;
+ this.gameId = gameId;
+ this.playerId = playerId;
+ this.inning = inning;
+ this.status = status;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getGameId() {
+ return gameId;
+ }
+
+ public Long getPlayerId() {
+ return playerId;
+ }
+
+ public int getInning() {
+ return inning;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ @JsonIgnore
+ public int getStatusInt() {
+ return status.getValue();
+ }
+
+ public static class Builder {
+
+ private Long id;
+ private Long gameId;
+ private Long playerId;
+ private int inning;
+ private Status status;
+
+ public Builder() {
+ }
+
+ public Builder id(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder gameId(Long gameId) {
+ this.gameId = gameId;
+ return this;
+ }
+
+ public Builder playerId(Long playerId) {
+ this.playerId = playerId;
+ return this;
+ }
+
+ public Builder inning(int inning) {
+ this.inning = inning;
+ return this;
+ }
+
+ public Builder status(int value) {
+ this.status = Status.of(value);
+ return this;
+ }
+
+ public BattingLog build() {
+ return new BattingLog(id, gameId, playerId, inning, status);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", id)
+ .append("gameId", gameId)
+ .append("playerId", playerId)
+ .append("inning", inning)
+ .append("status", status)
+ .toString();
+ }
+} | Java | ์ ์ ํ builder ์ฌ์ฉ ์ข๋ค์. ๐ |
@@ -0,0 +1,282 @@
+package com.codesquad.baseball09.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import java.util.List;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+public class Board {
+
+ private Long gameId;
+ private int inning;
+
+ @JsonIgnore
+ private Long homeId;
+ private String homeName;
+ private int homeScore;
+ @JsonIgnore
+ private int homeOrder;
+
+ @JsonIgnore
+ private Long awayId;
+ private String awayName;
+ private int awayScore;
+ @JsonIgnore
+ private int awayOrder;
+
+ private boolean isBottom;
+
+ private Game game;
+ private InningStatus status;
+ private List<BattingLog> log;
+
+ private Board(Long gameId, int inning, Long homeId, String homeName, int homeScore, int homeOrder,
+ Long awayId, String awayName, int awayScore, int awayOrder, boolean isBottom, Game game,
+ InningStatus status,
+ List<BattingLog> log) {
+ this.gameId = gameId;
+ this.inning = inning;
+ this.homeId = homeId;
+ this.homeName = homeName;
+ this.homeScore = homeScore;
+ this.homeOrder = homeOrder;
+ this.awayId = awayId;
+ this.awayName = awayName;
+ this.awayScore = awayScore;
+ this.awayOrder = awayOrder;
+ this.isBottom = isBottom;
+ this.game = game;
+ this.status = status;
+ this.log = log;
+ }
+
+ public void change() {
+ this.homeOrder = 0;
+ this.awayOrder = 0;
+
+ if (isBottom) {
+ isBottom = false;
+ this.inning++;
+ } else {
+ isBottom = true;
+ }
+ }
+
+ public Long getGameId() {
+ return gameId;
+ }
+
+ public int getInning() {
+ return inning;
+ }
+
+ public Long getHomeId() {
+ return homeId;
+ }
+
+ public String getHomeName() {
+ return homeName;
+ }
+
+ public int getHomeScore() {
+ return homeScore;
+ }
+
+ public int getHomeOrder() {
+ return homeOrder;
+ }
+
+ public Long getAwayId() {
+ return awayId;
+ }
+
+ public String getAwayName() {
+ return awayName;
+ }
+
+ public int getAwayScore() {
+ return awayScore;
+ }
+
+ public int getAwayOrder() {
+ return awayOrder;
+ }
+
+ public boolean isBottom() {
+ return isBottom;
+ }
+
+ public Game getGame() {
+ return game;
+ }
+
+ public InningStatus getStatus() {
+ return status;
+ }
+
+ public List<BattingLog> getLog() {
+ return log;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("gameId", gameId)
+ .append("inning", inning)
+ .append("homeId", homeId)
+ .append("homeName", homeName)
+ .append("homeScore", homeScore)
+ .append("homeOrder", homeOrder)
+ .append("awayId", awayId)
+ .append("awayName", awayName)
+ .append("awayScore", awayScore)
+ .append("awayOrder", awayOrder)
+ .append("isBottom", isBottom)
+ .append("game", game)
+ .append("status", status)
+ .append("log", log)
+ .toString();
+ }
+
+ public static final class Builder {
+
+ private Long gameId;
+ private int inning;
+ private String homeName;
+ private Long homeId;
+ private int homeScore;
+ private int homeOrder;
+ private Long awayId;
+ private String awayName;
+ private int awayScore;
+ private int awayOrder;
+ private boolean isBottom;
+ private Game game;
+ private InningStatus status;
+ private List<BattingLog> log;
+
+ private Builder() {
+ }
+
+ public static Builder of() {
+ return new Builder();
+ }
+
+ public Builder(Board board) {
+ this.gameId = board.gameId;
+ this.inning = board.inning;
+ this.homeId = board.homeId;
+ this.homeName = board.homeName;
+ this.homeScore = board.homeScore;
+ this.homeOrder = board.homeOrder;
+ this.awayId = board.awayId;
+ this.awayName = board.awayName;
+ this.awayScore = board.awayScore;
+ this.awayOrder = board.awayOrder;
+ this.isBottom = board.isBottom;
+ this.game = board.game;
+ this.status = board.status;
+ this.log = board.log;
+ }
+
+ public Builder gameId(Long gameId) {
+ this.gameId = gameId;
+ return this;
+ }
+
+ public Builder inning(int inning) {
+ this.inning = inning;
+ return this;
+ }
+
+ public Builder homeId(Long homeId) {
+ this.homeId = homeId;
+ return this;
+ }
+
+ public Builder homeName(String homeName) {
+ this.homeName = homeName;
+ return this;
+ }
+
+ public Builder homeScore(int homeScore) {
+ this.homeScore = homeScore;
+ return this;
+ }
+
+ public Builder homeOrder(int homeOrder) {
+ if (homeOrder > 8) {
+ this.homeOrder = 0;
+ } else {
+ this.homeOrder = homeOrder;
+ }
+ return this;
+ }
+
+ public Builder awayId(Long awayId) {
+ this.awayId = awayId;
+ return this;
+ }
+
+ public Builder awayName(String awayName) {
+ this.awayName = awayName;
+ return this;
+ }
+
+ public Builder awayScore(int awayScore) {
+ this.awayScore = awayScore;
+ return this;
+ }
+
+ public Builder awayOrder(int awayOrder) {
+ if (awayOrder > 8) {
+ this.awayOrder = 0;
+ } else {
+ this.awayOrder = awayOrder;
+ }
+ return this;
+ }
+
+ public Builder isBottom(boolean isBottom) {
+ this.isBottom = isBottom;
+ return this;
+ }
+
+ public Builder game(Game game) {
+ this.game = game;
+ this.homeId(game.getHomeTeamId());
+ this.awayId(game.getAwayTeamId());
+ return this;
+ }
+
+ public Builder status(InningStatus status) {
+ this.status = status;
+ return this;
+ }
+
+ public Builder score(List<Score> scores) {
+ for (int i = 0; i < scores.size(); i++) {
+ Score score = scores.get(i);
+ if (score.getTeamId().equals(homeId)) {
+ homeName(score.getName());
+ homeScore(score.getScore());
+ }
+ if (score.getTeamId().equals(awayId)) {
+ awayName(score.getName());
+ awayScore(score.getScore());
+ }
+ }
+ return this;
+ }
+
+ public Builder log(List<BattingLog> log) {
+ this.log = log;
+ return this;
+ }
+
+ public Board build() {
+ return new Board(gameId, inning, homeId, homeName, homeScore, homeOrder, awayId, awayName,
+ awayScore, awayOrder, isBottom, game, status, log);
+ }
+ }
+} | Java | ์ธ์๊ฐ ๋ง์ด ํ์ํ ์์ฑ์๋ฅผ `private` ํ๊ฒ ๊ฐ๋ฆฌ๋ ๊ตฌํ ์์ฃผ ์ข์ต๋๋ค! ๐ฏ ๐ฅ |
@@ -0,0 +1,282 @@
+package com.codesquad.baseball09.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import java.util.List;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+public class Board {
+
+ private Long gameId;
+ private int inning;
+
+ @JsonIgnore
+ private Long homeId;
+ private String homeName;
+ private int homeScore;
+ @JsonIgnore
+ private int homeOrder;
+
+ @JsonIgnore
+ private Long awayId;
+ private String awayName;
+ private int awayScore;
+ @JsonIgnore
+ private int awayOrder;
+
+ private boolean isBottom;
+
+ private Game game;
+ private InningStatus status;
+ private List<BattingLog> log;
+
+ private Board(Long gameId, int inning, Long homeId, String homeName, int homeScore, int homeOrder,
+ Long awayId, String awayName, int awayScore, int awayOrder, boolean isBottom, Game game,
+ InningStatus status,
+ List<BattingLog> log) {
+ this.gameId = gameId;
+ this.inning = inning;
+ this.homeId = homeId;
+ this.homeName = homeName;
+ this.homeScore = homeScore;
+ this.homeOrder = homeOrder;
+ this.awayId = awayId;
+ this.awayName = awayName;
+ this.awayScore = awayScore;
+ this.awayOrder = awayOrder;
+ this.isBottom = isBottom;
+ this.game = game;
+ this.status = status;
+ this.log = log;
+ }
+
+ public void change() {
+ this.homeOrder = 0;
+ this.awayOrder = 0;
+
+ if (isBottom) {
+ isBottom = false;
+ this.inning++;
+ } else {
+ isBottom = true;
+ }
+ }
+
+ public Long getGameId() {
+ return gameId;
+ }
+
+ public int getInning() {
+ return inning;
+ }
+
+ public Long getHomeId() {
+ return homeId;
+ }
+
+ public String getHomeName() {
+ return homeName;
+ }
+
+ public int getHomeScore() {
+ return homeScore;
+ }
+
+ public int getHomeOrder() {
+ return homeOrder;
+ }
+
+ public Long getAwayId() {
+ return awayId;
+ }
+
+ public String getAwayName() {
+ return awayName;
+ }
+
+ public int getAwayScore() {
+ return awayScore;
+ }
+
+ public int getAwayOrder() {
+ return awayOrder;
+ }
+
+ public boolean isBottom() {
+ return isBottom;
+ }
+
+ public Game getGame() {
+ return game;
+ }
+
+ public InningStatus getStatus() {
+ return status;
+ }
+
+ public List<BattingLog> getLog() {
+ return log;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("gameId", gameId)
+ .append("inning", inning)
+ .append("homeId", homeId)
+ .append("homeName", homeName)
+ .append("homeScore", homeScore)
+ .append("homeOrder", homeOrder)
+ .append("awayId", awayId)
+ .append("awayName", awayName)
+ .append("awayScore", awayScore)
+ .append("awayOrder", awayOrder)
+ .append("isBottom", isBottom)
+ .append("game", game)
+ .append("status", status)
+ .append("log", log)
+ .toString();
+ }
+
+ public static final class Builder {
+
+ private Long gameId;
+ private int inning;
+ private String homeName;
+ private Long homeId;
+ private int homeScore;
+ private int homeOrder;
+ private Long awayId;
+ private String awayName;
+ private int awayScore;
+ private int awayOrder;
+ private boolean isBottom;
+ private Game game;
+ private InningStatus status;
+ private List<BattingLog> log;
+
+ private Builder() {
+ }
+
+ public static Builder of() {
+ return new Builder();
+ }
+
+ public Builder(Board board) {
+ this.gameId = board.gameId;
+ this.inning = board.inning;
+ this.homeId = board.homeId;
+ this.homeName = board.homeName;
+ this.homeScore = board.homeScore;
+ this.homeOrder = board.homeOrder;
+ this.awayId = board.awayId;
+ this.awayName = board.awayName;
+ this.awayScore = board.awayScore;
+ this.awayOrder = board.awayOrder;
+ this.isBottom = board.isBottom;
+ this.game = board.game;
+ this.status = board.status;
+ this.log = board.log;
+ }
+
+ public Builder gameId(Long gameId) {
+ this.gameId = gameId;
+ return this;
+ }
+
+ public Builder inning(int inning) {
+ this.inning = inning;
+ return this;
+ }
+
+ public Builder homeId(Long homeId) {
+ this.homeId = homeId;
+ return this;
+ }
+
+ public Builder homeName(String homeName) {
+ this.homeName = homeName;
+ return this;
+ }
+
+ public Builder homeScore(int homeScore) {
+ this.homeScore = homeScore;
+ return this;
+ }
+
+ public Builder homeOrder(int homeOrder) {
+ if (homeOrder > 8) {
+ this.homeOrder = 0;
+ } else {
+ this.homeOrder = homeOrder;
+ }
+ return this;
+ }
+
+ public Builder awayId(Long awayId) {
+ this.awayId = awayId;
+ return this;
+ }
+
+ public Builder awayName(String awayName) {
+ this.awayName = awayName;
+ return this;
+ }
+
+ public Builder awayScore(int awayScore) {
+ this.awayScore = awayScore;
+ return this;
+ }
+
+ public Builder awayOrder(int awayOrder) {
+ if (awayOrder > 8) {
+ this.awayOrder = 0;
+ } else {
+ this.awayOrder = awayOrder;
+ }
+ return this;
+ }
+
+ public Builder isBottom(boolean isBottom) {
+ this.isBottom = isBottom;
+ return this;
+ }
+
+ public Builder game(Game game) {
+ this.game = game;
+ this.homeId(game.getHomeTeamId());
+ this.awayId(game.getAwayTeamId());
+ return this;
+ }
+
+ public Builder status(InningStatus status) {
+ this.status = status;
+ return this;
+ }
+
+ public Builder score(List<Score> scores) {
+ for (int i = 0; i < scores.size(); i++) {
+ Score score = scores.get(i);
+ if (score.getTeamId().equals(homeId)) {
+ homeName(score.getName());
+ homeScore(score.getScore());
+ }
+ if (score.getTeamId().equals(awayId)) {
+ awayName(score.getName());
+ awayScore(score.getScore());
+ }
+ }
+ return this;
+ }
+
+ public Builder log(List<BattingLog> log) {
+ this.log = log;
+ return this;
+ }
+
+ public Board build() {
+ return new Board(gameId, inning, homeId, homeName, homeScore, homeOrder, awayId, awayName,
+ awayScore, awayOrder, isBottom, game, status, log);
+ }
+ }
+} | Java | `else` ์์ด ๊ตฌํํด๋ณผ ์ ์์ง ์์์๊น์? |
@@ -0,0 +1,196 @@
+package com.codesquad.baseball09.model;
+
+import static com.codesquad.baseball09.model.Status.BALL;
+import static com.codesquad.baseball09.model.Status.HIT;
+import static com.codesquad.baseball09.model.Status.OUT;
+import static com.codesquad.baseball09.model.Status.STRIKE;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class InningStatus {
+
+ @JsonIgnore
+ private Long id;
+ private Long gameId;
+ private int inning;
+ private int strike;
+ private int ball;
+ private int out;
+ private int hit;
+
+ public InningStatus(Long id, Long gameId, int inning, int strike, int ball, int out, int hit) {
+ this.id = id;
+ this.gameId = gameId;
+ this.inning = inning;
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ private InningStatus(Long gameId, int inning, int strike, int ball, int out, int hit) {
+ this.gameId = gameId;
+ this.inning = inning;
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ public InningStatus(int strike, int ball, int out, int hit) {
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ public static InningStatus of(Long gameId, int inning, int strike, int ball, int out, int hit) {
+ return new InningStatus(gameId, inning, strike, ball, out, hit);
+ }
+
+ public int plus(Status status) {
+ int value = 0;
+
+ if (STRIKE.equals(status)) {
+ strike++;
+ value = checkThreeStrike();
+ } else if (BALL.equals(status)) {
+ ball++;
+ value = checkFourBall();
+ } else if (OUT.equals(status)) {
+ out++;
+ resetStrikeAndBall();
+ value = checkThreeOut();
+ } else if (HIT.equals(status)) {
+ hit++;
+ resetStrikeAndBall();
+ value = checkFourHit();
+ }
+ return value;
+ }
+
+ private void resetStrikeAndBall() {
+ this.strike = 0;
+ this.ball = 0;
+ }
+
+ private void resetAll() {
+ resetStrikeAndBall();
+ this.out = 0;
+ this.hit = 0;
+ }
+
+ private int checkFourHit() {
+ if (this.hit == 4) {
+ resetStrikeAndBall();
+ this.hit--;
+ return 1;
+ }
+ return 0;
+ }
+
+ private int checkThreeOut() {
+ if (this.out == 3) {
+ resetAll();
+ return -1;
+ }
+ return 0;
+ }
+
+ private int checkFourBall() {
+ if (this.ball == 4) {
+ resetStrikeAndBall();
+ plus(HIT);
+ }
+ return 2;
+ }
+
+ private int checkThreeStrike() {
+ if (this.strike == 3) {
+ resetStrikeAndBall();
+ plus(OUT);
+ }
+ return 2;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getGameId() {
+ return gameId;
+ }
+
+ public int getInning() {
+ return inning;
+ }
+
+ public int getStrike() {
+ return strike;
+ }
+
+ public int getBall() {
+ return ball;
+ }
+
+ public int getOut() {
+ return out;
+ }
+
+ public int getHit() {
+ return hit;
+ }
+
+ public static final class Builder {
+
+ private Long id;
+ private Long gameId;
+ private int inning;
+ private int strike;
+ private int ball;
+ private int out;
+ private int hit;
+
+ public Builder() {
+ }
+
+ public Builder id(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder gameId(Long gameId) {
+ this.gameId = gameId;
+ return this;
+ }
+
+ public Builder inning(int inning) {
+ this.inning = inning;
+ return this;
+ }
+
+ public Builder strike(int strike) {
+ this.strike = strike;
+ return this;
+ }
+
+ public Builder ball(int ball) {
+ this.ball = ball;
+ return this;
+ }
+
+ public Builder out(int out) {
+ this.out = out;
+ return this;
+ }
+
+ public Builder hit(int hit) {
+ this.hit = hit;
+ return this;
+ }
+
+ public InningStatus build() {
+ return new InningStatus(id, gameId, inning, strike, ball, out, hit);
+ }
+ }
+} | Java | ๋ค ๊ฐ์ ํ์์ ๋ํด ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ํด์ผ ํ๋ค ๋ณด๋, ๋ค ๊ฐ์ `case` ๋ฅผ ๊ฐ๋ `switch` ๋ฌธ๊ณผ ๊ฐ์ ๊ตฌํ์ด ๋์ค๊ฒ ๋์์ต๋๋ค.
์ด๋ฅผ ์ด๋ป๊ฒ ๊ฐ์ฒด์งํฅ์ ์ผ๋ก, ๊น๋ํ๊ฒ ํ ์ ์์๊น์.
๋จ์ํ ์๊ฐํด๋ณด๊ธฐ๋ก๋ `InningCount` ๋ผ๋ ๊ฐ์ฒด๊ฐ `BallCount` ๊ฐ์ฒด๋ฅผ ๋ค์ ๊ฐ๊ณ ์์ผ๋ฉด์, ์์ ์นด์ดํธ์ ๋ณผ ์นด์ดํธ๋ฅผ ๊ด๋ฆฌํ๋ ๋ฐฉ์์ด ๋ ์ค๋ฆ
๋๋ค.
๊ฐ ํ์์ ํด๋นํ๋ `enum` ์ ๊ฐ์ฒด์ ๋๊ธฐ๋ฉด ๊ทธ ๊ฐ์ฒด๊ฐ ๋๋จธ์ง ์ผ์ ์ฒ๋ฆฌํ๊ฒ ๋๋ ๊ฑฐ์ฃ .
ํ ๋ฒ ์๊ฐํด๋ณด์๊ณ ๋๋๊ธ๋ก ๊ณ์ ๊ตฌํ์ ๋ํด ์๊ฒฌ ๋๋ ๋ณด๋ฉด ์ฌ๋ฐ๊ฒ ๋ค์. |
@@ -0,0 +1,18 @@
+package com.codesquad.baseball09.controller;
+
+import java.text.SimpleDateFormat;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("hcheck")
+public class HealthCheckRestController {
+
+ private final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ @GetMapping
+ public String healthCheck() {
+ return dateFormat.format(System.currentTimeMillis());
+ }
+} | Java | ๋ค์ ํ๋ก์ ํธ์ ํ๋ฒ ์ ์ฉํด๋ณด๊ฒ ์ต๋๋ค |
@@ -0,0 +1,196 @@
+package com.codesquad.baseball09.model;
+
+import static com.codesquad.baseball09.model.Status.BALL;
+import static com.codesquad.baseball09.model.Status.HIT;
+import static com.codesquad.baseball09.model.Status.OUT;
+import static com.codesquad.baseball09.model.Status.STRIKE;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class InningStatus {
+
+ @JsonIgnore
+ private Long id;
+ private Long gameId;
+ private int inning;
+ private int strike;
+ private int ball;
+ private int out;
+ private int hit;
+
+ public InningStatus(Long id, Long gameId, int inning, int strike, int ball, int out, int hit) {
+ this.id = id;
+ this.gameId = gameId;
+ this.inning = inning;
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ private InningStatus(Long gameId, int inning, int strike, int ball, int out, int hit) {
+ this.gameId = gameId;
+ this.inning = inning;
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ public InningStatus(int strike, int ball, int out, int hit) {
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ public static InningStatus of(Long gameId, int inning, int strike, int ball, int out, int hit) {
+ return new InningStatus(gameId, inning, strike, ball, out, hit);
+ }
+
+ public int plus(Status status) {
+ int value = 0;
+
+ if (STRIKE.equals(status)) {
+ strike++;
+ value = checkThreeStrike();
+ } else if (BALL.equals(status)) {
+ ball++;
+ value = checkFourBall();
+ } else if (OUT.equals(status)) {
+ out++;
+ resetStrikeAndBall();
+ value = checkThreeOut();
+ } else if (HIT.equals(status)) {
+ hit++;
+ resetStrikeAndBall();
+ value = checkFourHit();
+ }
+ return value;
+ }
+
+ private void resetStrikeAndBall() {
+ this.strike = 0;
+ this.ball = 0;
+ }
+
+ private void resetAll() {
+ resetStrikeAndBall();
+ this.out = 0;
+ this.hit = 0;
+ }
+
+ private int checkFourHit() {
+ if (this.hit == 4) {
+ resetStrikeAndBall();
+ this.hit--;
+ return 1;
+ }
+ return 0;
+ }
+
+ private int checkThreeOut() {
+ if (this.out == 3) {
+ resetAll();
+ return -1;
+ }
+ return 0;
+ }
+
+ private int checkFourBall() {
+ if (this.ball == 4) {
+ resetStrikeAndBall();
+ plus(HIT);
+ }
+ return 2;
+ }
+
+ private int checkThreeStrike() {
+ if (this.strike == 3) {
+ resetStrikeAndBall();
+ plus(OUT);
+ }
+ return 2;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getGameId() {
+ return gameId;
+ }
+
+ public int getInning() {
+ return inning;
+ }
+
+ public int getStrike() {
+ return strike;
+ }
+
+ public int getBall() {
+ return ball;
+ }
+
+ public int getOut() {
+ return out;
+ }
+
+ public int getHit() {
+ return hit;
+ }
+
+ public static final class Builder {
+
+ private Long id;
+ private Long gameId;
+ private int inning;
+ private int strike;
+ private int ball;
+ private int out;
+ private int hit;
+
+ public Builder() {
+ }
+
+ public Builder id(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder gameId(Long gameId) {
+ this.gameId = gameId;
+ return this;
+ }
+
+ public Builder inning(int inning) {
+ this.inning = inning;
+ return this;
+ }
+
+ public Builder strike(int strike) {
+ this.strike = strike;
+ return this;
+ }
+
+ public Builder ball(int ball) {
+ this.ball = ball;
+ return this;
+ }
+
+ public Builder out(int out) {
+ this.out = out;
+ return this;
+ }
+
+ public Builder hit(int hit) {
+ this.hit = hit;
+ return this;
+ }
+
+ public InningStatus build() {
+ return new InningStatus(id, gameId, inning, strike, ball, out, hit);
+ }
+ }
+} | Java | @wheejuni ๋ฆ๊ฒ ๋ตํด๋๋ ค ์ฃ์กํฉ๋๋ค..
ํ์ฌ `InningStatus` ๊ฐ์ฒด๋ inning, strike, ball, out, hit๋ฅผ primitive ํ ๊ฐ์ผ๋ก ๋ณด๊ดํ๊ณ ์์ต๋๋ค.
๋ง์ํ์ ๋ฐฉ๋ฒ์ ball, out์ ๊ด๋ฆฌํ๋ `BallCount`๋ผ๋ ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด์ ํด๋น ํ์์ ๋ํด ์ด ๊ฐ์ฒด์์ ์ฒ๋ฆฌํ๋๋ก ๋ง๋๋ ๋ฐฉ๋ฒ์ด๋ผ ์ดํด๋ฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋๋จธ์ง ์ผ์ ์ฒ๋ฆฌํ๋ ๋ถ๋ถ์, `4ball`์ผ ๊ฒฝ์ฐ, `1 out`์ด ์ฌ๋ผ๊ฐ๋๋ก ํน์ `3 out` ์ ๊ณต์๊ต๋๋ฅผ ํ ์ ์๋๋ก ์๋ ค์ฃผ๋ ์ญํ ์ด๋ผ ์๊ฐ๋ฉ๋๋ค. ์ ๊ฐ ์ ๋๋ก ์ดํดํ ๊ฒ์ด ๋ง์๊น์? |
@@ -0,0 +1,196 @@
+package com.codesquad.baseball09.model;
+
+import static com.codesquad.baseball09.model.Status.BALL;
+import static com.codesquad.baseball09.model.Status.HIT;
+import static com.codesquad.baseball09.model.Status.OUT;
+import static com.codesquad.baseball09.model.Status.STRIKE;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class InningStatus {
+
+ @JsonIgnore
+ private Long id;
+ private Long gameId;
+ private int inning;
+ private int strike;
+ private int ball;
+ private int out;
+ private int hit;
+
+ public InningStatus(Long id, Long gameId, int inning, int strike, int ball, int out, int hit) {
+ this.id = id;
+ this.gameId = gameId;
+ this.inning = inning;
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ private InningStatus(Long gameId, int inning, int strike, int ball, int out, int hit) {
+ this.gameId = gameId;
+ this.inning = inning;
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ public InningStatus(int strike, int ball, int out, int hit) {
+ this.strike = strike;
+ this.ball = ball;
+ this.out = out;
+ this.hit = hit;
+ }
+
+ public static InningStatus of(Long gameId, int inning, int strike, int ball, int out, int hit) {
+ return new InningStatus(gameId, inning, strike, ball, out, hit);
+ }
+
+ public int plus(Status status) {
+ int value = 0;
+
+ if (STRIKE.equals(status)) {
+ strike++;
+ value = checkThreeStrike();
+ } else if (BALL.equals(status)) {
+ ball++;
+ value = checkFourBall();
+ } else if (OUT.equals(status)) {
+ out++;
+ resetStrikeAndBall();
+ value = checkThreeOut();
+ } else if (HIT.equals(status)) {
+ hit++;
+ resetStrikeAndBall();
+ value = checkFourHit();
+ }
+ return value;
+ }
+
+ private void resetStrikeAndBall() {
+ this.strike = 0;
+ this.ball = 0;
+ }
+
+ private void resetAll() {
+ resetStrikeAndBall();
+ this.out = 0;
+ this.hit = 0;
+ }
+
+ private int checkFourHit() {
+ if (this.hit == 4) {
+ resetStrikeAndBall();
+ this.hit--;
+ return 1;
+ }
+ return 0;
+ }
+
+ private int checkThreeOut() {
+ if (this.out == 3) {
+ resetAll();
+ return -1;
+ }
+ return 0;
+ }
+
+ private int checkFourBall() {
+ if (this.ball == 4) {
+ resetStrikeAndBall();
+ plus(HIT);
+ }
+ return 2;
+ }
+
+ private int checkThreeStrike() {
+ if (this.strike == 3) {
+ resetStrikeAndBall();
+ plus(OUT);
+ }
+ return 2;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getGameId() {
+ return gameId;
+ }
+
+ public int getInning() {
+ return inning;
+ }
+
+ public int getStrike() {
+ return strike;
+ }
+
+ public int getBall() {
+ return ball;
+ }
+
+ public int getOut() {
+ return out;
+ }
+
+ public int getHit() {
+ return hit;
+ }
+
+ public static final class Builder {
+
+ private Long id;
+ private Long gameId;
+ private int inning;
+ private int strike;
+ private int ball;
+ private int out;
+ private int hit;
+
+ public Builder() {
+ }
+
+ public Builder id(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder gameId(Long gameId) {
+ this.gameId = gameId;
+ return this;
+ }
+
+ public Builder inning(int inning) {
+ this.inning = inning;
+ return this;
+ }
+
+ public Builder strike(int strike) {
+ this.strike = strike;
+ return this;
+ }
+
+ public Builder ball(int ball) {
+ this.ball = ball;
+ return this;
+ }
+
+ public Builder out(int out) {
+ this.out = out;
+ return this;
+ }
+
+ public Builder hit(int hit) {
+ this.hit = hit;
+ return this;
+ }
+
+ public InningStatus build() {
+ return new InningStatus(id, gameId, inning, strike, ball, out, hit);
+ }
+ }
+} | Java | strike, ball, out, hit ๊ฐ๊ฐ ์ญํ ์ด ์๋ ๋งํผ , ๋ชจ๋ ๊ฐ์ฒด๋ก ๋ง๋๋ ๊ฒ์ด ์ข ๋ ๊น๋ํ ๋ฐฉ๋ฒ์ผ๊น์?
์ด๋ ๊ฒ ์ด๋ค ๋ณํ์ ๋ฐ๋ผ ์ํฅ ๋ฐ๋ ๊ฒ๋ค์ด ๋ง์ ๋, ์ด๋ป๊ฒ ๊ทธ๋ฌํ ์ํธ์์ฉ์ ๊ตฌํํ ์ ์์์ง, ๋๊ฐํฉ๋๋คใ
ใ
|
@@ -0,0 +1,27 @@
+package racingcar.dao;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
+import racingcar.dao.entity.GameEntity;
+
+public class InsertGameDao {
+
+ private final SimpleJdbcInsert insertActor;
+
+ public InsertGameDao(final JdbcTemplate jdbcTemplate) {
+ insertActor = new SimpleJdbcInsert(jdbcTemplate)
+ .withTableName("game")
+ .usingGeneratedKeyColumns("game_id");
+ }
+
+ public GameEntity insert(final GameEntity gameEntity) {
+ final Map<String, Object> parameters = new HashMap<>(3);
+ parameters.put("game_id", gameEntity.getGameId().getValue());
+ parameters.put("trial_count", gameEntity.getTrialCount());
+ parameters.put("created_at", gameEntity.getCreatedAt());
+
+ return new GameEntity(insertActor.executeAndReturnKey(parameters).intValue(), gameEntity.getTrialCount());
+ }
+} | Java | ์ด๊ฑฐ ์ธ ์ ๋ ? |
@@ -1,3 +1,5 @@
+import {ReviewLikeButtonProps} from "@review-canvas/theme";
+
export type Shadow = 'NONE' | 'SMALL' | 'MEDIUM' | 'LARGE';
export type FocusAreaLayout = 'BEST_REVIEW_TOP' | 'BEST_REVIEW_BOTTOM' | 'BEST_REVIEW_LEFT' | 'BEST_REVIEW_RIGHT';
export type ReviewAreaLayout = 'REVIEW_TOP' | 'REVIEW_BOTTOM' | 'REVIEW_LEFT' | 'REVIEW_RIGHT';
@@ -6,6 +8,7 @@ export type AlignmentPosition = 'LEFT' | 'CENTER' | 'RIGHT';
export type DetailViewType = 'SPREAD' | 'MODAL';
export type PagingType = 'PAGE_NUMBER' | 'SEE_MORE_SCROLL';
export type FilterType = 'LIST' | 'DROPDOWN';
+export type ReviewLikeButtonType = 'NONE' | 'THUMB_UP_WITH_TEXT' | 'THUMB_UP';
export interface Margin {
left: string;
@@ -43,11 +46,11 @@ export interface Round {
}
export interface ReviewLike {
- buttonType: string;
- iconColor: string;
- textColor: string;
buttonBorderColor: string;
buttonRound: Round;
+ buttonType: ReviewLikeButtonType;
+ iconColor: string;
+ textColor: string;
}
export interface ReviewLayout { | TypeScript | ์ ์ฒด์ ์ผ๋ก Prettier๊ฐ ์ ์ฉ์ด ์ ๋์ด ์๋ ๊ฒ ๊ฐ์๋ฐ Prettier ์ ์ฒด์ ์ผ๋ก ์ ์ฉํด ์ฃผ์ธ์! |
@@ -9,50 +9,55 @@ import {
generateShadowCSS,
} from '@review-canvas/theme';
+// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg';
import { Star } from '@/components/review/star.tsx';
import { useReviewItemStyle } from '@/contexts/style/review-item.ts';
import useMessageToShop from '@/hooks/use-message-to-shop.ts';
-import type { ReplyItem } from '@/services/api-types/review';
+import type { ReviewItemProps } from '@/services/api-types/review';
+import { useReviewService } from '@/services/review.tsx';
import { useConnectedShop } from '@/state/shop.ts';
import { MESSAGE_TYPES } from '@/utils/message';
import Reply from './reply';
-
-interface ReviewItemProps {
- id: number;
- rate: number;
- content: string;
- reviewerID: string;
- reviewer: string;
- replies: ReplyItem[];
-}
+import { useEffect, useState } from 'react';
export default function ReviewItem(props: ReviewItemProps) {
const style = useReviewItemStyle();
const { userID } = useConnectedShop();
+ const reviewService = useReviewService();
const message = useMessageToShop();
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ async function fetchData() {
+ return reviewService.userReviewLike(props.id);
+ }
+ void fetchData().then((response) => {
+ setCount(response.data.count);
+ });
+ }, [props.id, reviewService]);
const edit = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'edit_review',
url: `/reviews/${props.id}/edit`,
});
};
-
const deleteReview = () => {
message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, {
type: 'delete',
url: `/reviews/${props.id}/delete`,
});
};
-
const showReviewDetail = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'detail',
url: `/reviews/${props.id}`,
});
};
+ const createLike = () => {};
+
return (
<li
css={[
@@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) {
generateFontCSS(style.font),
generateShadowCSS(style.shadow, style.shadowColor),
css`
+ border-color: ${style.borderColor};
background-color: ${style.backgroundColor};
display: flex;
flex-direction: column;
@@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) {
์์ฑ์ <span>{props.reviewer}</span>
</div>
<p className="text-left">{props.content}</p>
+ {/*{style.reviewLike.buttonType !== 'NONE' ? (*/}
+ {/* <button*/}
+ {/* onClick={(evt) => {*/}
+ {/* evt.stopPropagation();*/}
+ {/* if (userID === props.reviewerID) {*/}
+ {/* return;*/}
+ {/* }*/}
+ {/* }}*/}
+ {/* css={[*/}
+ {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/}
+ {/* css`*/}
+ {/* border-width: 1px;*/}
+ {/* padding: 2px 6px;*/}
+ {/* margin-top: 15px;*/}
+ {/* margin-bottom: 10px;*/}
+ {/* border-color: ${style.reviewLike.buttonBorderColor};*/}
+ {/* color: ${style.reviewLike.textColor};*/}
+ {/* transition:*/}
+ {/* background-color 0.5s ease,*/}
+ {/* color 0.5s ease;*/}
+ {/* display: flex;*/}
+
+ {/* &:hover {*/}
+ {/* background-color: ${style.reviewLike.textColor};*/}
+ {/* color: white;*/}
+ {/* }*/}
+ {/* `,*/}
+ {/* ]}*/}
+ {/* >*/}
+ {/* <ThumbUpIcon />*/}
+ {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋์๋ผ์!</div> : null}*/}
+ {/* <div className="ml-1">0</div>*/}
+ {/* </button>*/}
+ {/*) : null}*/}
+ <button
+ css={[
+ generateBorderRadiusCSS(style.reviewLike.buttonRound),
+ css`
+ border-width: 1px;
+ padding: 2px 6px;
+ margin-top: 15px;
+ margin-bottom: 10px;
+ border-color: ${style.reviewLike.buttonBorderColor};
+ color: ${style.reviewLike.textColor};
+ transition:
+ background-color 0.5s ease,
+ color 0.5s ease;
+ display: flex;
+
+ &:hover {
+ background-color: ${style.reviewLike.textColor};
+ color: white;
+ }
+ `,
+ ]}
+ onClick={createLike}
+ type="button"
+ >
+ {/*<ThumbUpIcon />*/}
+ <div className="ml-1">๋์๋ผ์!</div>
+ <div className="ml-1">{count}</div>
+ </button>
{userID === props.reviewerID ? (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional
<div | Unknown | svg๋ component๋ก ๋ถ๋ฆฌํด์ Importํด์ ์ฐ๋ ๊ฒ ์ด๋จ๊ฐ์?? ๋ค๋ฅธ ๊ณณ์์๋ ์ธ ์ ์๊ณ , ์ปดํฌ๋ํธ ์ฝ๋ ๋ด์์ ๊ฐ๋
์ฑ์ด ์ข์ง ์์ ๊ฒ ๊ฐ์์์! |
@@ -9,50 +9,55 @@ import {
generateShadowCSS,
} from '@review-canvas/theme';
+// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg';
import { Star } from '@/components/review/star.tsx';
import { useReviewItemStyle } from '@/contexts/style/review-item.ts';
import useMessageToShop from '@/hooks/use-message-to-shop.ts';
-import type { ReplyItem } from '@/services/api-types/review';
+import type { ReviewItemProps } from '@/services/api-types/review';
+import { useReviewService } from '@/services/review.tsx';
import { useConnectedShop } from '@/state/shop.ts';
import { MESSAGE_TYPES } from '@/utils/message';
import Reply from './reply';
-
-interface ReviewItemProps {
- id: number;
- rate: number;
- content: string;
- reviewerID: string;
- reviewer: string;
- replies: ReplyItem[];
-}
+import { useEffect, useState } from 'react';
export default function ReviewItem(props: ReviewItemProps) {
const style = useReviewItemStyle();
const { userID } = useConnectedShop();
+ const reviewService = useReviewService();
const message = useMessageToShop();
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ async function fetchData() {
+ return reviewService.userReviewLike(props.id);
+ }
+ void fetchData().then((response) => {
+ setCount(response.data.count);
+ });
+ }, [props.id, reviewService]);
const edit = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'edit_review',
url: `/reviews/${props.id}/edit`,
});
};
-
const deleteReview = () => {
message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, {
type: 'delete',
url: `/reviews/${props.id}/delete`,
});
};
-
const showReviewDetail = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'detail',
url: `/reviews/${props.id}`,
});
};
+ const createLike = () => {};
+
return (
<li
css={[
@@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) {
generateFontCSS(style.font),
generateShadowCSS(style.shadow, style.shadowColor),
css`
+ border-color: ${style.borderColor};
background-color: ${style.backgroundColor};
display: flex;
flex-direction: column;
@@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) {
์์ฑ์ <span>{props.reviewer}</span>
</div>
<p className="text-left">{props.content}</p>
+ {/*{style.reviewLike.buttonType !== 'NONE' ? (*/}
+ {/* <button*/}
+ {/* onClick={(evt) => {*/}
+ {/* evt.stopPropagation();*/}
+ {/* if (userID === props.reviewerID) {*/}
+ {/* return;*/}
+ {/* }*/}
+ {/* }}*/}
+ {/* css={[*/}
+ {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/}
+ {/* css`*/}
+ {/* border-width: 1px;*/}
+ {/* padding: 2px 6px;*/}
+ {/* margin-top: 15px;*/}
+ {/* margin-bottom: 10px;*/}
+ {/* border-color: ${style.reviewLike.buttonBorderColor};*/}
+ {/* color: ${style.reviewLike.textColor};*/}
+ {/* transition:*/}
+ {/* background-color 0.5s ease,*/}
+ {/* color 0.5s ease;*/}
+ {/* display: flex;*/}
+
+ {/* &:hover {*/}
+ {/* background-color: ${style.reviewLike.textColor};*/}
+ {/* color: white;*/}
+ {/* }*/}
+ {/* `,*/}
+ {/* ]}*/}
+ {/* >*/}
+ {/* <ThumbUpIcon />*/}
+ {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋์๋ผ์!</div> : null}*/}
+ {/* <div className="ml-1">0</div>*/}
+ {/* </button>*/}
+ {/*) : null}*/}
+ <button
+ css={[
+ generateBorderRadiusCSS(style.reviewLike.buttonRound),
+ css`
+ border-width: 1px;
+ padding: 2px 6px;
+ margin-top: 15px;
+ margin-bottom: 10px;
+ border-color: ${style.reviewLike.buttonBorderColor};
+ color: ${style.reviewLike.textColor};
+ transition:
+ background-color 0.5s ease,
+ color 0.5s ease;
+ display: flex;
+
+ &:hover {
+ background-color: ${style.reviewLike.textColor};
+ color: white;
+ }
+ `,
+ ]}
+ onClick={createLike}
+ type="button"
+ >
+ {/*<ThumbUpIcon />*/}
+ <div className="ml-1">๋์๋ผ์!</div>
+ <div className="ml-1">{count}</div>
+ </button>
{userID === props.reviewerID ? (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional
<div | Unknown | ๋ถํ์ํ console์ ์ ์ธํด์ฃผ์ธ์! ์์ ์ ๋ฆฌ๋ทฐ์๋ ๋์๋ผ์ ๊ฐ์ ๊ฒฝ์ฐ๋ ์คํ๋ ค alert์ผ๋ก ๋ณด์ฌ์ฃผ๋ ๊ฒ ๋ซ์ง ์์๊น ์ถ๋ค์ |
@@ -9,50 +9,55 @@ import {
generateShadowCSS,
} from '@review-canvas/theme';
+// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg';
import { Star } from '@/components/review/star.tsx';
import { useReviewItemStyle } from '@/contexts/style/review-item.ts';
import useMessageToShop from '@/hooks/use-message-to-shop.ts';
-import type { ReplyItem } from '@/services/api-types/review';
+import type { ReviewItemProps } from '@/services/api-types/review';
+import { useReviewService } from '@/services/review.tsx';
import { useConnectedShop } from '@/state/shop.ts';
import { MESSAGE_TYPES } from '@/utils/message';
import Reply from './reply';
-
-interface ReviewItemProps {
- id: number;
- rate: number;
- content: string;
- reviewerID: string;
- reviewer: string;
- replies: ReplyItem[];
-}
+import { useEffect, useState } from 'react';
export default function ReviewItem(props: ReviewItemProps) {
const style = useReviewItemStyle();
const { userID } = useConnectedShop();
+ const reviewService = useReviewService();
const message = useMessageToShop();
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ async function fetchData() {
+ return reviewService.userReviewLike(props.id);
+ }
+ void fetchData().then((response) => {
+ setCount(response.data.count);
+ });
+ }, [props.id, reviewService]);
const edit = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'edit_review',
url: `/reviews/${props.id}/edit`,
});
};
-
const deleteReview = () => {
message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, {
type: 'delete',
url: `/reviews/${props.id}/delete`,
});
};
-
const showReviewDetail = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'detail',
url: `/reviews/${props.id}`,
});
};
+ const createLike = () => {};
+
return (
<li
css={[
@@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) {
generateFontCSS(style.font),
generateShadowCSS(style.shadow, style.shadowColor),
css`
+ border-color: ${style.borderColor};
background-color: ${style.backgroundColor};
display: flex;
flex-direction: column;
@@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) {
์์ฑ์ <span>{props.reviewer}</span>
</div>
<p className="text-left">{props.content}</p>
+ {/*{style.reviewLike.buttonType !== 'NONE' ? (*/}
+ {/* <button*/}
+ {/* onClick={(evt) => {*/}
+ {/* evt.stopPropagation();*/}
+ {/* if (userID === props.reviewerID) {*/}
+ {/* return;*/}
+ {/* }*/}
+ {/* }}*/}
+ {/* css={[*/}
+ {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/}
+ {/* css`*/}
+ {/* border-width: 1px;*/}
+ {/* padding: 2px 6px;*/}
+ {/* margin-top: 15px;*/}
+ {/* margin-bottom: 10px;*/}
+ {/* border-color: ${style.reviewLike.buttonBorderColor};*/}
+ {/* color: ${style.reviewLike.textColor};*/}
+ {/* transition:*/}
+ {/* background-color 0.5s ease,*/}
+ {/* color 0.5s ease;*/}
+ {/* display: flex;*/}
+
+ {/* &:hover {*/}
+ {/* background-color: ${style.reviewLike.textColor};*/}
+ {/* color: white;*/}
+ {/* }*/}
+ {/* `,*/}
+ {/* ]}*/}
+ {/* >*/}
+ {/* <ThumbUpIcon />*/}
+ {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋์๋ผ์!</div> : null}*/}
+ {/* <div className="ml-1">0</div>*/}
+ {/* </button>*/}
+ {/*) : null}*/}
+ <button
+ css={[
+ generateBorderRadiusCSS(style.reviewLike.buttonRound),
+ css`
+ border-width: 1px;
+ padding: 2px 6px;
+ margin-top: 15px;
+ margin-bottom: 10px;
+ border-color: ${style.reviewLike.buttonBorderColor};
+ color: ${style.reviewLike.textColor};
+ transition:
+ background-color 0.5s ease,
+ color 0.5s ease;
+ display: flex;
+
+ &:hover {
+ background-color: ${style.reviewLike.textColor};
+ color: white;
+ }
+ `,
+ ]}
+ onClick={createLike}
+ type="button"
+ >
+ {/*<ThumbUpIcon />*/}
+ <div className="ml-1">๋์๋ผ์!</div>
+ <div className="ml-1">{count}</div>
+ </button>
{userID === props.reviewerID ? (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional
<div | Unknown | ts ignore๋ ํน์ ์ ์ค์ ํด ๋์ผ์ ๊ฑธ๊น์?? |
@@ -9,50 +9,55 @@ import {
generateShadowCSS,
} from '@review-canvas/theme';
+// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg';
import { Star } from '@/components/review/star.tsx';
import { useReviewItemStyle } from '@/contexts/style/review-item.ts';
import useMessageToShop from '@/hooks/use-message-to-shop.ts';
-import type { ReplyItem } from '@/services/api-types/review';
+import type { ReviewItemProps } from '@/services/api-types/review';
+import { useReviewService } from '@/services/review.tsx';
import { useConnectedShop } from '@/state/shop.ts';
import { MESSAGE_TYPES } from '@/utils/message';
import Reply from './reply';
-
-interface ReviewItemProps {
- id: number;
- rate: number;
- content: string;
- reviewerID: string;
- reviewer: string;
- replies: ReplyItem[];
-}
+import { useEffect, useState } from 'react';
export default function ReviewItem(props: ReviewItemProps) {
const style = useReviewItemStyle();
const { userID } = useConnectedShop();
+ const reviewService = useReviewService();
const message = useMessageToShop();
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ async function fetchData() {
+ return reviewService.userReviewLike(props.id);
+ }
+ void fetchData().then((response) => {
+ setCount(response.data.count);
+ });
+ }, [props.id, reviewService]);
const edit = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'edit_review',
url: `/reviews/${props.id}/edit`,
});
};
-
const deleteReview = () => {
message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, {
type: 'delete',
url: `/reviews/${props.id}/delete`,
});
};
-
const showReviewDetail = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'detail',
url: `/reviews/${props.id}`,
});
};
+ const createLike = () => {};
+
return (
<li
css={[
@@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) {
generateFontCSS(style.font),
generateShadowCSS(style.shadow, style.shadowColor),
css`
+ border-color: ${style.borderColor};
background-color: ${style.backgroundColor};
display: flex;
flex-direction: column;
@@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) {
์์ฑ์ <span>{props.reviewer}</span>
</div>
<p className="text-left">{props.content}</p>
+ {/*{style.reviewLike.buttonType !== 'NONE' ? (*/}
+ {/* <button*/}
+ {/* onClick={(evt) => {*/}
+ {/* evt.stopPropagation();*/}
+ {/* if (userID === props.reviewerID) {*/}
+ {/* return;*/}
+ {/* }*/}
+ {/* }}*/}
+ {/* css={[*/}
+ {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/}
+ {/* css`*/}
+ {/* border-width: 1px;*/}
+ {/* padding: 2px 6px;*/}
+ {/* margin-top: 15px;*/}
+ {/* margin-bottom: 10px;*/}
+ {/* border-color: ${style.reviewLike.buttonBorderColor};*/}
+ {/* color: ${style.reviewLike.textColor};*/}
+ {/* transition:*/}
+ {/* background-color 0.5s ease,*/}
+ {/* color 0.5s ease;*/}
+ {/* display: flex;*/}
+
+ {/* &:hover {*/}
+ {/* background-color: ${style.reviewLike.textColor};*/}
+ {/* color: white;*/}
+ {/* }*/}
+ {/* `,*/}
+ {/* ]}*/}
+ {/* >*/}
+ {/* <ThumbUpIcon />*/}
+ {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋์๋ผ์!</div> : null}*/}
+ {/* <div className="ml-1">0</div>*/}
+ {/* </button>*/}
+ {/*) : null}*/}
+ <button
+ css={[
+ generateBorderRadiusCSS(style.reviewLike.buttonRound),
+ css`
+ border-width: 1px;
+ padding: 2px 6px;
+ margin-top: 15px;
+ margin-bottom: 10px;
+ border-color: ${style.reviewLike.buttonBorderColor};
+ color: ${style.reviewLike.textColor};
+ transition:
+ background-color 0.5s ease,
+ color 0.5s ease;
+ display: flex;
+
+ &:hover {
+ background-color: ${style.reviewLike.textColor};
+ color: white;
+ }
+ `,
+ ]}
+ onClick={createLike}
+ type="button"
+ >
+ {/*<ThumbUpIcon />*/}
+ <div className="ml-1">๋์๋ผ์!</div>
+ <div className="ml-1">{count}</div>
+ </button>
{userID === props.reviewerID ? (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional
<div | Unknown | P3: interface ๊ฐ์ ๊ฒฝ์ฐ ๋ค๋ฅธ ๊ณณ์์๋ ์ฌ๋ฌ ๊ณณ์์ ์ฐ์ผ ์ ์๋๋ฐ, type ๋๋ ํ ๋ฆฌ ๋ฑ์ ๊ณตํต์ ์ธ model์ ์ ์ํด๋๊ณ extends ๋ฑ์ผ๋ก ๊ฐ์ ธ์์ ์ฐ๋ ๋ฐฉ์๋ ๊ณ ๋ คํด ๋ณผ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. ReviewItem์ ์๋นํ ๋ง์ ๊ณณ์์ ์ฐ์ด๋ ์์๋ก ์๊ฐ๋์ ์ฐธ๊ณ ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ ๋จ๊น๋๋ค! |
@@ -1,3 +1,5 @@
+import {ReviewLikeButtonProps} from "@review-canvas/theme";
+
export type Shadow = 'NONE' | 'SMALL' | 'MEDIUM' | 'LARGE';
export type FocusAreaLayout = 'BEST_REVIEW_TOP' | 'BEST_REVIEW_BOTTOM' | 'BEST_REVIEW_LEFT' | 'BEST_REVIEW_RIGHT';
export type ReviewAreaLayout = 'REVIEW_TOP' | 'REVIEW_BOTTOM' | 'REVIEW_LEFT' | 'REVIEW_RIGHT';
@@ -6,6 +8,7 @@ export type AlignmentPosition = 'LEFT' | 'CENTER' | 'RIGHT';
export type DetailViewType = 'SPREAD' | 'MODAL';
export type PagingType = 'PAGE_NUMBER' | 'SEE_MORE_SCROLL';
export type FilterType = 'LIST' | 'DROPDOWN';
+export type ReviewLikeButtonType = 'NONE' | 'THUMB_UP_WITH_TEXT' | 'THUMB_UP';
export interface Margin {
left: string;
@@ -43,11 +46,11 @@ export interface Round {
}
export interface ReviewLike {
- buttonType: string;
- iconColor: string;
- textColor: string;
buttonBorderColor: string;
buttonRound: Round;
+ buttonType: ReviewLikeButtonType;
+ iconColor: string;
+ textColor: string;
}
export interface ReviewLayout { | TypeScript | Plugin ์ค์น๋ฅผ ํ๋ฉด ์๋ฃ์ธ ์ค ์์๋๋ฐ ์ค์ ์์ Manually๋ก ๋ฐ๊พธ์ด์ค์ผ ํ๊ตฐ์... ํ์ฌ Prettier๋ฅผ ํ์ฑํ ์ํ๋ก ๋ณ๊ฒฝํ์์ต๋๋ค. ์ ์ฒด ํ์ผ์ ์ ์ฉํ์ฌ ๋ค์ ์ปค๋ฐํ๊ฒ ์ต๋๋ค! |
@@ -9,50 +9,55 @@ import {
generateShadowCSS,
} from '@review-canvas/theme';
+// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg';
import { Star } from '@/components/review/star.tsx';
import { useReviewItemStyle } from '@/contexts/style/review-item.ts';
import useMessageToShop from '@/hooks/use-message-to-shop.ts';
-import type { ReplyItem } from '@/services/api-types/review';
+import type { ReviewItemProps } from '@/services/api-types/review';
+import { useReviewService } from '@/services/review.tsx';
import { useConnectedShop } from '@/state/shop.ts';
import { MESSAGE_TYPES } from '@/utils/message';
import Reply from './reply';
-
-interface ReviewItemProps {
- id: number;
- rate: number;
- content: string;
- reviewerID: string;
- reviewer: string;
- replies: ReplyItem[];
-}
+import { useEffect, useState } from 'react';
export default function ReviewItem(props: ReviewItemProps) {
const style = useReviewItemStyle();
const { userID } = useConnectedShop();
+ const reviewService = useReviewService();
const message = useMessageToShop();
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ async function fetchData() {
+ return reviewService.userReviewLike(props.id);
+ }
+ void fetchData().then((response) => {
+ setCount(response.data.count);
+ });
+ }, [props.id, reviewService]);
const edit = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'edit_review',
url: `/reviews/${props.id}/edit`,
});
};
-
const deleteReview = () => {
message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, {
type: 'delete',
url: `/reviews/${props.id}/delete`,
});
};
-
const showReviewDetail = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'detail',
url: `/reviews/${props.id}`,
});
};
+ const createLike = () => {};
+
return (
<li
css={[
@@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) {
generateFontCSS(style.font),
generateShadowCSS(style.shadow, style.shadowColor),
css`
+ border-color: ${style.borderColor};
background-color: ${style.backgroundColor};
display: flex;
flex-direction: column;
@@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) {
์์ฑ์ <span>{props.reviewer}</span>
</div>
<p className="text-left">{props.content}</p>
+ {/*{style.reviewLike.buttonType !== 'NONE' ? (*/}
+ {/* <button*/}
+ {/* onClick={(evt) => {*/}
+ {/* evt.stopPropagation();*/}
+ {/* if (userID === props.reviewerID) {*/}
+ {/* return;*/}
+ {/* }*/}
+ {/* }}*/}
+ {/* css={[*/}
+ {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/}
+ {/* css`*/}
+ {/* border-width: 1px;*/}
+ {/* padding: 2px 6px;*/}
+ {/* margin-top: 15px;*/}
+ {/* margin-bottom: 10px;*/}
+ {/* border-color: ${style.reviewLike.buttonBorderColor};*/}
+ {/* color: ${style.reviewLike.textColor};*/}
+ {/* transition:*/}
+ {/* background-color 0.5s ease,*/}
+ {/* color 0.5s ease;*/}
+ {/* display: flex;*/}
+
+ {/* &:hover {*/}
+ {/* background-color: ${style.reviewLike.textColor};*/}
+ {/* color: white;*/}
+ {/* }*/}
+ {/* `,*/}
+ {/* ]}*/}
+ {/* >*/}
+ {/* <ThumbUpIcon />*/}
+ {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋์๋ผ์!</div> : null}*/}
+ {/* <div className="ml-1">0</div>*/}
+ {/* </button>*/}
+ {/*) : null}*/}
+ <button
+ css={[
+ generateBorderRadiusCSS(style.reviewLike.buttonRound),
+ css`
+ border-width: 1px;
+ padding: 2px 6px;
+ margin-top: 15px;
+ margin-bottom: 10px;
+ border-color: ${style.reviewLike.buttonBorderColor};
+ color: ${style.reviewLike.textColor};
+ transition:
+ background-color 0.5s ease,
+ color 0.5s ease;
+ display: flex;
+
+ &:hover {
+ background-color: ${style.reviewLike.textColor};
+ color: white;
+ }
+ `,
+ ]}
+ onClick={createLike}
+ type="button"
+ >
+ {/*<ThumbUpIcon />*/}
+ <div className="ml-1">๋์๋ผ์!</div>
+ <div className="ml-1">{count}</div>
+ </button>
{userID === props.reviewerID ? (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional
<div | Unknown | ํ์ธํ์์ต๋๋ค, Alert๋ก ๋ณ๊ฒฝํ๊ฒ ์ต๋๋ค, ๋์๋ผ์!์ ๊ฒฝ์ฐ์๋ ๋ฒํผ์ด ์ ๋๋ก ๋์ํ๋ ๊ฒ์ ํ์ธํ๊ธฐ ์ํด ์์๋ก ๋ฃ์ด๋๊ณ ๋์ค์ ๋์๋ผ์ API๊ฐ ๋ฐฑ์๋์์ ๊ตฌํ๋๋ฉด ๋ก์ง์ผ๋ก ๋์ฒดํ๊ฒ ์ต๋๋ค! |
@@ -9,50 +9,55 @@ import {
generateShadowCSS,
} from '@review-canvas/theme';
+// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg';
import { Star } from '@/components/review/star.tsx';
import { useReviewItemStyle } from '@/contexts/style/review-item.ts';
import useMessageToShop from '@/hooks/use-message-to-shop.ts';
-import type { ReplyItem } from '@/services/api-types/review';
+import type { ReviewItemProps } from '@/services/api-types/review';
+import { useReviewService } from '@/services/review.tsx';
import { useConnectedShop } from '@/state/shop.ts';
import { MESSAGE_TYPES } from '@/utils/message';
import Reply from './reply';
-
-interface ReviewItemProps {
- id: number;
- rate: number;
- content: string;
- reviewerID: string;
- reviewer: string;
- replies: ReplyItem[];
-}
+import { useEffect, useState } from 'react';
export default function ReviewItem(props: ReviewItemProps) {
const style = useReviewItemStyle();
const { userID } = useConnectedShop();
+ const reviewService = useReviewService();
const message = useMessageToShop();
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ async function fetchData() {
+ return reviewService.userReviewLike(props.id);
+ }
+ void fetchData().then((response) => {
+ setCount(response.data.count);
+ });
+ }, [props.id, reviewService]);
const edit = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'edit_review',
url: `/reviews/${props.id}/edit`,
});
};
-
const deleteReview = () => {
message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, {
type: 'delete',
url: `/reviews/${props.id}/delete`,
});
};
-
const showReviewDetail = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'detail',
url: `/reviews/${props.id}`,
});
};
+ const createLike = () => {};
+
return (
<li
css={[
@@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) {
generateFontCSS(style.font),
generateShadowCSS(style.shadow, style.shadowColor),
css`
+ border-color: ${style.borderColor};
background-color: ${style.backgroundColor};
display: flex;
flex-direction: column;
@@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) {
์์ฑ์ <span>{props.reviewer}</span>
</div>
<p className="text-left">{props.content}</p>
+ {/*{style.reviewLike.buttonType !== 'NONE' ? (*/}
+ {/* <button*/}
+ {/* onClick={(evt) => {*/}
+ {/* evt.stopPropagation();*/}
+ {/* if (userID === props.reviewerID) {*/}
+ {/* return;*/}
+ {/* }*/}
+ {/* }}*/}
+ {/* css={[*/}
+ {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/}
+ {/* css`*/}
+ {/* border-width: 1px;*/}
+ {/* padding: 2px 6px;*/}
+ {/* margin-top: 15px;*/}
+ {/* margin-bottom: 10px;*/}
+ {/* border-color: ${style.reviewLike.buttonBorderColor};*/}
+ {/* color: ${style.reviewLike.textColor};*/}
+ {/* transition:*/}
+ {/* background-color 0.5s ease,*/}
+ {/* color 0.5s ease;*/}
+ {/* display: flex;*/}
+
+ {/* &:hover {*/}
+ {/* background-color: ${style.reviewLike.textColor};*/}
+ {/* color: white;*/}
+ {/* }*/}
+ {/* `,*/}
+ {/* ]}*/}
+ {/* >*/}
+ {/* <ThumbUpIcon />*/}
+ {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋์๋ผ์!</div> : null}*/}
+ {/* <div className="ml-1">0</div>*/}
+ {/* </button>*/}
+ {/*) : null}*/}
+ <button
+ css={[
+ generateBorderRadiusCSS(style.reviewLike.buttonRound),
+ css`
+ border-width: 1px;
+ padding: 2px 6px;
+ margin-top: 15px;
+ margin-bottom: 10px;
+ border-color: ${style.reviewLike.buttonBorderColor};
+ color: ${style.reviewLike.textColor};
+ transition:
+ background-color 0.5s ease,
+ color 0.5s ease;
+ display: flex;
+
+ &:hover {
+ background-color: ${style.reviewLike.textColor};
+ color: white;
+ }
+ `,
+ ]}
+ onClick={createLike}
+ type="button"
+ >
+ {/*<ThumbUpIcon />*/}
+ <div className="ml-1">๋์๋ผ์!</div>
+ <div className="ml-1">{count}</div>
+ </button>
{userID === props.reviewerID ? (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional
<div | Unknown | ํ์ธํ์์ต๋๋ค, Import๋ก ๋์ฒดํ๊ฒ ์ต๋๋ค! |
@@ -9,50 +9,55 @@ import {
generateShadowCSS,
} from '@review-canvas/theme';
+// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg';
import { Star } from '@/components/review/star.tsx';
import { useReviewItemStyle } from '@/contexts/style/review-item.ts';
import useMessageToShop from '@/hooks/use-message-to-shop.ts';
-import type { ReplyItem } from '@/services/api-types/review';
+import type { ReviewItemProps } from '@/services/api-types/review';
+import { useReviewService } from '@/services/review.tsx';
import { useConnectedShop } from '@/state/shop.ts';
import { MESSAGE_TYPES } from '@/utils/message';
import Reply from './reply';
-
-interface ReviewItemProps {
- id: number;
- rate: number;
- content: string;
- reviewerID: string;
- reviewer: string;
- replies: ReplyItem[];
-}
+import { useEffect, useState } from 'react';
export default function ReviewItem(props: ReviewItemProps) {
const style = useReviewItemStyle();
const { userID } = useConnectedShop();
+ const reviewService = useReviewService();
const message = useMessageToShop();
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ async function fetchData() {
+ return reviewService.userReviewLike(props.id);
+ }
+ void fetchData().then((response) => {
+ setCount(response.data.count);
+ });
+ }, [props.id, reviewService]);
const edit = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'edit_review',
url: `/reviews/${props.id}/edit`,
});
};
-
const deleteReview = () => {
message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, {
type: 'delete',
url: `/reviews/${props.id}/delete`,
});
};
-
const showReviewDetail = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'detail',
url: `/reviews/${props.id}`,
});
};
+ const createLike = () => {};
+
return (
<li
css={[
@@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) {
generateFontCSS(style.font),
generateShadowCSS(style.shadow, style.shadowColor),
css`
+ border-color: ${style.borderColor};
background-color: ${style.backgroundColor};
display: flex;
flex-direction: column;
@@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) {
์์ฑ์ <span>{props.reviewer}</span>
</div>
<p className="text-left">{props.content}</p>
+ {/*{style.reviewLike.buttonType !== 'NONE' ? (*/}
+ {/* <button*/}
+ {/* onClick={(evt) => {*/}
+ {/* evt.stopPropagation();*/}
+ {/* if (userID === props.reviewerID) {*/}
+ {/* return;*/}
+ {/* }*/}
+ {/* }}*/}
+ {/* css={[*/}
+ {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/}
+ {/* css`*/}
+ {/* border-width: 1px;*/}
+ {/* padding: 2px 6px;*/}
+ {/* margin-top: 15px;*/}
+ {/* margin-bottom: 10px;*/}
+ {/* border-color: ${style.reviewLike.buttonBorderColor};*/}
+ {/* color: ${style.reviewLike.textColor};*/}
+ {/* transition:*/}
+ {/* background-color 0.5s ease,*/}
+ {/* color 0.5s ease;*/}
+ {/* display: flex;*/}
+
+ {/* &:hover {*/}
+ {/* background-color: ${style.reviewLike.textColor};*/}
+ {/* color: white;*/}
+ {/* }*/}
+ {/* `,*/}
+ {/* ]}*/}
+ {/* >*/}
+ {/* <ThumbUpIcon />*/}
+ {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋์๋ผ์!</div> : null}*/}
+ {/* <div className="ml-1">0</div>*/}
+ {/* </button>*/}
+ {/*) : null}*/}
+ <button
+ css={[
+ generateBorderRadiusCSS(style.reviewLike.buttonRound),
+ css`
+ border-width: 1px;
+ padding: 2px 6px;
+ margin-top: 15px;
+ margin-bottom: 10px;
+ border-color: ${style.reviewLike.buttonBorderColor};
+ color: ${style.reviewLike.textColor};
+ transition:
+ background-color 0.5s ease,
+ color 0.5s ease;
+ display: flex;
+
+ &:hover {
+ background-color: ${style.reviewLike.textColor};
+ color: white;
+ }
+ `,
+ ]}
+ onClick={createLike}
+ type="button"
+ >
+ {/*<ThumbUpIcon />*/}
+ <div className="ml-1">๋์๋ผ์!</div>
+ <div className="ml-1">{count}</div>
+ </button>
{userID === props.reviewerID ? (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional
<div | Unknown | ํ
์คํธ๋ฅผ ํ ๋ ReviewLikeButton์ด 'None'์ผ๋ก ๊ณ ์ ์ด๋ผ ํ๋์ฝ๋ฉ์ผ๋ก ReviewLikeButton์ ๋ฐ๊พธ๊ณ ์์์ต๋๋ค. ๊ทธ ๊ณผ์ ์์ ์กฐ๊ฑด๋ฌธ ๊ฒฝ๊ณ ๊ฐ ๋ฐ์ํ์ฌ ์ค์ ํด๋์๋๋ฐ ํ๋์ฝ๋ฉ๋ง ์ง์ฐ๊ณ ์ด๊ทธ๋
ธ์ด๋ฅผ ๋ชป ์ง์ ๋ค์... ์ง์์ ๋ฐ์ํ๊ฒ ์ต๋๋ค! |
@@ -9,50 +9,55 @@ import {
generateShadowCSS,
} from '@review-canvas/theme';
+// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg';
import { Star } from '@/components/review/star.tsx';
import { useReviewItemStyle } from '@/contexts/style/review-item.ts';
import useMessageToShop from '@/hooks/use-message-to-shop.ts';
-import type { ReplyItem } from '@/services/api-types/review';
+import type { ReviewItemProps } from '@/services/api-types/review';
+import { useReviewService } from '@/services/review.tsx';
import { useConnectedShop } from '@/state/shop.ts';
import { MESSAGE_TYPES } from '@/utils/message';
import Reply from './reply';
-
-interface ReviewItemProps {
- id: number;
- rate: number;
- content: string;
- reviewerID: string;
- reviewer: string;
- replies: ReplyItem[];
-}
+import { useEffect, useState } from 'react';
export default function ReviewItem(props: ReviewItemProps) {
const style = useReviewItemStyle();
const { userID } = useConnectedShop();
+ const reviewService = useReviewService();
const message = useMessageToShop();
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ async function fetchData() {
+ return reviewService.userReviewLike(props.id);
+ }
+ void fetchData().then((response) => {
+ setCount(response.data.count);
+ });
+ }, [props.id, reviewService]);
const edit = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'edit_review',
url: `/reviews/${props.id}/edit`,
});
};
-
const deleteReview = () => {
message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, {
type: 'delete',
url: `/reviews/${props.id}/delete`,
});
};
-
const showReviewDetail = () => {
message(MESSAGE_TYPES.OPEN_MODAL, {
type: 'detail',
url: `/reviews/${props.id}`,
});
};
+ const createLike = () => {};
+
return (
<li
css={[
@@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) {
generateFontCSS(style.font),
generateShadowCSS(style.shadow, style.shadowColor),
css`
+ border-color: ${style.borderColor};
background-color: ${style.backgroundColor};
display: flex;
flex-direction: column;
@@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) {
์์ฑ์ <span>{props.reviewer}</span>
</div>
<p className="text-left">{props.content}</p>
+ {/*{style.reviewLike.buttonType !== 'NONE' ? (*/}
+ {/* <button*/}
+ {/* onClick={(evt) => {*/}
+ {/* evt.stopPropagation();*/}
+ {/* if (userID === props.reviewerID) {*/}
+ {/* return;*/}
+ {/* }*/}
+ {/* }}*/}
+ {/* css={[*/}
+ {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/}
+ {/* css`*/}
+ {/* border-width: 1px;*/}
+ {/* padding: 2px 6px;*/}
+ {/* margin-top: 15px;*/}
+ {/* margin-bottom: 10px;*/}
+ {/* border-color: ${style.reviewLike.buttonBorderColor};*/}
+ {/* color: ${style.reviewLike.textColor};*/}
+ {/* transition:*/}
+ {/* background-color 0.5s ease,*/}
+ {/* color 0.5s ease;*/}
+ {/* display: flex;*/}
+
+ {/* &:hover {*/}
+ {/* background-color: ${style.reviewLike.textColor};*/}
+ {/* color: white;*/}
+ {/* }*/}
+ {/* `,*/}
+ {/* ]}*/}
+ {/* >*/}
+ {/* <ThumbUpIcon />*/}
+ {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋์๋ผ์!</div> : null}*/}
+ {/* <div className="ml-1">0</div>*/}
+ {/* </button>*/}
+ {/*) : null}*/}
+ <button
+ css={[
+ generateBorderRadiusCSS(style.reviewLike.buttonRound),
+ css`
+ border-width: 1px;
+ padding: 2px 6px;
+ margin-top: 15px;
+ margin-bottom: 10px;
+ border-color: ${style.reviewLike.buttonBorderColor};
+ color: ${style.reviewLike.textColor};
+ transition:
+ background-color 0.5s ease,
+ color 0.5s ease;
+ display: flex;
+
+ &:hover {
+ background-color: ${style.reviewLike.textColor};
+ color: white;
+ }
+ `,
+ ]}
+ onClick={createLike}
+ type="button"
+ >
+ {/*<ThumbUpIcon />*/}
+ <div className="ml-1">๋์๋ผ์!</div>
+ <div className="ml-1">{count}</div>
+ </button>
{userID === props.reviewerID ? (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional
<div | Unknown | service/api-types/review.tsx์ ๊ณตํต ๋ชจ๋ธ๋ก ์ ์ธํ์ฌ export ๋ฐ import ํ์์ต๋๋ค! |
@@ -0,0 +1,97 @@
+package christmas.config;
+
+import christmas.controller.EventController;
+import christmas.exception.RetryHandler;
+import christmas.service.EventService;
+import christmas.service.MenuService;
+import christmas.validator.InputValidator;
+import christmas.view.input.ConsoleReader;
+import christmas.view.input.InputView;
+import christmas.view.input.Reader;
+import christmas.view.output.ConsoleWriter;
+import christmas.view.output.OutputView;
+import christmas.view.output.Writer;
+
+public class AppConfig {
+ private static AppConfig appConfig;
+ private EventController eventController;
+ private EventService eventService;
+ private MenuService menuService;
+ private InputValidator inputValidator;
+ private RetryHandler retryHandler;
+ private InputView inputView;
+ private OutputView outputView;
+ private Reader reader;
+ private Writer writer;
+
+ public static AppConfig getInstance() {
+ if (appConfig == null) {
+ appConfig = new AppConfig();
+ }
+ return appConfig;
+ }
+
+ public EventController eventController() {
+ if (eventController == null) {
+ eventController = new EventController(discountService(), menuService(),
+ inputView(), outputView(), exceptionHandler());
+ }
+ return eventController;
+ }
+
+ public EventService discountService() {
+ if (eventService == null) {
+ eventService = new EventService();
+ }
+ return eventService;
+ }
+
+ public MenuService menuService() {
+ if (menuService == null) {
+ menuService = new MenuService();
+ }
+ return menuService;
+ }
+
+ public RetryHandler exceptionHandler() {
+ if (retryHandler == null) {
+ retryHandler = new RetryHandler(outputView());
+ }
+ return retryHandler;
+ }
+
+ public InputView inputView() {
+ if (inputView == null) {
+ inputView = new InputView(reader(), inputValidator());
+ }
+ return inputView;
+ }
+
+ public InputValidator inputValidator() {
+ if (inputValidator == null) {
+ inputValidator = new InputValidator();
+ }
+ return inputValidator;
+ }
+
+ public Reader reader() {
+ if (reader == null) {
+ reader = new ConsoleReader();
+ }
+ return reader;
+ }
+
+ public OutputView outputView() {
+ if (outputView == null) {
+ outputView = new OutputView(writer());
+ }
+ return outputView;
+ }
+
+ public Writer writer() {
+ if (writer == null) {
+ writer = new ConsoleWriter();
+ }
+ return writer;
+ }
+} | Java | ์ ์ฒด์ ์ผ๋ก null ์ฒดํฌ๋ฅผ ํด์ฃผ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,30 @@
+package christmas.constants.event;
+
+public enum BadgeType {
+ NONE("์์", 0),
+ STAR("๋ณ", 5_000),
+ TREE("ํธ๋ฆฌ", 10_000),
+ SANTA("์ฐํ", 20_000);
+
+ private final String name;
+ private final int threshold;
+
+ BadgeType(String name, int threshold) {
+ this.name = name;
+ this.threshold = threshold;
+ }
+
+ public static BadgeType from(int benefitPrice) {
+ BadgeType result = NONE;
+ for (BadgeType badgeType : values()) {
+ if (benefitPrice >= badgeType.threshold) {
+ result = badgeType;
+ }
+ }
+ return result;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ๋ฐฐ์ง ์์์ NONE์ผ๋ก ๊ด๋ฆฌํ์ ๋ถ๋ถ๋ ์ข์ ์ ๋ต์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค :)
Optional์ ๊ณ ๋ คํด๋ณด์๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์์! ์ด๋ฒ์ Optional์ ์ฒ์ ํ์ฉํด๋ดค๋๋ฐ์, **์์ ์๋ ์๋ค ๋ผ๋ ๋น์ฆ๋์ค ์๊ตฌ์ฌํญ**์ **์ฝ๋๋ก ๋ช
์**ํ ์ ์๋ ์ ์ด ์ ๋ง ํฐ ์ฅ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค :)
๋ง์ฝ Optional์ ๋์
ํ๋ค๋ฉด `from` ๋ฉ์๋๋ฅผ ์ด๋ ๊ฒ ๋ฆฌํฉํฐ๋งํด๋ณผ ์ ์์ ๊ฒ ๊ฐ์์!
```java
public static Optional<BadgeType> from(int benefitPrice) {
Optional<Badge> badge = Arrays.stream(values())
.filter(badge -> badge.minTotalBenefitAmount <= totalBenefitAmount)
.findFirst();
if (badge.isPresent()) {
return badge.get();
}
return badge.empty();
}
}
```
์ ๋ ์์ง Optional์ ์ธ์ ์ฌ์ฉํด์ผ ๋จ์ฉ์ด ์๋๊น? ๋ผ๋ ํ์คํ ๊ธฐ์ค์ ์์ด์, ์ฐธ๊ณ ์ ๋๋ง ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค :) |
@@ -0,0 +1,54 @@
+package christmas.constants.menu;
+
+import static christmas.constants.menu.MenuType.APPETIZER;
+import static christmas.constants.menu.MenuType.DESSERT;
+import static christmas.constants.menu.MenuType.DRINKS;
+import static christmas.constants.menu.MenuType.MAIN;
+import static christmas.exception.ErrorCode.INVALID_MENU_ORDER;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public enum Menu {
+ MUSHROOM_SOUP(APPETIZER, "์์ก์ด์ํ", 6000),
+ TAPAS(APPETIZER, "ํํ์ค", 5500),
+ SALAD(APPETIZER, "์์ ์๋ฌ๋", 8000),
+ STAKE(MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000),
+ LIB(MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000),
+ PASTA_(MAIN, "ํด์ฐ๋ฌผํ์คํ", 35_000),
+ PASTA(MAIN, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000),
+ CAKE(DESSERT, "์ด์ฝ์ผ์ดํฌ", 15_000),
+ ICE_CREAM(DESSERT, "์์ด์คํฌ๋ฆผ", 5000),
+ ZERO_COLA(DRINKS, "์ ๋ก์ฝ๋ผ", 3000),
+ WINE(DRINKS, "๋ ๋์์ธ", 60_000),
+ CHAMPAGNE(DRINKS, "์ดํ์ธ", 25_000);
+
+ private final MenuType menuType;
+ private final String name;
+ private final int price;
+
+ Menu(MenuType menuType, String name, int price) {
+ this.menuType = menuType;
+ this.name = name;
+ this.price = price;
+ }
+
+ public static Menu from(String input) {
+ return Arrays.stream(values())
+ .filter(menu -> Objects.equals(menu.name, input))
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException(INVALID_MENU_ORDER.getMessage()));
+ }
+
+ public MenuType getMenuType() {
+ return menuType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+} | Java | `์ด๋ฆ`์ ๋ํ `๋ฉ๋ด`๋ฅผ HashMap์ผ๋ก ์บ์ฑํด๋๋ ์ ๋ต๋ ์ถ์ฒ๋๋ฆฝ๋๋ค.
Enum์์ static ๋ธ๋ก์ ์ถ๊ฐํ ์ ์๋๋ฐ์, ์๋ฐ์์ผ๋ก ๊ตฌํํ ์ ์์ต๋๋ค!
```java
public enum Menu {
// ์ด๊ฑฐํ ์์๋ค ...
private static final Map<String, Menu> cachedMenu = new HashMap<>();
static {
for (Menu menu : values()) {
cachedMenu.put(menu.getName(), menu);
}
}
}
```
์ด๋ ๊ฒ Map์ผ๋ก ์บ์ฑํด๋๋ฉด, ๋งค ๋ฒ ์ด๊ฑฐํ ์์๋ค์ ์ํํ์ง ์์๋ ๋๋ ์ฅ์ ์ด ์์ต๋๋ค :)
ํ์ง๋ง NPE๊ฐ ๋ฐ์ํ ์ํ์ด ์๊ธฐ ๋๋ฌธ์, Optional์ ์ฌ์ฉํด๋ณด์๋ ๊ฒ๋ ๊ณ ๋ คํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
๊ทธ๋ ๊ฒ ํ๋ฉด
```java
public static Optional<Menu> from(String menuName) {
return Optional.ofNullalbe(cachedMenu.get(menuName);
}
```
์์ ๊ฐ์ด ๋ฆฌํฉํฐ๋ง ํด๋ณผ ์ ์์ ๊ฒ ๊ฐ์์ :) |
@@ -0,0 +1,98 @@
+package christmas.service;
+
+import static christmas.constants.event.EventRule.MAX_MENU_AMOUNT;
+import static christmas.constants.menu.MenuType.DRINKS;
+import static christmas.exception.ErrorCode.INVALID_MENU_ORDER;
+
+import christmas.constants.menu.Menu;
+import christmas.constants.menu.MenuType;
+import christmas.dto.SingleMenu;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+public class MenuService {
+ private final Map<Menu, Integer> menuScript;
+
+ public MenuService() {
+ this.menuScript = new EnumMap<>(Menu.class);
+ }
+
+ public void order(List<SingleMenu> singleMenus) {
+ validate(singleMenus);
+ singleMenus.forEach(singleOrder -> {
+ Menu menu = Menu.from(singleOrder.menu());
+ menuScript.put(menu, singleOrder.amount());
+ });
+ }
+
+ public int getOrderPrice() {
+ return menuScript.keySet()
+ .stream()
+ .mapToInt(menu -> menu.getPrice() * menuScript.get(menu))
+ .sum();
+ }
+
+ private void validate(List<SingleMenu> singleMenus) {
+ validateDuplicate(singleMenus);
+ validatePerMenuAmount(singleMenus);
+ validateOnlyDrink(singleMenus);
+ validateTotalMenuAmount(singleMenus);
+ }
+
+ private void validateDuplicate(List<SingleMenu> singleMenus) {
+ int count = (int) getMenuStream(singleMenus)
+ .distinct()
+ .count();
+
+ if (count != singleMenus.size()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private void validateOnlyDrink(List<SingleMenu> singleMenus) {
+ int drinks = (int) getMenuStream(singleMenus)
+ .filter(menu -> menu.getMenuType() == DRINKS)
+ .count();
+
+ if (drinks > 0 && drinks == singleMenus.size()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private Stream<Menu> getMenuStream(List<SingleMenu> singleMenus) {
+ return singleMenus.stream()
+ .map(singleOrder -> Menu.from(singleOrder.menu()));
+ }
+
+ private void validatePerMenuAmount(List<SingleMenu> singleMenus) {
+ boolean present = singleMenus.stream()
+ .anyMatch(singleOrder -> singleOrder.amount() < 1);
+ if (present) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private void validateTotalMenuAmount(List<SingleMenu> singleMenus) {
+ int totalAmount = singleMenus.stream()
+ .mapToInt(SingleMenu::amount)
+ .sum();
+ if (totalAmount >= MAX_MENU_AMOUNT.getValue()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ public int getAmountByMenu(MenuType menuType) {
+ return menuScript.keySet()
+ .stream()
+ .filter(target -> target.getMenuType() == menuType)
+ .mapToInt(menuScript::get)
+ .sum();
+ }
+
+ public Map<Menu, Integer> getMenuScript() {
+ return Collections.unmodifiableMap(menuScript);
+ }
+} | Java | `MenuService` ์์ ์ฃผ๋ฌธ ์ ๋ณด๋ค์ ๋ด๊ณ ์๋๊ฒ ์ธ์๊น์ต๋๋ค!
์ด๊ฒ๋ ์ข์ ์ ๊ทผ ๋ฐฉ์์ธ ๊ฒ ๊ฐ์ง๋ง, `Map<Menu, Integer>`๊ฐ `์ฃผ๋ฌธ ์ ๋ณด` ๋ผ๋ ์ฌ์ค์ ์ถ์ ํ๊ธฐ ์ด๋ ค์ธ ์๋ ์์ ๊ฒ ๊ฐ์์!
`Order` Domain ํด๋์ค๋ฅผ ์์ฑํ๊ณ , validate ๊ฒ์ฆ ์ญํ ๋ ์์ํด์ฃผ๋ฉด MenuService ํด๋์ค๊ฐ ํ์ธต ์์์ง ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
์ฌ๊ธฐ์ Service Layer์ ํด๋์ค๊ฐ ์์์ง๋ค๋ ๊ฒ์ **Domain ๊ฐ์ฒด์๊ฒ ์์ฒญํ์ฌ ๊ฒฐ๊ณผ ๊ฐ์ ๋ฐํํ๋ ์ญํ **, **๋น์ฆ๋์ค ๋ก์ง ํ๋ฆ์ ๋ด๋นํ๋ ์ญํ **๋ก ์ถ์ ๋๋ค๋ ์๋ฏธ๋ผ๊ณ ์๊ฐํด์. ์ด๋์ ์ฅ์ ์ **MenuService ๋น์ฆ๋์ค ๋ก์ง์ด ์ด๋ค ํ๋ฆ์ผ๋ก ์งํ๋๋๊ตฌ๋** ์ถ์ ํ๊ธฐ ํธํด์ง๋ ์ ๊ฐ์ต๋๋ค :) |
@@ -0,0 +1,32 @@
+package christmas.util;
+
+import static christmas.exception.ErrorCode.INVALID_DATE;
+import static christmas.exception.ErrorCode.INVALID_MENU_ORDER;
+
+import java.util.List;
+
+public class Parser {
+ public static int parseToDate(String input) {
+ try {
+ return Integer.parseInt(input);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+ }
+
+ public static int parseToAmount(String input) {
+ try {
+ return Integer.parseInt(input);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ public static List<String> parseToMenu(String input, String delimiter) {
+ try {
+ return List.of(input.split(delimiter));
+ } catch (IndexOutOfBoundsException e) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+} | Java | catch ํ ์ด๋ ํ Exception์ ๋ค๋ฅธ Exception์ผ๋ก ๋ํํ์ฌ ๋ค์ ๋์ ธ์ค ๋, catch ํ๋ Exception๋ ๋ฃ์ด์ ๋๊ฒจ์ฃผ๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค.
```java
public static int parseToDate(String input) {
try {
return Integer.parseInt(input);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(INVALID_DATE.getMessage(), e);
}
}
```
๊ทธ๋ ์ง ์์ผ๋ฉด ๊ธฐ์กด์ catch ํ๋ ์์ธ๊ฐ ๋ ์๊ฐ๋ฒ๋ฆฌ๋ ์ํฉ์ด ๋์ด, ์ธ๋ถ ์์ธ๋ฅผ ์คํ ํธ๋ ์ด์ค ํ ์ ์๊ฒ๋ฉ๋๋น! |
@@ -0,0 +1,25 @@
+package christmas.constants.event;
+
+public enum EventRule {
+ EVENT_THRESHOLD(10_000),
+ PRESENT_THRESHOLD(120_000),
+ EVENT_START(1),
+ EVENT_END(31),
+ MAX_MENU_AMOUNT(20),
+ CHRISTMAS_EVENT_END(25),
+ CHRISTMAS_INIT_PRICE(1_000),
+ CHRISTMAS_EXTRA_DISCOUNT(100),
+ MENU_DISCOUNT(2_023),
+ SPECIAL_DISCOUNT(1_000);
+
+
+ private final int value;
+
+ EventRule(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+} | Java | ์ด๋ฒคํธ ๋ฃฐ์ ํ ๊ณณ์ ๋ชจ์๋์ผ๋ ์ฝ๋๊ฐ ์ฝ๊ฒ ์ฝํ์ง ์๋๊ฑฐ ๊ฐ์์! ์ด๋ฒคํธ ์ข
๋ฅ์ ๋ฐ๋ผ ๋ถ๋ฆฌํ๊ฑฐ๋, EventType์ ๋ฉค๋ฒ๋ณ์๋ก ๋ฃฐ์ ์ ์ํ์๋ ๊ฒ์ ์ด๋ค๊ฐ์? |
@@ -0,0 +1,38 @@
+package christmas.exception;
+
+import christmas.view.output.OutputView;
+import java.util.Arrays;
+import java.util.function.Supplier;
+
+public class RetryHandler implements ExceptionHandler {
+ private final OutputView outputView;
+
+ public RetryHandler(OutputView outputView) {
+ this.outputView = outputView;
+ }
+
+ @Override
+ @SafeVarargs
+ public final <T> T execute(Supplier<T> action, Class<? extends Exception>... exceptions) {
+ while (true) {
+ try {
+ return action.get();
+ } catch (IllegalArgumentException e) {
+ printException(e, exceptions);
+ }
+ }
+ }
+
+ private void printException(Exception actual, Class<? extends Exception>... exceptions) {
+ if (isExpectedException(actual, exceptions)) {
+ outputView.printError(actual.getMessage());
+ return;
+ }
+ throw new RuntimeException(actual);
+ }
+
+ private boolean isExpectedException(Exception actual, Class<? extends Exception>... exceptions) {
+ return Arrays.stream(exceptions)
+ .anyMatch(exception -> exception.isInstance(actual));
+ }
+} | Java | ์ค์ exception๊ณผ ์ธ์๋ก ๋ฐ์ exception์ ๋น๊ตํ๋ ๋ก์ง์ด ํ์ํ ์ด์ ๊ฐ ๊ถ๊ธํด์! |
@@ -0,0 +1,19 @@
+package christmas.constants.event;
+
+public enum EventType {
+ CHRISTMAS("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ"),
+ WEEKDAY("ํ์ผ ํ ์ธ"),
+ WEEKEND("์ฃผ๋ง ํ ์ธ"),
+ SPECIAL("ํน๋ณ ํ ์ธ"),
+ PRESENT("์ฆ์ ์ด๋ฒคํธ");
+
+ private final String description;
+
+ EventType(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+} | Java | `Eventable` ์ธํฐํ์ด์ค์ `๊ฐ๊ฐ์ ์ด๋ฒคํธ ๊ตฌํ์ฒด ํด๋์ค`์์ ํ ์ธ / ์ฆ์ ์ํ ๊ณ์ฐ ์ฒ๋ฆฌํ์ ๋ฐฉ๋ฒ๋ ๊ต์ฅํ ์ง๊ด์ ์ผ๋ก ์ฝํ๊ณ ์ ๋ง ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! ๐
์ ๋ `ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด/ ํ์ผ/ ์ฃผ๋ง /ํน๋ณ ํ ์ธ ์ด๋ฒคํธ ์ ํ`๊ณผ `ํ ์ธ ์ด๋ฒคํธ ์ ํ์ ํด๋นํ๋ ๊ณ์ฐ ์ฒ๋ฆฌ`๋ **์๋ก ๋ฐ์ ํ ์ฐ๊ด์ด ์๋ ์์**๋ผ๋ ์๊ฐ์ด ๋ค์์ต๋๋ค! ๊ทธ๋์ `EventType Enum`์์ ํ ์ธ ๊ณ์ฐ ์ฒ๋ฆฌ๋ ํจ๊ป ๊ด๋ฆฌํ๋๋ก ํ์ต๋๋ค.
์ด๋ ๊ฒ ์ฒ๋ฆฌ๋ฅผ ํ๋ **ํ ์ธ ์ด๋ฒคํธ ์ ํ์ด๋ผ๋ ์ํ**์ **์ด๋ฒคํธ ์ ํ์ ๋ํ ๊ณ์ฐ์ฒ๋ฆฌ๋ผ๋ ํ์**๊ฐ ํ ๊ณณ์ ๋ฐ์ง๋์ด ์์ด ์ ์ง๋ณด์ํ๊ธฐ ํธํ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ค์์ต๋๋ค! ์ด ๋ถ๋ถ์ ๋ํด์ HEY๋ ์๊ฒฌ์ด ๊ถ๊ธํฉ๋๋ค ๐ |
@@ -0,0 +1,7 @@
+package christmas.model;
+
+public interface Eventable<T> {
+ boolean canJoinEvent(T condition);
+
+ int getDiscountPrice();
+} | Java | Eventable์ด๋ผ๋ ๊ฐ์ฒด๋ช
์ด ์กฐ๊ธ ํท๊ฐ๋ฆฌ๋๊ฑฐ ๊ฐ์์. ํ์ฌ Eventable์ ์ด๋ฒคํธ ์ฌ๋ถ๋ฅผ ํ๋จํ๋ ๋ฉ์๋์ ํ ์ธ ๊ธ์ก์ ๊ณ์ฐํ๋ ๋ฉ์๋๊ฐ ์กด์ฌํด์. ํ์ง๋ง Eventable ๋ค์ด๋ฐ์ ํ ์ธ ์ฌ๋ถ๋ง ํ๋จํ๋ ์ญํ ์ด๋ผ๊ณ ์คํดํ ์ ์์๊ฑฐ ๊ฐ์ต๋๋ค ๐ฅ |
@@ -0,0 +1,33 @@
+package christmas.model;
+
+import static christmas.constants.event.EventRule.PRESENT_THRESHOLD;
+import static christmas.constants.menu.Menu.CHAMPAGNE;
+
+public class PresentEvent implements Eventable<Integer> {
+ private final int amount;
+
+ private PresentEvent(int orderPrice) {
+ if (canJoinEvent(orderPrice)) {
+ this.amount = 1;
+ return;
+ }
+ this.amount = 0;
+ }
+
+ public static PresentEvent create(int orderPrice) {
+ return new PresentEvent(orderPrice);
+ }
+
+ @Override
+ public boolean canJoinEvent(Integer orderPrice) {
+ if (orderPrice < PRESENT_THRESHOLD.getValue()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int getDiscountPrice() {
+ return CHAMPAGNE.getPrice() * amount;
+ }
+} | Java | 1 ์ด๋ผ๋ ์ซ์๋ฅผ ์์๋ก ์ ์ธํ๋ ๊ฒ์ ์ด๋ค๊ฐ์? ์๊ตฌ์ฌํญ์ ์ดํดํ์ง ๋ชปํ ์ฌ๋์ด ์ฝ๋๋ฅผ ๋ณด๋ ๊ฒฝ์ฐ 1์ด๋ผ๋ ์ซ์์ ์๋ฏธ๋ฅผ ํ์
ํ๊ธฐ ์ด๋ ค์ธ๊ฑฐ ๊ฐ์์ :) |
@@ -0,0 +1,80 @@
+package christmas.service;
+
+import static christmas.constants.event.EventRule.EVENT_THRESHOLD;
+import static christmas.constants.event.EventType.CHRISTMAS;
+import static christmas.constants.event.EventType.PRESENT;
+import static christmas.constants.event.EventType.SPECIAL;
+import static christmas.constants.event.EventType.WEEKDAY;
+import static christmas.constants.event.EventType.WEEKEND;
+
+import christmas.constants.event.EventType;
+import christmas.dto.EventDetail;
+import christmas.dto.UserOrder;
+import christmas.model.ChristmasEvent;
+import christmas.model.Eventable;
+import christmas.model.PresentEvent;
+import christmas.model.SpecialEvent;
+import christmas.model.WeekdayEvent;
+import christmas.model.WeekendEvent;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
+public class EventService {
+ private final Map<EventType, Eventable> eventResult;
+ private final int INVALID_VALUE = 0;
+
+ public EventService() {
+ eventResult = new EnumMap<>(EventType.class);
+ }
+
+ public void applyEvent(UserOrder userOrder) {
+ if (!canJoinEvent(userOrder.orderPrice())) {
+ userOrder = new UserOrder(INVALID_VALUE, INVALID_VALUE, INVALID_VALUE, INVALID_VALUE);
+ }
+
+ eventResult.put(PRESENT, PresentEvent.create(userOrder.orderPrice()));
+ eventResult.put(CHRISTMAS, ChristmasEvent.create(userOrder.date()));
+ eventResult.put(WEEKDAY, WeekdayEvent.create(userOrder));
+ eventResult.put(WEEKEND, WeekendEvent.create(userOrder));
+ eventResult.put(SPECIAL, SpecialEvent.create(userOrder.date()));
+ }
+
+ private boolean canJoinEvent(int orderPrice) {
+ if (orderPrice < EVENT_THRESHOLD.getValue()) {
+ return false;
+ }
+ return true;
+ }
+
+ public int getDiscountPriceByEvent(EventType eventType) {
+ return eventResult.get(eventType).getDiscountPrice();
+ }
+
+ public int getExpectedPrice(UserOrder userOrder) {
+ return userOrder.orderPrice() - getTotalDiscountPrice();
+ }
+
+ public int getTotalDiscountPrice() {
+ return eventResult.entrySet()
+ .stream()
+ .filter(entry -> entry.getKey() != PRESENT)
+ .mapToInt(value -> value.getValue().getDiscountPrice())
+ .sum();
+ }
+
+ public int getTotalBenefitPrice() {
+ return eventResult.values()
+ .stream()
+ .mapToInt(Eventable::getDiscountPrice)
+ .sum();
+ }
+
+ public List<EventDetail> convertToEventDetails() {
+ return eventResult.entrySet()
+ .stream()
+ .filter(entry -> entry.getValue().getDiscountPrice() != 0)
+ .map(entry -> new EventDetail(entry.getKey(), entry.getValue().getDiscountPrice()))
+ .toList();
+ }
+} | Java | EventService๋ ์ถฉ๋ถํ ์ข์ ์ฝ๋๋ผ๊ณ ์๊ฐ๋ฉ๋๋ค!
์ด๋ฒคํธ๋ `ํ ์ธ`์ ๋ํ ์ด๋ฒคํธ, `์ฆ์ ์ํ`์ ๋ํ ์ด๋ฒคํธ๋ก ๋๋๊ธฐ ๋๋ฌธ์ `DiscountEventService`, `GiftEventService`๋ก ๋๋๋ค๋ฉด, ๊ฐ ์๋น์ค ํด๋์ค๊ฐ ์ด๋ค ์ด๋ฒคํธ์ ๋ํด ์ฒ๋ฆฌํ๋์ง ๋ณด๋ค ๋ช
ํํด์ง๊ณ ์ ์ง๋ณด์ํ๊ธฐ๋ ์ข์์ง ๊ฒ ๊ฐ์ต๋๋ค :) |
@@ -0,0 +1,31 @@
+package christmas.model;
+
+import static christmas.constants.event.EventRule.SPECIAL_DISCOUNT;
+
+import christmas.util.DayAnalyzer;
+
+public class SpecialEvent implements Eventable<Integer> {
+ private final int discountPrice;
+
+ private SpecialEvent(Integer date) {
+ if (canJoinEvent(date)) {
+ discountPrice = SPECIAL_DISCOUNT.getValue();
+ return;
+ }
+ discountPrice = 0;
+ }
+
+ public static SpecialEvent create(Integer date) {
+ return new SpecialEvent(date);
+ }
+
+ @Override
+ public boolean canJoinEvent(Integer date) {
+ return DayAnalyzer.isSpecialDay(date);
+ }
+
+ @Override
+ public int getDiscountPrice() {
+ return this.discountPrice;
+ }
+} | Java | ํด๋น ๋ก์ง์ ์ ์ ๋ฉ์๋์ ๋ค์ด๊ฐ๋ ๊ฒ์ด ์ ํฉํ ๊ฑฐ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์? ์์ฑ์๋ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ์ฑ
์๋ง ๊ฐ๊ณ , ์ ์ ๋ฉ์๋์์ ์กฐ๊ฑด์ ๋ฐ๋ฅธ discountPrice๊ฐ์ ์์ฑ์๋ก ๋๊ฒจ์ค ์ ์์๊ฑฐ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,80 @@
+package christmas.service;
+
+import static christmas.constants.event.EventRule.EVENT_THRESHOLD;
+import static christmas.constants.event.EventType.CHRISTMAS;
+import static christmas.constants.event.EventType.PRESENT;
+import static christmas.constants.event.EventType.SPECIAL;
+import static christmas.constants.event.EventType.WEEKDAY;
+import static christmas.constants.event.EventType.WEEKEND;
+
+import christmas.constants.event.EventType;
+import christmas.dto.EventDetail;
+import christmas.dto.UserOrder;
+import christmas.model.ChristmasEvent;
+import christmas.model.Eventable;
+import christmas.model.PresentEvent;
+import christmas.model.SpecialEvent;
+import christmas.model.WeekdayEvent;
+import christmas.model.WeekendEvent;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
+public class EventService {
+ private final Map<EventType, Eventable> eventResult;
+ private final int INVALID_VALUE = 0;
+
+ public EventService() {
+ eventResult = new EnumMap<>(EventType.class);
+ }
+
+ public void applyEvent(UserOrder userOrder) {
+ if (!canJoinEvent(userOrder.orderPrice())) {
+ userOrder = new UserOrder(INVALID_VALUE, INVALID_VALUE, INVALID_VALUE, INVALID_VALUE);
+ }
+
+ eventResult.put(PRESENT, PresentEvent.create(userOrder.orderPrice()));
+ eventResult.put(CHRISTMAS, ChristmasEvent.create(userOrder.date()));
+ eventResult.put(WEEKDAY, WeekdayEvent.create(userOrder));
+ eventResult.put(WEEKEND, WeekendEvent.create(userOrder));
+ eventResult.put(SPECIAL, SpecialEvent.create(userOrder.date()));
+ }
+
+ private boolean canJoinEvent(int orderPrice) {
+ if (orderPrice < EVENT_THRESHOLD.getValue()) {
+ return false;
+ }
+ return true;
+ }
+
+ public int getDiscountPriceByEvent(EventType eventType) {
+ return eventResult.get(eventType).getDiscountPrice();
+ }
+
+ public int getExpectedPrice(UserOrder userOrder) {
+ return userOrder.orderPrice() - getTotalDiscountPrice();
+ }
+
+ public int getTotalDiscountPrice() {
+ return eventResult.entrySet()
+ .stream()
+ .filter(entry -> entry.getKey() != PRESENT)
+ .mapToInt(value -> value.getValue().getDiscountPrice())
+ .sum();
+ }
+
+ public int getTotalBenefitPrice() {
+ return eventResult.values()
+ .stream()
+ .mapToInt(Eventable::getDiscountPrice)
+ .sum();
+ }
+
+ public List<EventDetail> convertToEventDetails() {
+ return eventResult.entrySet()
+ .stream()
+ .filter(entry -> entry.getValue().getDiscountPrice() != 0)
+ .map(entry -> new EventDetail(entry.getKey(), entry.getValue().getDiscountPrice()))
+ .toList();
+ }
+} | Java | ํด๋น ๋ก์ง์ EnumMap์ ์ด๊ธฐํํ๋ ๋ก์ง์ธ๊ฑฐ ๊ฐ์์. ๊ทธ๋ผ ์์ฑ์๊ฐ ์๋ init ์ด๋ผ๋ ์ด๋ฆ์ ์ ์ ๋ฉ์๋๋ฅผ ํตํด ๋ด๋ถ ๋ก์ง์ ์ข ๋ ๋ช
ํํ ํ์
ํ ์ ์๋๋ก ํ๋ ๊ฒ์ ์ด๋ค๊ฐ์? |
@@ -0,0 +1,80 @@
+package christmas.service;
+
+import static christmas.constants.event.EventRule.EVENT_THRESHOLD;
+import static christmas.constants.event.EventType.CHRISTMAS;
+import static christmas.constants.event.EventType.PRESENT;
+import static christmas.constants.event.EventType.SPECIAL;
+import static christmas.constants.event.EventType.WEEKDAY;
+import static christmas.constants.event.EventType.WEEKEND;
+
+import christmas.constants.event.EventType;
+import christmas.dto.EventDetail;
+import christmas.dto.UserOrder;
+import christmas.model.ChristmasEvent;
+import christmas.model.Eventable;
+import christmas.model.PresentEvent;
+import christmas.model.SpecialEvent;
+import christmas.model.WeekdayEvent;
+import christmas.model.WeekendEvent;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
+public class EventService {
+ private final Map<EventType, Eventable> eventResult;
+ private final int INVALID_VALUE = 0;
+
+ public EventService() {
+ eventResult = new EnumMap<>(EventType.class);
+ }
+
+ public void applyEvent(UserOrder userOrder) {
+ if (!canJoinEvent(userOrder.orderPrice())) {
+ userOrder = new UserOrder(INVALID_VALUE, INVALID_VALUE, INVALID_VALUE, INVALID_VALUE);
+ }
+
+ eventResult.put(PRESENT, PresentEvent.create(userOrder.orderPrice()));
+ eventResult.put(CHRISTMAS, ChristmasEvent.create(userOrder.date()));
+ eventResult.put(WEEKDAY, WeekdayEvent.create(userOrder));
+ eventResult.put(WEEKEND, WeekendEvent.create(userOrder));
+ eventResult.put(SPECIAL, SpecialEvent.create(userOrder.date()));
+ }
+
+ private boolean canJoinEvent(int orderPrice) {
+ if (orderPrice < EVENT_THRESHOLD.getValue()) {
+ return false;
+ }
+ return true;
+ }
+
+ public int getDiscountPriceByEvent(EventType eventType) {
+ return eventResult.get(eventType).getDiscountPrice();
+ }
+
+ public int getExpectedPrice(UserOrder userOrder) {
+ return userOrder.orderPrice() - getTotalDiscountPrice();
+ }
+
+ public int getTotalDiscountPrice() {
+ return eventResult.entrySet()
+ .stream()
+ .filter(entry -> entry.getKey() != PRESENT)
+ .mapToInt(value -> value.getValue().getDiscountPrice())
+ .sum();
+ }
+
+ public int getTotalBenefitPrice() {
+ return eventResult.values()
+ .stream()
+ .mapToInt(Eventable::getDiscountPrice)
+ .sum();
+ }
+
+ public List<EventDetail> convertToEventDetails() {
+ return eventResult.entrySet()
+ .stream()
+ .filter(entry -> entry.getValue().getDiscountPrice() != 0)
+ .map(entry -> new EventDetail(entry.getKey(), entry.getValue().getDiscountPrice()))
+ .toList();
+ }
+} | Java | ์ด๋ฒคํธ์ ๋ํ ์ ์ฑ
๋ค์ ์ธ๋ถ์์ ์ฃผ์
๋ฐ๋๋ก ํ๋ ๊ฒ์ ์ด๋ค๊ฐ์? ํ์ฌ ์ฝ๋๋ ์์กด ์ญ์ ์์น(DIP)์ ์ค์ํ์ง ์์ ์ฝ๋๋ผ๊ณ ์๊ฐํฉ๋๋ค. ํ ์ธ ์ข
๋ฅ์ ๋ํ ์ ์ฑ
์ด ๋ณํ๋ ๊ฒฝ์ฐ ์ ํ๋ฆฌ์ผ์ด์
์ฝ๋๋ฅผ ์์ ํด์ผํ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค. ๋ฐ๋ผ์, ์ ํ๋ฆฌ์ผ์ด์
๋ด๋ถ์์๋ ์ถ์ ๊ฐ์ฒด์ ์์กดํ๊ณ , service ์์ฑ์์ EnumMap์ ๋๊ฒจ์ฃผ๋ ๊ฒ์ ์ด๋ค๊ฐ์? |
@@ -0,0 +1,98 @@
+package christmas.service;
+
+import static christmas.constants.event.EventRule.MAX_MENU_AMOUNT;
+import static christmas.constants.menu.MenuType.DRINKS;
+import static christmas.exception.ErrorCode.INVALID_MENU_ORDER;
+
+import christmas.constants.menu.Menu;
+import christmas.constants.menu.MenuType;
+import christmas.dto.SingleMenu;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+public class MenuService {
+ private final Map<Menu, Integer> menuScript;
+
+ public MenuService() {
+ this.menuScript = new EnumMap<>(Menu.class);
+ }
+
+ public void order(List<SingleMenu> singleMenus) {
+ validate(singleMenus);
+ singleMenus.forEach(singleOrder -> {
+ Menu menu = Menu.from(singleOrder.menu());
+ menuScript.put(menu, singleOrder.amount());
+ });
+ }
+
+ public int getOrderPrice() {
+ return menuScript.keySet()
+ .stream()
+ .mapToInt(menu -> menu.getPrice() * menuScript.get(menu))
+ .sum();
+ }
+
+ private void validate(List<SingleMenu> singleMenus) {
+ validateDuplicate(singleMenus);
+ validatePerMenuAmount(singleMenus);
+ validateOnlyDrink(singleMenus);
+ validateTotalMenuAmount(singleMenus);
+ }
+
+ private void validateDuplicate(List<SingleMenu> singleMenus) {
+ int count = (int) getMenuStream(singleMenus)
+ .distinct()
+ .count();
+
+ if (count != singleMenus.size()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private void validateOnlyDrink(List<SingleMenu> singleMenus) {
+ int drinks = (int) getMenuStream(singleMenus)
+ .filter(menu -> menu.getMenuType() == DRINKS)
+ .count();
+
+ if (drinks > 0 && drinks == singleMenus.size()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private Stream<Menu> getMenuStream(List<SingleMenu> singleMenus) {
+ return singleMenus.stream()
+ .map(singleOrder -> Menu.from(singleOrder.menu()));
+ }
+
+ private void validatePerMenuAmount(List<SingleMenu> singleMenus) {
+ boolean present = singleMenus.stream()
+ .anyMatch(singleOrder -> singleOrder.amount() < 1);
+ if (present) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private void validateTotalMenuAmount(List<SingleMenu> singleMenus) {
+ int totalAmount = singleMenus.stream()
+ .mapToInt(SingleMenu::amount)
+ .sum();
+ if (totalAmount >= MAX_MENU_AMOUNT.getValue()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ public int getAmountByMenu(MenuType menuType) {
+ return menuScript.keySet()
+ .stream()
+ .filter(target -> target.getMenuType() == menuType)
+ .mapToInt(menuScript::get)
+ .sum();
+ }
+
+ public Map<Menu, Integer> getMenuScript() {
+ return Collections.unmodifiableMap(menuScript);
+ }
+} | Java | ์ผ๋ฐ์ ์ผ๋ก validate ๊ฒ์ฆ ํ
์คํธ๋ public ๋ฉ์๋๋ฅผ ํ
์คํธํ์ฌ ์งํํ๋๋ฐ, ๋ชจ๋ private ๋ฉ์๋๊ฐ ๋์ผํ ์์ธ๋ฅผ ๋์ง๊ณ ์๊ธฐ ๋๋ฌธ์ ๋ฉ์์ง ๋ด์ฉ์ ํ์ธํ๋ ๋ฑ ์ธ๋ถ์ ์ธ ๊ฒ์ฆ ์ ์ฐจ๊ฐ ํ์ํ๋ค ์๊ฐํฉ๋๋ค. `IllegalArgumentException`์ด ์ ํํ ์ด๋ ์ง์ ์์ ๋ฐ์ํ๋์ง ์๊ธฐ ์ด๋ ค์ฐ๋๊น์!
ํ์ง๋ง ์ด๋ฒ ๋ฏธ์
์ `์๋ฌ๋ฌธ ๋ด์ฉ์ด 2๊ฐ์ง`๋ก ์ ํด์ ธ ์๊ธฐ ๋๋ฌธ์, ์ด์ ๋ฏธ์
๊ฐ์ด `์๋ฌ๋ฌธ ๋ด์ฉ์ผ๋ก ์ธ๋ถ์ ์ธ ํ
์คํธ`๋ฅผ ํ๊ธฐ๊ฐ ์ด๋ ค์ ์ต๋๋ค. ๊ทธ๋์ ์ ๋ ์ธ๋ถ ๊ฒ์ฆ์ ์ํด **์ปค์คํ
์์ธ**๋ฅผ ๋์
ํ์ฌ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์๋๋ฐ, ์ฐธ๊ณ ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค :)
์กฐ๊ธ ์ค๋ฒ์์ง๋์ด๋ง ๊ฐ์ ์๊ฐ๋ ๋ค์ด ์ฌ๋ฐ๋ฅธ ์ ๊ทผ ๋ฐฉ์์ธ์ง๋ ์ ๋ชจ๋ฅด๊ฒ ๋ค์ ใ
ใ
.. |
@@ -0,0 +1,45 @@
+package christmas.util;
+
+import static christmas.constants.Day.FRIDAY;
+import static christmas.constants.Day.SATURDAY;
+import static christmas.constants.Day.SUNDAY;
+import static christmas.constants.Day.THURSDAY;
+
+import christmas.constants.Day;
+import java.util.Arrays;
+
+public class DayAnalyzer {
+ private static final int DAY_OF_WEEK = 7;
+ private static final int CHRISTMAS_DAY = 25;
+
+ private static Day getDay(int date) {
+ return Arrays.stream(Day.values())
+ .filter(day -> day.getIndex() == date % DAY_OF_WEEK)
+ .findFirst()
+ .orElseThrow();
+ }
+
+ public static boolean isWeekday(int date) {
+ Day targetDay = getDay(date);
+ if (targetDay.compareTo(THURSDAY) <= 0 && targetDay.compareTo(SUNDAY) >= 0) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isWeekend(int date) {
+ Day targetDay = getDay(date);
+ if (targetDay == FRIDAY || targetDay == SATURDAY) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isSpecialDay(int date) {
+ Day targetDay = getDay(date);
+ if (targetDay == SUNDAY || date == CHRISTMAS_DAY) {
+ return true;
+ }
+ return false;
+ }
+} | Java | ์ ๋ ๋ ์ง๋ฅผ ํ๋์ฝ๋ฉํด๋ฒ๋ ธ๋๋ฐ,,, DayAnalyzer ํด๋์ค ์ ๋ง ์ง๊ด์ ์ด๊ณ ์ข์ ์ ๊ทผ ๋ฐฉ์์ธ ๊ฒ ๊ฐ์ต๋๋ค ๐๐ |
@@ -0,0 +1,7 @@
+package christmas.exception;
+
+import java.util.function.Supplier;
+
+public interface ExceptionHandler {
+ <T> T execute(Supplier<T> action, Class<? extends Exception>... exceptions);
+} | Java | `Class<? extends Exception>... exceptions`๋ ์ด๋ค ์ญํ ์ ํ๋ผ๋ฏธํฐ์ธ์ง, ์ด๋ป๊ฒ ํ์ฉ๋๋์ง ์ฌ์ญค๋ณด๊ณ ์ถ์ต๋๋ค! |
@@ -0,0 +1,30 @@
+package christmas.constants.event;
+
+public enum BadgeType {
+ NONE("์์", 0),
+ STAR("๋ณ", 5_000),
+ TREE("ํธ๋ฆฌ", 10_000),
+ SANTA("์ฐํ", 20_000);
+
+ private final String name;
+ private final int threshold;
+
+ BadgeType(String name, int threshold) {
+ this.name = name;
+ this.threshold = threshold;
+ }
+
+ public static BadgeType from(int benefitPrice) {
+ BadgeType result = NONE;
+ for (BadgeType badgeType : values()) {
+ if (benefitPrice >= badgeType.threshold) {
+ result = badgeType;
+ }
+ }
+ return result;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | stream์ผ๋ก ์ต์ ํ ํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,13 @@
+package christmas.dto;
+
+import christmas.util.Parser;
+import java.util.List;
+
+public record SingleMenu(String menu, int amount) {
+ private static final String DELIMITER = "-";
+
+ public static SingleMenu create(String singleOrder) {
+ List<String> parsed = Parser.parseToMenu(singleOrder, DELIMITER);
+ return new SingleMenu(parsed.get(0), Parser.parseToAmount(parsed.get(1)));
+ }
+} | Java | SingleMenu๋ฅผ record๋ก ํ์ ์ด์ ๊ฐ ๋ฌด์์ธ๊ฐ์? |
@@ -0,0 +1,38 @@
+package christmas.exception;
+
+import christmas.view.output.OutputView;
+import java.util.Arrays;
+import java.util.function.Supplier;
+
+public class RetryHandler implements ExceptionHandler {
+ private final OutputView outputView;
+
+ public RetryHandler(OutputView outputView) {
+ this.outputView = outputView;
+ }
+
+ @Override
+ @SafeVarargs
+ public final <T> T execute(Supplier<T> action, Class<? extends Exception>... exceptions) {
+ while (true) {
+ try {
+ return action.get();
+ } catch (IllegalArgumentException e) {
+ printException(e, exceptions);
+ }
+ }
+ }
+
+ private void printException(Exception actual, Class<? extends Exception>... exceptions) {
+ if (isExpectedException(actual, exceptions)) {
+ outputView.printError(actual.getMessage());
+ return;
+ }
+ throw new RuntimeException(actual);
+ }
+
+ private boolean isExpectedException(Exception actual, Class<? extends Exception>... exceptions) {
+ return Arrays.stream(exceptions)
+ .anyMatch(exception -> exception.isInstance(actual));
+ }
+} | Java | @safevarargs๋ ์ ์ฌ์ฉํ์ ๊ฑด๊ฐ์? |
@@ -0,0 +1,80 @@
+package christmas.service;
+
+import static christmas.constants.event.EventRule.EVENT_THRESHOLD;
+import static christmas.constants.event.EventType.CHRISTMAS;
+import static christmas.constants.event.EventType.PRESENT;
+import static christmas.constants.event.EventType.SPECIAL;
+import static christmas.constants.event.EventType.WEEKDAY;
+import static christmas.constants.event.EventType.WEEKEND;
+
+import christmas.constants.event.EventType;
+import christmas.dto.EventDetail;
+import christmas.dto.UserOrder;
+import christmas.model.ChristmasEvent;
+import christmas.model.Eventable;
+import christmas.model.PresentEvent;
+import christmas.model.SpecialEvent;
+import christmas.model.WeekdayEvent;
+import christmas.model.WeekendEvent;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
+public class EventService {
+ private final Map<EventType, Eventable> eventResult;
+ private final int INVALID_VALUE = 0;
+
+ public EventService() {
+ eventResult = new EnumMap<>(EventType.class);
+ }
+
+ public void applyEvent(UserOrder userOrder) {
+ if (!canJoinEvent(userOrder.orderPrice())) {
+ userOrder = new UserOrder(INVALID_VALUE, INVALID_VALUE, INVALID_VALUE, INVALID_VALUE);
+ }
+
+ eventResult.put(PRESENT, PresentEvent.create(userOrder.orderPrice()));
+ eventResult.put(CHRISTMAS, ChristmasEvent.create(userOrder.date()));
+ eventResult.put(WEEKDAY, WeekdayEvent.create(userOrder));
+ eventResult.put(WEEKEND, WeekendEvent.create(userOrder));
+ eventResult.put(SPECIAL, SpecialEvent.create(userOrder.date()));
+ }
+
+ private boolean canJoinEvent(int orderPrice) {
+ if (orderPrice < EVENT_THRESHOLD.getValue()) {
+ return false;
+ }
+ return true;
+ }
+
+ public int getDiscountPriceByEvent(EventType eventType) {
+ return eventResult.get(eventType).getDiscountPrice();
+ }
+
+ public int getExpectedPrice(UserOrder userOrder) {
+ return userOrder.orderPrice() - getTotalDiscountPrice();
+ }
+
+ public int getTotalDiscountPrice() {
+ return eventResult.entrySet()
+ .stream()
+ .filter(entry -> entry.getKey() != PRESENT)
+ .mapToInt(value -> value.getValue().getDiscountPrice())
+ .sum();
+ }
+
+ public int getTotalBenefitPrice() {
+ return eventResult.values()
+ .stream()
+ .mapToInt(Eventable::getDiscountPrice)
+ .sum();
+ }
+
+ public List<EventDetail> convertToEventDetails() {
+ return eventResult.entrySet()
+ .stream()
+ .filter(entry -> entry.getValue().getDiscountPrice() != 0)
+ .map(entry -> new EventDetail(entry.getKey(), entry.getValue().getDiscountPrice()))
+ .toList();
+ }
+} | Java | ์ด๋ฒคํธ๊ฐ ์ถ๊ฐ๋ ๋๋ง๋ค put์ ํด์ผํ๋ ๋ถํธํจ์ด ์์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,98 @@
+package christmas.service;
+
+import static christmas.constants.event.EventRule.MAX_MENU_AMOUNT;
+import static christmas.constants.menu.MenuType.DRINKS;
+import static christmas.exception.ErrorCode.INVALID_MENU_ORDER;
+
+import christmas.constants.menu.Menu;
+import christmas.constants.menu.MenuType;
+import christmas.dto.SingleMenu;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+public class MenuService {
+ private final Map<Menu, Integer> menuScript;
+
+ public MenuService() {
+ this.menuScript = new EnumMap<>(Menu.class);
+ }
+
+ public void order(List<SingleMenu> singleMenus) {
+ validate(singleMenus);
+ singleMenus.forEach(singleOrder -> {
+ Menu menu = Menu.from(singleOrder.menu());
+ menuScript.put(menu, singleOrder.amount());
+ });
+ }
+
+ public int getOrderPrice() {
+ return menuScript.keySet()
+ .stream()
+ .mapToInt(menu -> menu.getPrice() * menuScript.get(menu))
+ .sum();
+ }
+
+ private void validate(List<SingleMenu> singleMenus) {
+ validateDuplicate(singleMenus);
+ validatePerMenuAmount(singleMenus);
+ validateOnlyDrink(singleMenus);
+ validateTotalMenuAmount(singleMenus);
+ }
+
+ private void validateDuplicate(List<SingleMenu> singleMenus) {
+ int count = (int) getMenuStream(singleMenus)
+ .distinct()
+ .count();
+
+ if (count != singleMenus.size()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private void validateOnlyDrink(List<SingleMenu> singleMenus) {
+ int drinks = (int) getMenuStream(singleMenus)
+ .filter(menu -> menu.getMenuType() == DRINKS)
+ .count();
+
+ if (drinks > 0 && drinks == singleMenus.size()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private Stream<Menu> getMenuStream(List<SingleMenu> singleMenus) {
+ return singleMenus.stream()
+ .map(singleOrder -> Menu.from(singleOrder.menu()));
+ }
+
+ private void validatePerMenuAmount(List<SingleMenu> singleMenus) {
+ boolean present = singleMenus.stream()
+ .anyMatch(singleOrder -> singleOrder.amount() < 1);
+ if (present) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ private void validateTotalMenuAmount(List<SingleMenu> singleMenus) {
+ int totalAmount = singleMenus.stream()
+ .mapToInt(SingleMenu::amount)
+ .sum();
+ if (totalAmount >= MAX_MENU_AMOUNT.getValue()) {
+ throw new IllegalArgumentException(INVALID_MENU_ORDER.getMessage());
+ }
+ }
+
+ public int getAmountByMenu(MenuType menuType) {
+ return menuScript.keySet()
+ .stream()
+ .filter(target -> target.getMenuType() == menuType)
+ .mapToInt(menuScript::get)
+ .sum();
+ }
+
+ public Map<Menu, Integer> getMenuScript() {
+ return Collections.unmodifiableMap(menuScript);
+ }
+} | Java | stream์ int๋ก ์บ์คํ
ํ๋ ๊ฒ์ด ์ดํด๊ฐ ๋์ง ์์ต๋๋ค. |
@@ -0,0 +1,167 @@
+## ํ ์ค๋ก ํํํ๋ ํต์ฌ ๊ธฐ๋ฅ!
+
+> ๐๋ ์ง์ ์ฃผ๋ฌธ ๋ด์ญ์ ์กฐ๊ฑด์ ๋ง์ถฐ 12์ ํ ์ธ ์ด๋ฒคํธ๋ฅผ ์ ์ฉํ๊ธฐ
+
+---
+
+### ๊ธฐ๋ฅ ์๊ตฌ ์ฌํญ
+
+1๏ธโฃ 12์ ์ด๋ฒคํธ์ ๊ด๋ จ๋ ์ ๋ณด ์
๋ ฅ๋ฐ๊ธฐ
+
+-[x] ์ธ์ฟ๋ง ์ถ๋ ฅ
+-[x] ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ๋ฐ๊ธฐ
+ -[x] โ ๏ธ ์ ํจํ์ง ์์ ๊ฐ์ ๋ฐ์์ ๋ ์์ธ์ฒ๋ฆฌ
+ -[x] ์ซ์๋ฅผ ์
๋ ฅํ์ง ์์์ ๋
+ -[x] 1์ผ์์ 31์ผ ์ฌ์ด์ ์๊ฐ ์๋ ๋: *[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ์ ํจํ์ง ์์ ๊ฐ์ ์
๋ ฅ๋ฐ์์ ๊ฒฝ์ฐ, ์ ํจํ ๊ฐ์ ์
๋ ฅํ ๋๊น์ง ๋ค์ ์
๋ ฅ๋ฐ๊ธฐ
+-[x] ์ฃผ๋ฌธ ๋ฉ๋ด ์
๋ ฅ๋ฐ๊ธฐ
+ -[x] โ ๏ธ ์ ํจํ์ง ์์ ๊ฐ์ ๋ฐ์์ ๋ ์์ธ์ฒ๋ฆฌ
+ -[x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅํ๋ ๊ฒฝ์ฐ: *[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ๋ฉ๋ด์ ์ฃผ๋ฌธ ๊ฐ์๊ฐ 1 ์ด์์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ: *[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ์๋ฃ๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ: *[ERROR] ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ๋ฉ๋ด ํ์์ด ์์์ ๋ค๋ฅธ ๊ฒฝ์ฐ
+ -[x] `๋ฉ๋ด๋ช
-๊ฐ์`์ ํ์์ผ๋ก ์ด๋ฃจ์ด์ ธ ์์ง ์์ ๊ฒฝ์ฐ
+ -[x] `๋ฉ๋ด๋ช
-๊ฐ์`๊ฐ ,๋ฅผ ํตํด ๊ตฌ๋ถ๋์ง ์๋ ๊ฒฝ์ฐ
+ -[x] ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ: *[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ์ด ๊ฐ์๊ฐ 20๊ฐ๋ฅผ ์ด๊ณผํ ๊ฒฝ์ฐ: *[ERROR] ๋ฉ๋ด๋ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ์ ํจํ์ง ์์ ๊ฐ์ ์
๋ ฅ๋ฐ์์ ๊ฒฝ์ฐ, ์ ํจํ ๊ฐ์ ์
๋ ฅํ ๋๊น์ง ๋ค์ ์
๋ ฅ๋ฐ๊ธฐ
+
+2๏ธโฃ ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅํ๊ธฐ
+
+-[x] ์
๋ ฅ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ
+ -[x] ์ฃผ๋ฌธ ๋ฉ๋ด์ ์ถ๋ ฅ ์์๋ ์์ ๋กญ๊ฒ : ๐ฅ์ํผํ์ด์ - ๋ฉ์ธ - ๋์ ํธ - ์๋ฃ ์์๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ๋ค
+ -[x] ํฌ๋ฉง: ๋ฉ๋ด "{๋ฉ๋ด ์ด๋ฆ} {x๊ฐ}" ex) ์ ๋ก์ฝ๋ผ 1๊ฐ
+
+3๏ธโฃ ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก: MenuService
+
+-[x] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+ -[x] `๋ฉ๋ด์ ๊ฐ๊ฒฉ * ์๋`์ ์ด ํฉ๊ณ
+
+4๏ธโฃ ์ฆ์ ๋ฉ๋ดโจ
+
+-[x] ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ํ์ธํ๊ณ , ๊ธ์ก์ ๋ฐ๋ผ ์ฆ์ ์ฌ๋ถ ๊ฒฐ์
+ -[x] ์ ๋ฌ๋ฐ์ ๋ ์ง๋ฅผ ํตํด ์ฆ์ ์ฌ๋ถ ๊ฒฐ์
+ -[x] `์ด์ฃผ๋ฌธ ๊ธ์ก`์ด `120,000์` ์ด์์ธ ๊ฒฝ์ฐ, ์ฆ์ ๊ฐ์ 1๋ก ์ค์
+ -[x] `์ด์ฃผ๋ฌธ ๊ธ์ก`์ด `120,000์` ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ, ์ฆ์ ๊ฐ์ 0์ผ๋ก ์ค์
+ -[x] ์กฐ๊ฑด์ ๋ฐ๋ผ ์ฆ์ ๊ฒฐ๊ณผ ์ถ๋ ฅ
+ -[x] `์ด์ฃผ๋ฌธ ๊ธ์ก`์ด `120,000์` ์ด์์ธ ๊ฒฝ์ฐ, "์ดํ์ธ n๊ฐ" ์ถ๋ ฅ
+ -[x] `์ด์ฃผ๋ฌธ ๊ธ์ก`์ด `120,000์` ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ, "์์" ์ถ๋ ฅ
+
+5๏ธโฃ ํํ ๋ด์ญโจ : DiscountService -> EventService
+
+-[x] ํํ์ ๋ฐ์ ์ ์๋ ์กฐ๊ฑด์ธ์ง ํ์ธ
+ -[x] `์ด์ฃผ๋ฌธ๊ธ์ก`์ด 10,000์ ์ด์์ธ์ง ํ์ธ
+-[x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ -[x] 1์ผ๋ถํฐ 25์ผ ์ฌ์ด์ ๋ ์ง์๋ง ์ด๋ฒคํธ ์ ์ฉ
+ -[x] 1์ผ์ 1000์๋ถํฐ ์์ํ์ฌ, ํ๋ฃจ๊ฐ ์ง๋ ์๋ก 100์์ฉ ์ถ๊ฐ ํ ์ธ
+ -[x] "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -1,200์" ํํ๋ก ์ถ๋ ฅ
+-[x] ํ์ผ ํ ์ธ
+ -[x] ์ผ์์ผ~๋ชฉ์์ผ ์งํ
+ -[x] `๋์ ํธ`๋ฉ๋ด๋ฅผ `1๊ฐ๋น 2023์` ํ ์ธ
+ -[x] "ํ์ผ ํ ์ธ: -4,046์" ํํ๋ก ์ถ๋ ฅ. ๋จ ํ ์ธ์ด ์๋๋ ๊ฒฝ์ฐ, ์ถ๋ ฅ์ ๋ณ๋๋ก ํ์ง ์์
+-[x] ์ฃผ๋ง ํ ์ธ
+ -[x] ๊ธ์์ผ~ํ ์์ผ ์งํ
+ -[x] `๋ฉ์ธ`๋ฉ๋ด๋ฅผ `1๊ฐ๋น 2,023์` ํ ์ธ
+ -[x] "์ฃผ๋ง ํ ์ธ: -1,000์" ํํ๋ก ์ถ๋ ฅ. ๋จ ํ ์ธ์ด ์๋๋ ๊ฒฝ์ฐ, ์ถ๋ ฅ์ ๋ณ๋๋ก ํ์ง ์์
+-[x] ํน๋ณ ํ ์ธ
+ -[x] ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์๋ ๊ฒฝ์ฐ(๋งค์ฃผ ์ผ์์ผ + 25์ผ)
+ -[x] `์ด ๊ธ์ก`์์ `1000์` ํ ์ธ
+ -[x] "ํน๋ณ ํ ์ธ: -1,000์" ํํ๋ก ์ถ๋ ฅ. ๋จ ํ ์ธ์ด ์๋๋ ๊ฒฝ์ฐ, ์ถ๋ ฅ์ ๋ณ๋๋ก ํ์ง ์์
+-[x] ํํ ๋ด์ญ์ ๋ํด ์ถ๋ ฅ
+ -[x] ํฌ๋งท์ {์ข
๋ฅ} ํ ์ธ: -{ํ ์ธ ๊ฐ๊ฒฉ}์. ์ด ๋, ๊ฐ๊ฒฉ์ 1000์ ๋จ์๋ก ์ผํ(,)๋ฅผ ๋ฃ๋๋ค
+ -[x] ๋ง์ผ, ๋ชจ๋ ํํ์ ๋ฐ์ง ๋ชปํ ๊ฒฝ์ฐ์๋ "์์"์ผ๋ก ํ์ํ๋ค
+
+6๏ธโฃ ์ดํํ ๊ธ์ก : DiscountService -> EventService
+
+-[x] ์ดํํ ๊ธ์ก์ ๋ํด ๊ณ์ฐ ๋ฐ ์ถ๋ ฅ
+ -[x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด, ํ์ผ, ํน๋ณ, ์ฆ์ ์ด๋ฒคํธ ํ ์ธ์ ๋ชจ๋ ํฉํ ๊ฐ๊ฒฉ์ ํ์ํ๋ค (์ด ํ ์ธ ๊ธ์ก + ์ฆ์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ)
+ -[x] ์์ -๊ฐ ๋ถ์ผ๋ฉฐ, 1000์ ๋จ์๋ง๋ค ์ผํ(,)๋ฅผ ์ถ๊ฐํ๋ค
+
+7๏ธโฃ ํ ์ธ ํ, ์์ ๊ฒฐ์ ๊ธ์ก
+
+-[x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์ ๋ํด ๊ณ์ฐ ๋ฐ ์ถ๋ ฅ
+ -[x] `ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก` - `์ดํํ ๊ธ์ก`์ ๊ณ์ฐํ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ค
+ -[x] 1000์ ๋จ์๋ง๋ค ์ผํ(,)๋ฅผ ์ถ๊ฐํ๋ค
+
+8๏ธโฃ 12์ ์ด๋ฒคํธ ๋ฐฐ์ง
+
+-[x] ์ด๋ฒคํธ ๋ฐฐ์ง: `์ด ํํ ๊ธ์ก`์ ๋ฐ๋ผ ๋ฐฐ์ง ๋ถ์ฌ ๋ฐ ์ถ๋ ฅ
+ -[x] ์ด๋ฒคํธ ๋ฐฐ์ง์ ๋ํด ๊ณ์ฐ
+ -[x] 5000 <= x < 10,000 : ๋ณ
+ -[x] 10,000 <= x < 20,000 : ํธ๋ฆฌ
+ -[x] 20,000 <= x : ์ฐํ
+
+---
+
+### ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ ์ฌํญ
+
+-[x] ApplicationTest์ ๋ชจ๋ ํ
์คํธ๊ฐ ์ฑ๊ณตํด์ผ ํ๋ค.
+-[x] indent depth๋ 2๊น์ง ํ์ฉํ๋ค.
+-[x] ๋ฉ์๋์ ๊ธธ์ด๊ฐ 15๋ฅผ ๋์ด๊ฐ์ง ์๋๋ก ํ๋ค.
+-[x] ์ฌ์ฉ์๊ฐ ์๋ชป๋ ๊ฐ์ ์
๋ ฅํ ๊ฒฝ์ฐ, `IllegalArgumentException`์ ๋ฐ์์ํค๊ณ , `[ERROR]`๋ก ์์ํ๋ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ ํ, ๊ทธ ๋ถ๋ถ๋ถํฐ ์
๋ ฅ์ ๋ค์ ๋ฐ๋๋ค.
+-[x] ์
๋ ฅ๊ณผ ์ถ๋ ฅ์ ๋ด๋นํ๋ ํด๋์ค๋ฅผ ๋ณ๋๋ก ๊ตฌํํ๋ค.
+ -[x] InputView: readDate()...
+ -[x] OutputView : printMenu()...
+-[x] Console.readLine()์ ํ์ฉํ๋ค.
+
+---
+
+### 3์ฃผ์ฐจ ํผ๋๋ฐฑ ๋ด์ฉ
+
+-[x] 3์ฃผ์ฐจ ๊ณตํตํผ๋๋ฐฑ ์งํค๊ธฐ!
+-[x] `Integer.parseInt()`๋ฅผ ์ฌ์ฉํ๋ฉด ์ ์์ ๋ฒ์๊ฐ ์๋ ๋์๋ ์์ธ๊ฐ ๋ฐ์ํ๋๋ฐ, ์์ธ ๋ฉ์์ง๋ฅด ์กฐ๊ธ ๋ ๊ผผ๊ผผํ๊ฒ ์ฑ๊ธฐ์
+-[x] Enum์์ ๋ฌธ์์ด์ ํฉ์น ๋ `+`๋ณด๋ค๋, `String.format()`์ ์ฌ์ฉํ์
+-[x] `System.lineSeperator()`์ `String.format("%n")`์ ๊ฐ์ ์ญํ ์ ํ๋ค. ํ์ฉํด๋ณด์!
+-[x] ์๊ตฌ์ฌํญ์ ๊ผผ๊ผผํ๊ฒ ์ฝ์. (์ธ์๋ฆฌ๋ง๋ค ์ผํ๋ฅผ ๋ฃ์ด์ค๋ค๋์ง...)
+-[x] ์์๋ฅผ enum์ผ๋ก ๋บ์ผ๋ฉด ์ด๋ฅผ ํ์ฉํ์! ๋งค์ง ๋๋ฒ์ ์ฌ์ฉ์ ์ค์ด์! ํ์ฅ์ฑ์ ๊ณ ๋ คํ ๊ตฌ์กฐ๋ฅผ ๋ง๋ค์!
+-[x] ์์ธ๋ฅผ ๋ค์ ๋ฐ๋ ๋ฐฉ๋ฒ์ผ๋ก ์ฌ๊ท๋ฅผ ์ฌ์ฉํ๋๋ฐ, ๋ฉ๋ชจ๋ฆฌ๊ฐ ํฐ์ง ๊ฐ๋ฅ์ฑ์ด ์๋ค. `Supplier`๋ฅผ ๋์
ํด๋ณด์.
+-[x] ๊ฒ์ฆ(Validate)๊ณผ ํ์ฑ(Parsing)์ ๋ก์ง์ ์ด๋์ ๋๋ฉด ์ข์๊น? ๊ณ ๋ฏผํด๋ณด์.
+-[x] ๋๋ฏธํฐ์ ๋ฒ์น!
+-[x] `Console.close()`๋ฅผ ํตํด ์ฌ์ฉ ์๋ฃํ ์ฝ์์ ๋ซ์์ฃผ์
+
+---
+
+### ๊ฐ๋ฐ ์ค ์์ฑํ๋ ๋ฆฌํฉํ ๋ง ๋ชฉ๋ก
+
+-[x] IoC ์ปจํ
์ด๋ ์ ์ฉํ๊ธฐ
+-[x] Enum์ด ๋๋ฌด ์ฐํ์ฃฝ์ ์๊ธด ๊ฒ ๊ฐ๋ค! ์ ๋ฆฌํ ์ ์๋ ๋ถ๋ถ์ ์ ๋ฆฌํด๋ณด์
+-[x] InputView, OutputView์์ `readLine()`๊ณผ `System.out.print` ๋ถ๋ถ ์ถ์ํํ๊ธฐ
+-[x] `Supplier`๋ฅผ ์ด์ฉํ์ฌ ์ฌ์
๋ ฅ ์ฒ๋ฆฌํ๊ธฐ
+-[x] Validator(๊ฒ์ฆ)์ ์ญํ ์ด ์ ์ ํ๊ฒ ๋ถ๋ฐฐ๋์ด ์๋์ง ํ์ธ
+ -[x] MenuService์ validate ํจ์๋ค์ ๋ํด ์ค๋ณต๋์ด์๋ ์ฝ๋ ์ฒ๋ฆฌํ๊ธฐ
+-[x] MenuService์ ์ฝ๋๊ฐ ์กฐ๊ธ ๋์กํ ๊ฒ ๊ฐ์
+-[x] Message์ %n์ ๋ํด ์ด๋ป๊ฒ...์ฒ๋ฆฌ ์ข ํ๊ธฐ
+-[ ] Parser์์ parseToDate, parseToAmount์ ์ฝ๋๊ฐ ๊ฒน์น๋ค. ์ ๋ฌํ๋ ์์ธ ๋ฉ์ธ์ง๋ง ๋ค๋ฅธ๋ฐ... ๋ฐฉ๋ฒ์ ์ฐพ์๋ณด์.
+-[x] DiscountResult์ ๋๋ฌด ๋ง์ ์ฑ
์์ด ์๋ ๊ฒ ๊ฐ๋ค! DiscountService์๊ฒ ์ฑ
์์ ๋ ๋ถ์ฌํ์.
+ -> DiscountResult -> EventResult -> EventService๋ก ๋ณ๊ฒฝ ๋ฐ ์ญํ ๋ถ์ฌ
+-[x] ๋ฉ์๋, ๋ณ์๋ช
์ด ์ ์ ํ์ง ํ์ธ ํ ์์
+-[x] ๋ฉ๋ด๋ฅผ ์๋ชป์
๋ ฅํ์ ๋ `IndexOutOfBounds`๊ฐ ๋ฐ์ํ๋ฉด์ ์ข
๋ฃ๋๋ค.
+-[x] OutputView์์ formatting์ ํ๋ฉด์ ๊ฒน์น๋ ์ฝ๋๊ฐ ๊ณณ๊ณณ์ ์๋ค. ์์ ํ์!
+
+---
+
+### ๊ตฌํํ๋ฉด์ ์ง์คํ๋ ๋ถ๋ถ๋ค! ๊ณ ๋ฏผ๊ฑฐ๋ฆฌ!
+
+#### โ
Discountable(Eventable๋ก ๋ณ๊ฒฝ) ์ธํฐํ์ด์ค์ ์ ๋๋ฆญ์ ์ ์ฉํ์
+
+> ๐ง ๊ณ ๋ฏผ ๋ด์ฉ ๐ง
+> ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด, ์ฆ์ ์ด๋ฒคํธ, ํ์ผ ํ ์ธ, ์ฃผ๋ง ํ ์ธ, ํน๋ณ ํ ์ธ ๋ชจ๋ ๊ฐ์๋ง์ ๊ณ ์ ํ ํ ์ธ ์กฐ๊ฑด๋ค์ด ์๋ค.
+> ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด์ ์ฆ์ ์ด๋ฒคํธ๋ `์ด ์ฃผ๋ฌธ ๊ธ์ก`๊ณผ `๋ ์ง`๋ฅผ ํ์ธํ๋ฉด ๋๋๋ฐ, ์ด๋ค์ ๋ชจ๋ intํ์ผ๋ก ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํ๋ค.
+>
+> ํ์ง๋ง ํ์ผ, ์ฃผ๋ง ํ ์ธ์ `๋ ์ง`๋ง ๋ฐ๋ ๊ฒ์ด ์๋๋ผ, ๋ฉ๋ด์ ๋ํ ์ต์ํ์ ์ ๋ณด๊ฐ ์ถ๊ฐ์ ์ผ๋ก ํ์ํ๋ค.
+> ๋ชจ๋ ํ ์ธ ํด๋์ค๋ค์ด ๊ณตํต์ผ๋ก ๊ฐ์ง๊ณ ์์ด์ผ ํ๋ ๊ฒ๋ค์ `Discountable ์ธํฐํ์ด์ค(Eventable ์ธํฐํ์ด์ค๋ก ๋ณ๊ฒฝ)`๋ก ํํํ๊ณ ์ถ์๋ฐ ์ด๋ป๊ฒ ํ๋ฉด ์ข์๊น?
+
+์ด์ ๋ํด ์๊ฐ๋ ํด๋ต์ ๋ฐ๋ก `์ ๋๋ฆญ`์ ์ฌ์ฉํ๋ ๊ฒ์ด์๋ค.
+`์ ๋๋ฆญ`์ ์ฌ์ฉํ๋ฉด `canDiscount`์ ๋งค๊ฐ๋ณ์์ ์๋ฃํ์ ์๊ด์์ด ์ ๋ฌํ๊ณ ์ถ์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
+๋ฐ๋ผ์ `Discountable` ์ธํฐํ์ด์ค์ `canDiscount()`์ ๋งค๊ฐ๋ณ์๋ก ์ ๋ฌ๋๋ ์กฐ๊ฑด(`condition`) `์ ๋๋ฆญ <T>`๋ฅผ ์ ์ฉํ๋ค.
+
+<br>
+
+#### โ
View์์ ์ ์ ํ ๋ณํํด์ ์ ๋ฌํ์. ๊ผญ String์ผ๋ก ์ ๋ฌํ ํ์๊ฐ ์๋ค.
+
+<br>
+
+#### โ
๋ค๋ฅธ ๊ณ์ธต๊ณผ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์ ๋์๋ DTO๋ฅผ ์ด์ฉํ์.
+
+
+ | Unknown | ์ ๋ค๋ฆญ์ ์ฌ์ฉํด Discountable๋ก ํํํ ๊ฒ์ด ๋งค์ฐ ์ธ์๊น๋ค์! ์ฝ๋ ๋ฆฌ๋ทฐํ ๋๋ ๋ณด๋ฉด์ ๊ณต๋ถํ๋๋ก ํ๊ฒ ์ต๋๋ค ๐ซก |
@@ -0,0 +1,97 @@
+package christmas.config;
+
+import christmas.controller.EventController;
+import christmas.exception.RetryHandler;
+import christmas.service.EventService;
+import christmas.service.MenuService;
+import christmas.validator.InputValidator;
+import christmas.view.input.ConsoleReader;
+import christmas.view.input.InputView;
+import christmas.view.input.Reader;
+import christmas.view.output.ConsoleWriter;
+import christmas.view.output.OutputView;
+import christmas.view.output.Writer;
+
+public class AppConfig {
+ private static AppConfig appConfig;
+ private EventController eventController;
+ private EventService eventService;
+ private MenuService menuService;
+ private InputValidator inputValidator;
+ private RetryHandler retryHandler;
+ private InputView inputView;
+ private OutputView outputView;
+ private Reader reader;
+ private Writer writer;
+
+ public static AppConfig getInstance() {
+ if (appConfig == null) {
+ appConfig = new AppConfig();
+ }
+ return appConfig;
+ }
+
+ public EventController eventController() {
+ if (eventController == null) {
+ eventController = new EventController(discountService(), menuService(),
+ inputView(), outputView(), exceptionHandler());
+ }
+ return eventController;
+ }
+
+ public EventService discountService() {
+ if (eventService == null) {
+ eventService = new EventService();
+ }
+ return eventService;
+ }
+
+ public MenuService menuService() {
+ if (menuService == null) {
+ menuService = new MenuService();
+ }
+ return menuService;
+ }
+
+ public RetryHandler exceptionHandler() {
+ if (retryHandler == null) {
+ retryHandler = new RetryHandler(outputView());
+ }
+ return retryHandler;
+ }
+
+ public InputView inputView() {
+ if (inputView == null) {
+ inputView = new InputView(reader(), inputValidator());
+ }
+ return inputView;
+ }
+
+ public InputValidator inputValidator() {
+ if (inputValidator == null) {
+ inputValidator = new InputValidator();
+ }
+ return inputValidator;
+ }
+
+ public Reader reader() {
+ if (reader == null) {
+ reader = new ConsoleReader();
+ }
+ return reader;
+ }
+
+ public OutputView outputView() {
+ if (outputView == null) {
+ outputView = new OutputView(writer());
+ }
+ return outputView;
+ }
+
+ public Writer writer() {
+ if (writer == null) {
+ writer = new ConsoleWriter();
+ }
+ return writer;
+ }
+} | Java | outview์ ๊ฒฝ์ฐ static๋ฉ์๋๋ฅผ ํ์ฉํด ๊ฐ์ฒด๋ฅผ ์์ฑํ์ง ์๋ ๋ฐฉ๋ฒ๋ ์๋๋ฐ, ๊ทธ๋ผ์๋ ์ฑ๊ธํค ํจํด์ ์ ์งํ์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,94 @@
+package christmas.controller;
+
+import static christmas.constants.event.EventType.PRESENT;
+import static christmas.constants.menu.MenuType.DESSERT;
+import static christmas.constants.menu.MenuType.MAIN;
+
+import christmas.constants.event.BadgeType;
+import christmas.dto.SingleMenu;
+import christmas.dto.UserOrder;
+import christmas.exception.RetryHandler;
+import christmas.service.EventService;
+import christmas.service.MenuService;
+import christmas.view.input.InputView;
+import christmas.view.output.OutputView;
+import java.util.List;
+
+public class EventController {
+ private final EventService eventService;
+ private final MenuService menuService;
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RetryHandler retryHandler;
+
+ public EventController(EventService eventService, MenuService menuService, InputView inputView,
+ OutputView outputView, RetryHandler retryHandler) {
+ this.eventService = eventService;
+ this.menuService = menuService;
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.retryHandler = retryHandler;
+ }
+
+ public void run() {
+ int visitDate = getVisitDate();
+ UserOrder userOrder = receiveOrder(visitDate);
+ printOrderInformation();
+
+ applyEvent(userOrder);
+ printEventDetails(userOrder);
+
+ printBadge();
+ inputView.close();
+ }
+
+ private int getVisitDate() {
+ outputView.printGreeting();
+ outputView.printAskVisitDate();
+
+ return retryHandler.execute(inputView::askVisitDate, IllegalArgumentException.class);
+ }
+
+ private UserOrder receiveOrder(int visitDate) {
+ outputView.printAskMenu();
+ UserOrder userOrder = retryHandler.execute(() -> getUserOrder(visitDate), IllegalArgumentException.class);
+ outputView.printPreview(visitDate);
+
+ return userOrder;
+ }
+
+ private UserOrder getUserOrder(int visitDate) {
+ List<SingleMenu> singleMenus = inputView.askOrderMenu();
+ menuService.order(singleMenus);
+ return new UserOrder(
+ menuService.getOrderPrice(),
+ visitDate,
+ menuService.getAmountByMenu(MAIN),
+ menuService.getAmountByMenu(DESSERT)
+ );
+ }
+
+ private void printOrderInformation() {
+ outputView.printOrderMenu(menuService.getMenuScript());
+ outputView.printBeforeDiscountPrice(menuService.getOrderPrice());
+ }
+
+ private void applyEvent(UserOrder userOrder) {
+ eventService.applyEvent(userOrder);
+ }
+
+ private void printEventDetails(UserOrder userOrder) {
+ int discountPrice = eventService.getDiscountPriceByEvent(PRESENT);
+ int expectedPrice = eventService.getExpectedPrice(userOrder);
+
+ outputView.printPresent(discountPrice);
+ outputView.printEventDetails(eventService.convertToEventDetails());
+ outputView.printTotalBenefitPrice(eventService.getTotalBenefitPrice());
+ outputView.printExpectedPrice(expectedPrice);
+ }
+
+ private void printBadge() {
+ int totalDiscountPrice = eventService.getTotalBenefitPrice();
+ outputView.printEventBadge(BadgeType.from(totalDiscountPrice));
+ }
+} | Java | print๋ผ๋ ๋ค์ด๋ฐ์ ์ปจํธ๋กค๋ฌ๊ฐ ์ถ๋ ฅ์ ๋ด๋นํ๋ค ๋ผ๋ ๋ป์ผ๋ก ๋ณด์
๋๋ค! ๋ค๋ฅธ ๋ง๋ก ๋์ฒด ํ๋๊ฑด ์ด๋ป๊ฒ ์๊ฐํ์ธ์? |
@@ -0,0 +1,25 @@
+package christmas.constants.event;
+
+public enum EventRule {
+ EVENT_THRESHOLD(10_000),
+ PRESENT_THRESHOLD(120_000),
+ EVENT_START(1),
+ EVENT_END(31),
+ MAX_MENU_AMOUNT(20),
+ CHRISTMAS_EVENT_END(25),
+ CHRISTMAS_INIT_PRICE(1_000),
+ CHRISTMAS_EXTRA_DISCOUNT(100),
+ MENU_DISCOUNT(2_023),
+ SPECIAL_DISCOUNT(1_000);
+
+
+ private final int value;
+
+ EventRule(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+} | Java | ๊ฐ์ธ์ ์ผ๋ก enum์ ์ฐ๊ด๋ ์์๋ฅผ ๋ชจ์๋๋ ๊ณณ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค!
CHRISTMAS_EXTRA_DISCOUNT(100),
MENU_DISCOUNT(2_023),
๋ฑ์ ์๋ก ๋ค๋ฅธ ๊ฐ์ฒด๋จ์๋ก ๋ถ๋ฆฌ๊ฐ ๊ฐ๋ฅํด๋ณด์ฌ์!
์ฐจ๋ผ๋ฆฌ ๊ฐ์ฒด ๋ด๋ถ์ ์์ ํ๋๋ก ๊ด๋ฆฌํ๋ ๊ฒ์ ์ด๋ ์ธ์? |
@@ -0,0 +1,167 @@
+## ํ ์ค๋ก ํํํ๋ ํต์ฌ ๊ธฐ๋ฅ!
+
+> ๐๋ ์ง์ ์ฃผ๋ฌธ ๋ด์ญ์ ์กฐ๊ฑด์ ๋ง์ถฐ 12์ ํ ์ธ ์ด๋ฒคํธ๋ฅผ ์ ์ฉํ๊ธฐ
+
+---
+
+### ๊ธฐ๋ฅ ์๊ตฌ ์ฌํญ
+
+1๏ธโฃ 12์ ์ด๋ฒคํธ์ ๊ด๋ จ๋ ์ ๋ณด ์
๋ ฅ๋ฐ๊ธฐ
+
+-[x] ์ธ์ฟ๋ง ์ถ๋ ฅ
+-[x] ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ๋ฐ๊ธฐ
+ -[x] โ ๏ธ ์ ํจํ์ง ์์ ๊ฐ์ ๋ฐ์์ ๋ ์์ธ์ฒ๋ฆฌ
+ -[x] ์ซ์๋ฅผ ์
๋ ฅํ์ง ์์์ ๋
+ -[x] 1์ผ์์ 31์ผ ์ฌ์ด์ ์๊ฐ ์๋ ๋: *[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ์ ํจํ์ง ์์ ๊ฐ์ ์
๋ ฅ๋ฐ์์ ๊ฒฝ์ฐ, ์ ํจํ ๊ฐ์ ์
๋ ฅํ ๋๊น์ง ๋ค์ ์
๋ ฅ๋ฐ๊ธฐ
+-[x] ์ฃผ๋ฌธ ๋ฉ๋ด ์
๋ ฅ๋ฐ๊ธฐ
+ -[x] โ ๏ธ ์ ํจํ์ง ์์ ๊ฐ์ ๋ฐ์์ ๋ ์์ธ์ฒ๋ฆฌ
+ -[x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅํ๋ ๊ฒฝ์ฐ: *[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ๋ฉ๋ด์ ์ฃผ๋ฌธ ๊ฐ์๊ฐ 1 ์ด์์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ: *[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ์๋ฃ๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ: *[ERROR] ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ๋ฉ๋ด ํ์์ด ์์์ ๋ค๋ฅธ ๊ฒฝ์ฐ
+ -[x] `๋ฉ๋ด๋ช
-๊ฐ์`์ ํ์์ผ๋ก ์ด๋ฃจ์ด์ ธ ์์ง ์์ ๊ฒฝ์ฐ
+ -[x] `๋ฉ๋ด๋ช
-๊ฐ์`๊ฐ ,๋ฅผ ํตํด ๊ตฌ๋ถ๋์ง ์๋ ๊ฒฝ์ฐ
+ -[x] ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ: *[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ์ด ๊ฐ์๊ฐ 20๊ฐ๋ฅผ ์ด๊ณผํ ๊ฒฝ์ฐ: *[ERROR] ๋ฉ๋ด๋ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.*
+ -[x] ์ ํจํ์ง ์์ ๊ฐ์ ์
๋ ฅ๋ฐ์์ ๊ฒฝ์ฐ, ์ ํจํ ๊ฐ์ ์
๋ ฅํ ๋๊น์ง ๋ค์ ์
๋ ฅ๋ฐ๊ธฐ
+
+2๏ธโฃ ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅํ๊ธฐ
+
+-[x] ์
๋ ฅ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ
+ -[x] ์ฃผ๋ฌธ ๋ฉ๋ด์ ์ถ๋ ฅ ์์๋ ์์ ๋กญ๊ฒ : ๐ฅ์ํผํ์ด์ - ๋ฉ์ธ - ๋์ ํธ - ์๋ฃ ์์๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ๋ค
+ -[x] ํฌ๋ฉง: ๋ฉ๋ด "{๋ฉ๋ด ์ด๋ฆ} {x๊ฐ}" ex) ์ ๋ก์ฝ๋ผ 1๊ฐ
+
+3๏ธโฃ ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก: MenuService
+
+-[x] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+ -[x] `๋ฉ๋ด์ ๊ฐ๊ฒฉ * ์๋`์ ์ด ํฉ๊ณ
+
+4๏ธโฃ ์ฆ์ ๋ฉ๋ดโจ
+
+-[x] ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ํ์ธํ๊ณ , ๊ธ์ก์ ๋ฐ๋ผ ์ฆ์ ์ฌ๋ถ ๊ฒฐ์
+ -[x] ์ ๋ฌ๋ฐ์ ๋ ์ง๋ฅผ ํตํด ์ฆ์ ์ฌ๋ถ ๊ฒฐ์
+ -[x] `์ด์ฃผ๋ฌธ ๊ธ์ก`์ด `120,000์` ์ด์์ธ ๊ฒฝ์ฐ, ์ฆ์ ๊ฐ์ 1๋ก ์ค์
+ -[x] `์ด์ฃผ๋ฌธ ๊ธ์ก`์ด `120,000์` ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ, ์ฆ์ ๊ฐ์ 0์ผ๋ก ์ค์
+ -[x] ์กฐ๊ฑด์ ๋ฐ๋ผ ์ฆ์ ๊ฒฐ๊ณผ ์ถ๋ ฅ
+ -[x] `์ด์ฃผ๋ฌธ ๊ธ์ก`์ด `120,000์` ์ด์์ธ ๊ฒฝ์ฐ, "์ดํ์ธ n๊ฐ" ์ถ๋ ฅ
+ -[x] `์ด์ฃผ๋ฌธ ๊ธ์ก`์ด `120,000์` ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ, "์์" ์ถ๋ ฅ
+
+5๏ธโฃ ํํ ๋ด์ญโจ : DiscountService -> EventService
+
+-[x] ํํ์ ๋ฐ์ ์ ์๋ ์กฐ๊ฑด์ธ์ง ํ์ธ
+ -[x] `์ด์ฃผ๋ฌธ๊ธ์ก`์ด 10,000์ ์ด์์ธ์ง ํ์ธ
+-[x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ -[x] 1์ผ๋ถํฐ 25์ผ ์ฌ์ด์ ๋ ์ง์๋ง ์ด๋ฒคํธ ์ ์ฉ
+ -[x] 1์ผ์ 1000์๋ถํฐ ์์ํ์ฌ, ํ๋ฃจ๊ฐ ์ง๋ ์๋ก 100์์ฉ ์ถ๊ฐ ํ ์ธ
+ -[x] "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -1,200์" ํํ๋ก ์ถ๋ ฅ
+-[x] ํ์ผ ํ ์ธ
+ -[x] ์ผ์์ผ~๋ชฉ์์ผ ์งํ
+ -[x] `๋์ ํธ`๋ฉ๋ด๋ฅผ `1๊ฐ๋น 2023์` ํ ์ธ
+ -[x] "ํ์ผ ํ ์ธ: -4,046์" ํํ๋ก ์ถ๋ ฅ. ๋จ ํ ์ธ์ด ์๋๋ ๊ฒฝ์ฐ, ์ถ๋ ฅ์ ๋ณ๋๋ก ํ์ง ์์
+-[x] ์ฃผ๋ง ํ ์ธ
+ -[x] ๊ธ์์ผ~ํ ์์ผ ์งํ
+ -[x] `๋ฉ์ธ`๋ฉ๋ด๋ฅผ `1๊ฐ๋น 2,023์` ํ ์ธ
+ -[x] "์ฃผ๋ง ํ ์ธ: -1,000์" ํํ๋ก ์ถ๋ ฅ. ๋จ ํ ์ธ์ด ์๋๋ ๊ฒฝ์ฐ, ์ถ๋ ฅ์ ๋ณ๋๋ก ํ์ง ์์
+-[x] ํน๋ณ ํ ์ธ
+ -[x] ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์๋ ๊ฒฝ์ฐ(๋งค์ฃผ ์ผ์์ผ + 25์ผ)
+ -[x] `์ด ๊ธ์ก`์์ `1000์` ํ ์ธ
+ -[x] "ํน๋ณ ํ ์ธ: -1,000์" ํํ๋ก ์ถ๋ ฅ. ๋จ ํ ์ธ์ด ์๋๋ ๊ฒฝ์ฐ, ์ถ๋ ฅ์ ๋ณ๋๋ก ํ์ง ์์
+-[x] ํํ ๋ด์ญ์ ๋ํด ์ถ๋ ฅ
+ -[x] ํฌ๋งท์ {์ข
๋ฅ} ํ ์ธ: -{ํ ์ธ ๊ฐ๊ฒฉ}์. ์ด ๋, ๊ฐ๊ฒฉ์ 1000์ ๋จ์๋ก ์ผํ(,)๋ฅผ ๋ฃ๋๋ค
+ -[x] ๋ง์ผ, ๋ชจ๋ ํํ์ ๋ฐ์ง ๋ชปํ ๊ฒฝ์ฐ์๋ "์์"์ผ๋ก ํ์ํ๋ค
+
+6๏ธโฃ ์ดํํ ๊ธ์ก : DiscountService -> EventService
+
+-[x] ์ดํํ ๊ธ์ก์ ๋ํด ๊ณ์ฐ ๋ฐ ์ถ๋ ฅ
+ -[x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด, ํ์ผ, ํน๋ณ, ์ฆ์ ์ด๋ฒคํธ ํ ์ธ์ ๋ชจ๋ ํฉํ ๊ฐ๊ฒฉ์ ํ์ํ๋ค (์ด ํ ์ธ ๊ธ์ก + ์ฆ์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ)
+ -[x] ์์ -๊ฐ ๋ถ์ผ๋ฉฐ, 1000์ ๋จ์๋ง๋ค ์ผํ(,)๋ฅผ ์ถ๊ฐํ๋ค
+
+7๏ธโฃ ํ ์ธ ํ, ์์ ๊ฒฐ์ ๊ธ์ก
+
+-[x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์ ๋ํด ๊ณ์ฐ ๋ฐ ์ถ๋ ฅ
+ -[x] `ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก` - `์ดํํ ๊ธ์ก`์ ๊ณ์ฐํ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ค
+ -[x] 1000์ ๋จ์๋ง๋ค ์ผํ(,)๋ฅผ ์ถ๊ฐํ๋ค
+
+8๏ธโฃ 12์ ์ด๋ฒคํธ ๋ฐฐ์ง
+
+-[x] ์ด๋ฒคํธ ๋ฐฐ์ง: `์ด ํํ ๊ธ์ก`์ ๋ฐ๋ผ ๋ฐฐ์ง ๋ถ์ฌ ๋ฐ ์ถ๋ ฅ
+ -[x] ์ด๋ฒคํธ ๋ฐฐ์ง์ ๋ํด ๊ณ์ฐ
+ -[x] 5000 <= x < 10,000 : ๋ณ
+ -[x] 10,000 <= x < 20,000 : ํธ๋ฆฌ
+ -[x] 20,000 <= x : ์ฐํ
+
+---
+
+### ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ ์ฌํญ
+
+-[x] ApplicationTest์ ๋ชจ๋ ํ
์คํธ๊ฐ ์ฑ๊ณตํด์ผ ํ๋ค.
+-[x] indent depth๋ 2๊น์ง ํ์ฉํ๋ค.
+-[x] ๋ฉ์๋์ ๊ธธ์ด๊ฐ 15๋ฅผ ๋์ด๊ฐ์ง ์๋๋ก ํ๋ค.
+-[x] ์ฌ์ฉ์๊ฐ ์๋ชป๋ ๊ฐ์ ์
๋ ฅํ ๊ฒฝ์ฐ, `IllegalArgumentException`์ ๋ฐ์์ํค๊ณ , `[ERROR]`๋ก ์์ํ๋ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ ํ, ๊ทธ ๋ถ๋ถ๋ถํฐ ์
๋ ฅ์ ๋ค์ ๋ฐ๋๋ค.
+-[x] ์
๋ ฅ๊ณผ ์ถ๋ ฅ์ ๋ด๋นํ๋ ํด๋์ค๋ฅผ ๋ณ๋๋ก ๊ตฌํํ๋ค.
+ -[x] InputView: readDate()...
+ -[x] OutputView : printMenu()...
+-[x] Console.readLine()์ ํ์ฉํ๋ค.
+
+---
+
+### 3์ฃผ์ฐจ ํผ๋๋ฐฑ ๋ด์ฉ
+
+-[x] 3์ฃผ์ฐจ ๊ณตํตํผ๋๋ฐฑ ์งํค๊ธฐ!
+-[x] `Integer.parseInt()`๋ฅผ ์ฌ์ฉํ๋ฉด ์ ์์ ๋ฒ์๊ฐ ์๋ ๋์๋ ์์ธ๊ฐ ๋ฐ์ํ๋๋ฐ, ์์ธ ๋ฉ์์ง๋ฅด ์กฐ๊ธ ๋ ๊ผผ๊ผผํ๊ฒ ์ฑ๊ธฐ์
+-[x] Enum์์ ๋ฌธ์์ด์ ํฉ์น ๋ `+`๋ณด๋ค๋, `String.format()`์ ์ฌ์ฉํ์
+-[x] `System.lineSeperator()`์ `String.format("%n")`์ ๊ฐ์ ์ญํ ์ ํ๋ค. ํ์ฉํด๋ณด์!
+-[x] ์๊ตฌ์ฌํญ์ ๊ผผ๊ผผํ๊ฒ ์ฝ์. (์ธ์๋ฆฌ๋ง๋ค ์ผํ๋ฅผ ๋ฃ์ด์ค๋ค๋์ง...)
+-[x] ์์๋ฅผ enum์ผ๋ก ๋บ์ผ๋ฉด ์ด๋ฅผ ํ์ฉํ์! ๋งค์ง ๋๋ฒ์ ์ฌ์ฉ์ ์ค์ด์! ํ์ฅ์ฑ์ ๊ณ ๋ คํ ๊ตฌ์กฐ๋ฅผ ๋ง๋ค์!
+-[x] ์์ธ๋ฅผ ๋ค์ ๋ฐ๋ ๋ฐฉ๋ฒ์ผ๋ก ์ฌ๊ท๋ฅผ ์ฌ์ฉํ๋๋ฐ, ๋ฉ๋ชจ๋ฆฌ๊ฐ ํฐ์ง ๊ฐ๋ฅ์ฑ์ด ์๋ค. `Supplier`๋ฅผ ๋์
ํด๋ณด์.
+-[x] ๊ฒ์ฆ(Validate)๊ณผ ํ์ฑ(Parsing)์ ๋ก์ง์ ์ด๋์ ๋๋ฉด ์ข์๊น? ๊ณ ๋ฏผํด๋ณด์.
+-[x] ๋๋ฏธํฐ์ ๋ฒ์น!
+-[x] `Console.close()`๋ฅผ ํตํด ์ฌ์ฉ ์๋ฃํ ์ฝ์์ ๋ซ์์ฃผ์
+
+---
+
+### ๊ฐ๋ฐ ์ค ์์ฑํ๋ ๋ฆฌํฉํ ๋ง ๋ชฉ๋ก
+
+-[x] IoC ์ปจํ
์ด๋ ์ ์ฉํ๊ธฐ
+-[x] Enum์ด ๋๋ฌด ์ฐํ์ฃฝ์ ์๊ธด ๊ฒ ๊ฐ๋ค! ์ ๋ฆฌํ ์ ์๋ ๋ถ๋ถ์ ์ ๋ฆฌํด๋ณด์
+-[x] InputView, OutputView์์ `readLine()`๊ณผ `System.out.print` ๋ถ๋ถ ์ถ์ํํ๊ธฐ
+-[x] `Supplier`๋ฅผ ์ด์ฉํ์ฌ ์ฌ์
๋ ฅ ์ฒ๋ฆฌํ๊ธฐ
+-[x] Validator(๊ฒ์ฆ)์ ์ญํ ์ด ์ ์ ํ๊ฒ ๋ถ๋ฐฐ๋์ด ์๋์ง ํ์ธ
+ -[x] MenuService์ validate ํจ์๋ค์ ๋ํด ์ค๋ณต๋์ด์๋ ์ฝ๋ ์ฒ๋ฆฌํ๊ธฐ
+-[x] MenuService์ ์ฝ๋๊ฐ ์กฐ๊ธ ๋์กํ ๊ฒ ๊ฐ์
+-[x] Message์ %n์ ๋ํด ์ด๋ป๊ฒ...์ฒ๋ฆฌ ์ข ํ๊ธฐ
+-[ ] Parser์์ parseToDate, parseToAmount์ ์ฝ๋๊ฐ ๊ฒน์น๋ค. ์ ๋ฌํ๋ ์์ธ ๋ฉ์ธ์ง๋ง ๋ค๋ฅธ๋ฐ... ๋ฐฉ๋ฒ์ ์ฐพ์๋ณด์.
+-[x] DiscountResult์ ๋๋ฌด ๋ง์ ์ฑ
์์ด ์๋ ๊ฒ ๊ฐ๋ค! DiscountService์๊ฒ ์ฑ
์์ ๋ ๋ถ์ฌํ์.
+ -> DiscountResult -> EventResult -> EventService๋ก ๋ณ๊ฒฝ ๋ฐ ์ญํ ๋ถ์ฌ
+-[x] ๋ฉ์๋, ๋ณ์๋ช
์ด ์ ์ ํ์ง ํ์ธ ํ ์์
+-[x] ๋ฉ๋ด๋ฅผ ์๋ชป์
๋ ฅํ์ ๋ `IndexOutOfBounds`๊ฐ ๋ฐ์ํ๋ฉด์ ์ข
๋ฃ๋๋ค.
+-[x] OutputView์์ formatting์ ํ๋ฉด์ ๊ฒน์น๋ ์ฝ๋๊ฐ ๊ณณ๊ณณ์ ์๋ค. ์์ ํ์!
+
+---
+
+### ๊ตฌํํ๋ฉด์ ์ง์คํ๋ ๋ถ๋ถ๋ค! ๊ณ ๋ฏผ๊ฑฐ๋ฆฌ!
+
+#### โ
Discountable(Eventable๋ก ๋ณ๊ฒฝ) ์ธํฐํ์ด์ค์ ์ ๋๋ฆญ์ ์ ์ฉํ์
+
+> ๐ง ๊ณ ๋ฏผ ๋ด์ฉ ๐ง
+> ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด, ์ฆ์ ์ด๋ฒคํธ, ํ์ผ ํ ์ธ, ์ฃผ๋ง ํ ์ธ, ํน๋ณ ํ ์ธ ๋ชจ๋ ๊ฐ์๋ง์ ๊ณ ์ ํ ํ ์ธ ์กฐ๊ฑด๋ค์ด ์๋ค.
+> ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด์ ์ฆ์ ์ด๋ฒคํธ๋ `์ด ์ฃผ๋ฌธ ๊ธ์ก`๊ณผ `๋ ์ง`๋ฅผ ํ์ธํ๋ฉด ๋๋๋ฐ, ์ด๋ค์ ๋ชจ๋ intํ์ผ๋ก ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํ๋ค.
+>
+> ํ์ง๋ง ํ์ผ, ์ฃผ๋ง ํ ์ธ์ `๋ ์ง`๋ง ๋ฐ๋ ๊ฒ์ด ์๋๋ผ, ๋ฉ๋ด์ ๋ํ ์ต์ํ์ ์ ๋ณด๊ฐ ์ถ๊ฐ์ ์ผ๋ก ํ์ํ๋ค.
+> ๋ชจ๋ ํ ์ธ ํด๋์ค๋ค์ด ๊ณตํต์ผ๋ก ๊ฐ์ง๊ณ ์์ด์ผ ํ๋ ๊ฒ๋ค์ `Discountable ์ธํฐํ์ด์ค(Eventable ์ธํฐํ์ด์ค๋ก ๋ณ๊ฒฝ)`๋ก ํํํ๊ณ ์ถ์๋ฐ ์ด๋ป๊ฒ ํ๋ฉด ์ข์๊น?
+
+์ด์ ๋ํด ์๊ฐ๋ ํด๋ต์ ๋ฐ๋ก `์ ๋๋ฆญ`์ ์ฌ์ฉํ๋ ๊ฒ์ด์๋ค.
+`์ ๋๋ฆญ`์ ์ฌ์ฉํ๋ฉด `canDiscount`์ ๋งค๊ฐ๋ณ์์ ์๋ฃํ์ ์๊ด์์ด ์ ๋ฌํ๊ณ ์ถ์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
+๋ฐ๋ผ์ `Discountable` ์ธํฐํ์ด์ค์ `canDiscount()`์ ๋งค๊ฐ๋ณ์๋ก ์ ๋ฌ๋๋ ์กฐ๊ฑด(`condition`) `์ ๋๋ฆญ <T>`๋ฅผ ์ ์ฉํ๋ค.
+
+<br>
+
+#### โ
View์์ ์ ์ ํ ๋ณํํด์ ์ ๋ฌํ์. ๊ผญ String์ผ๋ก ์ ๋ฌํ ํ์๊ฐ ์๋ค.
+
+<br>
+
+#### โ
๋ค๋ฅธ ๊ณ์ธต๊ณผ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์ ๋์๋ DTO๋ฅผ ์ด์ฉํ์.
+
+
+ | Unknown | ๊ณ ๋ฏผ ๋ด์ฉ์ ์ ์ผ์ ๊ฒ... ์ฐธ์ ํ๋ค์ !! ์ ๋ ๋ฆฌ๋๋ฏธ ์์ฑ์ด ํ๋ค์ด์ ใ
.ใ
๋ฐฐ์๊ฐ๋๋ค ๐ |
@@ -0,0 +1,24 @@
+package com.requestrealpiano.songrequest.controller;
+
+import com.requestrealpiano.songrequest.service.AccountService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/api/accounts")
+public class AccountController {
+
+ private final AccountService accountService;
+
+ @GetMapping("/auth")
+ public ResponseEntity<Void> generateToken(@RequestHeader HttpHeaders httpHeaders) {
+ String jwtToken = accountService.generateJwtToken(httpHeaders.getFirst(HttpHeaders.AUTHORIZATION));
+ HttpHeaders responseHeaders = new HttpHeaders();
+ responseHeaders.add(HttpHeaders.AUTHORIZATION, jwtToken);
+ return new ResponseEntity<>(responseHeaders, HttpStatus.NO_CONTENT);
+ }
+} | Java | ๋ค๋ฅธ ์ปจํธ๋กค๋ฌ์์๋ ResponseStatus๋ก ์ง์ ํ๋๋ฐ ์ฌ๊ธด ResponseEntity๋ก ์ง์ ํ๊ตฐ์ ์ด๋ค ์ด์ ๋ก ์ง์ ํ๋์ง ๊ถ๊ธํฉ๋๋ค. |
@@ -2,18 +2,18 @@
import com.requestrealpiano.songrequest.domain.song.searchapi.response.SearchApiResponse;
import com.requestrealpiano.songrequest.global.response.ApiResponse;
+import com.requestrealpiano.songrequest.global.response.StatusCode;
import com.requestrealpiano.songrequest.service.SongService;
import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.Size;
import static com.requestrealpiano.songrequest.global.constant.ValidationCondition.*;
-import static com.requestrealpiano.songrequest.global.response.ApiResponse.OK;
+import static com.requestrealpiano.songrequest.global.response.ApiResponse.SUCCESS;
+import static com.requestrealpiano.songrequest.global.response.StatusCode.OK;
@RequiredArgsConstructor
@Validated
@@ -23,12 +23,13 @@ public class SongController {
private final SongService songService;
+ @ResponseStatus(HttpStatus.OK)
@GetMapping
public ApiResponse<SearchApiResponse> search(@RequestParam(defaultValue = "artist") @Size(max = ARTIST_MAX)
String artist,
@RequestParam(defaultValue = "title") @Size(max = TITLE_MAX)
String title) {
SearchApiResponse searchApiResponse = songService.searchSong(artist, title);
- return OK(searchApiResponse);
+ return SUCCESS(OK, searchApiResponse);
}
} | Java | ์ด ๋ถ๋ถ์ ์ปจํธ๋กค๋ฌ์์ Validation์ ์ก๊ธฐ๋ณด๋จ Validation DTO๋ฅผ ์์ฑํด์ ํด๋น ๊ฐ์ฒด์์ ๊ด๋ฆฌํ๋ฉด ๋์ฑ ํธ๋ฆฌํ๊ณ ๋ณด๊ธฐ๊ฐ ์ข์๋ฏ ํฉ๋๋ค. |
@@ -1,5 +1,6 @@
package com.requestrealpiano.songrequest.domain.account;
+import com.requestrealpiano.songrequest.security.oauth.OAuthAttributes;
import com.requestrealpiano.songrequest.domain.base.BaseTimeEntity;
import com.requestrealpiano.songrequest.domain.letter.Letter;
import lombok.AccessLevel;
@@ -8,9 +9,6 @@
import lombok.NoArgsConstructor;
import javax.persistence.*;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
@@ -25,7 +23,7 @@ public class Account extends BaseTimeEntity {
private Long id;
@Column(name = "google_oauth_id")
- private Long googleOauthId;
+ private String googleOauthId;
private String name;
@@ -44,12 +42,36 @@ public class Account extends BaseTimeEntity {
private List<Letter> letters = new ArrayList<>();
@Builder
- private Account(Long googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) {
+ private Account(String googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) {
this.googleOauthId = googleOauthId;
this.name = name;
this.email = email;
this.role = role;
this.avatarUrl = avatarUrl;
this.requestCount = requestCount;
}
+
+ public String getRoleKey() { return role.getKey(); }
+
+ public String getRoleValue() {
+ return role.getValue();
+ }
+
+ public Account updateProfile(OAuthAttributes attributes) {
+ this.name = attributes.getName();
+ this.email = attributes.getEmail();
+ this.avatarUrl = attributes.getAvatarUrl();
+ return this;
+ }
+
+ public static Account from(OAuthAttributes oAuthAttributes) {
+ return Account.builder()
+ .googleOauthId(oAuthAttributes.getGoogleOauthId())
+ .name(oAuthAttributes.getName())
+ .email(oAuthAttributes.getEmail())
+ .role(Role.MEMBER)
+ .avatarUrl(oAuthAttributes.getAvatarUrl())
+ .requestCount(0)
+ .build();
+ }
} | Java | ์ใ
ใ
ใ
ใ
OAuthId๋ฅผ ํ์ธํ์๊ณ ๋ฐ๊พธ์
จ๊ตฐ์. |
@@ -1,5 +1,6 @@
package com.requestrealpiano.songrequest.domain.account;
+import com.requestrealpiano.songrequest.security.oauth.OAuthAttributes;
import com.requestrealpiano.songrequest.domain.base.BaseTimeEntity;
import com.requestrealpiano.songrequest.domain.letter.Letter;
import lombok.AccessLevel;
@@ -8,9 +9,6 @@
import lombok.NoArgsConstructor;
import javax.persistence.*;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
@@ -25,7 +23,7 @@ public class Account extends BaseTimeEntity {
private Long id;
@Column(name = "google_oauth_id")
- private Long googleOauthId;
+ private String googleOauthId;
private String name;
@@ -44,12 +42,36 @@ public class Account extends BaseTimeEntity {
private List<Letter> letters = new ArrayList<>();
@Builder
- private Account(Long googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) {
+ private Account(String googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) {
this.googleOauthId = googleOauthId;
this.name = name;
this.email = email;
this.role = role;
this.avatarUrl = avatarUrl;
this.requestCount = requestCount;
}
+
+ public String getRoleKey() { return role.getKey(); }
+
+ public String getRoleValue() {
+ return role.getValue();
+ }
+
+ public Account updateProfile(OAuthAttributes attributes) {
+ this.name = attributes.getName();
+ this.email = attributes.getEmail();
+ this.avatarUrl = attributes.getAvatarUrl();
+ return this;
+ }
+
+ public static Account from(OAuthAttributes oAuthAttributes) {
+ return Account.builder()
+ .googleOauthId(oAuthAttributes.getGoogleOauthId())
+ .name(oAuthAttributes.getName())
+ .email(oAuthAttributes.getEmail())
+ .role(Role.MEMBER)
+ .avatarUrl(oAuthAttributes.getAvatarUrl())
+ .requestCount(0)
+ .build();
+ }
} | Java | ์ฌ๊ธฐ ์ ํ์๋ MaginNumber 0์ ์ด๋ค์๋ฏธ์ธ๊ฐ์? |
@@ -11,6 +11,12 @@ public enum ErrorCode {
METHOD_NOT_ALLOWED(405, "์ง์ํ์ง ์๋ ์์ฒญ ๋ฉ์๋ ์
๋๋ค."),
INTERNAL_SERVER_ERROR(500, "์๋ฒ์์ ์์ฒญ์ ์ฒ๋ฆฌํ์ง ๋ชปํ์ต๋๋ค."),
+ // Auth
+ UNAUTHENTICATED_ERROR(401, "์ธ์ฆ์ด ํ์ํฉ๋๋ค. ๋ก๊ทธ์ธ ์ดํ ๋ค์ ์๋ ํด์ฃผ์ธ์."),
+ JWT_INVALID_ERROR(400, "์ฌ๋ฐ๋ฅธ ์ธ์ฆ ์ ๋ณด๊ฐ ์๋๋๋ค. ๋ค์ ๋ก๊ทธ์ธ ํด์ฃผ์ธ์."),
+ JWT_EXPIRATION_ERROR(401, "์ธ์ฆ ์ ๋ณด๊ฐ ๋ง๋ฃ ๋์์ต๋๋ค. ๋ค์ ๋ก๊ทธ์ธ ํด์ฃผ์ธ์."),
+ ACCESS_DENIED_ERROR(403, "ํด๋น ์์ฒญ์ ๋ํ ์ ๊ทผ ๊ถํ์ด ์์ต๋๋ค."),
+
// Account
ACCOUNT_NOT_FOUND(404, "ํด๋น ๊ณ์ ์ด ์กด์ฌํ์ง ์์ต๋๋ค."),
| Java | ์ฌ๊ธฐ์ JWT ์ธ์ฆํ ๋ ๋๊ฐ์ง ์กฐ๊ฑด์ด ์๋๊ตฐ์.
1. JWT๊ฐ ์๋ Token์ ์ฌ์ฉํ ๊ฒฝ์ฐ - 400
2. JWT๋ ๋ง๋๋ฐ ์ฌ๋ฐ๋ฅธ JWT๊ฐ ์๋ ๊ฒฝ์ฐ - 401
๋๊ฐ์ง ๊ณ ๋ คํ์๋๊ฑด ์ด๋ ์ ์ง ๋๋ ์๊ฒฌ์ด ๊ถ๊ธํฉ๋๋ค. |
@@ -11,6 +11,12 @@ public enum ErrorCode {
METHOD_NOT_ALLOWED(405, "์ง์ํ์ง ์๋ ์์ฒญ ๋ฉ์๋ ์
๋๋ค."),
INTERNAL_SERVER_ERROR(500, "์๋ฒ์์ ์์ฒญ์ ์ฒ๋ฆฌํ์ง ๋ชปํ์ต๋๋ค."),
+ // Auth
+ UNAUTHENTICATED_ERROR(401, "์ธ์ฆ์ด ํ์ํฉ๋๋ค. ๋ก๊ทธ์ธ ์ดํ ๋ค์ ์๋ ํด์ฃผ์ธ์."),
+ JWT_INVALID_ERROR(400, "์ฌ๋ฐ๋ฅธ ์ธ์ฆ ์ ๋ณด๊ฐ ์๋๋๋ค. ๋ค์ ๋ก๊ทธ์ธ ํด์ฃผ์ธ์."),
+ JWT_EXPIRATION_ERROR(401, "์ธ์ฆ ์ ๋ณด๊ฐ ๋ง๋ฃ ๋์์ต๋๋ค. ๋ค์ ๋ก๊ทธ์ธ ํด์ฃผ์ธ์."),
+ ACCESS_DENIED_ERROR(403, "ํด๋น ์์ฒญ์ ๋ํ ์ ๊ทผ ๊ถํ์ด ์์ต๋๋ค."),
+
// Account
ACCOUNT_NOT_FOUND(404, "ํด๋น ๊ณ์ ์ด ์กด์ฌํ์ง ์์ต๋๋ค."),
| Java | ์ฌ๊ธฐ์๋ ์ด์ผ๊ธฐ ํ๊ณ ์ถ์๊ฒ์ด ์์ต๋๋ค. ํด๋น API๋ฅผ ์ฌ์ฉํ ๋ ๊ถํ์ ๋ง๋ ๊ฒ์ด 403์ด์ง๋ง ๋ง์ฝ ๋น๊ณต๊ฐ๋ ์ ๋ณด๋ฅผ API๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ ธ์ฌ๋๋ 404๋ก Not Found๋ก ๋์์ผํ๋ค๊ณ ํ๋๊ตฐ์.
๊ทธ์ ๋ํ ๋๋น์ฑ
๋ ํ์ํด ๋ณด์
๋๋ค. |
@@ -0,0 +1,105 @@
+package com.requestrealpiano.songrequest.security;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.requestrealpiano.songrequest.domain.account.Role;
+import com.requestrealpiano.songrequest.security.filter.JwtAuthorizationFilter;
+import com.requestrealpiano.songrequest.security.jwt.JwtTokenProvider;
+import com.requestrealpiano.songrequest.security.oauth.CustomAccessDeniedHandler;
+import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationEntryPoint;
+import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationSuccessHandler;
+import com.requestrealpiano.songrequest.security.oauth.CustomOAuth2UserService;
+import com.requestrealpiano.songrequest.domain.account.AccountRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpMethod;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.security.web.csrf.CsrfFilter;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.CorsConfigurationSource;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CharacterEncodingFilter;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.springframework.security.config.Customizer.withDefaults;
+
+@RequiredArgsConstructor
+@Configuration
+@EnableWebSecurity
+public class SecurityConfig extends WebSecurityConfigurerAdapter {
+
+ private final CustomOAuth2UserService customOAuth2UserService;
+ private final CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler;
+ private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint;
+ private final CustomAccessDeniedHandler customAccessDeniedHandler;
+ private final AccountRepository accountRepository;
+ private final JwtTokenProvider jwtTokenProvider;
+ private final ObjectMapper objectMapper;
+
+ @Override
+ public void configure(WebSecurity web) throws Exception {
+ web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations());
+
+ web.ignoring().antMatchers(HttpMethod.GET, "/api/accounts/auth")
+ .antMatchers(HttpMethod.GET, "/api/letters/**")
+ ;
+ }
+
+ @Override
+ protected void configure(HttpSecurity http) throws Exception {
+ http.cors(withDefaults());
+
+ http.csrf().disable()
+ .httpBasic().disable();
+
+ http.authorizeRequests()
+// .antMatchers("/**").permitAll()
+ .antMatchers("/api/letters").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey())
+ .antMatchers("/api/songs").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey())
+ .anyRequest().authenticated();
+
+ http.sessionManagement()
+ .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
+
+ http.addFilterBefore(characterEncodingFilter(), CsrfFilter.class)
+ .addFilterBefore(JwtAuthorizationFilter.of(accountRepository, jwtTokenProvider, objectMapper), UsernamePasswordAuthenticationFilter.class);
+
+ http.oauth2Login()
+ .userInfoEndpoint()
+ .userService(customOAuth2UserService)
+ .and()
+ .successHandler(customAuthenticationSuccessHandler);
+
+ http.exceptionHandling()
+ .authenticationEntryPoint(customAuthenticationEntryPoint)
+ .accessDeniedHandler(customAccessDeniedHandler);
+ }
+
+ public CharacterEncodingFilter characterEncodingFilter() {
+ CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
+ encodingFilter.setEncoding("UTF-8");
+ encodingFilter.setForceEncoding(true);
+ return encodingFilter;
+ }
+
+ @Bean
+ CorsConfigurationSource corsConfigurationSource() {
+ CorsConfiguration configuration = new CorsConfiguration();
+ configuration.setAllowedOrigins(Collections.singletonList("*"));
+ configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
+ configuration.setAllowedHeaders(Collections.singletonList("*"));
+ configuration.setExposedHeaders(Collections.singletonList("Authorization"));
+ configuration.setAllowCredentials(true);
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+ source.registerCorsConfiguration("/**", configuration);
+ return source;
+ }
+} | Java | ์ฌ์ฉํ์์ง ์์ ์ฝ๋๋ฉด ์ญ์ ํ๊ณ ๊ทธ๋๋ ์ฃผ์์ฒ๋ฆฌ๋ฅผ ๋จ๊ธฐ๊ณ ์ถ๋ค๋ฉด ์ ์ฃผ์์ฒ๋ฆฌํ๋์ง์ ๋ํ ์ค๋ช
์ ์ถ๊ฐํด์ฃผ์ธ์ |
@@ -0,0 +1,105 @@
+package com.requestrealpiano.songrequest.security;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.requestrealpiano.songrequest.domain.account.Role;
+import com.requestrealpiano.songrequest.security.filter.JwtAuthorizationFilter;
+import com.requestrealpiano.songrequest.security.jwt.JwtTokenProvider;
+import com.requestrealpiano.songrequest.security.oauth.CustomAccessDeniedHandler;
+import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationEntryPoint;
+import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationSuccessHandler;
+import com.requestrealpiano.songrequest.security.oauth.CustomOAuth2UserService;
+import com.requestrealpiano.songrequest.domain.account.AccountRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpMethod;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.security.web.csrf.CsrfFilter;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.CorsConfigurationSource;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CharacterEncodingFilter;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.springframework.security.config.Customizer.withDefaults;
+
+@RequiredArgsConstructor
+@Configuration
+@EnableWebSecurity
+public class SecurityConfig extends WebSecurityConfigurerAdapter {
+
+ private final CustomOAuth2UserService customOAuth2UserService;
+ private final CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler;
+ private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint;
+ private final CustomAccessDeniedHandler customAccessDeniedHandler;
+ private final AccountRepository accountRepository;
+ private final JwtTokenProvider jwtTokenProvider;
+ private final ObjectMapper objectMapper;
+
+ @Override
+ public void configure(WebSecurity web) throws Exception {
+ web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations());
+
+ web.ignoring().antMatchers(HttpMethod.GET, "/api/accounts/auth")
+ .antMatchers(HttpMethod.GET, "/api/letters/**")
+ ;
+ }
+
+ @Override
+ protected void configure(HttpSecurity http) throws Exception {
+ http.cors(withDefaults());
+
+ http.csrf().disable()
+ .httpBasic().disable();
+
+ http.authorizeRequests()
+// .antMatchers("/**").permitAll()
+ .antMatchers("/api/letters").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey())
+ .antMatchers("/api/songs").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey())
+ .anyRequest().authenticated();
+
+ http.sessionManagement()
+ .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
+
+ http.addFilterBefore(characterEncodingFilter(), CsrfFilter.class)
+ .addFilterBefore(JwtAuthorizationFilter.of(accountRepository, jwtTokenProvider, objectMapper), UsernamePasswordAuthenticationFilter.class);
+
+ http.oauth2Login()
+ .userInfoEndpoint()
+ .userService(customOAuth2UserService)
+ .and()
+ .successHandler(customAuthenticationSuccessHandler);
+
+ http.exceptionHandling()
+ .authenticationEntryPoint(customAuthenticationEntryPoint)
+ .accessDeniedHandler(customAccessDeniedHandler);
+ }
+
+ public CharacterEncodingFilter characterEncodingFilter() {
+ CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
+ encodingFilter.setEncoding("UTF-8");
+ encodingFilter.setForceEncoding(true);
+ return encodingFilter;
+ }
+
+ @Bean
+ CorsConfigurationSource corsConfigurationSource() {
+ CorsConfiguration configuration = new CorsConfiguration();
+ configuration.setAllowedOrigins(Collections.singletonList("*"));
+ configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
+ configuration.setAllowedHeaders(Collections.singletonList("*"));
+ configuration.setExposedHeaders(Collections.singletonList("Authorization"));
+ configuration.setAllowCredentials(true);
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+ source.registerCorsConfiguration("/**", configuration);
+ return source;
+ }
+} | Java | Role์ ์์ฃผ ์ฌ์ฉํ์ค ๋ฏํ๋ฐ import static์ผ๋ก ์ ์ธํ๋ ๊ฒ๋ ๋์์ง ์๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,105 @@
+package com.requestrealpiano.songrequest.security;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.requestrealpiano.songrequest.domain.account.Role;
+import com.requestrealpiano.songrequest.security.filter.JwtAuthorizationFilter;
+import com.requestrealpiano.songrequest.security.jwt.JwtTokenProvider;
+import com.requestrealpiano.songrequest.security.oauth.CustomAccessDeniedHandler;
+import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationEntryPoint;
+import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationSuccessHandler;
+import com.requestrealpiano.songrequest.security.oauth.CustomOAuth2UserService;
+import com.requestrealpiano.songrequest.domain.account.AccountRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpMethod;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.security.web.csrf.CsrfFilter;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.CorsConfigurationSource;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CharacterEncodingFilter;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.springframework.security.config.Customizer.withDefaults;
+
+@RequiredArgsConstructor
+@Configuration
+@EnableWebSecurity
+public class SecurityConfig extends WebSecurityConfigurerAdapter {
+
+ private final CustomOAuth2UserService customOAuth2UserService;
+ private final CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler;
+ private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint;
+ private final CustomAccessDeniedHandler customAccessDeniedHandler;
+ private final AccountRepository accountRepository;
+ private final JwtTokenProvider jwtTokenProvider;
+ private final ObjectMapper objectMapper;
+
+ @Override
+ public void configure(WebSecurity web) throws Exception {
+ web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations());
+
+ web.ignoring().antMatchers(HttpMethod.GET, "/api/accounts/auth")
+ .antMatchers(HttpMethod.GET, "/api/letters/**")
+ ;
+ }
+
+ @Override
+ protected void configure(HttpSecurity http) throws Exception {
+ http.cors(withDefaults());
+
+ http.csrf().disable()
+ .httpBasic().disable();
+
+ http.authorizeRequests()
+// .antMatchers("/**").permitAll()
+ .antMatchers("/api/letters").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey())
+ .antMatchers("/api/songs").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey())
+ .anyRequest().authenticated();
+
+ http.sessionManagement()
+ .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
+
+ http.addFilterBefore(characterEncodingFilter(), CsrfFilter.class)
+ .addFilterBefore(JwtAuthorizationFilter.of(accountRepository, jwtTokenProvider, objectMapper), UsernamePasswordAuthenticationFilter.class);
+
+ http.oauth2Login()
+ .userInfoEndpoint()
+ .userService(customOAuth2UserService)
+ .and()
+ .successHandler(customAuthenticationSuccessHandler);
+
+ http.exceptionHandling()
+ .authenticationEntryPoint(customAuthenticationEntryPoint)
+ .accessDeniedHandler(customAccessDeniedHandler);
+ }
+
+ public CharacterEncodingFilter characterEncodingFilter() {
+ CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
+ encodingFilter.setEncoding("UTF-8");
+ encodingFilter.setForceEncoding(true);
+ return encodingFilter;
+ }
+
+ @Bean
+ CorsConfigurationSource corsConfigurationSource() {
+ CorsConfiguration configuration = new CorsConfiguration();
+ configuration.setAllowedOrigins(Collections.singletonList("*"));
+ configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
+ configuration.setAllowedHeaders(Collections.singletonList("*"));
+ configuration.setExposedHeaders(Collections.singletonList("Authorization"));
+ configuration.setAllowCredentials(true);
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+ source.registerCorsConfiguration("/**", configuration);
+ return source;
+ }
+} | Java | `WebConfig`์์๋ CORS ์๋ฌ์ ๋ํ ๋๋น์ฑ
์ ์ค์ ํ์
จ๋๋ฐ ์ฌ๊ธฐ์๋ ์ค์ ํ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,115 @@
+package com.requestrealpiano.songrequest.security.jwt;
+
+import com.requestrealpiano.songrequest.domain.account.Account;
+import com.requestrealpiano.songrequest.global.error.exception.jwt.JwtExpirationException;
+import com.requestrealpiano.songrequest.global.error.exception.jwt.JwtInvalidTokenException;
+import com.requestrealpiano.songrequest.global.error.exception.jwt.JwtRequiredException;
+import com.requestrealpiano.songrequest.security.jwt.claims.AccountClaims;
+import io.jsonwebtoken.*;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+@RequiredArgsConstructor
+@Component
+public class JwtTokenProvider {
+
+ private final JwtProperties jwtProperties;
+
+ private final String ID = "id";
+ private final String EMAIL = "email";
+ private final String NAME = "name";
+ private final String AVATAR_URL = "avatarUrl";
+ private final String ROLE = "role";
+
+ public String createGenerationKey(String email) {
+ Date now = new Date();
+ return Jwts.builder()
+ .setHeaderParam(Header.TYPE, Header.JWT_TYPE)
+ .setIssuedAt(now)
+ .setExpiration(new Date(now.getTime() + Long.parseLong(jwtProperties.getGenerationKeyExpiration())))
+ .claim(EMAIL, email)
+ .signWith(SignatureAlgorithm.HS256, jwtProperties.getGenerationKeySecret())
+ .compact();
+ }
+
+ public String parseGenerationKey(String authorization) {
+ String generationKey = extractToken(authorization);
+ try {
+ Jws<Claims> claims = Jwts.parser()
+ .setSigningKey(jwtProperties.getGenerationKeySecret())
+ .parseClaimsJws(generationKey);
+ return claims.getBody()
+ .get(EMAIL, String.class);
+ } catch (ExpiredJwtException exception) {
+ throw new JwtExpirationException();
+ } catch (JwtException exception) {
+ throw new JwtInvalidTokenException();
+ }
+ }
+
+ public String createJwtToken(Account account) {
+ Date now = new Date();
+ String jwtToken = Jwts.builder()
+ .setHeaderParam(Header.TYPE, Header.JWT_TYPE)
+ .setIssuedAt(now)
+ .setExpiration(new Date(now.getTime() + Long.parseLong(jwtProperties.getTokenExpiration())))
+ .claim(ID, account.getId())
+ .claim(EMAIL, account.getEmail())
+ .claim(NAME, account.getName())
+ .claim(AVATAR_URL, account.getAvatarUrl())
+ .claim(ROLE, account.getRoleKey())
+ .signWith(SignatureAlgorithm.HS256, jwtProperties.getTokenSecret())
+ .compact();
+ return jwtProperties.getHeaderPrefix() + jwtToken;
+ }
+
+ public boolean validateJwtToken(String authorization) {
+ String jwtToken = extractToken(authorization);
+ try {
+ Jws<Claims> claims = Jwts.parser()
+ .setSigningKey(jwtProperties.getTokenSecret())
+ .parseClaimsJws(jwtToken);
+ return claims.getBody()
+ .getExpiration()
+ .after(new Date());
+ } catch (ExpiredJwtException exception) {
+ throw new JwtExpirationException();
+ } catch (JwtException exception) {
+ throw new JwtInvalidTokenException();
+ }
+ }
+
+ public AccountClaims parseJwtToken(String jwtToken) {
+ try {
+ Jws<Claims> claims = Jwts.parser()
+ .setSigningKey(jwtProperties.getTokenSecret())
+ .parseClaimsJws(jwtToken);
+ Claims body = claims.getBody();
+
+ return AccountClaims.from(body);
+ } catch (ExpiredJwtException exception) {
+ throw new JwtExpirationException();
+ } catch (JwtException exception) {
+ throw new JwtInvalidTokenException();
+ }
+ }
+
+ public String extractToken(String authorizationHeader) {
+ if (isTokenContained(authorizationHeader)) {
+ int tokenBeginIndex = jwtProperties.getHeaderPrefix().length();
+ return StringUtils.substring(authorizationHeader, tokenBeginIndex);
+ }
+ throw new JwtRequiredException();
+ }
+
+ private boolean isTokenContained(String authorization) {
+ if (StringUtils.isEmpty(authorization)) {
+ return false;
+ }
+
+ return authorization.startsWith(jwtProperties.getHeaderPrefix());
+ }
+} | Java | Date ํ์
์ ์ฐ์
จ๋๋ฐ LocalDate ํ์
์ด ์๋ ์ด์ ๊ฐ ๋ฌด์์ธ๊ฐ์? |
@@ -0,0 +1,21 @@
+package com.requestrealpiano.songrequest.security.jwt;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.ConstructorBinding;
+
+@RequiredArgsConstructor
+@Getter
+@ConstructorBinding
+@ConfigurationProperties(prefix = "jwt")
+public class JwtProperties {
+
+ private final String tokenSecret;
+ private final String tokenExpiration;
+ private final String header;
+ private final String headerPrefix;
+ private final String tokenUrl;
+ private final String generationKeySecret;
+ private final String generationKeyExpiration;
+} | Java | ์์ฑ์๊ฐ ํ์ํ๊ฐ์? ๋ถํ์ํ ์์ฑ์๊ฐ์์ |
@@ -0,0 +1,33 @@
+package com.requestrealpiano.songrequest.security.oauth;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.requestrealpiano.songrequest.global.error.response.ErrorCode;
+import com.requestrealpiano.songrequest.global.error.response.ErrorResponse;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.MediaType;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.web.access.AccessDeniedHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@RequiredArgsConstructor
+@Component
+public class CustomAccessDeniedHandler implements AccessDeniedHandler {
+
+ private final ObjectMapper objectMapper;
+
+ @Override
+ public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
+ ErrorCode accessDeniedError = ErrorCode.ACCESS_DENIED_ERROR;
+ String errorResponse = objectMapper.writeValueAsString(ErrorResponse.from(accessDeniedError));
+ response.getWriter().print(errorResponse);
+ response.setContentType(MediaType.APPLICATION_JSON_VALUE);
+ response.setStatus(accessDeniedError.getStatusCode());
+ response.getWriter().flush();
+ response.getWriter().close();
+ }
+} | Java | ์ด์ ๋ ๊ธธ์ด์ง๋ฉด throws๋ถํฐ ํ์นธ ๋ด๋ ค์ ๋ณด๊ธฐ ์ฝ๊ฒ ํด์ฃผ์ธ์ฉ |
@@ -0,0 +1,33 @@
+package com.requestrealpiano.songrequest.security.oauth;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.requestrealpiano.songrequest.global.error.response.ErrorCode;
+import com.requestrealpiano.songrequest.global.error.response.ErrorResponse;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.MediaType;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.web.access.AccessDeniedHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@RequiredArgsConstructor
+@Component
+public class CustomAccessDeniedHandler implements AccessDeniedHandler {
+
+ private final ObjectMapper objectMapper;
+
+ @Override
+ public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
+ ErrorCode accessDeniedError = ErrorCode.ACCESS_DENIED_ERROR;
+ String errorResponse = objectMapper.writeValueAsString(ErrorResponse.from(accessDeniedError));
+ response.getWriter().print(errorResponse);
+ response.setContentType(MediaType.APPLICATION_JSON_VALUE);
+ response.setStatus(accessDeniedError.getStatusCode());
+ response.getWriter().flush();
+ response.getWriter().close();
+ }
+} | Java | ์ฌ๊ธฐ์ ๊ถ๊ธํ๊ฒ ์ด๋๋ก ์ฌ์ฉํ์ ๋ ์๋ฌ์ฒ๋ฆฌ๋ ๋ฐ์์ด ์ ๋๊ฒ ์ผ๋ ์คํ๋ง ๋ก๊ทธ์๋ ์ฐํ๋ ์ง ๊ถ๊ธํฉ๋๋ค.
์ ๊ฐ ์ด์ ์ฝ๋์ค์ฟผ๋ ๋์๊ด ํ๋ก์ ํธ์์๋ ์ด๋ฐ์์ผ๋ก ์ฒ๋ฆฌํ์ ๋ ๋ก๊ทธ์ ์ฐํ์ง ์๋ ์ฌ์ํ ๋ฌธ์ ์ ์ด ์๊ฒผ์ต๋๋ค. |
@@ -0,0 +1,33 @@
+package com.requestrealpiano.songrequest.security.oauth;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.requestrealpiano.songrequest.global.error.response.ErrorCode;
+import com.requestrealpiano.songrequest.global.error.response.ErrorResponse;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.MediaType;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.web.access.AccessDeniedHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@RequiredArgsConstructor
+@Component
+public class CustomAccessDeniedHandler implements AccessDeniedHandler {
+
+ private final ObjectMapper objectMapper;
+
+ @Override
+ public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
+ ErrorCode accessDeniedError = ErrorCode.ACCESS_DENIED_ERROR;
+ String errorResponse = objectMapper.writeValueAsString(ErrorResponse.from(accessDeniedError));
+ response.getWriter().print(errorResponse);
+ response.setContentType(MediaType.APPLICATION_JSON_VALUE);
+ response.setStatus(accessDeniedError.getStatusCode());
+ response.getWriter().flush();
+ response.getWriter().close();
+ }
+} | Java | ๊ทธ๋์ ์๊ฐํด๋ธ ๊ฒ์ด `AccessDeniedException`์ ๋ฐ๋ ์๋ฌํด๋์ค๋ฅผ ๋ง๋ค๊ณ ํด๋น ์๋ฌ๋ฅผ ์์๋ฐ์ ์ฌ๊ธฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ฉด ํด๋น ํด๋์ค๋ฅผ ํธ์ถํ๋ ๋ฐฉ์์ ์ฌ์ฉํ์ฌ ๋ค๋ฅธ exceptionHandler์ฒ๋ผ ํ๋ฒ์ ๊ด๋ฆฌํ๊ธฐ๋ ํธํ๊ณ ๋ก๊ทธ๋ ์ฐํ ์ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค.
```java
@Component("restAuthenticationEntryPoint")
public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Autowired
private HandlerExceptionResolver resolver;
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
resolver.resolveException(request, response, null, exception);
}
}
``` |
@@ -0,0 +1,14 @@
+package com.requestrealpiano.songrequest.security.oauth;
+
+import org.springframework.security.core.annotation.AuthenticationPrincipal;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.PARAMETER)
+@Retention(RetentionPolicy.RUNTIME)
+@AuthenticationPrincipal
+public @interface LoginAccount {
+} | Java | ์ด๊ฒ๋ง ๋ฌ์๋ GlobalAdvice ์ค์ ์ ํ ํ์๊ฐ ์์ด์ ์ข์ฃ ! |
@@ -0,0 +1,24 @@
+package com.requestrealpiano.songrequest.controller;
+
+import com.requestrealpiano.songrequest.service.AccountService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/api/accounts")
+public class AccountController {
+
+ private final AccountService accountService;
+
+ @GetMapping("/auth")
+ public ResponseEntity<Void> generateToken(@RequestHeader HttpHeaders httpHeaders) {
+ String jwtToken = accountService.generateJwtToken(httpHeaders.getFirst(HttpHeaders.AUTHORIZATION));
+ HttpHeaders responseHeaders = new HttpHeaders();
+ responseHeaders.add(HttpHeaders.AUTHORIZATION, jwtToken);
+ return new ResponseEntity<>(responseHeaders, HttpStatus.NO_CONTENT);
+ }
+} | Java | ๋ถ๋ช
๋ชจ๋ ์ปจํธ๋กค๋ฌ๋ฅผ ๋์์ ์์ ์ ํ์ํ
๋ฐ ์ฌ๊ธฐ๋ ์ํ์ฝ๋๋ง ๋ฐ๊พธ๊ณ ํ์์ ์ด๋ ๊ฒ ๋จ๊ฒจ ๋์์๋ค์.
ํต์ผ์ฑ์ ์ํด ์์ ํ๊ฒ ์ต๋๋คใ
ใ
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.