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์ ๋ชจ๋ ์์ ๊ณ ํด๋น ํด๋์ค๋ฅผ ์ธ์คํด์ค๋ก ์์ฑํด์ ํ์ฉํ์ธ์. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.