code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -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,52 @@ +import React, { Component } from 'react'; + +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faHeart } from '@fortawesome/free-regular-svg-icons'; + +import './LikeBtn.scss'; + +class LikeBtn extends Component { + constructor(props) { + super(props); + const { isLiked } = this.props; + this.state = { isLikeBtnClicked: isLiked }; + } + + handleLikeBtnColor = () => { + const { isLikeBtnClicked } = this.state; + const { whoseBtn, handler, userId, categoryTitle, coffeeName } = this.props; + this.setState({ isLikeBtnClicked: !isLikeBtnClicked }); + + switch (whoseBtn) { + case 'product': + handler(!isLikeBtnClicked); + break; + case 'review': + handler(userId, !isLikeBtnClicked); + break; + case 'coffeeCard': + handler(categoryTitle, coffeeName, !isLikeBtnClicked); + break; + default: + break; + } + }; + + render() { + const { isLikeBtnClicked } = this.state; + const { handleLikeBtnColor } = this; + return ( + <div className="like-btn-wrap"> + <button + className={isLikeBtnClicked ? 'like-wrap clicked' : 'like-wrap'} + id="product-like" + onClick={handleLikeBtnColor} + > + <FontAwesomeIcon icon={faHeart} /> + </button> + </div> + ); + } +} + +export default LikeBtn;
JavaScript
react๋ถ€ํ„ฐ wecode์—์„œ๋Š” ํด๋ž˜์Šค๋ช…๋„ ์นด๋ฉœ์ผ€์ด์Šค๋กœ ํ†ต์ผํ•˜์ž๊ณ  ํ–ˆ๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค...?
@@ -0,0 +1,103 @@ +{ + "footerList": [ + { + "id": 1, + "title": "COMPANY", + "contents": [ + { + "id": 1, + "contentName": "ํ•œ๋ˆˆ์— ๋ณด๊ธฐ" + }, + { + "id": 2, + "contentName": "์œ„๋ฒ…์Šค ์‚ฌ๋ช…" + }, + { + "id": 3, + "contentName": "์œ„๋ฒ…์Šค ์†Œ๊ฐœ" + }, + { + "id": 4, + "contentName": "๊ตญ๋‚ด ๋‰ด์Šค๋ฃธ" + }, + { + "id": 5, + "contentName": "์„ธ๊ณ„์˜ ์œ„๋ฒ…์Šค" + }, + { + "id": 6, + "contentName": "๊ธ€๋กœ๋ฒŒ ๋‰ด์Šค๋ฃธ" + } + ] + }, + { + "id": 2, + "title": "CORPORATE_SALES", + "contents": [ + { + "id": 1, + "contentName": "๋‹จ์ฒด ๋ฐ ๊ธฐ์—… ๊ตฌ๋งค ์•ˆ๋‚ด" + } + ] + }, + { + "id": 3, + "title": "PARTNERSHIP", + "contents": [ + { + "id": 1, + "contentName": "๊ธ€๋กœ๋ฒŒ ๋‰ด์Šค๋ฃธ" + }, + { + "id": 2, + "contentName": "์‹ ๊ทœ ์ž…์  ์ œ์˜" + } + ] + }, + { + "id": 4, + "title": "ONLINE COMMUNITY", + "contents": [ + { + "id": 1, + "contentName": "ํŽ˜์ด์Šค๋ถ" + }, + { + "id": 2, + "contentName": "ํŠธ์œ„ํ„ฐ" + }, + { + "id": 3, + "contentName": "์œ ํŠœ๋ธŒ" + }, + { + "id": 4, + "contentName": "๋ธ”๋กœ๊ทธ" + }, + { + "id": 5, + "contentName": "์ธ์Šคํƒ€๊ทธ๋žจ" + }, + { + "id": 6, + "contentName": "ํŽ˜์ด์Šค๋ถ" + } + ] + }, + { + "id": 5, + "title": "RECRUIT", + "contents": [ + { + "id": 1, + "contentName": "์ฑ„์šฉ ์†Œ๊ฐœ" + }, + { + "id": 2, + "contentName": "์ฑ„์šฉ ์ง€์›ํ•˜๊ธฐ" + } + ] + }, + { "id": 6, "title": "WEBUKCS", "contents": [] } + ] +} \ No newline at end of file
Unknown
footer๊นŒ์ง€ json์œผ๋กœ ํ•˜์…จ๋„ค์š”! ๋ถ€์ง€๋Ÿฐํ•˜์‹ญ๋‹ˆ๋‹ค,,๐Ÿ‘๐Ÿผ
@@ -0,0 +1,44 @@ +{ + "menus": [ + { + "id": 1, + "parentId": 0, + "level": 1, + "name": "ํ™ˆ", + "path": "/", + "children": null + }, + { + "id": 2, + "parentId": 1, + "level": 2, + "name": "MENU", + "path": "/menu/", + "children": null + }, + { + "id": 3, + "parentId": 2, + "level": 3, + "name": "์Œ๋ฃŒ", + "path": "/list-junbeom", + "children": null + }, + { + "id": 4, + "parentId": 3, + "level": 4, + "name": "์ฝœ๋“œ๋ธŒ๋ฃจ", + "path": "/menu/drink/coldbrew/", + "children": null + }, + { + "id": 5, + "parentId": 4, + "level": 5, + "name": "์‹œ๊ทธ๋‹ˆ์ฒ˜ ๋” ๋ธ”๋ž™ ์ฝœ๋“œ ๋ธŒ๋ฃจ", + "path": "/detail-junbeom", + "children": null + } + ] +} \ No newline at end of file
Unknown
์ €๋Š” ์ œ๊ฐ€ list๋กœ ๋Œ์•„๊ฐ€๊ณ  ์‹ถ์–ด์„œ menu์—๋งŒ Link ์ฒ˜๋ฆฌ๋ฅผ ํ•ด๋‘์—ˆ๋Š”๋ฐ path๊นŒ์ง€ ๋””ํ…Œ์ผ๊นŒ์ง€ ์„ค์ •ํ•˜์…จ๋„ค์š”! ์ €๋„ ์ข€๋” ๋””ํ…Œ์ผํ•˜๊ฒŒ ์ˆ˜์ •ํ•ด๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค. ์ข‹์€ ์ •๋ณด ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :)
@@ -0,0 +1,48 @@ +import React, { Component } from 'react'; + +import FooterMenuTitle from './FooterMenuTitle'; +import FooterMenuContent from './FooterMenuContent'; + +import './Footer.scss'; + +class Footer extends Component { + constructor(props) { + super(props); + this.state = { footerList: [] }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/footerListMockData.json') + .then(res => res.json()) + .then(data => { + this.setState({ footerList: data.footerList }); + }); + } + + render() { + const { footerList } = this.state; + return ( + <footer className="Footer"> + <div className="footer-menus"> + {footerList.map(data => { + return ( + <ul key={data.id}> + <FooterMenuTitle title={data.title} /> + {data.contents.map(content => { + return ( + <FooterMenuContent + key={content.id} + content={content.contentName} + /> + ); + })} + </ul> + ); + })} + </div> + </footer> + ); + } +} + +export default Footer;
JavaScript
import ์ฝ”๋”ฉ ์ปจ๋ฒค์…˜์ด ๋”ฐ๋กœ ์žˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์œผ๋‚˜, ํŒ€๋ผ๋ฆฌ ์˜๋…ผํ•ด์„œ ๋” ๊ฐ€๋…์„ฑ ์ข‹์€ ์ชฝ์œผ๋กœ ์ค„๋ฐ”๊ฟˆ์„ ์ ์šฉํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค :)
@@ -0,0 +1,35 @@ +@import '../../Styles/variables.scss'; + +.Footer { + width: 100%; + background-color: #2c2a29; + + .footer-menus { + display: flex; + justify-content: space-around; + flex-wrap: wrap; + margin: 20px auto; + padding: 10px 50px; + color: white; + + li { + list-style: none; + } + + a { + color: $theme-color; + text-decoration: none; + } + + .footer-menu-title { + margin-bottom: 15px; + font-size: 15px; + font-weight: 100; + } + + .footer-menu-content { + margin-bottom: 6px; + font-size: 12px; + } + } +}
Unknown
sass variable์„ ์–ด๋””์— ์ ์šฉํ•ด์•ผ ํ• ์ง€ ๋ชฐ๋ผ ๊ณ ๋ฏผํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ์ฐธ๊ณ  ๋งŽ์ด ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :)
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
์ €๋Š” ๋ฐ”์ธ๋“œ๋ฅผ ํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ, ํ˜น์‹œ ์–ด๋–ค ๊ฒฝ์šฐ์— ๋ฐ”์ธ๋“œ๋ฅผ ํ•ด์•ผํ•˜๋Š”์ง€ ๊ฐ„๋‹จํžˆ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :)
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
promise์™€ all์„ ์‚ฌ์šฉํ•˜์…จ๊ตฐ์š”!!!! ์˜์ƒ์€ ๋ดค๋Š”๋ฐ ๋ฌด์„œ์›Œ์„œ ์ ์šฉ์„ ๋ชปํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ์ €๋„ ์šฉ๊ธฐ ์–ป๊ณ  ์‹œ๋„ํ•ด๋ด…๋‹ˆ๋‹ค!!!
@@ -0,0 +1,164 @@ +@import '../../../Styles/variables.scss'; +@import '../../../Styles/font.scss'; + +.Detail { + @extend %flex-column; + align-items: center; + flex-wrap: wrap; + padding-top: 3rem; + + .detail-section { + @extend %flex-column; + width: 60%; + margin-top: 30px; + + .category-title { + font-size: 25px; + font-weight: 700; + } + } + + .detail-category { + position: relative; + height: 80px; + margin-bottom: 20px; + padding: 10px; + + .category-nav { + position: absolute; + right: 0; + bottom: 0; + width: 400px; + } + } + + .detail-content { + @extend %flex-between; + flex-wrap: wrap; + } + + .detail-img-wrap { + max-width: 45%; + min-width: 300px; + padding: 10px; + + img { + width: 100%; + } + } + + .detail-text-wrap { + max-width: 55%; + padding: 10px; + } + + .detail-text { + position: relative; + + .product-name-kr { + padding-bottom: 18px; + margin-bottom: 20px; + color: #222; + border-bottom: 2px solid #333; + font-size: 25px; + font-weight: 400; + } + + .product-name-en { + color: #666; + font-size: 16px; + } + + .like-btn-wrap { + position: absolute; + top: 0; + right: 0; + + .like-wrap { + font-size: 25px; + } + } + + .product-description { + margin-bottom: 20px; + font-size: 16px; + white-space: pre-wrap; + } + } + + .product-info { + @extend %flex-column; + + .product-info-head { + @extend %flex-between; + border-top: 1px solid $division-color; + border-bottom: 1px solid $division-color; + + .info-head-text { + color: #222; + font-size: 18px; + padding: 10px; + margin: 10px; + } + } + + .product-info-content { + @extend %flex-center; + margin: 10px; + padding: 10px; + + table { + width: 100%; + + tr { + height: 30px; + } + + td { + width: 25%; + } + + .align-right { + text-align: right; + } + + .padding-right { + padding-right: 10px; + } + + .dashed-border { + padding-left: 10px; + border-left: 1px dashed $division-color; + } + } + } + + .allergens-wrap { + margin: 10px; + padding: 10px; + font-size: 18px; + background-color: $division-color; + } + } + + .detail-review { + margin-bottom: 30px; + + .review-title { + padding: 20px 0px; + border-bottom: 1px solid $division-color; + } + + ul { + padding: 20px 0px; + list-style: none; + } + + .review-input { + width: 100%; + padding: 10px; + background-color: $division-color; + border: none; + } + } +}
Unknown
๋””ํ…Œ์ผ ํŽ˜์ด์ง€์—๋Š” ๋Œ€๋ถ€๋ถ„ camelCase์ด ์ ์šฉ์ด ๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
์ด ๋ถ€๋ถ„์€ ๋‹ค๋นˆ๋‹˜ ๋ฆฌ๋ทฐ ์ฝ”๋ฉ˜ํŠธ์— ์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค! ์ œ๊ฐ€ ์ž˜๋ชป ์•Œ๊ณ  ์žˆ๋˜ ๋ถ€๋ถ„์ด ์žˆ์–ด์„œ ํ˜„์žฌ ์ œ ์ฝ”๋“œ์—๋„ ๋ฌธ์ œ๊ฐ€ ์ข€ ์žˆ๋„ค์š”! ์ €๋„ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ํ•จ์ˆ˜๋ฅผ ์„ ์–ธ ๋ฐ ์ •์˜ํ•  ๋•Œ ํด๋ž˜์Šค ํ•„๋“œ ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ๋กœ .bind()๋ฅผ ์•ˆ ํ•ด๋„ ๋˜๋Š”๊ฒŒ ๋งž์Šต๋‹ˆ๋‹ค! ๊ด€๋ จ ๋‚ด์šฉ์€ ๋‹ค๋นˆ๋‹˜ ๋ฆฌ๋ทฐ์— ๋งํฌ๋กœ ์˜ฌ๋ ธ์œผ๋‹ˆ ํ™•์ธํ•ด๋ณด์‹œ์™€์š” ~
@@ -0,0 +1,44 @@ +{ + "menus": [ + { + "id": 1, + "parentId": 0, + "level": 1, + "name": "ํ™ˆ", + "path": "/", + "children": null + }, + { + "id": 2, + "parentId": 1, + "level": 2, + "name": "MENU", + "path": "/menu/", + "children": null + }, + { + "id": 3, + "parentId": 2, + "level": 3, + "name": "์Œ๋ฃŒ", + "path": "/list-junbeom", + "children": null + }, + { + "id": 4, + "parentId": 3, + "level": 4, + "name": "์ฝœ๋“œ๋ธŒ๋ฃจ", + "path": "/menu/drink/coldbrew/", + "children": null + }, + { + "id": 5, + "parentId": 4, + "level": 5, + "name": "์‹œ๊ทธ๋‹ˆ์ฒ˜ ๋” ๋ธ”๋ž™ ์ฝœ๋“œ ๋ธŒ๋ฃจ", + "path": "/detail-junbeom", + "children": null + } + ] +} \ No newline at end of file
Unknown
์—„์ฒญ ๊ผผ๊ผผํžˆ ์ž‘์„ฑํ•˜์…จ๋„ค์š”. ๋Œ€๋‹จํ•ฉ๋‹ˆ๋‹ค!! :)
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
์˜ค์šฐ~~ ์ง„๋„ ๋„ˆ๋ฌด ๋‚˜๊ฐ€์…จ๋Š”๋ฐ์š”??ใ…‹ใ…‹ ๋ฒŒ์จ Promise๊นŒ์ง€ ์ ์šฉํ•˜์‹œ๋‹ค๋‹ˆ ์ตœ๊ณ ์ž…๋‹ˆ๋‹ค!! :)
@@ -1,3 +0,0 @@ -.logo { - margin: 0; -}
Unknown
์ด๋Ÿฐ ์ดˆ๊ธฐํ™”๋Š” reset์— ๋„ฃ์–ด ์ฃผ์„ธ์š”!
@@ -0,0 +1,10 @@ +.like-wrap { + color: #666; + background-color: white; + border: none; + cursor: pointer; + + &.clicked { + color: tomato; + } +}
Unknown
์ „์ฒด nesting ํ•ด์ฃผ์„ธ์š”!
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
์ด๋ ‡๊ฒŒ ํ•˜๋”๋ผ๋„ ์ฃผ์†Œ๊ฐ€ ๋ณต์‚ฌ๋˜๊ธฐ ๋•Œ๋ฌธ์— state๋ฅผ ์ง์ ‘ ๊ฑด๋“œ๋ฆฌ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ฃผ์†Œ๋ฅผ ๋Š์–ด ์ฃผ์„ธ์š”!
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
๊ตฌ์กฐ๋ถ„ํ•ด ํ• ๋‹น์ด ์ž˜๋ชป๋˜์„œ state๋ฅผ ์ „์ฒด ๋‹ค returnํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํ•จ์ˆ˜์˜ ๋ชฉ์ ์€ ๋ฌด์—‡์ธ๊ฐ€์š”?
@@ -0,0 +1,52 @@ +import React, { Component } from 'react'; + +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faHeart } from '@fortawesome/free-regular-svg-icons'; + +import './LikeBtn.scss'; + +class LikeBtn extends Component { + constructor(props) { + super(props); + const { isLiked } = this.props; + this.state = { isLikeBtnClicked: isLiked }; + } + + handleLikeBtnColor = () => { + const { isLikeBtnClicked } = this.state; + const { whoseBtn, handler, userId, categoryTitle, coffeeName } = this.props; + this.setState({ isLikeBtnClicked: !isLikeBtnClicked }); + + switch (whoseBtn) { + case 'product': + handler(!isLikeBtnClicked); + break; + case 'review': + handler(userId, !isLikeBtnClicked); + break; + case 'coffeeCard': + handler(categoryTitle, coffeeName, !isLikeBtnClicked); + break; + default: + break; + } + }; + + render() { + const { isLikeBtnClicked } = this.state; + const { handleLikeBtnColor } = this; + return ( + <div className="like-btn-wrap"> + <button + className={isLikeBtnClicked ? 'like-wrap clicked' : 'like-wrap'} + id="product-like" + onClick={handleLikeBtnColor} + > + <FontAwesomeIcon icon={faHeart} /> + </button> + </div> + ); + } +} + +export default LikeBtn;
JavaScript
๋ฒ„ํŠผ์˜ ์ข‹์•„์š” ์ƒํƒœ๋ฅผ ๋ฒ„ํŠผ์ด ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉด ํ•ญ์ƒ ์ข‹์•„์š”๊ฐ€ false๊ฒ ์ฃ ? ์ด๋ฏธ ์ข‹์•„์š” ํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ props๋กœ ๋ฐ›์•„์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๋ฐ”๋€Œ๋ฉด ๋ฉ”์„œ๋“œ ๋“ค๋„ ์กฐ๊ธˆ ์ˆ˜์ •ํ•˜์…”์•ผ ํ• ๊ฒ๋‹ˆ๋‹ค!
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
review์˜ valid๋Š” ๋ฌด์—‡์„ ์˜๋ฏธํ•˜๋‚˜์š”?
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
Promise.all๋ฅผ ์‚ฌ์šฉํ•˜์…จ๊ตฐ์š”! ๊ตฟ! ๋ฐ์ดํ„ฐ๊ฐ€ ๋จผ์ € ์˜ค๋Š”๊ฒƒ๋ถ€ํ„ฐ setState๋ฅผ ํ•ด์„œ ํ™”๋ฉด์— ๋น ๋ฅด๊ฒŒ ๋ณด์—ฌ์ค˜์•ผ ํ•˜๋Š”๋ฐ ์ง€๊ธˆ์€ ์„ธ ๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ชจ๋‘ ๋ฐ›์•„์™”์„ ๋•Œ๋งŒ ํ™”๋ฉด์— ๋ณด์—ฌ์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์กฐ๊ธˆ ๋А๋ฆด๊ฒ๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์ด์œ ๋กœ Promise.all์—๋Š” fetch์™€ setState๋ฅผ ๋ชจ๋‘ ํ•˜๊ณ  ์žˆ๋Š” ํ•˜๋‚˜์˜ ํ•จ์ˆ˜๋ฅผ ๊ฐ๊ฐ ๋„ฃ์–ด์ฃผ์‹œ๋Š”๊ฒŒ ๋” ์ข‹์Šต๋‹ˆ๋‹ค.
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
ํด๋ž˜์Šค์ด๋ฆ„ ๋‹ค์Œ ํ”„๋กœ์ ํŠธ ๋ถ€ํ„ฐ๋Š” ๊ผญ camelCase๋กœ ์‚ฌ์šฉํ•ด ์ฃผ์„ธ์š”.
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
table ํ˜•์‹์ด๋ผ์„œ table ๊ด€๋ จ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด ์ฃผ์„ธ์š”
@@ -1 +1,245 @@ -console.log("์‹์‚ฌ์ข€ ํ•ฉ์‹œ๋‹ค."); +import React, { Component } from 'react'; + +import { getProducts, getReviews, getMenus } from '../api'; + +import TopMenuNav from './TopMenuNav'; +import LikeBtn from '../../../components/LikeBtn/LikeBtn'; +import Review from './Review'; + +import './Detail.scss'; + +class Detail extends Component { + testIdNum = 1; + + constructor(props) { + super(props); + this.state = { + product: {}, + reviewList: [], + menuList: [], + reviewInputVal: '', + }; + } + + handleReviewInput = event => { + const { key } = event; + const { value } = event.target; + const { reviewList } = this.state; + + if (key === 'Enter' && value !== '') { + let newReview = { + userId: 'test' + this.testIdNum, + text: value, + isDeleted: false, + isLiked: false, + }; + const newReviewList = [...reviewList]; + newReviewList.push(newReview); + + this.setState({ + reviewInputVal: '', + reviewList: newReviewList, + }); + this.testIdNum++; + } + }; + + getReviewInputVal = event => { + const { value } = event.target; + this.setState({ reviewInputVal: value }); + }; + + handleDelReviewBtn = userId => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isDeleted = true; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + getNotDeletedReviews = () => { + const { reviewList } = this.state; + const notDelReviewList = []; + for (let review of reviewList) { + if (!review.isDeleted) { + notDelReviewList.push(review); + } + } + return notDelReviewList; + }; + + isProductLiked = isLiked => { + const { product } = this.state; + const updatedProduct = { ...product }; + updatedProduct.isLiked = isLiked; + this.setState({ product: updatedProduct }); + }; + + isReviewLiked = (userId, isLiked) => { + const { reviewList } = this.state; + const updatedReviewList = [...reviewList]; + for (let review of updatedReviewList) { + if (userId === review.userId) { + review.isLiked = isLiked; + } + } + this.setState({ reviewList: updatedReviewList }); + }; + + async componentDidMount() { + // console.time('์†Œ์š”์‹œ๊ฐ„'); + // Promise.all([ + // fetch('http://localhost:3000/data/detailMockData.json'), + // fetch('http://localhost:3000/data/reviewListMockData.json'), + // fetch('http://localhost:3000/data/menuListMockData.json'), + // ]) + // .then(([res1, res2, res3]) => + // Promise.all([res1.json(), res2.json(), res3.json()]) + // ) + // .then(([data1, data2, data3]) => { + // this.setState({ + // product: data1.data[0], + // reviewList: data2.reviews, + // menuList: data3.menus, + // }); + // }); + // console.timeEnd('์†Œ์š”์‹œ๊ฐ„'); + try { + const jsonData = await Promise.all([ + getProducts(), + getReviews(), + getMenus(), + ]); + this.setState({ product: jsonData[0].data[0] }); + this.setState({ reviewList: jsonData[1].reviews }); + this.setState({ menuList: jsonData[2].menus }); + } catch (err) { + new Error('Failed to set state'); + } + } + + render() { + const { + handleReviewInput, + getReviewInputVal, + handleDelReviewBtn, + getNotDeletedReviews, + isProductLiked, + isReviewLiked, + } = this; + const { product, menuList, reviewInputVal } = this.state; + + let currentMenu; + for (let menu of menuList) { + if (menu.name === product.name) { + currentMenu = menu; + } + } + + return ( + <div className="Detail"> + {/* <TopNav /> */} + <section className="detail-section"> + <article> + <div className="detail-category"> + <h2 className="category-title">{product.catecory}</h2> + <div className="category-nav"> + <TopMenuNav {...currentMenu} menuList={menuList} /> + </div> + </div> + <div className="detail-content"> + <div className="detail-img-wrap"> + <img alt={product.name} src={product.imgUrl} /> + </div> + <div className="detail-text-wrap"> + <div className="detail-text"> + <h3 className="product-name-kr"> + {product.name} + <br /> + <span className="product-name-en">{product.engName}</span> + </h3> + <LikeBtn + whoseBtn="product" + handler={isProductLiked} + isLiked={product.isLiked} + /> + <p className="product-description">{product.summary}</p> + </div> + <div className="product-info"> + <div className="product-info-head"> + <p className="info-head-text">์ œํ’ˆ ์˜์–‘ ์ •๋ณด</p> + <p className="info-head-text">{product.servingSize}</p> + </div> + <div className="product-info-content"> + <table> + <tbody> + <tr> + <td>1ํšŒ ์ œ๊ณต๋Ÿ‰ (kcal)</td> + <td className="align-right padding-right"> + {product.kcal} + </td> + <td className="dashed-border">๋‚˜ํŠธ๋ฅจ (mg)</td> + <td className="align-right">{product.natrium}</td> + </tr> + <tr> + <td>ํฌํ™”์ง€๋ฐฉ (g)</td> + <td className="align-right padding-right"> + {product.fat} + </td> + <td className="dashed-border">๋‹น๋ฅ˜ (g)</td> + <td className="align-right">{product.sugars}</td> + </tr> + <tr> + <td>๋‹จ๋ฐฑ์งˆ (g)</td> + <td className="align-right padding-right"> + {product.protein} + </td> + <td className="dashed-border">์นดํŽ˜์ธ (mg)</td> + <td className="align-right">{product.caffeine}</td> + </tr> + </tbody> + </table> + </div> + <div className="allergens-wrap"> + <p>์•Œ๋ ˆ๋ฅด๊ธฐ ์œ ๋ฐœ ์š”์ธ : {product.allergen}</p> + </div> + </div> + <div className="detail-review"> + <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2> + <ul className="review-list"> + {getNotDeletedReviews().map(review => { + return ( + <Review + key={review.userId} + {...review} + isReviewLiked={isReviewLiked} + handleDelReviewBtn={handleDelReviewBtn} + /> + ); + })} + </ul> + <div className="review-input-wrap"> + <input + className="review-input" + placeholder="๋ฆฌ๋ทฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”." + type="text" + value={reviewInputVal} + onChange={getReviewInputVal} + onKeyPress={handleReviewInput} + /> + </div> + </div> + </div> + </div> + </article> + </section> + {/* <Footer /> */} + </div> + ); + } +} + +export default Detail;
JavaScript
null์„ returnํ•˜๋Š”๊ฒŒ ์กฐ๊ธˆ ๊ฑธ๋ ค์„œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋งŒ๋“œ์‹  ๋‹ค์Œ์— ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜๋Š” ์š”์†Œ๋ฅผ push ํ•ด์„œ ๊ทธ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜์‹œ๋Š” ๊ฒŒ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -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` ๋ฅผ ํ™œ์šฉํ•˜๋ฉด ๋˜๊ตฐ์š”! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์•„์ง ์ŠคํŠธ๋ฆผ์— ๋Œ€ํ•ด์„  ๋ฐฐ์šธ๊ฒŒ ๋งŽ์€๊ฒƒ ๊ฐ™๋„ค์š”! ใ…Žใ…Ž
@@ -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
๋‚˜๋ฆ„ ๊ณ ๋ฏผํ–ˆ๋˜ ๋ถ€๋ถ„์ด์˜€๋Š”๋ฐ ์—ญ์‹œ ํ”ผ๋“œ๋ฐฑ ํ•ด์ฃผ์…จ๋„ค์š”! ใ…Žใ…Ž ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
@@ -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
์™€,, ์ด๋Ÿฐ ๊ธฐ๋Šฅ๋„ ์žˆ์—ˆ๊ตฐ์š”! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ใ…Žใ…Ž
@@ -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
enum์•ˆ์— ๊ฐ์ฒด๋ฅผ ๋„ฃ๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ๊ตฐ์š” ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค!
@@ -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
7๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๊ฐ€ 1,2์ธ์ ์„ ์ด์šฉํ•ด์„œ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋ณ„๋กœ์ผ๊นŒ์š”! ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด ์ƒ์ˆ˜๊ฐ€ ํ•„์š”์—†์–ด์งˆ๊ฒƒ๊ฐ™์•„์š”!
@@ -0,0 +1,59 @@ +package christmas.domain; + +import christmas.domain.discount.DiscountRepository; +import christmas.domain.discount.GiftDiscount; +import christmas.domain.menu.Menu; +import christmas.domain.menu.OrderRepository; + +public class Reservation { + private final DiscountRepository discountRepository; + private final DecemberDate decemberDate; + private final OrderRepository orderRepository; + + private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) { + this.decemberDate = decemberDate; + this.orderRepository = orderRepository; + this.discountRepository = DiscountRepository.of(decemberDate, orderRepository); + } + + public static Reservation of(DecemberDate decemberDate, OrderRepository menus) { + return new Reservation(decemberDate, menus); + } + + public Menu calculateGift() { + return discountRepository.calculateGift(); + } + + public Money calculateTotalOriginalMoney() { + return orderRepository.calculateTotalPrice(); + } + + public Money calculateTotalDiscountMoney() { + return discountRepository.calculateTotalDiscountMoney(); + } + + public Money calculateTotalFinalMoney() { + Money discountMoney = calculateTotalDiscountMoney(); + if (discountRepository.hasGiftDiscount()) { + discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice()); + } + return calculateTotalOriginalMoney().minus(discountMoney); + } + + public EventBadge calculateEventBadge() { + Money totalDiscountMoney = calculateTotalDiscountMoney(); + return EventBadge.findByTotalDiscountPrice(totalDiscountMoney); + } + + public DiscountRepository getDiscountRepository() { + return discountRepository; + } + + public DecemberDate getDecemberDate() { + return decemberDate; + } + + public OrderRepository getOrderRepository() { + return orderRepository; + } +}
Java
ํด๋ž˜์Šค ์ด๋ฆ„์„ ์ง€์„๋•Œ Repository๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ๊ฐ€์ง€๋Š” ๊ด€๋ก€์ ์ธ ๊ตญ๋ฃฐ(?)์ด ์žˆ์–ด์„œ ํ•ด๋‹น ๋‹จ์–ด๋ฅผ ์“ฐ์‹ ๊ฑด๊ฐ€์š”? ์•„๋‹ˆ๋ฉด ๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์—์„œ ์ง€์œผ์‹ ๊ฑด๊ฐ€์š”! (์ˆœ์ˆ˜ ๊ถ๊ธˆ์ฆ์ž…๋‹ˆ๋‹ค!)
@@ -0,0 +1,59 @@ +package christmas.domain; + +import christmas.domain.discount.DiscountRepository; +import christmas.domain.discount.GiftDiscount; +import christmas.domain.menu.Menu; +import christmas.domain.menu.OrderRepository; + +public class Reservation { + private final DiscountRepository discountRepository; + private final DecemberDate decemberDate; + private final OrderRepository orderRepository; + + private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) { + this.decemberDate = decemberDate; + this.orderRepository = orderRepository; + this.discountRepository = DiscountRepository.of(decemberDate, orderRepository); + } + + public static Reservation of(DecemberDate decemberDate, OrderRepository menus) { + return new Reservation(decemberDate, menus); + } + + public Menu calculateGift() { + return discountRepository.calculateGift(); + } + + public Money calculateTotalOriginalMoney() { + return orderRepository.calculateTotalPrice(); + } + + public Money calculateTotalDiscountMoney() { + return discountRepository.calculateTotalDiscountMoney(); + } + + public Money calculateTotalFinalMoney() { + Money discountMoney = calculateTotalDiscountMoney(); + if (discountRepository.hasGiftDiscount()) { + discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice()); + } + return calculateTotalOriginalMoney().minus(discountMoney); + } + + public EventBadge calculateEventBadge() { + Money totalDiscountMoney = calculateTotalDiscountMoney(); + return EventBadge.findByTotalDiscountPrice(totalDiscountMoney); + } + + public DiscountRepository getDiscountRepository() { + return discountRepository; + } + + public DecemberDate getDecemberDate() { + return decemberDate; + } + + public OrderRepository getOrderRepository() { + return orderRepository; + } +}
Java
๋ถ„๋ฆฌ๊ฐ€ ์ž˜๋˜์„œ ๊ทธ๋Ÿฐ๊ฐ€ ํ• ์ธ ๋‚ ์งœ ์ฃผ๋ฌธ์„ ํ•œ๊ณณ์— ๋„ฃ์–ด๋„ ๊ฐ€๋…์„ฑ์ด ๋งค์šฐ ๊น”๋”ํ•˜๋„ค์š”,, ๊ฐํƒ„ํ•˜๊ณ ๊ฐ‘๋‹ˆ๋‹ค
@@ -0,0 +1,45 @@ +package christmas.domain.menu; + +import christmas.message.ExceptionMessage; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public record Order(Menu menu, int count) { + private static final String FORMAT_MENU_ORDER = "([๊ฐ€-ํžฃ]+)-(\\d+)"; + private static final Pattern PATTERN_MENU = Pattern.compile(FORMAT_MENU_ORDER); + private static final int NAME_INDEX = 1; + private static final int COUNT_INDEX = 2; + + public Order { + validateNotNull(menu); + validateCount(count); + } + + public static Order createByString(String menuString) { + Matcher matcher = PATTERN_MENU.matcher(menuString); + validateFormat(matcher); + Menu menu = Menu.findByName(matcher.group(NAME_INDEX)); + int count = Integer.parseInt(matcher.group(COUNT_INDEX)); + return new Order(menu, count); + } + + private static void validateFormat(Matcher matcher) { + if (matcher.matches()) { + return; + } + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + + private static void validateNotNull(Menu menu) { + if (Objects.isNull(menu)) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + } + + private static void validateCount(int count) { + if (count <= 0) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + } +}
Java
์ƒ์ˆ˜์™€ Matcher๋ฅผ ํ†ตํ•ด ์ •๊ทœ์‹์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ‘œํ˜„ํ•œ๊ฒŒ ์ธ์ƒ๊นŠ์–ด์š” !
@@ -0,0 +1,45 @@ +package christmas.domain.menu; + +import christmas.message.ExceptionMessage; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public record Order(Menu menu, int count) { + private static final String FORMAT_MENU_ORDER = "([๊ฐ€-ํžฃ]+)-(\\d+)"; + private static final Pattern PATTERN_MENU = Pattern.compile(FORMAT_MENU_ORDER); + private static final int NAME_INDEX = 1; + private static final int COUNT_INDEX = 2; + + public Order { + validateNotNull(menu); + validateCount(count); + } + + public static Order createByString(String menuString) { + Matcher matcher = PATTERN_MENU.matcher(menuString); + validateFormat(matcher); + Menu menu = Menu.findByName(matcher.group(NAME_INDEX)); + int count = Integer.parseInt(matcher.group(COUNT_INDEX)); + return new Order(menu, count); + } + + private static void validateFormat(Matcher matcher) { + if (matcher.matches()) { + return; + } + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + + private static void validateNotNull(Menu menu) { + if (Objects.isNull(menu)) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + } + + private static void validateCount(int count) { + if (count <= 0) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + } +}
Java
์›๋ž˜ Matcher์™€ Pattern์œผ๋กœ ์ •๊ทœ์‹์„ ๊ด€๋ฆฌํ•˜๋Š”๊ฒŒ ์ •์„์ธ๊ฐ€์š”? ์ด๋Ÿฐ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ๋Š”์ง€ ์ฒ˜์Œ์•Œ์•˜์Šต๋‹ˆ๋‹ค! ๊ต‰์žฅํžˆ ๊น”๋”ํ•œ๊ฒƒ๊ฐ™์•„์š”
@@ -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
์•„ํ•˜ ๊ทธ๋Ÿฐ ๋ฐฉ๋ฒ•๋„ ์žˆ๊ตฐ์š”! ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค!๐Ÿ‘
@@ -0,0 +1,59 @@ +package christmas.domain; + +import christmas.domain.discount.DiscountRepository; +import christmas.domain.discount.GiftDiscount; +import christmas.domain.menu.Menu; +import christmas.domain.menu.OrderRepository; + +public class Reservation { + private final DiscountRepository discountRepository; + private final DecemberDate decemberDate; + private final OrderRepository orderRepository; + + private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) { + this.decemberDate = decemberDate; + this.orderRepository = orderRepository; + this.discountRepository = DiscountRepository.of(decemberDate, orderRepository); + } + + public static Reservation of(DecemberDate decemberDate, OrderRepository menus) { + return new Reservation(decemberDate, menus); + } + + public Menu calculateGift() { + return discountRepository.calculateGift(); + } + + public Money calculateTotalOriginalMoney() { + return orderRepository.calculateTotalPrice(); + } + + public Money calculateTotalDiscountMoney() { + return discountRepository.calculateTotalDiscountMoney(); + } + + public Money calculateTotalFinalMoney() { + Money discountMoney = calculateTotalDiscountMoney(); + if (discountRepository.hasGiftDiscount()) { + discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice()); + } + return calculateTotalOriginalMoney().minus(discountMoney); + } + + public EventBadge calculateEventBadge() { + Money totalDiscountMoney = calculateTotalDiscountMoney(); + return EventBadge.findByTotalDiscountPrice(totalDiscountMoney); + } + + public DiscountRepository getDiscountRepository() { + return discountRepository; + } + + public DecemberDate getDecemberDate() { + return decemberDate; + } + + public OrderRepository getOrderRepository() { + return orderRepository; + } +}
Java
๊ด€๋ก€๊ฐ€ ์žˆ๋Š”์ง€๋Š” ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ ๋Œ€๋ถ€๋ถ„๋“ค Repository ๋ผ๊ณ  ํ•˜๋”๋ผ๊ณ ์š”! ํŠน์ • ๊ทœ์น™์ด ์žˆ๋Š”์ง€๋Š” ์ €๋„ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋„ค์š”! ๐Ÿ˜‚
@@ -0,0 +1,45 @@ +package christmas.domain.menu; + +import christmas.message.ExceptionMessage; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public record Order(Menu menu, int count) { + private static final String FORMAT_MENU_ORDER = "([๊ฐ€-ํžฃ]+)-(\\d+)"; + private static final Pattern PATTERN_MENU = Pattern.compile(FORMAT_MENU_ORDER); + private static final int NAME_INDEX = 1; + private static final int COUNT_INDEX = 2; + + public Order { + validateNotNull(menu); + validateCount(count); + } + + public static Order createByString(String menuString) { + Matcher matcher = PATTERN_MENU.matcher(menuString); + validateFormat(matcher); + Menu menu = Menu.findByName(matcher.group(NAME_INDEX)); + int count = Integer.parseInt(matcher.group(COUNT_INDEX)); + return new Order(menu, count); + } + + private static void validateFormat(Matcher matcher) { + if (matcher.matches()) { + return; + } + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + + private static void validateNotNull(Menu menu) { + if (Objects.isNull(menu)) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + } + + private static void validateCount(int count) { + if (count <= 0) { + throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER); + } + } +}
Java
๋‹ค๋ฅธ๋ถ„๋“ค์€ ์ •๊ทœํ‘œํ˜„์‹์„ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ ์ €๋Š” ์ด๋Ÿฌํ•œ ๋ฐฉ์‹๋Œ€๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค! ใ…Žใ…Ž
@@ -0,0 +1,54 @@ +package christmas; + +import christmas.domain.DecemberDate; +import christmas.domain.menu.OrderRepository; +import christmas.domain.Reservation; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.function.Supplier; + +public class ChristmasController { + public static void run() { + Reservation reservation = initReservation(); + printOrderInformation(reservation); + printDiscountInformation(reservation); + } + + private static Reservation initReservation() { + OutputView.printWelcomeMessage(); + DecemberDate date = initDecemberDate(); + OrderRepository orderRepository = initOrderRepository(); + return Reservation.of(date, orderRepository); + } + + private static DecemberDate initDecemberDate() { + return receiveValidatedValue(() -> new DecemberDate(InputView.readDate())); + } + + private static OrderRepository initOrderRepository() { + return receiveValidatedValue(() -> OrderRepository.createByString(InputView.readOrders())); + } + + private static <T> T receiveValidatedValue(Supplier<T> inputMethod) { + try { + return inputMethod.get(); + } catch (IllegalArgumentException exception) { + OutputView.printException(exception); + return receiveValidatedValue(inputMethod); + } + } + + private static void printOrderInformation(Reservation reservation) { + OutputView.printEventPreMessage(reservation.getDecemberDate()); + OutputView.printOrderMenus(reservation.getOrderRepository()); + } + + private static void printDiscountInformation(Reservation reservation) { + OutputView.printOriginalPrice(reservation.calculateTotalOriginalMoney()); + OutputView.printGiftMenu(reservation.calculateGift()); + OutputView.printDiscountLogs(reservation.getDiscountRepository()); + OutputView.printTotalDiscountMoney(reservation.calculateTotalDiscountMoney()); + OutputView.printToTalFinalPrice(reservation.calculateTotalFinalMoney()); + OutputView.printEventBadge(reservation.calculateEventBadge()); + } +}
Java
๋žŒ๋‹ค์‹์„ ํ™œ์šฉํ•˜์—ฌ ๋ฐ˜๋ณต์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ํ•œ ๋ฒˆ๋งŒ ํ•˜๋Š” ๋ฐฉ์‹๋„ ์žˆ๊ตฐ์š”. ๋ฐฐ์šฐ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค. ์ข‹์€ ๋ฐฉ์‹์ธ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,59 @@ +package christmas.domain; + +import christmas.domain.discount.DiscountRepository; +import christmas.domain.discount.GiftDiscount; +import christmas.domain.menu.Menu; +import christmas.domain.menu.OrderRepository; + +public class Reservation { + private final DiscountRepository discountRepository; + private final DecemberDate decemberDate; + private final OrderRepository orderRepository; + + private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) { + this.decemberDate = decemberDate; + this.orderRepository = orderRepository; + this.discountRepository = DiscountRepository.of(decemberDate, orderRepository); + } + + public static Reservation of(DecemberDate decemberDate, OrderRepository menus) { + return new Reservation(decemberDate, menus); + } + + public Menu calculateGift() { + return discountRepository.calculateGift(); + } + + public Money calculateTotalOriginalMoney() { + return orderRepository.calculateTotalPrice(); + } + + public Money calculateTotalDiscountMoney() { + return discountRepository.calculateTotalDiscountMoney(); + } + + public Money calculateTotalFinalMoney() { + Money discountMoney = calculateTotalDiscountMoney(); + if (discountRepository.hasGiftDiscount()) { + discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice()); + } + return calculateTotalOriginalMoney().minus(discountMoney); + } + + public EventBadge calculateEventBadge() { + Money totalDiscountMoney = calculateTotalDiscountMoney(); + return EventBadge.findByTotalDiscountPrice(totalDiscountMoney); + } + + public DiscountRepository getDiscountRepository() { + return discountRepository; + } + + public DecemberDate getDecemberDate() { + return decemberDate; + } + + public OrderRepository getOrderRepository() { + return orderRepository; + } +}
Java
์ œ๊ฐ€ ์•Œ๊ธฐ๋กœ๋Š” Repositoy๋Š” ์ฃผ๋กœ ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ๊ณผ ๊ด€๋ จํ•œ ๊ฐ์ฒด๋กœ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ์™ธ๋ถ€์˜ ์‹œ์Šคํ…œ๊ณผ ์—ฐ๊ฒฐํ•˜๋Š” ์žฌ์‚ฌ์šฉ๋˜๋Š” ๋กœ์ง์„ ์ฃผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,59 @@ +package christmas.domain; + +import christmas.domain.discount.DiscountRepository; +import christmas.domain.discount.GiftDiscount; +import christmas.domain.menu.Menu; +import christmas.domain.menu.OrderRepository; + +public class Reservation { + private final DiscountRepository discountRepository; + private final DecemberDate decemberDate; + private final OrderRepository orderRepository; + + private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) { + this.decemberDate = decemberDate; + this.orderRepository = orderRepository; + this.discountRepository = DiscountRepository.of(decemberDate, orderRepository); + } + + public static Reservation of(DecemberDate decemberDate, OrderRepository menus) { + return new Reservation(decemberDate, menus); + } + + public Menu calculateGift() { + return discountRepository.calculateGift(); + } + + public Money calculateTotalOriginalMoney() { + return orderRepository.calculateTotalPrice(); + } + + public Money calculateTotalDiscountMoney() { + return discountRepository.calculateTotalDiscountMoney(); + } + + public Money calculateTotalFinalMoney() { + Money discountMoney = calculateTotalDiscountMoney(); + if (discountRepository.hasGiftDiscount()) { + discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice()); + } + return calculateTotalOriginalMoney().minus(discountMoney); + } + + public EventBadge calculateEventBadge() { + Money totalDiscountMoney = calculateTotalDiscountMoney(); + return EventBadge.findByTotalDiscountPrice(totalDiscountMoney); + } + + public DiscountRepository getDiscountRepository() { + return discountRepository; + } + + public DecemberDate getDecemberDate() { + return decemberDate; + } + + public OrderRepository getOrderRepository() { + return orderRepository; + } +}
Java
์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์…จ๋Š”๋ฐ ํ˜น์‹œ ์ด ๋ฉ”์„œ๋“œ์˜ ์žฅ์ ์ด ์–ด๋–ค ์ ์ธ์ง€ ์•Œ ์ˆ˜ ์žˆ์„๊นŒ์š”? (๊ถ๊ธˆ์ฆ ์ž…๋‹ˆ๋‹ค.)
@@ -0,0 +1,29 @@ +package christmas.domain.discount; + +import christmas.domain.DecemberDate; +import christmas.domain.Money; +import java.util.List; + +public class SpecialDiscount { + public static final String NAME = "ํŠน๋ณ„ ํ• ์ธ"; + private static final int DISCOUNT_AMOUNT = 1000; + private static final List<DecemberDate> specialDates = List.of( + new DecemberDate(3), + new DecemberDate(10), + new DecemberDate(17), + new DecemberDate(24), + new DecemberDate(25), + new DecemberDate(31) + ); + + public static Money calculateDiscountAmount(DecemberDate date) { + if (isSpecialDate(date)) { + return new Money(DISCOUNT_AMOUNT); + } + return new Money(0); + } + + private static boolean isSpecialDate(DecemberDate date) { + return specialDates.contains(date); + } +}
Java
7๋กœ ๋‚˜๋ˆ„์–ด์„œ 3์ด ๋˜๋Š” ๊ฒฝ์šฐ๋กœ ํ‘œํ˜„ํ•˜๋ฉด ์ฝ”๋“œ์˜ ๊ธธ์ด๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ ๋‚˜๋จธ์ง€ ๊ฐ’์ด ํ•˜๋‚˜์˜ ์š”์ผ์— ๋Œ€์‘๋˜๋ฏ€๋กœ, ๋‚˜๋จธ์ง€ ๊ฐ’์„ ๊ฐ๊ฐ์˜ ์š”์ผ๊ณผ ๋Œ€์‘์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•๋„ ํšจ๊ณผ์ ์ผ ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,133 @@ +## ๊ธฐ๋Šฅ ๋ชฉ๋ก + +- [X] ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘ ์‹œ, "์•ˆ๋…•ํ•˜์„ธ์š”! ์šฐํ…Œ์ฝ” ์‹๋‹น 12์›” ์ด๋ฒคํŠธ ํ”Œ๋ž˜๋„ˆ์ž…๋‹ˆ๋‹ค." ์ถœ๋ ฅ + +- [X] ๋ฐฉ๋ฌธ ๋‚ ์งœ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - [X] "12์›” ์ค‘ ์‹๋‹น ์˜ˆ์ƒ ๋ฐฉ๋ฌธ ๋‚ ์งœ๋Š” ์–ธ์ œ์ธ๊ฐ€์š”? (์ˆซ์ž๋งŒ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”!)" ์ถœ๋ ฅ + - [X] ์ˆซ์ž๋กœ๋งŒ ์ž…๋ ฅ ๋ฐ›์•˜๋Š”์ง€ ํ™•์ธ + - [X] ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ, NumberFormatException ๋ฐœ์ƒ + - [X] "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”." ์ถœ๋ ฅ ํ›„ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - [X] 1 ~ 31 ๋ฒ”์œ„ ๋‚ด์ธ์ง€ ํ™•์ธ + - [X] ๋ฒ”์œ„ ์™ธ์˜ ๊ฐ’ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ, IllegalArgumentException ๋ฐœ์ƒ + - [X] "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”." ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅํ›„ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ + +- [X] ๋ฉ”๋‰ด ์ž…๋ ฅ ๋ฐ›๊ธฐ + - [X] enum์œผ๋กœ ๋ฉ”๋‰ด ๊ตฌํ˜„ + - [X] "์ฃผ๋ฌธํ•˜์‹ค ๋ฉ”๋‰ด๋ฅผ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜๋ฅผ ์•Œ๋ ค ์ฃผ์„ธ์š”. (e.g. ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€-2,๋ ˆ๋“œ์™€์ธ-1,์ดˆ์ฝ”์ผ€์ดํฌ-1)" ์ถœ๋ ฅ + - [] ์˜ฌ๋ฐ”๋ฅธ ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅ ๋ฐ›์•˜๋Š”์ง€ ํ™•์ธ + - [X] ๋ฉ”๋‰ดํŒ์— ์—†๋Š” ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅ๋ฐ›์„ ๊ฒฝ์šฐ, IllegalArgumentException ๋ฐœ์ƒ + - [X] "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”." ์ถœ๋ ฅ ํ›„ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - [X] ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ, NumberFormatException ๋ฐœ์ƒ + - [X] "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”." ์ถœ๋ ฅ ํ›„ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - [X] ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๊ฐ€ 1 ์ด์ƒ์˜ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ, IllegalArgumentException ๋ฐœ์ƒ + - [X] "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”." ์ถœ๋ ฅ ํ›„ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - [X] ๋ฉ”๋‰ด ํ˜•์‹์ด ์˜ˆ์‹œ์™€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ, IllegalArgumentException ๋ฐœ์ƒ + - [X] "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”." ์ถœ๋ ฅ ํ›„ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - [X] ์ค‘๋ณต ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ, IllegalArgumentException ๋ฐœ์ƒ + - [X] "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”." ์ถœ๋ ฅ ํ›„ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - [X] ์Œ๋ฃŒ ๋ฉ”๋‰ด๋งŒ ์ฃผ๋ฌธํ•œ ๊ฒฝ์šฐ, IllegalArgumentException ๋ฐœ์ƒ + - [X] "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”." ์ถœ๋ ฅ ํ›„ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ + +- [X] "12์›” n์ผ์— ์šฐํ…Œ์ฝ” ์‹๋‹น์—์„œ ๋ฐ›์„ ์ด๋ฒคํŠธ ํ˜œํƒ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!" ์ถœ๋ ฅ + +- [X] ์ฃผ๋ฌธ ๋ฉ”๋‰ด ์ถœ๋ ฅ ํ•˜๊ธฐ + - [X] "<์ฃผ๋ฌธ ๋ฉ”๋‰ด>" ์ถœ๋ ฅ + - [X] "๋ฉ”๋‰ด๋ช… n๊ฐœ" ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅ + +- [X] ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก ์ถœ๋ ฅํ•˜๊ธฐ + - [X] "<ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก>" ์ถœ๋ ฅ + - [X] ์ด์ฃผ๋ฌธ ๊ธˆ์•ก ๊ณ„์‚ฐ ํ›„ ์ถœ๋ ฅ + +- [X] ์ด๋ฒคํŠธ ์˜ˆ์™ธ์ฒ˜๋ฆฌํ•˜๊ธฐ + - [X] ์ด์ฃผ๋ฌธ ๊ธˆ์•ก 10,000์› ์ด์ƒ๋ถ€ํ„ฐ ์ด๋ฒคํŠธ ์ ์šฉ + - [X] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•  ๊ฒฝ์šฐ, ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Œ + - [X] ๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธ ๊ฐ€๋Šฅ + +- [X] ์ด๋ฒคํŠธ ์ ์šฉํ•˜๊ธฐ + - [X] ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ ํ•ด๋‹น ์—ฌ๋ถ€ ํ™•์ธ ๋ฐ ์ ์šฉํ•˜๊ธฐ + - [X] ํ‰์ผ ํ• ์ธ ํ•ด๋‹น ์—ฌ๋ถ€ ํ™•์ธ ๋ฐ ์ ์šฉํ•˜๊ธฐ + - [X] ์ฃผ๋ง ํ• ์ธ ํ•ด๋‹น ์—ฌ๋ถ€ ํ™•์ธ ๋ฐ ์ ์šฉํ•˜๊ธฐ + - [X] ํŠน๋ณ„ ํ• ์ธ ํ•ด๋‹น ์—ฌ๋ถ€ ํ™•์ธ ๋ฐ ์ ์šฉํ•˜๊ธฐ + - [X] ์ฆ์ • ์ด๋ฒคํŠธ ํ•ด๋‹น ์—ฌ๋ถ€ ํ™•์ธ ๋ฐ ์ ์šฉํ•˜๊ธฐ + +- [X] ์ฆ์ • ๋ฉ”๋‰ด ์ถœ๋ ฅํ•˜๊ธฐ + - [X] ๋งŒ์•ฝ ์ƒดํŽ˜์ธ ์ฆ์ •์ด ํ•ด๋‹น๋˜๋ฉด "์ƒดํŽ˜์ธ 1๊ฐœ" ์ถœ๋ ฅ + - [X] ์•„๋‹ˆ๋ฉด "์—†์Œ" ์ถœ๋ ฅ + +- [X] ํ˜œํƒ ๋‚ด์—ญ ์ถœ๋ ฅํ•˜๊ธฐ + - [X] ๊ณ ๊ฐ์—๊ฒŒ ์ ์šฉ๋œ ์ด๋ฒคํŠธ ๋‚ด์—ญ๋งŒ ์ถœ๋ ฅ + - [X] ์ ์šฉ๋œ ์ด๋ฒคํŠธ๊ฐ€ ํ•˜๋‚˜๋„ ์—†๋‹ค๋ฉด "์—†์Œ" ์ถœ๋ ฅ + +- [X] ์ดํ˜œํƒ ๊ธˆ์•ก ์ถœ๋ ฅํ•˜๊ธฐ + - [X] ์ดํ˜œํƒ ๊ธˆ์•ก ๊ณ„์‚ฐ ํ›„ "-n์›" ์ถœ๋ ฅ + +- [X] ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก ์ถœ๋ ฅํ•˜๊ธฐ + - [X] ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก ๊ณ„์‚ฐ ํ›„ "n์›" ์ถœ๋ ฅ + +- [X] ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ์ถœ๋ ฅํ•˜๊ธฐ + - [X] ํ˜œํƒ๊ธˆ์•ก์— ๋”ฐ๋ผ "๋ณ„, ํŠธ๋ฆฌ, ์‚ฐํƒ€" ์ถœ๋ ฅ + - [X] ์—†์œผ๋ฉด "์—†์Œ" ์ถœ๋ ฅ + +## ๐ŸŽฏ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ + +- JDK 17 ๋ฒ„์ „์—์„œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ด์•ผ ํ•œ๋‹ค. **JDK 17์—์„œ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ 0์  ์ฒ˜๋ฆฌํ•œ๋‹ค.** +- ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์˜ ์‹œ์ž‘์ ์€ `Application`์˜ `main()`์ด๋‹ค. +- `build.gradle` ํŒŒ์ผ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๊ณ , ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. +- [Java ์ฝ”๋“œ ์ปจ๋ฒค์…˜](https://github.com/woowacourse/woowacourse-docs/tree/master/styleguide/java) ๊ฐ€์ด๋“œ๋ฅผ ์ค€์ˆ˜ํ•˜๋ฉฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•œ๋‹ค. +- ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ ์‹œ `System.exit()`๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„์ด ์™„๋ฃŒ๋˜๋ฉด `ApplicationTest`์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๊ฐ€ ์„ฑ๊ณตํ•ด์•ผ ํ•œ๋‹ค. **ํ…Œ์ŠคํŠธ๊ฐ€ ์‹คํŒจํ•  ๊ฒฝ์šฐ 0์  ์ฒ˜๋ฆฌํ•œ๋‹ค.** +- ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ์—์„œ ๋‹ฌ๋ฆฌ ๋ช…์‹œํ•˜์ง€ ์•Š๋Š” ํ•œ ํŒŒ์ผ, ํŒจํ‚ค์ง€ ์ด๋ฆ„์„ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ์ด๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. +- indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ 3์ด ๋„˜์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. 2๊นŒ์ง€๋งŒ ํ—ˆ์šฉํ•œ๋‹ค. + - ์˜ˆ๋ฅผ ๋“ค์–ด while๋ฌธ ์•ˆ์— if๋ฌธ์ด ์žˆ์œผ๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” 2์ด๋‹ค. + - ํžŒํŠธ: indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ ์ค„์ด๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์€ ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๋ฅผ ๋ถ„๋ฆฌํ•˜๋ฉด ๋œ๋‹ค. +- 3ํ•ญ ์—ฐ์‚ฐ์ž๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. +- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)์˜ ๊ธธ์ด๊ฐ€ 15๋ผ์ธ์„ ๋„˜์–ด๊ฐ€์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. + - ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ํ•˜๋„๋ก ์ตœ๋Œ€ํ•œ ์ž‘๊ฒŒ ๋งŒ๋“ค์–ด๋ผ. +- JUnit 5์™€ AssertJ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณธ์ธ์ด ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก์ด ์ •์ƒ ๋™์ž‘ํ•จ์„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ ํ™•์ธํ•œ๋‹ค. +- else ์˜ˆ์•ฝ์–ด๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. + - ํžŒํŠธ: if ์กฐ๊ฑด์ ˆ์—์„œ ๊ฐ’์„ return ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด else๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. + - else๋ฅผ ์“ฐ์ง€ ๋ง๋ผ๊ณ  ํ•˜๋‹ˆ switch/case๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”๋ฐ switch/case๋„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ๋„๋ฉ”์ธ ๋กœ์ง์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๋‹จ, UI(System.out, System.in, Scanner) ๋กœ์ง์€ ์ œ์™ธํ•œ๋‹ค. + - ํ•ต์‹ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์™€ UI๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋กœ์ง์„ ๋ถ„๋ฆฌํ•ด ๊ตฌํ˜„ํ•œ๋‹ค. +- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ `IllegalArgumentException`๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ณ , "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ ํ›„ ๊ทธ ๋ถ€๋ถ„๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋‹ค์‹œ ๋ฐ›๋Š”๋‹ค. + - `Exception`์ด ์•„๋‹Œ `IllegalArgumentException`, `IllegalStateException` ๋“ฑ๊ณผ ๊ฐ™์€ ๋ช…ํ™•ํ•œ ์œ ํ˜•์„ ์ฒ˜๋ฆฌํ•œ๋‹ค. + +### ์ถ”๊ฐ€๋œ ์š”๊ตฌ ์‚ฌํ•ญ + +- ์•„๋ž˜ ์žˆ๋Š” `InputView`, `OutputView` ํด๋ž˜์Šค๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์ž…์ถœ๋ ฅ ํด๋ž˜์Šค๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. + - ์ž…๋ ฅ๊ณผ ์ถœ๋ ฅ์„ ๋‹ด๋‹นํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋ณ„๋„๋กœ ๊ตฌํ˜„ํ•œ๋‹ค. + - ํ•ด๋‹น ํด๋ž˜์Šค์˜ ํŒจํ‚ค์ง€, ํด๋ž˜์Šค๋ช…, ๋ฉ”์„œ๋“œ์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…๊ณผ ์‹œ๊ทธ๋‹ˆ์ฒ˜๋Š” ์ž์œ ๋กญ๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. + ```java + public class InputView { + public int readDate() { + System.out.println("12์›” ์ค‘ ์‹๋‹น ์˜ˆ์ƒ ๋ฐฉ๋ฌธ ๋‚ ์งœ๋Š” ์–ธ์ œ์ธ๊ฐ€์š”? (์ˆซ์ž๋งŒ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”!)"); + String input = Console.readLine(); + // ... + } + // ... + } + ``` + ```java + public class OutputView { + public void printMenu() { + System.out.println("<์ฃผ๋ฌธ ๋ฉ”๋‰ด>"); + // ... + } + // ... + } + ``` + +### ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ + +- `camp.nextstep.edu.missionutils`์—์„œ ์ œ๊ณตํ•˜๋Š” `Console` API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. + - ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•˜๋Š” ๊ฐ’์€ `camp.nextstep.edu.missionutils.Console`์˜ `readLine()`์„ ํ™œ์šฉํ•œ๋‹ค. + +--- + +## โœ๏ธ ๊ณผ์ œ ์ง„ํ–‰ ์š”๊ตฌ ์‚ฌํ•ญ + +- ๋ฏธ์…˜์€ [java-christmas-6](https://github.com/woowacourse-precourse/java-christmas-6) ์ €์žฅ์†Œ๋ฅผ ๋น„๊ณต๊ฐœ ์ €์žฅ์†Œ๋กœ ์ƒ์„ฑํ•ด ์‹œ์ž‘ํ•œ๋‹ค. +- **๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „ `docs/README.md`์— ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ์ •๋ฆฌ**ํ•ด ์ถ”๊ฐ€ํ•œ๋‹ค. +- **Git์˜ ์ปค๋ฐ‹ ๋‹จ์œ„๋Š” ์•ž ๋‹จ๊ณ„์—์„œ `docs/README.md`์— ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก ๋‹จ์œ„**๋กœ ์ถ”๊ฐ€ํ•œ๋‹ค. + - [์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€ ์ปจ๋ฒค์…˜](https://gist.github.com/stephenparish/9941e89d80e2bc58a153) ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ๊ณ ํ•ด ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. +- ๊ณผ์ œ ์ง„ํ–‰ ๋ฐ ์ œ์ถœ ๋ฐฉ๋ฒ•์€ [ํ”„๋ฆฌ์ฝ”์Šค ๊ณผ์ œ ์ œ์ถœ](https://docs.google.com/document/d/1cmg0VpPkuvdaetxwp4hnyyFC_G-1f2Gr8nIDYIWcKC8/edit?usp=sharing) ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.
Unknown
๊ผผ๊ผผํ•œ ๊ธฐ๋Šฅ๋ชฉ๋ก ์ •๋ฆฌ ๐Ÿ‘๐Ÿ‘ PR ๋ณธ๋ฌธ์— ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ๋ฆฌ๋ทฐํ•˜๋Š” ์‚ฌ๋žŒ์ด ์•Œ์•„์•ผํ•  ์ ์ด๋‚˜ ์‹ ๊ฒฝ์จ์„œ ๋ด์•ผํ•  ์ ์— ๋Œ€ํ•ด ์–ธ๊ธ‰ํ•ด์ฃผ์‹œ๋ฉด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž
@@ -0,0 +1,23 @@ +package christmas.constant; + +public class Number { + public static final int ZERO = 0; + public static final int ONE = 1; + public static final int TWO = 2; + public static final int THREE = 3; + public static final int SEVEN = 7; + public static final int TWENTY = 20; + public static final int HUNDRED = 100; + public static final int THOUSAND = 1000; + public static final int TEN_THOUSAND = 10000; + public static final int MIN_DATE = 1; + public static final int MAX_DATE = 31; + public static final int CHRISTMAS = 25; + public static final int YEAR = 2023; + public static final int FREE_GIFT = 120000; + public static final int STAR = 5000; + public static final int TREE = 10000; + public static final int SANTA = 20000; + + +}
Java
ํ˜น์‹œ ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“œ์‹  ์ด์œ ๋Š” ๋ญ˜๊นŒ์š”? `์—ฐ๊ด€์„ฑ์ด ์žˆ๋Š” ์ƒ์ˆ˜๋Š” static final ๋Œ€์‹  enum์„ ํ™œ์šฉํ•œ๋‹ค` ํ•ด๋‹น ๋ฌธ๊ตฌ ๋•Œ๋ฌธ์ด๋ผ๋ฉด, ์ƒ์ˆ˜๋ผ๋ฆฌ ์—ฐ๊ด€์„ฑ๋„ ๋‚ฎ๊ณ , Enum๋„ ์•„๋‹ˆ๊ตฐ์š”... 3์„ THREE๋ผ๊ณ  ๋„ค์ด๋ฐํ•˜๋Š” ๊ฒƒ๋„ ๋‹ค์†Œ ์•„์‰ฝ์Šต๋‹ˆ๋‹ค. ๋งฅ๋ฝ์ƒ ์–ด๋–ค ์—ญํ• ์„ ํ•˜๋Š”์ง€ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ์ด ๋” ์ข‹๊ฒ ๋„ค์š”
@@ -0,0 +1,6 @@ +package christmas.constant.message; + +public class InputMessage { + public static final String DATE = "12์›” ์ค‘ ์‹๋‹น ์˜ˆ์ƒ ๋ฐฉ๋ฌธ ๋‚ ์งœ๋Š” ์–ธ์ œ์ธ๊ฐ€์š”? (์ˆซ์ž๋งŒ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”!)"; + public static final String ORDER = "์ฃผ๋ฌธํ•˜์‹ค ๋ฉ”๋‰ด๋ฅผ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜๋ฅผ ์•Œ๋ ค ์ฃผ์„ธ์š”. (e.g. ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€-2,๋ ˆ๋“œ์™€์ธ-1,์ดˆ์ฝ”์ผ€์ดํฌ-1)"; +}
Java
์ œ ์ƒ๊ฐ์—” ๋ฉ”์„ธ์ง€๋“ค์€ ๊ตณ์ด ์ƒ์ˆ˜ํ™” ์‹œํ‚ค์ง€ ์•Š์•„๋„ ํ•˜๋‚˜์˜ ๋ฉ”์„œ๋“œ์—๋งŒ ์“ฐ์ด๊ณ , ๋ฉ”์„ธ์ง€๋ฅผ ์ฝ์—ˆ์„ ๋•Œ ์–ด๋–ค ์šฉ๋„์ธ์ง€ ์ถฉ๋ถ„ํžˆ ์•Œ ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ์ง€๊ธˆ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ์—” ๊ตณ์ด ์ƒ์ˆ˜ํ™” ์‹œํ‚ค์ง€ ์•Š๋Š” ํŽธ์ธ๋ฐ ์Šน์ฒ ๋‹˜์€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”? (OutputMessage๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค ใ…Žใ…Ž)
@@ -0,0 +1,87 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.domain.calculator.PriceCalculator; +import christmas.view.*; + +public class EventController { + public void event() { + printStart(); + Date date = getDate(); + Order order = getOrder(); + printPreview(date); + printOrder(order); + Price price = getBeforeDiscount(order); + printBeforeDiscount(price); + Event event = applyEvent(date, order, price); + printGift(event); + printEvent(event); + printAllBenefit(event); + printAfterDiscount(event, price); + printEventBadge(event); + } + + public void printStart() { + OutputHelloView outputHello = new OutputHelloView(); + outputHello.outputHello(); + } + + public Date getDate() { + InputDateView inputDateView = new InputDateView(); + return inputDateView.inputDate(); + } + + public Order getOrder() { + InputOrderView inputOrderView = new InputOrderView(); + return inputOrderView.inputOrder(); + } + + public void printPreview(Date date) { + OutputPreviewView outputPreviewView = new OutputPreviewView(); + outputPreviewView.outputPreview(date); + } + + public void printOrder(Order order) { + OutputOrderView outputOrderView = new OutputOrderView(); + outputOrderView.outputOrder(order); + } + + public Price getBeforeDiscount(Order order) { + PriceCalculator priceCalculator = new PriceCalculator(); + return priceCalculator.calculatePrice(order); + } + + public void printBeforeDiscount(Price price) { + OutputBeforeDiscountView outputBeforeDiscountView = new OutputBeforeDiscountView(); + outputBeforeDiscountView.outputBeforeDiscount(price); + } + + public Event applyEvent(Date date, Order order, Price price) { + return new Event(date, order, price); + } + + public void printGift(Event event) { + OutputGiftView outputGiftView = new OutputGiftView(); + outputGiftView.outputGift(event); + } + + public void printEvent(Event event) { + OutputEventView outputEventView = new OutputEventView(); + outputEventView.outputEvent(event); + } + + public void printAllBenefit(Event event) { + OutputAllBenefitView outputAllBenefitView = new OutputAllBenefitView(); + outputAllBenefitView.outputAllBenefit(event); + } + + public void printAfterDiscount(Event event, Price price) { + OutputAfterDiscountView outputAfterDiscountView = new OutputAfterDiscountView(); + outputAfterDiscountView.outputAfterDiscount(event, price); + } + + public void printEventBadge(Event event) { + OutputEventBadgeView outputEventBadgeView = new OutputEventBadgeView(); + outputEventBadgeView.outputEventBadge(event); + } +}
Java
View ํด๋ž˜์Šค๋ฅผ ๊ต‰์žฅํžˆ ์ž˜๊ฒŒ ๋‚˜๋ˆ„์–ด์ฃผ์…จ๋„ค์š” ์•ˆ์— ๋ฉ”์„œ๋“œ๋“ค์ด ํ•˜๋‚˜๋ฐ–์— ์—†๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋˜๋ฐ ์ด๋ ‡๊ฒŒ ์ž˜๊ฒŒ ๋‚˜๋ˆ ์ฃผ์‹  ์ด์œ ๊ฐ€ ๋ญ˜๊นŒ์š”?
@@ -0,0 +1,87 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.domain.calculator.PriceCalculator; +import christmas.view.*; + +public class EventController { + public void event() { + printStart(); + Date date = getDate(); + Order order = getOrder(); + printPreview(date); + printOrder(order); + Price price = getBeforeDiscount(order); + printBeforeDiscount(price); + Event event = applyEvent(date, order, price); + printGift(event); + printEvent(event); + printAllBenefit(event); + printAfterDiscount(event, price); + printEventBadge(event); + } + + public void printStart() { + OutputHelloView outputHello = new OutputHelloView(); + outputHello.outputHello(); + } + + public Date getDate() { + InputDateView inputDateView = new InputDateView(); + return inputDateView.inputDate(); + } + + public Order getOrder() { + InputOrderView inputOrderView = new InputOrderView(); + return inputOrderView.inputOrder(); + } + + public void printPreview(Date date) { + OutputPreviewView outputPreviewView = new OutputPreviewView(); + outputPreviewView.outputPreview(date); + } + + public void printOrder(Order order) { + OutputOrderView outputOrderView = new OutputOrderView(); + outputOrderView.outputOrder(order); + } + + public Price getBeforeDiscount(Order order) { + PriceCalculator priceCalculator = new PriceCalculator(); + return priceCalculator.calculatePrice(order); + } + + public void printBeforeDiscount(Price price) { + OutputBeforeDiscountView outputBeforeDiscountView = new OutputBeforeDiscountView(); + outputBeforeDiscountView.outputBeforeDiscount(price); + } + + public Event applyEvent(Date date, Order order, Price price) { + return new Event(date, order, price); + } + + public void printGift(Event event) { + OutputGiftView outputGiftView = new OutputGiftView(); + outputGiftView.outputGift(event); + } + + public void printEvent(Event event) { + OutputEventView outputEventView = new OutputEventView(); + outputEventView.outputEvent(event); + } + + public void printAllBenefit(Event event) { + OutputAllBenefitView outputAllBenefitView = new OutputAllBenefitView(); + outputAllBenefitView.outputAllBenefit(event); + } + + public void printAfterDiscount(Event event, Price price) { + OutputAfterDiscountView outputAfterDiscountView = new OutputAfterDiscountView(); + outputAfterDiscountView.outputAfterDiscount(event, price); + } + + public void printEventBadge(Event event) { + OutputEventBadgeView outputEventBadgeView = new OutputEventBadgeView(); + outputEventBadgeView.outputEventBadge(event); + } +}
Java
MVC ํŒจํ„ด์„ ์ ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ญ˜๊นŒ์š”? ํ˜„์žฌ ์ฝ”๋“œ์ƒ์—์„œ View๊ฐ€ model์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๊ณ  ์žˆ๋Š”๋ฐ ์ •๋ง MVC ํŒจํ„ด์ด ์ž˜ ์ ์šฉ๋œ ๊ฑด ๋งž์„๊นŒ์š”?
@@ -0,0 +1,17 @@ +package christmas.domain; + +import static christmas.constant.Number.MAX_DATE; +import static christmas.constant.Number.MIN_DATE; +import static christmas.constant.message.ErrorMessage.INVALID_DATE; + +public record Date(int date) { + public Date { + validate(date); + } + + private void validate(int date) { + if (date < MIN_DATE || date > MAX_DATE) { + throw new IllegalArgumentException(INVALID_DATE); + } + } +}
Java
๋ฌด์—‡์„ ๊ฒ€์ฆํ•˜๋Š”์ง€ ์ข€ ๋” ๋ช…ํ™•ํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚ด๋Š” ๋„ค์ด๋ฐ์ด ์ข‹๊ฒ ๊ตฐ์š”
@@ -0,0 +1,87 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.domain.calculator.PriceCalculator; +import christmas.view.*; + +public class EventController { + public void event() { + printStart(); + Date date = getDate(); + Order order = getOrder(); + printPreview(date); + printOrder(order); + Price price = getBeforeDiscount(order); + printBeforeDiscount(price); + Event event = applyEvent(date, order, price); + printGift(event); + printEvent(event); + printAllBenefit(event); + printAfterDiscount(event, price); + printEventBadge(event); + } + + public void printStart() { + OutputHelloView outputHello = new OutputHelloView(); + outputHello.outputHello(); + } + + public Date getDate() { + InputDateView inputDateView = new InputDateView(); + return inputDateView.inputDate(); + } + + public Order getOrder() { + InputOrderView inputOrderView = new InputOrderView(); + return inputOrderView.inputOrder(); + } + + public void printPreview(Date date) { + OutputPreviewView outputPreviewView = new OutputPreviewView(); + outputPreviewView.outputPreview(date); + } + + public void printOrder(Order order) { + OutputOrderView outputOrderView = new OutputOrderView(); + outputOrderView.outputOrder(order); + } + + public Price getBeforeDiscount(Order order) { + PriceCalculator priceCalculator = new PriceCalculator(); + return priceCalculator.calculatePrice(order); + } + + public void printBeforeDiscount(Price price) { + OutputBeforeDiscountView outputBeforeDiscountView = new OutputBeforeDiscountView(); + outputBeforeDiscountView.outputBeforeDiscount(price); + } + + public Event applyEvent(Date date, Order order, Price price) { + return new Event(date, order, price); + } + + public void printGift(Event event) { + OutputGiftView outputGiftView = new OutputGiftView(); + outputGiftView.outputGift(event); + } + + public void printEvent(Event event) { + OutputEventView outputEventView = new OutputEventView(); + outputEventView.outputEvent(event); + } + + public void printAllBenefit(Event event) { + OutputAllBenefitView outputAllBenefitView = new OutputAllBenefitView(); + outputAllBenefitView.outputAllBenefit(event); + } + + public void printAfterDiscount(Event event, Price price) { + OutputAfterDiscountView outputAfterDiscountView = new OutputAfterDiscountView(); + outputAfterDiscountView.outputAfterDiscount(event, price); + } + + public void printEventBadge(Event event) { + OutputEventBadgeView outputEventBadgeView = new OutputEventBadgeView(); + outputEventBadgeView.outputEventBadge(event); + } +}
Java
์ถ”๊ฐ€์ ์œผ๋กœ, ๋ชจ๋“  View ๊ด€๋ จ ๊ฐ์ฒด๋“ค์— ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๊ฐ€ ์—†์–ด์„œ ์œ ํ‹ธ์„ฑ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด๋„ ๋์„ ๊ฒƒ ๊ฐ™์€๋ฐ ์ง€๊ธˆ์ฒ˜๋Ÿผ ๋งค ํด๋ž˜์Šค๋งˆ๋‹ค ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์‹œ๋Š” ์ด์œ ๋Š” ๋ญ˜๊นŒ์š”?
@@ -0,0 +1,91 @@ +package christmas.domain; + +import christmas.domain.menu.Dessert; +import christmas.domain.menu.Drink; +import christmas.domain.menu.Entree; +import christmas.domain.menu.Menu; + +import java.util.Map; + +import static christmas.constant.Number.*; +import static christmas.constant.message.OutputMessage.*; + +public record Event(Date date, Order order, Price price) { + public int d_Day() { + if (price.price() < TEN_THOUSAND || date.date() > CHRISTMAS) { + return ZERO; + } + return THOUSAND + (date.date() - MIN_DATE) * HUNDRED; + } + + public int weekday() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN == ONE || date.date() % SEVEN == TWO)) { + return ZERO; + } + int count = ZERO; + for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) { + Menu menu = entry.getKey(); + Integer i = entry.getValue(); + try { + Dessert.valueOf(menu.name()); + } catch (IllegalArgumentException e) { + continue; + } + count += i; + } + return YEAR * count; + } + + public int weekend() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != ONE && date.date() % SEVEN != TWO)) { + return ZERO; + } + int count = ZERO; + for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) { + Menu menu = entry.getKey(); + Integer i = entry.getValue(); + try { + Entree.valueOf(menu.name()); + } catch (IllegalArgumentException e) { + continue; + } + count += i; + } + return YEAR * count; + } + + public int special() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != THREE && date.date() != CHRISTMAS)) { + return ZERO; + } + return THOUSAND; + } + + public int freeGift() { + if (price.price() > FREE_GIFT) { + return Drink.์ƒดํŽ˜์ธ.getPrice(); + } + return ZERO; + } + + public String badge() { + if (allBenefit() >= SANTA) { + return SANTA_BADGE; + } + if (allBenefit() >= TREE) { + return TREE_BADGE; + } + if (allBenefit() >= STAR) { + return STAR_BADGE; + } + return NOTHING; + } + + public int allBenefit() { + return d_Day() + weekday() + weekend() + special() + freeGift(); + } + + public int afterDiscount() { + return d_Day() + weekday() + weekend() + special(); + } +}
Java
์ž๋ฐ” ์ปจ๋ฒค์…˜ ์ƒ ๋ฉ”์„œ๋“œ๋Š” ๋™์‚ฌํ˜•์œผ๋กœ ์ž‘์„ฑํ•˜๋Š” ๊ฑธ ๊ถŒ์žฅ๋“œ๋ฆฝ๋‹ˆ๋‹ค
@@ -0,0 +1,91 @@ +package christmas.domain; + +import christmas.domain.menu.Dessert; +import christmas.domain.menu.Drink; +import christmas.domain.menu.Entree; +import christmas.domain.menu.Menu; + +import java.util.Map; + +import static christmas.constant.Number.*; +import static christmas.constant.message.OutputMessage.*; + +public record Event(Date date, Order order, Price price) { + public int d_Day() { + if (price.price() < TEN_THOUSAND || date.date() > CHRISTMAS) { + return ZERO; + } + return THOUSAND + (date.date() - MIN_DATE) * HUNDRED; + } + + public int weekday() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN == ONE || date.date() % SEVEN == TWO)) { + return ZERO; + } + int count = ZERO; + for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) { + Menu menu = entry.getKey(); + Integer i = entry.getValue(); + try { + Dessert.valueOf(menu.name()); + } catch (IllegalArgumentException e) { + continue; + } + count += i; + } + return YEAR * count; + } + + public int weekend() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != ONE && date.date() % SEVEN != TWO)) { + return ZERO; + } + int count = ZERO; + for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) { + Menu menu = entry.getKey(); + Integer i = entry.getValue(); + try { + Entree.valueOf(menu.name()); + } catch (IllegalArgumentException e) { + continue; + } + count += i; + } + return YEAR * count; + } + + public int special() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != THREE && date.date() != CHRISTMAS)) { + return ZERO; + } + return THOUSAND; + } + + public int freeGift() { + if (price.price() > FREE_GIFT) { + return Drink.์ƒดํŽ˜์ธ.getPrice(); + } + return ZERO; + } + + public String badge() { + if (allBenefit() >= SANTA) { + return SANTA_BADGE; + } + if (allBenefit() >= TREE) { + return TREE_BADGE; + } + if (allBenefit() >= STAR) { + return STAR_BADGE; + } + return NOTHING; + } + + public int allBenefit() { + return d_Day() + weekday() + weekend() + special() + freeGift(); + } + + public int afterDiscount() { + return d_Day() + weekday() + weekend() + special(); + } +}
Java
ํ•ด๋‹น ํด๋ž˜์Šค์—์„œ ๋„ˆ๋ฌด ๋งŽ์€ ๊ฑธ ํ•˜๊ณ  ์žˆ๋„ค์š” ํ• ์ธ์œจ์„ ๊ณ„์‚ฐํ•˜๊ณ , ์ฆ์ ํ’ˆ์„ ์ค„์ง€ ๊ฒฐ์ •ํ•˜๊ณ , ๋ฐฐ์ง€๋ฅผ ์ค„์ง€ ๊ฒฐ์ •ํ•˜๊ณ ... Event๋ผ๋Š” ๋„ค์ด๋ฐ๋งŒ ๋“ค์—ˆ์„ ๋•Œ, ์ € ๋ชจ๋“  ์ผ์„ ํ•˜๋Š” ๊ฒƒ์„ ์˜ˆ์ธกํ•˜๊ธฐ ์‰ฝ์ง€ ์•Š์„๊ฒƒ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ์ฒด์ง€ํ–ฅ ์„ค๊ณ„์˜ 5๊ฐ€์ง€ ์›์น™(SOLID) ์ค‘ [๋‹จ์ผ ์ฑ…์ž„์˜ ์›์น™(SRP, Single Responsibility Principle)](https://mangkyu.tistory.com/194)์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ๊นŒ์š”?
@@ -0,0 +1,91 @@ +package christmas.domain; + +import christmas.domain.menu.Dessert; +import christmas.domain.menu.Drink; +import christmas.domain.menu.Entree; +import christmas.domain.menu.Menu; + +import java.util.Map; + +import static christmas.constant.Number.*; +import static christmas.constant.message.OutputMessage.*; + +public record Event(Date date, Order order, Price price) { + public int d_Day() { + if (price.price() < TEN_THOUSAND || date.date() > CHRISTMAS) { + return ZERO; + } + return THOUSAND + (date.date() - MIN_DATE) * HUNDRED; + } + + public int weekday() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN == ONE || date.date() % SEVEN == TWO)) { + return ZERO; + } + int count = ZERO; + for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) { + Menu menu = entry.getKey(); + Integer i = entry.getValue(); + try { + Dessert.valueOf(menu.name()); + } catch (IllegalArgumentException e) { + continue; + } + count += i; + } + return YEAR * count; + } + + public int weekend() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != ONE && date.date() % SEVEN != TWO)) { + return ZERO; + } + int count = ZERO; + for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) { + Menu menu = entry.getKey(); + Integer i = entry.getValue(); + try { + Entree.valueOf(menu.name()); + } catch (IllegalArgumentException e) { + continue; + } + count += i; + } + return YEAR * count; + } + + public int special() { + if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != THREE && date.date() != CHRISTMAS)) { + return ZERO; + } + return THOUSAND; + } + + public int freeGift() { + if (price.price() > FREE_GIFT) { + return Drink.์ƒดํŽ˜์ธ.getPrice(); + } + return ZERO; + } + + public String badge() { + if (allBenefit() >= SANTA) { + return SANTA_BADGE; + } + if (allBenefit() >= TREE) { + return TREE_BADGE; + } + if (allBenefit() >= STAR) { + return STAR_BADGE; + } + return NOTHING; + } + + public int allBenefit() { + return d_Day() + weekday() + weekend() + special() + freeGift(); + } + + public int afterDiscount() { + return d_Day() + weekday() + weekend() + special(); + } +}
Java
Date, Event, Order, Price ๋ชจ๋‘ Record๋กœ ๋งŒ๋“ค์–ด์ฃผ์‹  ์ด์œ ๋Š” ๋ญ˜๊นŒ์š”?
@@ -0,0 +1,93 @@ +import Util from './util/Util.js'; +import MenuValidation from './validation/MenuValidation.js'; +import { PRICE, APPETIZER, MAIN, DESSERT, BEVERAGE, PRICE_CONSTANT } from './constants/constant.js'; + +class Menu { + #main = { ...MAIN }; + + #dessert = { ...DESSERT }; + + #beverage = { ...BEVERAGE }; + + #appetizer = { ...APPETIZER }; + + #totalPrice = 0; + + constructor(menu) { + const data = Util.countMethod(menu); + this.#validate(data); + this.#calculateMenuAndPrice(data); + } + + #validate(data) { + MenuValidation.validateMenuAndMenuCount(data); + MenuValidation.validateDuplicate(data); + MenuValidation.validateOnlyBeverage({ ...this.#appetizer, ...this.#main, ...this.#dessert }, data); + } + + #calculateMenuAndPrice(data) { + data.forEach(([food, count]) => { + if (this.#appetizer[food] !== undefined) this.#appetizer[food] += count; + if (this.#dessert[food] !== undefined) this.#dessert[food] += count; + if (this.#main[food] !== undefined) this.#main[food] += count; + if (this.#beverage[food] !== undefined) this.#beverage[food] += count; + this.#totalPrice += PRICE[food] * count; + }); + } + + /** + * ์ด ์ฃผ๋ฌธํ•œ ๋””์ €ํŠธ์˜ ๊ฐœ์ˆ˜ + * @returns {number} totalDessert + */ + calcultaeTotalDessert() { + return Util.extractValuesAndSum(this.#dessert); + } + + /** + * ์ด ์ฃผ๋ฌธํ•œ ๋ฉ”์ธ ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜ + * @returns {number} totalMainMenu + */ + calcultaeTotalMain() { + return Util.extractValuesAndSum(this.#main); + } + + /** + * ์—ํ”ผํƒ€์ด์ €, ๋ฉ”์ธ๋ฉ”๋‰ด, ๋””์ €ํŠธ, ์Œ๋ฃŒ ์ค‘ 1๊ฐœ์ด์ƒ ์ฃผ๋ฌธํ•œ ๋ฉ”๋‰ด๋งŒ ์ถ”๋ ค์„œ ๋ฐ˜ํ™˜ + * @returns {{[key:string]: number}} buyingMenu + */ + calculateBuyingMenu() { + const totalFood = { ...this.#appetizer, ...this.#main, ...this.#dessert, ...this.#beverage }; + const foodNames = Util.extractKeys(totalFood); + const buyingMenu = {}; + foodNames.forEach((food) => { + if (totalFood[food]) buyingMenu[food] = totalFood[food]; + }); + return buyingMenu; + } + + /** + * 12๋งŒ์› ์ด์ƒ ๊ตฌ๋งค ์—ฌ๋ถ€ ๋ฐ˜ํ™˜ + * @returns {boolean} isPresentedAmount + */ + isPresentedAmount() { + return this.#totalPrice >= PRICE_CONSTANT.presentedAmountPrice; + } + + /** + * ์ด ๊ตฌ์ž… ๊ธˆ์•ก์ด ๊ธฐ์ค€ ๊ธˆ์•ก ์ด์ƒ ์—ฌ๋ถ€์— ๋”ฐ๋ผ์„œ ์ด๋ฒคํŠธ ํ˜œํƒ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + * @returns {boolean} ์ด๋ฒคํŠธ ๋Œ€์ƒ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + */ + isEvent() { + return this.#totalPrice >= 10000; + } + + /** + * ํ• ์ธ์ „ ์ด ๊ธˆ์•ก ๋ฐ˜ํ™˜ + * @returns {number} totalPrice + */ + getTotalPrice() { + return this.#totalPrice; + } +} + +export default Menu;
JavaScript
ํ•„๋“œ์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋งŽ์€๋ฐ ์ด๋ ‡๊ฒŒ ๋‘์‹  ์ด์œ ๊ฐ€ ์žˆ์œผ์‹ค๊นŒ์š”?
@@ -0,0 +1,93 @@ +import Util from './util/Util.js'; +import MenuValidation from './validation/MenuValidation.js'; +import { PRICE, APPETIZER, MAIN, DESSERT, BEVERAGE, PRICE_CONSTANT } from './constants/constant.js'; + +class Menu { + #main = { ...MAIN }; + + #dessert = { ...DESSERT }; + + #beverage = { ...BEVERAGE }; + + #appetizer = { ...APPETIZER }; + + #totalPrice = 0; + + constructor(menu) { + const data = Util.countMethod(menu); + this.#validate(data); + this.#calculateMenuAndPrice(data); + } + + #validate(data) { + MenuValidation.validateMenuAndMenuCount(data); + MenuValidation.validateDuplicate(data); + MenuValidation.validateOnlyBeverage({ ...this.#appetizer, ...this.#main, ...this.#dessert }, data); + } + + #calculateMenuAndPrice(data) { + data.forEach(([food, count]) => { + if (this.#appetizer[food] !== undefined) this.#appetizer[food] += count; + if (this.#dessert[food] !== undefined) this.#dessert[food] += count; + if (this.#main[food] !== undefined) this.#main[food] += count; + if (this.#beverage[food] !== undefined) this.#beverage[food] += count; + this.#totalPrice += PRICE[food] * count; + }); + } + + /** + * ์ด ์ฃผ๋ฌธํ•œ ๋””์ €ํŠธ์˜ ๊ฐœ์ˆ˜ + * @returns {number} totalDessert + */ + calcultaeTotalDessert() { + return Util.extractValuesAndSum(this.#dessert); + } + + /** + * ์ด ์ฃผ๋ฌธํ•œ ๋ฉ”์ธ ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜ + * @returns {number} totalMainMenu + */ + calcultaeTotalMain() { + return Util.extractValuesAndSum(this.#main); + } + + /** + * ์—ํ”ผํƒ€์ด์ €, ๋ฉ”์ธ๋ฉ”๋‰ด, ๋””์ €ํŠธ, ์Œ๋ฃŒ ์ค‘ 1๊ฐœ์ด์ƒ ์ฃผ๋ฌธํ•œ ๋ฉ”๋‰ด๋งŒ ์ถ”๋ ค์„œ ๋ฐ˜ํ™˜ + * @returns {{[key:string]: number}} buyingMenu + */ + calculateBuyingMenu() { + const totalFood = { ...this.#appetizer, ...this.#main, ...this.#dessert, ...this.#beverage }; + const foodNames = Util.extractKeys(totalFood); + const buyingMenu = {}; + foodNames.forEach((food) => { + if (totalFood[food]) buyingMenu[food] = totalFood[food]; + }); + return buyingMenu; + } + + /** + * 12๋งŒ์› ์ด์ƒ ๊ตฌ๋งค ์—ฌ๋ถ€ ๋ฐ˜ํ™˜ + * @returns {boolean} isPresentedAmount + */ + isPresentedAmount() { + return this.#totalPrice >= PRICE_CONSTANT.presentedAmountPrice; + } + + /** + * ์ด ๊ตฌ์ž… ๊ธˆ์•ก์ด ๊ธฐ์ค€ ๊ธˆ์•ก ์ด์ƒ ์—ฌ๋ถ€์— ๋”ฐ๋ผ์„œ ์ด๋ฒคํŠธ ํ˜œํƒ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + * @returns {boolean} ์ด๋ฒคํŠธ ๋Œ€์ƒ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. + */ + isEvent() { + return this.#totalPrice >= 10000; + } + + /** + * ํ• ์ธ์ „ ์ด ๊ธˆ์•ก ๋ฐ˜ํ™˜ + * @returns {number} totalPrice + */ + getTotalPrice() { + return this.#totalPrice; + } +} + +export default Menu;
JavaScript
Data๋Š” ๋ถˆ์šฉ์–ด๋ผ๊ณ  ๋“ค์—ˆ๋Š”๋ฐ ์ „๋ถ€ ์†Œ๋ฌธ์ž์ด๋ฉด ์ƒ๊ด€์ด ์—†๋‚˜์š”?
@@ -0,0 +1,70 @@ +import ReservationDateValidation from './validation/ReservationDateValidation.js'; +import { DAY_CONSTANT, PRICE_CONSTANT } from './constants/constant.js'; + +class ReservationDate { + #date; + + constructor(date) { + const dateToNumber = Number(date); + this.#validate(dateToNumber); + this.#date = dateToNumber; + } + + #validate(date) { + ReservationDateValidation.validateNumber(date); + ReservationDateValidation.validateUnderAndOver(date); + } + + #getDate() { + const index = this.#date % DAY_CONSTANT.days.length; + const day = DAY_CONSTANT.days[index]; + return day; + } + + /** + * ํ•ด๋‹น ์š”์ผ ์ด๋ฒคํŠธ ํ˜œํƒ ์‹œ์ž‘ ๋ฌธ๊ตฌ ๋ฐ˜ํ™˜ + * @returns {string} dateString + */ + makeDateString() { + return `12์›” ${this.#date}์ผ์— ์šฐํ…Œ์ฝ” ์‹์žฅ์—์„œ ๋ฐ›์„ ์ด๋ฒคํŠธ ํ˜œํƒ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!`; + } + + /** + * ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ ๊ธˆ์•ก ์ถœ๋ ฅ + * @returns {number} christmasDiscount + */ + calculateChristmasDiscount() { + if (this.#date <= DAY_CONSTANT.christmas) { + return (this.#date - DAY_CONSTANT.startDay) * 100 + PRICE_CONSTANT.christmasBaseDiscountPrice; + } + return 0; + } + + /** + * ์ฃผ๋ง ์—ฌ๋ถ€ ํ™•์ธ + * @returns {boolean} isWeekend + */ + isWeekend() { + const day = this.#getDate(); + return day === DAY_CONSTANT.days[1] || day === DAY_CONSTANT.days[2]; + } + + /** + * ํ‰์ผ ์—ฌ๋ถ€ ํ™•์ธ + * @returns {boolean} isWeekday + */ + isWeekday() { + const day = this.#getDate(); + return !(day === DAY_CONSTANT.days[1]) && !(day === DAY_CONSTANT.days[2]); + } + + /** + * ํ•ด๋‹น ์š”์ผ์ด ์ŠคํŽ˜์…œ ํ• ์ธ์ด ํฌํ•จ๋˜๋Š” ์š”์ผ์ธ์ง€ ํ™•์ธ + * @returns {boolean} isSpecialDiscount + */ + isSpecialDiscount() { + return DAY_CONSTANT.specialDiscountDays.includes(this.#date); + } +} + +export default ReservationDate;
JavaScript
์ด ํด๋ž˜์Šค๋Š” ๋„๋ฉ”์ธ์ธ๊ฐ€์š”..? getDate() ๋ฉ”์„œ๋“œ๋Š” ์ ‘๊ทผ์ œํ•œ์„ ๋‘์‹œ๊ณ  ์ด ๋ฉ”์„œ๋“œ์—์„œ๋Š” ๊ฐ์ฒด์˜ ์ƒํƒœ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ๋‚ด๋ณด๋‚ด์‹œ๋Š” ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ด์š”..๐Ÿค”
@@ -0,0 +1,58 @@ +package com.codesquad.dust4.api; + +import com.codesquad.dust4.domain.DustForecast; +import com.codesquad.dust4.dto.DustInfoByStationDto; +import com.codesquad.dust4.dto.ForecastResponseDto; +import com.codesquad.dust4.dto.LocationReturnDto; +import com.codesquad.dust4.service.DustStatusPublicApi; +import com.codesquad.dust4.service.ForecastPublicApi; +import com.codesquad.dust4.utils.DustMockDataUtil; +import com.codesquad.dust4.utils.LocationConverterUtil; + +import java.net.URISyntaxException; +import java.util.concurrent.ExecutionException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + +@RestController +public class DustAPIController { + + private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class); + + @GetMapping("/dust-status") + + public ResponseEntity<DustInfoByStationDto> getDustInfo(@RequestParam("latitude") String EPSGlatitude, @RequestParam("longitude") String EPSGlongitude) + throws IOException, ExecutionException, InterruptedException { + logger.info("longitude: {}, latitude: {}", EPSGlongitude, EPSGlatitude); + + LocationReturnDto locationReturnDto = LocationConverterUtil.locationConverter(EPSGlongitude, EPSGlatitude); + + String tmX = locationReturnDto.getLongitude(); + String tmY = locationReturnDto.getLatitude(); + + DustInfoByStationDto dustInfoByStationDto = DustStatusPublicApi.dustStatus(tmX, tmY); + + return new ResponseEntity<>(dustInfoByStationDto, HttpStatus.OK); + } + + @GetMapping("/forecast") + public ResponseEntity<ForecastResponseDto> enlistDustForecast() throws URISyntaxException, JsonProcessingException { + + logger.info("dust forecast"); + + DustForecast forecast = ForecastPublicApi.forecast(); + ForecastResponseDto responseDto = new ForecastResponseDto(); + responseDto.setContent(forecast); + + return new ResponseEntity<>(responseDto, HttpStatus.OK); + } +}
Java
๋ถˆํ•„์š”ํ•œ ๊ฐœํ–‰์ด ์žˆ๋„ค์š”!
@@ -0,0 +1,58 @@ +package com.codesquad.dust4.api; + +import com.codesquad.dust4.domain.DustForecast; +import com.codesquad.dust4.dto.DustInfoByStationDto; +import com.codesquad.dust4.dto.ForecastResponseDto; +import com.codesquad.dust4.dto.LocationReturnDto; +import com.codesquad.dust4.service.DustStatusPublicApi; +import com.codesquad.dust4.service.ForecastPublicApi; +import com.codesquad.dust4.utils.DustMockDataUtil; +import com.codesquad.dust4.utils.LocationConverterUtil; + +import java.net.URISyntaxException; +import java.util.concurrent.ExecutionException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + +@RestController +public class DustAPIController { + + private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class); + + @GetMapping("/dust-status") + + public ResponseEntity<DustInfoByStationDto> getDustInfo(@RequestParam("latitude") String EPSGlatitude, @RequestParam("longitude") String EPSGlongitude) + throws IOException, ExecutionException, InterruptedException { + logger.info("longitude: {}, latitude: {}", EPSGlongitude, EPSGlatitude); + + LocationReturnDto locationReturnDto = LocationConverterUtil.locationConverter(EPSGlongitude, EPSGlatitude); + + String tmX = locationReturnDto.getLongitude(); + String tmY = locationReturnDto.getLatitude(); + + DustInfoByStationDto dustInfoByStationDto = DustStatusPublicApi.dustStatus(tmX, tmY); + + return new ResponseEntity<>(dustInfoByStationDto, HttpStatus.OK); + } + + @GetMapping("/forecast") + public ResponseEntity<ForecastResponseDto> enlistDustForecast() throws URISyntaxException, JsonProcessingException { + + logger.info("dust forecast"); + + DustForecast forecast = ForecastPublicApi.forecast(); + ForecastResponseDto responseDto = new ForecastResponseDto(); + responseDto.setContent(forecast); + + return new ResponseEntity<>(responseDto, HttpStatus.OK); + } +}
Java
ํŒŒ๋ผ๋ฏธํ„ฐ ๋ณ€์ˆ˜๋ช… ์ฒซ ๊ธ€์ž์— ๋Œ€๋ฌธ์ž ์“ฐ์ง€ ์•Š๋„๋ก ๋ฐ”๊ฟ” ์ฃผ์‹œ๊ณ ์š”. ์•„๋งˆ `EPSG` ๊ฐ€ ๋ฌด์–ธ๊ฐ€์˜ ์•ฝ์–ด์ธ ๋ชจ์–‘์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿด๋• ์•„๋ž˜์™€ ๊ฐ™์€ ๋„ค์ด๋ฐ์ด๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. `String epsgLatitude, String epsgLongitude`
@@ -0,0 +1,49 @@ +package com.codesquad.dust4.domain; + +public class DustStatusQuo { + + private String dataTime; //์ธก์ •์ผ + private String pm10Value; //๋ฏธ์„ธ๋จผ์ง€(PM10) ๋†๋„ + private String pm10Grade; //๋ฏธ์„ธ๋จผ์ง€(PM10) 24์‹œ๊ฐ„ ๋“ฑ๊ธ‰ + + public DustStatusQuo() {} + + public DustStatusQuo(String dataTime, String pm10Value, String pm10Grade) { + this.dataTime = dataTime; + this.pm10Value = pm10Value; + this.pm10Grade = pm10Grade; + } + + public String getDataTime() { + return dataTime; + } + + public void setDataTime(String dataTime) { + this.dataTime = dataTime; + } + + public String getPm10Value() { + return pm10Value; + } + + public void setPm10Value(String pm10Value) { + this.pm10Value = pm10Value; + } + + public String getPm10Grade() { + return pm10Grade; + } + + public void setPm10Grade(String pm10Grade) { + this.pm10Grade = pm10Grade; + } + + @Override + public String toString() { + return "DustStatusQuo{" + + "dataTime='" + dataTime + '\'' + + ", pm10Value='" + pm10Value + '\'' + + ", pm10Grade='" + pm10Grade + '\'' + + '}'; + } +}
Java
์Œ....์ด๊ฒŒ ์ €๋„ ํ•ญ์ƒ ๊ณ ๋ฏผ๋˜๋Š” ๋ถ€๋ถ„์ธ๋ฐ์š”. ํ˜„์žฌ ์ƒํƒœ๋ผ๋Š” ์˜๋ฏธ์—์„œ `StatusQuo` ๋ผ๊ณ  ํ•˜์…จ๊ฒ ์ง€๋งŒ ์‚ฌ์‹ค ์ด๊ฒŒ ํ˜‘์—…์˜ ๊ด€์ ์—์„œ๋Š”...ํ”ํžˆ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๋‹จ์–ด์ด๊ธด ํ•ด์„œ... `CurrentStatus` ์ •๋„๋ฉด ์ข‹์ง€ ์•Š์„๊นŒ ์‹ถ๊ธด ํ•œ๋ฐ์š”. status quo๋Š” ์‚ฌ์‹ค ์ข€ ์–ด๋ ค์šด ๋‹จ์–ด๋ผ์„œ์š”. ํด๋ž˜์Šค๋ช…์ด๋‚˜ ๋ณ€์ˆ˜๋ช… ์ž‘๋ช…์— ์‚ฌ์šฉ๋˜๋Š” ์˜๋‹จ์–ด๋Š” ํ•ญ์ƒ ์ค‘ํ•™๊ต ์˜์–ด ๋‹จ์–ด์ง‘ ์ •๋„ ์ˆ˜์ค€์„ ๋ฒ—์–ด๋‚˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์งํ•ด๋ด‰์š”. ๊ทธ๋ฆฌ๊ณ  ๊ฐ€๊ธ‰์  ๊ต‰์žฅํžˆ ์‰ฝ๊ฒŒ ์จ์•ผ ํ•˜๊ณ ์š”. `HyunjaeSangTae` ๊ฐ™์€ ์ž‘๋ช…๋งŒ ์•„๋‹ˆ๋ผ๋ฉด ๋ง์ด์—์š”.
@@ -0,0 +1,131 @@ +package com.codesquad.dust4.service; + +import com.codesquad.dust4.domain.DustStatusQuo; +import com.codesquad.dust4.domain.LocationOfStation; +import com.codesquad.dust4.dto.DustInfoByStationDto; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class DustStatusPublicApi { + public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException { + String response = stationFromPublicApi(tmX, tmY); + LocationOfStation closestStation = closestStation(response); + String dustStatusResponse = dustStatusFromPublicApi(closestStation); + List<DustStatusQuo> status = statusQuos(dustStatusResponse); + + return new DustInfoByStationDto(status, closestStation); + } + + private static LocationOfStation closestStation(String stationJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<LocationOfStation> stations = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(stationJson); + array = (JSONArray) obj.get("list"); + for (Object o : array) { + JSONObject o1 = (JSONObject) o; + String addr = String.valueOf(o1.get("addr")); + String stationName = String.valueOf(o1.get("stationName")); + String tm = String.valueOf(o1.get("tm")); + + LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm)); + stations.add(station); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station); + } + + private static String stationFromPublicApi(String tmX, String tmY) throws IOException { + URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY + + "&tmX=" + tmX + + "&tmY=" + tmY + + "&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } + + private static List<DustStatusQuo> statusQuos(String statusJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<DustStatusQuo> statusList = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(statusJson); + array = (JSONArray) obj.get("list"); + for (Object object : array) { + JSONObject stationObject = (JSONObject) object; + String dateTime = String.valueOf(stationObject.get("dataTime")); + String grade = String.valueOf(stationObject.get("pm10Grade")); + if (grade.equals("-")) { + grade = "0"; + } + String value = String.valueOf(stationObject.get("pm10Value")); + if (value.equals("-")) { + value = "0"; + } + + DustStatusQuo status = new DustStatusQuo(dateTime, value, grade); + statusList.add(status); + } + } catch (ParseException e) { + e.printStackTrace(); + } + + return statusList; + } + + private static String readString(HttpURLConnection connection) throws IOException { + BufferedReader bufferedReader; + if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + } else { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); + } + + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + + bufferedReader.close(); + connection.disconnect(); + + return stringBuilder.toString(); + } + + + private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException { + URL url = new URL(PublicApi.API_URL + + "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" + + station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" + + PublicApi.API_KEY + + "&ver=1.3&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } +}
Java
o1 ๋ณด๋‹ค ๋” ๋‚˜์€ ๋„ค์ด๋ฐ ๊ณ ๋ฏผํ•ด์ฃผ์‹œ๊ณ ์š”.
@@ -0,0 +1,131 @@ +package com.codesquad.dust4.service; + +import com.codesquad.dust4.domain.DustStatusQuo; +import com.codesquad.dust4.domain.LocationOfStation; +import com.codesquad.dust4.dto.DustInfoByStationDto; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class DustStatusPublicApi { + public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException { + String response = stationFromPublicApi(tmX, tmY); + LocationOfStation closestStation = closestStation(response); + String dustStatusResponse = dustStatusFromPublicApi(closestStation); + List<DustStatusQuo> status = statusQuos(dustStatusResponse); + + return new DustInfoByStationDto(status, closestStation); + } + + private static LocationOfStation closestStation(String stationJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<LocationOfStation> stations = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(stationJson); + array = (JSONArray) obj.get("list"); + for (Object o : array) { + JSONObject o1 = (JSONObject) o; + String addr = String.valueOf(o1.get("addr")); + String stationName = String.valueOf(o1.get("stationName")); + String tm = String.valueOf(o1.get("tm")); + + LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm)); + stations.add(station); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station); + } + + private static String stationFromPublicApi(String tmX, String tmY) throws IOException { + URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY + + "&tmX=" + tmX + + "&tmY=" + tmY + + "&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } + + private static List<DustStatusQuo> statusQuos(String statusJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<DustStatusQuo> statusList = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(statusJson); + array = (JSONArray) obj.get("list"); + for (Object object : array) { + JSONObject stationObject = (JSONObject) object; + String dateTime = String.valueOf(stationObject.get("dataTime")); + String grade = String.valueOf(stationObject.get("pm10Grade")); + if (grade.equals("-")) { + grade = "0"; + } + String value = String.valueOf(stationObject.get("pm10Value")); + if (value.equals("-")) { + value = "0"; + } + + DustStatusQuo status = new DustStatusQuo(dateTime, value, grade); + statusList.add(status); + } + } catch (ParseException e) { + e.printStackTrace(); + } + + return statusList; + } + + private static String readString(HttpURLConnection connection) throws IOException { + BufferedReader bufferedReader; + if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + } else { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); + } + + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + + bufferedReader.close(); + connection.disconnect(); + + return stringBuilder.toString(); + } + + + private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException { + URL url = new URL(PublicApi.API_URL + + "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" + + station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" + + PublicApi.API_KEY + + "&ver=1.3&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } +}
Java
ํด๋ž˜์Šค๋ช…์ด ๋ชจํ˜ธํ•˜๋„ค์š”. ์Œ.... `ApiUtils` ์ •๋„๋กœ? ์•„๋‹ˆ๋ฉด `ApiProcessor` ์ •๋„๋„ ๊ดœ์ฐฎ๊ฒ ๋„ค์š”. ๊ทธ๋ฆฌ๊ณ  ์ด ํด๋ž˜์Šค์—์„œ ๋„ˆ๋ฌด ๋งŽ์€ ๊ธฐ๋Šฅ์ด ์ˆ˜ํ–‰๋˜๊ณ  ์žˆ๋Š”๋ฐ์š”, ์ด ํด๋ž˜์Šค์˜ ์—ญํ• ์€ 1) ๋„˜์–ด์˜จ ๋ฆฌ์Šคํฐ์Šค๋ฅผ ํŒŒ์‹ฑํ•ด์„œ ์ ์ ˆํ•œ ๊ฐ์ฒด๋กœ ๋Œ๋ ค์ฃผ๊ฑฐ๋‚˜ 2) API ์ฝœ์„ ์œ„ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์กฐํ•ฉํ•ด์„œ connection string์„ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ ์ •๋„๋กœ ํ•œ์ •ํ–ˆ์œผ๋ฉด ์ข‹๊ฒ ์–ด์š”.
@@ -0,0 +1,131 @@ +package com.codesquad.dust4.service; + +import com.codesquad.dust4.domain.DustStatusQuo; +import com.codesquad.dust4.domain.LocationOfStation; +import com.codesquad.dust4.dto.DustInfoByStationDto; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class DustStatusPublicApi { + public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException { + String response = stationFromPublicApi(tmX, tmY); + LocationOfStation closestStation = closestStation(response); + String dustStatusResponse = dustStatusFromPublicApi(closestStation); + List<DustStatusQuo> status = statusQuos(dustStatusResponse); + + return new DustInfoByStationDto(status, closestStation); + } + + private static LocationOfStation closestStation(String stationJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<LocationOfStation> stations = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(stationJson); + array = (JSONArray) obj.get("list"); + for (Object o : array) { + JSONObject o1 = (JSONObject) o; + String addr = String.valueOf(o1.get("addr")); + String stationName = String.valueOf(o1.get("stationName")); + String tm = String.valueOf(o1.get("tm")); + + LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm)); + stations.add(station); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station); + } + + private static String stationFromPublicApi(String tmX, String tmY) throws IOException { + URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY + + "&tmX=" + tmX + + "&tmY=" + tmY + + "&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } + + private static List<DustStatusQuo> statusQuos(String statusJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<DustStatusQuo> statusList = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(statusJson); + array = (JSONArray) obj.get("list"); + for (Object object : array) { + JSONObject stationObject = (JSONObject) object; + String dateTime = String.valueOf(stationObject.get("dataTime")); + String grade = String.valueOf(stationObject.get("pm10Grade")); + if (grade.equals("-")) { + grade = "0"; + } + String value = String.valueOf(stationObject.get("pm10Value")); + if (value.equals("-")) { + value = "0"; + } + + DustStatusQuo status = new DustStatusQuo(dateTime, value, grade); + statusList.add(status); + } + } catch (ParseException e) { + e.printStackTrace(); + } + + return statusList; + } + + private static String readString(HttpURLConnection connection) throws IOException { + BufferedReader bufferedReader; + if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + } else { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); + } + + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + + bufferedReader.close(); + connection.disconnect(); + + return stringBuilder.toString(); + } + + + private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException { + URL url = new URL(PublicApi.API_URL + + "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" + + station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" + + PublicApi.API_KEY + + "&ver=1.3&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } +}
Java
๋‘ ์นธ ๋„์–ด์กŒ๊ตฐ์š”.
@@ -0,0 +1,30 @@ +package com.codesquad.dust4.utils; + +import com.codesquad.dust4.api.DustAPIController; +import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.client.RestTemplate; + +public class AccessTokenUtil { + + public static final String CONSUMER_KEY_LOCATION = "6e8fc57906324e20805a"; + public static final String CONSUMER_SECRET_LOCATION = "aaa5becbdfcd4b5bb349"; + private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class); + + public static String getLocationConversionAPIToken() + throws ExecutionException, InterruptedException { + String URL = "https://sgisapi.kostat.go.kr/OpenAPI3/auth/authentication.json"; + String accessTokenURL = + URL + "?consumer_key=" + AccessTokenUtil.CONSUMER_KEY_LOCATION + "&consumer_secret=" + + AccessTokenUtil.CONSUMER_SECRET_LOCATION; + + RestTemplate restTemplate = new RestTemplate(); + + String receivedToken = restTemplate.getForObject(accessTokenURL, String.class); + String accessToken = ParseJSONDataUtil.parseAccessTokenJson(receivedToken); + logger.info("accessToken: {} ", accessToken); + + return accessToken; + } +}
Java
์š”์ฒญ์ด ๋“ค์–ด์˜ฌ๋•Œ๋งˆ๋‹ค API call์„ ๋ฐœ์ƒ์‹œ์ผœ ํ† ํฐ ์ •๋ณด๋ฅผ ์–ป์–ด์˜ค๊ฒŒ ๋˜๊ฒ ๋„ค์š”. ์ •๋ง ๊ทธ๋ž˜์•ผ ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‚˜์š”? ํ† ํฐ์ด ๋งค ์š”์ฒญ์‹œ๋งˆ๋‹ค ๋ณ€๊ฒฝ๋˜๋Š” ๊ฑด๊ฐ€์š”. ์™ธ๋ถ€ API ํ˜ธ์ถœ ํšŸ์ˆ˜๋Š” ์ตœ์†Œํ™”ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์€๋ฐ์š”, ๋งŒ์•ฝ ์ด API์˜ ์‘๋‹ต ์†๋„๊ฐ€ ๋Šฆ๋‹ค๊ฑฐ๋‚˜ ํ•˜๋ฉด, ์„œ๋น„์Šค ์†๋„์˜ ์ง€์—ฐ์œผ๋กœ ๋ฐ”๋กœ ์ด์–ด์งˆ ๊ฑฐ๊ณ , ์ด๋Ÿฐ ์‹์œผ๋กœ ์—ฐ์‡„์ ์ธ ์ง€์—ฐ์„ ๊ฒช๋‹ค ๋ณด๋ฉด ๊ฒฐ๊ตญ ์„œ๋น„์Šค ์ „๋ฉด ์žฅ์• ๋กœ๋„ ์ด์–ด์งˆ ์ˆ˜ ์žˆ์–ด์š”. ๋งŒ์•ฝ access token์ด ๊ณ„์† ๋™์ ์œผ๋กœ ๋ฐ”๋€Œ์–ด์•ผ๋งŒ ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ๋ฉด, properties ํŒŒ์ผ์—์„œ ์ •์  ๊ฐ’์œผ๋กœ ๊ด€๋ฆฌํ•ด์ฃผ์‹œ๊ณ , ์˜ˆ๋ฅผ ๋“ค์–ด... ๋งค ์‹œ๊ฐ„๋งˆ๋‹ค ๋ฐ”๋€Œ์–ด์•ผ ํ•œ๋‹ค๋ฉด `@Scheduled` ์ ๊ทน์ ์œผ๋กœ ํ™œ์šฉํ•ด์„œ ๋‚ด๋ถ€ cache ์‚ฌ์šฉํ•˜๋Š” ์ชฝ์œผ๋กœ ์ˆ˜์ •๋˜๋ฉด ์ข‹๊ฒ ๋„ค์š”.
@@ -0,0 +1,30 @@ +package com.codesquad.dust4.utils; + +import com.codesquad.dust4.api.DustAPIController; +import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.client.RestTemplate; + +public class AccessTokenUtil { + + public static final String CONSUMER_KEY_LOCATION = "6e8fc57906324e20805a"; + public static final String CONSUMER_SECRET_LOCATION = "aaa5becbdfcd4b5bb349"; + private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class); + + public static String getLocationConversionAPIToken() + throws ExecutionException, InterruptedException { + String URL = "https://sgisapi.kostat.go.kr/OpenAPI3/auth/authentication.json"; + String accessTokenURL = + URL + "?consumer_key=" + AccessTokenUtil.CONSUMER_KEY_LOCATION + "&consumer_secret=" + + AccessTokenUtil.CONSUMER_SECRET_LOCATION; + + RestTemplate restTemplate = new RestTemplate(); + + String receivedToken = restTemplate.getForObject(accessTokenURL, String.class); + String accessToken = ParseJSONDataUtil.parseAccessTokenJson(receivedToken); + logger.info("accessToken: {} ", accessToken); + + return accessToken; + } +}
Java
์ด ํด๋ž˜์Šค๋Š” `@Component` ์—ฌ๋„ ๋˜๊ฒ ๋Š”๋ฐ์š”.
@@ -0,0 +1,30 @@ +package com.codesquad.dust4.utils; + +import com.codesquad.dust4.api.DustAPIController; +import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.client.RestTemplate; + +public class AccessTokenUtil { + + public static final String CONSUMER_KEY_LOCATION = "6e8fc57906324e20805a"; + public static final String CONSUMER_SECRET_LOCATION = "aaa5becbdfcd4b5bb349"; + private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class); + + public static String getLocationConversionAPIToken() + throws ExecutionException, InterruptedException { + String URL = "https://sgisapi.kostat.go.kr/OpenAPI3/auth/authentication.json"; + String accessTokenURL = + URL + "?consumer_key=" + AccessTokenUtil.CONSUMER_KEY_LOCATION + "&consumer_secret=" + + AccessTokenUtil.CONSUMER_SECRET_LOCATION; + + RestTemplate restTemplate = new RestTemplate(); + + String receivedToken = restTemplate.getForObject(accessTokenURL, String.class); + String accessToken = ParseJSONDataUtil.parseAccessTokenJson(receivedToken); + logger.info("accessToken: {} ", accessToken); + + return accessToken; + } +}
Java
ํด๋ž˜์Šค๋ฅผ `@Component` ๋กœ ๊ด€๋ฆฌํ•˜๋ฉด ์ด ๊ฐ’๋„ `@Value` ๋กœ ์ฃผ์ž…๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”.
@@ -0,0 +1,15 @@ +package com.codesquad.dust4.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebCorsConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*"); + } +} \ No newline at end of file
Java
`implements WebMvcConfigurer` ๋ณด๋‹จ `extends WebMvcConfigurationSupport` ๊ฐ€ ๋” ๋‚ซ๋‹ค๊ณ  ์ƒ๊ฐ๋˜๋„ค์š”. https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.html
@@ -0,0 +1,8 @@ +package com.codesquad.dust4.exception; + +import org.springframework.web.bind.annotation.ControllerAdvice; + +@ControllerAdvice +public class CustomControllerAdvice { + +}
Java
์•„๋งˆ OAuth2 ์š”๊ตฌ์‚ฌํ•ญ์„ ์ € ๋•Œ ๊ตฌํ˜„ํ•˜์ง€ ๋ชปํ–ˆ๋˜ ๊ฒƒ์ด ์•„๋‹Œ๊ฐ€ ์ƒ๊ฐ๋“ญ๋‹ˆ๋‹ค ใ…‹ใ…‹
@@ -0,0 +1,49 @@ +package com.codesquad.dust4.domain; + +public class DustStatusQuo { + + private String dataTime; //์ธก์ •์ผ + private String pm10Value; //๋ฏธ์„ธ๋จผ์ง€(PM10) ๋†๋„ + private String pm10Grade; //๋ฏธ์„ธ๋จผ์ง€(PM10) 24์‹œ๊ฐ„ ๋“ฑ๊ธ‰ + + public DustStatusQuo() {} + + public DustStatusQuo(String dataTime, String pm10Value, String pm10Grade) { + this.dataTime = dataTime; + this.pm10Value = pm10Value; + this.pm10Grade = pm10Grade; + } + + public String getDataTime() { + return dataTime; + } + + public void setDataTime(String dataTime) { + this.dataTime = dataTime; + } + + public String getPm10Value() { + return pm10Value; + } + + public void setPm10Value(String pm10Value) { + this.pm10Value = pm10Value; + } + + public String getPm10Grade() { + return pm10Grade; + } + + public void setPm10Grade(String pm10Grade) { + this.pm10Grade = pm10Grade; + } + + @Override + public String toString() { + return "DustStatusQuo{" + + "dataTime='" + dataTime + '\'' + + ", pm10Value='" + pm10Value + '\'' + + ", pm10Grade='" + pm10Grade + '\'' + + '}'; + } +}
Java
๋„ค, ๊ทธ๋ ‡๋„ค์š”. ์‚ฌ์‹ค Status๋งŒ ์žˆ์œผ๋ฉด ๋˜์ง€ Quo๋Š” ๊ดœํžˆ ์“ธ๋ฐ์—†๋Š” ์ ‘๋ฏธ์‚ฌ ๊ฐ™์€^^ ์กฐ๊ธˆ ๋” ๋ช…ํ™•ํ•œ ๋‹จ์–ด๋ช… ์‚ฌ์šฉ์— ๋…ธ๋ ฅํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,131 @@ +package com.codesquad.dust4.service; + +import com.codesquad.dust4.domain.DustStatusQuo; +import com.codesquad.dust4.domain.LocationOfStation; +import com.codesquad.dust4.dto.DustInfoByStationDto; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class DustStatusPublicApi { + public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException { + String response = stationFromPublicApi(tmX, tmY); + LocationOfStation closestStation = closestStation(response); + String dustStatusResponse = dustStatusFromPublicApi(closestStation); + List<DustStatusQuo> status = statusQuos(dustStatusResponse); + + return new DustInfoByStationDto(status, closestStation); + } + + private static LocationOfStation closestStation(String stationJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<LocationOfStation> stations = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(stationJson); + array = (JSONArray) obj.get("list"); + for (Object o : array) { + JSONObject o1 = (JSONObject) o; + String addr = String.valueOf(o1.get("addr")); + String stationName = String.valueOf(o1.get("stationName")); + String tm = String.valueOf(o1.get("tm")); + + LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm)); + stations.add(station); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station); + } + + private static String stationFromPublicApi(String tmX, String tmY) throws IOException { + URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY + + "&tmX=" + tmX + + "&tmY=" + tmY + + "&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } + + private static List<DustStatusQuo> statusQuos(String statusJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<DustStatusQuo> statusList = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(statusJson); + array = (JSONArray) obj.get("list"); + for (Object object : array) { + JSONObject stationObject = (JSONObject) object; + String dateTime = String.valueOf(stationObject.get("dataTime")); + String grade = String.valueOf(stationObject.get("pm10Grade")); + if (grade.equals("-")) { + grade = "0"; + } + String value = String.valueOf(stationObject.get("pm10Value")); + if (value.equals("-")) { + value = "0"; + } + + DustStatusQuo status = new DustStatusQuo(dateTime, value, grade); + statusList.add(status); + } + } catch (ParseException e) { + e.printStackTrace(); + } + + return statusList; + } + + private static String readString(HttpURLConnection connection) throws IOException { + BufferedReader bufferedReader; + if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + } else { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); + } + + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + + bufferedReader.close(); + connection.disconnect(); + + return stringBuilder.toString(); + } + + + private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException { + URL url = new URL(PublicApi.API_URL + + "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" + + station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" + + PublicApi.API_KEY + + "&ver=1.3&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } +}
Java
์—ฌ๊ธฐ์„œ๋Š” gson ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ์š”. ํ˜น์ž๋Š” (์•„๋งˆ ํ˜ธ๋ˆ…์Šค์˜€๋˜ ๊ฒƒ ๊ฐ™์€) ์Šคํ”„๋ง๋ถ€ํŠธ์— ๋‚ด์žฅ๋œ Jackson ์‚ฌ์šฉ์„ ๊ถŒ์žฅํ•˜์‹œ๋”๋ผ๊ตฌ์š”. ์•„๋ฌด๋ž˜๋„ ๊ทธ๊ฒŒ ๋งž์„๊นŒ์š”? ๊ทธ๋Ÿฐ๋ฐ gson์ด ์•„๋ฌด๋ž˜๋„ Jackson์— ๋น„ํ•ด ์‚ฌ์šฉํ•˜๊ธฐ๋Š” ์‰ฝ๋‹ค๋ณด๋‹ˆ ใ…Žใ…Ž
@@ -0,0 +1,131 @@ +package com.codesquad.dust4.service; + +import com.codesquad.dust4.domain.DustStatusQuo; +import com.codesquad.dust4.domain.LocationOfStation; +import com.codesquad.dust4.dto.DustInfoByStationDto; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class DustStatusPublicApi { + public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException { + String response = stationFromPublicApi(tmX, tmY); + LocationOfStation closestStation = closestStation(response); + String dustStatusResponse = dustStatusFromPublicApi(closestStation); + List<DustStatusQuo> status = statusQuos(dustStatusResponse); + + return new DustInfoByStationDto(status, closestStation); + } + + private static LocationOfStation closestStation(String stationJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<LocationOfStation> stations = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(stationJson); + array = (JSONArray) obj.get("list"); + for (Object o : array) { + JSONObject o1 = (JSONObject) o; + String addr = String.valueOf(o1.get("addr")); + String stationName = String.valueOf(o1.get("stationName")); + String tm = String.valueOf(o1.get("tm")); + + LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm)); + stations.add(station); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station); + } + + private static String stationFromPublicApi(String tmX, String tmY) throws IOException { + URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY + + "&tmX=" + tmX + + "&tmY=" + tmY + + "&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } + + private static List<DustStatusQuo> statusQuos(String statusJson) { + JSONParser parser = new JSONParser(); + JSONObject obj; + JSONArray array; + List<DustStatusQuo> statusList = new ArrayList<>(); + + try { + obj = (JSONObject) parser.parse(statusJson); + array = (JSONArray) obj.get("list"); + for (Object object : array) { + JSONObject stationObject = (JSONObject) object; + String dateTime = String.valueOf(stationObject.get("dataTime")); + String grade = String.valueOf(stationObject.get("pm10Grade")); + if (grade.equals("-")) { + grade = "0"; + } + String value = String.valueOf(stationObject.get("pm10Value")); + if (value.equals("-")) { + value = "0"; + } + + DustStatusQuo status = new DustStatusQuo(dateTime, value, grade); + statusList.add(status); + } + } catch (ParseException e) { + e.printStackTrace(); + } + + return statusList; + } + + private static String readString(HttpURLConnection connection) throws IOException { + BufferedReader bufferedReader; + if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + } else { + bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); + } + + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + + bufferedReader.close(); + connection.disconnect(); + + return stringBuilder.toString(); + } + + + private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException { + URL url = new URL(PublicApi.API_URL + + "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" + + station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" + + PublicApi.API_KEY + + "&ver=1.3&_returnType=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-type", "application/json"); + + return readString(connection); + } +}
Java
์ธํ…”๋ฆฌ์ œ์ด์— ์ €์žฅํ•  ๋•Œ ์•Œ์•„์„œ ์ปจ๋ฒค์…˜์„ ๋งž์ถฐ์ฃผ๋Š” ๊ธฐ๋Šฅ์ด ์žˆ๋‹ค๊ณ  ํ•˜๋˜๋ฐ์š”. ๊ทธ ์ด๋ฆ„์ด ๊ธฐ์–ต์ด ์•ˆ๋‚˜์ง€๋งŒ ๋„์ž…์„ ํ•ด์•ผ๊ฐฐ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,67 @@ +package christmas.controller; + +import christmas.domain.Menu; +import christmas.domain.Today; +import christmas.domain.dao.OrderDAO; +import christmas.service.EventDatable; +import christmas.service.EventDateService; +import christmas.service.EventPrice; +import christmas.view.InputView; +import christmas.view.OutputView; + +public class Planner { + private final EventDatable eventDatable = new EventDateService(); + private final OrderDAO orderDAO = OrderDAO.getInstance(); + private Today today; + private EventPrice eventPrice; + + public void run() { + InputView.printStartMessage(); + dateRun(); + menuRun(); + eventPrice = new EventPrice(today); + InputView.printResultMessage(); + discountDetailsRun(); + } + + private void menuRun() { + while (true) { + try { + orderDAO.addOrderDetail(InputView.readOrderAccept()); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private void dateRun() { + while (true) { + try { + String input = InputView.readVisitDate(); + Validator.validateDateToNumber(input); + today = new Today(Integer.parseInt(input), eventDatable); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private String giveaway() { + if (eventPrice.isGiveawayLimit()) { + return Menu.CHAMPAGNE.getName() + " 1๊ฐœ"; + } + return null; + } + + private void discountDetailsRun() { + OutputView.printMenu(orderDAO.getOrder()); + OutputView.printTotalOrderPrice(eventPrice.getTotalPrice()); + OutputView.printGiveAway(giveaway()); + OutputView.printBenefitDetails(eventPrice.getDiscountDetails()); + OutputView.printTotalBenefit(eventPrice.totalDiscount()); + OutputView.printResultPayment(eventPrice.totalDiscountExcludingGiveaway()); + OutputView.printEventBadge(eventPrice.getEventBadge()); + } +}
Java
Planner ๋ณด๋‹ค๋Š” ~~~Controller๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋ฐ”๊พธ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ฒ˜์Œ์— ๋„๋ฉ”์ธ์ธ ์ค„ ์•Œ์•˜์–ด์š”.
@@ -0,0 +1,67 @@ +package christmas.controller; + +import christmas.domain.Menu; +import christmas.domain.Today; +import christmas.domain.dao.OrderDAO; +import christmas.service.EventDatable; +import christmas.service.EventDateService; +import christmas.service.EventPrice; +import christmas.view.InputView; +import christmas.view.OutputView; + +public class Planner { + private final EventDatable eventDatable = new EventDateService(); + private final OrderDAO orderDAO = OrderDAO.getInstance(); + private Today today; + private EventPrice eventPrice; + + public void run() { + InputView.printStartMessage(); + dateRun(); + menuRun(); + eventPrice = new EventPrice(today); + InputView.printResultMessage(); + discountDetailsRun(); + } + + private void menuRun() { + while (true) { + try { + orderDAO.addOrderDetail(InputView.readOrderAccept()); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private void dateRun() { + while (true) { + try { + String input = InputView.readVisitDate(); + Validator.validateDateToNumber(input); + today = new Today(Integer.parseInt(input), eventDatable); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private String giveaway() { + if (eventPrice.isGiveawayLimit()) { + return Menu.CHAMPAGNE.getName() + " 1๊ฐœ"; + } + return null; + } + + private void discountDetailsRun() { + OutputView.printMenu(orderDAO.getOrder()); + OutputView.printTotalOrderPrice(eventPrice.getTotalPrice()); + OutputView.printGiveAway(giveaway()); + OutputView.printBenefitDetails(eventPrice.getDiscountDetails()); + OutputView.printTotalBenefit(eventPrice.totalDiscount()); + OutputView.printResultPayment(eventPrice.totalDiscountExcludingGiveaway()); + OutputView.printEventBadge(eventPrice.getEventBadge()); + } +}
Java
์ปจํŠธ๋กค๋Ÿฌ๋Š” ์ƒํƒœ๋ฅผ ๊ฐ€์ง€์ง€ ์•Š๋Š” ๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค. Today์™€ EventPrice๋ฅผ ๋ฉ”์†Œ๋“œ ๋‚ด ์ง€์—ญ๋ณ€์ˆ˜๋กœ ํ™œ์šฉํ•ด์ฃผ์„ธ์š”. ์œ ์ง€๋ณด์ˆ˜ ์‹œ, ๊ฐ’์„ ์ž˜๋ชป ํ• ๋‹นํ•˜๊ฑฐ๋‚˜ ์‹คํ–‰ ์ˆœ์„œ๊ฐ€ ๊ผฌ์—ฌ์„œ ์˜๋„ํ•˜์ง€ ์•Š์€ ๋ฒ„๊ทธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์–ด์š”.
@@ -0,0 +1,67 @@ +package christmas.controller; + +import christmas.domain.Menu; +import christmas.domain.Today; +import christmas.domain.dao.OrderDAO; +import christmas.service.EventDatable; +import christmas.service.EventDateService; +import christmas.service.EventPrice; +import christmas.view.InputView; +import christmas.view.OutputView; + +public class Planner { + private final EventDatable eventDatable = new EventDateService(); + private final OrderDAO orderDAO = OrderDAO.getInstance(); + private Today today; + private EventPrice eventPrice; + + public void run() { + InputView.printStartMessage(); + dateRun(); + menuRun(); + eventPrice = new EventPrice(today); + InputView.printResultMessage(); + discountDetailsRun(); + } + + private void menuRun() { + while (true) { + try { + orderDAO.addOrderDetail(InputView.readOrderAccept()); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private void dateRun() { + while (true) { + try { + String input = InputView.readVisitDate(); + Validator.validateDateToNumber(input); + today = new Today(Integer.parseInt(input), eventDatable); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private String giveaway() { + if (eventPrice.isGiveawayLimit()) { + return Menu.CHAMPAGNE.getName() + " 1๊ฐœ"; + } + return null; + } + + private void discountDetailsRun() { + OutputView.printMenu(orderDAO.getOrder()); + OutputView.printTotalOrderPrice(eventPrice.getTotalPrice()); + OutputView.printGiveAway(giveaway()); + OutputView.printBenefitDetails(eventPrice.getDiscountDetails()); + OutputView.printTotalBenefit(eventPrice.totalDiscount()); + OutputView.printResultPayment(eventPrice.totalDiscountExcludingGiveaway()); + OutputView.printEventBadge(eventPrice.getEventBadge()); + } +}
Java
eventPrice์˜ ๋กœ์ง์ด ์™ธ๋ถ€๋กœ ๋…ธ์ถœ๋˜์–ด ์žˆ์–ด์š”. ๋กœ์ง์„ eventPrice ๋‚ด๋ถ€๋กœ ์˜ฎ๊ฒจ์ฃผ์„ธ์š”. ```suggestion private String giveaway() { return eventPrice.getGiveawayMessage(); } ```
@@ -0,0 +1,11 @@ +package christmas.controller; + +public class Validator { + public static void validateDateToNumber(String number) { + try { + Integer.parseInt(number); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } +}
Java
Validator๋ฅผ validator ํŒจํ‚ค์ง€๋กœ ์˜ฎ๊ฒจ์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ด๋ฆ„๋„ DateValidator๋กœ ๋ฐ”๊พธ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”.
@@ -0,0 +1,75 @@ +package christmas.domain; + +import java.util.Map; +import java.util.AbstractMap; + +public enum Menu { + APPETIZER(0, 0, "์• ํ”ผํƒ€์ด์ €"), + MAIN_DISH(1, 2023, "๋ฉ”์ธ"), + DESSERT(2, 2023, "๋””์ €ํŠธ"), + DRINK(3, 0, "์Œ๋ฃŒ"), + MUSHROOM_SOUP(0, 6000, "์–‘์†ก์ด์ˆ˜ํ”„"), + TAPAS(0, 5500, "ํƒ€ํŒŒ์Šค"), + CAESAR_SALAD(0, 8000, "์‹œ์ €์ƒ๋Ÿฌ๋“œ"), + T_BONE_STEAK(1, 55000, "ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ"), + BBQ_RIBS(1, 54000, "๋ฐ”๋น„ํ๋ฆฝ"), + SEAFOOD_PASTA(1, 35000, "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€"), + CHRISTMAS_PASTA(1, 25000, "ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€"), + CHOCO_CAKE(2, 15000, "์ดˆ์ฝ”์ผ€์ดํฌ"), + ICE_CREAM(2, 5000, "์•„์ด์Šคํฌ๋ฆผ"), + ZERO_COKE(3, 3000, "์ œ๋กœ์ฝœ๋ผ"), + RED_WINE(3, 60000, "๋ ˆ๋“œ์™€์ธ"), + CHAMPAGNE(3, 25000, "์ƒดํŽ˜์ธ"); + + private final int type; + private final int price; + private final String name; + + Menu(int type, int price, String name) { + this.type = type; + this.price = price; + this.name = name; + } + + public String getName() { + return name; + } + + public static Menu matchingMenu(String inputMenuName) { + for (Menu menu : Menu.values()) { + if (menu.name.equalsIgnoreCase(inputMenuName)) { + return menu; + } + } + throw new IllegalArgumentException("[ERROR] ์ž…๋ ฅํ•˜์‹  ๋ฉ”๋‰ด๋Š” ์—†๋Š” ๋ฉ”๋‰ด์ž…๋‹ˆ๋‹ค."); + } + + public static AbstractMap.SimpleEntry<String, Integer> giveawayChampagne() { + return new AbstractMap.SimpleEntry<>(CHAMPAGNE.name, CHAMPAGNE.price); + } + + public static boolean isAllDrinks(Map<Menu, Integer> orderDetail) { + return orderDetail.keySet().stream() + .allMatch(item -> item.type == DRINK.type); + } + + public static int calculateTotalPrice(Map<Menu, Integer> orderDetail) { + return orderDetail.entrySet().stream() + .mapToInt(entry -> entry.getKey().price * entry.getValue()) + .sum(); + } + + public static int calculateMainDishDiscount(Map<Menu, Integer> orderDetail) { + return orderDetail.entrySet().stream() + .filter(entry -> entry.getKey().type == MAIN_DISH.type) + .mapToInt(entry -> MAIN_DISH.price * entry.getValue()) + .sum(); + } + + public static int calculateDessertDiscount(Map<Menu, Integer> orderDetail) { + return orderDetail.entrySet().stream() + .filter(entry -> entry.getKey().type == DESSERT.type) + .mapToInt(entry -> DESSERT.price * entry.getValue()) + .sum(); + } +}
Java
type์„ ์ˆซ์ž๋กœ ๊ตฌ๋ณ„ํ•˜์ง€ ๋ง๊ณ  ์ƒˆ enum์„ ํŒŒ์„œ ๊ตฌ๋ณ„ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”. ์ €๋Š” Course enum์—์„œ APPETIZER, MAIN, DESSERT, DRINK๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ตฌ๋ณ„ํ–ˆ์–ด์š”.
@@ -0,0 +1,48 @@ +package christmas.domain; + +import christmas.service.EventDatable; + +public class Today { + private final DayOfWeek startDayOfMonth = DayOfWeek.FRIDAY; + private final EventDatable eventDatable; + private final int INDEX_ALIGN = 1; + private final int WEEK_LENGTH = 7; + private DayOfWeek todayOfWeek; + private int todayDate; + + enum DayOfWeek { + SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY + } + + public Today(int inputDate, EventDatable eventDatable) { + this.eventDatable = eventDatable; + setDate(inputDate); + } + + public void setDate(int inputDate) { + eventDatable.validateDecemberDate(inputDate); + this.todayDate = inputDate; + this.todayOfWeek = getDayOfWeek(inputDate, startDayOfMonth); + } + + public int getChristmasEventToday() { + if (eventDatable.isChristmasEventDay(todayDate)) { + return (todayDate * 100) + 900; + } + return 0; + } + + public boolean isWeekend() { + return todayOfWeek == DayOfWeek.FRIDAY || todayOfWeek == DayOfWeek.SATURDAY; + } + + public boolean isSpecialDay() { + return todayOfWeek == DayOfWeek.SUNDAY || eventDatable.isChristmasDDay(todayDate); + } + + private DayOfWeek getDayOfWeek(int inputDate, DayOfWeek startDate) { + int startDayIndex = startDate.ordinal(); + int dayOfWeekIndex = (startDayIndex + inputDate - INDEX_ALIGN) % WEEK_LENGTH; + return DayOfWeek.values()[dayOfWeekIndex]; + } +}
Java
setter๋Š” ์ง€์–‘ํ•ด์ฃผ์„ธ์š”. ๋‚ด๋ถ€์ ์œผ๋กœ๋งŒ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค๋ฉด, private๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
@@ -0,0 +1,30 @@ +package christmas.domain.dao; + +import christmas.domain.Menu; +import christmas.domain.parser.OrderParsable; +import christmas.domain.parser.OrderParser; + +import java.util.Map; +import java.util.Collections; + +public class OrderDAO { + private final OrderParsable orderParsable; + private static final OrderDAO ORDER_DAO = new OrderDAO(); + private static Map<Menu, Integer> orderDetail; + + private OrderDAO() { + this.orderParsable = new OrderParser(); + } + + public static OrderDAO getInstance() { + return ORDER_DAO; + } + + public Map<Menu, Integer> getOrder() { + return Collections.unmodifiableMap(orderDetail); + } + + public void addOrderDetail(String inputOrder) { + orderDetail = orderParsable.getOrderDetail(inputOrder); + } +}
Java
๋ฒ„๊ทธ๊ฐ€ ์ผ์–ด๋‚˜๊ธฐ ์ •๋ง ์‰ฌ์šด ์„ค๊ณ„์—์š”. private static ๋ณ€์ˆ˜๋ฅผ ์กฐ์ž‘ํ•˜๋Š” add ๋ฉ”์†Œ๋“œ๊ฐ€ ์กด์žฌํ•˜๊ณ  ์žˆ๊ณ , getOrder์—์„œ ์ดˆ๊ธฐํ™”๋˜์ง€๋„ ์•Š์•„์š”. static์„ ๋ชจ๋‘ ์—†์• ๊ณ  ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ ์ธ์Šคํ„ด์Šค๋กœ ์ƒ์„ฑํ•ด์„œ ํ™œ์šฉํ•˜์„ธ์š”.