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` ๋ฅผ ํ™œ์šฉํ•˜๋ฉด ๋˜๊ตฐ์š”! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์•„์ง ์ŠคํŠธ๋ฆผ์— ๋Œ€ํ•ด์„  ๋ฐฐ์šธ๊ฒŒ ๋งŽ์€๊ฒƒ ๊ฐ™๋„ค์š”! ใ…Žใ…Ž