code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,27 @@
+package christmas.system;
+
+public final class IOMessage {
+ public static final String VISIT_DATE_PROMPT_MESSAGE = "์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n" +
+ "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)";
+
+ public static final String ORDER_PROMPT_MESSAGE = "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)";
+
+ public static final String NONE = "์์";
+ public static final String EMPTY_STRING = " ";
+ public static final String MESSAGE_DELIMITER = ": -";
+
+ public static final String QUANTITY_UNIT = "๊ฐ";
+
+ public static final String MONEY_UNIT = "์";
+
+ public static final String XMAS_DDAY_DISCOUNT = "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ";
+ public static final String WEEKDAY_DISCOUNT = "ํ์ผ ํ ์ธ";
+ public static final String WEEKEND_DISCOUNT = "์ฃผ๋ง ํ ์ธ";
+ public static final String SPECIAL_DISCOUNT = "ํน๋ณ ํ ์ธ";
+ public static final String BONUS_EVENT = "์ฆ์ ์ด๋ฒคํธ";
+
+
+ private IOMessage() {
+
+ }
+} | Java | ์์ฑ์๋ฅผ `private`์ผ๋ก ๋ง์๋์ ๋ชจ์ต์ด ๋ณด๊ธฐ ์ข์ต๋๋ค! ๐ |
@@ -0,0 +1,54 @@
+package christmas.controller;
+
+import christmas.domain.entity.Day;
+import christmas.domain.entity.Order;
+import christmas.view.InputView;
+import java.util.function.Supplier;
+
+import static christmas.domain.verifier.RuntimeVerifier.RUNTIME_VERIFIER;
+import static christmas.system.IOMessage.ORDER_PROMPT_MESSAGE;
+import static christmas.system.IOMessage.VISIT_DATE_PROMPT_MESSAGE;
+import static christmas.view.InputView.*;
+import static christmas.view.OutputView.*;
+
+public class PlannerSystem {
+
+ private final Day day;
+ private final Order order;
+ private final SettlementSystem settlementSystem;
+
+ public PlannerSystem() {
+ printMessage(VISIT_DATE_PROMPT_MESSAGE);
+ this.day = readDay();
+ printEventNotice();
+ printMessage(ORDER_PROMPT_MESSAGE);
+ this.order = readOrder(InputView::tryReadOrder);
+ this.settlementSystem = new SettlementSystem(day, order);
+ }
+ public void run() {
+ renderResult();
+ }
+
+ private Order readOrder(Supplier<Order> orderSupplier) {
+ while (true) {
+ try {
+ Order order = orderSupplier.get();
+ RUNTIME_VERIFIER.validate(order);
+ return order;
+ } catch (IllegalStateException e) {
+ printMessage(e.getMessage());
+ }
+ }
+ }
+
+ private void renderResult() {
+ renderPlannerResult();
+ settlementSystem.renderSettlementResult();
+
+ }
+
+ private void renderPlannerResult() {
+ printResultStartMessage(day);
+ printOrderList(order);
+ }
+} | Java | static์ด ์๋๊ฒ ๊ตฌํํด์ ์์กด๊ด๊ณ๋ฅผ ๊ฐ์ง๊ฒ ํด์ผํ ๊น ๊ณ ๋ฏผํด๋ดค์ต๋๋ค. ํ์คํ ์์กด์ฑ ์ฃผ์
์ด ํ์ํ ๊ด๊ณ์ด๋ค ์ถ์๊ฑฐ๋ ์ฃผ์
์ ์์ผฐ๋๋ฐ inputview์ outputview๊น์ง ์์ผ์ผํ๋ ํด์์. ์ํค๋๊ฒ ๋ง์๊น์? |
@@ -0,0 +1,54 @@
+package christmas.controller;
+
+import christmas.domain.entity.Day;
+import christmas.domain.entity.Order;
+import christmas.view.InputView;
+import java.util.function.Supplier;
+
+import static christmas.domain.verifier.RuntimeVerifier.RUNTIME_VERIFIER;
+import static christmas.system.IOMessage.ORDER_PROMPT_MESSAGE;
+import static christmas.system.IOMessage.VISIT_DATE_PROMPT_MESSAGE;
+import static christmas.view.InputView.*;
+import static christmas.view.OutputView.*;
+
+public class PlannerSystem {
+
+ private final Day day;
+ private final Order order;
+ private final SettlementSystem settlementSystem;
+
+ public PlannerSystem() {
+ printMessage(VISIT_DATE_PROMPT_MESSAGE);
+ this.day = readDay();
+ printEventNotice();
+ printMessage(ORDER_PROMPT_MESSAGE);
+ this.order = readOrder(InputView::tryReadOrder);
+ this.settlementSystem = new SettlementSystem(day, order);
+ }
+ public void run() {
+ renderResult();
+ }
+
+ private Order readOrder(Supplier<Order> orderSupplier) {
+ while (true) {
+ try {
+ Order order = orderSupplier.get();
+ RUNTIME_VERIFIER.validate(order);
+ return order;
+ } catch (IllegalStateException e) {
+ printMessage(e.getMessage());
+ }
+ }
+ }
+
+ private void renderResult() {
+ renderPlannerResult();
+ settlementSystem.renderSettlementResult();
+
+ }
+
+ private void renderPlannerResult() {
+ printResultStartMessage(day);
+ printOrderList(order);
+ }
+} | Java | ํ ๋ชฐ๋์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.!! |
@@ -0,0 +1,32 @@
+package christmas.controller;
+
+import christmas.domain.entity.Day;
+import christmas.domain.entity.DiscountRecord;
+import christmas.domain.entity.Order;
+import christmas.domain.manager.BonusEventManager;
+import christmas.domain.manager.DiscountManager;
+
+import static christmas.domain.entity.EventBadge.createBadge;
+import static christmas.view.OutputView.*;
+
+public class SettlementSystem {
+
+ private final Order order;
+ private final DiscountRecord discountRecord;
+
+ public SettlementSystem(Day day, Order order) {
+ DiscountManager discountManager = new DiscountManager();
+ BonusEventManager bonusEventManager = new BonusEventManager();
+ this.order = order;
+ this.discountRecord = DiscountRecord.create(day, order, discountManager, bonusEventManager);
+ }
+
+ public void renderSettlementResult() {
+ printOriginalTotalAmount(order);
+ printBonusMenu(order);
+ printDiscountRecord(discountRecord);
+ printTotalDiscountAmount(discountRecord);
+ printExpectedPayment(order, discountRecord);
+ printEventBadge(createBadge(discountRecord));
+ }
+} | Java | ์ด๊ฒ ์ฌ๋ฌ๊ฐ์ง๋ก ๋๋ ๋ณผ๋ ค๊ณ ํ๋๋ฐ ๋๋ฌด ์ด๋ ต๋๋ผ๊ตฌ์... ๋๋ ์ผ ๊น๋ํ ๊ฑฐ ๊ฐ๊ธฐ๋ ํ๋ฐ...
๊ทธ๋ฅ ์ ํฌ๊ฐ plannerSystem์ ๊ตฌํํ๋๊ฑฐ์๊ณ , ๊ธฐ๋ฅ๋ค์ด ๋ค ์ ์ฐ(๊ธ์ต)๊ณผ ๊ด๋ จ๋ ๋ถ๋ถ์ด๋ผ์ settlementSystem์ ๋์์ต๋๋ค. |
@@ -0,0 +1,76 @@
+package christmas.domain.entity;
+
+import static christmas.domain.verifier.VisitDateVerifier.VISIT_DATE_VERIFIER;
+import static christmas.system.Constant.CHRISTMAS;
+import static christmas.system.Constant.FIRST_DAY_OF_MONTH;
+
+public class Day {
+
+ private static final int WEEK_LENGTH = 7;
+ private final int day;
+
+ public Day(int day) {
+ VISIT_DATE_VERIFIER.validateInputInDomain(day);
+ this.day = day;
+ }
+
+ public int getDay() {
+ return day;
+ }
+
+ public boolean isChristmasSeason() {
+ if (day >= FIRST_DAY_OF_MONTH && day <= CHRISTMAS) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isWeekday() {
+ if (!(isFriday() || isSaturday())) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isWeekend() {
+ if (isFriday() || isSaturday()) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isSpecialDay() {
+ if (isSunday() || isChristmas()) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isFriday() {
+ if (day % WEEK_LENGTH == 1) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isSaturday() {
+ if (day % WEEK_LENGTH == 2) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isSunday() {
+ if (day % WEEK_LENGTH == 3) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isChristmas() {
+ if (day == CHRISTMAS) {
+ return true;
+ }
+ return false;
+ }
+} | Java | ๋ฉ์๋๋ช
์ ์ ๋ง ์ ์ง์ผ์ ๊ฑฐ ๊ฐ์์! ๐ |
@@ -0,0 +1,48 @@
+package christmas.domain.entity;
+
+import christmas.domain.util.Util;
+
+import java.util.Arrays;
+
+import static christmas.system.IOMessage.EMPTY_STRING;
+import static christmas.system.IOMessage.QUANTITY_UNIT;
+
+public enum BonusMenu {
+ CHAMPAGNE(Menu.CHAMPAGNE, 1);
+
+ private final Menu menu;
+ private final int quantity;
+
+ BonusMenu(Menu menu, int quantity) {
+ this.menu = menu;
+ this.quantity = quantity;
+ }
+
+ public static int calculateTotalPriceForAllMenus() {
+ return Arrays.stream(BonusMenu.values())
+ .mapToInt(BonusMenu::getTotalPrice)
+ .sum();
+ }
+
+ public static String generateAllMenuDetails() {
+ StringBuilder stringBuilder = new StringBuilder();
+ for (BonusMenu bonusMenu : BonusMenu.values()) {
+ stringBuilder.append(bonusMenu.toString()).append(System.lineSeparator());
+ }
+ return stringBuilder.toString();
+ }
+
+ @Override
+ public String toString() {
+ return getName() + EMPTY_STRING + Util.createFormattedAmount(quantity) + QUANTITY_UNIT;
+ }
+
+ private String getName() {
+ return menu.getMenuName();
+ }
+
+ private int getTotalPrice() {
+ return menu.getMenuPrice() * quantity;
+ }
+
+} | Java | ์ฒ์์๋ ๊ทธ๋ฐ ๋ฐฉ์์ผ๋ก ํ์๋๋ฐ,
๊ฐ ํด๋์ค์์, ํด๋์ค์ ๋ํด ์ถ๋ ฅํ ์ ๋ณด๋ฅผ ๋ง๋๋๊ฑฐ๊น์ง๋ ๊ฐ์ฒด๊ฐ ๋ด๋นํด์ผํ ๋ชซ์ด์ง ์์๊น ํด์ ๋ฐ๊ฟจ์์ด์...
์ถ๋ ฅ์ outputview์์ ํฉ๋๋ค. ์ด ๋ถ๋ถ์ ๋ค๋ฅธ๋ถ๋ถ์ ์๊ฒฌ๋ ๋ฃ๊ณ ์ถ์ด์!!
1. outputview์์ getter๊ฐ ์๋๋๋ผ๋, ์ธ์๋ฅผ ํตํด ์ถ๋ ฅํ ํด๋์ค์ ์ ๋ณด๋ฅผ ๊บผ๋ด์ ์ถ๋ ฅ ๋ฉ์์ง๋ฅผ ๋ง๋ค๊ณ ์ถ๋ ฅ๊น์ง ํ๋๊ฑธ ๋ด๋นํด์ผํ ๊น?
2. ์ถ๋ ฅํด์ผํ ํด๋์ค์ ์ ๋ณด๋ ํด๋์ค ๋ด์์ ๋ง๋ค๊ณ , ์ถ๋ ฅ๋ง outputview์์ ํด์ผํ๋๊ฒ ๋ง์๊น์? |
@@ -0,0 +1,12 @@
+package christmas.domain.util;
+
+
+import java.text.DecimalFormat;
+
+public final class Util {
+ public static String createFormattedAmount(int target) {
+ DecimalFormat formatter = new DecimalFormat("###,##0");
+ return formatter.format(target);
+ }
+
+} | Java | ์ฐธ๊ณ ํ๊ฒ ์ต๋๋ค. ๋๋ฌด๋๋ฌด ํผ๋๋ฐฑ ์ด์ฌํ ํด์ฃผ์
์ ๊ฐ์ฌํด์ ์์ฌ๋ ๐ |
@@ -0,0 +1,76 @@
+package christmas.domain.entity;
+
+import static christmas.domain.verifier.VisitDateVerifier.VISIT_DATE_VERIFIER;
+import static christmas.system.Constant.CHRISTMAS;
+import static christmas.system.Constant.FIRST_DAY_OF_MONTH;
+
+public class Day {
+
+ private static final int WEEK_LENGTH = 7;
+ private final int day;
+
+ public Day(int day) {
+ VISIT_DATE_VERIFIER.validateInputInDomain(day);
+ this.day = day;
+ }
+
+ public int getDay() {
+ return day;
+ }
+
+ public boolean isChristmasSeason() {
+ if (day >= FIRST_DAY_OF_MONTH && day <= CHRISTMAS) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isWeekday() {
+ if (!(isFriday() || isSaturday())) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isWeekend() {
+ if (isFriday() || isSaturday()) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isSpecialDay() {
+ if (isSunday() || isChristmas()) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isFriday() {
+ if (day % WEEK_LENGTH == 1) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isSaturday() {
+ if (day % WEEK_LENGTH == 2) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isSunday() {
+ if (day % WEEK_LENGTH == 3) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isChristmas() {
+ if (day == CHRISTMAS) {
+ return true;
+ }
+ return false;
+ }
+} | Java | ๊ฐ์ธ์ ์ธ ์๊ฒฌ์ธ๋ฐ, `isFriday() || isSaturday()`๊ฐ `isWeekend()`๋ฉ์๋์ ๋๊ฐ์ผ๋, ์ด๊ฑธ ํ์ฉํ๋๊ฒ ์ด๋จ๊น์?
```java
public boolean isWeekday() {
return !isWeekend();
}
```
์ด๋ ๊ฒ์! ๐ |
@@ -0,0 +1,59 @@
+package christmas.domain.entity;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static christmas.domain.entity.MenuType.*;
+
+public enum Menu {
+
+ MUSHROOM_SOUP("์์ก์ด์ํ", 6_000, APPETIZER),
+ TAPAS("ํํ์ค", 5_500, APPETIZER),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000, APPETIZER),
+
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55_000, MAIN),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", 54_000, MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35_000, MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000, MAIN),
+
+ CHOCOLATE_CAKE("์ด์ฝ์ผ์ดํฌ", 15_000, DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5_000, DESSERT),
+
+ ZERO_COLA("์ ๋ก์ฝ๋ผ", 3_000, BEVERAGE),
+ RED_WINE("๋ ๋์์ธ", 60_000, BEVERAGE),
+ CHAMPAGNE("์ดํ์ธ", 25_000, BEVERAGE);
+
+ private static final Map<String, Menu> MENU_MAP = new HashMap<>();
+ private final String menuName;
+ private final int price;
+ private final MenuType menuType;
+
+ Menu(String menuName, int price, MenuType menuType) {
+ this.menuName = menuName;
+ this.price = price;
+ this.menuType = menuType;
+ }
+
+ static {
+ for (Menu menu : Menu.values()) {
+ MENU_MAP.put(menu.menuName, menu);
+ }
+ }
+
+ public static Menu getMenuItemByName(String menuName) {
+ return MENU_MAP.get(menuName);
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getMenuPrice() {
+ return price;
+ }
+
+ public MenuType getMenuType() {
+ return menuType;
+ }
+
+} | Java | ๋ฐ๋ก `HashMap`์ ๋ง๋ค์ด ๋ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค! `getMenuItemByName`๋ฉ์๋์์ ๊ฒ์์๋๋ฅผ ๋์ด๊ธฐ ์ํจ์ธ๊ฐ์? |
@@ -0,0 +1,12 @@
+package christmas.domain.util;
+
+
+import java.text.DecimalFormat;
+
+public final class Util {
+ public static String createFormattedAmount(int target) {
+ DecimalFormat formatter = new DecimalFormat("###,##0");
+ return formatter.format(target);
+ }
+
+} | Java | split์ ํ ๊ฒฐ๊ณผ๊ฐ ์ฌ์ด์ฆ๊ฐ 1์ด์ด์ `orderItemSpec[1]`์ ์ ๊ทผ์ด `IndexOutOfBoundsException`์ ์ผ์ผํฌ ๊ฒฝ์ฐ๋ ์๋์? ์ด๋ฅผ ์ผ๋ํด๋์
จ๋๋ฉด ์ด๋ป๊ฒ ๊ฒ์ฆ์ ํ์
จ๋์ง ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,96 @@
+package christmas.domain.verifier;
+
+
+import christmas.domain.entity.Menu;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static christmas.system.ExceptionMessage.*;
+
+public class OrderMenuVerifier implements Verifier<String> {
+
+ public static final OrderMenuVerifier ORDER_MENU_VERIFIER = new OrderMenuVerifier();
+
+ private final Pattern pattern;
+
+ private OrderMenuVerifier() {
+ this.pattern = Pattern.compile("[๊ฐ-ํฃ]+-\\d+(,[๊ฐ-ํฃ]+-\\d+)*");
+ }
+
+ @Override
+ public void validate(final String input) {
+ validateMenuFormat(input);
+ }
+
+ public void validateInputInDomain(final String input) {
+ validateMenuExistence(input);
+ validateDistinctMenu(input);
+ validateMenuQuantity(input);
+ }
+
+ private void validateMenuFormat(final String input) {
+ String[] orders = input.split(",");
+ for (String order : orders) {
+ validateOrderFormat(order);
+ }
+ }
+
+ private void validateMenuExistence(final String input) {
+ String[] orders = input.split(",");
+ for (String order : orders) {
+ validateOrderExistence(order);
+ }
+ }
+
+ private void validateDistinctMenu(final String input) {
+ Set<String> uniqueMenuItems = new HashSet<>();
+ String[] orders = input.split(",");
+ for (String order : orders) {
+ validateDistinctMenu(order, uniqueMenuItems);
+ }
+ }
+
+ private void validateMenuQuantity(final String input) {
+ String[] orders = input.split(",");
+ for (String order : orders) {
+ validateOrderQuantity(order);
+ }
+ }
+
+ private void validateOrderFormat(final String order) {
+ Matcher matcher = pattern.matcher(order);
+ if (!matcher.matches()) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private void validateOrderExistence(final String order) {
+ String[] orderInfo = order.split("-");
+ if (Menu.getMenuItemByName(orderInfo[0]) == null) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private void validateDistinctMenu(final String order, Set<String> uniqueMenuItems) {
+ String[] orderInfo = order.split("-");
+ if (!uniqueMenuItems.add(orderInfo[0])) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private void validateOrderQuantity(final String order) {
+ String[] orderInfo = order.split("-");
+ try {
+ int quantity = Integer.parseInt(orderInfo[1]);
+ if (quantity < 1) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ } catch (NumberFormatException e) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+
+} | Java | ๋ฐ๋ก ์ธ์์ ๋ฐ๋ผ์ ํจํด์ด ๋ฌ๋ผ์ง๋ ๊ฒ ๊ฐ์ง ์์๋ฐ, ํ๋์์ ๋ฐ๋ก ์ด๊ธฐํํ์ง ์๊ณ , ์์ฑ์ ๋ด๋ถ์์ ์ด๊ธฐํํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค! ๋ญ๊ฐ ๋ ์ข์ ๋ฐฉ๋ฒ์ธ์ง ์ ๋ ์ ๋ชจ๋ฅด๊ฒ ์ด์.. ๐ |
@@ -0,0 +1,14 @@
+package christmas.domain.verifier;
+
+public interface Verifier<T> {
+
+ abstract public void validate(T input);
+
+ static void throwIllegalArgumentError(String errorMessage) {
+ throw new IllegalArgumentException(errorMessage);
+ }
+
+ static void throwIllegalStateError(String errorMessage) {
+ throw new IllegalStateException(errorMessage);
+ }
+} | Java | ์ด ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ ํด๋์ค๋ค์ `check`๋ง ์ฌ์ฉํ๋ฉด ํ์ํ ๊ฒ์ฆ์ด ๋ค ๋๋ ๋ฐฉ์์ด๋ค์! ๊น๋ํ๊ณ ์ข๋ค์! ๐ |
@@ -0,0 +1,59 @@
+package christmas.domain.entity;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static christmas.domain.entity.MenuType.*;
+
+public enum Menu {
+
+ MUSHROOM_SOUP("์์ก์ด์ํ", 6_000, APPETIZER),
+ TAPAS("ํํ์ค", 5_500, APPETIZER),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000, APPETIZER),
+
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55_000, MAIN),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", 54_000, MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35_000, MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000, MAIN),
+
+ CHOCOLATE_CAKE("์ด์ฝ์ผ์ดํฌ", 15_000, DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5_000, DESSERT),
+
+ ZERO_COLA("์ ๋ก์ฝ๋ผ", 3_000, BEVERAGE),
+ RED_WINE("๋ ๋์์ธ", 60_000, BEVERAGE),
+ CHAMPAGNE("์ดํ์ธ", 25_000, BEVERAGE);
+
+ private static final Map<String, Menu> MENU_MAP = new HashMap<>();
+ private final String menuName;
+ private final int price;
+ private final MenuType menuType;
+
+ Menu(String menuName, int price, MenuType menuType) {
+ this.menuName = menuName;
+ this.price = price;
+ this.menuType = menuType;
+ }
+
+ static {
+ for (Menu menu : Menu.values()) {
+ MENU_MAP.put(menu.menuName, menu);
+ }
+ }
+
+ public static Menu getMenuItemByName(String menuName) {
+ return MENU_MAP.get(menuName);
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getMenuPrice() {
+ return price;
+ }
+
+ public MenuType getMenuType() {
+ return menuType;
+ }
+
+} | Java | ๋ค ๋ง์์! HashMap์ ์ฌ์ฉํ๋ฉด ๊ฒ์์๋๊ฐ O(1)์ ๊ฐ๊น์ด ์๋๋ก ๋งค์ฐ ํฅ์๋๋ค๊ณ ํฉ๋๋ค.!! |
@@ -0,0 +1,96 @@
+package christmas.domain.verifier;
+
+
+import christmas.domain.entity.Menu;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static christmas.system.ExceptionMessage.*;
+
+public class OrderMenuVerifier implements Verifier<String> {
+
+ public static final OrderMenuVerifier ORDER_MENU_VERIFIER = new OrderMenuVerifier();
+
+ private final Pattern pattern;
+
+ private OrderMenuVerifier() {
+ this.pattern = Pattern.compile("[๊ฐ-ํฃ]+-\\d+(,[๊ฐ-ํฃ]+-\\d+)*");
+ }
+
+ @Override
+ public void validate(final String input) {
+ validateMenuFormat(input);
+ }
+
+ public void validateInputInDomain(final String input) {
+ validateMenuExistence(input);
+ validateDistinctMenu(input);
+ validateMenuQuantity(input);
+ }
+
+ private void validateMenuFormat(final String input) {
+ String[] orders = input.split(",");
+ for (String order : orders) {
+ validateOrderFormat(order);
+ }
+ }
+
+ private void validateMenuExistence(final String input) {
+ String[] orders = input.split(",");
+ for (String order : orders) {
+ validateOrderExistence(order);
+ }
+ }
+
+ private void validateDistinctMenu(final String input) {
+ Set<String> uniqueMenuItems = new HashSet<>();
+ String[] orders = input.split(",");
+ for (String order : orders) {
+ validateDistinctMenu(order, uniqueMenuItems);
+ }
+ }
+
+ private void validateMenuQuantity(final String input) {
+ String[] orders = input.split(",");
+ for (String order : orders) {
+ validateOrderQuantity(order);
+ }
+ }
+
+ private void validateOrderFormat(final String order) {
+ Matcher matcher = pattern.matcher(order);
+ if (!matcher.matches()) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private void validateOrderExistence(final String order) {
+ String[] orderInfo = order.split("-");
+ if (Menu.getMenuItemByName(orderInfo[0]) == null) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private void validateDistinctMenu(final String order, Set<String> uniqueMenuItems) {
+ String[] orderInfo = order.split("-");
+ if (!uniqueMenuItems.add(orderInfo[0])) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private void validateOrderQuantity(final String order) {
+ String[] orderInfo = order.split("-");
+ try {
+ int quantity = Integer.parseInt(orderInfo[1]);
+ if (quantity < 1) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ } catch (NumberFormatException e) {
+ Verifier.throwIllegalArgumentError(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+
+} | Java | ์ ๋ ๋ญ๊ฐ ๋ ์ข์ ๋ฐฉ๋ฒ์ธ์ง ๋ชฐ๋ผ์ ์ฐพ์๋ดค์๋๋ฐ,
์์ฑ์์์ ์ด๊ธฐํ๋ฅผ ํ๋ฉด, ์์ฑ์ ์์ ํจ์์ ๋ํ ์์ธ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํด์ง๊ณ , ์ธ๋ถ์์ ๋ค๋ฅธ pattern๊ฐ์ฒด๋ฅผ ์ฃผ์
ํ๊ธฐ๊ฐ ์ฌ์์ง๋ค๊ณ ํ๋๋ผ๊ตฌ์.
๋ฐ๋ฉด์ ํ๋์์ ์ด๊ธฐํํ๋ฉด ๊ฐ๋
์ฑ๊ณผ ๊ฐ๊ฒฐํจ์ด ์ฅ์ ์ด์ฃ .
์์ฑ์์์์ ์์ธ์ฒ๋ฆฌ ๋ก์ง์ด ์์ง๋ง ์ด๋ ๊ฒ๋ ํ๋ฒ ํด๋ดค์ด์! ์ํฉ์ ๋ฐ๋ผ์ ๋ค๋ฅด๊ฒ ํด๋ณด๋ฉด ์ข์๊ฑฐ ๊ฐ์์!! |
@@ -0,0 +1,14 @@
+package christmas.domain.verifier;
+
+public interface Verifier<T> {
+
+ abstract public void validate(T input);
+
+ static void throwIllegalArgumentError(String errorMessage) {
+ throw new IllegalArgumentException(errorMessage);
+ }
+
+ static void throwIllegalStateError(String errorMessage) {
+ throw new IllegalStateException(errorMessage);
+ }
+} | Java | ํผ๋๋ฐฑ ์ ๋ง ๊ฐ์ฌํด์! ์ธ์
๋๋ ํฌ๋ฆฌ์ค๋ง์ค ์ฝ๋ ๋ฆฌ๋ทฐ ํด๋๋ฆด๋ ค๊ณ ํ๋๋ฐ repository๊ฐ private์ธ๊ฐ๋ด์๐ |
@@ -0,0 +1,76 @@
+package christmas.domain.entity;
+
+import static christmas.domain.verifier.VisitDateVerifier.VISIT_DATE_VERIFIER;
+import static christmas.system.Constant.CHRISTMAS;
+import static christmas.system.Constant.FIRST_DAY_OF_MONTH;
+
+public class Day {
+
+ private static final int WEEK_LENGTH = 7;
+ private final int day;
+
+ public Day(int day) {
+ VISIT_DATE_VERIFIER.validateInputInDomain(day);
+ this.day = day;
+ }
+
+ public int getDay() {
+ return day;
+ }
+
+ public boolean isChristmasSeason() {
+ if (day >= FIRST_DAY_OF_MONTH && day <= CHRISTMAS) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isWeekday() {
+ if (!(isFriday() || isSaturday())) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isWeekend() {
+ if (isFriday() || isSaturday()) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isSpecialDay() {
+ if (isSunday() || isChristmas()) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isFriday() {
+ if (day % WEEK_LENGTH == 1) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isSaturday() {
+ if (day % WEEK_LENGTH == 2) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isSunday() {
+ if (day % WEEK_LENGTH == 3) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isChristmas() {
+ if (day == CHRISTMAS) {
+ return true;
+ }
+ return false;
+ }
+} | Java | ์ค... ๊ฐ์ฌํฉ๋๋ค.! ๋ฆฌํํ ๋ง ํด๋ณผ๊ฒ์ |
@@ -0,0 +1,12 @@
+package christmas.domain.util;
+
+
+import java.text.DecimalFormat;
+
+public final class Util {
+ public static String createFormattedAmount(int target) {
+ DecimalFormat formatter = new DecimalFormat("###,##0");
+ return formatter.format(target);
+ }
+
+} | Java | ์๋ฅผ๋ค์ด,
Input: ์ดํ์ธ-
์ด๋ ๊ฒ ์
๋ ฅ๋ ๊ฒฝ์ฐ, orderMenuVerifier์ checkMenuFormat ๋ฉ์๋์ ์ํด ์ฌ๋ฐ๋ฅธ ๋ฉ๋ด ํ์์ด ์๋ ์์ธ์ฒ๋ฆฌ๊ฐ ๋์ด์ ธ๋ฒ๋ ค
์์ Util๋ฉ์๋๋ฅผ ํธ์ถํ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ก ๊ตฌํํ์ต๋๋ค.
<img width="474" alt="image" src="https://github.com/Hoo-sung/java-christmas-6-Hoo-sung/assets/121723421/e2a0a147-e665-4a6a-94ce-3876632e0d0b">
์ด๋ ๊ฒ orderMenuVerifier๋ก ๊ฒ์ฆ์ ๋ง์น๊ณ Util class๋ฅผ ์ด์ฉํด์ order๊ฐ์ฒด๋ฅผ ๋ฐํํ๋๋ก ํ์ต๋๋ค. |
@@ -0,0 +1,54 @@
+const generateBasicToken = (userId: string, userPassword: string): string => {
+ const token = btoa(`${userId}:${userPassword}`);
+ return `Basic ${token}`;
+};
+
+const API_URL = `${import.meta.env.VITE_API_URL}`;
+const USER_ID = `${import.meta.env.VITE_USER_ID}`;
+const USER_PASSWORD = `${import.meta.env.VITE_USER_PASSWORD}`;
+
+try {
+ if (!API_URL || !USER_ID || !USER_PASSWORD) {
+ throw new Error(
+ "API_URL, USER_ID, PASSWORD environment variables are not set",
+ );
+ }
+} catch (error) {
+ console.log(error);
+}
+
+type HttpMethod = "GET" | "POST" | "PATCH" | "DELETE";
+
+interface RequestOptions {
+ method: HttpMethod;
+ body?: Record<string, unknown>;
+}
+
+export const fetchWithAuth = async (path: string, options: RequestOptions) => {
+ const requestInit = requestBuilder(options);
+ const response = await fetch(path, requestInit);
+
+ try {
+ if (!response.ok) {
+ throw new Error(`Failed to ${options.method} ${path}`);
+ }
+ } catch (error) {
+ console.log(error);
+ }
+
+ return response;
+};
+
+const requestBuilder = ({ method, body }: RequestOptions): RequestInit => {
+ const token = generateBasicToken(USER_ID, USER_PASSWORD);
+ const headers: HeadersInit = {
+ "Content-Type": "application/json",
+ Authorization: token,
+ };
+
+ return {
+ method,
+ headers,
+ body: body ? JSON.stringify(body) : undefined,
+ };
+}; | TypeScript | ```
const API_URL = `${import.meta.env.VITE_API_URL}`;
const USER_ID = `${import.meta.env.VITE_USER_ID}`;
const USER_PASSWORD = `${import.meta.env.VITE_USER_PASSWORD}`;
```
์ด ๋ถ๋ถ์ ์์ ํ์ผ์์ ๋ฐ๋ก ๊ด๋ฆฌํด๋ณด๋ ๊ฒ์ ์ด๋จ๊น์?
`API_URL `์ด ์์ด๋ endPoint, fetchWithAuth์์ ๋ ๋ฒ ์ ์ธ๋๋ค์ |
@@ -0,0 +1,123 @@
+import { RULE } from "@constants/rules";
+import {
+ CART_ITEMS_COUNTS_ENDPOINT,
+ CART_ITEMS_ENDPOINT,
+ PRODUCTS_ENDPOINT,
+} from "./endpoints";
+import { fetchWithAuth } from "./fetchWithAuth";
+
+/**
+ * @example
+ * const params: QueryParams = {
+ * category: 'fashion',
+ * page: 1,
+ * size: 20,
+ * sort: ['price', 'asc']
+ * }
+ */
+interface QueryParams {
+ [key: string]:
+ | undefined
+ | string
+ | number
+ | boolean
+ | (string | number | boolean)[];
+}
+
+export interface GetProductsParams {
+ category?: Category;
+ page?: number;
+ size?: number;
+ sort?: Sort;
+}
+
+const createQueryString = (params: QueryParams) => {
+ return Object.entries(params)
+ .filter(([, value]) => value !== undefined)
+ .map(([key, value]) => {
+ if (Array.isArray(value)) {
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value.join(","))}`;
+ }
+ return `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`;
+ })
+ .join("&");
+};
+
+export const getProducts = async ({
+ category,
+ page = 0,
+ size = 20,
+ sort = "asc",
+}: GetProductsParams = {}): Promise<Product[]> => {
+ const params = {
+ category,
+ page,
+ size,
+ sort: ["price", sort],
+ };
+ const queryString = createQueryString(params) + RULE.sortQueryByIdAsc;
+
+ const response = await fetchWithAuth(`${PRODUCTS_ENDPOINT}?${queryString}`, {
+ method: "GET",
+ });
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new Error("Failed to get products item");
+ }
+
+ return data.content;
+};
+
+export const postProductInCart = async (
+ productId: number,
+ quantity: number = 1,
+) => {
+ const response = await fetchWithAuth(CART_ITEMS_ENDPOINT, {
+ method: "POST",
+ body: {
+ productId,
+ quantity,
+ },
+ });
+
+ if (!response.ok) {
+ throw new Error("Failed to post product item in cart");
+ }
+};
+
+export const deleteProductInCart = async (cartId: number) => {
+ const response = await fetchWithAuth(`${CART_ITEMS_ENDPOINT}/${cartId}`, {
+ method: "DELETE",
+ });
+
+ if (!response.ok) {
+ throw new Error("Failed to delete product item in cart");
+ }
+};
+
+export const getCartItemsCount = async (): Promise<number> => {
+ const response = await fetchWithAuth(CART_ITEMS_COUNTS_ENDPOINT, {
+ method: "GET",
+ });
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new Error("Failed to get cart items count");
+ }
+
+ return data;
+};
+
+export const getCartItems = async (): Promise<CartItem[]> => {
+ const response = await fetchWithAuth(CART_ITEMS_ENDPOINT, {
+ method: "GET",
+ });
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new Error("Failed to get cart items count");
+ }
+
+ return data.content;
+}; | TypeScript | ์์ฒญํด์ผํ๋ api ๊ฐ ๋ง์์ง๋ค๋ฉด, api/index.ts ์ฝ๋๊ฐ ๋ง์์ง๊ฒ ๋ค์.
๊ด๋ จ์๋ api ์์ฒญ ๋ผ๋ฆฌ ๋ฌถ์ด์ ํ์ผ๋ก ๊ด๋ฆฌํ๊ณ , index.ts์์ ํด๋น ํ์ผ๋ค์ api ์์ฒญ ๋ฉ์๋๋ฅผ export ํ๋ ๊ฒ์ ์ด๋จ๊น์?
```dash
api
ใด cart
ใด products
ใด index
``` |
@@ -0,0 +1,61 @@
+import { forwardRef, useContext } from "react";
+import * as PI from "./ProductItem.style";
+import CartControlButton from "../../Button/CartControlButton";
+import { deleteProductInCart, postProductInCart } from "@api/index";
+import { useError } from "@hooks/index";
+import { CartItemsContext } from "@context/CartItemsContext";
+
+interface ProductProps {
+ product: Product;
+}
+
+const ProductItem = forwardRef<HTMLDivElement, ProductProps>(
+ ({ product }, ref) => {
+ const { cartItems, refreshCartItems } = useContext(CartItemsContext);
+
+ const cartItemIds = cartItems.map((item) => item.product.id);
+ const isInCart = cartItemIds.includes(product.id);
+
+ const { showError } = useError();
+
+ const handleIsInCart = async () => {
+ try {
+ if (!isInCart) {
+ await postProductInCart(product.id);
+ refreshCartItems();
+ return;
+ }
+
+ const filteredItem = cartItems.find(
+ (item) => item.product.id === product.id,
+ );
+ if (filteredItem) {
+ await deleteProductInCart(filteredItem.id);
+ refreshCartItems();
+ }
+ } catch (error) {
+ if (error instanceof Error) {
+ showError(error.message);
+ }
+ }
+ };
+
+ return (
+ <PI.ProductItemStyle ref={ref}>
+ <PI.ProductImg
+ src={`${product.imageUrl}`}
+ alt={`${product.name} ์ํ ์ด๋ฏธ์ง`}
+ />
+ <PI.ProductGroup>
+ <PI.ProductContent>
+ <PI.ProductName>{product.name}</PI.ProductName>
+ <span>{product.price.toLocaleString("ko-kr")}์</span>
+ </PI.ProductContent>
+ <CartControlButton onClick={handleIsInCart} isInCart={isInCart} />
+ </PI.ProductGroup>
+ </PI.ProductItemStyle>
+ );
+ },
+);
+
+export default ProductItem; | Unknown | ์ฅ๋ฐ๊ตฌ๋์ ๋ด๋ ๋ก์ง๊ณผ ๋นผ๋ ๋ก์ง์ ํจ์๋ก ๋ถ๋ฆฌํ๊ณ ,
if else๋์ early return ์ ์ฌ์ฉํด๋ณด๋ ๊ฒ์ ์ด๋จ๊น์? |
@@ -0,0 +1,61 @@
+import { forwardRef, useContext } from "react";
+import * as PI from "./ProductItem.style";
+import CartControlButton from "../../Button/CartControlButton";
+import { deleteProductInCart, postProductInCart } from "@api/index";
+import { useError } from "@hooks/index";
+import { CartItemsContext } from "@context/CartItemsContext";
+
+interface ProductProps {
+ product: Product;
+}
+
+const ProductItem = forwardRef<HTMLDivElement, ProductProps>(
+ ({ product }, ref) => {
+ const { cartItems, refreshCartItems } = useContext(CartItemsContext);
+
+ const cartItemIds = cartItems.map((item) => item.product.id);
+ const isInCart = cartItemIds.includes(product.id);
+
+ const { showError } = useError();
+
+ const handleIsInCart = async () => {
+ try {
+ if (!isInCart) {
+ await postProductInCart(product.id);
+ refreshCartItems();
+ return;
+ }
+
+ const filteredItem = cartItems.find(
+ (item) => item.product.id === product.id,
+ );
+ if (filteredItem) {
+ await deleteProductInCart(filteredItem.id);
+ refreshCartItems();
+ }
+ } catch (error) {
+ if (error instanceof Error) {
+ showError(error.message);
+ }
+ }
+ };
+
+ return (
+ <PI.ProductItemStyle ref={ref}>
+ <PI.ProductImg
+ src={`${product.imageUrl}`}
+ alt={`${product.name} ์ํ ์ด๋ฏธ์ง`}
+ />
+ <PI.ProductGroup>
+ <PI.ProductContent>
+ <PI.ProductName>{product.name}</PI.ProductName>
+ <span>{product.price.toLocaleString("ko-kr")}์</span>
+ </PI.ProductContent>
+ <CartControlButton onClick={handleIsInCart} isInCart={isInCart} />
+ </PI.ProductGroup>
+ </PI.ProductItemStyle>
+ );
+ },
+);
+
+export default ProductItem; | Unknown | alt์ ๋ํด์ ์ ๋ฒ ๋ฏธ์
์์ ํ๋ฃจ์๊ฒ ๋ฐ์ ํผ๋๋ฐฑ์ ๊ณต์ ํ ๊ฒ์.
image์ alt๋ 'ํฐ ์ด๋ํ์ ๊ฒ์์ ์ค์ด ํ๋ ๋ค์ด๊ฐ ์๋๋ค์ค ์ด๋ํ'์ฒ๋ผ ํด๋น ์ด๋ฏธ์ง์ ๋ํ ๊ตฌ์ฒด์ ์ธ ์ค๋ช
์ด ๋ค์ด๊ฐ์ผํด์.
ํ์ง๋ง ํ์ฌ ์๋ฒ์์ ์ฃผ๋ ์์ธํ ์ํ ์ค๋ช
์ด ์๋ ์ํฉ์์๋`alt=''"`๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๋ค๊ณ ํ๋ค์.
alt๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒ๊ณผ alt์ ๋น๋ฌธ์์ด๋ก ๋๋ ๊ฒ์ ์ฐจ์ด๋ฅผ ๊ณต๋ถํด๋ณธ๋ค๋ฉด, ์ํ์๊ฒ ๋์์ด ๋ ๊ฑฐ์์. ๐ |
@@ -0,0 +1,44 @@
+import { FILTER_CATEGORIES, SORT_PRICE } from "@constants/rules";
+import * as PLH from "./ProductListHeader.style";
+
+interface ProductListHeaderProps {
+ handleCategory: (category: Category) => void;
+ handleSort: (sort: Sort) => void;
+}
+
+const ProductListHeader = ({
+ handleCategory,
+ handleSort,
+}: ProductListHeaderProps) => {
+ return (
+ <PLH.Header>
+ <PLH.Title>bpple ์ํ ๋ชฉ๋ก</PLH.Title>
+ <PLH.SelectBoxGroup>
+ <PLH.SelectBox
+ name=""
+ id=""
+ onChange={(e) => handleCategory(e.target.value as Category)}
+ >
+ {Object.entries(FILTER_CATEGORIES).map(([key, value]) => (
+ <option value={key} key={key}>
+ {value}
+ </option>
+ ))}
+ </PLH.SelectBox>
+ <PLH.SelectBox
+ name=""
+ id=""
+ onChange={(e) => handleSort(e.target.value as Sort)}
+ >
+ {Object.entries(SORT_PRICE).map(([key, value]) => (
+ <option value={key} key={key}>
+ {value}
+ </option>
+ ))}
+ </PLH.SelectBox>
+ </PLH.SelectBoxGroup>
+ </PLH.Header>
+ );
+};
+
+export default ProductListHeader; | Unknown | selectbox ๋ ๋ค name,id๋ฅผ ๋น๋ฌธ์์ด๋ก ๋ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,44 @@
+import { FILTER_CATEGORIES, SORT_PRICE } from "@constants/rules";
+import * as PLH from "./ProductListHeader.style";
+
+interface ProductListHeaderProps {
+ handleCategory: (category: Category) => void;
+ handleSort: (sort: Sort) => void;
+}
+
+const ProductListHeader = ({
+ handleCategory,
+ handleSort,
+}: ProductListHeaderProps) => {
+ return (
+ <PLH.Header>
+ <PLH.Title>bpple ์ํ ๋ชฉ๋ก</PLH.Title>
+ <PLH.SelectBoxGroup>
+ <PLH.SelectBox
+ name=""
+ id=""
+ onChange={(e) => handleCategory(e.target.value as Category)}
+ >
+ {Object.entries(FILTER_CATEGORIES).map(([key, value]) => (
+ <option value={key} key={key}>
+ {value}
+ </option>
+ ))}
+ </PLH.SelectBox>
+ <PLH.SelectBox
+ name=""
+ id=""
+ onChange={(e) => handleSort(e.target.value as Sort)}
+ >
+ {Object.entries(SORT_PRICE).map(([key, value]) => (
+ <option value={key} key={key}>
+ {value}
+ </option>
+ ))}
+ </PLH.SelectBox>
+ </PLH.SelectBoxGroup>
+ </PLH.Header>
+ );
+};
+
+export default ProductListHeader; | Unknown | selectbox๋ฅผ ํ๋์ ์ปดํฌ๋ํธ๋ก ๋ถ๋ฆฌํด๋ ์ข์ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,54 @@
+const generateBasicToken = (userId: string, userPassword: string): string => {
+ const token = btoa(`${userId}:${userPassword}`);
+ return `Basic ${token}`;
+};
+
+const API_URL = `${import.meta.env.VITE_API_URL}`;
+const USER_ID = `${import.meta.env.VITE_USER_ID}`;
+const USER_PASSWORD = `${import.meta.env.VITE_USER_PASSWORD}`;
+
+try {
+ if (!API_URL || !USER_ID || !USER_PASSWORD) {
+ throw new Error(
+ "API_URL, USER_ID, PASSWORD environment variables are not set",
+ );
+ }
+} catch (error) {
+ console.log(error);
+}
+
+type HttpMethod = "GET" | "POST" | "PATCH" | "DELETE";
+
+interface RequestOptions {
+ method: HttpMethod;
+ body?: Record<string, unknown>;
+}
+
+export const fetchWithAuth = async (path: string, options: RequestOptions) => {
+ const requestInit = requestBuilder(options);
+ const response = await fetch(path, requestInit);
+
+ try {
+ if (!response.ok) {
+ throw new Error(`Failed to ${options.method} ${path}`);
+ }
+ } catch (error) {
+ console.log(error);
+ }
+
+ return response;
+};
+
+const requestBuilder = ({ method, body }: RequestOptions): RequestInit => {
+ const token = generateBasicToken(USER_ID, USER_PASSWORD);
+ const headers: HeadersInit = {
+ "Content-Type": "application/json",
+ Authorization: token,
+ };
+
+ return {
+ method,
+ headers,
+ body: body ? JSON.stringify(body) : undefined,
+ };
+}; | TypeScript | ์ค, ๋ฐ๋ก ์ ๊ทน ๋ฐ์ ํ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,61 @@
+import { forwardRef, useContext } from "react";
+import * as PI from "./ProductItem.style";
+import CartControlButton from "../../Button/CartControlButton";
+import { deleteProductInCart, postProductInCart } from "@api/index";
+import { useError } from "@hooks/index";
+import { CartItemsContext } from "@context/CartItemsContext";
+
+interface ProductProps {
+ product: Product;
+}
+
+const ProductItem = forwardRef<HTMLDivElement, ProductProps>(
+ ({ product }, ref) => {
+ const { cartItems, refreshCartItems } = useContext(CartItemsContext);
+
+ const cartItemIds = cartItems.map((item) => item.product.id);
+ const isInCart = cartItemIds.includes(product.id);
+
+ const { showError } = useError();
+
+ const handleIsInCart = async () => {
+ try {
+ if (!isInCart) {
+ await postProductInCart(product.id);
+ refreshCartItems();
+ return;
+ }
+
+ const filteredItem = cartItems.find(
+ (item) => item.product.id === product.id,
+ );
+ if (filteredItem) {
+ await deleteProductInCart(filteredItem.id);
+ refreshCartItems();
+ }
+ } catch (error) {
+ if (error instanceof Error) {
+ showError(error.message);
+ }
+ }
+ };
+
+ return (
+ <PI.ProductItemStyle ref={ref}>
+ <PI.ProductImg
+ src={`${product.imageUrl}`}
+ alt={`${product.name} ์ํ ์ด๋ฏธ์ง`}
+ />
+ <PI.ProductGroup>
+ <PI.ProductContent>
+ <PI.ProductName>{product.name}</PI.ProductName>
+ <span>{product.price.toLocaleString("ko-kr")}์</span>
+ </PI.ProductContent>
+ <CartControlButton onClick={handleIsInCart} isInCart={isInCart} />
+ </PI.ProductGroup>
+ </PI.ProductItemStyle>
+ );
+ },
+);
+
+export default ProductItem; | Unknown | ์ง์ง ์ ์ฑ์ด๋ฆฐ ๋ต๋ณ ์ต๊ณ .. |
@@ -0,0 +1,44 @@
+import { FILTER_CATEGORIES, SORT_PRICE } from "@constants/rules";
+import * as PLH from "./ProductListHeader.style";
+
+interface ProductListHeaderProps {
+ handleCategory: (category: Category) => void;
+ handleSort: (sort: Sort) => void;
+}
+
+const ProductListHeader = ({
+ handleCategory,
+ handleSort,
+}: ProductListHeaderProps) => {
+ return (
+ <PLH.Header>
+ <PLH.Title>bpple ์ํ ๋ชฉ๋ก</PLH.Title>
+ <PLH.SelectBoxGroup>
+ <PLH.SelectBox
+ name=""
+ id=""
+ onChange={(e) => handleCategory(e.target.value as Category)}
+ >
+ {Object.entries(FILTER_CATEGORIES).map(([key, value]) => (
+ <option value={key} key={key}>
+ {value}
+ </option>
+ ))}
+ </PLH.SelectBox>
+ <PLH.SelectBox
+ name=""
+ id=""
+ onChange={(e) => handleSort(e.target.value as Sort)}
+ >
+ {Object.entries(SORT_PRICE).map(([key, value]) => (
+ <option value={key} key={key}>
+ {value}
+ </option>
+ ))}
+ </PLH.SelectBox>
+ </PLH.SelectBoxGroup>
+ </PLH.Header>
+ );
+};
+
+export default ProductListHeader; | Unknown | ์.. ๊ทธ๊ฒ์ ๋ฏธ์ฒ ์์ฑํ์ง ๋ชปํ ์ ์ ์ค์.. |
@@ -0,0 +1,44 @@
+import { FILTER_CATEGORIES, SORT_PRICE } from "@constants/rules";
+import * as PLH from "./ProductListHeader.style";
+
+interface ProductListHeaderProps {
+ handleCategory: (category: Category) => void;
+ handleSort: (sort: Sort) => void;
+}
+
+const ProductListHeader = ({
+ handleCategory,
+ handleSort,
+}: ProductListHeaderProps) => {
+ return (
+ <PLH.Header>
+ <PLH.Title>bpple ์ํ ๋ชฉ๋ก</PLH.Title>
+ <PLH.SelectBoxGroup>
+ <PLH.SelectBox
+ name=""
+ id=""
+ onChange={(e) => handleCategory(e.target.value as Category)}
+ >
+ {Object.entries(FILTER_CATEGORIES).map(([key, value]) => (
+ <option value={key} key={key}>
+ {value}
+ </option>
+ ))}
+ </PLH.SelectBox>
+ <PLH.SelectBox
+ name=""
+ id=""
+ onChange={(e) => handleSort(e.target.value as Sort)}
+ >
+ {Object.entries(SORT_PRICE).map(([key, value]) => (
+ <option value={key} key={key}>
+ {value}
+ </option>
+ ))}
+ </PLH.SelectBox>
+ </PLH.SelectBoxGroup>
+ </PLH.Header>
+ );
+};
+
+export default ProductListHeader; | Unknown | ๋ฐ๋ก ๋ถ๋ฆฌํ ๊น ๊ณ ๋ฏผํ์๋๋ฐ, ์๊ฒฌ์ด ๋ค์ด์์ผ๋ ๋ถ๋ฆฌํด๋ณด๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,195 @@
+# https://www.acmicpc.net/problem/9663
+
+# import sys
+# from turtle import width
+# n = int(sys.stdin.readline())
+
+# all_page = [0] * n #์ด
+# a = [False] * n #ํ
+# b = [False] * ((n * 2) - 1) #์ ๋ฐฉํฅ ๋๊ฐ
+# c = [False] * ((n * 2) - 1) #์ญ๋ฐฉํฅ ๋๊ฐ
+
+
+# def queen(n) -> None:
+# first = 0
+# count = 0
+# for i in range(n):
+# print("i=",i)
+# if (not a[i]
+# and not b[first+i]
+# and not c[first-i+(n-1)]
+# ):
+# print("qwe")
+# count += 1
+# if i == n-1:
+# print(count)
+# else:
+# a[i] = True
+# b[i+first] = True
+# c[i-first+(n-1)] = True
+# queen(first+1)
+# a[i] = False
+# b[i+first] = False
+# c[i-first+(n-1)] = False
+# queen(8)
+
+
+# import sys
+# n = int(sys.stdin.readline())
+
+# pos = [0] * n #์ด
+# flag_a = [False] * n #ํ
+# flag_b = [False] * ((n * 2) - 1) #์ ๋ฐฉํฅ ๋๊ฐ
+# flag_c = [False] * ((n * 2) - 1) #์ญ๋ฐฉํฅ ๋๊ฐ
+# sum = [0]
+
+
+# def queen(i) -> None:
+# for j in range(n):
+# if(not flag_a[j]
+# and not flag_b[i+j]
+# and not flag_c[i-j+(n-1)]):
+# pos[i] = j
+# if i == n-1:
+# # for i in range(n):
+# # print(f'{pos[i]:2}', end='')
+# # print()
+# sum[0] += 1
+# else:
+# flag_a[j] = flag_b[i+j] = flag_c[i-j+(n-1)] = True
+# queen(i + 1)
+# flag_a[j] = flag_b[i+j] = flag_c[i-j+(n-1)] = False
+# queen(0)
+# print(sum[0])
+
+# import sys
+# n = int(sys.stdin.readline())
+
+# pos = [0] * n #์ด
+# flag_a = [False] * n #ํ
+# flag_b = [False] * ((n * 2) - 1) #์ ๋ฐฉํฅ ๋๊ฐ
+# flag_c = [False] * ((n * 2) - 1) #์ญ๋ฐฉํฅ ๋๊ฐ
+# sum = [0]
+
+
+# def queen(i) -> None:
+# for j in range(n):
+# if(not flag_a[j]
+# and not flag_b[i+j]
+# and not flag_c[i-j+7]):
+# pos[i] = j
+# if i == 7:
+# # for i in range(8):
+# # print(f'{pos[i]:2}', end='')
+# # print()
+# sum[0] += 1
+# else:
+# flag_a[j] = flag_b[i+j] = flag_c[i-j+7] = True
+# queen(i + 1)
+# flag_a[j] = flag_b[i+j] = flag_c[i-j+7] = False
+# queen(0)
+# print(sum[0])
+
+# https://seongonion.tistory.com/103
+# import sys
+
+# n = int(sys.stdin.readline())
+
+# ans = 0
+# row = [0] * n
+
+# def is_promising(x):
+# for i in range(x):
+# if row[x] == row[i] or abs(row[x] - row[i]) == abs(x - i):
+# return False
+
+# return True
+
+# def n_queens(x):
+# global ans
+# if x == n:
+# ans += 1
+# return
+
+# else:
+# for i in range(n):
+# # [x, i]์ ํธ์ ๋๊ฒ ๋ค.
+# row[x] = i
+# if is_promising(x):
+# n_queens(x+1)
+
+# n_queens(0)
+# print(ans)
+
+# https://velog.io/@inhwa1025/BOJ-9663%EB%B2%88-N-Queen-Python-%ED%8C%8C%EC%9D%B4%EC%8D%AC
+
+# n = int(input())
+# result = 0
+
+
+# # ํธ์ ๋์ ํ ๊ทธ ์ดํ์ ์ค์ ๋ํด์๋ง ๋ถ๊ฐ๋ฅํ ์นธ ์ฒดํฌ
+# def visit(x, y, in_visited):
+# tmp_visited = [visi[:] for visi in in_visited]
+# for i in range(1, n-x):
+# tmp_visited[x+i][y] = True # ์๋ ๋ฐฉํฅ ์ฒดํฌ
+# if 0 <= y-i < n:
+# tmp_visited[x+i][y-i] = True # ์ผ์ชฝ ์๋ ๋๊ฐ์ ์ฒดํฌ
+# if 0 <= y+i < n:
+# tmp_visited[x+i][y+i] = True # ์ค๋ฅธ์ชฝ ์๋ ๋๊ฐ์ ์ฒดํฌ
+# return tmp_visited
+
+
+# def recursion(q, _visited): # q๋ฒ์งธ ์ค์ ํธ์ ๋ ์ ์๋ ๊ฒฝ์ฐ๋ค์ ํ์ธํ๋ ์ฌ๊ทํจ์
+# global result
+# # ํ ์ค์ ํธ์ด ํ๋์ฉ ๋ค์ด๊ฐ์ผ ํจ
+# # ํ ์ค ์ ์ฒด๊ฐ ๋ถ๊ฐ๋ฅํ ๊ฒฝ์ฐ ์์ n๊ฐ์ ํธ์ ๋ชจ๋ ๋์ ์ ์์ผ๋ฏ๋ก ์ฌ๊ท ์ข
๋ฃ
+# for idx in range(q, n):
+# if sum(_visited[idx]) == n:
+# return 0
+# # ๋ง์ง๋ง ์ค์ ๋๋ฌํ ๊ฒฝ์ฐ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ์ฐ๋ฅผ ์ธ๊ณ ์ฌ๊ท ์ข
๋ฃ
+# if q == (n-1):
+# result += n - sum(_visited[q])
+# return 0
+
+# for i in range(n):
+# if not _visited[q][i]: # ํธ์ ๋ ์ ์๋ ๊ฒฝ์ฐ
+# tmp = visit(q, i, _visited) # ํธ์ ๋์ ๋ ๋ถ๊ฐ๋ฅํ ์นธ๋ค ์ฒดํฌ
+# recursion(q+1, tmp) # ๊ทธ ๋ค์ ์ค์ ๋ํด ์ฌ๊ท ํธ์ถ
+# # ์ฌ๊ทํธ์ถ ์ข
๋ฃ ํ ํธ์ ๋ ์ ์๋ ๋ค๋ฅธ ๊ฒฝ์ฐ์ ๋ํด ์ฒดํฌ
+
+
+# visited = [[False for _ in range(n)] for _ in range(n)]
+# recursion(0, visited) # 0๋ฒ์งธ ์ค๋ถํฐ ํ์ ์์
+# print(result)
+
+
+
+#๋ฐ์ฐฌ์ฐ๋์ ์ฝ๋
+
+global cnt
+cnt = 0
+
+def n_queen (col, i) :
+ n = len(col) - 1
+ if (judge(col, i)) :
+ if(i==n) :
+ print(col[1: n+1])
+ else :
+ for j in range(1, n+1) :
+ col[i+1] = j
+ n_queen(col, i+1, cnt)
+
+ print(cnt)
+
+def judge(col, i) :
+ k = 1
+ flag = True
+ while (k < i and flag) :
+ if (col[i] == col[k] or abs(col[i] - col[k]) == (i - k)) :
+ flag = False
+ k += 1
+ return flag
+
+n = 8
+a = [0] * (n+1)
+n_queen(a, 0, 0)
\ No newline at end of file | Python | ์ ๋ ๋จ์ ๊ฑฐ ์ฐธ๊ณ ํ๊ฑฐ๋ผ ๋ถ๋๋ฝ๋ค์ ใ
์ด์ฐจ์ ๋ฐฐ์ด๋ก ํ๋ค๊ฐ 1์ฐจ์๋ฐฐ์ด๋ก ์ค์ผ ์ ์๋ค๋ ๋ฐ์์ด ์ด๋ ค์ ๋ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,23 @@
+# https://www.acmicpc.net/problem/1181
+# https://blockdmask.tistory.com/543
+# set์ ์ด์ฉํ๋ฉด ์ค๋ณต์ด ์ ๊ฑฐ๋จ
+# https://always-challenger-lab.tistory.com/22
+# ๋๋ค ์ด์ฉํด์ ๋ค์ค์กฐ๊ฑด ์ ๋ ฌ
+import sys
+
+n = int(sys.stdin.readline())
+s = []
+m = []
+for i in range(n):
+ s.append(str(sys.stdin.readline().strip()))
+
+
+set_s = list(set(s))
+for j in set_s:
+ m.append([j,len(j)])
+
+print(m)
+m.sort(key=lambda x:(x[1],x[0]))
+
+for i in m:
+ print(i[0])
\ No newline at end of file | Python | ๋๋ค ์ฌ์ฉ์ด ์ ๋ฐํค๋ค์ ใ
.ใ
์ฐธ๊ณ ๊ฐ ๋์ต๋๋ค. |
@@ -1,152 +1,44 @@
package com.example.project.compile.service;
+import com.example.project.compile.domain.CompileLanguage;
import com.example.project.error.dto.ErrorMessage;
-import org.springframework.beans.factory.annotation.Value;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.IOException;
-import java.nio.file.*;
-import java.util.UUID;
+import java.nio.file.Files;
+import java.nio.file.Path;
+@Slf4j
@Service
+@RequiredArgsConstructor
public class CompileService {
- private final String code_dir;
- public CompileService(@Value("${compile.url}") String codeDir) {
- this.code_dir = codeDir;
- }
+ private final FileService fileService;
+ private final CommandExecutorService commandExecutorService;
- public String compileAndRun(String language, String code) throws IOException, InterruptedException {
+ public String compileAndRun(String language, String code, String codeDir) throws IOException {
+ CompileLanguage compileLanguage = CompileLanguage.JAVA.getByLanguageName(language);
+ Path filePath = null;
try {
- Path codePath = Paths.get(code_dir);
- if (!Files.exists(codePath)) {
- Files.createDirectories(codePath);
+ filePath = fileService.createCodeFile(code, compileLanguage, codeDir);
+ return executeCode(filePath);
+ } finally {
+ if (filePath != null) {
+ Files.deleteIfExists(filePath);
}
-
- String filename = generateFileName(language);
- Path filePath = codePath.resolve(filename);
-
- Files.write(filePath, code.getBytes());
-
- return executeCode(language, filePath, codePath);
- } catch (FileAlreadyExistsException e) {
- throw new IOException(ErrorMessage.CODE_DIRECTORY_CREATION_FAILED.getMessage(), e);
- } catch (IOException e) {
- throw new IOException(ErrorMessage.CODE_WRITE_FAILED.getMessage(), e);
}
}
- private String executeCode(String language, Path filePath, Path codePath) throws IOException, InterruptedException {
+ private String executeCode(Path filePath) throws IOException {
+ String result;
try {
- //TODO Enum ์ฌ์ฉํ๊ธฐ
- return switch (language.toLowerCase()) {
- case "c" -> compileAndRun(filePath, "gcc", codePath.resolve("output").toString(), "");
- case "java" -> compileJava(filePath);
- case "python" -> compilePython(filePath);
- default -> throw new IllegalArgumentException(ErrorMessage.UNSUPPORTED_LANGUAGE.getMessage());
- };
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(ErrorMessage.UNSUPPORTED_LANGUAGE.getMessage(), e);
+ String command = filePath.getParent().resolve("output").toString();
+ result = commandExecutorService.runCommand(command);
} catch (IOException | InterruptedException e) {
throw new IOException(ErrorMessage.GENERAL_COMPILE_ERROR.getMessage(), e);
}
- }
-
- private String compileAndRun(Path filePath, String compiler, String outputFileName, String additionalArgs) throws IOException, InterruptedException {
- String command = String.format("%s %s -o %s %s", compiler, filePath, outputFileName, additionalArgs);
- Process compileProcess = Runtime.getRuntime().exec(command);
- compileProcess.waitFor();
-
- if (compileProcess.exitValue() == 0) {
- return runCompiledProgram(outputFileName);
- } else {
- String errorOutput = new String(compileProcess.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.COMPILATION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String runCompiledProgram(String outputFileName) throws IOException, InterruptedException {
- Process runProcess = Runtime.getRuntime().exec(outputFileName);
- runProcess.waitFor();
-
- if (runProcess.exitValue() == 0) {
- return new String(runProcess.getInputStream().readAllBytes());
- } else {
- String errorOutput = new String(runProcess.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.EXECUTION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String compileJava(Path filePath) throws IOException, InterruptedException {
- String className = extractClassName(filePath);
- Path correctFilePath = filePath.getParent().resolve(className + ".java");
-
- try {
- Files.move(filePath, correctFilePath, StandardCopyOption.REPLACE_EXISTING);
- } catch (FileAlreadyExistsException e) {
- throw new IOException(ErrorMessage.JAVA_FILE_RENAMING_FAILED.getMessage(), e);
- }
-
- String command = String.format("javac %s", correctFilePath);
- Process compileProcess = Runtime.getRuntime().exec(command);
- compileProcess.waitFor();
-
- if (compileProcess.exitValue() == 0) {
- return runJavaProgram(correctFilePath);
- } else {
- String errorOutput = new String(compileProcess.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.COMPILATION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String extractClassName(Path filePath) throws IOException {
- try {
- String content = Files.readString(filePath);
- return content.split("public class ")[1].split("\\s")[0].trim();
- } catch (Exception e) {
- throw new IOException(ErrorMessage.JAVA_CLASS_EXTRACTION_FAILED.getMessage(), e);
- }
- }
-
- private String runJavaProgram(Path filePath) throws IOException, InterruptedException {
- String className = filePath.getFileName().toString().replace(".java", "");
- String runCommand = String.format("java -cp %s %s", filePath.getParent(), className);
-
- Process runProcess = Runtime.getRuntime().exec(runCommand);
- runProcess.waitFor();
-
- if (runProcess.exitValue() == 0) {
- return new String(runProcess.getInputStream().readAllBytes());
- } else {
- String errorOutput = new String(runProcess.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.EXECUTION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String compilePython(Path filePath) throws IOException, InterruptedException {
- String command = String.format("python %s", filePath);
- Process process = Runtime.getRuntime().exec(command);
- process.waitFor();
-
- if (process.exitValue() == 0) {
- return new String(process.getInputStream().readAllBytes());
- } else {
- String errorOutput = new String(process.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.EXECUTION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String generateFileName(String language) {
- return UUID.randomUUID() + getExtension(language);
- }
-
- private String getExtension(String language) {
- //TODO ENUM
- return switch (language.toLowerCase()) {
- case "c" -> ".c";
- case "java" -> ".java";
- case "python" -> ".py";
- default -> throw new IllegalArgumentException(ErrorMessage.UNSUPPORTED_LANGUAGE.getMessage());
- };
+ return result;
}
}
\ No newline at end of file | Java | enum์ ์ฌ์ฉํฉ์๋ค |
@@ -1,152 +1,44 @@
package com.example.project.compile.service;
+import com.example.project.compile.domain.CompileLanguage;
import com.example.project.error.dto.ErrorMessage;
-import org.springframework.beans.factory.annotation.Value;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.IOException;
-import java.nio.file.*;
-import java.util.UUID;
+import java.nio.file.Files;
+import java.nio.file.Path;
+@Slf4j
@Service
+@RequiredArgsConstructor
public class CompileService {
- private final String code_dir;
- public CompileService(@Value("${compile.url}") String codeDir) {
- this.code_dir = codeDir;
- }
+ private final FileService fileService;
+ private final CommandExecutorService commandExecutorService;
- public String compileAndRun(String language, String code) throws IOException, InterruptedException {
+ public String compileAndRun(String language, String code, String codeDir) throws IOException {
+ CompileLanguage compileLanguage = CompileLanguage.JAVA.getByLanguageName(language);
+ Path filePath = null;
try {
- Path codePath = Paths.get(code_dir);
- if (!Files.exists(codePath)) {
- Files.createDirectories(codePath);
+ filePath = fileService.createCodeFile(code, compileLanguage, codeDir);
+ return executeCode(filePath);
+ } finally {
+ if (filePath != null) {
+ Files.deleteIfExists(filePath);
}
-
- String filename = generateFileName(language);
- Path filePath = codePath.resolve(filename);
-
- Files.write(filePath, code.getBytes());
-
- return executeCode(language, filePath, codePath);
- } catch (FileAlreadyExistsException e) {
- throw new IOException(ErrorMessage.CODE_DIRECTORY_CREATION_FAILED.getMessage(), e);
- } catch (IOException e) {
- throw new IOException(ErrorMessage.CODE_WRITE_FAILED.getMessage(), e);
}
}
- private String executeCode(String language, Path filePath, Path codePath) throws IOException, InterruptedException {
+ private String executeCode(Path filePath) throws IOException {
+ String result;
try {
- //TODO Enum ์ฌ์ฉํ๊ธฐ
- return switch (language.toLowerCase()) {
- case "c" -> compileAndRun(filePath, "gcc", codePath.resolve("output").toString(), "");
- case "java" -> compileJava(filePath);
- case "python" -> compilePython(filePath);
- default -> throw new IllegalArgumentException(ErrorMessage.UNSUPPORTED_LANGUAGE.getMessage());
- };
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(ErrorMessage.UNSUPPORTED_LANGUAGE.getMessage(), e);
+ String command = filePath.getParent().resolve("output").toString();
+ result = commandExecutorService.runCommand(command);
} catch (IOException | InterruptedException e) {
throw new IOException(ErrorMessage.GENERAL_COMPILE_ERROR.getMessage(), e);
}
- }
-
- private String compileAndRun(Path filePath, String compiler, String outputFileName, String additionalArgs) throws IOException, InterruptedException {
- String command = String.format("%s %s -o %s %s", compiler, filePath, outputFileName, additionalArgs);
- Process compileProcess = Runtime.getRuntime().exec(command);
- compileProcess.waitFor();
-
- if (compileProcess.exitValue() == 0) {
- return runCompiledProgram(outputFileName);
- } else {
- String errorOutput = new String(compileProcess.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.COMPILATION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String runCompiledProgram(String outputFileName) throws IOException, InterruptedException {
- Process runProcess = Runtime.getRuntime().exec(outputFileName);
- runProcess.waitFor();
-
- if (runProcess.exitValue() == 0) {
- return new String(runProcess.getInputStream().readAllBytes());
- } else {
- String errorOutput = new String(runProcess.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.EXECUTION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String compileJava(Path filePath) throws IOException, InterruptedException {
- String className = extractClassName(filePath);
- Path correctFilePath = filePath.getParent().resolve(className + ".java");
-
- try {
- Files.move(filePath, correctFilePath, StandardCopyOption.REPLACE_EXISTING);
- } catch (FileAlreadyExistsException e) {
- throw new IOException(ErrorMessage.JAVA_FILE_RENAMING_FAILED.getMessage(), e);
- }
-
- String command = String.format("javac %s", correctFilePath);
- Process compileProcess = Runtime.getRuntime().exec(command);
- compileProcess.waitFor();
-
- if (compileProcess.exitValue() == 0) {
- return runJavaProgram(correctFilePath);
- } else {
- String errorOutput = new String(compileProcess.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.COMPILATION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String extractClassName(Path filePath) throws IOException {
- try {
- String content = Files.readString(filePath);
- return content.split("public class ")[1].split("\\s")[0].trim();
- } catch (Exception e) {
- throw new IOException(ErrorMessage.JAVA_CLASS_EXTRACTION_FAILED.getMessage(), e);
- }
- }
-
- private String runJavaProgram(Path filePath) throws IOException, InterruptedException {
- String className = filePath.getFileName().toString().replace(".java", "");
- String runCommand = String.format("java -cp %s %s", filePath.getParent(), className);
-
- Process runProcess = Runtime.getRuntime().exec(runCommand);
- runProcess.waitFor();
-
- if (runProcess.exitValue() == 0) {
- return new String(runProcess.getInputStream().readAllBytes());
- } else {
- String errorOutput = new String(runProcess.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.EXECUTION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String compilePython(Path filePath) throws IOException, InterruptedException {
- String command = String.format("python %s", filePath);
- Process process = Runtime.getRuntime().exec(command);
- process.waitFor();
-
- if (process.exitValue() == 0) {
- return new String(process.getInputStream().readAllBytes());
- } else {
- String errorOutput = new String(process.getErrorStream().readAllBytes());
- throw new IOException(ErrorMessage.EXECUTION_FAILED.getMessage() + "\n" + errorOutput);
- }
- }
-
- private String generateFileName(String language) {
- return UUID.randomUUID() + getExtension(language);
- }
-
- private String getExtension(String language) {
- //TODO ENUM
- return switch (language.toLowerCase()) {
- case "c" -> ".c";
- case "java" -> ".java";
- case "python" -> ".py";
- default -> throw new IllegalArgumentException(ErrorMessage.UNSUPPORTED_LANGUAGE.getMessage());
- };
+ return result;
}
}
\ No newline at end of file | Java | ํด๋์ค๊ฐ ๋๋ฌด ํฝ๋๋ค. ์ญํ ์ ๋๋ ์ฃผ์ธ์ |
@@ -1,36 +1,40 @@
package com.example.project.compile.controller.rest;
+import com.example.project.auth.service.AuthTokenService;
import com.example.project.common.dto.ResponseDto;
import com.example.project.common.dto.ResponseMessage;
-import com.example.project.solution.dto.request.user.SolutionCompileRequest;
+import com.example.project.common.util.HeaderUtil;
+import com.example.project.compile.dto.CompileRequest;
import com.example.project.compile.service.CompileService;
+import com.example.project.error.dto.ErrorMessage;
+import com.example.project.error.dto.ErrorResponseDto;
+import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
-import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
+@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/compile")
public class CompileApiController {
+
private final CompileService compileService;
+ private final AuthTokenService authTokenService;
@PostMapping
- @PreAuthorize("hasAnyRole('USER', 'ADMIN')")
- public ResponseEntity<?> compileCode(@RequestBody SolutionCompileRequest request) {
- try {
- String result = compileService.compileAndRun(request.getLanguage(), request.getCode());
+ public ResponseEntity<?> compileCode(@RequestBody CompileRequest request, HttpServletRequest httpServletRequest, @Value("${compile.url}") String codeDir) throws IOException {
+ if (authTokenService.isValidateToken(HeaderUtil.resolveToken(httpServletRequest))) {
+ String result = compileService.compileAndRun(
+ request.getLanguage(),
+ request.getCode(),
+ codeDir
+ );
return ResponseDto.toResponseEntity(ResponseMessage.COMPILE_SUCCESS, result);
- } catch (IllegalArgumentException e) {
- return ResponseDto.toResponseEntity(ResponseMessage.INVALID_LANGUAGE, e.getMessage());
- } catch (IOException e) {
- return ResponseDto.toResponseEntity(ResponseMessage.IO_ERROR, e.getMessage());
- } catch (InterruptedException e) {
- return ResponseDto.toResponseEntity(ResponseMessage.EXECUTION_INTERRUPTED, e.getMessage());
- } catch (Exception e) {
- return ResponseDto.toResponseEntity(ResponseMessage.GENERAL_COMPILE_ERROR, e.getMessage());
- }
+ } else return ErrorResponseDto.of(ErrorMessage.NOT_FOUND_CLIENT_ID_HEADER);
}
}
\ No newline at end of file | Java | HttpServletRequest๋ง ๋ฐ์์ค๋ฉด ํ ํฐ ๊ฐ์ ๋ฐ๋ก ๋ฐ์์ค์ง ์์๋ ๋ฉ๋๋ค |
@@ -0,0 +1,37 @@
+package com.example.project.compile.service;
+
+import com.example.project.compile.domain.CompileLanguage;
+import com.example.project.error.dto.ErrorMessage;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.UUID;
+
+@Service
+public class FileService {
+
+ public Path createCodeFile(String code, CompileLanguage compileLanguage, String codeDir) throws IOException {
+ try {
+ Path codePath = Paths.get(codeDir);
+ if (!Files.exists(codePath)) {
+ Files.createDirectories(codePath);
+ }
+
+ //UUID๋ฅผ ์ฌ์ฉํ๋ ์ด์ ๋ ๊ณ ์ ํ ํ์ผ ์ด๋ฆ์ ์์ฑํ์ฌ ํ์ผ์ ์ถฉ๋์ ๋ฐฉ์งํ๊ธฐ ์ํจ์
๋๋ค.
+ String filename = "Main_" + UUID.randomUUID() + compileLanguage.getExtension();
+
+ Path filePath = codePath.resolve(filename);
+ Files.writeString(filePath, code);
+ return filePath;
+
+ } catch (InvalidPathException e) {
+ throw new IOException(ErrorMessage.INVALID_PATH_EXCEPTION.getMessage(), e);
+ } catch (SecurityException e) {
+ throw new IOException(ErrorMessage.ACCESS_PERMISSION_EXCEPTION.getMessage(), e);
+ }
+ }
+}
\ No newline at end of file | Java | yml ์ ์ค์ ํ ๊ฐ์ ์ฌ์ฉํด์ฃผ์ธ์.
๊ทธ๋ฆฌ๊ณ static์ ์ฌ์ฉํ ํ์๋ ์์ด๋ณด์
๋๋ค. |
@@ -1,36 +1,40 @@
package com.example.project.compile.controller.rest;
+import com.example.project.auth.service.AuthTokenService;
import com.example.project.common.dto.ResponseDto;
import com.example.project.common.dto.ResponseMessage;
-import com.example.project.solution.dto.request.user.SolutionCompileRequest;
+import com.example.project.common.util.HeaderUtil;
+import com.example.project.compile.dto.CompileRequest;
import com.example.project.compile.service.CompileService;
+import com.example.project.error.dto.ErrorMessage;
+import com.example.project.error.dto.ErrorResponseDto;
+import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
-import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
+@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/compile")
public class CompileApiController {
+
private final CompileService compileService;
+ private final AuthTokenService authTokenService;
@PostMapping
- @PreAuthorize("hasAnyRole('USER', 'ADMIN')")
- public ResponseEntity<?> compileCode(@RequestBody SolutionCompileRequest request) {
- try {
- String result = compileService.compileAndRun(request.getLanguage(), request.getCode());
+ public ResponseEntity<?> compileCode(@RequestBody CompileRequest request, HttpServletRequest httpServletRequest, @Value("${compile.url}") String codeDir) throws IOException {
+ if (authTokenService.isValidateToken(HeaderUtil.resolveToken(httpServletRequest))) {
+ String result = compileService.compileAndRun(
+ request.getLanguage(),
+ request.getCode(),
+ codeDir
+ );
return ResponseDto.toResponseEntity(ResponseMessage.COMPILE_SUCCESS, result);
- } catch (IllegalArgumentException e) {
- return ResponseDto.toResponseEntity(ResponseMessage.INVALID_LANGUAGE, e.getMessage());
- } catch (IOException e) {
- return ResponseDto.toResponseEntity(ResponseMessage.IO_ERROR, e.getMessage());
- } catch (InterruptedException e) {
- return ResponseDto.toResponseEntity(ResponseMessage.EXECUTION_INTERRUPTED, e.getMessage());
- } catch (Exception e) {
- return ResponseDto.toResponseEntity(ResponseMessage.GENERAL_COMPILE_ERROR, e.getMessage());
- }
+ } else return ErrorResponseDto.of(ErrorMessage.NOT_FOUND_CLIENT_ID_HEADER);
}
}
\ No newline at end of file | Java | ์ปดํ์ผํ๋ ์๋ฒ์์๋ JWT ํ ํฐ์ ๊ฐ์ง๊ณ ์ ํจํ ์ ๊ทผ์ธ์ง ์๋์ง ํ๋จํด์ ์ปดํ์ผํ ์ ์๋๋ก ํด์ฃผ์ธ์ |
@@ -0,0 +1,37 @@
+package com.example.project.compile.service;
+
+import com.example.project.compile.domain.CompileLanguage;
+import com.example.project.error.dto.ErrorMessage;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.UUID;
+
+@Service
+public class FileService {
+
+ public Path createCodeFile(String code, CompileLanguage compileLanguage, String codeDir) throws IOException {
+ try {
+ Path codePath = Paths.get(codeDir);
+ if (!Files.exists(codePath)) {
+ Files.createDirectories(codePath);
+ }
+
+ //UUID๋ฅผ ์ฌ์ฉํ๋ ์ด์ ๋ ๊ณ ์ ํ ํ์ผ ์ด๋ฆ์ ์์ฑํ์ฌ ํ์ผ์ ์ถฉ๋์ ๋ฐฉ์งํ๊ธฐ ์ํจ์
๋๋ค.
+ String filename = "Main_" + UUID.randomUUID() + compileLanguage.getExtension();
+
+ Path filePath = codePath.resolve(filename);
+ Files.writeString(filePath, code);
+ return filePath;
+
+ } catch (InvalidPathException e) {
+ throw new IOException(ErrorMessage.INVALID_PATH_EXCEPTION.getMessage(), e);
+ } catch (SecurityException e) {
+ throw new IOException(ErrorMessage.ACCESS_PERMISSION_EXCEPTION.getMessage(), e);
+ }
+ }
+}
\ No newline at end of file | Java | ๋ณ์๋ช
์ ์นด๋ฉ์ผ์ด์ค๋ฅผ ์ง์ผ์ ์์ฑํด์ฃผ์ธ์ |
@@ -0,0 +1,9 @@
+package com.codesquad.baseballgame.domain.game.controller;
+
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class GameController {
+
+
+} | Java | ์. ์ด๋ฐ ์ปจํธ๋กค๋ฌ๋ ์ฐ์ง ์๋๋ค๋ฉด ๊ทธ๋๊ทธ๋ ์ง์์ฃผ๋ ๊ฒ์ด ์ข๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,24 @@
+package com.codesquad.baseballgame.domain.game.controller;
+
+import com.codesquad.baseballgame.domain.game.service.MatchService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequiredArgsConstructor
+public class MatchController {
+
+ private final MatchService matchService;
+
+ @PostMapping("games/{id}")
+ public ResponseEntity<Boolean> matching(@PathVariable int id) {
+ if (matchService.matchStatus(id)) {
+ return new ResponseEntity<>(true, HttpStatus.OK);
+ }
+ return new ResponseEntity<>(false, HttpStatus.OK);
+ }
+} | Java | ์ค๊ณํ๊ธฐ ๋๋ฆ์ด๊ธด ํ์ง๋ง, `@PathVariable` ๋ง์ ํ๋ผ๋ฏธํฐ๋ก ๋ฐ๋ ์๋ํฌ์ธํธ์์ `POST` ๋ฅผ ์ฐ๋๊ฑด ๋ค์ ์ด์ํด๋ณด์ด๊ธด ํ๋ค์.
๋ญ๊ฐ๊ฐ ๋๋ฝ๋ ๊ฑด ์๋๊ฐ์. ๋ฆฌํด ๋ฐ๋์ `true` `false` ๋ง์ ์ฃ๋ ๊ฒ๋ ์ข ์ด์ํฉ๋๋ค. |
@@ -0,0 +1,7 @@
+package com.codesquad.baseballgame.domain.game.dao;
+
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class GameDao {
+} | Java | ์ ์ฌ๊ธฐ๋ ๋น์ด์๊ตฐ์? |
@@ -0,0 +1,14 @@
+package com.codesquad.baseballgame.domain.game.dto;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+
+@Getter @ToString
+@RequiredArgsConstructor
+public class BallCountDto {
+
+ private int strike;
+ private int ball;
+ private int out;
+} | Java | ์ ๋
ธํ
์ด์
์ ํ ์ค์ ํ๋๋ฅผ ์ฐ๋ ๊ฒ์ ์์น์ผ๋ก ํด ์ฃผ์ธ์.
```suggestion
@Getter
@ToString |
@@ -0,0 +1,14 @@
+package com.codesquad.baseballgame.domain.game.dto;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+
+@Getter @ToString
+@RequiredArgsConstructor
+public class BallCountDto {
+
+ private int strike;
+ private int ball;
+ private int out;
+} | Java | ์์ฑ์๊ฐ ์ํ๋ ๋๋ก ์์ฑ๋์๋์?
์ ๊ฐ ์๊ธฐ๋ก ์ด ์ ๋
ธํ
์ด์
์ `final` ํ๋์ ๋ํด์๋ง ์์ฑ์๋ฅผ ๋ง๋๋๋ฐ์.
์๋ ์ด๋ค ํ๋๋ `final` ์์ฝ์ด๋ฅผ ๊ฐ์ง ์๋ค์. |
@@ -0,0 +1,10 @@
+package com.codesquad.baseballgame.domain.game.service;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class GameService {
+
+
+
+} | Java | ์ ์ด๋ ๊ฒ ๋น์ด์๋ ํด๋์ค๋ค์ด ๋ง์๊ฑฐ์ฃ ... |
@@ -0,0 +1,23 @@
+package com.codesquad.baseballgame.domain.game.service;
+
+import com.codesquad.baseballgame.domain.team.dao.TeamDao;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@RequiredArgsConstructor
+public class MatchService {
+
+ private final TeamDao teamDao;
+
+ @Transactional(isolation = Isolation.SERIALIZABLE)
+ public Boolean matchStatus(int id) {
+ return countMatchUser(id) == 2;
+ }
+
+ public Integer countMatchUser(int id) {
+ return teamDao.countMatchUser(id);
+ }
+} | Java | `SERIALIZABLE` ์ ๋ง ๊ด์ฐฎ์๊น์? ์ ํํ ์ดํดํ๊ณ ์ฌ์ฉํ์ ๊ฑด๊ฐ์.
๋๋ถ๋ถ์ ๊ฒฝ์ฐ `SERIALIZABLE` ๊น์ง ๊ณ ๋ฆฝ์์ผ์ผ ํ ํธ๋์ญ์
์ ์์ต๋๋ค.
์ ํ๋ฆฌ์ผ์ด์
๋ ์ด์ด์์ ์ด๋ฐ ์์ค์ ๊ณ ๋ฆฝ์ด ํ์ํ ๊ฒฝ์ฐ, ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง์ ๋ค์ ๊ฒํ ํด์ ์ ๋ง ์ด์ ๋์ ํธ๋์ญ์
์ด ํ์ํ์ง ์ดํด๋ณด๊ณ ,
์ ๋ง ๊ณ ๋ฆฝ ์์ค ์กฐ์ ์ด ํ์ํ ๊ฒฝ์ฐ์๋, ์ฌ์ค์ ๊ณ ๋ฆฝ ์์ค ์กฐ์ ์ด ์๋๋ผ propagation ์ ๋ต ์์ ์ผ๋ก ๋์ํ ์ ์์ง๋ ์์์ง ๋ค์ ํ ๋ฒ ์๊ฐํด๋ด์ผ ํฉ๋๋ค.
์๋ง ๊ฐฏ์๋ฅผ ์ธ๋ ์ฟผ๋ฆฌ๊ฐ ์๋ค๋ณด๋ ์ฟผ๋ฆฌ๊ฐ ๋๋ ๋์ ์๋ก์ด ์ปค๋ฐ์ด ์ผ์ด๋์ ๊ฒฐ๊ณผ๊ฐ ๋ค๋ฐ๋๋ ์ผ์ ์ฐ๋ คํ์์ง๋ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
๊ทธ๋ฐ ๊ฒฝ์ฐ๋ผ๋ฉด `READ COMMITTED` ๋ก ์ถฉ๋ถํ์ง ์๋์. ์..... |
@@ -0,0 +1,23 @@
+package com.codesquad.baseballgame.domain.game.service;
+
+import com.codesquad.baseballgame.domain.team.dao.TeamDao;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@RequiredArgsConstructor
+public class MatchService {
+
+ private final TeamDao teamDao;
+
+ @Transactional(isolation = Isolation.SERIALIZABLE)
+ public Boolean matchStatus(int id) {
+ return countMatchUser(id) == 2;
+ }
+
+ public Integer countMatchUser(int id) {
+ return teamDao.countMatchUser(id);
+ }
+} | Java | `@Transactional` ์ด ์ ์ธ๋ ๋ฉ์๋์์ ์ด๋ ๊ฒ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ฉด, ํธ๋์ญ์
์ด ์ ์ฉ๋์ง ์์ต๋๋ค.
https://mommoo.tistory.com/92 |
@@ -0,0 +1,20 @@
+package com.codesquad.baseballgame.domain.hitter.mapper;
+
+import com.codesquad.baseballgame.domain.hitter.dto.HitterListDto;
+import org.springframework.jdbc.core.RowMapper;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class HitterListMapper implements RowMapper<HitterListDto> {
+
+ @Override
+ public HitterListDto mapRow(ResultSet rs, int rowNum) throws SQLException {
+ return HitterListDto.builder()
+ .teamName(rs.getString("name"))
+ .totalsBatterBox(rs.getInt("total_sum"))
+ .totalsHit(rs.getInt("total_hit"))
+ .totalsOut(rs.getInt("total_out"))
+ .build();
+ }
+} | Java | `RowMapper` ์์ ๋ฐ๋ก DTO๋ก ๋งคํํ๋ค์.
๋ชจ๋ธ ํด๋์ค๊ฐ ํ๋ ์๋๊ฒ ์ข๊ธด ํ๋ฐ... ๋ชจ๋ธ ํด๋์ค์ ํ์์ฑ์ด ์์๋๋ณด๋ค์. |
@@ -0,0 +1,15 @@
+package com.codesquad.baseballgame.domain.scoreboard.controller;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class ScoreBoardController {
+
+ @GetMapping("games/{id}/scoreboard")
+ public void showScoreBoard(@PathVariable int id) {
+
+
+ }
+} | Java | ์...... |
@@ -0,0 +1,23 @@
+package com.codesquad.baseballgame.domain.scoreboard.dao;
+
+import com.codesquad.baseballgame.domain.scoreboard.dto.ScoreBoardInningDto;
+import com.codesquad.baseballgame.domain.team.mapper.TeamDtoMapper;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.stereotype.Repository;
+
+import javax.sql.DataSource;
+
+@Repository
+public class ScoreBoardDao {
+
+ private final NamedParameterJdbcTemplate namedJdbcTemplate;
+ private final TeamDtoMapper teamDtoMapper = new TeamDtoMapper();
+
+ public ScoreBoardDao(DataSource dataSource) {
+ this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
+ }
+
+// public ScoreBoardInningDto findInningById(int id) {
+// String inningSql = ""
+// }
+} | Java | ์ฃผ์์ ์ง์์ฃผ์ธ์. |
@@ -0,0 +1,9 @@
+package com.codesquad.baseballgame.domain.game.controller;
+
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class GameController {
+
+
+} | Java | ๋ค ๊ผญ ์ง์ฐ๋๋ก ํ๊ฒ ์ต๋๋ค ์ ๋ ํด์ ์๋๋ ์ง์ ํด๋ฒ๋ ธ๊ตฐ์. ๊ผญ ๋ช
์ฌํ๊ฒ ์ต๋๋ค |
@@ -0,0 +1,24 @@
+package com.codesquad.baseballgame.domain.game.controller;
+
+import com.codesquad.baseballgame.domain.game.service.MatchService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequiredArgsConstructor
+public class MatchController {
+
+ private final MatchService matchService;
+
+ @PostMapping("games/{id}")
+ public ResponseEntity<Boolean> matching(@PathVariable int id) {
+ if (matchService.matchStatus(id)) {
+ return new ResponseEntity<>(true, HttpStatus.OK);
+ }
+ return new ResponseEntity<>(false, HttpStatus.OK);
+ }
+} | Java | ์ฐ๋ฉด์ ์๋ฟ์ธ.. ํ๊ณ ๋๋์ ์์๋๋ฐ.. ๋ง์ง๋ง์ ๋ง๋๋๋ผ ๊ธฐ๋ณธ ๋ฒ์น์ ์๊ณ ๋ง ๋ง๋ ๊ฒ ์์ธ์ด์์ต๋๋ค. ๊ธํ๋๋ผ๋ ์งํฌ๊ฑด ์งํค๋ฉด์ ๋ง๋ค์ด์ผํ๋๋ฐ ์ ๊ฐ ๋๋ฌด ์๋๋ ๋ค์. ์ต์ํ์ Json์ ๋ง๋ค์์ด์ผํ๋๋ฐ ๋ค์์๋ ์งํค๋๋ก ํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,7 @@
+package com.codesquad.baseballgame.domain.game.dao;
+
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class GameDao {
+} | Java | ๋ค... ๋ง์์ ์ง์ ์ด์ผํ์ด์. |
@@ -0,0 +1,14 @@
+package com.codesquad.baseballgame.domain.game.dto;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+
+@Getter @ToString
+@RequiredArgsConstructor
+public class BallCountDto {
+
+ private int strike;
+ private int ball;
+ private int out;
+} | Java | ์ฌ๋ฌ์๊ฐ ํ๋ฉด์ ์ฝ๋ฉํ๋ค๊ฐ ์๋ฌด๊ฑฐ๋ ๋ค ๋ฃ๋๋ฐ๋์ ์๊ธด ๋ฌธ์ ์
๋๋ค. ๊ธฐ๋ฅ ํ๋๋ง๋ค ๋ ๊ทธ๋ ์ง์คํ์ด์ผ ํ๋๋ฐ ์ด๊ฒ ์ ๊ฒํ๋ค๊ฐ ์ด๋์ ๋ ์๋๊ฒ ๋์์ต๋๋ค. ์ ๊ฐ ์ด๊ฑธ ๋ฃ์๋ค๋๊ฒ๋ ์ง๊ธ ์์๋ค์. Dto ์์ ๋ฃ์ ์๊ฐ ์์๋๋ฐ.... ์ด๋ฒ ๊ธฐํ๋ก ์ ์ ๋๋ฐ๋ก ์ฐจ๋ ค์ผ๊ฒ ์ต๋๋ค |
@@ -0,0 +1,23 @@
+package com.codesquad.baseballgame.domain.game.service;
+
+import com.codesquad.baseballgame.domain.team.dao.TeamDao;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@RequiredArgsConstructor
+public class MatchService {
+
+ private final TeamDao teamDao;
+
+ @Transactional(isolation = Isolation.SERIALIZABLE)
+ public Boolean matchStatus(int id) {
+ return countMatchUser(id) == 2;
+ }
+
+ public Integer countMatchUser(int id) {
+ return teamDao.countMatchUser(id);
+ }
+} | Java | ํธ๋์ ์
์ ๋ํ ๋ด์ฉ์ ๋ธ๋ก๊ทธ์์ ๊ฐ๋ณ๊ฒ ๋ณด๊ณ ์ด ๋ ์ฐ๋๊ฑด๊ฐ ํ๊ณ ์ผ๋๋ฐ ์ข ๋ ๊ณต๋ถ๊ฐ ํ์ํ๋๊ตฐ์. Read Committed ์ ๋ํด์ ์กฐ์ฌํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,20 @@
+package com.codesquad.baseballgame.domain.hitter.mapper;
+
+import com.codesquad.baseballgame.domain.hitter.dto.HitterListDto;
+import org.springframework.jdbc.core.RowMapper;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class HitterListMapper implements RowMapper<HitterListDto> {
+
+ @Override
+ public HitterListDto mapRow(ResultSet rs, int rowNum) throws SQLException {
+ return HitterListDto.builder()
+ .teamName(rs.getString("name"))
+ .totalsBatterBox(rs.getInt("total_sum"))
+ .totalsHit(rs.getInt("total_hit"))
+ .totalsOut(rs.getInt("total_out"))
+ .build();
+ }
+} | Java | ๋ชจ๋ธ ํด๋์ค์ ํ์์ฑ์ด ์์๋ค๊ธฐ๋ณด๋จ ์ค๊ณ๊ฐ ์๋ชป๋์์ต๋๋ค. ๋ง์ฝ ๋ชจ๋ธํด๋์ค์ ๋ง๊ฒ ํ๋ค๋ฉด ์ง๊ธ๋ณด๋ค ๋์ฑ ๋น ๋ฅด๊ฒ ์ฝ๋ฉ์ด ๋์์ํ
๋ฐ ์์ฝ์ต๋๋ค. ์ค๊ณ๋ฅผ ๊ผญ ์ ๋๋ก ๋ง์ถฐ์ผ๊ฒ ๋ค์ |
@@ -0,0 +1,23 @@
+package com.codesquad.baseballgame.domain.scoreboard.dao;
+
+import com.codesquad.baseballgame.domain.scoreboard.dto.ScoreBoardInningDto;
+import com.codesquad.baseballgame.domain.team.mapper.TeamDtoMapper;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.stereotype.Repository;
+
+import javax.sql.DataSource;
+
+@Repository
+public class ScoreBoardDao {
+
+ private final NamedParameterJdbcTemplate namedJdbcTemplate;
+ private final TeamDtoMapper teamDtoMapper = new TeamDtoMapper();
+
+ public ScoreBoardDao(DataSource dataSource) {
+ this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
+ }
+
+// public ScoreBoardInningDto findInningById(int id) {
+// String inningSql = ""
+// }
+} | Java | ๋ต |
@@ -0,0 +1,15 @@
+package com.codesquad.baseballgame.domain.scoreboard.controller;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class ScoreBoardController {
+
+ @GetMapping("games/{id}/scoreboard")
+ public void showScoreBoard(@PathVariable int id) {
+
+
+ }
+} | Java | ์ฉ์ํด์ฃผ์ญ์์ค... |
@@ -0,0 +1,23 @@
+package com.codesquad.baseballgame.domain.game.service;
+
+import com.codesquad.baseballgame.domain.team.dao.TeamDao;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@RequiredArgsConstructor
+public class MatchService {
+
+ private final TeamDao teamDao;
+
+ @Transactional(isolation = Isolation.SERIALIZABLE)
+ public Boolean matchStatus(int id) {
+ return countMatchUser(id) == 2;
+ }
+
+ public Integer countMatchUser(int id) {
+ return teamDao.countMatchUser(id);
+ }
+} | Java | ํธ๋์ ์
์ ๋ํด์ ํ์คํ๊ฒ ๊ณต๋ถํด์ผ๊ฒ ๋ค์. ์ด์คํ ์ฌ์ฉ์ ์ง์ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,23 @@
+package com.codesquad.baseballgame.domain.game.service;
+
+import com.codesquad.baseballgame.domain.team.dao.TeamDao;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@RequiredArgsConstructor
+public class MatchService {
+
+ private final TeamDao teamDao;
+
+ @Transactional(isolation = Isolation.SERIALIZABLE)
+ public Boolean matchStatus(int id) {
+ return countMatchUser(id) == 2;
+ }
+
+ public Integer countMatchUser(int id) {
+ return teamDao.countMatchUser(id);
+ }
+} | Java | ์ ์ค๋ ์ ํํ๊ฒ ์์
์ ํ๋๊ตฐ์ ๋ฆฌ๋ทฐ๋ณด์๋ง์ ์์
์ ํ๋ ๊ธฐ์ฉ๋๋ค. Repeatable Read๋ก๋ง ์ปค๋ฒ๊ฐ ๊ฐ๋ฅํ๋ค์ |
@@ -0,0 +1,28 @@
+package christmas.util;
+
+public class DateValidator {
+ private static final String INVALID_DATE_MESSAGE = "์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+
+ public static void validateInput(String input) {
+ validateNumeric(input);
+ int date = Integer.parseInt(input);
+ validateDate(date);
+ }
+
+ private static void validateNumeric(String input) {
+ if (input == null) {
+ throw new ValidationException(INVALID_DATE_MESSAGE);
+ }
+ try {
+ Integer.parseInt(input);
+ } catch (NumberFormatException e) {
+ throw new ValidationException(INVALID_DATE_MESSAGE);
+ }
+ }
+
+ private static void validateDate(int date) {
+ if (date < 1 || date > 31) {
+ throw new ValidationException(INVALID_DATE_MESSAGE);
+ }
+ }
+} | Java | 31์ผ๋ก ๋๋์ง ์๋ ๋ฌ๋ ์๊ธฐ๋๋ฌธ์ 12์์ ๋ํ ์์กด์ฑ์ ์ฃผ์
๋ฐ์์ ํด๋นํ๋ ์(ๆ)์ ๋ง์ถฐ ์ต๋ ์ผ์๋ฅผ ๋ณ๊ฒฝ ํ๋์ง ํด๋น ์ด๋ฒคํธ์ ๋ํ ์์๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ ๊ทธ ์ธ ๋ค์ํ ๋ฐฉ์์ผ๋ก ์กฐ๊ฑด์ ์กฐ์ ํ๋ ๊ฒ๋ ์ข์๊ฑฐ๋ผ ์๊ฐํฉ๋๋ค! |
@@ -0,0 +1,103 @@
+package christmas.util;
+
+import christmas.domain.type.Menu;
+
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+public class OrderValidator {
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+
+ private static final int MIN_AMOUNT = 1;
+ private static final int MAX_AMOUNT = 20;
+ private static final String INPUT_PATTERN = "([\\S]+-\\d+)(,\\s*[\\S]+-\\d+)*";
+ private static final String INVALID_ORDER_MESSAGE = "์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String BEVERAGE_ONLY_MESSAGE = "์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String INVALID_ORDER_AMOUNT_MESSAGE = "๋ฉ๋ด๋ ํ ๋ฒ์ 1๊ฐ์ด์, ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String MENU_NOT_EXIST_MESSAGE = "์กด์ฌํ์ง ์๋ ๋ฉ๋ด์
๋๋ค.";
+ private static final String DUPLICATED_MENU_ORDER_MESSAGE = "์ค๋ณต๋ ๋ฉ๋ด ํญ๋ชฉ์ด ์์ต๋๋ค.";
+
+ public static void validateInput(String input) {
+ checkInputPattern(input);
+ checkInputPatternMore(input);
+ List<String> menuNames = parseMenuName(input);
+ checkDuplicated(menuNames);
+
+ for (String menuName : menuNames) {
+ checkMenu(menuName);
+ }
+ }
+
+ public static void validateOrder(Map<Menu, Integer> order) {
+ checkAmount(order);
+ checkBeverageOnly(order);
+ }
+
+ private static void checkBeverageOnly(Map<Menu, Integer> order) {
+ if (order.keySet()
+ .stream()
+ .allMatch(menu -> menu.getCategory() == Menu.Category.BEVERAGE)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + BEVERAGE_ONLY_MESSAGE);
+ }
+ }
+
+ private static void checkAmount(Map<Menu, Integer> order) {
+ int totalAmount = order.values()
+ .stream()
+ .mapToInt(Integer::intValue).sum();
+
+ if (totalAmount < MIN_AMOUNT || totalAmount > MAX_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+
+ for (Integer amount : order.values()) {
+ if (amount < MIN_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkMenu(String menuName) {
+ boolean menuExists = Arrays.stream(Menu.values()).anyMatch(menu -> menu.getName().equals(menuName));
+
+ if (!menuExists) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + MENU_NOT_EXIST_MESSAGE);
+ }
+ }
+ private static void checkDuplicated(List<String> menuNames) {
+ Set<String> uniqueMenuNames = new HashSet<>();
+
+ for (String name : menuNames) {
+ if (!uniqueMenuNames.add(name)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + DUPLICATED_MENU_ORDER_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkInputPattern(String input) {
+ if (input == null || !Pattern.matches(INPUT_PATTERN, input)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private static List<String> parseMenuName(String input) {
+ List<String> menuNames = Arrays.stream(input.split(","))
+ .map(order -> order.trim().split("-")[0].trim())
+ .collect(Collectors.toList());
+
+ return menuNames;
+ }
+
+ private static void checkInputPatternMore(String input) {
+ String[] items = input.split(",");
+
+ for (String item : items) {
+ int count = StringUtil.countMatches(item, '-');
+ if (count != 1) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+ }
+
+} | Java | ์ ๊ท์์ ์ฌ์ฉํ ๋ ๋ฏธ๋ฆฌ ์บ์ฑํ๋ ๋ฐฉ๋ฒ์ด ์๋ค๊ณ ํฉ๋๋ค!
https://mntdev.tistory.com/69#%F0%9F%91%8D%20%EC%A0%95%EC%A0%81%20%ED%8C%A9%ED%84%B0%EB%A6%AC%EB%A5%BC%20%EC%A0%9C%EA%B3%B5%ED%95%98%EB%8A%94%20%EB%B6%88%EB%B3%80%20%ED%81%B4%EB%9E%98%EC%8A%A4-1
์ด ๊ธ์ ํ๋ฒ ์ฐธ๊ณ ํด๋ณด์๋ฉด ์ข์ ๊ฒ๊ฐ์์! ๐ |
@@ -0,0 +1,103 @@
+package christmas.util;
+
+import christmas.domain.type.Menu;
+
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+public class OrderValidator {
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+
+ private static final int MIN_AMOUNT = 1;
+ private static final int MAX_AMOUNT = 20;
+ private static final String INPUT_PATTERN = "([\\S]+-\\d+)(,\\s*[\\S]+-\\d+)*";
+ private static final String INVALID_ORDER_MESSAGE = "์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String BEVERAGE_ONLY_MESSAGE = "์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String INVALID_ORDER_AMOUNT_MESSAGE = "๋ฉ๋ด๋ ํ ๋ฒ์ 1๊ฐ์ด์, ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String MENU_NOT_EXIST_MESSAGE = "์กด์ฌํ์ง ์๋ ๋ฉ๋ด์
๋๋ค.";
+ private static final String DUPLICATED_MENU_ORDER_MESSAGE = "์ค๋ณต๋ ๋ฉ๋ด ํญ๋ชฉ์ด ์์ต๋๋ค.";
+
+ public static void validateInput(String input) {
+ checkInputPattern(input);
+ checkInputPatternMore(input);
+ List<String> menuNames = parseMenuName(input);
+ checkDuplicated(menuNames);
+
+ for (String menuName : menuNames) {
+ checkMenu(menuName);
+ }
+ }
+
+ public static void validateOrder(Map<Menu, Integer> order) {
+ checkAmount(order);
+ checkBeverageOnly(order);
+ }
+
+ private static void checkBeverageOnly(Map<Menu, Integer> order) {
+ if (order.keySet()
+ .stream()
+ .allMatch(menu -> menu.getCategory() == Menu.Category.BEVERAGE)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + BEVERAGE_ONLY_MESSAGE);
+ }
+ }
+
+ private static void checkAmount(Map<Menu, Integer> order) {
+ int totalAmount = order.values()
+ .stream()
+ .mapToInt(Integer::intValue).sum();
+
+ if (totalAmount < MIN_AMOUNT || totalAmount > MAX_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+
+ for (Integer amount : order.values()) {
+ if (amount < MIN_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkMenu(String menuName) {
+ boolean menuExists = Arrays.stream(Menu.values()).anyMatch(menu -> menu.getName().equals(menuName));
+
+ if (!menuExists) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + MENU_NOT_EXIST_MESSAGE);
+ }
+ }
+ private static void checkDuplicated(List<String> menuNames) {
+ Set<String> uniqueMenuNames = new HashSet<>();
+
+ for (String name : menuNames) {
+ if (!uniqueMenuNames.add(name)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + DUPLICATED_MENU_ORDER_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkInputPattern(String input) {
+ if (input == null || !Pattern.matches(INPUT_PATTERN, input)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private static List<String> parseMenuName(String input) {
+ List<String> menuNames = Arrays.stream(input.split(","))
+ .map(order -> order.trim().split("-")[0].trim())
+ .collect(Collectors.toList());
+
+ return menuNames;
+ }
+
+ private static void checkInputPatternMore(String input) {
+ String[] items = input.split(",");
+
+ for (String item : items) {
+ int count = StringUtil.countMatches(item, '-');
+ if (count != 1) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+ }
+
+} | Java | "," ๋ "-"๋ ์์๋ก ๊ด๋ฆฌํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์! ์ด๋ฒคํธ์ ๋ฐ๋ผ ์
๋ ฅ๋ฐ๋ ๋ฐฉ์์ด ๋ฐ๋ ์๋ ์์์์ ๐ |
@@ -0,0 +1,76 @@
+package christmas.domain.logic;
+
+import christmas.domain.type.Badge;
+import christmas.domain.type.Menu;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class EventCalculatorTest {
+
+ @Test
+ void isEligibleForEvent() {
+ assertTrue(EventCalculator.isEligibleForEvent(15000));
+ assertFalse(EventCalculator.isEligibleForEvent(5000));
+ }
+
+ @Test
+ void calculateWeekdayDiscount_์ฃผ์ค_๋์ ํธ() {
+ Map<Menu, Integer> order = Map.of(Menu.CHOCOLATE_CAKE, 1);
+ int discount = EventCalculator.calculateWeekdayDiscount(3, order);
+ assertEquals(2023, discount);
+ }
+
+ @Test
+ void calculateWeekdayDiscount_์ฃผ์ค_๋์ ํธ์์() {
+ Map<Menu, Integer> order = Map.of(Menu.CAESAR_SALAD, 1, Menu.TAPAS, 1);
+ int discount = EventCalculator.calculateWeekdayDiscount(3, order);
+ assertEquals(0, discount);
+ }
+
+ @Test
+ void calculateWeekendDiscount_์ฃผ๋ง_๋ฉ์ธ() {
+ Map<Menu, Integer> order = Map.of(Menu.T_BONE_STEAK, 2, Menu.TAPAS, 1);
+ int discount = EventCalculator.calculateWeekendDiscount(4, order);
+ assertEquals(2023 * 2, discount);
+ }
+
+ @Test
+ void calculateWeekendDiscount_์ฃผ๋ง_๋ฉ์ธ์์() {
+ Map<Menu, Integer> order = Map.of(Menu.ICE_CREAM, 1);
+ int discount = EventCalculator.calculateWeekendDiscount(4, order);
+ assertEquals(0, discount);
+ }
+
+ @Test
+ void calculateSpecialDiscount_๋ณ๋ฐ์ด() {
+ int discount = EventCalculator.calculateSpecialDiscount(25);
+ assertEquals(1000, discount);
+ }
+
+ @Test
+ void calculateSpecialDiscount_๋ณ๋ฐ์ด_์๋() {
+ int discount = EventCalculator.calculateSpecialDiscount(26);
+ assertEquals(0, discount);
+ }
+
+ @Test
+ void calculateGiveawayEvent() {
+ Map<Menu, Integer> giveaway = EventCalculator.calculateGiveawayEvent(120000);
+ assertNotNull(giveaway);
+ assertTrue(giveaway.containsKey(Menu.CHAMPAGNE));
+ assertEquals(1, giveaway.get(Menu.CHAMPAGNE));
+ }
+
+ @Test
+ void calculateBadge() {
+ assertEquals(Badge.SANTA, EventCalculator.calculateBadge(20000));
+ assertEquals(Badge.SANTA, EventCalculator.calculateBadge(30000));
+ assertEquals(Badge.TREE, EventCalculator.calculateBadge(15000));
+ assertEquals(Badge.TREE, EventCalculator.calculateBadge(19999));
+ assertEquals(Badge.STAR, EventCalculator.calculateBadge(7000));
+ assertEquals(Badge.NONE, EventCalculator.calculateBadge(4000));
+ }
+} | Java | ํด๋ฆฐ์ฝ๋์ ๋์ค๋ ๋ด์ฉ์ธ๋ฐ ํ ํ
์คํธ ๋ฉ์๋ ์์ ์ฌ๋ฌ assert๋ฌธ์ ์ฌ์ฉํ๋ ๊ฒ์ ์ข์ง ์๋ค๊ณ ํด์! ํด๋น ๋ฉ์๋์์@ParameterizedTest ์ @MethodSource๋ฅผ ์ฌ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,20 @@
+package christmas.domain.logic;
+
+import christmas.domain.model.DecemberEvent;
+
+public class ChristmasEventCalculator {
+ public static int calculateChristmasDiscount(int date) {
+ int startDay = DecemberEvent.getEventStartDate();
+ int discountPricePerDay = DecemberEvent.getDayDiscountPrice();
+ int discountPriceOfFirstDay = DecemberEvent.getStartDiscountPrice();
+
+ if (date > DecemberEvent.CHRISTMAS_DAY) {
+ return 0;
+ }
+
+ int daysUntilDate = date - startDay;
+ int totalDiscount = discountPriceOfFirstDay + (daysUntilDate * discountPricePerDay);
+
+ return totalDiscount;
+ }
+} | Java | ์ ํธ๋ฆฌํฐ ํด๋์ค๋ก ๋ณด์ด๋๋ฐ ์์ฑ์๋ฅผ private๋ก ๋ง๋๋๊ฒ ์ข์๋ณด์ฌ์! ๐ |
@@ -0,0 +1,71 @@
+package christmas.domain.model;
+
+import christmas.domain.type.Menu;
+
+import java.util.*;
+
+public class DecemberEvent {
+ public static final int CHRISTMAS_DAY = 25;
+ private static final int EVENT_START_DATE = 1;
+ private static final int DAY_DISCOUNT_PRICE = 100;
+ private static final int START_DISCOUNT_PRICE = 1_000;
+ private static final int MIN_PRICE = 10_000;
+ private static final int WEEKDAY_DISCOUNT_PRICE = 2_023;
+ private static final int WEEKEND_DISCOUNT_PRICE = 2_023;
+ private static final Menu.Category WEEKDAY_DISCOUNT_CATEGORY = Menu.Category.DESSERT;
+ private static final Menu.Category WEEKEND_DISCOUNT_CATEGORY = Menu.Category.MAIN;
+ private static final List<Integer> WEEKEND_DATES = Arrays.asList(1, 2, 8, 9, 15, 16, 22, 23, 29, 30);
+ private static final List<Integer> STAR_DATES = Arrays.asList(3, 10, 17, 24, 25, 31);
+ private static final int SPECIAL_DISCOUNT_PRICE = 1_000;
+ private static final int GIVEAWAY_CONDITION_PRICE = 120_000;
+ private static final Map<Menu, Integer> GIVEAWAY_BENEFITS = Map.of(Menu.CHAMPAGNE, 1);
+
+
+ public static boolean isOverThanMinPrice(int totalPrice) {
+ return totalPrice >= MIN_PRICE;
+ }
+
+ public static boolean isStarDate(int date) {
+ return STAR_DATES.contains(date);
+ }
+
+ public static boolean isWeekend(int date) {
+ return WEEKEND_DATES.contains(date);
+ }
+
+ public static boolean isEligibleForGiveaway(int totalPrice) {
+ return totalPrice >= GIVEAWAY_CONDITION_PRICE;
+ }
+
+ public static int getSpecialDiscountPrice() {
+ return SPECIAL_DISCOUNT_PRICE;
+ }
+
+ public static int getWeekdayDiscountPrice() { return WEEKDAY_DISCOUNT_PRICE; }
+
+ public static int getWeekendDiscountPrice() { return WEEKEND_DISCOUNT_PRICE; }
+
+ public static Menu.Category getWeekdayDiscountCategory() {
+ return WEEKDAY_DISCOUNT_CATEGORY;
+ }
+
+ public static Menu.Category getWeekendDiscountCategory() {
+ return WEEKEND_DISCOUNT_CATEGORY;
+ }
+
+ public static Map<Menu, Integer> getGiveawayBenefits() {
+ return GIVEAWAY_BENEFITS;
+ }
+
+ public static int getDayDiscountPrice() {
+ return DAY_DISCOUNT_PRICE;
+ }
+
+ public static int getStartDiscountPrice() {
+ return START_DISCOUNT_PRICE;
+ }
+
+ public static int getEventStartDate() {
+ return EVENT_START_DATE;
+ }
+} | Java | ์์๋ฅผ ๊ด๋ฆฌํ๋ ํด๋์ค๋ฅผ ๋ค๋ฅธ ํจํค์ง๋ก ๊ตฌ๋ถํ๋ ๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,103 @@
+package christmas.util;
+
+import christmas.domain.type.Menu;
+
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+public class OrderValidator {
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+
+ private static final int MIN_AMOUNT = 1;
+ private static final int MAX_AMOUNT = 20;
+ private static final String INPUT_PATTERN = "([\\S]+-\\d+)(,\\s*[\\S]+-\\d+)*";
+ private static final String INVALID_ORDER_MESSAGE = "์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String BEVERAGE_ONLY_MESSAGE = "์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String INVALID_ORDER_AMOUNT_MESSAGE = "๋ฉ๋ด๋ ํ ๋ฒ์ 1๊ฐ์ด์, ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String MENU_NOT_EXIST_MESSAGE = "์กด์ฌํ์ง ์๋ ๋ฉ๋ด์
๋๋ค.";
+ private static final String DUPLICATED_MENU_ORDER_MESSAGE = "์ค๋ณต๋ ๋ฉ๋ด ํญ๋ชฉ์ด ์์ต๋๋ค.";
+
+ public static void validateInput(String input) {
+ checkInputPattern(input);
+ checkInputPatternMore(input);
+ List<String> menuNames = parseMenuName(input);
+ checkDuplicated(menuNames);
+
+ for (String menuName : menuNames) {
+ checkMenu(menuName);
+ }
+ }
+
+ public static void validateOrder(Map<Menu, Integer> order) {
+ checkAmount(order);
+ checkBeverageOnly(order);
+ }
+
+ private static void checkBeverageOnly(Map<Menu, Integer> order) {
+ if (order.keySet()
+ .stream()
+ .allMatch(menu -> menu.getCategory() == Menu.Category.BEVERAGE)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + BEVERAGE_ONLY_MESSAGE);
+ }
+ }
+
+ private static void checkAmount(Map<Menu, Integer> order) {
+ int totalAmount = order.values()
+ .stream()
+ .mapToInt(Integer::intValue).sum();
+
+ if (totalAmount < MIN_AMOUNT || totalAmount > MAX_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+
+ for (Integer amount : order.values()) {
+ if (amount < MIN_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkMenu(String menuName) {
+ boolean menuExists = Arrays.stream(Menu.values()).anyMatch(menu -> menu.getName().equals(menuName));
+
+ if (!menuExists) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + MENU_NOT_EXIST_MESSAGE);
+ }
+ }
+ private static void checkDuplicated(List<String> menuNames) {
+ Set<String> uniqueMenuNames = new HashSet<>();
+
+ for (String name : menuNames) {
+ if (!uniqueMenuNames.add(name)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + DUPLICATED_MENU_ORDER_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkInputPattern(String input) {
+ if (input == null || !Pattern.matches(INPUT_PATTERN, input)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private static List<String> parseMenuName(String input) {
+ List<String> menuNames = Arrays.stream(input.split(","))
+ .map(order -> order.trim().split("-")[0].trim())
+ .collect(Collectors.toList());
+
+ return menuNames;
+ }
+
+ private static void checkInputPatternMore(String input) {
+ String[] items = input.split(",");
+
+ for (String item : items) {
+ int count = StringUtil.countMatches(item, '-');
+ if (count != 1) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+ }
+
+} | Java | getter๋ฅผ ์ฌ์ฉํ๋ ๋์ menu๊ฐ์ฒด๊ฐ ์ง์ ์นดํ
๊ณ ๋ฆฌ๋ฅผ ๋น๊ตํ๊ฒ ํด๋ณด๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,61 @@
+package christmas.view;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.domain.type.Menu;
+import christmas.util.DateValidator;
+import christmas.util.OrderValidator;
+import christmas.util.ValidationException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class InputView {
+ private static final String ASK_DATE_MESSAGE = "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)";
+ private static final String ASK_ORDER_MESSAGE = "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)";
+
+ public int readDate() {
+ while (true) {
+ try {
+ System.out.println(ASK_DATE_MESSAGE);
+ String input = Console.readLine();
+ DateValidator.validateInput(input);
+ int date = Integer.parseInt(input);
+ return date;
+ } catch (ValidationException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ public Map<Menu, Integer> readOrder() {
+ while (true) {
+ try {
+ System.out.println(ASK_ORDER_MESSAGE);
+ String input = Console.readLine();
+ OrderValidator.validateInput(input);
+ Map<Menu, Integer> order = parseOrder(input);
+ OrderValidator.validateOrder(order);
+
+ return order;
+ } catch (ValidationException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private Map<Menu, Integer> parseOrder(String input) {
+ Map<Menu, Integer> order = new HashMap<>();
+
+ String[] items = input.split(",");
+ for (String item : items) {
+ String[] parts = item.trim()
+ .split("-");
+ String menuName = parts[0].trim();
+ int amount = Integer.parseInt(parts[1].trim());
+
+ Menu menu = Menu.findByName(menuName);
+ order.put(menu, amount);
+ }
+ return order;
+ }
+} | Java | ๋ฐ๋ณต๋์ง๋ง ๋ฏธ์ธํ๊ฒ ๋ค๋ฅธ ์ฝ๋๋ค์! ์ด๋ป๊ฒ ๋ฐ๋ณต์ ์ค์ผ์ง ๊ณ ๋ฏผํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์! ๐ |
@@ -0,0 +1,103 @@
+package christmas.util;
+
+import christmas.domain.type.Menu;
+
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+public class OrderValidator {
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+
+ private static final int MIN_AMOUNT = 1;
+ private static final int MAX_AMOUNT = 20;
+ private static final String INPUT_PATTERN = "([\\S]+-\\d+)(,\\s*[\\S]+-\\d+)*";
+ private static final String INVALID_ORDER_MESSAGE = "์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String BEVERAGE_ONLY_MESSAGE = "์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String INVALID_ORDER_AMOUNT_MESSAGE = "๋ฉ๋ด๋ ํ ๋ฒ์ 1๊ฐ์ด์, ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String MENU_NOT_EXIST_MESSAGE = "์กด์ฌํ์ง ์๋ ๋ฉ๋ด์
๋๋ค.";
+ private static final String DUPLICATED_MENU_ORDER_MESSAGE = "์ค๋ณต๋ ๋ฉ๋ด ํญ๋ชฉ์ด ์์ต๋๋ค.";
+
+ public static void validateInput(String input) {
+ checkInputPattern(input);
+ checkInputPatternMore(input);
+ List<String> menuNames = parseMenuName(input);
+ checkDuplicated(menuNames);
+
+ for (String menuName : menuNames) {
+ checkMenu(menuName);
+ }
+ }
+
+ public static void validateOrder(Map<Menu, Integer> order) {
+ checkAmount(order);
+ checkBeverageOnly(order);
+ }
+
+ private static void checkBeverageOnly(Map<Menu, Integer> order) {
+ if (order.keySet()
+ .stream()
+ .allMatch(menu -> menu.getCategory() == Menu.Category.BEVERAGE)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + BEVERAGE_ONLY_MESSAGE);
+ }
+ }
+
+ private static void checkAmount(Map<Menu, Integer> order) {
+ int totalAmount = order.values()
+ .stream()
+ .mapToInt(Integer::intValue).sum();
+
+ if (totalAmount < MIN_AMOUNT || totalAmount > MAX_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+
+ for (Integer amount : order.values()) {
+ if (amount < MIN_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkMenu(String menuName) {
+ boolean menuExists = Arrays.stream(Menu.values()).anyMatch(menu -> menu.getName().equals(menuName));
+
+ if (!menuExists) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + MENU_NOT_EXIST_MESSAGE);
+ }
+ }
+ private static void checkDuplicated(List<String> menuNames) {
+ Set<String> uniqueMenuNames = new HashSet<>();
+
+ for (String name : menuNames) {
+ if (!uniqueMenuNames.add(name)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + DUPLICATED_MENU_ORDER_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkInputPattern(String input) {
+ if (input == null || !Pattern.matches(INPUT_PATTERN, input)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private static List<String> parseMenuName(String input) {
+ List<String> menuNames = Arrays.stream(input.split(","))
+ .map(order -> order.trim().split("-")[0].trim())
+ .collect(Collectors.toList());
+
+ return menuNames;
+ }
+
+ private static void checkInputPatternMore(String input) {
+ String[] items = input.split(",");
+
+ for (String item : items) {
+ int count = StringUtil.countMatches(item, '-');
+ if (count != 1) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+ }
+
+} | Java | throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + ******);
์ด๋ถ๋ถ์ด ๋ฐ๋ณต๋๋ค์! ์ ๋ ๋ฉ์๋๋ ์์๋ก ๋ฐ๋ณต์ ์ค์ผ ์ ์๋ค๊ณ ์๊ฐํ๋๋ฐ ์ด๋ค๊ฐ์? ๐ |
@@ -0,0 +1,28 @@
+package christmas.util;
+
+public class DateValidator {
+ private static final String INVALID_DATE_MESSAGE = "์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+
+ public static void validateInput(String input) {
+ validateNumeric(input);
+ int date = Integer.parseInt(input);
+ validateDate(date);
+ }
+
+ private static void validateNumeric(String input) {
+ if (input == null) {
+ throw new ValidationException(INVALID_DATE_MESSAGE);
+ }
+ try {
+ Integer.parseInt(input);
+ } catch (NumberFormatException e) {
+ throw new ValidationException(INVALID_DATE_MESSAGE);
+ }
+ }
+
+ private static void validateDate(int date) {
+ if (date < 1 || date > 31) {
+ throw new ValidationException(INVALID_DATE_MESSAGE);
+ }
+ }
+} | Java | ์ ๋ง๋ค์ ์ ๊ฐ ์ถ๊ตฌํ๋ ๋ฐฉํฅ์ด `12์ ์ด๋ฒคํธ` ํด๋์ค๋ง ๋งค๋ฌ ํด๋นํ๋ ๋ฌ์ ๊ฐ์ ๋ผ์ฐ๋ ๊ฑฐ์๊ฑฐ๋ ์ `๋ช์.LAST_DATE` ์ด๋ฐ์์ผ๋ก ๋ฐ๊ฟ์ผ ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,76 @@
+package christmas.domain.logic;
+
+import christmas.domain.type.Badge;
+import christmas.domain.type.Menu;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class EventCalculatorTest {
+
+ @Test
+ void isEligibleForEvent() {
+ assertTrue(EventCalculator.isEligibleForEvent(15000));
+ assertFalse(EventCalculator.isEligibleForEvent(5000));
+ }
+
+ @Test
+ void calculateWeekdayDiscount_์ฃผ์ค_๋์ ํธ() {
+ Map<Menu, Integer> order = Map.of(Menu.CHOCOLATE_CAKE, 1);
+ int discount = EventCalculator.calculateWeekdayDiscount(3, order);
+ assertEquals(2023, discount);
+ }
+
+ @Test
+ void calculateWeekdayDiscount_์ฃผ์ค_๋์ ํธ์์() {
+ Map<Menu, Integer> order = Map.of(Menu.CAESAR_SALAD, 1, Menu.TAPAS, 1);
+ int discount = EventCalculator.calculateWeekdayDiscount(3, order);
+ assertEquals(0, discount);
+ }
+
+ @Test
+ void calculateWeekendDiscount_์ฃผ๋ง_๋ฉ์ธ() {
+ Map<Menu, Integer> order = Map.of(Menu.T_BONE_STEAK, 2, Menu.TAPAS, 1);
+ int discount = EventCalculator.calculateWeekendDiscount(4, order);
+ assertEquals(2023 * 2, discount);
+ }
+
+ @Test
+ void calculateWeekendDiscount_์ฃผ๋ง_๋ฉ์ธ์์() {
+ Map<Menu, Integer> order = Map.of(Menu.ICE_CREAM, 1);
+ int discount = EventCalculator.calculateWeekendDiscount(4, order);
+ assertEquals(0, discount);
+ }
+
+ @Test
+ void calculateSpecialDiscount_๋ณ๋ฐ์ด() {
+ int discount = EventCalculator.calculateSpecialDiscount(25);
+ assertEquals(1000, discount);
+ }
+
+ @Test
+ void calculateSpecialDiscount_๋ณ๋ฐ์ด_์๋() {
+ int discount = EventCalculator.calculateSpecialDiscount(26);
+ assertEquals(0, discount);
+ }
+
+ @Test
+ void calculateGiveawayEvent() {
+ Map<Menu, Integer> giveaway = EventCalculator.calculateGiveawayEvent(120000);
+ assertNotNull(giveaway);
+ assertTrue(giveaway.containsKey(Menu.CHAMPAGNE));
+ assertEquals(1, giveaway.get(Menu.CHAMPAGNE));
+ }
+
+ @Test
+ void calculateBadge() {
+ assertEquals(Badge.SANTA, EventCalculator.calculateBadge(20000));
+ assertEquals(Badge.SANTA, EventCalculator.calculateBadge(30000));
+ assertEquals(Badge.TREE, EventCalculator.calculateBadge(15000));
+ assertEquals(Badge.TREE, EventCalculator.calculateBadge(19999));
+ assertEquals(Badge.STAR, EventCalculator.calculateBadge(7000));
+ assertEquals(Badge.NONE, EventCalculator.calculateBadge(4000));
+ }
+} | Java | ์ค... ์์ง ํ
์คํธ์ฝ๋๊ฐ ์ต์์น์์๋๋ฐ ํ์ฉํด ๋ณด๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,20 @@
+package christmas.domain.logic;
+
+import christmas.domain.model.DecemberEvent;
+
+public class ChristmasEventCalculator {
+ public static int calculateChristmasDiscount(int date) {
+ int startDay = DecemberEvent.getEventStartDate();
+ int discountPricePerDay = DecemberEvent.getDayDiscountPrice();
+ int discountPriceOfFirstDay = DecemberEvent.getStartDiscountPrice();
+
+ if (date > DecemberEvent.CHRISTMAS_DAY) {
+ return 0;
+ }
+
+ int daysUntilDate = date - startDay;
+ int totalDiscount = discountPriceOfFirstDay + (daysUntilDate * discountPricePerDay);
+
+ return totalDiscount;
+ }
+} | Java | ์ํ ๊ตณ์ด ๊ฐ์ฒด๊ฐ ์์ฑ๋ ํ์๊ฐ ์๊ตฐ์ |
@@ -0,0 +1,71 @@
+package christmas.domain.model;
+
+import christmas.domain.type.Menu;
+
+import java.util.*;
+
+public class DecemberEvent {
+ public static final int CHRISTMAS_DAY = 25;
+ private static final int EVENT_START_DATE = 1;
+ private static final int DAY_DISCOUNT_PRICE = 100;
+ private static final int START_DISCOUNT_PRICE = 1_000;
+ private static final int MIN_PRICE = 10_000;
+ private static final int WEEKDAY_DISCOUNT_PRICE = 2_023;
+ private static final int WEEKEND_DISCOUNT_PRICE = 2_023;
+ private static final Menu.Category WEEKDAY_DISCOUNT_CATEGORY = Menu.Category.DESSERT;
+ private static final Menu.Category WEEKEND_DISCOUNT_CATEGORY = Menu.Category.MAIN;
+ private static final List<Integer> WEEKEND_DATES = Arrays.asList(1, 2, 8, 9, 15, 16, 22, 23, 29, 30);
+ private static final List<Integer> STAR_DATES = Arrays.asList(3, 10, 17, 24, 25, 31);
+ private static final int SPECIAL_DISCOUNT_PRICE = 1_000;
+ private static final int GIVEAWAY_CONDITION_PRICE = 120_000;
+ private static final Map<Menu, Integer> GIVEAWAY_BENEFITS = Map.of(Menu.CHAMPAGNE, 1);
+
+
+ public static boolean isOverThanMinPrice(int totalPrice) {
+ return totalPrice >= MIN_PRICE;
+ }
+
+ public static boolean isStarDate(int date) {
+ return STAR_DATES.contains(date);
+ }
+
+ public static boolean isWeekend(int date) {
+ return WEEKEND_DATES.contains(date);
+ }
+
+ public static boolean isEligibleForGiveaway(int totalPrice) {
+ return totalPrice >= GIVEAWAY_CONDITION_PRICE;
+ }
+
+ public static int getSpecialDiscountPrice() {
+ return SPECIAL_DISCOUNT_PRICE;
+ }
+
+ public static int getWeekdayDiscountPrice() { return WEEKDAY_DISCOUNT_PRICE; }
+
+ public static int getWeekendDiscountPrice() { return WEEKEND_DISCOUNT_PRICE; }
+
+ public static Menu.Category getWeekdayDiscountCategory() {
+ return WEEKDAY_DISCOUNT_CATEGORY;
+ }
+
+ public static Menu.Category getWeekendDiscountCategory() {
+ return WEEKEND_DISCOUNT_CATEGORY;
+ }
+
+ public static Map<Menu, Integer> getGiveawayBenefits() {
+ return GIVEAWAY_BENEFITS;
+ }
+
+ public static int getDayDiscountPrice() {
+ return DAY_DISCOUNT_PRICE;
+ }
+
+ public static int getStartDiscountPrice() {
+ return START_DISCOUNT_PRICE;
+ }
+
+ public static int getEventStartDate() {
+ return EVENT_START_DATE;
+ }
+} | Java | 12์ ์ด๋ฒคํธ์๋ ํ ์ธ ๊ธ์ก์ด๋ ๊ธฐ๊ฐ๋ฑ์ด ์์ด์ ๋น์ฆ๋์ค ๋ก์ง๊ณผ ๋ฐ์ ํ๋ค๊ณ ์๊ฐํด์ ์ ๊ธฐ์ ์์นํ๊ธด ํ์ต๋๋ค. |
@@ -0,0 +1,103 @@
+package christmas.util;
+
+import christmas.domain.type.Menu;
+
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+public class OrderValidator {
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+
+ private static final int MIN_AMOUNT = 1;
+ private static final int MAX_AMOUNT = 20;
+ private static final String INPUT_PATTERN = "([\\S]+-\\d+)(,\\s*[\\S]+-\\d+)*";
+ private static final String INVALID_ORDER_MESSAGE = "์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String BEVERAGE_ONLY_MESSAGE = "์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String INVALID_ORDER_AMOUNT_MESSAGE = "๋ฉ๋ด๋ ํ ๋ฒ์ 1๊ฐ์ด์, ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String MENU_NOT_EXIST_MESSAGE = "์กด์ฌํ์ง ์๋ ๋ฉ๋ด์
๋๋ค.";
+ private static final String DUPLICATED_MENU_ORDER_MESSAGE = "์ค๋ณต๋ ๋ฉ๋ด ํญ๋ชฉ์ด ์์ต๋๋ค.";
+
+ public static void validateInput(String input) {
+ checkInputPattern(input);
+ checkInputPatternMore(input);
+ List<String> menuNames = parseMenuName(input);
+ checkDuplicated(menuNames);
+
+ for (String menuName : menuNames) {
+ checkMenu(menuName);
+ }
+ }
+
+ public static void validateOrder(Map<Menu, Integer> order) {
+ checkAmount(order);
+ checkBeverageOnly(order);
+ }
+
+ private static void checkBeverageOnly(Map<Menu, Integer> order) {
+ if (order.keySet()
+ .stream()
+ .allMatch(menu -> menu.getCategory() == Menu.Category.BEVERAGE)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + BEVERAGE_ONLY_MESSAGE);
+ }
+ }
+
+ private static void checkAmount(Map<Menu, Integer> order) {
+ int totalAmount = order.values()
+ .stream()
+ .mapToInt(Integer::intValue).sum();
+
+ if (totalAmount < MIN_AMOUNT || totalAmount > MAX_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+
+ for (Integer amount : order.values()) {
+ if (amount < MIN_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkMenu(String menuName) {
+ boolean menuExists = Arrays.stream(Menu.values()).anyMatch(menu -> menu.getName().equals(menuName));
+
+ if (!menuExists) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + MENU_NOT_EXIST_MESSAGE);
+ }
+ }
+ private static void checkDuplicated(List<String> menuNames) {
+ Set<String> uniqueMenuNames = new HashSet<>();
+
+ for (String name : menuNames) {
+ if (!uniqueMenuNames.add(name)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + DUPLICATED_MENU_ORDER_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkInputPattern(String input) {
+ if (input == null || !Pattern.matches(INPUT_PATTERN, input)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private static List<String> parseMenuName(String input) {
+ List<String> menuNames = Arrays.stream(input.split(","))
+ .map(order -> order.trim().split("-")[0].trim())
+ .collect(Collectors.toList());
+
+ return menuNames;
+ }
+
+ private static void checkInputPatternMore(String input) {
+ String[] items = input.split(",");
+
+ for (String item : items) {
+ int count = StringUtil.countMatches(item, '-');
+ if (count != 1) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+ }
+
+} | Java | ํด๋น ๊ท์น์ ๋ํ ์ฑ
์์ ๋ฉ๋ด๋ณด๋ค๋ ์ฃผ๋ฌธ๊ฒ์ฆ์ ์๋ค๊ณ ์๊ฐํด์ ์ ๋ ๊ฒ ๊ตฌํํ๊ธด ํ๋๋ฐ ๋ฉ๋ด๊ฐ ์ค์ค๋ก ํ๋จ ํ ์ ์๋๊ฒ์ ์ข๋ ๊ตฌ๋ถํด๋์ผ๋ฉด ๋ ์ข์์ง๊ฒ ๋ค์! |
@@ -0,0 +1,41 @@
+package christmas.domain.model;
+
+import christmas.domain.type.Menu;
+
+import java.util.Map;
+
+public class OrderInfo {
+ private final int date;
+ private final Map<Menu, Integer> order;
+ private final int totalOrderPrice;
+
+ public OrderInfo(int date, Map<Menu, Integer> order) {
+ this.date = date;
+ this.order = order;
+ this.totalOrderPrice = calculateTotalOrderPrice();
+ }
+
+ public int getDate() {
+ return date;
+ }
+ public Map<Menu, Integer> getOrder() {
+ return order;
+ }
+
+ public int getTotalOrderPrice() {
+ return totalOrderPrice;
+ }
+
+ private int calculateTotalOrderPrice() {
+ int totalOrderPrice = 0;
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalOrderPrice += menu.getPrice() * quantity;
+ }
+
+ return totalOrderPrice;
+ }
+} | Java | calculateTotalOrderPrice๋ก ํญ์ ๊ฐ์ ๊ตฌํ ์ ์์ผ๋ totalOrderPrice๋ฅผ ๋ฉค๋ฒ๋ณ์๋ก ๊ฐ๋ ๊ฒ ๋ณด๋ค ์ธ๋ถ์์ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ๋ฐฉ์์ ์ด๋ ์ ๊ฐ์? |
@@ -0,0 +1,58 @@
+package christmas.domain.type;
+
+public enum Menu {
+ //์ํผํ์ด์
+ MUSHROOM_SOUP("์์ก์ด์ํ", 6_000, Category.APPETIZER),
+ TAPAS("ํํ์ค", 5_500, Category.APPETIZER),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000, Category.APPETIZER),
+
+ //๋ฉ์ธ
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55_000, Category.MAIN),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", 54_000, Category.MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35_000, Category.MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000, Category.MAIN),
+
+ //๋์ ํธ
+ CHOCOLATE_CAKE("์ด์ฝ์ผ์ดํฌ", 15_000, Category.DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5_000, Category.DESSERT),
+
+ //์๋ฃ
+ ZERO_COKE("์ ๋ก์ฝ๋ผ", 3_000, Category.BEVERAGE),
+ RED_WINE("๋ ๋์์ธ", 60_000, Category.BEVERAGE),
+ CHAMPAGNE("์ดํ์ธ", 25_000, Category.BEVERAGE);
+
+ private final String name;
+ private final int price;
+ private final Category category;
+
+ Menu(String name, int price, Category category) {
+ this.name = name;
+ this.price = price;
+ this.category = category;
+ }
+
+ public static Menu findByName(String menuName) {
+ for (Menu menu : Menu.values()) {
+ if (menu.getName().equals(menuName)) {
+ return menu;
+ }
+ }
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public Category getCategory() {
+ return category;
+ }
+
+ public enum Category {
+ APPETIZER, MAIN, DESSERT, BEVERAGE
+ }
+} | Java | ์๋ฐ ์คํธ๋ฆผ api ๋ฅผ ์ฌ์ฉํ์๋ฉด ์ธ๋ดํธ๋ฅผ ์ค์ด๊ณ ๋ช
ํ์ฑ์ ๋์ด์ค ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,58 @@
+package christmas.domain.type;
+
+public enum Menu {
+ //์ํผํ์ด์
+ MUSHROOM_SOUP("์์ก์ด์ํ", 6_000, Category.APPETIZER),
+ TAPAS("ํํ์ค", 5_500, Category.APPETIZER),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000, Category.APPETIZER),
+
+ //๋ฉ์ธ
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55_000, Category.MAIN),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", 54_000, Category.MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35_000, Category.MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000, Category.MAIN),
+
+ //๋์ ํธ
+ CHOCOLATE_CAKE("์ด์ฝ์ผ์ดํฌ", 15_000, Category.DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5_000, Category.DESSERT),
+
+ //์๋ฃ
+ ZERO_COKE("์ ๋ก์ฝ๋ผ", 3_000, Category.BEVERAGE),
+ RED_WINE("๋ ๋์์ธ", 60_000, Category.BEVERAGE),
+ CHAMPAGNE("์ดํ์ธ", 25_000, Category.BEVERAGE);
+
+ private final String name;
+ private final int price;
+ private final Category category;
+
+ Menu(String name, int price, Category category) {
+ this.name = name;
+ this.price = price;
+ this.category = category;
+ }
+
+ public static Menu findByName(String menuName) {
+ for (Menu menu : Menu.values()) {
+ if (menu.getName().equals(menuName)) {
+ return menu;
+ }
+ }
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public Category getCategory() {
+ return category;
+ }
+
+ public enum Category {
+ APPETIZER, MAIN, DESSERT, BEVERAGE
+ }
+} | Java | InputView์์๋ ๋น์ทํ ์ฝ๋๋ก ๋ฉ๋ด ์ด๋ฆ์ ๊ฒ์ฆํ์๋๋ฐ null ์ ๋ฐํํ๋ ๋์ ์ฌ๊ธฐ์ ๋ฐ๋ก ์์ธ๋ฅผ ๋์ง์๋ ๊ฑด ์ด๋ ์ ๊ฐ์? |
@@ -0,0 +1,70 @@
+package christmas.domain.logic;
+
+import christmas.domain.model.DecemberEvent;
+import christmas.domain.type.Badge;
+import christmas.domain.type.Menu;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class EventCalculator {
+ public static boolean isEligibleForEvent(int totalPrice) {
+ return DecemberEvent.isOverThanMinPrice(totalPrice);
+ }
+
+ public static int calculateWeekdayDiscount(int date, Map<Menu, Integer> order) {
+ int totalDiscount = 0;
+ Menu.Category category = DecemberEvent.getWeekdayDiscountCategory();
+ int discountPrice = DecemberEvent.getWeekdayDiscountPrice();
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalDiscount += calculateDiscountByCategory(menu, quantity, category, discountPrice);
+ }
+
+ return totalDiscount;
+ }
+
+ public static int calculateWeekendDiscount(int date, Map<Menu, Integer> order) {
+ int totalDiscount = 0;
+ Menu.Category category = DecemberEvent.getWeekendDiscountCategory();
+ int discountPrice = DecemberEvent.getWeekendDiscountPrice();
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalDiscount += calculateDiscountByCategory(menu, quantity, category, discountPrice);
+ }
+
+ return totalDiscount;
+ }
+
+ public static int calculateSpecialDiscount(int date) {
+ if (DecemberEvent.isStarDate(date)) {
+ return DecemberEvent.getSpecialDiscountPrice();
+ }
+ return 0;
+ }
+
+ public static Map<Menu, Integer> calculateGiveawayEvent(int totalPrice) {
+ if (DecemberEvent.isEligibleForGiveaway(totalPrice)) {
+ return DecemberEvent.getGiveawayBenefits();
+ }
+ return Collections.emptyMap();
+ }
+
+ public static Badge calculateBadge(int totalDiscount) {
+ Badge badge = Badge.findByTotalDiscount(totalDiscount);
+ return badge;
+ }
+
+ private static int calculateDiscountByCategory(Menu menu, int quantity, Menu.Category category, int discountPrice) {
+ if (menu.getCategory().equals(category)) {
+ return quantity * discountPrice;
+ }
+ return 0;
+ }
+} | Java | ์ด ๋ฉ์๋์์ date๋ ์ฌ์ฉํ์ง ์๋๋ฐ ํ๋ผ๋ฏธํฐ๋ก ๋ฐ์ผ์๋ ์ด์ ๊ฐ ์์ผ์ค๊น์? |
@@ -0,0 +1,70 @@
+package christmas.domain.logic;
+
+import christmas.domain.model.DecemberEvent;
+import christmas.domain.type.Badge;
+import christmas.domain.type.Menu;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class EventCalculator {
+ public static boolean isEligibleForEvent(int totalPrice) {
+ return DecemberEvent.isOverThanMinPrice(totalPrice);
+ }
+
+ public static int calculateWeekdayDiscount(int date, Map<Menu, Integer> order) {
+ int totalDiscount = 0;
+ Menu.Category category = DecemberEvent.getWeekdayDiscountCategory();
+ int discountPrice = DecemberEvent.getWeekdayDiscountPrice();
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalDiscount += calculateDiscountByCategory(menu, quantity, category, discountPrice);
+ }
+
+ return totalDiscount;
+ }
+
+ public static int calculateWeekendDiscount(int date, Map<Menu, Integer> order) {
+ int totalDiscount = 0;
+ Menu.Category category = DecemberEvent.getWeekendDiscountCategory();
+ int discountPrice = DecemberEvent.getWeekendDiscountPrice();
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalDiscount += calculateDiscountByCategory(menu, quantity, category, discountPrice);
+ }
+
+ return totalDiscount;
+ }
+
+ public static int calculateSpecialDiscount(int date) {
+ if (DecemberEvent.isStarDate(date)) {
+ return DecemberEvent.getSpecialDiscountPrice();
+ }
+ return 0;
+ }
+
+ public static Map<Menu, Integer> calculateGiveawayEvent(int totalPrice) {
+ if (DecemberEvent.isEligibleForGiveaway(totalPrice)) {
+ return DecemberEvent.getGiveawayBenefits();
+ }
+ return Collections.emptyMap();
+ }
+
+ public static Badge calculateBadge(int totalDiscount) {
+ Badge badge = Badge.findByTotalDiscount(totalDiscount);
+ return badge;
+ }
+
+ private static int calculateDiscountByCategory(Menu menu, int quantity, Menu.Category category, int discountPrice) {
+ if (menu.getCategory().equals(category)) {
+ return quantity * discountPrice;
+ }
+ return 0;
+ }
+} | Java | Map<Menu, Integer> order ๋ก ์นดํ
์ฝ๋ฆฌ๋ณ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
์ ์์ผ๋ ์ด๋ฅผ OrderInfo ๋ชจ๋ธ์ ์ญํ ๋ก ๋๊ธฐ์๋ ๊ฑด ์ด๋ ์ค๊น์? |
@@ -0,0 +1,61 @@
+package christmas.domain.model;
+
+import christmas.domain.type.Badge;
+import christmas.domain.type.Benefit;
+
+import java.util.Map;
+
+public class EventResult {
+ private final OrderInfo orderInfo;
+ private final Map<Benefit, Integer> benefitHistory;
+ private final int totalBenefitsPrice;
+ private final int finalPrice;
+ private final Badge badge;
+
+ public EventResult(OrderInfo orderInfo, Map<Benefit, Integer> benefitHistory, int totalBenefitsPrice, Badge badge) {
+ this.orderInfo = orderInfo;
+ this.benefitHistory = benefitHistory;
+ this.totalBenefitsPrice = totalBenefitsPrice;
+ this.finalPrice = calculateFinalPrice();
+ this.badge = badge;
+ }
+
+ // getter
+ public OrderInfo getOrder() {
+ return orderInfo;
+ }
+
+ public Map<Benefit, Integer> getBenefitHistory() {
+ return benefitHistory;
+ }
+
+ public int getTotalBenefitsPrice() {
+ return totalBenefitsPrice;
+ }
+
+ public int getFinalPrice() {
+ return finalPrice;
+ }
+
+ public Badge getBadge() {
+ return badge;
+ }
+
+ public boolean hasGiveawayBenefits() {
+ if (benefitHistory.containsKey(Benefit.GIVEAWAY)) {
+ return true;
+ }
+ return false;
+ }
+
+ //private ํฌํผ
+ private int calculateFinalPrice() {
+ int finalPrice = orderInfo.getTotalOrderPrice() - totalBenefitsPrice;
+
+ if (benefitHistory.containsKey(Benefit.GIVEAWAY)) {
+ finalPrice += benefitHistory.get(Benefit.GIVEAWAY);
+ }
+
+ return finalPrice;
+ }
+} | Java | EventResult๋ dto๋ก ์ฌ์ฉํ์ ๊ฑธ๊น์? |
@@ -0,0 +1,103 @@
+package christmas.util;
+
+import christmas.domain.type.Menu;
+
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+public class OrderValidator {
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+
+ private static final int MIN_AMOUNT = 1;
+ private static final int MAX_AMOUNT = 20;
+ private static final String INPUT_PATTERN = "([\\S]+-\\d+)(,\\s*[\\S]+-\\d+)*";
+ private static final String INVALID_ORDER_MESSAGE = "์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String BEVERAGE_ONLY_MESSAGE = "์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String INVALID_ORDER_AMOUNT_MESSAGE = "๋ฉ๋ด๋ ํ ๋ฒ์ 1๊ฐ์ด์, ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String MENU_NOT_EXIST_MESSAGE = "์กด์ฌํ์ง ์๋ ๋ฉ๋ด์
๋๋ค.";
+ private static final String DUPLICATED_MENU_ORDER_MESSAGE = "์ค๋ณต๋ ๋ฉ๋ด ํญ๋ชฉ์ด ์์ต๋๋ค.";
+
+ public static void validateInput(String input) {
+ checkInputPattern(input);
+ checkInputPatternMore(input);
+ List<String> menuNames = parseMenuName(input);
+ checkDuplicated(menuNames);
+
+ for (String menuName : menuNames) {
+ checkMenu(menuName);
+ }
+ }
+
+ public static void validateOrder(Map<Menu, Integer> order) {
+ checkAmount(order);
+ checkBeverageOnly(order);
+ }
+
+ private static void checkBeverageOnly(Map<Menu, Integer> order) {
+ if (order.keySet()
+ .stream()
+ .allMatch(menu -> menu.getCategory() == Menu.Category.BEVERAGE)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + BEVERAGE_ONLY_MESSAGE);
+ }
+ }
+
+ private static void checkAmount(Map<Menu, Integer> order) {
+ int totalAmount = order.values()
+ .stream()
+ .mapToInt(Integer::intValue).sum();
+
+ if (totalAmount < MIN_AMOUNT || totalAmount > MAX_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+
+ for (Integer amount : order.values()) {
+ if (amount < MIN_AMOUNT) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + INVALID_ORDER_AMOUNT_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkMenu(String menuName) {
+ boolean menuExists = Arrays.stream(Menu.values()).anyMatch(menu -> menu.getName().equals(menuName));
+
+ if (!menuExists) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + MENU_NOT_EXIST_MESSAGE);
+ }
+ }
+ private static void checkDuplicated(List<String> menuNames) {
+ Set<String> uniqueMenuNames = new HashSet<>();
+
+ for (String name : menuNames) {
+ if (!uniqueMenuNames.add(name)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE + LINE_SEPARATOR + DUPLICATED_MENU_ORDER_MESSAGE);
+ }
+ }
+ }
+
+ private static void checkInputPattern(String input) {
+ if (input == null || !Pattern.matches(INPUT_PATTERN, input)) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private static List<String> parseMenuName(String input) {
+ List<String> menuNames = Arrays.stream(input.split(","))
+ .map(order -> order.trim().split("-")[0].trim())
+ .collect(Collectors.toList());
+
+ return menuNames;
+ }
+
+ private static void checkInputPatternMore(String input) {
+ String[] items = input.split(",");
+
+ for (String item : items) {
+ int count = StringUtil.countMatches(item, '-');
+ if (count != 1) {
+ throw new ValidationException(INVALID_ORDER_MESSAGE);
+ }
+ }
+ }
+
+} | Java | More ๋ณด๋ค ๋ฉ์๋ ์๋๋ฅผ ๋ํ๋ด๋ ๋ฉ์๋๋ช
์ ์ฌ์ฉํ์๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,41 @@
+package christmas.domain.model;
+
+import christmas.domain.type.Menu;
+
+import java.util.Map;
+
+public class OrderInfo {
+ private final int date;
+ private final Map<Menu, Integer> order;
+ private final int totalOrderPrice;
+
+ public OrderInfo(int date, Map<Menu, Integer> order) {
+ this.date = date;
+ this.order = order;
+ this.totalOrderPrice = calculateTotalOrderPrice();
+ }
+
+ public int getDate() {
+ return date;
+ }
+ public Map<Menu, Integer> getOrder() {
+ return order;
+ }
+
+ public int getTotalOrderPrice() {
+ return totalOrderPrice;
+ }
+
+ private int calculateTotalOrderPrice() {
+ int totalOrderPrice = 0;
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalOrderPrice += menu.getPrice() * quantity;
+ }
+
+ return totalOrderPrice;
+ }
+} | Java | ์์ ์ด ๊ฐ์ง ๊ฐ์ผ๋ก ํ๋ฒ ์ ํด์ง๊ณ ๋ณํ์ง ์๋ ๊ฐ์ด์ด์ ์ด๋ ๊ฒ ๊ตฌํํ์ต๋๋ค!
orderInfo์ ๊ฐ์ ๋ค๋ฅธ ๊ณณ์์ ํ์ฉ๋ฉ๋๋ค |
@@ -0,0 +1,58 @@
+package christmas.domain.type;
+
+public enum Menu {
+ //์ํผํ์ด์
+ MUSHROOM_SOUP("์์ก์ด์ํ", 6_000, Category.APPETIZER),
+ TAPAS("ํํ์ค", 5_500, Category.APPETIZER),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000, Category.APPETIZER),
+
+ //๋ฉ์ธ
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55_000, Category.MAIN),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", 54_000, Category.MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35_000, Category.MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000, Category.MAIN),
+
+ //๋์ ํธ
+ CHOCOLATE_CAKE("์ด์ฝ์ผ์ดํฌ", 15_000, Category.DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5_000, Category.DESSERT),
+
+ //์๋ฃ
+ ZERO_COKE("์ ๋ก์ฝ๋ผ", 3_000, Category.BEVERAGE),
+ RED_WINE("๋ ๋์์ธ", 60_000, Category.BEVERAGE),
+ CHAMPAGNE("์ดํ์ธ", 25_000, Category.BEVERAGE);
+
+ private final String name;
+ private final int price;
+ private final Category category;
+
+ Menu(String name, int price, Category category) {
+ this.name = name;
+ this.price = price;
+ this.category = category;
+ }
+
+ public static Menu findByName(String menuName) {
+ for (Menu menu : Menu.values()) {
+ if (menu.getName().equals(menuName)) {
+ return menu;
+ }
+ }
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public Category getCategory() {
+ return category;
+ }
+
+ public enum Category {
+ APPETIZER, MAIN, DESSERT, BEVERAGE
+ }
+} | Java | ๋ค์ฌ๋ ์ฝ๋์์ ํ์ ๋ฐฐ์ ์ต๋๋ค! |
@@ -0,0 +1,58 @@
+package christmas.domain.type;
+
+public enum Menu {
+ //์ํผํ์ด์
+ MUSHROOM_SOUP("์์ก์ด์ํ", 6_000, Category.APPETIZER),
+ TAPAS("ํํ์ค", 5_500, Category.APPETIZER),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000, Category.APPETIZER),
+
+ //๋ฉ์ธ
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55_000, Category.MAIN),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", 54_000, Category.MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35_000, Category.MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000, Category.MAIN),
+
+ //๋์ ํธ
+ CHOCOLATE_CAKE("์ด์ฝ์ผ์ดํฌ", 15_000, Category.DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5_000, Category.DESSERT),
+
+ //์๋ฃ
+ ZERO_COKE("์ ๋ก์ฝ๋ผ", 3_000, Category.BEVERAGE),
+ RED_WINE("๋ ๋์์ธ", 60_000, Category.BEVERAGE),
+ CHAMPAGNE("์ดํ์ธ", 25_000, Category.BEVERAGE);
+
+ private final String name;
+ private final int price;
+ private final Category category;
+
+ Menu(String name, int price, Category category) {
+ this.name = name;
+ this.price = price;
+ this.category = category;
+ }
+
+ public static Menu findByName(String menuName) {
+ for (Menu menu : Menu.values()) {
+ if (menu.getName().equals(menuName)) {
+ return menu;
+ }
+ }
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public Category getCategory() {
+ return category;
+ }
+
+ public enum Category {
+ APPETIZER, MAIN, DESSERT, BEVERAGE
+ }
+} | Java | ์ฑ
์์ ๋ถ๋ฆฌํ๋ ค๊ณ ๊ทธ๋ ๊ฒ ์์ฑํ์ต๋๋ค.
๋ฐ๋ก ๋ฉ๋ด์์ ์์ธ๋ฅผ ๋์ง๋ฉด ์ถ์ ํ๊ธฐ ์ฌ์ธ์ ์๊ฒ ๋ค์ |
@@ -0,0 +1,41 @@
+package christmas.domain.model;
+
+import christmas.domain.type.Menu;
+
+import java.util.Map;
+
+public class OrderInfo {
+ private final int date;
+ private final Map<Menu, Integer> order;
+ private final int totalOrderPrice;
+
+ public OrderInfo(int date, Map<Menu, Integer> order) {
+ this.date = date;
+ this.order = order;
+ this.totalOrderPrice = calculateTotalOrderPrice();
+ }
+
+ public int getDate() {
+ return date;
+ }
+ public Map<Menu, Integer> getOrder() {
+ return order;
+ }
+
+ public int getTotalOrderPrice() {
+ return totalOrderPrice;
+ }
+
+ private int calculateTotalOrderPrice() {
+ int totalOrderPrice = 0;
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalOrderPrice += menu.getPrice() * quantity;
+ }
+
+ return totalOrderPrice;
+ }
+} | Java | date์ ๋ํ validation์ InputView์์ ์งํํ์
จ๊ตฐ์!
์ ๋ ์ด ๋ถ๋ถ์ ๋ํด์ ์ด๋ค ๊ฒ์ด ๋ ํจ์จ์ ์ผ๊น ๊ณ ๋ฏผ์ ๋ง์ด ํด๋ดค๋๋ฐ @T3rryAhn ๋์ ์๊ฐ์ ์ด๋ค ์ง ์ฌ์ญ๊ณ ์ถ์ต๋๋ค.
์ ๋ ์ฒ์์๋ ์
๋ ฅ๊ฐ์ ๋ํ validation์ InputView์์ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ์ข์์ง domain์์ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ์ข์ ์ง ๊ณ ๋ฏผ์ ๋ง์ด ํ์๋๋ฐ์. ํ๋ก๊ทธ๋จ์ด ๋ณต์กํด์ง ์๋ก InputView๊ฐ ๊ฒ์ฆํด์ผํ validation์ ์ข
๋ฅ๊ฐ ๋ง์์ง์ผ๋ก ์ ๋ validation์ domain์ผ๋ก ์ฑ
์์ ๋๊ธฐ๋ ๊ฒ์ด ๋ ์ข๋ค๊ณ ํ๋จํ์ต๋๋ค.
์๋ฅผ ๋ค์ด ์ ๋ InputView์์ validation์ ์ต์ํ์ ์
๋ ฅ ์ค๋ฅ(Ex. `NumberFormatException`, ๋น ์
๋ ฅ๊ฐ, ๊ธ์์ ์ ํ ๋ฑ)๋ง ๊ฒ์ฆํ๊ณ , ์
๋ ฅ์ด domain ๊ด๋ จ ๊ฐ์ผ๋ก ์ ํจํ ์ง ํ๋จํ๋ ๊ฑด, ๋ชจ๋ธ ๊ฐ์ฒด ์ค์ค๋ก๊ฐ ์์ ์ ๊ฐ์ ๊ฒ์ฆํ๋๋ก ๊ตฌ์กฐ๋ฅผ ์ธ์ ์ต๋๋ค.
@T3rryAhn ๋์ ์๊ฐ์ ์ด๋ ์ ๊ฐ์?
์ฐธ๊ณ : https://tecoble.techcourse.co.kr/post/2020-05-29-wrap-primitive-type/ |
@@ -0,0 +1,41 @@
+package christmas.domain.model;
+
+import christmas.domain.type.Menu;
+
+import java.util.Map;
+
+public class OrderInfo {
+ private final int date;
+ private final Map<Menu, Integer> order;
+ private final int totalOrderPrice;
+
+ public OrderInfo(int date, Map<Menu, Integer> order) {
+ this.date = date;
+ this.order = order;
+ this.totalOrderPrice = calculateTotalOrderPrice();
+ }
+
+ public int getDate() {
+ return date;
+ }
+ public Map<Menu, Integer> getOrder() {
+ return order;
+ }
+
+ public int getTotalOrderPrice() {
+ return totalOrderPrice;
+ }
+
+ private int calculateTotalOrderPrice() {
+ int totalOrderPrice = 0;
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalOrderPrice += menu.getPrice() * quantity;
+ }
+
+ return totalOrderPrice;
+ }
+} | Java | Map<Menu, Integer>์ ๊ฒฝ์ฐ ์ปฌ๋ ์
์ ํด๋นํฉ๋๋ค.
์ด ๊ฒฝ์ฐ ์ผ๊ธ ์ปฌ๋ ์
์ ์ฌ์ฉํด์ ๊ด๋ฆฌํ๋ ๊ฑด ์ด๋จ๊น์?
์ฐธ๊ณ : https://tecoble.techcourse.co.kr/post/2020-05-08-First-Class-Collection/ |
@@ -0,0 +1,41 @@
+package christmas.domain.model;
+
+import christmas.domain.type.Menu;
+
+import java.util.Map;
+
+public class OrderInfo {
+ private final int date;
+ private final Map<Menu, Integer> order;
+ private final int totalOrderPrice;
+
+ public OrderInfo(int date, Map<Menu, Integer> order) {
+ this.date = date;
+ this.order = order;
+ this.totalOrderPrice = calculateTotalOrderPrice();
+ }
+
+ public int getDate() {
+ return date;
+ }
+ public Map<Menu, Integer> getOrder() {
+ return order;
+ }
+
+ public int getTotalOrderPrice() {
+ return totalOrderPrice;
+ }
+
+ private int calculateTotalOrderPrice() {
+ int totalOrderPrice = 0;
+
+ for (Map.Entry<Menu, Integer> entry : order.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ totalOrderPrice += menu.getPrice() * quantity;
+ }
+
+ return totalOrderPrice;
+ }
+} | Java | 3์ฃผ์ฐจ ๊ณตํต ํผ๋๋ฐฑ์์ '**๊ฐ์ฒด๋ ๊ฐ์ฒด๋ต๊ฒ **'๋ผ๋ ๊ฒ์ด ์์์ต๋๋ค.
์ด ๊ฒฝ์ฐ `private final Map<Menu, Integer> order;`์ผ๋ก ์ ์ธํ order์ ๋ฐํํ๋๋ฐ์.
Map<Menu, Integer>์ ์ปฌ๋ ์
์ค์ ํ๋์
๋๋ค.
๋ฐ๋ผ์ final ํค์๋๋ฅผ ์ฌ์ฉํ๋ค๊ณ ํด๋ ๊ฐ์ ๋ณ๊ฒฝ์ด ๋ฐ์ํ ์ ์์ต๋๋ค ใ
ใ
กใ
.
๋ฐ๋ผ์ ์ปฌ๋ ์
๋ณ์๋ ์ต๋ํ getter ์ฌ์ฉ์ ์ง์ํ๊ณ ๊ฐ์ฒด์ ๋ฉ์์ง๋ฅผ ๋์ง๋ ๋ฐฉ์์ผ๋ก ์ฒ๋ฆฌํ๋ฉด ์ข์๋ฐ์.
์์ comment์ ์ฐ๊ดํ์ฌ '์ผ๊ธ์ปฌ๋ ์
' ๊ฐ๋
์ด ๋ง์ด ๋์ ๋์ค ๊ฒ ๊ฐ์ต๋๋ค!
์ฐธ๊ณ : https://tecoble.techcourse.co.kr/post/2020-05-08-First-Class-Collection/ |
@@ -0,0 +1,112 @@
+package christmas.view;
+
+import christmas.domain.model.DecemberEvent;
+import christmas.domain.model.EventResult;
+import christmas.domain.type.Badge;
+import christmas.domain.type.Benefit;
+import christmas.domain.type.Menu;
+import christmas.util.MapToStringConverter;
+
+import java.util.Map;
+
+public class OutputView {
+ private static final String LINE_SEPARATOR = System.lineSeparator();
+ private static final String INTRO_MESSAGE = "์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.";
+ private static final String RESULT_INTRO_MESSAGE = "12์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!";
+ private static final String EVENT_CAUTION = "์ด๋ฒคํธ ์ฃผ์ ์ฌํญ!" + LINE_SEPARATOR +
+ " - ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์๋ถํฐ ์ด๋ฒคํธ๊ฐ ์ ์ฉ๋ฉ๋๋ค." + LINE_SEPARATOR +
+ " - ์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์ฃผ๋ฌธํ ์ ์์ต๋๋ค." + LINE_SEPARATOR +
+ " - ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค." + LINE_SEPARATOR;
+ private static final String RESULT_HEAD_ORDERED_MENU = "<์ฃผ๋ฌธ ๋ฉ๋ด>";
+ private static final String RESULT_HEAD_TOTAL_PRICE = "<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>";
+ private static final String RESULT_HEAD_GIVEAWAY_MENU = "<์ฆ์ ๋ฉ๋ด>";
+ private static final String RESULT_HEAD_BENEFIT_DETAILS = "<ํํ ๋ด์ญ>";
+ private static final String RESULT_HEAD_TOTAL_BENEFIT_PRICE = "<์ดํํ ๊ธ์ก>";
+ private static final String RESULT_HEAD_DISCOUNTED_TOTAL_PRICE = "<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>";
+ private static final String RESULT_HEAD_BADGE = "<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>";
+ private static final String PRICE = "%,d์";
+ private static final String NONE = "์์";
+
+ public void printIntro() {
+ System.out.printf(INTRO_MESSAGE + LINE_SEPARATOR);
+ }
+
+ public void printCaution() {
+ System.out.printf(EVENT_CAUTION + LINE_SEPARATOR);
+ }
+
+ public void printResult(EventResult eventResult) {
+ printResultIntro(eventResult.getOrder().getDate());
+ printOrder(eventResult.getOrder().getOrder());
+ printTotalPrice(eventResult.getOrder().getTotalOrderPrice());
+ printGiveawayMenu(eventResult.hasGiveawayBenefits());
+ printBenefitDetails(eventResult.getBenefitHistory());
+ printTotalBenefitPrice(eventResult.getTotalBenefitsPrice());
+ printDiscountedPrice(eventResult.getFinalPrice());
+ printBadge(eventResult.getBadge());
+ }
+
+ public void printResultIntro(int date) {
+ System.out.printf(LINE_SEPARATOR + RESULT_INTRO_MESSAGE + LINE_SEPARATOR, date);
+ }
+
+ public void printOrder(Map<Menu, Integer> order) {
+ System.out.printf(LINE_SEPARATOR + RESULT_HEAD_ORDERED_MENU + LINE_SEPARATOR);
+ String result = MapToStringConverter.orderToString(order);
+ System.out.printf(result);
+ }
+
+
+
+ public void printTotalPrice(int totalOrderPrice) {
+ System.out.printf(LINE_SEPARATOR + RESULT_HEAD_TOTAL_PRICE + LINE_SEPARATOR);
+
+ int price = totalOrderPrice;
+ System.out.printf(PRICE, price);
+ System.out.println();
+ }
+
+ public void printGiveawayMenu(boolean hasGiveawayBenefits) {
+ System.out.printf(LINE_SEPARATOR + RESULT_HEAD_GIVEAWAY_MENU + LINE_SEPARATOR);
+
+ String result = NONE + LINE_SEPARATOR;
+
+ if (hasGiveawayBenefits) {
+ result = MapToStringConverter.orderToString(DecemberEvent.getGiveawayBenefits());
+ }
+
+ System.out.printf(result);
+ }
+
+ public void printBenefitDetails(Map<Benefit, Integer> benefitAndPrice) {
+ System.out.printf(LINE_SEPARATOR + RESULT_HEAD_BENEFIT_DETAILS + LINE_SEPARATOR);
+ String result = NONE + LINE_SEPARATOR;
+
+ if (!benefitAndPrice.isEmpty()) {
+ result = MapToStringConverter.benefitToString(benefitAndPrice);
+ }
+
+ System.out.printf(result);
+ }
+
+ public void printTotalBenefitPrice(int totalBenefitPrice) {
+ System.out.printf(LINE_SEPARATOR + RESULT_HEAD_TOTAL_BENEFIT_PRICE + LINE_SEPARATOR);
+ String result = "-" + PRICE + LINE_SEPARATOR;
+ if (totalBenefitPrice == 0) {
+ result = PRICE + "\n";
+ }
+ System.out.printf(result, totalBenefitPrice);
+ }
+
+ public void printDiscountedPrice(int finalPrice) {
+ System.out.printf(LINE_SEPARATOR + RESULT_HEAD_DISCOUNTED_TOTAL_PRICE + LINE_SEPARATOR);
+
+ System.out.printf(PRICE + LINE_SEPARATOR, finalPrice);
+ }
+
+ public void printBadge(Badge badge) {
+ System.out.printf(LINE_SEPARATOR + RESULT_HEAD_BADGE + LINE_SEPARATOR);
+
+ System.out.printf(badge.getName() + LINE_SEPARATOR);
+ }
+} | Java | OutputView์์ ์ฌ์ฉ๋๋ ์์๊ฐ ๊ฒฝ์ฐ, enum์ผ๋ก ๋ฌถ์ด์ ๊ด๋ฆฌํ๋ฉด ์ฝ๋๊ฐ ํจ์ฌ ๊น๋ํ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,173 @@
+์์ฑ์: ์ํ๋ฆฌ
+
+# ๐
ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
+
+**์ด๋ฒคํธ ๋ชฉํ**
+````
+1. ์ค๋ณต๋ ํ ์ธ๊ณผ ์ฆ์ ์ ํ์ฉํด์, ๊ณ ๊ฐ๋ค์ด ํํ์ ๋ง์ด ๋ฐ๋๋ค๋ ๊ฒ์ ์ฒด๊ฐํ ์ ์๊ฒ ํ๋ ๊ฒ
+2. ์ฌํด 12์์ ์ง๋ 5๋
์ค ์ต๊ณ ์ ํ๋งค ๊ธ์ก์ ๋ฌ์ฑ
+3. 12์ ์ด๋ฒคํธ ์ฐธ์ฌ ๊ณ ๊ฐ์ 5%๊ฐ ๋ด๋
1์ ์ํด ์ด๋ฒคํธ์ ์ฌ์ฐธ์ฌํ๋ ๊ฒ
+````
+
+---------------
+## โ ๊ธฐ๋ฅ ๋ชฉ๋ก
+
+### ์ฌ์ฉ์ ์ธํฐํ์ด์ค
+ - ์ฌ์ฉ์์๊ฒ ์
๋ ฅ์ ์์ฒญํ๋ ์๋ด ๋ฉ์์ง ์ถ๋ ฅ
+ - ์ฌ์ฉ์ ์
๋ ฅ ์๋ฌ ๋ฐ์ ์, '[ERROR]'๋ก ์์ํ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅ
+### ๋ ์ง ์
๋ ฅ ๋ฐ ๊ฒ์ฆ
+ - ์ฌ์ฉ์๋ก๋ถํฐ 12์ ์ค ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์ซ์๋ก ์
๋ ฅ๋ฐ์
+ - ์
๋ ฅ๋ฐ์ ๋ ์ง๊ฐ 1 ์ด์ 31 ์ดํ์ธ์ง ๊ฒ์ฆ
+ - ์ ํจํ์ง ์์ ๋ ์ง ์
๋ ฅ ์ ์๋ฌ ๋ฉ์์ง ์ ๋ฌ ๋ฐ ์ฌ์
๋ ฅ ์์ฒญ
+### ๋ฉ๋ด ์ฃผ๋ฌธ ์
๋ ฅ ๋ฐ ๊ฒ์ฆ
+ - ์ฌ์ฉ์๋ก๋ถํฐ ์ฃผ๋ฌธํ ๋ฉ๋ด์ ์๋์ ์
๋ ฅ๋ฐ์ (์: ํด์ฐ๋ฌผํ์คํ-2, ๋ ๋์์ธ-1)
+ - ์
๋ ฅ๋ฐ์ ๋ฉ๋ด๊ฐ ๋ฉ๋ดํ์ ์๋์ง, ์๋์ด ์ ํจํ์ง ์ฃผ๋ฌธ ๊ฒ์ฆ
+ - ์ ํจํ์ง ์์ ์ฃผ๋ฌธ ์
๋ ฅ ์ ์๋ฌ ๋ฉ์์ง ์ ๋ฌ ๋ฐ ์ฌ์
๋ ฅ ์์ฒญ
+### ํ ์ธ ๋ฐ ์ฆ์ ์ด๋ฒคํธ ๊ณ์ฐ
+ - ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ณ์ฐ
+ - ํ์ผ ํ ์ธ ๊ณ์ฐ (๋์ ํธ ๋ฉ๋ด)
+ - ์ฃผ๋ง ํ ์ธ ๊ณ์ฐ (๋ฉ์ธ ๋ฉ๋ด)
+ - ํน๋ณ ํ ์ธ ๊ณ์ฐ (๋ฌ๋ ฅ์ ๋ณ ํ์๋ ๋ )
+ - ์ฆ์ ์ด๋ฒคํธ ์ ์ฉ (์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๊ฒฝ์ฐ ์ดํ์ธ ์ฆ์ )
+### ํํ ๋ด์ญ ๋ฐ ์ดํํ ๊ธ์ก ๊ณ์ฐ
+ - ํ ์ธ ๊ธ์ก์ ํฉ๊ณ ๊ณ์ฐ
+ - ์ฆ์ ๋ฉ๋ด ๊ฐ๊ฒฉ ๊ณ์ฐ
+ - ์ดํํ ๊ธ์ก ๊ณ์ฐ
+### ์์ ๊ฒฐ์ ๊ธ์ก ๊ณ์ฐ
+ - ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ๊ณ์ฐ
+### ์ด๋ฒคํธ ๋ฐฐ์ง ๋ถ์ฌ
+ - ์ดํํ ๊ธ์ก์ ๋ฐ๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง ๋ถ์ฌ (๋ณ, ํธ๋ฆฌ, ์ฐํ)
+### ๊ฒฐ๊ณผ ์ถ๋ ฅ
+ - ์ฃผ๋ฌธ ๋ฉ๋ด, ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก, ์ฆ์ ๋ฉ๋ด, ํํ ๋ด์ญ, ์ดํํ ๊ธ์ก, ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก, ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅ
+### ๋จ์ ํ
์คํธ
+ - ๊ฐ ๊ธฐ๋ฅ๋ณ๋ก JUnit 5์ AssertJ๋ฅผ ์ด์ฉํ์ฌ ๋จ์ ํ
์คํธ ์์ฑ
+
+------------
+
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
ํ๋ก์ ํธ ๊ตฌ์กฐ
+
+```
+๐ป๐main
+ ๐ป๐java
+ ๐ป๐christmas
+ ๐ป๐controller
+ EventPlanner.java
+ ๐ป๐domain
+ ๐ป๐logic
+ ChristmasEventCalculator.java
+ EventCalculator.java
+ EventService.java
+ ๐ป๐model
+ DecemberEvent.java
+ EventResult.java
+ OrderInfo.java
+ ๐ป๐type
+ Badge.java (enum)
+ Benefit.java (enum)
+ Menu.java (enum)
+ ๐ป๐view
+ InputView.java
+ OutputView.java
+ ๐ป๐util
+ DateValidator.java
+ MapToStringConverter.java
+ OrderValidator.java
+ StringUtil.java
+ ValidationException.java
+ Application.java
+```
+### ์ค๋ช
+#### controller
+> ์ฌ์ฉ์์ ์์ฒญ์ ์ฒ๋ฆฌํ๊ณ , ๋ชจ๋ธ์ ์กฐ์, ์ ์ ํ ์๋ต์ ๋ทฐ์ ์ ๋ฌํ๋ ํด๋์ค๊ฐ ์์นํฉ๋๋ค.
+
+#### domain
+> ๋๋ฉ์ธ ๋ก์ง์ ๋ด๋นํ๋ ํด๋์ค๋ค์ด ์์นํฉ๋๋ค. <br>
+
+- #### logic
+> **EventCalculator**: ์ด๋ฒคํธ ํ ์ธ์ ๊ณ์ฐํฉ๋๋ค. <br>
+> **ChristmasEventCalculator**: ๋ ์ง ๊ธฐ๋ฐ ํ ์ธ ๋ก์ง์ ์ฒ๋ฆฌํฉ๋๋ค. <br>
+> **EventService**: ์ฃผ๋ฌธ ์ ๋ณด๋ก ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ๋ง๋ค์ด์ฃผ๋ ํด๋์ค์
๋๋ค. <br>
+
+- #### model
+> **DecemberEvent**: ์ด๋ฒคํธ ๊ด๋ จ ๋ก์ง์ ์ฒ๋ฆฌํฉ๋๋ค. <br>
+> **EventResult**: ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ๋ด๋ ํด๋์ค์
๋๋ค. <br>
+> **OrderInfo**: ์ฃผ๋ฌธ ์ ๋ณด๋ฅผ ๋ด๋ ํด๋์ค์
๋๋ค. <br>
+
+- #### type
+> **Benefit**: ํํ ์ข
๋ฅ๋ฅผ ๋ํ๋ด๋ ์ด๊ฑฐํ์
๋๋ค. <br>
+> **Menu**: ๋ฉ๋ด๋ฅผ ๋ํ๋ด๋ ์ด๊ฑฐํ์
๋๋ค. <br>
+> **Badge**: ๋ฑ์ง๋ฅผ ๋ํ๋ด๋ ์ด๊ฑฐํ์
๋๋ค. <br>
+
+
+#### view
+> ์ฌ์ฉ์ ์ธํฐํ์ด์ค๋ฅผ ๋ด๋นํ๋ ํด๋์ค๋ค์ด ์์นํฉ๋๋ค. <br>
+>
+> **InputView**: ์ฌ์ฉ์ ์
๋ ฅ์ ์ฒ๋ฆฌ. <br>
+> **OutputView**: ๊ฒฐ๊ณผ ์ถ๋ ฅ์ ์ฒ๋ฆฌ. <br>
+
+#### util
+> ์ ํธ๋ฆฌํฐ ํด๋์ค๋ค์ด ์์นํฉ๋๋ค. <br>
+>
+> **DateValidator**: ๋ ์ง ์ ํจ์ฑ ๊ฒ์ฌ ๋ก์ง์ ํฌํจ. <br>
+> **MapToStringConverter**: Map์ key, value ๊ฐ์ ๋ฌธ์์ด๋ก ๋ณํํ๋ ์์
์ฒ๋ฆฌ. <br>
+> **OrderValidator**: ๋ฉ๋ด์ ์๋ ์
๋ ฅ ์ ํจ์ฑ ๊ฒ์ฌ ๋ก์ง์ ํฌํจ. <br>
+> **StringUtil**: ๋ฌธ์์ด์ ํํท ๋ฌธ์๊ฐ ๋ช๊ฐ์๋์ง ์นด์ดํธํ๋ ๊ธฐ๋ฅ. <br>
+> **ValidationException**: ์ฌ์ฉ์ ์ ์ ์์ธ์ฒ๋ฆฌ ํด๋์ค. <br>
+
+----------------------
+## ๋์
+````
+1. Applicaton ์์ InputView, OutputView ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ EventPlaner(inputView, outputView)์ ์ฃผ์
์์ผ EventPlanner๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค.
+2. EventPlanner์์ InputView๋ฅผ ํตํด ์ฌ์ฉ์์๊ฒ ๋ ์ง(int date)์ ์ฃผ๋ฌธ(Map<๋ฉ๋ด, ์๋>)์ ๊ฒ์ฆํ ์
๋ ฅ๋ฐ๋๋ค.
+3. EventService(๋ ์ง, ์ฃผ๋ฌธ)์ ์ฃผ์
ํด ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค. eventService(๊ฐ์ฒด)๊ฐ ์์ฑ๋จ๊ณผ ๋์์ orderInfo(๊ฐ์ฒด)๊ฐ ์์ฑ๋๋ค.
+4. orderInfo๋ ์ค์ค๋ก ์ฃผ๋ฌธ ์ด์ก์ ๊ณ์ฐํด์ ์์ฑ๋๋ค. orderInfo์ ์ ๋ณด๋ฅผ ์ฌ์ฉํด
+ eventService์์ ๋ก์ง์ ๊ณ์ฐ๊ธฐ(EventCalculator, ChristmasEventCalculator) ํด๋์ค๋ค์ ํ์ฉํด ํ ์ธ ํํ์ ๊ณ์ฐํ๋ค.
+5. ๊ณ์ฐ๊ธฐ๋ค์ DecemberEvent์๊ฒ ํ ์ธ ์ฌ๋ถ๋ฅผ ๋ฌป๋๋ค.
+6. eventService์์ ๊ณ์ฐ๋ ๊ฐ๋ค๋ก eventResult๋ฅผ ์์ฑํ๋ค.
+7. eventResult์ ๊ฐ๋ค์ outView์์ ์ถ๋ ฅํ๋ค.
+````
+
+-------------------
+## ์์ธ ์ํฉ
+
+๋ ์ง ์
๋ ฅ
+- ๋ฌธ์์ด ์
๋ ฅ, ๊ณต๋ฐฑ ์
๋ ฅ
+
+์ฃผ๋ฌธ ์
๋ ฅ
+- **case 1: ๊ณต๋ฐฑ๋ง์ ์ ์ธํ ์๋ชป๋ ์
๋ ฅ์ ๋ฐ์๋ค๋ฉด ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํต๊ณผ ์ํฌ ๊ฒ์ธ๊ฐ?**
+````
+์
๋ ฅ ์์: ํํ์ค -1, ์ ๋ก ์ฝ๋ผ-1,์ด์ฝ ์ผ์ดํฌ- 3
+
+์ฌ์ฉ์ ์นํ์ ๋ฐฉ์: ๊ณต๋ฐฑ ์ ๊ฑฐ ๊ธฐ๋ฅ์ ์ด์ฉํ๋ฉด ๋๋ฏ๋ก ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํต๊ณผ์ํจ๋ค.
+ํ์ง๋ง, ๋ฐ์ดํฐ์ ์ผ๊ด์ฑ ์ ์งํ๊ธฐ ์ด๋ ค์ธ ์ ์์, ๋ก์ง์ด ๋ณต์กํด์ ธ์ ์ค๋ฅ๋ฐ์ ๊ฐ๋ฅ์ฑ์ด ์์.
+(ex. ํ ํ์ค, ํํ์ค, ํํ ์ค)์ ๊ฐ์ด ๊ณต๋ฐฑ์ด ์ ๋๋ก ์ ๊ฑฐ๊ฐ ์๋๊ฒ ๋ก์ง์ ์งฐ๋์ง ์ ํ์ธํด์ผํจ.
+๊ฒฐ๋ก : ํ๋ก ํธ์์ ๊ณต๋ฐฑ์ฌ๋ถ๋ฅผ ์ ๊ฐ๊ณตํด์ ์ ๋ฌ๋ฐ์ ๋ฐฑ์๋์์๋ ์ ํํ ๊ฐ์ ์
๋ ฅ๋ฐ๋๋ก ๊ตฌํํ๋ ๊ฒํ๋ ๊ฒ์ด ๋ง๋๊ฒ ๊ฐ๋ค.
+````
+
+- ์ค๋ณต๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅ๋ฐ๋๋ค.
+- ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅ๋ฐ๋๋ค.
+
+**case 2**
+- ์ฃผ๋ฌธ ์
๋ ฅ: ์ดํ์ธ-1-1, ์ด์ฝ์ผ์ดํฌ-1 ์ ํต๊ณผํด์ ๋ฐ์.
+- ์ฃผ๋ฌธ ์
๋ ฅ: ๋ฉ๋ด -- ์
๋ ฅ์ ์ค๋ฅ๋ฐ์.
+> ',' ๋ก ๋ถ๋ฆฌํ ๋ฌธ์์ด์ '-' ๊ฐฏ์๊ฐ 1๊ฐ ๊ฐ ์๋๋ผ๋ฉด ์์ธ์ฒ๋ฆฌ.
+
+
+--------
+## ๋ฆฌํํ ๋ง ํ ๋ฒํ ๊ฒ๋ค
+
+util์ MapReader ํด๋์ค ๋ง๋ค๊ธฐ
+```
+private void readMenuAndQuantity(Map<Menu, Integer> menuAndQuantity) {
+ for (Map.Entry<Menu, Integer> entry : menuAndQuantity.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ //์ฐ์ฐ ๋ช
๋ น
+ }
+
+}
+```
+์ด์ : ์์ ๊ฐ์ ํํ๊ฐ ๋ง์ด ๋ฐ๋ณตํด์ ์ฐ์ด๊ณ ์์.
+
+//์ฐ์ฐ ๋ช
๋ น ๋ถ๋ถ๋ง ๊ฐ์๋ผ์ฐ๋ ๋ฐฉ๋ฒ์ด ์์๊น? > BiConsumer ์์๋ณด๊ธฐ. | Unknown | README ๊น๋ํด์ ์ ๋ฆฌ๊ฐ ์ ๋ ๊ฒ ๊ฐ์ต๋๋ค :) |
@@ -0,0 +1,116 @@
+package christmas.domain.logic;
+
+import christmas.domain.model.DecemberEvent;
+import christmas.domain.model.OrderInfo;
+import christmas.domain.model.EventResult;
+import christmas.domain.type.Badge;
+import christmas.domain.type.Benefit;
+import christmas.domain.type.Menu;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class EventService {
+ private final OrderInfo orderInfo;
+ private Map<Benefit, Integer> benefitHistory = new HashMap<>();
+
+ public EventService(int date, Map<Menu, Integer> order) {
+ this.orderInfo = new OrderInfo(date, order);
+ }
+
+ public EventResult makeEventResult() {
+ int totalOrderPrice = orderInfo.getTotalOrderPrice();
+ int date = orderInfo.getDate();
+ int totalBenefitsPrice = 0;
+ Badge badge = Badge.NONE;
+
+ if (EventCalculator.isEligibleForEvent(totalOrderPrice)) {
+ checkAll(totalOrderPrice, date);
+ totalBenefitsPrice = calculateTotalBenefitsPrice();
+ badge = checkBadge(totalBenefitsPrice);
+ }
+
+ EventResult eventResult = new EventResult(orderInfo, benefitHistory, totalBenefitsPrice, badge);
+ return eventResult;
+ }
+
+ private void checkAll(int totalOrderPrice, int date) {
+ checkChristmasEvent(date);
+ checkWeekdayDiscount(date);
+ checkWeekendDiscount(date);
+ checkSpecialDiscount(date);
+ checkGiveaway(totalOrderPrice);
+ }
+
+ private void updateBenefitHistory(Benefit benefit, int discount) {
+ if (discount != 0) {
+ benefitHistory.put(benefit, discount);
+ }
+ }
+
+ private void checkGiveaway(int totalPrice) {
+ Map<Menu, Integer> giveaway = EventCalculator.calculateGiveawayEvent(totalPrice);
+ int discount = 0;
+
+ for (Map.Entry<Menu, Integer> entry : giveaway.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+ int menuPrice = menu.getPrice();
+
+ discount += menuPrice * quantity;
+ }
+
+ if (discount != 0) {
+ updateBenefitHistory(Benefit.GIVEAWAY, discount);
+ }
+ }
+
+ private void checkWeekdayDiscount(int date) {
+ int discount = 0;
+
+ if (!DecemberEvent.isWeekend(date)) {
+ discount = EventCalculator.calculateWeekdayDiscount(date, orderInfo.getOrder());
+ updateBenefitHistory(Benefit.WEEKDAY, discount);
+ }
+ }
+
+ private void checkWeekendDiscount(int date) {
+ int discount = 0;
+
+ if (DecemberEvent.isWeekend(date)) {
+ discount = EventCalculator.calculateWeekendDiscount(date, orderInfo.getOrder());
+ updateBenefitHistory(Benefit.WEEKEND, discount);
+ }
+ }
+
+ private void checkChristmasEvent(int date) {
+ int discount = ChristmasEventCalculator.calculateChristmasDiscount(date);
+
+ if (discount != 0) {
+ updateBenefitHistory(Benefit.CHRISTMAS_D_DAY, discount);
+ }
+ }
+
+ private void checkSpecialDiscount(int date) {
+ int discount = EventCalculator.calculateSpecialDiscount(date);
+
+ if (discount != 0) {
+ updateBenefitHistory(Benefit.SPECIAL, discount);
+ }
+ }
+
+ private int calculateTotalBenefitsPrice() {
+ int totalBenefitsPrice = benefitHistory
+ .values()
+ .stream()
+ .mapToInt(Integer::intValue)
+ .sum();
+
+ return totalBenefitsPrice;
+ }
+
+ private Badge checkBadge(int totalBenefitsPrice) {
+ return EventCalculator.calculateBadge(totalBenefitsPrice);
+ }
+}
+ | Java | EventService๋ผ๋ ๊ฐ์ฒด์ ์กด์ฌ ์ด์ ๊ฐ ์ ์๋ฟ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์๋น์ค ๊ฐ์ฒด์ธ์ง, ์ ํธ์ฉ ๊ฐ์ฒด์ธ์ง, ํน์ ๋๋ฉ์ธ ๊ฐ์ฒด์ธ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ์๋น์ค ๊ฐ์ฒด๋ผ๋ฉด logic์ด๋ผ๋ ํจํค์ง๋ช
์ด ๋ชจํธํ๋ค๊ณ ์๊ฐํ๊ณ , service ํจํค์ง๋ฅผ ๋ง๋ค์ด ๊ทธ ํ์ ์์ด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,82 @@
+package christmas.controller;
+
+import static christmas.domain.event.EventConstants.*;
+
+import christmas.domain.restaurant.Orders;
+import christmas.domain.restaurant.VisitDate;
+import christmas.service.RestaurantCalculator;
+import christmas.view.inputview.InputValueType;
+import christmas.view.inputview.InputView;
+import christmas.view.outputview.OutputView;
+
+public class WootecoRestaurantController {
+ private final RestaurantCalculator restaurantCalculator;
+ private final EventPlanerController eventPlanerController;
+
+ public WootecoRestaurantController(RestaurantCalculator restaurantCalculator,
+ EventPlanerController eventPlanerController) {
+ this.restaurantCalculator = restaurantCalculator;
+ this.eventPlanerController = eventPlanerController;
+ }
+
+ public void takeReservation() {
+ VisitDate visitDate = getVisitDate();
+ Orders orders = getOrders();
+ int orderTotalAmount = getOrderTotalAmount(orders);
+
+ showEventPreviewMessage(visitDate);
+ showOrderDetails(orders, orderTotalAmount);
+ executeEvent(visitDate, orders, orderTotalAmount);
+ }
+
+ private VisitDate getVisitDate() {
+ OutputView.printHelloMessage();
+ VisitDate visitDate = inputVisitDate();
+ return visitDate;
+ }
+
+ private Orders getOrders() {
+ OutputView.printMenu();
+ Orders orders = inputOrders();
+ return orders;
+ }
+
+ private int getOrderTotalAmount(Orders orders) {
+ return restaurantCalculator.getOrderTotalAmount(orders);
+ }
+
+ private static void showEventPreviewMessage(VisitDate visitDate) {
+ OutputView.printEventPreviewMessage(visitDate);
+ }
+
+ private static void showOrderDetails(Orders orders, int orderTotalAmount) {
+ OutputView.printOrder(orders, orderTotalAmount);
+ }
+
+ private void executeEvent(VisitDate visitDate, Orders orders, int orderTotalAmount) {
+ if (canApplyEvent(orderTotalAmount)) {
+ eventPlanerController.executeEventPlaner(visitDate, orders, orderTotalAmount);
+ }
+ }
+
+ private boolean canApplyEvent(int orderTotalAmount) {
+ if (isOrderTotalAmountValidForEvent(orderTotalAmount)) {
+ return true;
+ }
+
+ eventPlanerController.notApplyEvent(orderTotalAmount);
+ return false;
+ }
+
+ private static boolean isOrderTotalAmountValidForEvent(int orderTotalAmount) {
+ return orderTotalAmount >= EVENT_MIN_PAY_AMOUNT.getValue();
+ }
+
+ private Orders inputOrders() {
+ return (Orders) InputView.inputValue(InputValueType.ORDERS);
+ }
+
+ private VisitDate inputVisitDate() {
+ return (VisitDate) InputView.inputValue(InputValueType.VISIT_DATE);
+ }
+} | Java | ๊ฐ์ธ์ ์ธ ์๊ฐ์ผ๋ก, ์ปจํธ๋กค๋ฌ๊ฐ ๋ค๋ฅธ ์ปจํธ๋กค๋ฌ๋ฅผ ์ธ์คํด์ค ๋ณ์๋ก ๊ฐ์ง๊ณ ํธ์ถํ๋ ๊ฒ์ด ๋ง๋์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
๋ง์ฝ ๊ณตํต๋ ๋ถ๋ถ์ด ์์ด์๋ผ๋ฉด, ์๋น์ค๋ฅผ ๋ฐ๋ก ๋๊ฑฐ๋ ์ปจํธ๋กค๋ฌ๋ฅผ ํ๋๋ก ํฉ์น๋๊ฑธ ์ถ์ฒ๋๋ฆฝ๋๋ค! |
@@ -0,0 +1,78 @@
+package christmas.domain.restaurant;
+
+import christmas.domain.food.Dessert;
+import christmas.domain.food.Food;
+import christmas.domain.food.MainFood;
+import christmas.util.parser.Parser;
+import christmas.util.validator.OrderValidator;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class Orders {
+ private final Map<Food, Integer> orders;
+
+ private Orders(String orders) {
+ validate(orders);
+ this.orders = registerOrders(orders);
+ }
+
+ public static Orders create(String orders) {
+ return new Orders(orders);
+ }
+
+ public int getMainMenuCount() {
+ int mainMenuCount = 0;
+
+ for (Entry<Food, Integer> entry : orders.entrySet()) {
+ Food menu = entry.getKey();
+ int menuCount = entry.getValue();
+
+ if (menu instanceof MainFood) {
+ mainMenuCount += menuCount;
+ }
+ }
+
+ return mainMenuCount;
+ }
+
+ public int getDessertMenuCount() {
+ int dessertMenuCount = 0;
+
+ for (Entry<Food, Integer> entry : orders.entrySet()) {
+ Food menu = entry.getKey();
+ int menuCount = entry.getValue();
+
+ if (menu instanceof Dessert) {
+ dessertMenuCount += menuCount;
+ }
+ }
+
+ return dessertMenuCount;
+ }
+
+ private void validate(String orders) {
+ OrderValidator.validateOrders(orders);
+ }
+
+ private Map<Food, Integer> registerOrders(String orders) {
+ List<String> menus = Parser.parseMenus(orders);
+ List<Integer> counts = Parser.parseMenuCounts(orders);
+ Map<Food, Integer> order = new HashMap<>();
+
+ for (int idx = 0; idx < menus.size(); idx++) {
+ String menuName = menus.get(idx);
+ Food food = Menu.getFoodByName(menuName);
+ int count = counts.get(idx);
+
+ order.put(food, count);
+ }
+ return order;
+ }
+
+ public Map<Food, Integer> getOrders() {
+ return Collections.unmodifiableMap(orders);
+ }
+} | Java | Map ์๋ฃ๊ตฌ์กฐ๋ ์ฐ๋ค๋ณด๋ฉด ์๊ทผ ์์ด ๋ง์ด ๊ฐ๊ฒ๋๋ ์๋ฃ๊ตฌ์กฐ๋ผ๋ ์๊ฐ์ด ๋ค๋๋ผ๊ตฌ์.
๋ฌผ๋ก ์๋ฃ๊ตฌ์กฐ๋ง๋ค ์ฅ์ ๊ณผ ๋จ์ ์ด ์์ง๋ง
๊ฐ์ธ์ ์ผ๋ก ์ฌ๊ธฐ์๋ Map๋ณด๋ค๋ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ๊ฐ์ง ๋ณ๋์ Order ๊ฐ์ฒด๋ฅผ ๋๋ ๊ฒ์ด ์ข์๋ณด์
๋๋ค! |
@@ -0,0 +1,82 @@
+package christmas.controller;
+
+import static christmas.domain.event.EventConstants.*;
+
+import christmas.domain.restaurant.Orders;
+import christmas.domain.restaurant.VisitDate;
+import christmas.service.RestaurantCalculator;
+import christmas.view.inputview.InputValueType;
+import christmas.view.inputview.InputView;
+import christmas.view.outputview.OutputView;
+
+public class WootecoRestaurantController {
+ private final RestaurantCalculator restaurantCalculator;
+ private final EventPlanerController eventPlanerController;
+
+ public WootecoRestaurantController(RestaurantCalculator restaurantCalculator,
+ EventPlanerController eventPlanerController) {
+ this.restaurantCalculator = restaurantCalculator;
+ this.eventPlanerController = eventPlanerController;
+ }
+
+ public void takeReservation() {
+ VisitDate visitDate = getVisitDate();
+ Orders orders = getOrders();
+ int orderTotalAmount = getOrderTotalAmount(orders);
+
+ showEventPreviewMessage(visitDate);
+ showOrderDetails(orders, orderTotalAmount);
+ executeEvent(visitDate, orders, orderTotalAmount);
+ }
+
+ private VisitDate getVisitDate() {
+ OutputView.printHelloMessage();
+ VisitDate visitDate = inputVisitDate();
+ return visitDate;
+ }
+
+ private Orders getOrders() {
+ OutputView.printMenu();
+ Orders orders = inputOrders();
+ return orders;
+ }
+
+ private int getOrderTotalAmount(Orders orders) {
+ return restaurantCalculator.getOrderTotalAmount(orders);
+ }
+
+ private static void showEventPreviewMessage(VisitDate visitDate) {
+ OutputView.printEventPreviewMessage(visitDate);
+ }
+
+ private static void showOrderDetails(Orders orders, int orderTotalAmount) {
+ OutputView.printOrder(orders, orderTotalAmount);
+ }
+
+ private void executeEvent(VisitDate visitDate, Orders orders, int orderTotalAmount) {
+ if (canApplyEvent(orderTotalAmount)) {
+ eventPlanerController.executeEventPlaner(visitDate, orders, orderTotalAmount);
+ }
+ }
+
+ private boolean canApplyEvent(int orderTotalAmount) {
+ if (isOrderTotalAmountValidForEvent(orderTotalAmount)) {
+ return true;
+ }
+
+ eventPlanerController.notApplyEvent(orderTotalAmount);
+ return false;
+ }
+
+ private static boolean isOrderTotalAmountValidForEvent(int orderTotalAmount) {
+ return orderTotalAmount >= EVENT_MIN_PAY_AMOUNT.getValue();
+ }
+
+ private Orders inputOrders() {
+ return (Orders) InputView.inputValue(InputValueType.ORDERS);
+ }
+
+ private VisitDate inputVisitDate() {
+ return (VisitDate) InputView.inputValue(InputValueType.VISIT_DATE);
+ }
+} | Java | ํด๋น ๋ถ๋ถ์ ์ด๋ฒคํธ ๋๋ฉ์ธ ๊ด๋ จ ํด๋์ค์ ์์นํ๋ ๊ฒ์ด ์ข์๋ณด์
๋๋ค.
์ด๋ฒคํธ๋ฅผ ์ ์ฉํ ์ ์๋์ง ์๋์ง์ ๋ํด์๋ ๋น์ฆ๋์ค ๋ก์ง์ ํด๋น๋๋ค๊ณ ์๊ฐํด์! |
@@ -0,0 +1,82 @@
+package christmas.controller;
+
+import static christmas.domain.event.EventConstants.*;
+
+import christmas.domain.restaurant.Orders;
+import christmas.domain.restaurant.VisitDate;
+import christmas.service.RestaurantCalculator;
+import christmas.view.inputview.InputValueType;
+import christmas.view.inputview.InputView;
+import christmas.view.outputview.OutputView;
+
+public class WootecoRestaurantController {
+ private final RestaurantCalculator restaurantCalculator;
+ private final EventPlanerController eventPlanerController;
+
+ public WootecoRestaurantController(RestaurantCalculator restaurantCalculator,
+ EventPlanerController eventPlanerController) {
+ this.restaurantCalculator = restaurantCalculator;
+ this.eventPlanerController = eventPlanerController;
+ }
+
+ public void takeReservation() {
+ VisitDate visitDate = getVisitDate();
+ Orders orders = getOrders();
+ int orderTotalAmount = getOrderTotalAmount(orders);
+
+ showEventPreviewMessage(visitDate);
+ showOrderDetails(orders, orderTotalAmount);
+ executeEvent(visitDate, orders, orderTotalAmount);
+ }
+
+ private VisitDate getVisitDate() {
+ OutputView.printHelloMessage();
+ VisitDate visitDate = inputVisitDate();
+ return visitDate;
+ }
+
+ private Orders getOrders() {
+ OutputView.printMenu();
+ Orders orders = inputOrders();
+ return orders;
+ }
+
+ private int getOrderTotalAmount(Orders orders) {
+ return restaurantCalculator.getOrderTotalAmount(orders);
+ }
+
+ private static void showEventPreviewMessage(VisitDate visitDate) {
+ OutputView.printEventPreviewMessage(visitDate);
+ }
+
+ private static void showOrderDetails(Orders orders, int orderTotalAmount) {
+ OutputView.printOrder(orders, orderTotalAmount);
+ }
+
+ private void executeEvent(VisitDate visitDate, Orders orders, int orderTotalAmount) {
+ if (canApplyEvent(orderTotalAmount)) {
+ eventPlanerController.executeEventPlaner(visitDate, orders, orderTotalAmount);
+ }
+ }
+
+ private boolean canApplyEvent(int orderTotalAmount) {
+ if (isOrderTotalAmountValidForEvent(orderTotalAmount)) {
+ return true;
+ }
+
+ eventPlanerController.notApplyEvent(orderTotalAmount);
+ return false;
+ }
+
+ private static boolean isOrderTotalAmountValidForEvent(int orderTotalAmount) {
+ return orderTotalAmount >= EVENT_MIN_PAY_AMOUNT.getValue();
+ }
+
+ private Orders inputOrders() {
+ return (Orders) InputView.inputValue(InputValueType.ORDERS);
+ }
+
+ private VisitDate inputVisitDate() {
+ return (VisitDate) InputView.inputValue(InputValueType.VISIT_DATE);
+ }
+} | Java | ๋ง์ฐฌ๊ฐ์ง์ ์ด์ ๋ก, view์์๋ ๋๋ฉ์ธ ๋ชจ๋ธ ์์ฒด๊ฐ ์๋ ๋๋ฉ์ธ ๋ชจ๋ธ์ ๋ฐ์ดํฐ๋ง ์ ๋ฌํ๋ ๊ฒ์ด ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค |
@@ -0,0 +1,82 @@
+package christmas.controller;
+
+import static christmas.domain.event.EventConstants.*;
+
+import christmas.domain.restaurant.Orders;
+import christmas.domain.restaurant.VisitDate;
+import christmas.service.RestaurantCalculator;
+import christmas.view.inputview.InputValueType;
+import christmas.view.inputview.InputView;
+import christmas.view.outputview.OutputView;
+
+public class WootecoRestaurantController {
+ private final RestaurantCalculator restaurantCalculator;
+ private final EventPlanerController eventPlanerController;
+
+ public WootecoRestaurantController(RestaurantCalculator restaurantCalculator,
+ EventPlanerController eventPlanerController) {
+ this.restaurantCalculator = restaurantCalculator;
+ this.eventPlanerController = eventPlanerController;
+ }
+
+ public void takeReservation() {
+ VisitDate visitDate = getVisitDate();
+ Orders orders = getOrders();
+ int orderTotalAmount = getOrderTotalAmount(orders);
+
+ showEventPreviewMessage(visitDate);
+ showOrderDetails(orders, orderTotalAmount);
+ executeEvent(visitDate, orders, orderTotalAmount);
+ }
+
+ private VisitDate getVisitDate() {
+ OutputView.printHelloMessage();
+ VisitDate visitDate = inputVisitDate();
+ return visitDate;
+ }
+
+ private Orders getOrders() {
+ OutputView.printMenu();
+ Orders orders = inputOrders();
+ return orders;
+ }
+
+ private int getOrderTotalAmount(Orders orders) {
+ return restaurantCalculator.getOrderTotalAmount(orders);
+ }
+
+ private static void showEventPreviewMessage(VisitDate visitDate) {
+ OutputView.printEventPreviewMessage(visitDate);
+ }
+
+ private static void showOrderDetails(Orders orders, int orderTotalAmount) {
+ OutputView.printOrder(orders, orderTotalAmount);
+ }
+
+ private void executeEvent(VisitDate visitDate, Orders orders, int orderTotalAmount) {
+ if (canApplyEvent(orderTotalAmount)) {
+ eventPlanerController.executeEventPlaner(visitDate, orders, orderTotalAmount);
+ }
+ }
+
+ private boolean canApplyEvent(int orderTotalAmount) {
+ if (isOrderTotalAmountValidForEvent(orderTotalAmount)) {
+ return true;
+ }
+
+ eventPlanerController.notApplyEvent(orderTotalAmount);
+ return false;
+ }
+
+ private static boolean isOrderTotalAmountValidForEvent(int orderTotalAmount) {
+ return orderTotalAmount >= EVENT_MIN_PAY_AMOUNT.getValue();
+ }
+
+ private Orders inputOrders() {
+ return (Orders) InputView.inputValue(InputValueType.ORDERS);
+ }
+
+ private VisitDate inputVisitDate() {
+ return (VisitDate) InputView.inputValue(InputValueType.VISIT_DATE);
+ }
+} | Java | ์ด ๋ถ๋ถ์ ๊ตฌ์กฐ ๊ฐ์ ์ด ํ์ํ๊ฒ ๋ค์. ๋ง์ํด์ฃผ์ ๋๋ก ์ปจํธ๋กค๋ฌ ๋ด๋ถ์ ์ปจํธ๋กค๋ฌ๋ฅผ ๋ ํ์๋ ์์๋ค๊ณ ์๊ฐํฉ๋๋ค. EventPlanerController๋ Service์ ๋๋ ๊ฒ ๋ง์๊ฒ ๋ค์.
๋๋ถ์ ์ด๋ ดํํ๊ฒ ์์๋ ์๋น์ค์ ์ปจํธ๋กค๋ฌ์ ์ญํ ์ ๋ํด ๋ค์ ํ ๋ฒ ์๊ฐํด๋ณผ ์ ์๋ ๊ธฐํ๊ฐ ๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ข์ ํผ๋๋ฐฑ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,82 @@
+package christmas.controller;
+
+import static christmas.domain.event.EventConstants.*;
+
+import christmas.domain.restaurant.Orders;
+import christmas.domain.restaurant.VisitDate;
+import christmas.service.RestaurantCalculator;
+import christmas.view.inputview.InputValueType;
+import christmas.view.inputview.InputView;
+import christmas.view.outputview.OutputView;
+
+public class WootecoRestaurantController {
+ private final RestaurantCalculator restaurantCalculator;
+ private final EventPlanerController eventPlanerController;
+
+ public WootecoRestaurantController(RestaurantCalculator restaurantCalculator,
+ EventPlanerController eventPlanerController) {
+ this.restaurantCalculator = restaurantCalculator;
+ this.eventPlanerController = eventPlanerController;
+ }
+
+ public void takeReservation() {
+ VisitDate visitDate = getVisitDate();
+ Orders orders = getOrders();
+ int orderTotalAmount = getOrderTotalAmount(orders);
+
+ showEventPreviewMessage(visitDate);
+ showOrderDetails(orders, orderTotalAmount);
+ executeEvent(visitDate, orders, orderTotalAmount);
+ }
+
+ private VisitDate getVisitDate() {
+ OutputView.printHelloMessage();
+ VisitDate visitDate = inputVisitDate();
+ return visitDate;
+ }
+
+ private Orders getOrders() {
+ OutputView.printMenu();
+ Orders orders = inputOrders();
+ return orders;
+ }
+
+ private int getOrderTotalAmount(Orders orders) {
+ return restaurantCalculator.getOrderTotalAmount(orders);
+ }
+
+ private static void showEventPreviewMessage(VisitDate visitDate) {
+ OutputView.printEventPreviewMessage(visitDate);
+ }
+
+ private static void showOrderDetails(Orders orders, int orderTotalAmount) {
+ OutputView.printOrder(orders, orderTotalAmount);
+ }
+
+ private void executeEvent(VisitDate visitDate, Orders orders, int orderTotalAmount) {
+ if (canApplyEvent(orderTotalAmount)) {
+ eventPlanerController.executeEventPlaner(visitDate, orders, orderTotalAmount);
+ }
+ }
+
+ private boolean canApplyEvent(int orderTotalAmount) {
+ if (isOrderTotalAmountValidForEvent(orderTotalAmount)) {
+ return true;
+ }
+
+ eventPlanerController.notApplyEvent(orderTotalAmount);
+ return false;
+ }
+
+ private static boolean isOrderTotalAmountValidForEvent(int orderTotalAmount) {
+ return orderTotalAmount >= EVENT_MIN_PAY_AMOUNT.getValue();
+ }
+
+ private Orders inputOrders() {
+ return (Orders) InputView.inputValue(InputValueType.ORDERS);
+ }
+
+ private VisitDate inputVisitDate() {
+ return (VisitDate) InputView.inputValue(InputValueType.VISIT_DATE);
+ }
+} | Java | ์ ๊ฐ ํด๋น ๋ถ๋ถ์ ๊ธฐ๋ฅ ๊ตฌํ์ ๊น๋จน๊ณ ์๋ค๊ฐ ๋ง์ง๋ง์ ํ๊ฒ ๋์๋๋ฐ, ์ด๋ฌํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค์.
๊ธฐ๋ณธ MVC ํจํด์ ์ปจํธ๋กค๋ฌ ์ญํ ์ ์๊ฐํด๋ณด๋ฉด ์ด๋ฒคํธ ๋๋ฉ์ธ์ด๋ ์๋น์ค์์ ํด๋น ๋ก์ง์ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ์ข์๋ณด์
๋๋ค. ๊ฐ์ฌํฉ๋๋ค! |
@@ -8,71 +8,72 @@
import bridge.view.OutputView;
public class BridgeGameController {
- private final OutputView outputView = new OutputView();
- private final InputView inputView = new InputView();
+ private final OutputView outputView;
+ private final InputView inputView;
private BridgeGame bridgeGame;
- private boolean isGameEndStatus = false;
- private boolean isGameRunning = false;
+
+ public BridgeGameController(OutputView outputView, InputView inputView) {
+ this.outputView = outputView;
+ this.inputView = inputView;
+ }
public void play() {
outputView.initGame();
Bridge bridge = initBridge();
bridgeGame = new BridgeGame(bridge);
- while (!isGameRunning) {
+ while (bridgeGame.isRunning()) {
playOneRound(bridge);
}
- outputView.printResult(isGameEndStatus, bridgeGame.getTryCount());
+ outputView.printResult(bridgeGame.isGameSuccess(), bridgeGame.getTryCount());
+ }
+
+
+ private void playOneRound(Bridge bridge) {
+ checkMove(bridge);
+ bridgeGame.isGameEnd();
+ if (bridgeGame.isGameSuccess()) {
+ return;
+ }
+ playOneRound(bridge);
+ }
+
+
+ private void checkMove(Bridge bridge) {
+ inputMoving();
+ outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
+ if (!bridgeGame.isRunning()) {
+ retry();
+ }
}
private Bridge initBridge() {
try {
int bridgeSize = inputView.readBridgeSize();
- return new Bridge(new BridgeMaker(new BridgeRandomNumberGenerator()).makeBridge(bridgeSize));
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return new Bridge(bridgeMaker.makeBridge(bridgeSize));
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
return initBridge();
}
}
- private boolean inputMoving() {
+ private void inputMoving() {
try {
String moveCommand = inputView.readMoving();
- return bridgeGame.move(moveCommand);
+ bridgeGame.move(moveCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return inputMoving();
- }
- }
-
- private void playOneRound(Bridge bridge) {
- checkMove(bridge);
- isGameEndStatus = bridgeGame.isGameEnd();
- if (isGameEndStatus) {
- return;
- }
- playOneRound(bridge);
- }
-
- private void checkMove(Bridge bridge) {
- boolean isMove = inputMoving();
- outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
- if (!isMove) {
- if (!retry()) {
- isGameEndStatus = false;
- isGameRunning = false;
- return;
- }
+ inputMoving();
}
- isGameRunning = true;
}
- private boolean retry() {
+ private void retry() {
try {
String gameCommand = inputView.readGameCommand();
- return bridgeGame.retry(gameCommand);
+ bridgeGame.retry(gameCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return retry();
+ retry();
}
}
| Java | ๋ฉ์๋์ ์ญํ ์ด ์กฐ๊ธ ๋ง์ ๊ฒ ๊ฐ์ต๋๋ค!
์์ง์ ์
๋ ฅ์ ๋ฐ๋ ๋ฉ์๋์์ `bridgeGame.move()` ๊ฐ ์กด์ฌํ๋ ๊ฒ์ ์กฐ๊ธ ์ด์ํฉ๋๋ค! |
@@ -8,71 +8,72 @@
import bridge.view.OutputView;
public class BridgeGameController {
- private final OutputView outputView = new OutputView();
- private final InputView inputView = new InputView();
+ private final OutputView outputView;
+ private final InputView inputView;
private BridgeGame bridgeGame;
- private boolean isGameEndStatus = false;
- private boolean isGameRunning = false;
+
+ public BridgeGameController(OutputView outputView, InputView inputView) {
+ this.outputView = outputView;
+ this.inputView = inputView;
+ }
public void play() {
outputView.initGame();
Bridge bridge = initBridge();
bridgeGame = new BridgeGame(bridge);
- while (!isGameRunning) {
+ while (bridgeGame.isRunning()) {
playOneRound(bridge);
}
- outputView.printResult(isGameEndStatus, bridgeGame.getTryCount());
+ outputView.printResult(bridgeGame.isGameSuccess(), bridgeGame.getTryCount());
+ }
+
+
+ private void playOneRound(Bridge bridge) {
+ checkMove(bridge);
+ bridgeGame.isGameEnd();
+ if (bridgeGame.isGameSuccess()) {
+ return;
+ }
+ playOneRound(bridge);
+ }
+
+
+ private void checkMove(Bridge bridge) {
+ inputMoving();
+ outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
+ if (!bridgeGame.isRunning()) {
+ retry();
+ }
}
private Bridge initBridge() {
try {
int bridgeSize = inputView.readBridgeSize();
- return new Bridge(new BridgeMaker(new BridgeRandomNumberGenerator()).makeBridge(bridgeSize));
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return new Bridge(bridgeMaker.makeBridge(bridgeSize));
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
return initBridge();
}
}
- private boolean inputMoving() {
+ private void inputMoving() {
try {
String moveCommand = inputView.readMoving();
- return bridgeGame.move(moveCommand);
+ bridgeGame.move(moveCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return inputMoving();
- }
- }
-
- private void playOneRound(Bridge bridge) {
- checkMove(bridge);
- isGameEndStatus = bridgeGame.isGameEnd();
- if (isGameEndStatus) {
- return;
- }
- playOneRound(bridge);
- }
-
- private void checkMove(Bridge bridge) {
- boolean isMove = inputMoving();
- outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
- if (!isMove) {
- if (!retry()) {
- isGameEndStatus = false;
- isGameRunning = false;
- return;
- }
+ inputMoving();
}
- isGameRunning = true;
}
- private boolean retry() {
+ private void retry() {
try {
String gameCommand = inputView.readGameCommand();
- return bridgeGame.retry(gameCommand);
+ bridgeGame.retry(gameCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return retry();
+ retry();
}
}
| Java | ๊ฐ์ธ์ ์ผ๋ก ์ด ๋ถ๋ถ์ ํ๋ฆ ์ฒ๋ฆฌ๊ฐ ์กฐ๊ธ ์์ฝ๋ค๊ณ ์๊ฐํฉ๋๋ค.
์ฐ์ ์๋์ `inputMoving()` ๋ฉ์๋์ ์ญํ ์ด ์กฐ๊ธ ๋ง๊ณ ,
`playOneRount()`๋ฅผ ๋ฐ๋ณตํ๋ ๋ก์ง๋ while ๋ฌธ์ ์ฌ์ฉํ๋ฉด ์ข ๋ ์ง๊ด์ ์ผ๋ก ๋ณด์ด์ง ์์๊น ์๊ฐ๋ฉ๋๋ค!
ํ๋ฒ์ฏค ๊ณ ๋ฏผํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์! |
@@ -8,71 +8,72 @@
import bridge.view.OutputView;
public class BridgeGameController {
- private final OutputView outputView = new OutputView();
- private final InputView inputView = new InputView();
+ private final OutputView outputView;
+ private final InputView inputView;
private BridgeGame bridgeGame;
- private boolean isGameEndStatus = false;
- private boolean isGameRunning = false;
+
+ public BridgeGameController(OutputView outputView, InputView inputView) {
+ this.outputView = outputView;
+ this.inputView = inputView;
+ }
public void play() {
outputView.initGame();
Bridge bridge = initBridge();
bridgeGame = new BridgeGame(bridge);
- while (!isGameRunning) {
+ while (bridgeGame.isRunning()) {
playOneRound(bridge);
}
- outputView.printResult(isGameEndStatus, bridgeGame.getTryCount());
+ outputView.printResult(bridgeGame.isGameSuccess(), bridgeGame.getTryCount());
+ }
+
+
+ private void playOneRound(Bridge bridge) {
+ checkMove(bridge);
+ bridgeGame.isGameEnd();
+ if (bridgeGame.isGameSuccess()) {
+ return;
+ }
+ playOneRound(bridge);
+ }
+
+
+ private void checkMove(Bridge bridge) {
+ inputMoving();
+ outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
+ if (!bridgeGame.isRunning()) {
+ retry();
+ }
}
private Bridge initBridge() {
try {
int bridgeSize = inputView.readBridgeSize();
- return new Bridge(new BridgeMaker(new BridgeRandomNumberGenerator()).makeBridge(bridgeSize));
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return new Bridge(bridgeMaker.makeBridge(bridgeSize));
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
return initBridge();
}
}
- private boolean inputMoving() {
+ private void inputMoving() {
try {
String moveCommand = inputView.readMoving();
- return bridgeGame.move(moveCommand);
+ bridgeGame.move(moveCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return inputMoving();
- }
- }
-
- private void playOneRound(Bridge bridge) {
- checkMove(bridge);
- isGameEndStatus = bridgeGame.isGameEnd();
- if (isGameEndStatus) {
- return;
- }
- playOneRound(bridge);
- }
-
- private void checkMove(Bridge bridge) {
- boolean isMove = inputMoving();
- outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
- if (!isMove) {
- if (!retry()) {
- isGameEndStatus = false;
- isGameRunning = false;
- return;
- }
+ inputMoving();
}
- isGameRunning = true;
}
- private boolean retry() {
+ private void retry() {
try {
String gameCommand = inputView.readGameCommand();
- return bridgeGame.retry(gameCommand);
+ bridgeGame.retry(gameCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return retry();
+ retry();
}
}
| Java | > ๊ฐ์ธ์ ์ผ๋ก ์ด ๋ถ๋ถ์ ํ๋ฆ ์ฒ๋ฆฌ๊ฐ ์กฐ๊ธ ์์ฝ๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ฐ์ ์๋์ `inputMoving()` ๋ฉ์๋์ ์ญํ ์ด ์กฐ๊ธ ๋ง๊ณ , `playOneRount()`๋ฅผ ๋ฐ๋ณตํ๋ ๋ก์ง๋ while ๋ฌธ์ ์ฌ์ฉํ๋ฉด ์ข ๋ ์ง๊ด์ ์ผ๋ก ๋ณด์ด์ง ์์๊น ์๊ฐ๋ฉ๋๋ค! ํ๋ฒ์ฏค ๊ณ ๋ฏผํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์!
๊ธฐ์กด์ ์ฌ๊ท๋ก ๊ตฌ์ฑํ๋ ์ฝ๋๋ฅผ while๋ก ๋ฐ๊ฟ ์๊ฐ์ ๋ชปํ๋ค์.. ๊ตณ์ด ์กฐ๊ฑด๊ฑธ์ด์ ์ฌ๊ท๋ฅผ ํ๊ธฐ๋ณด๋ค ์๊ฒฌ์ฃผ์ while์ ์ฌ์ฉํ๋๊ฒ ํ์คํ ๋ ์ข์๋ณด์ด๊ธด ํฉ๋๋ค ! ๊ฐ์ฌํฉ๋๋ค |
@@ -8,71 +8,72 @@
import bridge.view.OutputView;
public class BridgeGameController {
- private final OutputView outputView = new OutputView();
- private final InputView inputView = new InputView();
+ private final OutputView outputView;
+ private final InputView inputView;
private BridgeGame bridgeGame;
- private boolean isGameEndStatus = false;
- private boolean isGameRunning = false;
+
+ public BridgeGameController(OutputView outputView, InputView inputView) {
+ this.outputView = outputView;
+ this.inputView = inputView;
+ }
public void play() {
outputView.initGame();
Bridge bridge = initBridge();
bridgeGame = new BridgeGame(bridge);
- while (!isGameRunning) {
+ while (bridgeGame.isRunning()) {
playOneRound(bridge);
}
- outputView.printResult(isGameEndStatus, bridgeGame.getTryCount());
+ outputView.printResult(bridgeGame.isGameSuccess(), bridgeGame.getTryCount());
+ }
+
+
+ private void playOneRound(Bridge bridge) {
+ checkMove(bridge);
+ bridgeGame.isGameEnd();
+ if (bridgeGame.isGameSuccess()) {
+ return;
+ }
+ playOneRound(bridge);
+ }
+
+
+ private void checkMove(Bridge bridge) {
+ inputMoving();
+ outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
+ if (!bridgeGame.isRunning()) {
+ retry();
+ }
}
private Bridge initBridge() {
try {
int bridgeSize = inputView.readBridgeSize();
- return new Bridge(new BridgeMaker(new BridgeRandomNumberGenerator()).makeBridge(bridgeSize));
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return new Bridge(bridgeMaker.makeBridge(bridgeSize));
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
return initBridge();
}
}
- private boolean inputMoving() {
+ private void inputMoving() {
try {
String moveCommand = inputView.readMoving();
- return bridgeGame.move(moveCommand);
+ bridgeGame.move(moveCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return inputMoving();
- }
- }
-
- private void playOneRound(Bridge bridge) {
- checkMove(bridge);
- isGameEndStatus = bridgeGame.isGameEnd();
- if (isGameEndStatus) {
- return;
- }
- playOneRound(bridge);
- }
-
- private void checkMove(Bridge bridge) {
- boolean isMove = inputMoving();
- outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
- if (!isMove) {
- if (!retry()) {
- isGameEndStatus = false;
- isGameRunning = false;
- return;
- }
+ inputMoving();
}
- isGameRunning = true;
}
- private boolean retry() {
+ private void retry() {
try {
String gameCommand = inputView.readGameCommand();
- return bridgeGame.retry(gameCommand);
+ bridgeGame.retry(gameCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return retry();
+ retry();
}
}
| Java | > ๋ฉ์๋์ ์ญํ ์ด ์กฐ๊ธ ๋ง์ ๊ฒ ๊ฐ์ต๋๋ค! ์์ง์ ์
๋ ฅ์ ๋ฐ๋ ๋ฉ์๋์์ `bridgeGame.move()` ๊ฐ ์กด์ฌํ๋ ๊ฒ์ ์กฐ๊ธ ์ด์ํฉ๋๋ค!
์.. ๊ทธ๋ด๊น์ ? ๋ฉ์๋ ๋ช
์ด ์ด์ํ๊ฑธ๊น์ ๋ฉ์๋ ์ญํ ์ด ๋ฌธ์ ์ผ๊น์ ?
์ ๋ ์ปจํธ๋กค๋ฌ๋ผ๊ณ ์๊ฐํด์ '์
๋ ฅ์ ํตํด์ ์คํํ๋ค' ๊ฐ ํ๋์ ์ญํ ์ ํ๋ค๊ณ ์๊ฐํ๋๋ฐ ๊ทธ๊ฒ ์๋์์๊น์.. ์ ๋ง ์ด๋ ต๊ธดํ๋ค์ |
@@ -8,71 +8,72 @@
import bridge.view.OutputView;
public class BridgeGameController {
- private final OutputView outputView = new OutputView();
- private final InputView inputView = new InputView();
+ private final OutputView outputView;
+ private final InputView inputView;
private BridgeGame bridgeGame;
- private boolean isGameEndStatus = false;
- private boolean isGameRunning = false;
+
+ public BridgeGameController(OutputView outputView, InputView inputView) {
+ this.outputView = outputView;
+ this.inputView = inputView;
+ }
public void play() {
outputView.initGame();
Bridge bridge = initBridge();
bridgeGame = new BridgeGame(bridge);
- while (!isGameRunning) {
+ while (bridgeGame.isRunning()) {
playOneRound(bridge);
}
- outputView.printResult(isGameEndStatus, bridgeGame.getTryCount());
+ outputView.printResult(bridgeGame.isGameSuccess(), bridgeGame.getTryCount());
+ }
+
+
+ private void playOneRound(Bridge bridge) {
+ checkMove(bridge);
+ bridgeGame.isGameEnd();
+ if (bridgeGame.isGameSuccess()) {
+ return;
+ }
+ playOneRound(bridge);
+ }
+
+
+ private void checkMove(Bridge bridge) {
+ inputMoving();
+ outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
+ if (!bridgeGame.isRunning()) {
+ retry();
+ }
}
private Bridge initBridge() {
try {
int bridgeSize = inputView.readBridgeSize();
- return new Bridge(new BridgeMaker(new BridgeRandomNumberGenerator()).makeBridge(bridgeSize));
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return new Bridge(bridgeMaker.makeBridge(bridgeSize));
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
return initBridge();
}
}
- private boolean inputMoving() {
+ private void inputMoving() {
try {
String moveCommand = inputView.readMoving();
- return bridgeGame.move(moveCommand);
+ bridgeGame.move(moveCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return inputMoving();
- }
- }
-
- private void playOneRound(Bridge bridge) {
- checkMove(bridge);
- isGameEndStatus = bridgeGame.isGameEnd();
- if (isGameEndStatus) {
- return;
- }
- playOneRound(bridge);
- }
-
- private void checkMove(Bridge bridge) {
- boolean isMove = inputMoving();
- outputView.printMap(bridgeGame.getUserBridge().getUserBridge(), bridge.getBridge());
- if (!isMove) {
- if (!retry()) {
- isGameEndStatus = false;
- isGameRunning = false;
- return;
- }
+ inputMoving();
}
- isGameRunning = true;
}
- private boolean retry() {
+ private void retry() {
try {
String gameCommand = inputView.readGameCommand();
- return bridgeGame.retry(gameCommand);
+ bridgeGame.retry(gameCommand);
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e.getMessage());
- return retry();
+ retry();
}
}
| Java | ๊ทธ๋ ๊ฒ ํ๋๋ก ๋ณผ ์๋ ์๋ค๊ณ ์๊ฐํฉ๋๋ค!
๋ค๋ง ์ ๊ฐ ์๊ฐํ์ ๋๋ ์
๋ ฅ ๋ฐ๊ธฐ -> ์์ง์ธ๋ค ๊น์ง๊ฐ ํ๋์ round ๋ก ๋ฌถ์ด๊ณ ,
isSuccess(๋์ ๋๋ฌํจ) ๋ ๋จ์ด์ง ์ํ๊ฐ ๋์์ ๋ ๋ค์ ํ๋ฆ์ ์ ์ดํ๋ ๋ก์ง์ด ํ๋์ ๋ ํฐ ๋ฉ์๋๋ก
round๋ฅผ ๋ฐ๋ณต์ํค๋ ๊ฒ์ด ์ข๋ค๊ณ ์๊ฐํ์ต๋๋ค!
์ ๋ต์ ์์ผ๋ ํ๋ฒ ๊ณ ๋ฏผํด๋ณด์๊ณ ๋ ์ ์ ํ๋ค๊ณ ๋๋ผ๋ ๊ตฌ์กฐ๋ฅผ ์ก์๊ฐ๋ ๊ฒ์ด ์ค์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค! |
@@ -0,0 +1,47 @@
+package bridge.view;
+
+import java.util.List;
+import java.util.StringJoiner;
+
+public class StringUtil {
+
+ public static String createBridge(List<String> userBridge, List<String> gameBridge) {
+ StringJoiner bridge = new StringJoiner("\n");
+
+ StringJoiner upBridge = new StringJoiner(" | ");
+ StringJoiner downBridge = new StringJoiner(" | ");
+
+ for (int i = 0; i < userBridge.size(); i++) {
+ addBridgeSegment(userBridge.get(i), gameBridge.get(i), upBridge, downBridge);
+ }
+ return bridge.add(String.format("[ %s ]", upBridge)).add(String.format("[ %s ]", downBridge)).toString();
+ }
+
+ private static void addBridgeSegment(String userSegment, String gameSegment, StringJoiner upBridge, StringJoiner downBridge) {
+ if (userSegment.equals(gameSegment)) {
+ addMatchingSegment(userSegment, upBridge, downBridge);
+ } else {
+ addNonMatchingSegment(userSegment, upBridge, downBridge);
+ }
+ }
+
+ private static void addMatchingSegment(String segment, StringJoiner upBridge, StringJoiner downBridge) {
+ if (segment.equals("U")) {
+ upBridge.add("O");
+ downBridge.add(" ");
+ } else if (segment.equals("D")) {
+ upBridge.add(" ");
+ downBridge.add("O");
+ }
+ }
+
+ private static void addNonMatchingSegment(String segment, StringJoiner upBridge, StringJoiner downBridge) {
+ if (segment.equals("U")) {
+ upBridge.add("X");
+ downBridge.add(" ");
+ } else if (segment.equals("D")) {
+ upBridge.add(" ");
+ downBridge.add("X");
+ }
+ }
+} | Java | ๋ฌธ์์ด๋ค์ StringUtil ์ ๊ตฌํํด์ OutputView์ ์ฑ
์์ ๋์ด์ค ๊ฑด ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค!
๋ค๋ง ํ๋ผ๋ฏธํฐ๊ฐ ๋ค์ ๋ง๊ณ , ๋ชจ๋ ๊ฒฐ๊ณผ์ ๋ํ ๊ฒฐ๊ณผ ๋น๊ต๋ฅผ StringUtil์์ ๋ค ํ๊ณ ์๋ ๋ถ๋ถ์ ์กฐ๊ธ ์์ฌ์ด ๊ฒ ๊ฐ์ต๋๋ค
์๋น์ค ๊ณ์ธต์์ ์ด๋์ ๋ ๊ณ์ฐํ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ๊ณตํด์ ๋ฐํํ ์ ์๋๋ก ๊ตฌํํ๋ฉด ์ด๋จ๊น ์ถ์ต๋๋ค |
@@ -0,0 +1,47 @@
+package bridge.view;
+
+import java.util.List;
+import java.util.StringJoiner;
+
+public class StringUtil {
+
+ public static String createBridge(List<String> userBridge, List<String> gameBridge) {
+ StringJoiner bridge = new StringJoiner("\n");
+
+ StringJoiner upBridge = new StringJoiner(" | ");
+ StringJoiner downBridge = new StringJoiner(" | ");
+
+ for (int i = 0; i < userBridge.size(); i++) {
+ addBridgeSegment(userBridge.get(i), gameBridge.get(i), upBridge, downBridge);
+ }
+ return bridge.add(String.format("[ %s ]", upBridge)).add(String.format("[ %s ]", downBridge)).toString();
+ }
+
+ private static void addBridgeSegment(String userSegment, String gameSegment, StringJoiner upBridge, StringJoiner downBridge) {
+ if (userSegment.equals(gameSegment)) {
+ addMatchingSegment(userSegment, upBridge, downBridge);
+ } else {
+ addNonMatchingSegment(userSegment, upBridge, downBridge);
+ }
+ }
+
+ private static void addMatchingSegment(String segment, StringJoiner upBridge, StringJoiner downBridge) {
+ if (segment.equals("U")) {
+ upBridge.add("O");
+ downBridge.add(" ");
+ } else if (segment.equals("D")) {
+ upBridge.add(" ");
+ downBridge.add("O");
+ }
+ }
+
+ private static void addNonMatchingSegment(String segment, StringJoiner upBridge, StringJoiner downBridge) {
+ if (segment.equals("U")) {
+ upBridge.add("X");
+ downBridge.add(" ");
+ } else if (segment.equals("D")) {
+ upBridge.add(" ");
+ downBridge.add("X");
+ }
+ }
+} | Java | ๋ง๋๋ง์ธ๊ฑฐ๊ฐ์ต๋๋ค.. ์ธ์๊ฐ 4๊ฐ๋ ๋๋ค๋ณด๋ ์ ๋ง ๋ง์ ์๋๋ ๋ฉ์๋์๋๋ฐ์ ์ฌ๊ธธ ๋ฆฌํฉํ ๋ง ํ๋ ค๊ณ ํ๋ map์ ์ฌ์ฉํ๊ฑฐ๋ ํด์ผํ๋๋ฐ ๊ณ์ ๋ฆฌํฉํ ๋ง ๋์ ํด๋ดค๋๋ฐ ๊ธฐ์กด ๊ตฌ์กฐ๋ฅผ ๊นจ๊ณ ๋ง๋ค์ด์ผ๋๋ ๋ถ๋ถ์ด ์กด์ฌํด์ ๊ธฐ์กด๊ตฌ์กฐ ์ ์งํ๊ณ ๊ฐ๋๋ผ ์์ฌ์ด ๋ถ๋ถ์ด ๋์จ๊ฒ ๊ฐ์ต๋๋คใ
ใ
|
@@ -0,0 +1,74 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.message.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+public class ChristmasPromotionController {
+ private EventCalendar eventCalendar;
+ private VisitDate visitDate;
+ private Menu menu;
+ private Event event;
+ private StarDate starDate;
+
+ public void run() {
+ eventCalendarSetting(2023, 12);
+ starDateSetting();
+ visitDate();
+ menuSetting();
+ eventSetting();
+ result();
+ }
+
+ private void eventCalendarSetting(int year, int month) {
+ this.eventCalendar = new EventCalendar(year, month);
+ }
+
+ private void starDateSetting() {
+ this.starDate = new StarDate(eventCalendar);
+ }
+
+ private void visitDate() {
+ OutputView.printStart();
+ while (true) {
+ try {
+ this.visitDate = VisitDate.of(InputView.readDate(), this.eventCalendar);
+ return;
+ } catch (IllegalArgumentException e) {
+ OutputView.printErrorMessage(ErrorMessage.INVALID_DATE.getFormattedMessage());
+ System.out.println(e.getMessage());
+ System.out.println();
+ }
+ }
+ }
+
+ private void menuSetting() {
+ while (true) {
+ try {
+ this.menu = new Menu(InputView.readMenu());
+ return;
+ } catch (IllegalArgumentException e) {
+ OutputView.printErrorMessage(ErrorMessage.INVALID_ORDER.getFormattedMessage());
+ System.out.println(e.getMessage());
+ OutputView.printAllMenu(e.getMessage());
+ System.out.println();
+ }
+ }
+ }
+
+ private void eventSetting() {
+ this.event = new Event();
+ this.event.eventSetting(visitDate, eventCalendar, starDate, menu);
+ }
+
+ private void result() {
+ OutputView.printSelectMenu(menu);
+ OutputView.printBeforeDiscountMenuTotalPrice(menu);
+ OutputView.printGift(event);
+ OutputView.printBenefitHistory(event);
+ OutputView.printBenefitsAllAmount(event);
+ OutputView.printAfterDiscount(menu, event);
+ OutputView.printBadge(event, eventCalendar);
+ }
+} | Java | `InputView` ์์ `CommonValidator` ๋ฅผ ํตํด์ ๊ฒ์ฆ์ ํ๋๊ฒ์ผ๋ก ๋ณด์
๋๋ค. ๊ทธ๋ ๋ค๋ฉด `InputValidator` ์์ ์ถ๊ฐ์ ์ธ ๊ฒ์ฆ๋ ํจ๊ป ์งํํด์ ์์ธ๋ฅผ ์ฒ๋ฆฌํ๋ ์์ผ๋ก ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
์ ๋ ์
๋ ฅ์ ๋ด๋นํ๋ ํด๋์ค์์ ์
๋ ฅ์ ๋ฐ๊ณ ๊ฒ์ฆ ํด๋์ค๋ฅผ ํตํด ๊ฒ์ฆํ ์์ธ๊น์ง ๋์ง๋๋ก ๊ตฌํํ๋๋ ๊น๋ํ๊ฒ ๊ตฌํํ๋๊ฑฐ ๊ฐ์์ ์ฌ์ญค๋ด
๋๋ค! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.