code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,117 @@
+package christmas.domain;
+
+import christmas.domain.event.badge.BadgeEvent;
+import christmas.domain.event.discount.DDayEvent;
+import christmas.domain.event.discount.DiscountEvent;
+import christmas.domain.event.discount.SpecialEvent;
+import christmas.domain.event.discount.WeekdayEvent;
+import christmas.domain.event.discount.WeekendEvent;
+import christmas.domain.event.giveaway.ChampagneEvent;
+import christmas.domain.event.giveaway.Giveaway;
+import christmas.domain.event.giveaway.GiveawayEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitDetails {
+
+ private static final int PARTICIPATION_CRITERIA = 10000;
+ private static final int MIN_AMOUNT = 0;
+ public static final int EVENT_START_DAY = 1;
+ public static final int EVENT_LAST_DAY = 31;
+ private final List<String> discountNames;
+ private final List<Integer> discountAmount;
+ private int totalDiscountAmount;
+ private String badge;
+ private Giveaway giveaway;
+
+ public BenefitDetails() {
+ this.discountNames = new ArrayList<>();
+ this.discountAmount = new ArrayList<>();
+ }
+
+ public static BenefitDetails getBenefitDetails() {
+ return new BenefitDetails();
+ }
+
+ public void receive(int date, Bill bill) {
+ if (bill.getTotalAmount() >= PARTICIPATION_CRITERIA &&
+ date >= EVENT_START_DAY && date <= EVENT_LAST_DAY) {
+ getDiscountInfo(date, bill);
+ }
+ getGiveawayInfo(bill);
+ this.totalDiscountAmount = discountAmount.stream().mapToInt(Integer::intValue).sum();
+ this.badge = BadgeEvent.getBenefitAmountEvent().giveBadge(totalDiscountAmount);
+ }
+
+ private void getGiveawayInfo(Bill bill) {
+ ChampagneEvent champagneEvent = GiveawayEvent.getChampagneEvent();
+ this.giveaway = champagneEvent.give(bill.getTotalAmount());
+ if (giveaway.quantity() > MIN_AMOUNT) {
+ discountNames.add(champagneEvent.getChampagneEventName());
+ discountAmount.add(giveaway.price());
+ }
+ }
+
+ private void getDiscountInfo(int date, Bill bill) {
+ getDDayEventInfo(date);
+ getWeekdayEventInfo(date, bill.getNumberOfDessert());
+ getWeekendEventInfo(date, bill.getNumberOfMain());
+ getSpecialEventInfo(date);
+ }
+
+ private void getSpecialEventInfo(int date) {
+ SpecialEvent specialEvent = DiscountEvent.getSpecialEvent();
+ int discount = specialEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(specialEvent.getSpecialEventName());
+ }
+ }
+
+ private void getWeekendEventInfo(int date, int numberOfMain) {
+ WeekendEvent weekendEvent = DiscountEvent.getWeekendEvent();
+ int discount = weekendEvent.discount(date, numberOfMain);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekendEvent.getWeekendEventName());
+ }
+ }
+
+ private void getWeekdayEventInfo(int date, int numberOfDessert) {
+ WeekdayEvent weekdayEvent = DiscountEvent.getWeekdayEvent();
+ int discount = weekdayEvent.discount(date, numberOfDessert);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekdayEvent.getWeekdayEventName());
+ }
+ }
+
+ private void getDDayEventInfo(int date) {
+ DDayEvent dDayEvent = DiscountEvent.getDDayEvent();
+ int discount = dDayEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(dDayEvent.getDDayEventName());
+ }
+ }
+
+ public List<String> getDiscountNames() {
+ return discountNames;
+ }
+
+ public List<Integer> getDiscountAmount() {
+ return discountAmount;
+ }
+
+ public int getTotalDiscountAmount() {
+ return totalDiscountAmount;
+ }
+
+ public String getBadge() {
+ return badge;
+ }
+
+ public Giveaway getGiveaway() {
+ return giveaway;
+ }
+} | Java | ๋งค๊ฐ๋ณ์๋ก๋ถํฐ ์ดํ์ธ ์ด๋ฒคํธ์ ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ๋ ๊ฒ์ด๋ give ๋ง๊ณ ํน์ from ์ด๋ of๋ผ๋ ๋ฉ์๋๋ช
์ ์ด๋ ์ ๊ฐ์~? |
@@ -0,0 +1,117 @@
+package christmas.domain;
+
+import christmas.domain.event.badge.BadgeEvent;
+import christmas.domain.event.discount.DDayEvent;
+import christmas.domain.event.discount.DiscountEvent;
+import christmas.domain.event.discount.SpecialEvent;
+import christmas.domain.event.discount.WeekdayEvent;
+import christmas.domain.event.discount.WeekendEvent;
+import christmas.domain.event.giveaway.ChampagneEvent;
+import christmas.domain.event.giveaway.Giveaway;
+import christmas.domain.event.giveaway.GiveawayEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitDetails {
+
+ private static final int PARTICIPATION_CRITERIA = 10000;
+ private static final int MIN_AMOUNT = 0;
+ public static final int EVENT_START_DAY = 1;
+ public static final int EVENT_LAST_DAY = 31;
+ private final List<String> discountNames;
+ private final List<Integer> discountAmount;
+ private int totalDiscountAmount;
+ private String badge;
+ private Giveaway giveaway;
+
+ public BenefitDetails() {
+ this.discountNames = new ArrayList<>();
+ this.discountAmount = new ArrayList<>();
+ }
+
+ public static BenefitDetails getBenefitDetails() {
+ return new BenefitDetails();
+ }
+
+ public void receive(int date, Bill bill) {
+ if (bill.getTotalAmount() >= PARTICIPATION_CRITERIA &&
+ date >= EVENT_START_DAY && date <= EVENT_LAST_DAY) {
+ getDiscountInfo(date, bill);
+ }
+ getGiveawayInfo(bill);
+ this.totalDiscountAmount = discountAmount.stream().mapToInt(Integer::intValue).sum();
+ this.badge = BadgeEvent.getBenefitAmountEvent().giveBadge(totalDiscountAmount);
+ }
+
+ private void getGiveawayInfo(Bill bill) {
+ ChampagneEvent champagneEvent = GiveawayEvent.getChampagneEvent();
+ this.giveaway = champagneEvent.give(bill.getTotalAmount());
+ if (giveaway.quantity() > MIN_AMOUNT) {
+ discountNames.add(champagneEvent.getChampagneEventName());
+ discountAmount.add(giveaway.price());
+ }
+ }
+
+ private void getDiscountInfo(int date, Bill bill) {
+ getDDayEventInfo(date);
+ getWeekdayEventInfo(date, bill.getNumberOfDessert());
+ getWeekendEventInfo(date, bill.getNumberOfMain());
+ getSpecialEventInfo(date);
+ }
+
+ private void getSpecialEventInfo(int date) {
+ SpecialEvent specialEvent = DiscountEvent.getSpecialEvent();
+ int discount = specialEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(specialEvent.getSpecialEventName());
+ }
+ }
+
+ private void getWeekendEventInfo(int date, int numberOfMain) {
+ WeekendEvent weekendEvent = DiscountEvent.getWeekendEvent();
+ int discount = weekendEvent.discount(date, numberOfMain);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekendEvent.getWeekendEventName());
+ }
+ }
+
+ private void getWeekdayEventInfo(int date, int numberOfDessert) {
+ WeekdayEvent weekdayEvent = DiscountEvent.getWeekdayEvent();
+ int discount = weekdayEvent.discount(date, numberOfDessert);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekdayEvent.getWeekdayEventName());
+ }
+ }
+
+ private void getDDayEventInfo(int date) {
+ DDayEvent dDayEvent = DiscountEvent.getDDayEvent();
+ int discount = dDayEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(dDayEvent.getDDayEventName());
+ }
+ }
+
+ public List<String> getDiscountNames() {
+ return discountNames;
+ }
+
+ public List<Integer> getDiscountAmount() {
+ return discountAmount;
+ }
+
+ public int getTotalDiscountAmount() {
+ return totalDiscountAmount;
+ }
+
+ public String getBadge() {
+ return badge;
+ }
+
+ public Giveaway getGiveaway() {
+ return giveaway;
+ }
+} | Java | ํ์คํ ๋๋ฉ์ธ ์ชฝ์์ ํน์ ์ด๋ฒคํธ ํ ์ธ ๊ธ์ก์ด 0์ผ๋ ํ ์ธ ๋ฆฌ์คํธ์ ํฌํจ์ํค์ง ์๋ ๊ฒ์ด ์ข์๋ณด์ด๋ค์. ์ ๋ ์ด๋ถ๋ถ์ ํด๊ฒฐ ๋ชปํด์ ๋ทฐ ์ชฝ์์ ์ถ๋ ฅํ ๋ ํํฐ๋ง ํ๋๊ฑธ๋ก ์ค๊ณ๋ฅผ ํ๊ฑฐ๋ ์! ๋ค์ ๊ตฌํ๋๋ ์ฐธ๊ณ ํด์ ๋ฐ์ ํด๋ณด๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,35 @@
+package christmas.domain;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Stream;
+
+public enum Menu {
+
+ APPETIZER(List.of("์์ก์ด์ํ", "ํํ์ค", "์์ ์๋ฌ๋"), List.of(6000, 5500, 8000)),
+ MAIN(List.of("ํฐ๋ณธ์คํ
์ดํฌ", "๋ฐ๋นํ๋ฆฝ", "ํด์ฐ๋ฌผํ์คํ", "ํฌ๋ฆฌ์ค๋ง์คํ์คํ"), List.of(55000, 54000, 35000, 25000)),
+ DESSERT(List.of("์ด์ฝ์ผ์ดํฌ", "์์ด์คํฌ๋ฆผ"), List.of(15000, 5000)),
+ BEVERAGE(List.of("์ ๋ก์ฝ๋ผ", "๋ ๋์์ธ", "์ดํ์ธ"), List.of(3000, 60000, 25000));
+
+ private static final List<String> ALL_MENU = Stream.of(APPETIZER.menuName, MAIN.menuName,
+ DESSERT.menuName, BEVERAGE.menuName).flatMap(Collection::stream).toList();
+ private final List<String> menuName;
+ private final List<Integer> menuPrice;
+
+ Menu(List<String> menuName, List<Integer> menuPrice) {
+ this.menuName = menuName;
+ this.menuPrice = menuPrice;
+ }
+
+ public List<String> getMenuName() {
+ return menuName;
+ }
+
+ public List<Integer> getMenuPrice() {
+ return menuPrice;
+ }
+
+ public static boolean isExistMenu(String menu) {
+ return ALL_MENU.contains(menu);
+ }
+} | Java | ์นดํ
๊ณ ๋ฆฌ ์์ ๋ฆฌ์คํธ๋ฅผ ๊ฐ์ ธ๊ฐ์
จ๊ตฐ์! ์ด๋ถ๋ถ์ ๋ํด์ ํจ๊ป ๋ง์ ๋๋ ๋ณด๋ฉด ์ข์๊ฑฐ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,25 @@
+package christmas.domain.event.badge;
+
+public class BenefitAmountEvent {
+
+ private static final String STAR_BADGE = "๋ณ";
+ private static final String TREE_BADGE = "ํธ๋ฆฌ";
+ private static final String SANTA_BADGE = "์ฐํ";
+ private static final String NONE = "์์";
+ private static final int STAR_STANDARD_AMOUNT = 5000;
+ private static final int TREE_STANDARD_AMOUNT = 10000;
+ private static final int SANTA_STANDARD_AMOUNT = 20000;
+
+ public String giveBadge(int benefitAmount) {
+ if (benefitAmount < STAR_STANDARD_AMOUNT) {
+ return NONE;
+ }
+ if (benefitAmount < TREE_STANDARD_AMOUNT) {
+ return STAR_BADGE;
+ }
+ if (benefitAmount < SANTA_STANDARD_AMOUNT) {
+ return TREE_BADGE;
+ }
+ return SANTA_BADGE;
+ }
+} | Java | ์ด๋ถ๋ถ enum์ผ๋ก ๊ฐ์ ธ๊ฐ์๋๊ฑฐ์ ๋ํด์ ์ด๋ป๊ฒ ์๊ฐํ์๋์~? |
@@ -0,0 +1,25 @@
+package christmas.domain.event.badge;
+
+public class BenefitAmountEvent {
+
+ private static final String STAR_BADGE = "๋ณ";
+ private static final String TREE_BADGE = "ํธ๋ฆฌ";
+ private static final String SANTA_BADGE = "์ฐํ";
+ private static final String NONE = "์์";
+ private static final int STAR_STANDARD_AMOUNT = 5000;
+ private static final int TREE_STANDARD_AMOUNT = 10000;
+ private static final int SANTA_STANDARD_AMOUNT = 20000;
+
+ public String giveBadge(int benefitAmount) {
+ if (benefitAmount < STAR_STANDARD_AMOUNT) {
+ return NONE;
+ }
+ if (benefitAmount < TREE_STANDARD_AMOUNT) {
+ return STAR_BADGE;
+ }
+ if (benefitAmount < SANTA_STANDARD_AMOUNT) {
+ return TREE_BADGE;
+ }
+ return SANTA_BADGE;
+ }
+} | Java | ์ ์ ๋ ์ด๋ถ๋ถ์ ์กฐ๊ฑด์ ๋ณต์กํ๊ฒ ๊ฐ์ ธ๊ฐ์๋๋ฐ ์ง๊ธ ๋ณด๋ ๊ทธ๋ดํ์๊ฐ ์์๋ค์... ๋ฐฐ์๊ฐ๋๋ค! |
@@ -0,0 +1,7 @@
+package christmas.util;
+
+public class Constant {
+
+ public static final String DELIMITER_COMMA = ",";
+ public static final String DELIMITER_HYPHEN = "-";
+} | Java | ํด๋น ์์๋ฅผ ์ฌ์ฉํ์๋ ํด๋์ค์์ ์ ์ธํด์ฃผ์
๋ ๊ด์ฐฎ์๊ฑฐ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,21 @@
+package christmas.util.validator;
+
+import java.util.regex.Pattern;
+
+public abstract class Validator {
+
+ protected abstract void validate(String input);
+
+ public void validateInputPattern(String input, String regex, String error) {
+ Pattern pattern = Pattern.compile(regex);
+ if (!pattern.matcher(input).matches()) {
+ throw new IllegalArgumentException(error);
+ }
+ }
+
+ public void validateNumberRange(int number, int minNumber, int maxNumber, String error) {
+ if (number < minNumber || number > maxNumber) {
+ throw new IllegalArgumentException(error);
+ }
+ }
+} | Java | ์ถ์ํด๋์ค๋ฅผ ์ฌ์ฉํ์ ๊ฑฐ ์ข๋ค์!! |
@@ -0,0 +1,52 @@
+package christmas.view;
+
+import static christmas.util.Constant.*;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.util.validator.DateValidator;
+import christmas.util.validator.MenuValidator;
+import java.util.HashMap;
+import java.util.Map;
+
+public class InputView {
+
+ public int readDate() {
+ DateValidator validator = DateValidator.getValidator();
+ while (true) {
+ try {
+ String inputDate = input();
+ validator.validate(inputDate);
+ return Integer.parseInt(inputDate);
+ } catch (IllegalArgumentException error) {
+ System.out.println(error.getMessage());
+ }
+ }
+ }
+
+ public Map<String, Integer> readMenu() {
+ MenuValidator validator = MenuValidator.getValidator();
+ while (true) {
+ try {
+ String inputOrder = input();
+ validator.validate(inputOrder);
+ return getOrder(inputOrder);
+ } catch (IllegalArgumentException error) {
+ System.out.println(error.getMessage());
+ }
+ }
+ }
+
+ private Map<String, Integer> getOrder(String inputOrder) {
+ Map<String, Integer> order = new HashMap<>();
+ String[] menus = inputOrder.split(DELIMITER_COMMA);
+ for (String menu : menus) {
+ String[] menuInfo = menu.split(DELIMITER_HYPHEN);
+ order.put(menuInfo[0], Integer.parseInt(menuInfo[1]));
+ }
+ return order;
+ }
+
+ private String input() {
+ return Console.readLine();
+ }
+} | Java | ์ ๊ฐ ์ปจํธ๋กค๋ฌ์์ ์์ธ์ฒ๋ฆฌ๋ฅผ ํ ์ด์ ๋ ์๋ฅผ ๋ค์ด ๋ ์ง๋ฅผ ๊ฒ์ฆํ ๋ InputView์์๋ ๋ฌธ์๊ฐ์ด ํฌํจ ๋์๋์ง์ ๋ํ ๊ฒ์ฆ์, ๋๋ฉ์ธ์์๋ 1~31 ์ฌ์ด์ ์ซ์์ธ์ง ํ์ธ์ ํด์ผํ๊ธฐ ๋๋ฌธ์ด์์ต๋๋ค! ์น์ฐ๋์ฒ๋ผ ๋๋ฉ์ธ์ชฝ์์ ๊ฒ์ฆ์ด ํ์ํ์ง ์๋ค๋ฉด View์์ ์์ธ์ฒ๋ฆฌ๋ฅผ ํ๋ ๊ฒ๋ ๊ด์ฐฎ์ ๋ฐฉ๋ฒ์ธ๊ฑฐ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,118 @@
+import React, { useEffect, useState } from "react";
+import { Link, useNavigate } from "react-router-dom";
+import { signin } from "../../api";
+import styled from "styled-components";
+
+function SignIn() {
+ const navigate = useNavigate();
+ const [auth, setAuth] = useState({
+ email: "",
+ password: "",
+ });
+ const [isValid, setValid] = useState(false);
+ const [errorMessage, setError] = useState("");
+
+ const handleAuth = (e) => {
+ const { name, value } = e.target;
+ setValid(true);
+ setAuth((prev) => ({
+ ...prev,
+ [name]: value,
+ }));
+ };
+
+ const handleSignIn = async (e) => {
+ e.preventDefault();
+ setValid(false);
+ if (!auth?.email || !auth.email.includes("@")) {
+ setError("์ด๋ฉ์ผ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.");
+ } else if (!auth?.password || auth.password.length < 8) {
+ setError("๋น๋ฐ๋ฒํธ๋ ์ต์ 8์ ์ด์์ด์ด์ผ ํฉ๋๋ค.");
+ } else {
+ setError("");
+ setValid(true);
+ const isSign = await signin(auth);
+ if (isSign) return navigate("/todo");
+ }
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (token) {
+ return navigate("/todo");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ return (
+ <Container>
+ <h1>SIGN IN</h1>
+ <form onSubmit={handleSignIn}>
+ <input
+ data-testid="email-input"
+ type="text"
+ name="email"
+ onChange={handleAuth}
+ />
+ <input
+ data-testid="password-input"
+ type="password"
+ name="password"
+ onChange={handleAuth}
+ />
+ <button data-testid="signin-button" disabled={!isValid}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ {!isValid && <span>{errorMessage}</span>}
+ <StyledLink to="/signup">ํ์๊ฐ์
</StyledLink>
+ </Container>
+ );
+}
+
+export default SignIn;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const StyledLink = styled(Link)`
+ box-sizing: border-box;
+ display: block;
+ padding: 4px 8px;
+ margin: 0 auto;
+ text-align: center;
+ color: white;
+ text-decoration: none;
+`; | JavaScript | placeholder๋ก ํ์์ ์๋ ค์ฃผ๋ฉด ์ฌ์ฉ์ ๊ฒฝํ์ด ์ข ๋ ์ข์ง ์์๊น ์๊ฐํฉ๋๋ค!_! `@`๋ฅผ ํฌํจํด์ผ ํ๋ค๊ฑฐ๋ ๋น๋ฐ๋ฒํธ๋ 8์ ์ด์์ด์ด์ผ ํ๋ค๊ฑฐ๋..! |
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="theme-color" content="#000000" />
+ <meta
+ name="description"
+ content="Web site created using create-react-app"
+ />
+ <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
+ <!--
+ manifest.json provides metadata used when your web app is installed on a
+ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
+ -->
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
+ <!--
+ Notice the use of %PUBLIC_URL% in the tags above.
+ It will be replaced with the URL of the `public` folder during the build.
+ Only files inside the `public` folder can be referenced from the HTML.
+
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
+ work correctly both with client-side routing and a non-root public URL.
+ Learn how to configure a non-root public URL by running `npm run build`.
+ -->
+ <title>React App</title>
+ </head>
+ <body>
+ <noscript>You need to enable JavaScript to run this app.</noscript>
+ <div id="root"></div>
+ <!--
+ This HTML file is a template.
+ If you open it directly in the browser, you will see an empty page.
+
+ You can add webfonts, meta tags, or analytics to this file.
+ The build step will place the bundled scripts into the <body> tag.
+
+ To begin the development, run `npm start` or `yarn start`.
+ To create a production bundle, use `npm run build` or `yarn build`.
+ -->
+ </body>
+</html> | Unknown | ์์ด์ฝ์ด ํฌํจ๋ ํ๊ทธ๋ ํฌ๋์ฑ๊ณผ ํฐ ์๊ด์ด ์๋ค๊ณ ์๊ฐํ๋๋ฐ, ์ ๊ฑฐํด๋ ์ข์ง์์๊น ์ถ์ต๋๋ค! |
@@ -0,0 +1,34 @@
+import { Navigate, createBrowserRouter } from "react-router-dom";
+import App from "./App";
+import SignIn from "./Page/Auth/SignIn";
+import SignUp from "./Page/Auth/SignUp";
+import ToDoList from "./Page/ToDos/ToDoList";
+
+const routes = [
+ {
+ path: "",
+ element: <App />,
+ children: [
+ {
+ path: "/",
+ element: <Navigate to="/signin" />,
+ },
+ {
+ path: "/signin",
+ element: <SignIn />,
+ },
+ {
+ path: "/signup",
+ element: <SignUp />,
+ },
+ {
+ path: "/todo",
+ element: <ToDoList />,
+ },
+ ],
+ },
+];
+
+const router = createBrowserRouter(routes);
+
+export default router; | JavaScript | ์ค ๋ผ์ฐํฐ๋ฅผ ์ค์ฒฉํด์ ์์ฑํ ์๋ ์๊ตฐ์..! |
@@ -0,0 +1,118 @@
+import React, { useEffect, useState } from "react";
+import { Link, useNavigate } from "react-router-dom";
+import { signin } from "../../api";
+import styled from "styled-components";
+
+function SignIn() {
+ const navigate = useNavigate();
+ const [auth, setAuth] = useState({
+ email: "",
+ password: "",
+ });
+ const [isValid, setValid] = useState(false);
+ const [errorMessage, setError] = useState("");
+
+ const handleAuth = (e) => {
+ const { name, value } = e.target;
+ setValid(true);
+ setAuth((prev) => ({
+ ...prev,
+ [name]: value,
+ }));
+ };
+
+ const handleSignIn = async (e) => {
+ e.preventDefault();
+ setValid(false);
+ if (!auth?.email || !auth.email.includes("@")) {
+ setError("์ด๋ฉ์ผ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.");
+ } else if (!auth?.password || auth.password.length < 8) {
+ setError("๋น๋ฐ๋ฒํธ๋ ์ต์ 8์ ์ด์์ด์ด์ผ ํฉ๋๋ค.");
+ } else {
+ setError("");
+ setValid(true);
+ const isSign = await signin(auth);
+ if (isSign) return navigate("/todo");
+ }
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (token) {
+ return navigate("/todo");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ return (
+ <Container>
+ <h1>SIGN IN</h1>
+ <form onSubmit={handleSignIn}>
+ <input
+ data-testid="email-input"
+ type="text"
+ name="email"
+ onChange={handleAuth}
+ />
+ <input
+ data-testid="password-input"
+ type="password"
+ name="password"
+ onChange={handleAuth}
+ />
+ <button data-testid="signin-button" disabled={!isValid}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ {!isValid && <span>{errorMessage}</span>}
+ <StyledLink to="/signup">ํ์๊ฐ์
</StyledLink>
+ </Container>
+ );
+}
+
+export default SignIn;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const StyledLink = styled(Link)`
+ box-sizing: border-box;
+ display: block;
+ padding: 4px 8px;
+ margin: 0 auto;
+ text-align: center;
+ color: white;
+ text-decoration: none;
+`; | JavaScript | ์ด๋ฉ์ผ, ๋น๋ฐ๋ฒํธ input ์ด๋ฒคํธ ํธ๋ค๋ฌ๊ฐ ๊ณต์ ํด์ ์ฌ์ฉํ ์ ์๊ฒ
์ ์ถ์ํ๋ ๊ธฐ๋ฅ์ธ ๊ฒ ๊ฐ์์!
์ ๊ทผ๋ฐ ์ธํ์ด ๋ค์ด์ค๋ฉด ํญ์ valid ์ํ๊ฐ true๋ก ์ธํ
๋๋๋ฐ
๊ฒ์ฌํ ํ์ valid์ฒดํฌํ๋ ๊ฒ ๋ก์ง์ ๋ง์ง์๋์..?! ๐ |
@@ -0,0 +1,118 @@
+import React, { useEffect, useState } from "react";
+import { Link, useNavigate } from "react-router-dom";
+import { signin } from "../../api";
+import styled from "styled-components";
+
+function SignIn() {
+ const navigate = useNavigate();
+ const [auth, setAuth] = useState({
+ email: "",
+ password: "",
+ });
+ const [isValid, setValid] = useState(false);
+ const [errorMessage, setError] = useState("");
+
+ const handleAuth = (e) => {
+ const { name, value } = e.target;
+ setValid(true);
+ setAuth((prev) => ({
+ ...prev,
+ [name]: value,
+ }));
+ };
+
+ const handleSignIn = async (e) => {
+ e.preventDefault();
+ setValid(false);
+ if (!auth?.email || !auth.email.includes("@")) {
+ setError("์ด๋ฉ์ผ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.");
+ } else if (!auth?.password || auth.password.length < 8) {
+ setError("๋น๋ฐ๋ฒํธ๋ ์ต์ 8์ ์ด์์ด์ด์ผ ํฉ๋๋ค.");
+ } else {
+ setError("");
+ setValid(true);
+ const isSign = await signin(auth);
+ if (isSign) return navigate("/todo");
+ }
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (token) {
+ return navigate("/todo");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ return (
+ <Container>
+ <h1>SIGN IN</h1>
+ <form onSubmit={handleSignIn}>
+ <input
+ data-testid="email-input"
+ type="text"
+ name="email"
+ onChange={handleAuth}
+ />
+ <input
+ data-testid="password-input"
+ type="password"
+ name="password"
+ onChange={handleAuth}
+ />
+ <button data-testid="signin-button" disabled={!isValid}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ {!isValid && <span>{errorMessage}</span>}
+ <StyledLink to="/signup">ํ์๊ฐ์
</StyledLink>
+ </Container>
+ );
+}
+
+export default SignIn;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const StyledLink = styled(Link)`
+ box-sizing: border-box;
+ display: block;
+ padding: 4px 8px;
+ margin: 0 auto;
+ text-align: center;
+ color: white;
+ text-decoration: none;
+`; | JavaScript | ๊ฐ์์๊ธฐ๋ผ ๋ต๊ธ ๋ต๋๋ค!
handleAuth์์๋ setValid(true)๋ง ํ ๊ฒ์ด ์๋๋ผ ํ์ฌ ์ํ๊ฐ validํ์ง ํ๋จํ๋ ๋ก์ง์ด ์ถ๊ฐ์ ์ผ๋ก ํ์ํ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,118 @@
+import React, { useEffect, useState } from "react";
+import { Link, useNavigate } from "react-router-dom";
+import { signin } from "../../api";
+import styled from "styled-components";
+
+function SignIn() {
+ const navigate = useNavigate();
+ const [auth, setAuth] = useState({
+ email: "",
+ password: "",
+ });
+ const [isValid, setValid] = useState(false);
+ const [errorMessage, setError] = useState("");
+
+ const handleAuth = (e) => {
+ const { name, value } = e.target;
+ setValid(true);
+ setAuth((prev) => ({
+ ...prev,
+ [name]: value,
+ }));
+ };
+
+ const handleSignIn = async (e) => {
+ e.preventDefault();
+ setValid(false);
+ if (!auth?.email || !auth.email.includes("@")) {
+ setError("์ด๋ฉ์ผ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.");
+ } else if (!auth?.password || auth.password.length < 8) {
+ setError("๋น๋ฐ๋ฒํธ๋ ์ต์ 8์ ์ด์์ด์ด์ผ ํฉ๋๋ค.");
+ } else {
+ setError("");
+ setValid(true);
+ const isSign = await signin(auth);
+ if (isSign) return navigate("/todo");
+ }
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (token) {
+ return navigate("/todo");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ return (
+ <Container>
+ <h1>SIGN IN</h1>
+ <form onSubmit={handleSignIn}>
+ <input
+ data-testid="email-input"
+ type="text"
+ name="email"
+ onChange={handleAuth}
+ />
+ <input
+ data-testid="password-input"
+ type="password"
+ name="password"
+ onChange={handleAuth}
+ />
+ <button data-testid="signin-button" disabled={!isValid}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ {!isValid && <span>{errorMessage}</span>}
+ <StyledLink to="/signup">ํ์๊ฐ์
</StyledLink>
+ </Container>
+ );
+}
+
+export default SignIn;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const StyledLink = styled(Link)`
+ box-sizing: border-box;
+ display: block;
+ padding: 4px 8px;
+ margin: 0 auto;
+ text-align: center;
+ color: white;
+ text-decoration: none;
+`; | JavaScript | ์์์๋ ๋งํ๋ฏ์ด ๊ณผ์ ์ ๊ตฌํ ์ฌํญ์
`์
๋ ฅ๋ ์ด๋ฉ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๊ฐ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํต๊ณผํ์ง ๋ชปํ๋ค๋ฉด button์ disabled ์์ฑ์ ๋ถ์ฌํด์ฃผ์ธ์`
์ฆ submit์ด์ ์ ์ ํจ์ฑ๊ฒ์ฌ๋ฅผ ์ฒดํฌ ํ๊ณ disabled ์ํ๋ฅผ ๊ด๋ฆฌ ํด ์ค์ผ ํฉ๋๋ค. submit ์ ์ถ์์ ๊ฒ์ฌํ๋ฉด ์ ๋ ๊ฒ ๊ฐ์ต๋๋ค(๊ตฌํ์ฌํญ๋๋ก๋ผ๋ฉด) |
@@ -0,0 +1,34 @@
+import { Navigate, createBrowserRouter } from "react-router-dom";
+import App from "./App";
+import SignIn from "./Page/Auth/SignIn";
+import SignUp from "./Page/Auth/SignUp";
+import ToDoList from "./Page/ToDos/ToDoList";
+
+const routes = [
+ {
+ path: "",
+ element: <App />,
+ children: [
+ {
+ path: "/",
+ element: <Navigate to="/signin" />,
+ },
+ {
+ path: "/signin",
+ element: <SignIn />,
+ },
+ {
+ path: "/signup",
+ element: <SignUp />,
+ },
+ {
+ path: "/todo",
+ element: <ToDoList />,
+ },
+ ],
+ },
+];
+
+const router = createBrowserRouter(routes);
+
+export default router; | JavaScript | errorBoundary๋ errorElement๋ฅผ ์ฌ์ฉํด๋ณด๋ ๊ฒ์ด ์ด๋จ๊น์?
์๋ชป๋ url๋ก ์ ๊ทผ์ ํ์ฌ๋ ์ฑ์ด ๋ง๊ฐ์ง๋ ์ํฉ์ธ๋ฐ ์ต์ํ์ ์์ ์ฅ์น๊ฐ Route๋จ์ ์์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ๐ |
@@ -0,0 +1,94 @@
+import axios from "axios";
+
+const baseURL = "https://www.pre-onboarding-selection-task.shop";
+
+export const signUp = async (data) => {
+ try {
+ const response = await axios.post(
+ `${baseURL}/auth/signup`,
+ { email: data.email, password: data.password },
+ {
+ headers: { "Content-Type": "application/json" },
+ }
+ );
+ return response.status;
+ } catch (e) {
+ console.log(e.response.message);
+ }
+};
+
+export const signin = async (data) => {
+ try {
+ const response = await axios.post(
+ `${baseURL}/auth/signin`,
+ { email: data.email, password: data.password },
+ {
+ headers: { "Content-Type": "application/json" },
+ }
+ );
+ if (response.status === 200) {
+ const { access_token } = response.data;
+ localStorage.setItem("token", access_token);
+ return access_token;
+ }
+ } catch (e) {
+ return e;
+ }
+};
+
+export const createTodo = async (todo) => {
+ const data = { todo };
+ try {
+ const response = await axios.post(`${baseURL}/todos`, data, {
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${localStorage.getItem("token")}`,
+ },
+ });
+ return response.data;
+ } catch (error) {
+ console.log(error);
+ }
+};
+
+export const getTodos = async () => {
+ try {
+ const response = await axios.get(`${baseURL}/todos`, {
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${localStorage.getItem("token")}`,
+ },
+ });
+ return response.data;
+ } catch (e) {
+ console.log(e);
+ }
+};
+
+export const deleteTodo = async (id) => {
+ try {
+ const response = await axios.delete(`${baseURL}/todos/${id}`, {
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem("token")}`,
+ },
+ });
+ return response.status;
+ } catch (e) {
+ console.log(e);
+ }
+};
+
+export const updateTodo = async (data, id) => {
+ console.log(data);
+ try {
+ const response = await axios.put(`${baseURL}/todos/${id}`, data, {
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${localStorage.getItem("token")}`,
+ },
+ });
+ return response.data;
+ } catch (e) {
+ console.log(e);
+ }
+}; | JavaScript | ๋ฐ๋ณต๋๋ baseUrl๊ณผ header๋ axios instance์ axios interceptor๋ก ์ค์ผ ์ ์์๊ฒ ๊ฐ์์! |
@@ -0,0 +1,150 @@
+import React, { useEffect, useState } from "react";
+import styled from "styled-components";
+import { createTodo, deleteTodo, getTodos, updateTodo } from "../../api";
+import ToDo from "./ToDo";
+import { useNavigate } from "react-router-dom";
+
+function ToDoList() {
+ const [todo, setTodo] = useState("");
+ const [toDoList, setToDoList] = useState([]);
+
+ const [error, setError] = useState("");
+ const navigate = useNavigate();
+ const onChange = (e) => {
+ setError("");
+ setTodo(e.target.value);
+ };
+
+ const fetch = async () => {
+ try {
+ const todos = await getTodos();
+ setToDoList(todos);
+ } catch (e) {
+ console.log(e);
+ }
+ };
+
+ const onSubmit = async (e) => {
+ e.preventDefault();
+ if (!todo) return setError("์๋ฌด๊ฒ๋ ์
๋ ฅ๋์ง ์์์ต๋๋ค.");
+ await createTodo(todo);
+ fetch();
+ setTodo("");
+ };
+
+ const onDelete = async (id) => {
+ await deleteTodo(id);
+ fetch();
+ };
+ const onUpdate = async (data, id) => {
+ await updateTodo(data, id);
+ fetch();
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (!token) {
+ return navigate("/signin");
+ }
+ });
+
+ useEffect(() => {
+ fetch();
+ }, []);
+
+ return (
+ <Wrapper>
+ <Header
+ onClick={() => {
+ localStorage.removeItem("token");
+ navigate("/signin");
+ }}
+ >
+ <span>๋ก๊ทธ์์</span>
+ </Header>
+ <Container>
+ <h1>ToDo List</h1>
+ <form onSubmit={onSubmit}>
+ <input
+ data-testid="new-todo-input"
+ type="text"
+ value={todo}
+ onChange={onChange}
+ />
+ <button data-testid="new-todo-add-button">์ถ๊ฐ</button>
+ </form>
+ <span>{error}</span>
+ </Container>
+ <TodoList>
+ {toDoList?.map((data) => {
+ return (
+ <ToDo
+ key={data.id}
+ {...data}
+ onDelete={onDelete}
+ onUpdate={onUpdate}
+ />
+ );
+ })}
+ </TodoList>
+ </Wrapper>
+ );
+}
+
+export default ToDoList;
+
+const Wrapper = styled.div`
+ max-width: 480px;
+ margin: 0 auto;
+`;
+
+const Header = styled.nav`
+ display: flex;
+ justify-content: flex-end;
+ span {
+ cursor: pointer;
+ }
+`;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const TodoList = styled.ul`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 0;
+ margin: 0;
+`; | JavaScript | useEffect๋ฅผ ๋๋ ์ด์ ๊ฐ ์์๊น์? ์ฒซ useEffect๋ deps ๋ฐฐ์ด์ด ์๋๋ฐ ์ด ๊ฒฝ์ฐ๋ []์ ๋์ผํ๊ฒ ๋์ํฉ๋๋ค! |
@@ -0,0 +1,150 @@
+import React, { useEffect, useState } from "react";
+import styled from "styled-components";
+import { createTodo, deleteTodo, getTodos, updateTodo } from "../../api";
+import ToDo from "./ToDo";
+import { useNavigate } from "react-router-dom";
+
+function ToDoList() {
+ const [todo, setTodo] = useState("");
+ const [toDoList, setToDoList] = useState([]);
+
+ const [error, setError] = useState("");
+ const navigate = useNavigate();
+ const onChange = (e) => {
+ setError("");
+ setTodo(e.target.value);
+ };
+
+ const fetch = async () => {
+ try {
+ const todos = await getTodos();
+ setToDoList(todos);
+ } catch (e) {
+ console.log(e);
+ }
+ };
+
+ const onSubmit = async (e) => {
+ e.preventDefault();
+ if (!todo) return setError("์๋ฌด๊ฒ๋ ์
๋ ฅ๋์ง ์์์ต๋๋ค.");
+ await createTodo(todo);
+ fetch();
+ setTodo("");
+ };
+
+ const onDelete = async (id) => {
+ await deleteTodo(id);
+ fetch();
+ };
+ const onUpdate = async (data, id) => {
+ await updateTodo(data, id);
+ fetch();
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (!token) {
+ return navigate("/signin");
+ }
+ });
+
+ useEffect(() => {
+ fetch();
+ }, []);
+
+ return (
+ <Wrapper>
+ <Header
+ onClick={() => {
+ localStorage.removeItem("token");
+ navigate("/signin");
+ }}
+ >
+ <span>๋ก๊ทธ์์</span>
+ </Header>
+ <Container>
+ <h1>ToDo List</h1>
+ <form onSubmit={onSubmit}>
+ <input
+ data-testid="new-todo-input"
+ type="text"
+ value={todo}
+ onChange={onChange}
+ />
+ <button data-testid="new-todo-add-button">์ถ๊ฐ</button>
+ </form>
+ <span>{error}</span>
+ </Container>
+ <TodoList>
+ {toDoList?.map((data) => {
+ return (
+ <ToDo
+ key={data.id}
+ {...data}
+ onDelete={onDelete}
+ onUpdate={onUpdate}
+ />
+ );
+ })}
+ </TodoList>
+ </Wrapper>
+ );
+}
+
+export default ToDoList;
+
+const Wrapper = styled.div`
+ max-width: 480px;
+ margin: 0 auto;
+`;
+
+const Header = styled.nav`
+ display: flex;
+ justify-content: flex-end;
+ span {
+ cursor: pointer;
+ }
+`;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const TodoList = styled.ul`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 0;
+ margin: 0;
+`; | JavaScript | setError๋ฅผ ํ์ฉํ early-return์ด ์์ฃผ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! ์์ ํ๊ฒ apiํธ์ถ๋ ์ํ๊ฒ ๋ค์๐ |
@@ -0,0 +1,66 @@
+import React from 'react';
+import ReactDOM from 'react-dom/client';
+import {
+ RouterProvider,
+ createBrowserRouter,
+ redirect,
+} from 'react-router-dom';
+import Signin from './pages/Signin';
+import Signup from './pages/Signup';
+import { GlobalStyle } from './styles/GlobalStyle';
+import Todo from './pages/Todo';
+
+const redirectToSignIn = () => redirect('/signin');
+
+const privateMiddleware = () => {
+ const jwt = localStorage.getItem('access_token');
+
+ if (jwt) {
+ return true;
+ }
+
+ return redirect('/signin');
+};
+
+const publicMiddleware = () => {
+ const jwt = localStorage.getItem('access_token');
+
+ if (jwt) {
+ return redirect('/todo');
+ }
+
+ return true;
+};
+
+const router = createBrowserRouter([
+ {
+ path: '/todo',
+ element: <Todo />,
+ loader: privateMiddleware,
+ },
+ {
+ path: '/signin',
+ element: <Signin />,
+ loader: publicMiddleware,
+ },
+ {
+ path: '/signup',
+ element: <Signup />,
+ loader: publicMiddleware,
+ },
+ {
+ path: '*',
+ loader: redirectToSignIn,
+ },
+]);
+
+const root = ReactDOM.createRoot(
+ document.getElementById('root') as HTMLElement,
+);
+
+root.render(
+ <React.StrictMode>
+ <GlobalStyle />
+ <RouterProvider router={router} />
+ </React.StrictMode>,
+); | Unknown | useEffect๊ฐ ์๋ router์์ rediret ์ฒ๋ฆฌํ์ ๊ฒ ๋๋ฌด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! ๐ |
@@ -8,14 +8,16 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
+import javax.persistence.Table;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Entity
+@Table(name = "used_restroom")
@Getter
@NoArgsConstructor
-public class UsedRestroom {
+public class UsedRestroom extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -28,9 +30,29 @@ public class UsedRestroom {
@Column(name = "restroom_id")
private Long restroomId;
+ @Column(name = "is_reviewed")
+ private boolean isReviewed;
+
+ @Column(name = "review_id")
+ private Long reviewId;
+
@Builder
public UsedRestroom(User user, long restroomId) {
this.user = user;
this.restroomId = restroomId;
+ this.isReviewed = false;
+ this.reviewId = (long) -1;
+ }
+
+ // ๋ฆฌ๋ทฐ ๋ฑ๋ก ํ isReview true + reviewId ๋ฑ๋ก
+ public void EnrollReview(Long reviewId) {
+ this.reviewId = reviewId;
+ this.isReviewed = true;
+ }
+
+ // ๋ฆฌ๋ทฐ ์ญ์ ํ isReview false + reviewId ์ญ์
+ public void DeleteReview() {
+ this.reviewId = (long) -1;
+ this.isReviewed = false;
}
}
\ No newline at end of file | Java | isReviewed ๋ถ๋ถ ๊ธฐ๋ณธ๊ฐ์ false๋ก ๋ฌ์ผํ๋๊น ๊ทธ๋ฅ ํ๋ผ๋ฏธํฐ๋ก ์๋ฐ๊ณ false๋ก ํ ๋ผํ๋๋ฐ ํน์ ํ ์ฝ๋์์ ์ด Builder ์ฌ์ฉํ๋ ๋ถ๋ถ ์์ด?? |
@@ -8,14 +8,16 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
+import javax.persistence.Table;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Entity
+@Table(name = "used_restroom")
@Getter
@NoArgsConstructor
-public class UsedRestroom {
+public class UsedRestroom extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -28,9 +30,29 @@ public class UsedRestroom {
@Column(name = "restroom_id")
private Long restroomId;
+ @Column(name = "is_reviewed")
+ private boolean isReviewed;
+
+ @Column(name = "review_id")
+ private Long reviewId;
+
@Builder
public UsedRestroom(User user, long restroomId) {
this.user = user;
this.restroomId = restroomId;
+ this.isReviewed = false;
+ this.reviewId = (long) -1;
+ }
+
+ // ๋ฆฌ๋ทฐ ๋ฑ๋ก ํ isReview true + reviewId ๋ฑ๋ก
+ public void EnrollReview(Long reviewId) {
+ this.reviewId = reviewId;
+ this.isReviewed = true;
+ }
+
+ // ๋ฆฌ๋ทฐ ์ญ์ ํ isReview false + reviewId ์ญ์
+ public void DeleteReview() {
+ this.reviewId = (long) -1;
+ this.isReviewed = false;
}
}
\ No newline at end of file | Java | ์ฌ์ฉํ๋ ๋ถ๋ถ ์์ด์ false๋ก ๋ฐ๋๋ก ์์ ํ์ด |
@@ -0,0 +1,29 @@
+# This file configures the analyzer, which statically analyzes Dart code to
+# check for errors, warnings, and lints.
+#
+# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
+# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
+# invoked from the command line by running `flutter analyze`.
+
+# The following line activates a set of recommended lints for Flutter apps,
+# packages, and plugins designed to encourage good coding practices.
+include: package:flutter_lints/flutter.yaml
+
+linter:
+ # The lint rules applied to this project can be customized in the
+ # section below to disable rules from the `package:flutter_lints/flutter.yaml`
+ # included above or to enable additional rules. A list of all available lints
+ # and their documentation is published at
+ # https://dart-lang.github.io/linter/lints/index.html.
+ #
+ # Instead of disabling a lint rule for the entire project in the
+ # section below, it can also be suppressed for a single line of code
+ # or a specific dart file by using the `// ignore: name_of_lint` and
+ # `// ignore_for_file: name_of_lint` syntax on the line or in the file
+ # producing the lint.
+ rules:
+ require_trailing_commas: true
+ # avoid_print: false # Uncomment to disable the `avoid_print` rule
+ # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
+# Additional information about this file can be found at
+# https://dart.dev/guides/language/analysis-options | Unknown | ์๋ ๋ด์ฉ์ ์ถ๊ฐ ํ์ ๋ค project root ์์ `dart fix --apply` ๋ฅผ ์ํํ์๋ฉด ๋๋ถ๋ถ์
๊ฒฝ์ฐ์ `,` ๋ฅผ ๋ถ์ฌ์ ์ข ๋ ๊น๋ํ formatting ์ ํ์ค ์ ์์ต๋๋ค.
ํ์ผ ์ ์ฅํ ๋๋ง๋ค ์๋์ผ๋ก ์ ์ฉ๋๋๊ฑฐ๋ผ ํ๋ฒ ํด๋๋ฉด ๊ท์ฐฎ๊ฒ `,` ๋ฅผ ์๋์ผ๋ก ์๋ถ์ฌ๋ ํธํ๊ฒ ์ฌ์ฉํ์ค ์ ์์ด์. ๋ฆฌ๋ทฐ๋ฅผ ํ ๋๋ ์์ ฏ์ ๊ตฌ๋ถ์ด ๋ช
ํํด์ ํจ์ฌ ์์ํด์ง๊ฒ ๋ฉ๋๋ค.
```dart
// analysis_options.yaml
linter:
rules:
require_trailing_commas: true
``` |
@@ -13,7 +13,7 @@ private LottoTicket(final List<LottoNumber> numbers) {
validateCountOfNumbers(numbers);
validateDuplicateNumbers(numbers);
- this.numbers = numbers;
+ this.numbers = numbers.stream().sorted().collect(Collectors.toList());
}
public static LottoTicket create() {
@@ -32,9 +32,7 @@ private static List<LottoNumber> generate() {
List<LottoNumber> shuffledList = LottoNumber.all();
Collections.shuffle(shuffledList);
- return shuffledList.subList(0, 6).stream()
- .sorted()
- .collect(Collectors.toList());
+ return shuffledList.subList(0, 6).stream().collect(Collectors.toList());
}
private void validateCountOfNumbers(final List<LottoNumber> numbers) {
@@ -56,7 +54,7 @@ public int getTheNumberOfCommonNumbers(final LottoTicket winningTicket) {
}
public boolean hasNumber(final LottoNumber bonus) {
- return numbers.stream().anyMatch(n -> n.equals(bonus));
+ return numbers.contains(bonus);
}
public List<LottoNumber> getNumbers() { | Java | ์ด๋ฒ ์์ ๋ฒ์๊ฐ ์๋์ด์ ์ฝ๋ฉํธ๋ฅผ ๋จ๊ธธ ์ ์์ด ์ฌ๊ธฐ์ ๋์ ๋จ๊น๋๋ค.
`LottoTicket`์ 23๋ผ์ธ์ ์๋ ์ ์ ํฉํฐ๋ฆฌ ๋ฉ์๋๋ ํ์ฌ ์์ฑ์๋ก ์์ ํ ๋์ฒด ๊ฐ๋ฅํด ๋ณด์ด๋๋ฐ ๋ฐ๋ก ์กด์ฌํ๋ ์ด์ ๊ฐ ์์๊น์?
๋ํ 31๋ผ์ธ `generate()` ๋ฉ์๋๋ `LottoTicket`์ด ๋ด๋นํด์ผ ํ๋ ์ฑ
์์ผ๋ก ์ ์ ํ์ง๋ ๊ณ ๋ฏผํด ๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์! |
@@ -1,29 +1,40 @@
package lotto;
-import lotto.domain.*;
+import lotto.domain.LottoGame;
+import lotto.domain.LottoPrize;
+import lotto.domain.LottoTicket;
+import lotto.domain.WinningLotto;
import lotto.view.LottoInputView;
import lotto.view.LottoResultView;
+import java.util.ArrayList;
import java.util.List;
public class LottoGameApplication {
public static void main(String[] args) {
- int moneyForTicket = LottoInputView.getMoneyForTicket();
- List<LottoTicket> tickets = LottoGame.buy(moneyForTicket);
-
- LottoResultView.printTickets(tickets);
-
- if (tickets.isEmpty()) {
- return;
+ try {
+ List<List<Integer>> numbersForManualTicket = new ArrayList<>();
+ int moneyForTicket = LottoInputView.getMoneyForTicket();
+ int numberOfManualTickets = LottoInputView.getNumberOfManualTicket();
+ if (numberOfManualTickets > 0) {
+ numbersForManualTicket = LottoInputView.getLottoTicketNumbers(numberOfManualTickets);
+ }
+ List<LottoTicket> tickets = LottoGame.buy(moneyForTicket, numbersForManualTicket);
+
+ LottoResultView.printTickets(tickets, numberOfManualTickets);
+
+ if (tickets.isEmpty()) {
+ return;
+ }
+
+ WinningLotto lastWeekWinningLotto = new WinningLotto(LottoInputView.getLastWeekWinnerNumber(), LottoInputView.getLastWeekBonusNumber());
+ List<LottoPrize> prizes = lastWeekWinningLotto.prizes(tickets);
+
+ LottoResultView.printResult(prizes, tickets.size());
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
}
- LottoTicket lastWeekWinnerTicket = LottoTicket.createFromIntegerList(LottoInputView.getLastWeekWinnerNumber());
- LottoNumber lastWeekBonusNumber = new LottoNumber(LottoInputView.getLastWeekBonusNumber());
- WinningLotto lastWeekWinningLotto = new WinningLotto(lastWeekWinnerTicket, lastWeekBonusNumber);
-
- List<LottoPrize> prizes = lastWeekWinningLotto.prizes(tickets);
-
- LottoResultView.printResult(prizes, tickets.size());
}
} | Java | `numbersForManualTicket`์ด ์ด๋ ๊ฒ ๋งจ ์์ ๋ฏธ๋ฆฌ ์ ์ธ๋์ด์ผ ํ ํ์๊ฐ ์์๊น์? |
@@ -1,29 +1,40 @@
package lotto;
-import lotto.domain.*;
+import lotto.domain.LottoGame;
+import lotto.domain.LottoPrize;
+import lotto.domain.LottoTicket;
+import lotto.domain.WinningLotto;
import lotto.view.LottoInputView;
import lotto.view.LottoResultView;
+import java.util.ArrayList;
import java.util.List;
public class LottoGameApplication {
public static void main(String[] args) {
- int moneyForTicket = LottoInputView.getMoneyForTicket();
- List<LottoTicket> tickets = LottoGame.buy(moneyForTicket);
-
- LottoResultView.printTickets(tickets);
-
- if (tickets.isEmpty()) {
- return;
+ try {
+ List<List<Integer>> numbersForManualTicket = new ArrayList<>();
+ int moneyForTicket = LottoInputView.getMoneyForTicket();
+ int numberOfManualTickets = LottoInputView.getNumberOfManualTicket();
+ if (numberOfManualTickets > 0) {
+ numbersForManualTicket = LottoInputView.getLottoTicketNumbers(numberOfManualTickets);
+ }
+ List<LottoTicket> tickets = LottoGame.buy(moneyForTicket, numbersForManualTicket);
+
+ LottoResultView.printTickets(tickets, numberOfManualTickets);
+
+ if (tickets.isEmpty()) {
+ return;
+ }
+
+ WinningLotto lastWeekWinningLotto = new WinningLotto(LottoInputView.getLastWeekWinnerNumber(), LottoInputView.getLastWeekBonusNumber());
+ List<LottoPrize> prizes = lastWeekWinningLotto.prizes(tickets);
+
+ LottoResultView.printResult(prizes, tickets.size());
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
}
- LottoTicket lastWeekWinnerTicket = LottoTicket.createFromIntegerList(LottoInputView.getLastWeekWinnerNumber());
- LottoNumber lastWeekBonusNumber = new LottoNumber(LottoInputView.getLastWeekBonusNumber());
- WinningLotto lastWeekWinningLotto = new WinningLotto(lastWeekWinnerTicket, lastWeekBonusNumber);
-
- List<LottoPrize> prizes = lastWeekWinningLotto.prizes(tickets);
-
- LottoResultView.printResult(prizes, tickets.size());
}
} | Java | <img width="648" alt="แแ
ณแแ
ณแ
แ
ตแซแแ
ฃแบ 2022-11-16 แแ
ฉแแ
ฅแซ 1 49 53" src="https://user-images.githubusercontent.com/18049492/201978579-7de023e7-aadc-418e-8102-b5c6e23888ae.png">
ํ์ฌ ๋ฉ์ธ ๋ฉ์๋์ ๊ธธ์ด๊ฐ ๋๋ฌด ๊ธธ์ด์ง ์ํฉ์ด๋ค์. ์ฝ์ง ์์ ์ผ์ด์ง๋ง, ์ ์ฒด์ ์ธ ํ๋ฆ์ ํ์
ํ๊ธฐ ์ฝ๋๋ก ๊ฐ์ ํ ๋ฐฉ๋ฒ์ ์์์ง ๊ณ ๋ฏผํด ๋ณด์
๋ ์ข์ ๊ฒ ๊ฐ์์. |
@@ -1,29 +1,40 @@
package lotto;
-import lotto.domain.*;
+import lotto.domain.LottoGame;
+import lotto.domain.LottoPrize;
+import lotto.domain.LottoTicket;
+import lotto.domain.WinningLotto;
import lotto.view.LottoInputView;
import lotto.view.LottoResultView;
+import java.util.ArrayList;
import java.util.List;
public class LottoGameApplication {
public static void main(String[] args) {
- int moneyForTicket = LottoInputView.getMoneyForTicket();
- List<LottoTicket> tickets = LottoGame.buy(moneyForTicket);
-
- LottoResultView.printTickets(tickets);
-
- if (tickets.isEmpty()) {
- return;
+ try {
+ List<List<Integer>> numbersForManualTicket = new ArrayList<>();
+ int moneyForTicket = LottoInputView.getMoneyForTicket();
+ int numberOfManualTickets = LottoInputView.getNumberOfManualTicket();
+ if (numberOfManualTickets > 0) {
+ numbersForManualTicket = LottoInputView.getLottoTicketNumbers(numberOfManualTickets);
+ }
+ List<LottoTicket> tickets = LottoGame.buy(moneyForTicket, numbersForManualTicket);
+
+ LottoResultView.printTickets(tickets, numberOfManualTickets);
+
+ if (tickets.isEmpty()) {
+ return;
+ }
+
+ WinningLotto lastWeekWinningLotto = new WinningLotto(LottoInputView.getLastWeekWinnerNumber(), LottoInputView.getLastWeekBonusNumber());
+ List<LottoPrize> prizes = lastWeekWinningLotto.prizes(tickets);
+
+ LottoResultView.printResult(prizes, tickets.size());
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
}
- LottoTicket lastWeekWinnerTicket = LottoTicket.createFromIntegerList(LottoInputView.getLastWeekWinnerNumber());
- LottoNumber lastWeekBonusNumber = new LottoNumber(LottoInputView.getLastWeekBonusNumber());
- WinningLotto lastWeekWinningLotto = new WinningLotto(lastWeekWinnerTicket, lastWeekBonusNumber);
-
- List<LottoPrize> prizes = lastWeekWinningLotto.prizes(tickets);
-
- LottoResultView.printResult(prizes, tickets.size());
}
} | Java | <img width="295" alt="แแ
ณแแ
ณแ
แ
ตแซแแ
ฃแบ 2022-11-16 แแ
ฉแแ
ฅแซ 1 54 53" src="https://user-images.githubusercontent.com/18049492/201979676-12c7da76-8473-4db8-a2c6-5050921f04f1.png">
์์ต๋ฅ ๊ณ์ฐ ๋ก์ง๋ ์ ๊ฒํด ๋ณผ๊น์? |
@@ -1,29 +1,40 @@
package lotto;
-import lotto.domain.*;
+import lotto.domain.LottoGame;
+import lotto.domain.LottoPrize;
+import lotto.domain.LottoTicket;
+import lotto.domain.WinningLotto;
import lotto.view.LottoInputView;
import lotto.view.LottoResultView;
+import java.util.ArrayList;
import java.util.List;
public class LottoGameApplication {
public static void main(String[] args) {
- int moneyForTicket = LottoInputView.getMoneyForTicket();
- List<LottoTicket> tickets = LottoGame.buy(moneyForTicket);
-
- LottoResultView.printTickets(tickets);
-
- if (tickets.isEmpty()) {
- return;
+ try {
+ List<List<Integer>> numbersForManualTicket = new ArrayList<>();
+ int moneyForTicket = LottoInputView.getMoneyForTicket();
+ int numberOfManualTickets = LottoInputView.getNumberOfManualTicket();
+ if (numberOfManualTickets > 0) {
+ numbersForManualTicket = LottoInputView.getLottoTicketNumbers(numberOfManualTickets);
+ }
+ List<LottoTicket> tickets = LottoGame.buy(moneyForTicket, numbersForManualTicket);
+
+ LottoResultView.printTickets(tickets, numberOfManualTickets);
+
+ if (tickets.isEmpty()) {
+ return;
+ }
+
+ WinningLotto lastWeekWinningLotto = new WinningLotto(LottoInputView.getLastWeekWinnerNumber(), LottoInputView.getLastWeekBonusNumber());
+ List<LottoPrize> prizes = lastWeekWinningLotto.prizes(tickets);
+
+ LottoResultView.printResult(prizes, tickets.size());
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
}
- LottoTicket lastWeekWinnerTicket = LottoTicket.createFromIntegerList(LottoInputView.getLastWeekWinnerNumber());
- LottoNumber lastWeekBonusNumber = new LottoNumber(LottoInputView.getLastWeekBonusNumber());
- WinningLotto lastWeekWinningLotto = new WinningLotto(lastWeekWinnerTicket, lastWeekBonusNumber);
-
- List<LottoPrize> prizes = lastWeekWinningLotto.prizes(tickets);
-
- LottoResultView.printResult(prizes, tickets.size());
}
} | Java | ๊ทธ๋ฌ๊ณ ๋ณด๋ 2๋ฑ ์ถ๋ ฅ ์ ๊ธ์ก์ด "๋ณด๋์ค ๋ณผ ์ผ์น" ํ
์คํธ ๋ค๋ก ์์ผ ํ ๊ฒ ๊ฐ์์~ |
@@ -15,8 +15,9 @@ public class LottoResultView {
public static final String RESULT_OUTPUT_COMMENT = "๋น์ฒจ ํต๊ณ\n---------";
public static final String BONUS_MATCH_COMMENT = ", ๋ณด๋์ค ๋ณผ ์ผ์น";
- public static void printTickets(List<LottoTicket> ticketList) {
- System.out.println(ticketList.size() + "๊ฐ๋ฅผ ๊ตฌ๋งคํ์ต๋๋ค.");
+ public static void printTickets(List<LottoTicket> ticketList, int numberOfManualTickets) {
+ int numberOfAutoTickets = ticketList.size() - numberOfManualTickets;
+ System.out.println(String.format("์๋์ผ๋ก %d์ฅ, ์๋์ผ๋ก %d๊ฐ๋ฅผ ๊ตฌ๋งคํ์ต๋๋ค.", numberOfManualTickets, numberOfAutoTickets));
ticketList.stream()
.map(LottoTicket::getNumbers)
.map(numbers -> numbers.stream().map(Object::toString).collect(Collectors.joining(", ", "[", "]"))) | Java | `\n`์ ํญ์ ๊ฐํ์ ๋ณด์ฅํ์ง ์์์. ๊ด๋ จํ์ฌ ํ์ตํด ๋ณด๊ณ ์์ ํด ์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์~ |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | try ~ catch ๋ฌธ์ด ๊ณ์ ๋ฐ๋ณต๋๊ณ ์๊ณ ๋น์ฆ๋์ค ๋ก์ง๊ณผ ์์ฌ ์์ด ๋น์ฆ๋์ค ๋ก์ง๊ณผ ๋ถ๋ฆฌ๋ฅผ ํ๋ฉด ์ข์ ๋ฏ ํฉ๋๋ค. ์๊ณ ๊ณ์ค์ง๋ ๋ชจ๋ฅด๊ฒ ์ผ๋ AOP์ ๋ํด ํ๋ฒ ์ฐพ์ ๋ณด์๋ ๊ฒ์ ์ถ์ฒ ๋๋ฆฝ๋๋ค.
์ถ๊ฐ์ ์ผ๋ก try ~ catch ๋ฌธ์ ๋ถ๋ฆฌํ๋ ๋ฐฉ๋ฒ์๋ ํ๋ก์ ํจํด, ํ์
๋ ์ธํฐํ์ด์ค ํ์ฉ ๋ฑ ์ฌ๋ฌ ๋ฐฉ๋ฒ์ด ์์ผ๋ ํ๋ฒ ์ฐพ์๋ณด์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,47 @@
+package christmas.domain;
+
+import static christmas.domain.MenuDiscountType.WEEKDAYS;
+import static christmas.domain.MenuDiscountType.WEEKENDS;
+
+import java.time.LocalDate;
+
+public class MenuDiscount {
+
+ private static final int WEEKDAYS_DISCOUNT = 2023;
+ private static final int WEEKENDS_DISCOUNT = 2023;
+ private static final MenuDiscount NONE = new MenuDiscount(Money.ZERO, MenuDiscountType.NONE);
+ private Money money;
+ private MenuDiscountType type;
+
+ private MenuDiscount(Money money, MenuDiscountType type) {
+ this.money = money;
+ this.type = type;
+ }
+
+
+ public static MenuDiscount of(OrderLine orderLine, LocalDate localDate) {
+ MenuDiscountType type = MenuDiscountType.findByLocalDate(localDate);
+
+ if (type == WEEKDAYS && orderLine.isDessert()) {
+ return new MenuDiscount(
+ new Money(WEEKDAYS_DISCOUNT).multiply(orderLine.getQuantity()), WEEKDAYS);
+ }
+ if (type == WEEKENDS && orderLine.isMain()) {
+ return new MenuDiscount(
+ new Money(WEEKENDS_DISCOUNT).multiply(orderLine.getQuantity()), WEEKENDS);
+ }
+ return NONE;
+ }
+
+ public boolean isWeekdays() {
+ return type == WEEKDAYS;
+ }
+
+ public boolean isWeekends() {
+ return type == WEEKENDS;
+ }
+
+ public Money getMoney() {
+ return money;
+ }
+} | Java | ๊ฐ์ ๊ฐ์ธ๋ฐ ๋๊ฐ์ ๋ณ์๋ก ๋๋ ์ด์ ๊ฐ ์์ผ์ค๊น์? |
@@ -0,0 +1,26 @@
+package christmas.dtos;
+
+import christmas.domain.BenefitType;
+
+public class BenefitDto {
+
+ private BenefitType benefitType;
+ private int discountAmount;
+
+ BenefitDto(BenefitType benefitType, int discountAmount) {
+ this.benefitType = benefitType;
+ this.discountAmount = discountAmount;
+ }
+
+ public static BenefitDto toDto(BenefitType benefitType, int discountAmount) {
+ return new BenefitDto(benefitType, discountAmount);
+ }
+
+ public BenefitType getBenefitType() {
+ return benefitType;
+ }
+
+ public int getDiscountAmount() {
+ return discountAmount;
+ }
+} | Java | ์ฌ์ค dto๊ฐ ๋ง์ง๋ ์์์ dto ๋ด๋ถ์์ ๋ฐ๋ก ๋๋ฉ์ธ์ผ๋ก ๋ณ๊ฒฝํด๋ ์๊ด์ ์๊ฒ ์ผ๋ ๋์ค์๋ dto <-> domain์ ๋ณํํด์ฃผ๋ mapper ๋ฅผ ๋ง๋๋ ๊ฒ๋ ์ข์ ๋ฏ ํฉ๋๋ค. |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ๊ฐ์ฌํฉ๋๋ค. ์ ๋ ์์ฑํ๋ฉด์ ์๋ชป ๋์๋ค๋ ๊ฒ์ ๋๊ผ๋๋ฐ, ํจ์จ์ ์ธ ๋ฐฉ๋ฒ์ ๋ํด ์์ง ๋ชปํ์ต๋๋ค. ๋ง์ํ์ ๋ฐฉ๋ฒ๋ค์ ์ ์ฉํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค !! |
@@ -0,0 +1,47 @@
+package christmas.domain;
+
+import static christmas.domain.MenuDiscountType.WEEKDAYS;
+import static christmas.domain.MenuDiscountType.WEEKENDS;
+
+import java.time.LocalDate;
+
+public class MenuDiscount {
+
+ private static final int WEEKDAYS_DISCOUNT = 2023;
+ private static final int WEEKENDS_DISCOUNT = 2023;
+ private static final MenuDiscount NONE = new MenuDiscount(Money.ZERO, MenuDiscountType.NONE);
+ private Money money;
+ private MenuDiscountType type;
+
+ private MenuDiscount(Money money, MenuDiscountType type) {
+ this.money = money;
+ this.type = type;
+ }
+
+
+ public static MenuDiscount of(OrderLine orderLine, LocalDate localDate) {
+ MenuDiscountType type = MenuDiscountType.findByLocalDate(localDate);
+
+ if (type == WEEKDAYS && orderLine.isDessert()) {
+ return new MenuDiscount(
+ new Money(WEEKDAYS_DISCOUNT).multiply(orderLine.getQuantity()), WEEKDAYS);
+ }
+ if (type == WEEKENDS && orderLine.isMain()) {
+ return new MenuDiscount(
+ new Money(WEEKENDS_DISCOUNT).multiply(orderLine.getQuantity()), WEEKENDS);
+ }
+ return NONE;
+ }
+
+ public boolean isWeekdays() {
+ return type == WEEKDAYS;
+ }
+
+ public boolean isWeekends() {
+ return type == WEEKENDS;
+ }
+
+ public Money getMoney() {
+ return money;
+ }
+} | Java | ํ์ฌ ์๊ตฌ์ฌํญ์์๋ ๊ฐ์ด ๋์ผํ์ง๋ง ๊ทธ ์๋ฏธ๋ ๋ค๋ฅด๋ฏ๋ก ๋ถ๋ฆฌํ๋ ๊ฒ์ด ์ณ๋ค๊ณ ์๊ฐํ์ต๋๋ค. ์ถํ ์ฃผ๋ง ํ ์ธ๊ณผ ํ์ผ ํ ์ธ์ ์ฐจ์ด๊ฐ ์๊ธฐ๋๋ก ๋ณ๊ฒฝ์ฌํญ์ด ์๊ธด๋ค๋ฉด ๋ ํธํ๊ฒ ๋ณ๊ฒฝํ ์ ์์ ๊ฒ์ด๋ผ ๊ธฐ๋ํ๊ณ ๋ถ๋ฆฌํ์ต๋๋ค. |
@@ -0,0 +1,26 @@
+package christmas.dtos;
+
+import christmas.domain.BenefitType;
+
+public class BenefitDto {
+
+ private BenefitType benefitType;
+ private int discountAmount;
+
+ BenefitDto(BenefitType benefitType, int discountAmount) {
+ this.benefitType = benefitType;
+ this.discountAmount = discountAmount;
+ }
+
+ public static BenefitDto toDto(BenefitType benefitType, int discountAmount) {
+ return new BenefitDto(benefitType, discountAmount);
+ }
+
+ public BenefitType getBenefitType() {
+ return benefitType;
+ }
+
+ public int getDiscountAmount() {
+ return discountAmount;
+ }
+} | Java | ๊ฐ์ฌํฉ๋๋ค! ๊ผญ ์ ์ฉํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | 2023, 12์ ์์๋ก ํ๋๊ฑด ์ด๋จ๊น์?
๋ค๋ฅธ ๋ถ๋ถ์์๋ ๋๊ฐ์ด ์ฌ์ฉํ๊ณ ์๊ณ , ๋ง์ฝ ๋ค๋ฅธ ์ด๋ฒคํธ๋ก ์ถ๊ฐ๋๋ฉด ์์ ํ ๋ถ๋ถ์ ๋ค ์ฐพ์์ผ ํ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,58 @@
+package christmas.domain;
+
+import java.util.Collections;
+import java.util.List;
+
+public class Order {
+
+ private static final int MAX_QUANTITY = 20;
+ private static final String INSUFFICIENT_ORDERLINE_ERROR_MESSAGE = "[ERROR] ์ฃผ๋ฌธ ํญ๋ชฉ์ด ๋น์ด ์์ต๋๋ค.";
+ private static final String TOO_MANY_ORDERLINE_QUANTITY_ERROR_MESSAGE = "[ERROR] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String ONLY_DRINKS_ERROR_MESSAGE = "[ERROR] ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+
+ private List<OrderLine> orderLines;
+
+ public Order(List<OrderLine> orderLines) {
+ validateAtLeastOneOrderLine(orderLines);
+ validateTotalQuantity(orderLines);
+ validateOnlyDrinks(orderLines);
+ this.orderLines = orderLines;
+ }
+
+ public Money getTotalAmounts() {
+ return orderLines.stream()
+ .map(OrderLine::getAmounts)
+ .reduce(Money::plus)
+ .get();
+ }
+
+ private void validateAtLeastOneOrderLine(List<OrderLine> orderLines) {
+ if (orderLines == null || orderLines.isEmpty()) {
+ throw new IllegalArgumentException(INSUFFICIENT_ORDERLINE_ERROR_MESSAGE);
+ }
+ }
+
+ private void validateTotalQuantity(List<OrderLine> orderLines) {
+ int totalQuantity = orderLines.stream()
+ .mapToInt(OrderLine::getQuantity)
+ .sum();
+
+ if (totalQuantity > MAX_QUANTITY) {
+ throw new IllegalArgumentException(TOO_MANY_ORDERLINE_QUANTITY_ERROR_MESSAGE);
+ }
+ }
+
+ private void validateOnlyDrinks(List<OrderLine> orderLines) {
+ if (orderLines.stream().allMatch(OrderLine::isDrink)) {
+ throw new IllegalArgumentException(ONLY_DRINKS_ERROR_MESSAGE);
+ }
+ }
+
+ public List<OrderLine> getOrderLines() {
+ return Collections.unmodifiableList(orderLines);
+ }
+
+ public Money getAmountToPay(Money discountAmounts) {
+ return getTotalAmounts().minus(discountAmounts);
+ }
+} | Java | ```suggestion
if (isOnlyDrink())
```
๋ฉ์๋๋ก ๋ถ๋ฆฌํด์ ๊ฐ๋
์ฑ์ ๋์ด๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ํด๋์ค๋ก ๋ถ๋ฆฌ๋ฅผ ๋๋ฌด ์ํ์ ๊ฒ ๊ฐ์๋ฐ domain์ ๋๋ฌด ๋ง์ ํด๋์ค๋ค์ด ๋ญ์ณ ์๋๊ฒ ์๋๊ฐ ์ถ์ต๋๋ค.
- domain.benefit
- domain.menu
๋ฑ์ผ๋ก ๋ถ๋ฅ๋ฅผ ํด๋ณด๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | OutputView.printPreview๋ก ์ถ๋ ฅ์ ์ํ๊ณ
EventPlanner์์ ๋ค์ OutputView๋ฅผ ์ ๊ทผํ์๋ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ๋ง์ต๋๋ค ใ
. ํ๋์ ํด๋์ค ๋ด์์ ์์ ์ ์ธ์ ํ๋ฉด ๋ ๊น๋ํ๋๋ผ๊ตฌ์. ์กฐ์ธ ๊ฐ์ฌ๋๋ฆฝ๋๋ค !! |
@@ -0,0 +1,58 @@
+package christmas.domain;
+
+import java.util.Collections;
+import java.util.List;
+
+public class Order {
+
+ private static final int MAX_QUANTITY = 20;
+ private static final String INSUFFICIENT_ORDERLINE_ERROR_MESSAGE = "[ERROR] ์ฃผ๋ฌธ ํญ๋ชฉ์ด ๋น์ด ์์ต๋๋ค.";
+ private static final String TOO_MANY_ORDERLINE_QUANTITY_ERROR_MESSAGE = "[ERROR] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+ private static final String ONLY_DRINKS_ERROR_MESSAGE = "[ERROR] ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.";
+
+ private List<OrderLine> orderLines;
+
+ public Order(List<OrderLine> orderLines) {
+ validateAtLeastOneOrderLine(orderLines);
+ validateTotalQuantity(orderLines);
+ validateOnlyDrinks(orderLines);
+ this.orderLines = orderLines;
+ }
+
+ public Money getTotalAmounts() {
+ return orderLines.stream()
+ .map(OrderLine::getAmounts)
+ .reduce(Money::plus)
+ .get();
+ }
+
+ private void validateAtLeastOneOrderLine(List<OrderLine> orderLines) {
+ if (orderLines == null || orderLines.isEmpty()) {
+ throw new IllegalArgumentException(INSUFFICIENT_ORDERLINE_ERROR_MESSAGE);
+ }
+ }
+
+ private void validateTotalQuantity(List<OrderLine> orderLines) {
+ int totalQuantity = orderLines.stream()
+ .mapToInt(OrderLine::getQuantity)
+ .sum();
+
+ if (totalQuantity > MAX_QUANTITY) {
+ throw new IllegalArgumentException(TOO_MANY_ORDERLINE_QUANTITY_ERROR_MESSAGE);
+ }
+ }
+
+ private void validateOnlyDrinks(List<OrderLine> orderLines) {
+ if (orderLines.stream().allMatch(OrderLine::isDrink)) {
+ throw new IllegalArgumentException(ONLY_DRINKS_ERROR_MESSAGE);
+ }
+ }
+
+ public List<OrderLine> getOrderLines() {
+ return Collections.unmodifiableList(orderLines);
+ }
+
+ public Money getAmountToPay(Money discountAmounts) {
+ return getTotalAmounts().minus(discountAmounts);
+ }
+} | Java | ์ด๋ฏธ validateOnlyDrinks ๋ผ๋ ๋ฉ์๋ ๋ด์์ ๋ ๋ค๋ฅธ private ๋ฉ์๋๋ก ๋ ๋นผ๊ฒ ๋๋ฉด ์๋ฏธ์ ์ค๋ณต์ด ์๊ธธ ๊ฒ ๊ฐ์ ๊ตณ์ด ๋นผ์ง๋ ์์์ต๋๋ค. ๋ง์ํด์ฃผ์ ๋ถ๋ถ๋ ๋ค์ ๊ณ ๋ คํด๋ณด๊ฒ ์ต๋๋ค :> |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ๋ค๋ฅธ ๋ถ๋ค ์ฝ๋๋ฅผ ๋ณด๋ ํ์คํ ๋๋ฉ์ธ ํจํค์ง๊ฐ ๋ง์ด ๋ฑ๋ฑํ ๊ฒ ๊ฐ๋๋ผ๊ตฌ์...์ ๋ ๋ถ๋ฅํ๋ ๊ฒ์ด ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค!! |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ํ์ฌ EventPlanner๋ฅผ ์ฌ์ฉํ์ง ์์ผ๋ฉด ์ปจํธ๋กค๋ฌ์์ `.run()` ๋ฉ์๋์ ๋ผ์ธ ์๊ฐ ๋๋ฌด ๊ธธ์ด์ง๋๋ผ๊ตฌ์...
ํด์ OutputView๋ก ์ฌ๋ฌ์ค ๋๋ ๊ฒ ๋ณด๋จ ์ด ์ถ๋ ฅ์ด ์ด๋ค ์ถ๋ ฅ์ธ์ง ํ์
ํ๊ธฐ ์ฝ๋๋ก EventPlanner๋ฅผ ์ฌ์ฉํด์ ๋ค์ OutputView๋ฅผ ์ ๊ทผํ๋ ํํ๋ฅผ ์ฌ์ฉํ์ต๋๋ค.
๋ผ์ธ ์๋ฅผ ์ค์ด๊ธฐ ์ํด ์์๋ฐฉํธ์ผ๋ก ์ ๋ ๊ฒ ๋์๋๋ฐ ๋ ์ข์ ๋ฐฉ๋ฒ์ด ๋ฌด์์ธ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค ๐ฅน |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ๊ฒ์ฆ๊ณผ ๋์์ ์์ธ๊ฐ ๋ฐ์ํ๋ฉด ์ฌ๊ทํธ์ถํ๋ ๋ฐฉ์์ผ๋ก ๋์ด์๋ค์! ์ด๊ฒ๋ ํ๋์ ํธ๋ ์ด๋ ์คํ์ธ๊ฒ ๊ฐ์๋ฐ stackOverflow๊ฐ ๋ฐ์ํ ๊ฐ๋ฅ์ฑ์ ์ด๋ํ๋ ๋ฐฉ๋ฒ์
๋๋ค.!! while์ ์ฌ์ฉํ๋๊ฒ ์ ๋ต์ ์๋์ง๋ง ๋์ stackOverflow๋ ๋ฐฉ์งํ ์๋ ์์ฃ ์ด๋ป๊ฒ ์๊ฐํ์
์ ์ด๋ ๊ฒ ๊ตฌํํ์
จ๋์ง ์ฌ์ญค๋ด๋ ๋ ๊น์? |
@@ -0,0 +1,28 @@
+package christmas.domain;
+
+import static java.util.Comparator.comparingInt;
+
+import java.util.Arrays;
+
+public enum EventBadge {
+ NONE(0, "์์"), STAR(5000, "๋ณ"), TREE(10000, "ํธ๋ฆฌ"), SANTA(20000, "์ฐํ");
+
+ private final int money;
+ private String title;
+
+ EventBadge(int money, String title) {
+ this.money = money;
+ this.title = title;
+ }
+
+ public static EventBadge findByMoney(int input) {
+ return Arrays.stream(EventBadge.values())
+ .filter(eventBadge -> eventBadge.money <= input)
+ .max(comparingInt(o -> o.money))
+ .orElse(NONE);
+ }
+
+ public String getTitle() {
+ return title;
+ }
+} | Java | ์ฌ์ค "์์" ์ด๋ผ๋ ๋ฑ์ง๋ ์๋ ๊ฐ์ด๋ผ ์์ ์์ฒด๋ View์ ๋ด๋น์ธ ์ญํ ์ธ๊ฒ ๊ฐ์์! none์ด๋ ""๋ก ๊ด๋ฆฌํ์ผ๋ฉด ์ด๋์๊น์? |
@@ -0,0 +1,32 @@
+package christmas.domain;
+
+import java.time.LocalDate;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public enum TotalDiscountType {
+ CHRISTMAS_D_DAY(IntStream.range(1, 26).boxed().toList()),
+ SPECIAL(List.of(3, 10, 17, 24, 25, 31)),
+ NONE(List.of());
+
+ private List<Integer> days;
+
+ TotalDiscountType(List<Integer> days) {
+ this.days = days;
+ }
+
+ public List<Integer> getDays() {
+ return Collections.unmodifiableList(days);
+ }
+
+ public static TotalDiscountType findSpecialTypeByLocalDate(LocalDate localDate) {
+ int day = localDate.getDayOfMonth();
+
+ return Stream.of(TotalDiscountType.SPECIAL)
+ .filter(specialType -> specialType.days.contains(day))
+ .findAny()
+ .orElse(TotalDiscountType.NONE);
+ }
+} | Java | ์ด๋ถ๋ถ์ ๊ฐ์ธ์ ์ผ๋ก ์ ๋ 2023๋
์ 12์์ด๋ผ๋ ์๊ตฌ์ฌํญ์ด ์์๊ธฐ๋๋ฌธ์ ์ ๋ Date๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์ต๋๋ค! ๋ฌผ๋ก ์ ๋ ์ด ๋ฐฉ๋ฒ์ ๊ณ ๋ คํ์๋๋ฐ ์ด๋ ๊ฒ ๋ ์ง๋ฅผ ๊ตณ์ด ๋ฃ์ ์ด์ ๋ฅผ ์ฌ์ญค๋ด๋ ๋ ๊น์? |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ์ข์ ์ฒ๋ฆฌ ๋ฐฉ๋ฒ์ ๋ํด ๊น๊ฒ ๊ณ ๋ฏผํ์ง ๋ชปํ์ต๋๋ค ใ
... ๋ค๋ฅธ ๋ถ๊ป์ ์ธ๊ธํ์ ํ๋ก์ ํจํด, ํ์
๋ ์ธํฐํ์ด์ค๋ฅผ ํ์ฉํด ๋ฆฌํฉํ ๋ง ํด๋ณด๋ ค ํฉ๋๋ค !! |
@@ -0,0 +1,28 @@
+package christmas.domain;
+
+import static java.util.Comparator.comparingInt;
+
+import java.util.Arrays;
+
+public enum EventBadge {
+ NONE(0, "์์"), STAR(5000, "๋ณ"), TREE(10000, "ํธ๋ฆฌ"), SANTA(20000, "์ฐํ");
+
+ private final int money;
+ private String title;
+
+ EventBadge(int money, String title) {
+ this.money = money;
+ this.title = title;
+ }
+
+ public static EventBadge findByMoney(int input) {
+ return Arrays.stream(EventBadge.values())
+ .filter(eventBadge -> eventBadge.money <= input)
+ .max(comparingInt(o -> o.money))
+ .orElse(NONE);
+ }
+
+ public String getTitle() {
+ return title;
+ }
+} | Java | ์ค...์ง๊ธ ์๊ฐํด๋ณด๋ ๋ง์ํ์ ์๊ฒฌ์ด ๋ ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค. ๐ฅน |
@@ -0,0 +1,32 @@
+package christmas.domain;
+
+import java.time.LocalDate;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public enum TotalDiscountType {
+ CHRISTMAS_D_DAY(IntStream.range(1, 26).boxed().toList()),
+ SPECIAL(List.of(3, 10, 17, 24, 25, 31)),
+ NONE(List.of());
+
+ private List<Integer> days;
+
+ TotalDiscountType(List<Integer> days) {
+ this.days = days;
+ }
+
+ public List<Integer> getDays() {
+ return Collections.unmodifiableList(days);
+ }
+
+ public static TotalDiscountType findSpecialTypeByLocalDate(LocalDate localDate) {
+ int day = localDate.getDayOfMonth();
+
+ return Stream.of(TotalDiscountType.SPECIAL)
+ .filter(specialType -> specialType.days.contains(day))
+ .findAny()
+ .orElse(TotalDiscountType.NONE);
+ }
+} | Java | ์ ๊ฐ ์๊ธฐ๋ก java์ Calender์ Date๋ ์ง์ํด LocalDate๋ LocalDateTime์ ์ฌ์ฉํด์ผํ๋ ๊ฒ์ผ๋ก ์๊ณ ์์ต๋๋ค!
์ ๋ ๋จ์ํ๊ฒ ์ ์๋ฅผ ์ฌ์ฉํ๋ ๊ฒ๋ณด๋จ LocalDate๋ฅผ ํ์ฉํ๋ ํธ์ด ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ํด๋น ๋ถ๋ถ์ ์ซ์๋ฅผ ์์๋ก ๋ง๋ค๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,26 @@
+package christmas.domain;
+
+import java.time.LocalDate;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ChristmasDDayDiscountCreator implements TotalDiscountCreator {
+
+ private static final Map<Integer, TotalDiscount> CACHE;
+
+ static {
+ CACHE = new HashMap<>();
+
+ TotalDiscountType.CHRISTMAS_D_DAY.getDays()
+ .forEach(day -> CACHE.put(day,
+ new TotalDiscount(new Money(1000 + (day - 1) * 100),
+ TotalDiscountType.CHRISTMAS_D_DAY)));
+ }
+
+ @Override
+ public TotalDiscount from(LocalDate date) {
+ int dayOfMonth = date.getDayOfMonth();
+
+ return CACHE.getOrDefault(dayOfMonth, TotalDiscount.NONE);
+ }
+} | Java | ์ด ๋ถ๋ถ๋ ์์ํ ํ๋ค๋ฉด ์ซ์์ ์๋ฏธ๋ ๋ช
ํํ ์ ์ ์๊ณ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! :) |
@@ -0,0 +1,28 @@
+package christmas.domain;
+
+import java.util.List;
+
+public class MenuDiscounts {
+
+ private static final MenuDiscounts NONE = new MenuDiscounts(List.of());
+
+ private List<MenuDiscount> menuDiscounts;
+
+ public MenuDiscounts(List<MenuDiscount> menuDiscounts) {
+ this.menuDiscounts = menuDiscounts;
+ }
+
+ public Money sumOfWeekDaysDiscounts() {
+ return menuDiscounts.stream()
+ .filter(MenuDiscount::isWeekdays)
+ .map(MenuDiscount::getMoney)
+ .reduce(Money.ZERO, Money::plus);
+ }
+
+ public Money sumOfWeekendsDiscounts() {
+ return menuDiscounts.stream()
+ .filter(MenuDiscount::isWeekends)
+ .map(MenuDiscount::getMoney)
+ .reduce(Money.ZERO, Money::plus);
+ }
+} | Java | ์คํธ๋ฆผ์ ๋๊ฒ ์ ์ฌ์ฉํ์๋ ๊ฒ ๊ฐ์์..!
ํน์ ๊ณต๋ถํ์๋ ํ(??) ์ด๋ ๊ฒ ์์ผ์ค์ง.. ์ฌ์ญค๋ด
๋๋ค ใ
ใ
|
@@ -0,0 +1,46 @@
+package christmas.domain;
+
+import java.util.Arrays;
+import java.util.List;
+
+public enum MenuGroup {
+ APPETIZER("์ ํผํ์ด์ ", Arrays.asList(
+ MenuDetail.MUSHROOM_SOUP,
+ MenuDetail.TAPAS,
+ MenuDetail.CAESAR_SALAD)),
+ MAIN("๋ฉ์ธ", Arrays.asList(
+ MenuDetail.T_BONE_STEAK,
+ MenuDetail.BARBECUE_RIBS,
+ MenuDetail.SEAFOOD_PASTA,
+ MenuDetail.CHRISTMAS_PASTA)),
+ DESSERT("๋์ ํธ", Arrays.asList(
+ MenuDetail.CHOCOLATE_CAKE,
+ MenuDetail.ICE_CREAM
+ )),
+ DRINK("์๋ฃ", Arrays.asList(
+ MenuDetail.ZERO_COLA,
+ MenuDetail.RED_WINE,
+ MenuDetail.CHAMPAGNE
+ ));
+
+ private static final String MENU_GROUP_NOT_FOUND_ERROR_MESSAGE = "[ERROR] ๋ฉ๋ด๋ฅผ ํ์ธํด์ฃผ์ธ์.";
+
+ private String title;
+ private List<MenuDetail> menuDetails;
+
+ MenuGroup(String title, List<MenuDetail> menuDetails) {
+ this.title = title;
+ this.menuDetails = menuDetails;
+ }
+
+ public static MenuGroup findByMenuDetail(MenuDetail menuDetail) {
+ return Arrays.stream(MenuGroup.values())
+ .filter(menuGroup -> menuGroup.hasMenuDetail(menuDetail))
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException(MENU_GROUP_NOT_FOUND_ERROR_MESSAGE));
+ }
+
+ public boolean hasMenuDetail(MenuDetail menuDetail) {
+ return menuDetails.contains(menuDetail);
+ }
+}
\ No newline at end of file | Java | ํด๋น ์๋ฌ ๋ฉ์์ง๊ฐ ์กฐ๊ธ ๋ชจํธํ ๊ฒ ๊ฐ์์
ํด๋น ๋ฉ๋ด๋ ์ฐํ
์ฝ ์๋น์์ ํ๋งคํ์ง ์์ต๋๋ค ๋ฑ๊ณผ ๊ฐ์ ์กฐ๊ธ ํน์ ํ ๋ป์ ๋ด๋ ๊ฒ์ ์ด๋จ๊น์? |
@@ -0,0 +1,26 @@
+package christmas.dtos;
+
+import christmas.domain.BenefitType;
+
+public class BenefitDto {
+
+ private BenefitType benefitType;
+ private int discountAmount;
+
+ BenefitDto(BenefitType benefitType, int discountAmount) {
+ this.benefitType = benefitType;
+ this.discountAmount = discountAmount;
+ }
+
+ public static BenefitDto toDto(BenefitType benefitType, int discountAmount) {
+ return new BenefitDto(benefitType, discountAmount);
+ }
+
+ public BenefitType getBenefitType() {
+ return benefitType;
+ }
+
+ public int getDiscountAmount() {
+ return discountAmount;
+ }
+} | Java | dto๋ record ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ฉด ์ฝ๊ฒ ๊ตฌํ ๊ฐ๋ฅํ๋๋ผ๊ตฌ์, ์ฐธ๊ณ ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,80 @@
+package christmas.controller;
+
+import christmas.domain.BenefitCalculationFactory;
+import christmas.domain.Benefits;
+import christmas.domain.EventPlanner;
+import christmas.domain.Order;
+import christmas.dtos.OrderLineDto;
+import christmas.util.OrderLineMapper;
+import christmas.view.ErrorMessage;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.time.LocalDate;
+import java.util.List;
+
+public class ChristmasController {
+
+ public static void run() {
+ OutputView.printWelcomeMessage();
+ int day = getExpectedVisitDate();
+
+ Order order = getOrder();
+
+ LocalDate orderDate = LocalDate.of(2023, 12, day);
+
+ Benefits benefits = BenefitCalculationFactory.calculateBenefits(order, orderDate);
+
+ OutputView.printBenefitPreviewMessage(orderDate);
+
+ EventPlanner.printPreview(order, benefits);
+ }
+
+ public static Order getOrder() {
+ try {
+ OutputView.printOrderMenuMessage();
+ List<OrderLineDto> dtos = InputView.readMenus();
+ validateDuplicateMenus(dtos);
+
+ Order order = new Order(OrderLineMapper.orderLineDtosToOrderLines(dtos));
+
+ return order;
+ } catch (IllegalArgumentException e) {
+ OutputView.printExceptionMessage(e);
+ return getOrder();
+ }
+ }
+
+
+ public static int getExpectedVisitDate() {
+ try {
+ OutputView.printExpectedVisitDateMessage();
+ int day = InputView.readInteger();
+ validateExpectedVisitDate(day);
+ return day;
+ } catch (IllegalArgumentException e) {
+
+ System.out.println(e.getMessage());
+ System.out.println(e.getClass());
+ OutputView.printExceptionMessage(e);
+ return getExpectedVisitDate();
+ }
+ }
+
+ private static void validateExpectedVisitDate(int day) {
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_DATE_INPUT.getMessage());
+ }
+ }
+
+ private static void validateDuplicateMenus(List<OrderLineDto> dtos) {
+ int originalSize = dtos.size();
+ int distinctSize = (int) dtos.stream()
+ .map(OrderLineDto::getMenuDetail)
+ .distinct()
+ .count();
+
+ if (originalSize != distinctSize) {
+ throw new IllegalArgumentException(ErrorMessage.DUPLICATE_MENU_INPUT.getMessage());
+ }
+ }
+} | Java | ๋ง์ต๋๋ค!.. ๊ณผ์ ์์ ์๋ฏธ ์๋ ์ซ์๋ค์ ์์๋ก ๋ฆฌํฉํ ๋ง ํ๋ ๋ถ๋ถ์ด ์ ๋ฐ์ ์ผ๋ก ๋ถ์กฑํ๋ค ์๊ฐํฉ๋๋ค.๐ฅฒ |
@@ -0,0 +1,26 @@
+package christmas.domain;
+
+import java.time.LocalDate;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ChristmasDDayDiscountCreator implements TotalDiscountCreator {
+
+ private static final Map<Integer, TotalDiscount> CACHE;
+
+ static {
+ CACHE = new HashMap<>();
+
+ TotalDiscountType.CHRISTMAS_D_DAY.getDays()
+ .forEach(day -> CACHE.put(day,
+ new TotalDiscount(new Money(1000 + (day - 1) * 100),
+ TotalDiscountType.CHRISTMAS_D_DAY)));
+ }
+
+ @Override
+ public TotalDiscount from(LocalDate date) {
+ int dayOfMonth = date.getDayOfMonth();
+
+ return CACHE.getOrDefault(dayOfMonth, TotalDiscount.NONE);
+ }
+} | Java | ๊ฐ์ฌํฉ๋๋ค :> ๋ง๋ ๋ง์์ด๋ผ ์๊ฐํฉ๋๋ค |
@@ -0,0 +1,24 @@
+const PREFIX = '[ERROR]';
+
+const ERROR = Object.freeze({
+ dateType: `${PREFIX} ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuOrderType: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuDuplicated: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuNotExist: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuAmount: `${PREFIX} ํ๋ฒ์ ์ฃผ๋ฌธ ๊ฐ๋ฅํ ๋ฉ๋ด์ ์ต๋ ๊ฐฏ์๋ 20๊ฐ ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuOnlyBeverage: `${PREFIX} ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuName: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ์ด๋ฆ์ด String์ด ์๋๋๋ค.`,
+ menuType: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ menuPrice: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventType: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ eventStatus: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ์ํ๊ฐ Boolean์ด ์๋๋๋ค.`,
+ eventPrice: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventNotExist: `${PREFIX} ์กด์ฌํ์ง ์๋ ์ด๋ฒคํธ ์
๋๋ค.`,
+});
+
+export default ERROR; | JavaScript | ์ค๋ฅ ๋ฉ์์ง๊ฐ ์ฌ๋ฌ ๊ฐ์ธ ๊ฑด ์ข์ง๋ง ์ค์ง์ ์ธ ์ฌ์ฉ์ ์
์ฅ์์๋ String, Number, Boolean์ด ์ด๋ค๊ฑด์ง ๋ชจ๋ฅด์ค ๊ฒ ๊ฐ์์!
๊ทธ๋ฆฌ๊ณ ๊ฐ์ ๋ฌธ๊ตฌ์ธ๋ฐ ์ฌ๋ฌ ๊ฐ๋ก ๋ง๋์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,123 @@
+import { MESSAGE, SETTING } from '../constant/index.js';
+import { MenuRepository, EventRepository } from '../repository/index.js';
+
+export default class Events {
+ #date;
+ #menus;
+
+ constructor(date, menus) {
+ this.#date = date;
+ this.#menus = menus;
+ if (this.#menus.canApplyEvent()) {
+ this.#set();
+ }
+ }
+
+ #set() {
+ this.#setChristmasDiscount();
+ this.#setPresentChampagne();
+ this.#setSpecialDiscount();
+ this.#setWeekdayDiscount();
+ this.#setWeekendDiscount();
+ }
+
+ #setChristmasDiscount() {
+ const amount =
+ SETTING.christmasDiscount.default
+ + SETTING.christmasDiscount.forDay * (this.#date.get() - 1)
+ if (this.#date.get() <= SETTING.date.christmas && amount !== 0) {
+ EventRepository.getEventByType(MESSAGE.christmasDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.christmasDiscount).setAmount(amount);
+ }
+
+ #setWeekdayDiscount() {
+ const amount = SETTING.weekDiscount * this.#menus.types().dessert;
+ if (!this.#date.isWeekend() && amount !== 0) {
+ EventRepository.getEventByType(MESSAGE.weekdayDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.weekdayDiscount).setAmount(amount);
+ }
+
+ #setWeekendDiscount() {
+ const amount = SETTING.weekDiscount * this.#menus.types().main;
+ if (this.#date.isWeekend() && amount !== 0) {
+ EventRepository.getEventByType(MESSAGE.weekendDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.weekendDiscount).setAmount(amount);
+ }
+
+ #setSpecialDiscount() {
+ if (this.#date.hasStar()) {
+ EventRepository.getEventByType(MESSAGE.specialDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.specialDiscount).setAmount(
+ SETTING.specialDiscount,
+ );
+ }
+
+ #setPresentChampagne() {
+ if (this.#menus.previousPrice() >= SETTING.minimumPresentPrice) {
+ EventRepository.getEventByType(MESSAGE.presentDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.presentDiscount).setAmount(
+ -MenuRepository.getMenuByName(SETTING.presentMenu).get().price,
+ );
+ }
+
+ present() {
+ if (EventRepository.getEventByType(MESSAGE.presentDiscount).get().status) {
+ return MESSAGE.present;
+ }
+ return MESSAGE.printNoEvent;
+ }
+
+ totalEventAmount() {
+ let eventPrice = 0;
+ EventRepository.get().forEach(event => {
+ if (event.get().status) {
+ eventPrice += event.get().amount;
+ }
+ });
+
+ return eventPrice;
+ }
+
+ totalPrice() {
+ let price = this.#menus.previousPrice() + this.totalEventAmount();
+ if (EventRepository.getEventByType(MESSAGE.presentDiscount).get().status) {
+ price += MenuRepository.getMenuByName(SETTING.presentMenu).get().price;
+ }
+
+ return price;
+ }
+
+ eventBadge() {
+ const amount = this.totalEventAmount();
+ switch (true) {
+ case amount <= SETTING.minimumAmountBadge.santa:
+ return MESSAGE.badge.santa;
+ case amount <= SETTING.minimumAmountBadge.tree:
+ return MESSAGE.badge.tree;
+ case amount <= SETTING.minimumAmountBadge.star:
+ return MESSAGE.badge.star;
+ default:
+ return MESSAGE.printNoEvent;
+ }
+ }
+
+ appliedEvents() {
+ const result = [];
+
+ if (!this.#menus.canApplyEvent()) {
+ return [MESSAGE.printNoEvent];
+ }
+ EventRepository.get().forEach(event => {
+ if (event.get().status && event.get().amount !== 0) {
+ result.push(event.print());
+ }
+ });
+
+ return result;
+ }
+} | JavaScript | ์ด๋ฒคํธ๋ฅผ ๋ถ๋ฆฌํด๋ ๊ด์ฐฎ์ง ์์๊น ํ๋ ์๊ฐ์ด ๋ญ๋๋ค..!
ํ๋์ ํ์ผ ์์ ๋ฉ์๋๋ ๋ค๋ฅด๊ฒ ์์ง๋ง ํํ, ์ฆ์ , ์ด ๊ธ์ก, ํํ ์ ๊ธ์ก ๋ฑ ๋ชจ๋ ๋ค์ด๊ฐ์๋ ๊ฒ ๊ฐ์์ ! |
@@ -0,0 +1,70 @@
+import Menus from './Menus.js';
+import Order from './Order.js';
+import { REGEXP, SETTING } from '../constant/index.js';
+import { Date } from '../model/index.js';
+import { OutputView, InputView } from '../view/index.js';
+import {
+ MenuDuplicatedError,
+ MenuOrderTypeError,
+} from '../error/CustomError.js';
+
+export default class GetOrder {
+ #order;
+
+ async startOrder() {
+ const date = await this.#readDate();
+ const menus = await this.#readMenus();
+ this.#order = new Order(date, menus);
+ }
+
+ async #readDate() {
+ while (true) {
+ const date = await InputView.readDate();
+ try {
+ return new Date(date);
+ } catch (error) {
+ OutputView.printErrorMessage(error);
+ }
+ }
+ }
+
+ async #readMenus() {
+ while (true) {
+ const menus = await InputView.readMenus();
+ try {
+ this.#validateInputType(menus);
+ return this.#stringToMenus(menus);
+ } catch (error) {
+ OutputView.printErrorMessage(error);
+ }
+ }
+ }
+
+ #validateInputType(string) {
+ if (!REGEXP.menus.test(string)) {
+ throw new MenuOrderTypeError();
+ }
+ }
+
+ #validateMenuDuplicated(inputLength, resultLength) {
+ if (inputLength !== resultLength) {
+ throw new MenuDuplicatedError();
+ }
+ }
+
+ #stringToMenus(string) {
+ const menus = {};
+ string.split(SETTING.menuSplit).forEach(menuInfo => {
+ const menu = menuInfo.split(SETTING.menuAmountSplit)[0];
+ const amount = menuInfo.split(SETTING.menuAmountSplit)[1];
+ menus[`${menu}`] = Number(amount);
+ });
+
+ this.#validateMenuDuplicated(
+ string.split(SETTING.menuSplit).length,
+ Object.keys(menus).length,
+ );
+
+ return new Menus(menus);
+ }
+} | JavaScript | 0๊ณผ 1์ด ์์๋ผ๋ฉด ํด๋น ๋ถ๋ถ๋ ๋ณ์ํํด์ ์๋ฏธ๋ฅผ ์ฃผ๋ ๊ฒ๋ ๊ด์ฐฎ์๋ณด์
๋๋ค ! |
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | ์ค ์ด๋ ๊ฒ ํ๋ ๋ฐฉ๋ฒ์ด ์์๋ค์
Lotto ๋ ์ฌ์ฉํด๋๊ณ ์ด๋ฒ์ ์ด๋ ๊ฒ ์ํ๋ค์...! |
@@ -0,0 +1,24 @@
+const PREFIX = '[ERROR]';
+
+const ERROR = Object.freeze({
+ dateType: `${PREFIX} ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuOrderType: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuDuplicated: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuNotExist: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuAmount: `${PREFIX} ํ๋ฒ์ ์ฃผ๋ฌธ ๊ฐ๋ฅํ ๋ฉ๋ด์ ์ต๋ ๊ฐฏ์๋ 20๊ฐ ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuOnlyBeverage: `${PREFIX} ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuName: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ์ด๋ฆ์ด String์ด ์๋๋๋ค.`,
+ menuType: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ menuPrice: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventType: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ eventStatus: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ์ํ๊ฐ Boolean์ด ์๋๋๋ค.`,
+ eventPrice: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventNotExist: `${PREFIX} ์กด์ฌํ์ง ์๋ ์ด๋ฒคํธ ์
๋๋ค.`,
+});
+
+export default ERROR; | JavaScript | ์ค ๊ทธ๋ด ์ ์๊ฒ ๋ค์!
๊ฐ์ ๋ฌธ๊ตฌ์ธ๋ฐ ์ฌ๋ฌ๊ฐ๋ก ๋ง๋ ์ด์ ๋, ๋ฐ์ํ ์ํฉ์ด ๋ค ๋ฌ๋ผ์ ๋ค๋ฅด๊ฒ ๋ง๋ค์์ต๋๋ค...
์ฌ์ค ๋ง์๊ฐ์์ ์ํฉ๋ณ๋ก ๋ค๋ฅธ ๋ฉ์ธ์ง๋ฅผ ๋์ ธ์ฃผ๊ณ ์ถ์์ง๋ง, ์๊ตฌ์ฌํญ์์ ์๋ฌ๋ฉ์ธ์ง๋ฅผ ํต์ผํด์
์ด๋จ ์ ์์ด ๊ฐ์ ๋ฌธ๊ตฌ๋ก ๋ฃ๊ฒ ๋์๋ค์! |
@@ -0,0 +1,123 @@
+import { MESSAGE, SETTING } from '../constant/index.js';
+import { MenuRepository, EventRepository } from '../repository/index.js';
+
+export default class Events {
+ #date;
+ #menus;
+
+ constructor(date, menus) {
+ this.#date = date;
+ this.#menus = menus;
+ if (this.#menus.canApplyEvent()) {
+ this.#set();
+ }
+ }
+
+ #set() {
+ this.#setChristmasDiscount();
+ this.#setPresentChampagne();
+ this.#setSpecialDiscount();
+ this.#setWeekdayDiscount();
+ this.#setWeekendDiscount();
+ }
+
+ #setChristmasDiscount() {
+ const amount =
+ SETTING.christmasDiscount.default
+ + SETTING.christmasDiscount.forDay * (this.#date.get() - 1)
+ if (this.#date.get() <= SETTING.date.christmas && amount !== 0) {
+ EventRepository.getEventByType(MESSAGE.christmasDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.christmasDiscount).setAmount(amount);
+ }
+
+ #setWeekdayDiscount() {
+ const amount = SETTING.weekDiscount * this.#menus.types().dessert;
+ if (!this.#date.isWeekend() && amount !== 0) {
+ EventRepository.getEventByType(MESSAGE.weekdayDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.weekdayDiscount).setAmount(amount);
+ }
+
+ #setWeekendDiscount() {
+ const amount = SETTING.weekDiscount * this.#menus.types().main;
+ if (this.#date.isWeekend() && amount !== 0) {
+ EventRepository.getEventByType(MESSAGE.weekendDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.weekendDiscount).setAmount(amount);
+ }
+
+ #setSpecialDiscount() {
+ if (this.#date.hasStar()) {
+ EventRepository.getEventByType(MESSAGE.specialDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.specialDiscount).setAmount(
+ SETTING.specialDiscount,
+ );
+ }
+
+ #setPresentChampagne() {
+ if (this.#menus.previousPrice() >= SETTING.minimumPresentPrice) {
+ EventRepository.getEventByType(MESSAGE.presentDiscount).setStatus(true);
+ }
+ EventRepository.getEventByType(MESSAGE.presentDiscount).setAmount(
+ -MenuRepository.getMenuByName(SETTING.presentMenu).get().price,
+ );
+ }
+
+ present() {
+ if (EventRepository.getEventByType(MESSAGE.presentDiscount).get().status) {
+ return MESSAGE.present;
+ }
+ return MESSAGE.printNoEvent;
+ }
+
+ totalEventAmount() {
+ let eventPrice = 0;
+ EventRepository.get().forEach(event => {
+ if (event.get().status) {
+ eventPrice += event.get().amount;
+ }
+ });
+
+ return eventPrice;
+ }
+
+ totalPrice() {
+ let price = this.#menus.previousPrice() + this.totalEventAmount();
+ if (EventRepository.getEventByType(MESSAGE.presentDiscount).get().status) {
+ price += MenuRepository.getMenuByName(SETTING.presentMenu).get().price;
+ }
+
+ return price;
+ }
+
+ eventBadge() {
+ const amount = this.totalEventAmount();
+ switch (true) {
+ case amount <= SETTING.minimumAmountBadge.santa:
+ return MESSAGE.badge.santa;
+ case amount <= SETTING.minimumAmountBadge.tree:
+ return MESSAGE.badge.tree;
+ case amount <= SETTING.minimumAmountBadge.star:
+ return MESSAGE.badge.star;
+ default:
+ return MESSAGE.printNoEvent;
+ }
+ }
+
+ appliedEvents() {
+ const result = [];
+
+ if (!this.#menus.canApplyEvent()) {
+ return [MESSAGE.printNoEvent];
+ }
+ EventRepository.get().forEach(event => {
+ if (event.get().status && event.get().amount !== 0) {
+ result.push(event.print());
+ }
+ });
+
+ return result;
+ }
+} | JavaScript | Events ์์์ ์ฌ๋ฌ๊ฐ๋ฅผ ๋ค ๋ฐํํด ์ฃผ๋ ค ํ์๋๋ฐ, ๋ง์ํ์ ๊ฒ ์ฒ๋ผ ๋ถ๋ฆฌํ๋๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ผ ๊ฒ ๊ฐ๋ค์! |
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | ์ ๋ ์ด๋ ๊ฒ ์ฌ์ฉํ๊ณ , ์๋ฃ์ฃผ๋ฌธ validate์์ ์ด๊ฑธ ์ฌ์ฉํ๋ ค๊ณ ํ๋๊ฑด๋ฐ, ์ด์ํ๊ฒ
์๋ฃ์ฃผ๋ฌธ validate์์ ์ด types๋ฅผ ๋ถ๋ฌ์ค๋ฉด ํ
์คํธ์ฝ๋๊ฐ ๋ฌดํ๋ฃจํ์ ๋น ์ง๋๋ผ๊ตฌ์...
์ค๋ฅ๋ฅผ ์ฐพ๋๋ฐ 3-4์๊ฐ์ ๋ ์๊ฐ์ ์ฐ๋ค๊ฐ ๊ฒฐ๊ตญ ์๋ก์ด ๋ฉ์๋๋ฅผ ๋ง๋ค์์ต๋๋ค.. ํํ |
@@ -0,0 +1,24 @@
+const PREFIX = '[ERROR]';
+
+const ERROR = Object.freeze({
+ dateType: `${PREFIX} ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuOrderType: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuDuplicated: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuNotExist: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuAmount: `${PREFIX} ํ๋ฒ์ ์ฃผ๋ฌธ ๊ฐ๋ฅํ ๋ฉ๋ด์ ์ต๋ ๊ฐฏ์๋ 20๊ฐ ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuOnlyBeverage: `${PREFIX} ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuName: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ์ด๋ฆ์ด String์ด ์๋๋๋ค.`,
+ menuType: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ menuPrice: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventType: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ eventStatus: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ์ํ๊ฐ Boolean์ด ์๋๋๋ค.`,
+ eventPrice: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventNotExist: `${PREFIX} ์กด์ฌํ์ง ์๋ ์ด๋ฒคํธ ์
๋๋ค.`,
+});
+
+export default ERROR; | JavaScript | ์ ๋ ๋ค๋ฅธ ๋ถ์ด ๋จ๊ฒจ์ฃผ์ ๋ฆฌ๋ทฐ์ฒ๋ผ, ํด๋น ์๋ฌ ๋ฉ์ธ์ง๋ ์ฌ์ฉ์ ๋จ์ ์ถ๋ ฅ๋๋ ๋ถ๋ถ์ด๋ฏ๋ก, ์ฌ์ฉ์๊ฐ ์ข๋ ์ดํดํ๊ธฐ ํธํ ๋ฉ์ธ์ง ํํ๋ผ๋ฉด ๋ ์ข์ ๊ฑฐ ๊ฐ์์ ใ
ใ
โบ๏ธ |
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | ๋ฉ๋ด ์ ํจ์ฑ ๊ฒ์ฌ์ ๋ํ ์ฝ๋ ๋ถ๋ฆฌ๋ฅผ ๋ฐ๋ก ํ์ง ์๊ณ , ๋ฉ๋ด ํด๋์ค๋ด์์ ์งํํ์๋ ๋ฐฉ๋ฒ์ ํํ์ ๊ฑฐ ๊ฐ๋ค์! ์ ๋ 4์ฃผ๋์ ๋งค๋ฒ ์ ํจ์ฑ ๊ฒ์ฌ ํจ์, ํด๋์ค๋ฅผ ๋ฐ๋ก ๋ถ๋ฆฌํ์ฌ ํธ์ถํ์๋๋ฐ์ ! ํน์, ์ด๋ค ์๋๋ ์๊ฐ์ผ๋ก ๊ตฌ์ฑํ๊ณ ์ ํ์
จ๋์ง ์๊ฒฌ์ด ๊ถ๊ธํฉ๋๋ค ใ
ใ
|
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | ์ ๋ ์๋ฃ๋ง ์ฃผ๋ฌธํ ์๋ฌ ์ฒ๋ฆฌ์ ๋ํด์ ํ์
์ ๊ฐ์๊ฐ 1๊ฐ๋ง ์๋๋ฐ(has ์ฌ์ฉ), ๊ทธ๊ฒ drink ์ธ ๊ฒฝ์ฐ๋ผ๊ณ ์์ฑ์ ํ์์ด์
์ด๊ฒ ์ข๋ ๋ช
๋ฃํด์ ์ข์ ๊ฑฐ ๊ฐ๋ค์ฉ ๋ฐฐ์ฐ๊ณ ๊ฐ์ โบ๏ธ |
@@ -0,0 +1,24 @@
+const PREFIX = '[ERROR]';
+
+const ERROR = Object.freeze({
+ dateType: `${PREFIX} ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuOrderType: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuDuplicated: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuNotExist: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuAmount: `${PREFIX} ํ๋ฒ์ ์ฃผ๋ฌธ ๊ฐ๋ฅํ ๋ฉ๋ด์ ์ต๋ ๊ฐฏ์๋ 20๊ฐ ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuOnlyBeverage: `${PREFIX} ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuName: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ์ด๋ฆ์ด String์ด ์๋๋๋ค.`,
+ menuType: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ menuPrice: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventType: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ eventStatus: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ์ํ๊ฐ Boolean์ด ์๋๋๋ค.`,
+ eventPrice: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventNotExist: `${PREFIX} ์กด์ฌํ์ง ์๋ ์ด๋ฒคํธ ์
๋๋ค.`,
+});
+
+export default ERROR; | JavaScript | ๊ฐ์ฌํฉ๋๋ค!! ๊ทธ๋ถ๋ถ์ ์ธ์ธํ๊ฒ ์๊ฐํ์ง ๋ชปํ๋ค์ ใ
ใ
|
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | ์ฌ์ค ์ ๋ 2์ฃผ์ฐจ๊น์ง๋ ์ ํจ์ฑ๊ฒ์ฌ๋ฅผ ๋ฐ๋ก ๋ถ๋ฆฌํด์ ์งํํ์์ต๋๋ค!
ํ์ง๋ง, 3์ฃผ์ฐจ ๊ณผ์ Lotto์์, ์ฃผ์ด์ง Lotto ํด๋์ค ๋ด๋ถ์ ์ ํจ์ฑ๊ฒ์ฌ๋ฅผ ์งํํ๋ ์ฝ๋๋ฅผ ์ฃผ์ด์ก๊ธธ๋
์ด๋ ๊ฒ๋ ํ ์ ์๋? ์ฐํ
์ฝ๊ฐ ์ํ๋ ๋ฐฉ์์ ๋ฌด์์ผ๊น? ์๊ฐํ๋ฉฐ ๋น์ทํ๊ฒ ํ๋ ค๊ณ ํ๋ ๊ฒ ๊ฐ๋ค์ ใ
ใ
์์ง ์ฝ๋ฆฐ์ด๋ผ ์์ฒญ๋ ์๋๋ ์๊ฐ์ด ์์๋ ๊ฒ์ ์๋์์ต๋๋ค :) |
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | ์ฌ๊ฒฝ๋์ ๋ฐฉ๋ฒ๋ ๋์์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค! ์ฝ๋๋ฅผ ์ฝ๋ ์
์ฅ์์ ๊ทธ ํธ์ด ํจ์ฌ ๊น๋ํ ๊ฒ ๊ฐ์์ ใ
ใ
๋ฆฌ์์ค๋ ๋ฏธ์ํ๊ฒ๋๋ง ์ ๊ฒ ์ฐจ์งํ ๊ฒ ๊ฐ์ต๋๋ค :) |
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | `์ด๋ฒคํธ์ ์คํ์ ๊ฒฐ์ ` ํ๋ ์ฑ
์์ `Events`๊ฐ ๊ฐ์ง๊ณ ์์ ์๋ ์์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,76 @@
+import ERROR from '../constant/Error.js';
+
+export class DateTypeError extends Error {
+ constructor() {
+ super(ERROR.dateType);
+ }
+}
+
+export class MenuOrderTypeError extends Error {
+ constructor() {
+ super(ERROR.menuOrderType);
+ }
+}
+
+export class MenuDuplicatedError extends Error {
+ constructor() {
+ super(ERROR.menuDuplicated);
+ }
+}
+
+export class MenuNotExistError extends Error {
+ constructor() {
+ super(ERROR.menuNotExist);
+ }
+}
+
+export class MenuAmountError extends Error {
+ constructor() {
+ super(ERROR.menuAmount);
+ }
+}
+
+export class MenuOnlyBeverageError extends Error {
+ constructor() {
+ super(ERROR.menuOnlyBeverage);
+ }
+}
+
+export class MenuNameError extends Error {
+ constructor() {
+ super(ERROR.menuName);
+ }
+}
+
+export class MenuTypeError extends Error {
+ constructor() {
+ super(ERROR.menuType);
+ }
+}
+export class MenuPriceError extends Error {
+ constructor() {
+ super(ERROR.menuPrice);
+ }
+}
+
+export class EventTypeError extends Error {
+ constructor() {
+ super(ERROR.eventType);
+ }
+}
+export class EventStatusError extends Error {
+ constructor() {
+ super(ERROR.eventStatus);
+ }
+}
+export class EventAmountError extends Error {
+ constructor() {
+ super(ERROR.eventAmount);
+ }
+}
+
+export class EventNotExistError extends Error {
+ constructor() {
+ super(ERROR.eventNotExist);
+ }
+} | JavaScript | ์ปค์คํ
์๋ฌ ๐ |
@@ -0,0 +1,33 @@
+const SETTING = Object.freeze({
+ date: {
+ minimun: 1,
+ maximum: 31,
+ christmas: 25,
+ friday: 1,
+ saturday: 2,
+ sunday: 3,
+ },
+ weekDays: 7,
+
+ locale: 'ko-KR',
+ menuSplit: ',',
+ menuAmountSplit: '-',
+
+ maximumMenusAmount: 20,
+ minimumApplyEventPrice: 10000,
+
+ christmasDiscount: { default: -1000, forDay: -100 },
+ weekDiscount: -2023,
+ specialDiscount: -1000,
+
+ minimumPresentPrice: 120000,
+ presentMenu: '์ดํ์ธ',
+
+ minimumAmountBadge: {
+ santa: -20000,
+ tree: -10000,
+ star: -5000,
+ },
+});
+
+export default SETTING; | JavaScript | ํด๋จผ์๋ฌ๊ฐ ์๋ค์! [์ต์คํ
์
](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker)์ ์ฌ์ฉํด๋ณด๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | ```js
export default class Menus {
#menus = new Map();
constructor(menus) {
```
์ด๋ ๊ฒ ์์ฑ ํ ์๋ ์์ด์! |
@@ -0,0 +1,19 @@
+const MENU_LIST = Object.freeze({
+ mushRoomSoup: { name: '์์ก์ด์ํ', type: 'appetizer', price: 6000 },
+ tapas: { name: 'ํํ์ค', type: 'appetizer', price: 5500 },
+ caesarSalad: { name: '์์ ์๋ฌ๋', type: 'appetizer', price: 8000 },
+
+ tBoneSteak: { name: 'ํฐ๋ณธ์คํ
์ดํฌ', type: 'main', price: 55000 },
+ barbecueRibs: { name: '๋ฐ๋นํ๋ฆฝ', type: 'main', price: 54000 },
+ seafoodPasta: { name: 'ํด์ฐ๋ฌผํ์คํ', type: 'main', price: 35000 },
+ christmasPasta: { name: 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ', type: 'main', price: 25000 },
+
+ chocolateCake: { name: '์ด์ฝ์ผ์ดํฌ', type: 'dessert', price: 15000 },
+ iceCream: { name: '์์ด์คํฌ๋ฆผ', type: 'dessert', price: 5000 },
+
+ cokeZero: { name: '์ ๋ก์ฝ๋ผ', type: 'beverage', price: 3000 },
+ redWine: { name: '๋ ๋์์ธ', type: 'beverage', price: 60000 },
+ champagne: { name: '์ดํ์ธ', type: 'beverage', price: 25000 },
+});
+
+export default MENU_LIST; | JavaScript | ```js
const CATEGORIES = Object.freeze({
appetizer: 'appetizer',
main: 'main',
dessert: 'dessert',
beverage: 'beverage',
});
const MENU_LIST = Object.freeze({
mushRoomSoup: { name: '์์ก์ด์ํ', type: CATEGORIES.appetizer, price: 6000 },
tapas: { name: 'ํํ์ค', type: CATEGORIES.appetizer, price: 5500 },
caesarSalad: { name: '์์ ์๋ฌ๋', type: CATEGORIES.appetizer, price: 8000 },
```
์ด๋ถ๋ถ๋ ์์์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,24 @@
+const PREFIX = '[ERROR]';
+
+const ERROR = Object.freeze({
+ dateType: `${PREFIX} ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuOrderType: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuDuplicated: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuNotExist: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuAmount: `${PREFIX} ํ๋ฒ์ ์ฃผ๋ฌธ ๊ฐ๋ฅํ ๋ฉ๋ด์ ์ต๋ ๊ฐฏ์๋ 20๊ฐ ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuOnlyBeverage: `${PREFIX} ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuName: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ์ด๋ฆ์ด String์ด ์๋๋๋ค.`,
+ menuType: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ menuPrice: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventType: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ eventStatus: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ์ํ๊ฐ Boolean์ด ์๋๋๋ค.`,
+ eventPrice: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventNotExist: `${PREFIX} ์กด์ฌํ์ง ์๋ ์ด๋ฒคํธ ์
๋๋ค.`,
+});
+
+export default ERROR; | JavaScript | ํ์
์ฒดํน ๐๐
์ ๋ ์ฌ์ค ํ์
์ฒดํน ์๋ฌ๋ ๋์ ์ธ์ด์ ์ด์ฉ์ ์๋ ํ๊ณ๋ผ ์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ง๋ ์ํฉ ์์ฒด๊ฐ ์์ด์ ์๋๋ค๊ณ ์๊ฐํฉ๋๋คใ
ใ
... |
@@ -0,0 +1,893 @@
+import { MissionUtils } from '@woowacourse/mission-utils';
+import { EOL as LINE_SEPARATOR } from 'os';
+import App from '../../src/App.js';
+import { SETTING } from '../../src/constant/index.js';
+import { EventRepository } from '../../src/repository/index.js';
+
+const mockQuestions = inputs => {
+ MissionUtils.Console.readLineAsync = jest.fn();
+
+ MissionUtils.Console.readLineAsync.mockImplementation(() => {
+ const input = inputs.shift();
+
+ return Promise.resolve(input);
+ });
+};
+
+const getLogSpy = () => {
+ const logSpy = jest.spyOn(MissionUtils.Console, 'print');
+ logSpy.mockClear();
+
+ return logSpy;
+};
+
+const getOutput = logSpy => {
+ return [...logSpy.mock.calls].join(LINE_SEPARATOR);
+};
+
+const expectLogContains = (received, expectedLogs) => {
+ expectedLogs.forEach(log => {
+ expect(received).toContain(log);
+ });
+};
+
+const CHRISTMAS_WEEKDAY = '13';
+const CHRISTMAS_WEEKEND = '16';
+const CHRISTMAS_STAR = '24';
+const NOCHRISTMAS_WEEKDAY = '27';
+const NOCHRISTMAS_WEEKEND = '30';
+const NOCHRISTMAS_STAR = '31';
+
+const ALL_EVENTS = 'ํฐ๋ณธ์คํ
์ดํฌ-1,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,ํํ์ค-1,์ ๋ก์ฝ๋ผ-2,์ดํ์ธ-1,์ด์ฝ์ผ์ดํฌ-1';
+const NO_EVENTS = '์์ก์ด์ํ-1,์ ๋ก์ฝ๋ผ-1';
+const NO_DESSERT = 'ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,๋ ๋์์ธ-1,์์ ์๋ฌ๋-1';
+const NO_MAIN = '๋ ๋์์ธ-2,์์ ์๋ฌ๋-1,์ด์ฝ์ผ์ดํฌ-1';
+const NO_PRESENT = 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1,ํํ์ค-1';
+const NO_PRESENT_MAIN = '์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1,ํํ์ค-1';
+const NO_PRESENT_DESSERT = 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์ ๋ก์ฝ๋ผ-1,ํํ์ค-1';
+
+const BADGE_SANTA = ['13', 'ํฐ๋ณธ์คํ
์ดํฌ-2,์์ด์คํฌ๋ฆผ-5'];
+const BADGE_TREE = ['13', '์์ด์คํฌ๋ฆผ-5'];
+const BADGE_STAR = ['13', '์์ด์คํฌ๋ฆผ-3'];
+
+describe('App ๋ค์ํ case์์ ๋์ test', () => {
+ beforeEach(() => {
+ EventRepository.get().forEach(event => {
+ event.setAmount(0);
+ event.setStatus(false);
+ });
+ });
+
+ test(`case-1: ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด ${SETTING.minimumApplyEventPrice}๋ณด๋ค ์์ ๊ฒฝ์ฐ`, async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, NO_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์์ก์ด์ํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '9,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ '์์',
+ '<์ดํํ ๊ธ์ก>',
+ '0์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '9,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-2: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณx, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -2,023์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-29,223์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '127,277์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-3: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณx, ์ฃผ๋ง', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKEND, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,500์',
+ '์ฃผ๋ง ํ ์ธ: -4,046์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-31,546์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '124,954์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-4: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณo, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_STAR, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์',
+ 'ํ์ผ ํ ์ธ: -2,023์',
+ 'ํน๋ณ ํ ์ธ: -1,000',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-31,323์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '125,177์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-5: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณx, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKDAY, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํ์ผ ํ ์ธ: -2,023์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-27,023์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '129,477์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-6: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณx, ์ฃผ๋ง', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKEND, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ '์ฃผ๋ง ํ ์ธ: -4,046์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-29,046์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '127,454์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-7: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณo, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_STAR, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํ์ผ ํ ์ธ: -2,023์',
+ 'ํน๋ณ ํ ์ธ: -1,000',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-28,023์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '128,477์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-8: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณx, ์ฃผ๋ง์ด์ง๋ง ๋ฉ์ธ ๋ฉ๋ด๊ฐ ์์ด ์ฃผ๋ง ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKEND, NO_MAIN]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '๋ ๋์์ธ 2๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '143,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,500์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-27,500์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '140,500์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-9: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณx, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, NO_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํด์ฐ๋ฌผํ์คํ 1๊ฐ',
+ '๋ ๋์์ธ 1๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '158,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-27,200์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '155,800์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-10: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณo, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_STAR, NO_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํด์ฐ๋ฌผํ์คํ 1๊ฐ',
+ '๋ ๋์์ธ 1๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '158,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-29,300์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '153,700์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-11: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณx, ์ฃผ๋ง์ด์ง๋ง ๋ฉ์ธ ๋ฉ๋ด๊ฐ ์์ด ์ฃผ๋ง ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKEND, NO_MAIN]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '๋ ๋์์ธ 2๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '143,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-25,000์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '143,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-12: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณx, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKDAY, NO_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํด์ฐ๋ฌผํ์คํ 1๊ฐ',
+ '๋ ๋์์ธ 1๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '158,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-25,000์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '158,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-13: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณo, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_STAR, NO_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํด์ฐ๋ฌผํ์คํ 1๊ฐ',
+ '๋ ๋์์ธ 1๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '158,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-26,000์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '157,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-14: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณx, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -4,046์',
+ '<์ดํํ ๊ธ์ก>',
+ '-6,246์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '57,254์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '๋ณ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-15: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณx, ์ฃผ๋ง', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKEND, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,500์',
+ '์ฃผ๋ง ํ ์ธ: -2,023์',
+ '<์ดํํ ๊ธ์ก>',
+ '-4,523์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '58,977์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-16: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณo, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_STAR, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์',
+ 'ํ์ผ ํ ์ธ: -4,046์',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-8,346์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '55,154์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '๋ณ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-17: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณx, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKDAY, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํ์ผ ํ ์ธ: -4,046์',
+ '<์ดํํ ๊ธ์ก>',
+ '-4,046์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '59,454์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-18: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณx, ์ฃผ๋ง', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKEND, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ '์ฃผ๋ง ํ ์ธ: -2,023์',
+ '<์ดํํ ๊ธ์ก>',
+ '-2,023์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '61,477์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-19: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณo, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_STAR, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํ์ผ ํ ์ธ: -4,046์',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-5,046์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '58,454์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '๋ณ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-20: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณx, ์ฃผ๋ง์ด์ง๋ง ๋ฉ์ธ ๋ฉ๋ด๊ฐ ์์ด ์ฃผ๋ง ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKEND, NO_PRESENT_MAIN]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '38,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,500์',
+ '<์ดํํ ๊ธ์ก>',
+ '-2,500์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '36,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-21: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณx, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, NO_PRESENT_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '33,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ '<์ดํํ ๊ธ์ก>',
+ '-2,200์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '31,300์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-22: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณo, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_STAR, NO_PRESENT_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '33,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-4,300์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '29,200์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-23: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณx, ์ฃผ๋ง์ด์ง๋ง ๋ฉ์ธ ๋ฉ๋ด๊ฐ ์์ด ์ฃผ๋ง ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKEND, NO_PRESENT_MAIN]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '38,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ '์์',
+ '<์ดํํ ๊ธ์ก>',
+ '0์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '38,500์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-24: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณx, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKDAY, NO_PRESENT_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '33,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ '์์',
+ '<์ดํํ ๊ธ์ก>',
+ '0์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '33,500์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-24: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณo, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_STAR, NO_PRESENT_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '33,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-1,000์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '32,500์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-25: ์ด๋ฒคํธ ๋ฑ์ง๊ฐ ์ฐํ์ธ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions(BADGE_SANTA);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 2๊ฐ',
+ '์์ด์คํฌ๋ฆผ 5๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '135,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -10,115์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-37,315์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '122,685์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-26: ์ด๋ฒคํธ ๋ฑ์ง๊ฐ ํธ๋ฆฌ์ธ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions(BADGE_TREE);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์์ด์คํฌ๋ฆผ 5๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '25,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -10,115์',
+ '<์ดํํ ๊ธ์ก>',
+ '-12,315์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '12,685์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ 'ํธ๋ฆฌ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-26: ์ด๋ฒคํธ ๋ฑ์ง๊ฐ ๋ณ์ธ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions(BADGE_STAR);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์์ด์คํฌ๋ฆผ 3๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '15,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -6,069์',
+ '<์ดํํ ๊ธ์ก>',
+ '-8,269์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '6,731์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '๋ณ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+}); | JavaScript | ```js
describe('App ๋ค์ํ case์์ ๋์ test', () => {
let app;
beforeEach(() => {
EventRepository.get().forEach((event) => {
event.setAmount(0);
event.setStatus(false);
});
app = new App();
});
test(`case-1: ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด ${SETTING.minimumApplyEventPrice}๋ณด๋ค ์์ ๊ฒฝ์ฐ`, async () => {
const logSpy = getLogSpy();
mockQuestions([CHRISTMAS_WEEKDAY, NO_EVENTS]);
await app.run();
```
`beforeEach`์์ `app`์ ํ ๋นํ๋ฉด์ ํ
์คํธ๋ณ ํฝ์ค์ณ๋ฅผ ํต์ผ ์ํฌ ์ ์์ต๋๋ค! |
@@ -0,0 +1,893 @@
+import { MissionUtils } from '@woowacourse/mission-utils';
+import { EOL as LINE_SEPARATOR } from 'os';
+import App from '../../src/App.js';
+import { SETTING } from '../../src/constant/index.js';
+import { EventRepository } from '../../src/repository/index.js';
+
+const mockQuestions = inputs => {
+ MissionUtils.Console.readLineAsync = jest.fn();
+
+ MissionUtils.Console.readLineAsync.mockImplementation(() => {
+ const input = inputs.shift();
+
+ return Promise.resolve(input);
+ });
+};
+
+const getLogSpy = () => {
+ const logSpy = jest.spyOn(MissionUtils.Console, 'print');
+ logSpy.mockClear();
+
+ return logSpy;
+};
+
+const getOutput = logSpy => {
+ return [...logSpy.mock.calls].join(LINE_SEPARATOR);
+};
+
+const expectLogContains = (received, expectedLogs) => {
+ expectedLogs.forEach(log => {
+ expect(received).toContain(log);
+ });
+};
+
+const CHRISTMAS_WEEKDAY = '13';
+const CHRISTMAS_WEEKEND = '16';
+const CHRISTMAS_STAR = '24';
+const NOCHRISTMAS_WEEKDAY = '27';
+const NOCHRISTMAS_WEEKEND = '30';
+const NOCHRISTMAS_STAR = '31';
+
+const ALL_EVENTS = 'ํฐ๋ณธ์คํ
์ดํฌ-1,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,ํํ์ค-1,์ ๋ก์ฝ๋ผ-2,์ดํ์ธ-1,์ด์ฝ์ผ์ดํฌ-1';
+const NO_EVENTS = '์์ก์ด์ํ-1,์ ๋ก์ฝ๋ผ-1';
+const NO_DESSERT = 'ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,๋ ๋์์ธ-1,์์ ์๋ฌ๋-1';
+const NO_MAIN = '๋ ๋์์ธ-2,์์ ์๋ฌ๋-1,์ด์ฝ์ผ์ดํฌ-1';
+const NO_PRESENT = 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1,ํํ์ค-1';
+const NO_PRESENT_MAIN = '์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1,ํํ์ค-1';
+const NO_PRESENT_DESSERT = 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์ ๋ก์ฝ๋ผ-1,ํํ์ค-1';
+
+const BADGE_SANTA = ['13', 'ํฐ๋ณธ์คํ
์ดํฌ-2,์์ด์คํฌ๋ฆผ-5'];
+const BADGE_TREE = ['13', '์์ด์คํฌ๋ฆผ-5'];
+const BADGE_STAR = ['13', '์์ด์คํฌ๋ฆผ-3'];
+
+describe('App ๋ค์ํ case์์ ๋์ test', () => {
+ beforeEach(() => {
+ EventRepository.get().forEach(event => {
+ event.setAmount(0);
+ event.setStatus(false);
+ });
+ });
+
+ test(`case-1: ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด ${SETTING.minimumApplyEventPrice}๋ณด๋ค ์์ ๊ฒฝ์ฐ`, async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, NO_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์์ก์ด์ํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '9,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ '์์',
+ '<์ดํํ ๊ธ์ก>',
+ '0์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '9,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-2: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณx, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -2,023์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-29,223์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '127,277์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-3: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณx, ์ฃผ๋ง', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKEND, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,500์',
+ '์ฃผ๋ง ํ ์ธ: -4,046์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-31,546์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '124,954์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-4: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณo, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_STAR, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์',
+ 'ํ์ผ ํ ์ธ: -2,023์',
+ 'ํน๋ณ ํ ์ธ: -1,000',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-31,323์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '125,177์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-5: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณx, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKDAY, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํ์ผ ํ ์ธ: -2,023์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-27,023์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '129,477์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-6: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณx, ์ฃผ๋ง', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKEND, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ '์ฃผ๋ง ํ ์ธ: -4,046์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-29,046์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '127,454์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-7: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณo, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_STAR, ALL_EVENTS]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 2๊ฐ',
+ '์ดํ์ธ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '131,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํ์ผ ํ ์ธ: -2,023์',
+ 'ํน๋ณ ํ ์ธ: -1,000',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-28,023์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '128,477์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-8: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณx, ์ฃผ๋ง์ด์ง๋ง ๋ฉ์ธ ๋ฉ๋ด๊ฐ ์์ด ์ฃผ๋ง ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKEND, NO_MAIN]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '๋ ๋์์ธ 2๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '143,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,500์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-27,500์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '140,500์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-9: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณx, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, NO_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํด์ฐ๋ฌผํ์คํ 1๊ฐ',
+ '๋ ๋์์ธ 1๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '158,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-27,200์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '155,800์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-10: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ o, ํน๋ณo, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_STAR, NO_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํด์ฐ๋ฌผํ์คํ 1๊ฐ',
+ '๋ ๋์์ธ 1๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '158,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-29,300์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '153,700์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-11: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณx, ์ฃผ๋ง์ด์ง๋ง ๋ฉ์ธ ๋ฉ๋ด๊ฐ ์์ด ์ฃผ๋ง ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKEND, NO_MAIN]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '๋ ๋์์ธ 2๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '143,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-25,000์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '143,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-12: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณx, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKDAY, NO_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํด์ฐ๋ฌผํ์คํ 1๊ฐ',
+ '๋ ๋์์ธ 1๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '158,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-25,000์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '158,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-13: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ o, ํน๋ณo, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_STAR, NO_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ',
+ 'ํด์ฐ๋ฌผํ์คํ 1๊ฐ',
+ '๋ ๋์์ธ 1๊ฐ',
+ '์์ ์๋ฌ๋ 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '158,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-26,000์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '157,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-14: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณx, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -4,046์',
+ '<์ดํํ ๊ธ์ก>',
+ '-6,246์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '57,254์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '๋ณ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-15: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณx, ์ฃผ๋ง', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKEND, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,500์',
+ '์ฃผ๋ง ํ ์ธ: -2,023์',
+ '<์ดํํ ๊ธ์ก>',
+ '-4,523์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '58,977์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-16: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณo, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_STAR, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์',
+ 'ํ์ผ ํ ์ธ: -4,046์',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-8,346์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '55,154์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '๋ณ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-17: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณx, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKDAY, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํ์ผ ํ ์ธ: -4,046์',
+ '<์ดํํ ๊ธ์ก>',
+ '-4,046์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '59,454์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-18: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณx, ์ฃผ๋ง', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKEND, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ '์ฃผ๋ง ํ ์ธ: -2,023์',
+ '<์ดํํ ๊ธ์ก>',
+ '-2,023์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '61,477์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-19: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณo, ํ์ผ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_STAR, NO_PRESENT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '63,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํ์ผ ํ ์ธ: -4,046์',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-5,046์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '58,454์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '๋ณ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-20: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณx, ์ฃผ๋ง์ด์ง๋ง ๋ฉ์ธ ๋ฉ๋ด๊ฐ ์์ด ์ฃผ๋ง ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKEND, NO_PRESENT_MAIN]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '38,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,500์',
+ '<์ดํํ ๊ธ์ก>',
+ '-2,500์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '36,000์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-21: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณx, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_WEEKDAY, NO_PRESENT_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '33,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ '<์ดํํ ๊ธ์ก>',
+ '-2,200์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '31,300์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-22: ํฌ๋ฆฌ์ค๋ง์คo, ์ฆ์ x, ํน๋ณo, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([CHRISTMAS_STAR, NO_PRESENT_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '33,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-4,300์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '29,200์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-23: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณx, ์ฃผ๋ง์ด์ง๋ง ๋ฉ์ธ ๋ฉ๋ด๊ฐ ์์ด ์ฃผ๋ง ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKEND, NO_PRESENT_MAIN]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์ด์ฝ์ผ์ดํฌ 2๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '38,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ '์์',
+ '<์ดํํ ๊ธ์ก>',
+ '0์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '38,500์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-24: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณx, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_WEEKDAY, NO_PRESENT_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '33,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ '์์',
+ '<์ดํํ ๊ธ์ก>',
+ '0์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '33,500์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-24: ํฌ๋ฆฌ์ค๋ง์คx, ์ฆ์ x, ํน๋ณo, ํ์ผ์ด์ง๋ง ๋์ ํธ ๋ฉ๋ด๊ฐ ์์ด ํ์ผ ํ ์ธ์ด ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions([NOCHRISTMAS_STAR, NO_PRESENT_DESSERT]);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ',
+ '์ ๋ก์ฝ๋ผ 1๊ฐ',
+ 'ํํ์ค 1๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '33,500์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํน๋ณ ํ ์ธ: -1,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-1,000์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '32,500์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์์',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-25: ์ด๋ฒคํธ ๋ฑ์ง๊ฐ ์ฐํ์ธ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions(BADGE_SANTA);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ 'ํฐ๋ณธ์คํ
์ดํฌ 2๊ฐ',
+ '์์ด์คํฌ๋ฆผ 5๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '135,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์ดํ์ธ 1๊ฐ',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -10,115์',
+ '์ฆ์ ์ด๋ฒคํธ: -25,000์',
+ '<์ดํํ ๊ธ์ก>',
+ '-37,315์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '122,685์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '์ฐํ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-26: ์ด๋ฒคํธ ๋ฑ์ง๊ฐ ํธ๋ฆฌ์ธ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions(BADGE_TREE);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์์ด์คํฌ๋ฆผ 5๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '25,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -10,115์',
+ '<์ดํํ ๊ธ์ก>',
+ '-12,315์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '12,685์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ 'ํธ๋ฆฌ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+
+ test('case-26: ์ด๋ฒคํธ ๋ฑ์ง๊ฐ ๋ณ์ธ ๊ฒฝ์ฐ', async () => {
+ const logSpy = getLogSpy();
+ mockQuestions(BADGE_STAR);
+ const app = new App();
+ await app.run();
+
+ const RESULT = [
+ '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ '์์ด์คํฌ๋ฆผ 3๊ฐ',
+ '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ '15,000์',
+ '<์ฆ์ ๋ฉ๋ด>',
+ '์์',
+ '<ํํ ๋ด์ญ>',
+ 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -2,200์',
+ 'ํ์ผ ํ ์ธ: -6,069์',
+ '<์ดํํ ๊ธ์ก>',
+ '-8,269์',
+ '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ '6,731์',
+ '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ '๋ณ',
+ ];
+
+ expectLogContains(getOutput(logSpy), RESULT);
+ });
+}); | JavaScript | ํ๋ผ๋ฏธํฐ ํ
์คํธ๋ฅผ ์ ์ฉ์ํค๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,24 @@
+const PREFIX = '[ERROR]';
+
+const ERROR = Object.freeze({
+ dateType: `${PREFIX} ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuOrderType: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuDuplicated: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuNotExist: `${PREFIX} ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuAmount: `${PREFIX} ํ๋ฒ์ ์ฃผ๋ฌธ ๊ฐ๋ฅํ ๋ฉ๋ด์ ์ต๋ ๊ฐฏ์๋ 20๊ฐ ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+ menuOnlyBeverage: `${PREFIX} ์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`,
+
+ menuName: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ์ด๋ฆ์ด String์ด ์๋๋๋ค.`,
+ menuType: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ menuPrice: `${PREFIX} ์์ฑ๋ ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventType: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ํ์
์ด String์ด ์๋๋๋ค.`,
+ eventStatus: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ์ํ๊ฐ Boolean์ด ์๋๋๋ค.`,
+ eventPrice: `${PREFIX} ์์ฑ๋ ์ด๋ฒคํธ์ ๊ฐ๊ฒฉ์ด Number์ด ์๋๋๋ค.`,
+
+ eventNotExist: `${PREFIX} ์กด์ฌํ์ง ์๋ ์ด๋ฒคํธ ์
๋๋ค.`,
+});
+
+export default ERROR; | JavaScript | ๊ทธ๋ ๊ตฐ์! ์ข์ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค :) |
@@ -0,0 +1,19 @@
+const MENU_LIST = Object.freeze({
+ mushRoomSoup: { name: '์์ก์ด์ํ', type: 'appetizer', price: 6000 },
+ tapas: { name: 'ํํ์ค', type: 'appetizer', price: 5500 },
+ caesarSalad: { name: '์์ ์๋ฌ๋', type: 'appetizer', price: 8000 },
+
+ tBoneSteak: { name: 'ํฐ๋ณธ์คํ
์ดํฌ', type: 'main', price: 55000 },
+ barbecueRibs: { name: '๋ฐ๋นํ๋ฆฝ', type: 'main', price: 54000 },
+ seafoodPasta: { name: 'ํด์ฐ๋ฌผํ์คํ', type: 'main', price: 35000 },
+ christmasPasta: { name: 'ํฌ๋ฆฌ์ค๋ง์คํ์คํ', type: 'main', price: 25000 },
+
+ chocolateCake: { name: '์ด์ฝ์ผ์ดํฌ', type: 'dessert', price: 15000 },
+ iceCream: { name: '์์ด์คํฌ๋ฆผ', type: 'dessert', price: 5000 },
+
+ cokeZero: { name: '์ ๋ก์ฝ๋ผ', type: 'beverage', price: 3000 },
+ redWine: { name: '๋ ๋์์ธ', type: 'beverage', price: 60000 },
+ champagne: { name: '์ดํ์ธ', type: 'beverage', price: 25000 },
+});
+
+export default MENU_LIST; | JavaScript | ์ค ์ด๋ ๊ฒ๋ ์์ฑํ ์ ์๊ตฐ์! ์ข์ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค :) |
@@ -0,0 +1,33 @@
+const SETTING = Object.freeze({
+ date: {
+ minimun: 1,
+ maximum: 31,
+ christmas: 25,
+ friday: 1,
+ saturday: 2,
+ sunday: 3,
+ },
+ weekDays: 7,
+
+ locale: 'ko-KR',
+ menuSplit: ',',
+ menuAmountSplit: '-',
+
+ maximumMenusAmount: 20,
+ minimumApplyEventPrice: 10000,
+
+ christmasDiscount: { default: -1000, forDay: -100 },
+ weekDiscount: -2023,
+ specialDiscount: -1000,
+
+ minimumPresentPrice: 120000,
+ presentMenu: '์ดํ์ธ',
+
+ minimumAmountBadge: {
+ santa: -20000,
+ tree: -10000,
+ star: -5000,
+ },
+});
+
+export default SETTING; | JavaScript | ์
๊ทธ๋ ๋ค์! ์ ํ ์ธ์งํ์ง ๋ชปํ๊ณ ์์์ต๋๋ค ใ
ใ
๋ฐ๋ก ์ค์นํ์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค!!! |
@@ -0,0 +1,87 @@
+import { SETTING } from '../constant/index.js';
+import { MenuRepository } from '../repository/index.js';
+import {
+ MenuAmountError,
+ MenuOnlyBeverageError,
+} from '../error/CustomError.js';
+
+export default class Menus {
+ #menus;
+
+ constructor(menus) {
+ this.#menus = new Map();
+
+ Object.keys(menus).forEach(key => {
+ this.#menus.set(MenuRepository.getMenuByName(key), menus[key]);
+ });
+
+ this.#validateAmounts();
+ this.#validateOnlyBeverage();
+ }
+
+ #validateAmounts() {
+ let amount = 0;
+ this.#menus.forEach(value => {
+ amount += value;
+ });
+
+ if (amount > SETTING.maximumMenusAmount) {
+ throw new MenuAmountError();
+ }
+ }
+
+ #validateOnlyBeverage() {
+ if (this.#onlyBeverage()) {
+ throw new MenuOnlyBeverageError();
+ }
+ }
+
+ list() {
+ const string = [];
+
+ this.#menus.forEach((value, key) => {
+ string.push(`${key.get().name} ${value}๊ฐ`);
+ });
+
+ return string;
+ }
+
+ previousPrice() {
+ let price = 0;
+ this.#menus.forEach((value, key) => {
+ price += key.get().price * value;
+ });
+
+ return price;
+ }
+
+ canApplyEvent() {
+ if (this.previousPrice() > SETTING.minimumApplyEventPrice) {
+ return true;
+ }
+ return false;
+ }
+
+ #onlyBeverage() {
+ let notBeverage = 0;
+ this.#menus.forEach((value, key) => {
+ if (key.get().type !== 'beverage') {
+ notBeverage += value;
+ }
+ });
+
+ if (notBeverage === 0) {
+ return true;
+ }
+ return false;
+ }
+
+ types() {
+ const types = { appetizer: 0, main: 0, beverage: 0, dessert: 0 };
+ this.#menus.forEach((value, key) => {
+ types[key.get().type] += value;
+ });
+
+ return types;
+ }
+} | JavaScript | `Events`์๊ฒ ์์ํ๋ ๊ฒ์ด ์กฐ๊ธ ๋ ํต์ผ์ฑ์ด ์์ ๊ฒ ๊ฐ๋ค์ :) |
@@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
import 'package:mutyne/constants/styles.dart';
import 'package:mutyne/common/widgets/global_safe_area.dart';
+import 'package:mutyne/features/authentication/views/password_screen.dart';
class LoginScreen extends StatefulWidget {
static String routeName = "login";
@@ -40,96 +41,92 @@ class _LoginScreenState extends State<LoginScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SizedBox(
- width: MediaQuery.of(context).size.width,
+ width: double.infinity,
child: Column(
children: <Widget>[
const Text(
'๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 26.0,
+ fontSize: Sizes.size24 + Sizes.size2,
fontWeight: FontWeight.w700,
),
),
- const SizedBox(
- height: 30.0,
- ),
+ Gaps.v28,
+ Gaps.v2,
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '์ด๋ฉ์ผ',
- hintStyle: TextStyle(
- fontSize: 13.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size14 - Sizes.size1,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 8.0,
- ),
+ Gaps.v8,
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '๋น๋ฐ๋ฒํธ',
- hintStyle: TextStyle(
- fontSize: 13.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size12 + Sizes.size1,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 24.0,
- ),
+ Gaps.v24,
TextButton(
onPressed: () {
print('button login is clicked');
},
style: TextButton.styleFrom(
- backgroundColor: const Color(0xFFE5E5E5),
+ backgroundColor: BaseColors.black[10],
fixedSize: const Size(370, 54),
shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(5.0),
+ borderRadius:
+ BorderRadius.circular(Sizes.size5),
),
),
child: const Text(
'๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 16.0,
+ fontSize: Sizes.size16,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
- const SizedBox(height: 24.0),
+ Gaps.v24,
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
@@ -140,27 +137,28 @@ class _LoginScreenState extends State<LoginScreen> {
// builder: (BuildContext context) {
// return const PasswordScreen();
// }));
- context.push('/password');
+ context.pushNamed(PasswordScreen.routeName);
+ // context.goNamed('password');
},
- child: const Text(
+ child: Text(
'๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
GestureDetector(
onTap: () {
print('button join is clicked');
},
- child: const Text(
+ child: Text(
'๊ฐ์
ํ๊ธฐ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
@@ -176,18 +174,16 @@ class _LoginScreenState extends State<LoginScreen> {
onTap: () {
print('button join is clicked');
},
- child: const Text(
+ child: Text(
'๊ฐํธ ๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
- const SizedBox(
- height: 16.0,
- ),
+ Gaps.v16,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@@ -206,15 +202,13 @@ class _LoginScreenState extends State<LoginScreen> {
child: const Text(
'K',
style: TextStyle(
- fontSize: 24.0,
+ fontSize: Sizes.size24,
fontWeight: FontWeight.w700,
color: Colors.black87,
),
),
),
- const SizedBox(
- width: 25.0,
- ),
+ Gaps.h24,
TextButton(
onPressed: () {
print('button A is clicked');
@@ -230,7 +224,7 @@ class _LoginScreenState extends State<LoginScreen> {
child: const Text(
'A',
style: TextStyle(
- fontSize: 24.0,
+ fontSize: Sizes.size24,
fontWeight: FontWeight.w700,
color: Colors.black87,
), | Unknown | Sizes.size14 - Sizes.size1๋ก ๋ณ๊ฒฝ์ด ํ์ํด๋ณด์ฌ์ |
@@ -6,7 +6,7 @@ import 'package:mutyne/common/widgets/global_safe_area.dart';
class PasswordScreen extends StatefulWidget {
static String routeName = "password";
- static String routeURL = "/password";
+ static String routeURL = ":password";
const PasswordScreen({super.key});
@@ -15,7 +15,7 @@ class PasswordScreen extends StatefulWidget {
}
void _onNavigateBack(BuildContext context) {
- context.goNamed('login'); // ์์ ํ์
+ context.pop();
}
class _PasswordScreenState extends State<PasswordScreen> {
@@ -41,77 +41,70 @@ class _PasswordScreenState extends State<PasswordScreen> {
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
- children: const <Widget>[
+ children: [
Text(
'๋น๋ฐ๋ฒํธ ์ฌ์ค์ ์๋ด\n๋ฉ์ผ์ ๋ณด๋ด๋๋ฆฝ๋๋ค.',
style: TextStyle(
- fontSize: 22.0,
+ fontSize: Sizes.size20 + Sizes.size2,
fontWeight: FontWeight.w700,
- color: Color.fromRGBO(24, 24, 24, 1),
+ color: BaseColors.black[10],
),
),
Text(
'๊ฐ์
ํ์ ์ ํํ ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color.fromRGBO(24, 24, 24, 1),
+ color: BaseColors.black[10],
),
),
],
),
),
- const SizedBox(
- height: 34,
- ),
+ Row(children: const [Gaps.v32, Gaps.v2]),
Column(
- children: <Widget>[
+ children: [
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '์ด๋ฉ์ผ',
- hintStyle: TextStyle(
- fontSize: 14.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color.fromRGBO(212, 212, 212,
- 1), // TODO: ์ด๊ฑฐ color code ๋ก ๋ฐ๋ก ๋ฃ๋ ๋ฒ ์์? #D4D4D4 ์ด๋ฐ ๊ฑฐ
+ color: BaseColors.black[3]!, // ๋ชป์ฐพ๋ค...
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color.fromRGBO(212, 212, 212, 1),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 16,
- ),
+ Gaps.v16,
TextButton(
onPressed: () {
- print('button login is clicked');
+ print('button email is clicked');
},
style: TextButton.styleFrom(
- backgroundColor:
- const Color.fromRGBO(229, 229, 229, 1),
- fixedSize:
- Size(MediaQuery.of(context).size.width, 55),
+ backgroundColor: BaseColors.black[10],
+ fixedSize: const Size(double.infinity, Sizes.size52),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
child: const Text(
'์ด๋ฉ์ผ ๋ฐ์ก',
style: TextStyle(
- fontSize: 16.0,
+ fontSize: Sizes.size16,
fontWeight: FontWeight.w600,
color: Colors.white,
), | Unknown | 2px์ด ์ฐจ์ด๊ฐ ๋๋๋ฐ ์ด๋ ๊ฒ ํ๋ฉด ๋์ค์ Layout์ด ํ์ด์ง ์ ์์ด์. ๋ณ๊ฑฐ ์๋๊ฑฐ๊ฐ์ง๋ง 1px๋ ๋งค์ฐ ์ ์คํ ํด์ผ๋์
`Row(children:[Gaps.v32 + Gaps.v2])` ์ด๋ฐ์์ผ๋ก ํ๋๊ฒ ๋ ์ข์๊ฑฐ๊ฐ์์ |
@@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
import 'package:mutyne/constants/styles.dart';
import 'package:mutyne/common/widgets/global_safe_area.dart';
+import 'package:mutyne/features/authentication/views/password_screen.dart';
class LoginScreen extends StatefulWidget {
static String routeName = "login";
@@ -40,96 +41,92 @@ class _LoginScreenState extends State<LoginScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SizedBox(
- width: MediaQuery.of(context).size.width,
+ width: double.infinity,
child: Column(
children: <Widget>[
const Text(
'๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 26.0,
+ fontSize: Sizes.size24 + Sizes.size2,
fontWeight: FontWeight.w700,
),
),
- const SizedBox(
- height: 30.0,
- ),
+ Gaps.v28,
+ Gaps.v2,
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '์ด๋ฉ์ผ',
- hintStyle: TextStyle(
- fontSize: 13.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size14 - Sizes.size1,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 8.0,
- ),
+ Gaps.v8,
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '๋น๋ฐ๋ฒํธ',
- hintStyle: TextStyle(
- fontSize: 13.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size12 + Sizes.size1,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 24.0,
- ),
+ Gaps.v24,
TextButton(
onPressed: () {
print('button login is clicked');
},
style: TextButton.styleFrom(
- backgroundColor: const Color(0xFFE5E5E5),
+ backgroundColor: BaseColors.black[10],
fixedSize: const Size(370, 54),
shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(5.0),
+ borderRadius:
+ BorderRadius.circular(Sizes.size5),
),
),
child: const Text(
'๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 16.0,
+ fontSize: Sizes.size16,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
- const SizedBox(height: 24.0),
+ Gaps.v24,
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
@@ -140,27 +137,28 @@ class _LoginScreenState extends State<LoginScreen> {
// builder: (BuildContext context) {
// return const PasswordScreen();
// }));
- context.push('/password');
+ context.pushNamed(PasswordScreen.routeName);
+ // context.goNamed('password');
},
- child: const Text(
+ child: Text(
'๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
GestureDetector(
onTap: () {
print('button join is clicked');
},
- child: const Text(
+ child: Text(
'๊ฐ์
ํ๊ธฐ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
@@ -176,18 +174,16 @@ class _LoginScreenState extends State<LoginScreen> {
onTap: () {
print('button join is clicked');
},
- child: const Text(
+ child: Text(
'๊ฐํธ ๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
- const SizedBox(
- height: 16.0,
- ),
+ Gaps.v16,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@@ -206,15 +202,13 @@ class _LoginScreenState extends State<LoginScreen> {
child: const Text(
'K',
style: TextStyle(
- fontSize: 24.0,
+ fontSize: Sizes.size24,
fontWeight: FontWeight.w700,
color: Colors.black87,
),
),
),
- const SizedBox(
- width: 25.0,
- ),
+ Gaps.h24,
TextButton(
onPressed: () {
print('button A is clicked');
@@ -230,7 +224,7 @@ class _LoginScreenState extends State<LoginScreen> {
child: const Text(
'A',
style: TextStyle(
- fontSize: 24.0,
+ fontSize: Sizes.size24,
fontWeight: FontWeight.w700,
color: Colors.black87,
), | Unknown | 'password'๋ผ๋ ๋ฌธ์ ํ์
๋ณด๋จ
```
import PasswordScreen
PasswordScreen.routeName
```
์ด๋ ๊ฒ ๋ฐ๊ฟ์ฃผ๋๊ฒ ์ถํ์ ํ ๊ณณ์์๋ง ์์ ํ๋ฉด ๋์ ๋ ์ข์๊ฑฐ๊ฐ์์ |
@@ -6,7 +6,7 @@ import 'package:mutyne/common/widgets/global_safe_area.dart';
class PasswordScreen extends StatefulWidget {
static String routeName = "password";
- static String routeURL = "/password";
+ static String routeURL = ":password";
const PasswordScreen({super.key});
@@ -15,7 +15,7 @@ class PasswordScreen extends StatefulWidget {
}
void _onNavigateBack(BuildContext context) {
- context.goNamed('login'); // ์์ ํ์
+ context.pop();
}
class _PasswordScreenState extends State<PasswordScreen> {
@@ -41,77 +41,70 @@ class _PasswordScreenState extends State<PasswordScreen> {
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
- children: const <Widget>[
+ children: [
Text(
'๋น๋ฐ๋ฒํธ ์ฌ์ค์ ์๋ด\n๋ฉ์ผ์ ๋ณด๋ด๋๋ฆฝ๋๋ค.',
style: TextStyle(
- fontSize: 22.0,
+ fontSize: Sizes.size20 + Sizes.size2,
fontWeight: FontWeight.w700,
- color: Color.fromRGBO(24, 24, 24, 1),
+ color: BaseColors.black[10],
),
),
Text(
'๊ฐ์
ํ์ ์ ํํ ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color.fromRGBO(24, 24, 24, 1),
+ color: BaseColors.black[10],
),
),
],
),
),
- const SizedBox(
- height: 34,
- ),
+ Row(children: const [Gaps.v32, Gaps.v2]),
Column(
- children: <Widget>[
+ children: [
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '์ด๋ฉ์ผ',
- hintStyle: TextStyle(
- fontSize: 14.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color.fromRGBO(212, 212, 212,
- 1), // TODO: ์ด๊ฑฐ color code ๋ก ๋ฐ๋ก ๋ฃ๋ ๋ฒ ์์? #D4D4D4 ์ด๋ฐ ๊ฑฐ
+ color: BaseColors.black[3]!, // ๋ชป์ฐพ๋ค...
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color.fromRGBO(212, 212, 212, 1),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 16,
- ),
+ Gaps.v16,
TextButton(
onPressed: () {
- print('button login is clicked');
+ print('button email is clicked');
},
style: TextButton.styleFrom(
- backgroundColor:
- const Color.fromRGBO(229, 229, 229, 1),
- fixedSize:
- Size(MediaQuery.of(context).size.width, 55),
+ backgroundColor: BaseColors.black[10],
+ fixedSize: const Size(double.infinity, Sizes.size52),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
child: const Text(
'์ด๋ฉ์ผ ๋ฐ์ก',
style: TextStyle(
- fontSize: 16.0,
+ fontSize: Sizes.size16,
fontWeight: FontWeight.w600,
color: Colors.white,
), | Unknown | ์ด๋ ๊ฒ ํ๊ฒ๋๋ฉด routeName๊ณผ routeURL์ด ์ฐจ์ด๊ฐ ์๋๊ฑฐ๊ฐ์์
์๋ธ ๋ผ์ฐํฐ ๊ด๋ จ `/`์๋ฌ ๋๋ฌธ์ด์๋ค๋ฉด ๋น์ฅ ์๋ฌ๋ง ํด๊ฒฐ ํ๋ ค๊ณ ๋ง ํ์ ๊ฑฐ๊ฐ์์ ใ
```
static const String routeName = "chatDetail";
static const String routeURL = ":chatId";
```
์ด์ ๊ฐ์ด ์๋ธ ๋ผ์ฐํฐ์์ `:`๋ฅผ ๋ถ์ฌ์ค๋ค๋๊ฑธ ์์์ผ ๋์ค์ ์์ธ ํ์ด์ง id๊ฐ๋ ๊ตฌํํ ์ ์์ด์์ |
@@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
import 'package:mutyne/constants/styles.dart';
import 'package:mutyne/common/widgets/global_safe_area.dart';
+import 'package:mutyne/features/authentication/views/password_screen.dart';
class LoginScreen extends StatefulWidget {
static String routeName = "login";
@@ -40,96 +41,92 @@ class _LoginScreenState extends State<LoginScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SizedBox(
- width: MediaQuery.of(context).size.width,
+ width: double.infinity,
child: Column(
children: <Widget>[
const Text(
'๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 26.0,
+ fontSize: Sizes.size24 + Sizes.size2,
fontWeight: FontWeight.w700,
),
),
- const SizedBox(
- height: 30.0,
- ),
+ Gaps.v28,
+ Gaps.v2,
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '์ด๋ฉ์ผ',
- hintStyle: TextStyle(
- fontSize: 13.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size14 - Sizes.size1,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 8.0,
- ),
+ Gaps.v8,
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '๋น๋ฐ๋ฒํธ',
- hintStyle: TextStyle(
- fontSize: 13.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size12 + Sizes.size1,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 24.0,
- ),
+ Gaps.v24,
TextButton(
onPressed: () {
print('button login is clicked');
},
style: TextButton.styleFrom(
- backgroundColor: const Color(0xFFE5E5E5),
+ backgroundColor: BaseColors.black[10],
fixedSize: const Size(370, 54),
shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(5.0),
+ borderRadius:
+ BorderRadius.circular(Sizes.size5),
),
),
child: const Text(
'๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 16.0,
+ fontSize: Sizes.size16,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
- const SizedBox(height: 24.0),
+ Gaps.v24,
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
@@ -140,27 +137,28 @@ class _LoginScreenState extends State<LoginScreen> {
// builder: (BuildContext context) {
// return const PasswordScreen();
// }));
- context.push('/password');
+ context.pushNamed(PasswordScreen.routeName);
+ // context.goNamed('password');
},
- child: const Text(
+ child: Text(
'๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
GestureDetector(
onTap: () {
print('button join is clicked');
},
- child: const Text(
+ child: Text(
'๊ฐ์
ํ๊ธฐ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
@@ -176,18 +174,16 @@ class _LoginScreenState extends State<LoginScreen> {
onTap: () {
print('button join is clicked');
},
- child: const Text(
+ child: Text(
'๊ฐํธ ๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
- const SizedBox(
- height: 16.0,
- ),
+ Gaps.v16,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@@ -206,15 +202,13 @@ class _LoginScreenState extends State<LoginScreen> {
child: const Text(
'K',
style: TextStyle(
- fontSize: 24.0,
+ fontSize: Sizes.size24,
fontWeight: FontWeight.w700,
color: Colors.black87,
),
),
),
- const SizedBox(
- width: 25.0,
- ),
+ Gaps.h24,
TextButton(
onPressed: () {
print('button A is clicked');
@@ -230,7 +224,7 @@ class _LoginScreenState extends State<LoginScreen> {
child: const Text(
'A',
style: TextStyle(
- fontSize: 24.0,
+ fontSize: Sizes.size24,
fontWeight: FontWeight.w700,
color: Colors.black87,
), | Unknown | ์ฌ๊ธฐ๋ ์์ ์ด ํ์ํ ๊ฑฐ๊ฐ์์ |
@@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
import 'package:mutyne/constants/styles.dart';
import 'package:mutyne/common/widgets/global_safe_area.dart';
+import 'package:mutyne/features/authentication/views/password_screen.dart';
class LoginScreen extends StatefulWidget {
static String routeName = "login";
@@ -40,96 +41,92 @@ class _LoginScreenState extends State<LoginScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SizedBox(
- width: MediaQuery.of(context).size.width,
+ width: double.infinity,
child: Column(
children: <Widget>[
const Text(
'๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 26.0,
+ fontSize: Sizes.size24 + Sizes.size2,
fontWeight: FontWeight.w700,
),
),
- const SizedBox(
- height: 30.0,
- ),
+ Gaps.v28,
+ Gaps.v2,
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '์ด๋ฉ์ผ',
- hintStyle: TextStyle(
- fontSize: 13.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size14 - Sizes.size1,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 8.0,
- ),
+ Gaps.v8,
TextFormField(
- decoration: const InputDecoration(
+ decoration: InputDecoration(
hintText: '๋น๋ฐ๋ฒํธ',
- hintStyle: TextStyle(
- fontSize: 13.0,
+ hintStyle: const TextStyle(
+ fontSize: Sizes.size12 + Sizes.size1,
fontWeight: FontWeight.w400,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: Color(0xFFD4D4D4),
+ color: BaseColors.black[3]!,
),
- borderRadius: BorderRadius.all(
- Radius.circular(12.0),
+ borderRadius: const BorderRadius.all(
+ Radius.circular(Sizes.size12),
),
),
),
),
- const SizedBox(
- height: 24.0,
- ),
+ Gaps.v24,
TextButton(
onPressed: () {
print('button login is clicked');
},
style: TextButton.styleFrom(
- backgroundColor: const Color(0xFFE5E5E5),
+ backgroundColor: BaseColors.black[10],
fixedSize: const Size(370, 54),
shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(5.0),
+ borderRadius:
+ BorderRadius.circular(Sizes.size5),
),
),
child: const Text(
'๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 16.0,
+ fontSize: Sizes.size16,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
- const SizedBox(height: 24.0),
+ Gaps.v24,
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
@@ -140,27 +137,28 @@ class _LoginScreenState extends State<LoginScreen> {
// builder: (BuildContext context) {
// return const PasswordScreen();
// }));
- context.push('/password');
+ context.pushNamed(PasswordScreen.routeName);
+ // context.goNamed('password');
},
- child: const Text(
+ child: Text(
'๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
GestureDetector(
onTap: () {
print('button join is clicked');
},
- child: const Text(
+ child: Text(
'๊ฐ์
ํ๊ธฐ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
@@ -176,18 +174,16 @@ class _LoginScreenState extends State<LoginScreen> {
onTap: () {
print('button join is clicked');
},
- child: const Text(
+ child: Text(
'๊ฐํธ ๋ก๊ทธ์ธ',
style: TextStyle(
- fontSize: 14.0,
+ fontSize: Sizes.size14,
fontWeight: FontWeight.w400,
- color: Color(0xFF616161),
+ color: BaseColors.black[8],
),
),
),
- const SizedBox(
- height: 16.0,
- ),
+ Gaps.v16,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@@ -206,15 +202,13 @@ class _LoginScreenState extends State<LoginScreen> {
child: const Text(
'K',
style: TextStyle(
- fontSize: 24.0,
+ fontSize: Sizes.size24,
fontWeight: FontWeight.w700,
color: Colors.black87,
),
),
),
- const SizedBox(
- width: 25.0,
- ),
+ Gaps.h24,
TextButton(
onPressed: () {
print('button A is clicked');
@@ -230,7 +224,7 @@ class _LoginScreenState extends State<LoginScreen> {
child: const Text(
'A',
style: TextStyle(
- fontSize: 24.0,
+ fontSize: Sizes.size24,
fontWeight: FontWeight.w700,
color: Colors.black87,
), | Unknown | `fontSize`์ ๊ฒฝ์ฐ๋ ๊ฐ๊ธ์ ์ด๋ฉด ๊ณตํต theme์์ ๊ด๋ฆฌํ๋ฉด ์ข์๊ฑฐ๊ฐ์์ |
@@ -0,0 +1,12 @@
+package christmas.message;
+
+public class ExceptionMessage {
+ public static final String ERROR_PREFIX = "[ERROR] ";
+ public static final String INVALID_DATE = "์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ public static final String INVALID_ORDER = "์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ public static final String INVALID_MONEY = "์ ํจํ์ง ์์ ๊ธ์ก์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+
+ private ExceptionMessage() {
+ // ๋ถํ์ํ ์ธ์คํด์คํ ๋ฐฉ์ง
+ }
+} | Java | ์์ ๊ด๋ฆฌ๋ฅผ ์ํด์ ์ง๊ธ๊ณผ ๊ฐ์ด ์์ ํด๋์ค๋ฅผ ์ฌ์ฉํ์ค ๊ฒฝ์ฐ ํด๋น ์ฝ๋์ ๊ฐ์ด ์ธ์คํด์คํ๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด ์์ฑ์๋ฅผ ์จ๊ธฐ๋ ๊ฒ์ ์ ๋ง ์ข์ ์ ๊ทผ์ด๋ผ๊ณ ์๊ฐํด์!
๊ฐ์ ๊ด์ ์์, ์ ๋ 4์ฃผ์ฐจ ๊ณผ์ ์์ ์์ ํด๋์ค๋ฅผ ์ธํฐํ์ด์ค๋ก ์ฌ์ฉํ๋๋ฐ์.
์ธํฐํ์ด์ค๋
1. ๊ฐ์ฒด ์์ฑ์ด ๋ถ๊ฐ๋ฅํ๊ณ
2. ๋ด๋ถ์ ์ผ๋ก ์์์ ์ถ์ ๋ฉ์๋๋ง ๊ฐ์ง ์ ์๊ณ ,
3. ์์ ์ ์ธ์ `public static final`์ ์๋ตํ ์ ์๊ธฐ์
์์ ํด๋์ค๋ก ์ฌ์ฉํ๊ธฐ์ ์ ์ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค!
์ธํฐํ์ด์ค๋ ํ๋ฒ ๊ณ ๋ คํด ๋ณด์ธ์ :)
+) ์ธํฐํ์ด์ค๋ฅผ implementsํ์ฌ ์์ ๊ฐ์ ๊ฐ์ง๊ณ ์ค๋ ๊ฒ์ ์ผ์ข
์ ์ํฐํจํด์ด๋ผ๊ณ ํ๋ ํ๋ฒ์ฏค ์ฐพ์ ๋ณด์๋ ๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!! |
@@ -0,0 +1,35 @@
+package christmas.domain;
+
+import christmas.message.ExceptionMessage;
+
+public record Money(int amount) {
+ public Money {
+ validateAmount(amount);
+ }
+
+ private void validateAmount(int amount) {
+ if (amount < 0) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_MONEY);
+ }
+ }
+
+ public static Money sum(Money money1, Money money2) {
+ return new Money(money1.amount + money2.amount);
+ }
+
+ public boolean isMoreOrEqualThan(Money source) {
+ return amount >= source.amount;
+ }
+
+ public Money minus(Money money) {
+ return new Money(amount - money.amount);
+ }
+
+ public Money multiply(int count) {
+ return new Money(amount * count);
+ }
+
+ public boolean isZero() {
+ return amount == 0;
+ }
+} | Java | ๋๊ณผ ๊ด๋ จ๋ ์ ๋ณด๋ฅผ ๋ํํด์ ๊ฒ์ฆ๋ ๊ฐ๋ง ๊ฐ์ง๋๋ก ๊ตฌํํ์ ๊ฑฐ ๋๋ฌด ์ข์๋ฐ์ ๐
๋ถ๋ณ ๊ฐ์ฒด๋ก ๋ง๋ ๊ฒ๋ ์ข์ต๋๋ค! ๋ฉ๋ด ๊ฐ๊ฒฉ์์ `final Money` ๋ณ์๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ์ธ๋ถ์์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ด ๋ณ๊ฒฝ๋ ์ผ๋ ์์ด ์ข๊ฒ ์ด์ |
@@ -0,0 +1,33 @@
+package christmas.domain;
+
+public enum EventBadge {
+ SANTA("์ฐํ", new Money( 20000)),
+ TREE("ํธ๋ฆฌ", new Money( 10000)),
+ STAR("๋ณ", new Money(5000)),
+ NONE("์์", new Money(0));
+
+ private final String name;
+ private final Money price;
+
+ EventBadge(String name, Money price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public static EventBadge findByTotalDiscountPrice(Money totalDiscountMoney) {
+ if (totalDiscountMoney.isMoreOrEqualThan(SANTA.price)) {
+ return SANTA;
+ }
+ if (totalDiscountMoney.isMoreOrEqualThan(TREE.price)) {
+ return TREE;
+ }
+ if (totalDiscountMoney.isMoreOrEqualThan(STAR.price)) {
+ return STAR;
+ }
+ return NONE;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ์ด ๋ถ๋ถ์์ ์ ๊ฐ 3์ฃผ์ฐจ๋ ๋ฐ์๋ ํผ๋๋ฐฑ์ ๊ณต์ ํด ๋๋ฆด๊ฒ์!
์ปค๋ฎค๋ํฐ์์ _ ๋๋ค์์ผ๋ก ํ๋ํ์๋ ์ต์นํธ๋ ํผ๋๋ฐฑ์
๋๋ค.
>enum์ boolean, int ๋ฑ์ flag๋ฅผ ์ข ๋ ๋ช
์์ ์ธ ์ํ๋ก ํํํ๋ ์ฉ๋๋ก ๋ง์ด ์ฌ์ฉ๋๊ณ ,
>
>๊ด๋ก์ ์ผ๋ก enum constant ์ค ์ ํจํ์ง ์์ ์ํ, ์์์ ๋ํ๋ด๋ ์์๋ฅผ ๋งจ ์์ ๋๋ ๊ฒ์ด ๊ถ์ฅ๋ฉ๋๋ค.
>
>์ ํจํ์ง ์์ ์ํ๋ 1๊ฐ์ธ ๊ฒฝ์ฐ๊ฐ ๋ง์๋ฐ, ์ํ๊ฐ ๋ง์์ง ๊ฒฝ์ฐ ์ ํจํ์ง ์์ ์ํ๋ฅผ ํญ์ ๋งจ ์์ ๋๋ฉด ์ํ๊ฐ ์๋ฌด๋ฆฌ ๋ง์๋ ์ฐพ๋๋ฐ ์ด๋ ค์์ด ์๊ธฐ ๋๋ฌธ์
๋๋ค.
์์ ๊ฐ์ ์ด์ ๋ก `NONE`์ ์์น๋ฅผ ๊ฐ์ฅ ์์ ์์น์ํค๋ ๊ฒ์ ๊ณ ๋ คํด ๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,14 @@
+package christmas.domain.menu;
+
+public enum FoodType {
+ APPETIZER("์ ํผํ์ด์ "),
+ DESSERT("๋์ ํธ"),
+ MAIN_COURSE("๋ฉ์ธ"),
+ DRINK("์๋ฃ");
+
+ private final String name;
+
+ FoodType(String name) {
+ this.name = name;
+ }
+} | Java | ํด๋น `enum`์์ ์ด๋ฆ ์ ๋ณด๋ฅผ ์ ์ฅํ์ ๊ฒ์ ํ์ฅ์ฑ์ ๊ณ ๋ คํ ๊ฒ์ธ๊ฐ์?
๋ฉ๋ดํ์ ์ถ๋ ฅํด ๋ฌ๋ผ๋ ์๊ตฌ์ฌํญ์ด ์๊ธฐ๋ ๋ฑ์ ๋ณํ์๋ ๋์ฒํ๊ธฐ ์ข์ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,48 @@
+package christmas.domain.menu;
+
+import christmas.domain.Money;
+import java.util.Arrays;
+
+public enum Menu {
+ MUSHROOM_CREAM_SOUP("์์ก์ด์ํ", FoodType.APPETIZER, new Money(6000)),
+ TAPAS("ํํ์ค", FoodType.APPETIZER, new Money(5500)),
+ CAESAR_SALAD("์์ ์๋ฌ๋", FoodType.APPETIZER, new Money(8000)),
+ T_BORN_STAKE("ํฐ๋ณธ์คํ
์ดํฌ", FoodType.MAIN_COURSE, new Money(55000)),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", FoodType.MAIN_COURSE, new Money(54000)),
+ SEA_FOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", FoodType.MAIN_COURSE, new Money(35000)),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", FoodType.MAIN_COURSE, new Money(25000)),
+ CHOCO_CAKE("์ด์ฝ์ผ์ดํฌ", FoodType.DESSERT, new Money(15000)),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", FoodType.DESSERT, new Money(5000)),
+ ZERO_COKE("์ ๋ก์ฝ๋ผ", FoodType.DRINK, new Money(3000)),
+ RED_WINE("๋ ๋์์ธ", FoodType.DRINK, new Money(60000)),
+ CHAMPAGNE("์ดํ์ธ", FoodType.DRINK, new Money(25000))
+ ;
+ private final String name;
+ private final FoodType foodType;
+ private final Money price;
+
+ Menu(String name, FoodType foodType, Money price) {
+ this.name = name;
+ this.foodType = foodType;
+ this.price = price;
+ }
+
+ public static Menu findByName(String name) {
+ return Arrays.stream(values())
+ .filter(menu -> menu.name.equals(name))
+ .findFirst()
+ .orElse(null);
+ }
+
+ public boolean isSameType(FoodType foodType) {
+ return this.foodType == foodType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Money getPrice() {
+ return price;
+ }
+} | Java | ์ -๋ง ์ฌ์ํ ๋ถ๋ถ์ด์ง๋ง, ์ด์ ๊ฐ์ด ๊ฐ์ `enum`์์ ๋ค์ ์ธ๋ถ ์นดํ
๊ณ ๋ฆฌ๋ก ๊ตฌ๋ถ์ด ๋๋ ๊ฒฝ์ฐ์๋ ๊ฐํ์ ๋ฃ์ด ๊ตฌ๋ถ์ ํด ์ฃผ๋ ๊ฒ๋ ๊ฐ๋
์ฑ์ ์ํ ์ข์ ์ต๊ด์ด๋ผ ์๊ฐํด์!
```suggestion
CAESAR_SALAD("์์ ์๋ฌ๋", FoodType.APPETIZER, new Money(8000)),
T_BORN_STAKE("ํฐ๋ณธ์คํ
์ดํฌ", FoodType.MAIN_COURSE, new Money(55000)),
``` |
@@ -0,0 +1,48 @@
+package christmas.domain.menu;
+
+import christmas.domain.Money;
+import java.util.Arrays;
+
+public enum Menu {
+ MUSHROOM_CREAM_SOUP("์์ก์ด์ํ", FoodType.APPETIZER, new Money(6000)),
+ TAPAS("ํํ์ค", FoodType.APPETIZER, new Money(5500)),
+ CAESAR_SALAD("์์ ์๋ฌ๋", FoodType.APPETIZER, new Money(8000)),
+ T_BORN_STAKE("ํฐ๋ณธ์คํ
์ดํฌ", FoodType.MAIN_COURSE, new Money(55000)),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", FoodType.MAIN_COURSE, new Money(54000)),
+ SEA_FOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", FoodType.MAIN_COURSE, new Money(35000)),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", FoodType.MAIN_COURSE, new Money(25000)),
+ CHOCO_CAKE("์ด์ฝ์ผ์ดํฌ", FoodType.DESSERT, new Money(15000)),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", FoodType.DESSERT, new Money(5000)),
+ ZERO_COKE("์ ๋ก์ฝ๋ผ", FoodType.DRINK, new Money(3000)),
+ RED_WINE("๋ ๋์์ธ", FoodType.DRINK, new Money(60000)),
+ CHAMPAGNE("์ดํ์ธ", FoodType.DRINK, new Money(25000))
+ ;
+ private final String name;
+ private final FoodType foodType;
+ private final Money price;
+
+ Menu(String name, FoodType foodType, Money price) {
+ this.name = name;
+ this.foodType = foodType;
+ this.price = price;
+ }
+
+ public static Menu findByName(String name) {
+ return Arrays.stream(values())
+ .filter(menu -> menu.name.equals(name))
+ .findFirst()
+ .orElse(null);
+ }
+
+ public boolean isSameType(FoodType foodType) {
+ return this.foodType == foodType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Money getPrice() {
+ return price;
+ }
+} | Java | ๋ฉ์๋์์ ๋ช
์์ ์ผ๋ก `null`์ ๋ฐํํด ์ฃผ๋ ๊ฒ์ ํด๋น ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ ์ธ๋ถ์์ `null`์ ์กด์ฌ๋ฅผ ์์ง ๋ชปํด ์๋์น ๋ชปํ NPE๋ฅผ ๋ง๋ ๊ฐ๋ฅ์ฑ์ด ์๊ธด๋ค๊ณ ์๊ฐํฉ๋๋ค!
`null` ๋์ ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์ ๋ช
์ํ๋ `enum` ์์๋ฅผ ํ๋ ์ฌ์ฉํ๊ฑฐ๋, `Optional`์ ์ฌ์ฉํด ์ ํจํ์ง ์์ ์ํ์ ๋ํ ์กฐ๊ธ ๋ ์์ ํ ์ ๋ณด๋ฅผ ๋ฐํํ๋ ๊ฒ์ ์ด๋จ๊น์?
๊ทธ๋ ์ง ์๋ค๋ฉด, ํด๋น ๋ฉ์๋์์ ๋ฐ๋ก ์์ธ๋ฅผ ๋ฐ์ ์ํค๋ ๊ฒ ์ญ์ ํ๋์ ๋ฐฉ๋ฒ์ด ๋ ์ ์์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,55 @@
+package christmas.domain.menu;
+
+import christmas.message.ExceptionMessage;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.Map;
+
+public class OrderParser {
+ private static final int MAX_MENU_COUNT = 20;
+ private static final String DELIMITER_MENU_ORDER = ",";
+
+ private OrderParser() {
+ // ๋ถํ์ํ ์ธ์คํด์ค ์์ฑ ๋ฐฉ์ง
+ }
+
+ public static Map<Menu, Integer> parse(String inputValue) {
+ Map<Menu, Integer> orderRepository = new EnumMap<>(Menu.class);
+ Arrays.stream(inputValue.split(DELIMITER_MENU_ORDER))
+ .forEach(menuString -> addMenuToOrderRepository(orderRepository, menuString));
+ validateOnlyDrink(orderRepository);
+ validateMaxMenuCount(orderRepository);
+ return orderRepository;
+ }
+
+ private static void addMenuToOrderRepository(Map<Menu, Integer> orderRepository, String menuString) {
+ Order order = Order.createByString(menuString);
+ validateDuplicateMenu(orderRepository, order.menu());
+ orderRepository.put(order.menu(), order.count());
+ }
+
+ private static void validateDuplicateMenu(Map<Menu, Integer> result, Menu menu) {
+ if (result.containsKey(menu)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateOnlyDrink(Map<Menu, Integer> result) {
+ int drinkMenuCount = (int) result.keySet()
+ .stream()
+ .filter(menu -> menu.isSameType(FoodType.DRINK))
+ .count();
+ if (drinkMenuCount == result.size()) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateMaxMenuCount(Map<Menu, Integer> result) {
+ Integer totalMenuCount = result.values()
+ .stream()
+ .reduce(0, Integer::sum);
+ if (totalMenuCount > MAX_MENU_COUNT) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+} | Java | `Parser`๋ผ๋ ์ด๋ฆ๊ณผ `parse`๋ผ๋ ๋ฉ์๋ ๋ช
์ ๋นํด ๋๋ฌด ๋ง์ ์ญํ ์ด ๋ด๋ถ์ ๊ตฌํ๋์ด ์๋ ๊ฒ ๊ฐ์์.
๊ฐ๊ฐ์ ์ฃผ๋ฌธ ๋ชฉ๋ก๋ค์ `EnumMap`์ ์ ์ฅํ๋ ์ญํ ์ ์ด๊ณณ์์ ๋ถ๋ฆฌํด์ ๋ณ๋์ ์ปฌ๋ ์
์ ๋ํํ๋ ํด๋์ค๋ฅผ ๋ง๋ค ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,55 @@
+package christmas.domain.menu;
+
+import christmas.message.ExceptionMessage;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.Map;
+
+public class OrderParser {
+ private static final int MAX_MENU_COUNT = 20;
+ private static final String DELIMITER_MENU_ORDER = ",";
+
+ private OrderParser() {
+ // ๋ถํ์ํ ์ธ์คํด์ค ์์ฑ ๋ฐฉ์ง
+ }
+
+ public static Map<Menu, Integer> parse(String inputValue) {
+ Map<Menu, Integer> orderRepository = new EnumMap<>(Menu.class);
+ Arrays.stream(inputValue.split(DELIMITER_MENU_ORDER))
+ .forEach(menuString -> addMenuToOrderRepository(orderRepository, menuString));
+ validateOnlyDrink(orderRepository);
+ validateMaxMenuCount(orderRepository);
+ return orderRepository;
+ }
+
+ private static void addMenuToOrderRepository(Map<Menu, Integer> orderRepository, String menuString) {
+ Order order = Order.createByString(menuString);
+ validateDuplicateMenu(orderRepository, order.menu());
+ orderRepository.put(order.menu(), order.count());
+ }
+
+ private static void validateDuplicateMenu(Map<Menu, Integer> result, Menu menu) {
+ if (result.containsKey(menu)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateOnlyDrink(Map<Menu, Integer> result) {
+ int drinkMenuCount = (int) result.keySet()
+ .stream()
+ .filter(menu -> menu.isSameType(FoodType.DRINK))
+ .count();
+ if (drinkMenuCount == result.size()) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateMaxMenuCount(Map<Menu, Integer> result) {
+ Integer totalMenuCount = result.values()
+ .stream()
+ .reduce(0, Integer::sum);
+ if (totalMenuCount > MAX_MENU_COUNT) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+} | Java | ๋ชจ๋ ์๋ฃ์์ธ์ง ํ์ธํ๋ ์คํธ๋ฆผ ์ฒด์ธ ๋ก์ง์ ๋ฆฌ๋๋ฏธ ๊ณต์ฅ์ฅ ํด๋น๋ ์ฝ๋์์ ํ์ณ์์ด์....!
ํ์นธ๋ ์ฝ๋์ ๋ง๊ฒ ์์ ํด ๋ณด์์ต๋๋ค ^^
```suggestion
boolean isAllDrink = result.keySet()
.stream()
.allMatch(menu -> menu.isSameType(FoodType.DRINK));
if(isAllDrink){
throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
}
``` |
@@ -0,0 +1,31 @@
+package christmas.domain.menu;
+
+import christmas.domain.Money;
+import java.util.Collections;
+import java.util.Map;
+
+public record OrderRepository(Map<Menu, Integer> repository) {
+ public static OrderRepository createByString(String orderString) {
+ Map<Menu, Integer> orderRepository = OrderParser.parse(orderString);
+ return new OrderRepository(orderRepository);
+ }
+
+ public int findTotalCountByFoodType(FoodType foodType) {
+ return repository.keySet()
+ .stream()
+ .filter(menu -> menu.isSameType(foodType))
+ .map(repository::get)
+ .reduce(0, Integer::sum);
+ }
+
+ public Money calculateTotalPrice() {
+ return repository.keySet()
+ .stream()
+ .map((menu) -> menu.getPrice().multiply(repository.get(menu)))
+ .reduce(new Money(0), Money::sum);
+ }
+
+ public Map<Menu, Integer> repository() {
+ return Collections.unmodifiableMap(repository);
+ }
+} | Java | ๊ท์ฐฎ์๊ฑด ์ง์์ด๋๊น์...!
```suggestion
.mapToInt(repository::get)
.sum();
``` |
@@ -0,0 +1,20 @@
+package christmas.domain.discount;
+
+import christmas.domain.menu.Menu;
+import christmas.domain.Money;
+
+public class GiftDiscount {
+ public static final String NAME = "์ฆ์ ์ด๋ฒคํธ";
+ private static final Money MIN_PRESENTATION_MONEY = new Money(120000);
+
+ public static Money calculateDiscountAmount(Money totalPrize) {
+ if (totalPrize.isMoreOrEqualThan(MIN_PRESENTATION_MONEY)) {
+ return Menu.CHAMPAGNE.getPrice();
+ }
+ return new Money(0);
+ }
+
+ public static Menu getGift() {
+ return Menu.CHAMPAGNE;
+ }
+} | Java | ์ ๋ง ์ฌ์ํ ๊ฐ๋
์ฑ์ ์ํ ํ์
๋๋ค!
```suggestion
private static final Money MIN_PRESENTATION_MONEY = new Money(120_000);
``` |
@@ -0,0 +1,41 @@
+package christmas.domain;
+
+import christmas.message.ExceptionMessage;
+import java.util.List;
+
+public record DecemberDate(int dateAmount) {
+ private static final List<Integer> WEEKEND_DATES = List.of(1, 2, 8, 9, 15, 16, 22, 23, 29, 30);
+ private static final int MINIMUM_DATE_AMOUNT = 1;
+ private static final int MAXIMUM_DATE_AMOUNT = 31;
+
+ public DecemberDate {
+ validateDate(dateAmount);
+ }
+
+ private void validateDate(int dateAmount) {
+ if (isOutOfDateRange(dateAmount)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_DATE);
+ }
+ }
+
+ private boolean isOutOfDateRange(int dateAmount) {
+ return dateAmount < MINIMUM_DATE_AMOUNT || dateAmount > MAXIMUM_DATE_AMOUNT;
+ }
+
+ public boolean isLessThan(DecemberDate date) {
+ return dateAmount < date.dateAmount();
+ }
+
+ public boolean isMoreThan(DecemberDate date) {
+ return dateAmount > date.dateAmount();
+ }
+
+ public boolean isWeekend() {
+ return WEEKEND_DATES.contains(dateAmount);
+ }
+
+ public boolean isWeekday() {
+ return !isWeekend();
+ }
+
+} | Java | `DayOfWeek`๋ฅผ ํตํด ์์ผ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์จ๋ค๋ฉด ์ฝ๋๊ฐ ์กฐ๊ธ ๋ ๊ฐ๊ฒฐํด ์ง ์ ์์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,27 @@
+package christmas;
+
+import christmas.domain.Money;
+import christmas.message.ExceptionMessage;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+public class MoneyTest {
+ @DisplayName("๊ธ์ก์ 0์ ์ด์์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ์ง ์๋๋ค.")
+ @ParameterizedTest
+ @ValueSource(ints = {0, 10, 100, 1000, 999999, 1000000})
+ void moneySuccessTest(int amount) {
+ Assertions.assertThatNoException()
+ .isThrownBy(() -> new Money(amount));
+ }
+
+ @DisplayName("๊ธ์ก์ 0์ ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @ParameterizedTest
+ @ValueSource(ints = {-10, -100, -1000, -999999, -1000000})
+ void moneyFailTest(int amount) {
+ Assertions.assertThatThrownBy(() -> new Money(amount))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ExceptionMessage.INVALID_MONEY);
+ }
+} | Java | `@ParaneterizedTest`๋ฅผ ์ฌ์ฉํ ๋๋ ๊ฐ๊ฐ์ ํ
์คํธ ์ผ์ด์ค ์ด๋ฆ์ ์์๊ฒ ๋ณด์ฌ์ค ์ ์๋ค๋ ์ฌ์ค, ์๊ณ ๊ณ์
จ๋์?!
```suggestion
@ParameterizedTest(name = "{0} ๊ธ์ก์ด 0์ ๋ฏธ๋ง์ด๋ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
``` |
@@ -0,0 +1,33 @@
+package christmas.domain;
+
+public enum EventBadge {
+ SANTA("์ฐํ", new Money( 20000)),
+ TREE("ํธ๋ฆฌ", new Money( 10000)),
+ STAR("๋ณ", new Money(5000)),
+ NONE("์์", new Money(0));
+
+ private final String name;
+ private final Money price;
+
+ EventBadge(String name, Money price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public static EventBadge findByTotalDiscountPrice(Money totalDiscountMoney) {
+ if (totalDiscountMoney.isMoreOrEqualThan(SANTA.price)) {
+ return SANTA;
+ }
+ if (totalDiscountMoney.isMoreOrEqualThan(TREE.price)) {
+ return TREE;
+ }
+ if (totalDiscountMoney.isMoreOrEqualThan(STAR.price)) {
+ return STAR;
+ }
+ return NONE;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | @zangsu ์ํ ๊ทธ๋ฐ ๊ด๋ก๊ฐ ์์๊ตฐ์! ๊ฐ์ฌํฉ๋๋ค! โบ๏ธ |
@@ -0,0 +1,55 @@
+package christmas.domain.menu;
+
+import christmas.message.ExceptionMessage;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.Map;
+
+public class OrderParser {
+ private static final int MAX_MENU_COUNT = 20;
+ private static final String DELIMITER_MENU_ORDER = ",";
+
+ private OrderParser() {
+ // ๋ถํ์ํ ์ธ์คํด์ค ์์ฑ ๋ฐฉ์ง
+ }
+
+ public static Map<Menu, Integer> parse(String inputValue) {
+ Map<Menu, Integer> orderRepository = new EnumMap<>(Menu.class);
+ Arrays.stream(inputValue.split(DELIMITER_MENU_ORDER))
+ .forEach(menuString -> addMenuToOrderRepository(orderRepository, menuString));
+ validateOnlyDrink(orderRepository);
+ validateMaxMenuCount(orderRepository);
+ return orderRepository;
+ }
+
+ private static void addMenuToOrderRepository(Map<Menu, Integer> orderRepository, String menuString) {
+ Order order = Order.createByString(menuString);
+ validateDuplicateMenu(orderRepository, order.menu());
+ orderRepository.put(order.menu(), order.count());
+ }
+
+ private static void validateDuplicateMenu(Map<Menu, Integer> result, Menu menu) {
+ if (result.containsKey(menu)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateOnlyDrink(Map<Menu, Integer> result) {
+ int drinkMenuCount = (int) result.keySet()
+ .stream()
+ .filter(menu -> menu.isSameType(FoodType.DRINK))
+ .count();
+ if (drinkMenuCount == result.size()) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateMaxMenuCount(Map<Menu, Integer> result) {
+ Integer totalMenuCount = result.values()
+ .stream()
+ .reduce(0, Integer::sum);
+ if (totalMenuCount > MAX_MENU_COUNT) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+} | Java | @zangsu `allMatch` ๋ฅผ ํ์ฉํ๋ฉด ๋๊ตฐ์! ๊ฐ์ฌํฉ๋๋ค! ์์ง ์คํธ๋ฆผ์ ๋ํด์ ๋ฐฐ์ธ๊ฒ ๋ง์๊ฒ ๊ฐ๋ค์! ใ
ใ
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.