code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -0,0 +1,17 @@ +package lotto.domain + +object LottoTicketMachine { + fun issue(nums: List<Int>): LottoTicket { + require(nums.size == 6) { + "๋กœ๋˜ ๊ฐœ์ˆ˜๋ฅผ ์ž˜๋ชป ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค" + } + + val lottoBox = LottoBox() + + val lottoNums = nums.map { + lottoBox.getLottoNum(it) + }.toList() + + return LottoTicket(lottoNums) + } +}
Kotlin
issue๋ผ๋Š” ๋„ค์ด๋ฐ์„ ๋ถ™์ด์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,24 @@ +package lotto.domain + +class LottoBox { + private val lottoNums: MutableMap<Int, LottoNum> + + init { + val intRange = 1..45 + + lottoNums = intRange + .map { LottoNum(it) } + .associateBy { it.num } + .toMutableMap() + } + + fun getLottoNum(num: Int): LottoNum { + val lottoNum = lottoNums[num] + require(lottoNum != null) { + "๋กœ๋˜ ์ˆซ์ž๋Š” ์ค‘๋ณตํ•ด์„œ ์ž…๋ ฅํ•  ์ˆ˜ ์—…์Šต๋‹ˆ๋‹ค" + } + + lottoNums.remove(lottoNum.num) + return lottoNum + } +}
Kotlin
LottoBox๋งŒ ๋ดค์„๋•Œ lottoNum์ด null์ด๋ผ๊ณ ํ•ด์„œ ์ค‘๋ณต๋œ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ–ˆ๋‹ค๊ณ  ๋ณด์žฅํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,28 @@ +package lotto.domain + +class LottoNum(num: Int) { + val num: Int + + init { + require(num in 1..45) { + "๋กœ๋˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 1 ~ 45 ์ž…๋‹ˆ๋‹ค." + } + + this.num = num + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as LottoNum + + if (num != other.num) return false + + return true + } + + override fun hashCode(): Int { + return num + } +}
Kotlin
inline class๋ฅผ ํ™œ์šฉํ•ด๋ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!! :) > ๋ž˜ํผํด๋ž˜์Šค๋กœ inline class์™€ value class ๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฑฐ ๊ฐ™์€๋ฐ์š”! ์ž˜ ์ดํ•ด๊ฐ€ ์•ˆ๊ฐ€์„œ์š”~ ๋ญ”๊ฐ€ ์ข‹์€ ๊ธฐ๋Šฅ๊ฐ™๊ธฐ๋„ ํ•œ๋ฐ, ์‹ค๋ฌด์—์„œ ์–ด๋–ป๊ฒŒ, ์–ด๋–ค์ƒํ™ฉ์— ์‚ฌ์šฉํ•˜๋ฉด ์ข‹์„์ง€ ์งˆ๋ฌธ๋“œ๋ฆฝ๋‹ˆ๋‹ค! ์‚ฌ์‹ค ์ €๋„ ์ž˜ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ๋ง์”€๋“œ๋ฆฌ๊ธฐ๋Š” ์–ด๋ ต์ง€๋งŒ, ์ €๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ๊ธฐ์ค€์„ ์ถฉ์กฑ์‹œํ‚ค๋Š” ๊ฒฝ์šฐ ์ธ๋ผ์ธ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด์š” * ํ•ด๋‹น ๋ž˜ํผํƒ€์ž…์ด ์—ฌ๋Ÿฌ๊ณณ์—์„œ ํ˜ธ์ถœ๋˜๋Š”๊ฐ€? * ํ•ด๋‹น ํด๋ž˜์Šค๊ฐ€ data class์˜ ํŠน์ง•์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๊ฐ€? ์‹ค๋ฌด์—์„œ ์ ์šฉ์€ ํ•„์ˆ˜๊ฐ€ ์•„๋‹ˆ๊ณ  ํŒ€์›๋“ค๋งˆ๋‹ค ์˜๊ฒฌ์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์œผ๋‹ˆ ํŒ€ ๋‚ด๋ถ€์ ์œผ๋กœ๋„ ์ด์•ผ๊ธฐ๋ฅผ ํ•ด๋ณด๊ณ  ์ปจ๋ฒค์…˜์„ ์žก์•„๊ฐ€๋ณด๋Š”๊ฒƒ๋„ ๋ฐฉ๋ฒ•์ผ ๊ฒƒ ๊ฐ™์•„์š”! [์ด๋Ÿฐ ๊ธ€](https://github.com/Kotlin/KEEP/blob/master/notes/value-classes.md)๋„ ์ฝ์–ด๋ณด๋ฉด ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์•„์š”!! :)
@@ -0,0 +1,28 @@ +package lotto.domain + +class LottoNum(num: Int) { + val num: Int + + init { + require(num in 1..45) { + "๋กœ๋˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 1 ~ 45 ์ž…๋‹ˆ๋‹ค." + } + + this.num = num + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as LottoNum + + if (num != other.num) return false + + return true + } + + override fun hashCode(): Int { + return num + } +}
Kotlin
์—ฌ๊ธฐ๋„ ๋งค์ง๋„˜๋ฒ„๋ฅผ ์ƒ์ˆ˜ํ™”ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?
@@ -1,14 +1,40 @@ -import React from "react"; -import "./PostList.scss"; +import React, { useEffect, useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import Posts from './components/Posts'; +import './PostList.scss'; const PostList = () => { + const [postData, setPostData] = useState([]); -return( - <div className="postList"> - <div>๋กœ๊ทธ์ธ</div> - </div> -); + const navigate = useNavigate(); + const goToWrite = () => { + navigate('/post-add'); + }; + useEffect(() => { + fetch('/data/postList.json', { + method: 'GET', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + }) + .then(res => res.json()) + .then(result => { + setPostData(result.data); + }); + }, []); + + if (postData.length === 0) return null; + return ( + <div className="postList"> + <div className="posts"> + <Posts postData={postData} /> + </div> + <div className="buttonPlace"> + <button onClick={goToWrite}>๊ธ€์“ฐ๊ธฐ</button> + </div> + </div> + ); }; -export default PostList; \ No newline at end of file +export default PostList;
JavaScript
import ์ˆœ์„œ์—๋„ ์œ ์ง€๋ณด์ˆ˜ ๋ฐ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•œ ์ปจ๋ฒค์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์œ„์ฝ”๋“œ์˜ ์ปจ๋ฒค์…˜์€ ๊ฐ„๋žตํ•˜๊ฒŒ ์•„๋ž˜์™€ ๊ฐ™๊ณ , ์ฐธ๊ณ ํ•ด์„œ ์ˆ˜์ •ํ•ด ์ฃผ์„ธ์š”! - ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ - React ๊ด€๋ จ ํŒจํ‚ค์ง€ - ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ - ์ปดํฌ๋„ŒํŠธ - ๊ณตํ†ต ์ปดํฌ๋„ŒํŠธ โ†’ ๋จผ ์ปดํฌ๋„ŒํŠธ โ†’ ๊ฐ€๊นŒ์šด ์ปดํฌ๋„ŒํŠธ - ํ•จ์ˆ˜, ๋ณ€์ˆ˜ ๋ฐ ์„ค์ • ํŒŒ์ผ - ์‚ฌ์ง„ ๋“ฑ ๋ฏธ๋””์–ด ํŒŒ์ผ(`.png`) - css ํŒŒ์ผ (.`scss`)
@@ -0,0 +1,63 @@ +.postList { + margin: 0 auto; + display: flex; + width: 576px; + height: 80vh; + padding: 40px 24px; + flex-direction: column; + align-items: center; + border-radius: 16px; + border: 1px solid #e5e5e5; + background: white; + + .posts { + width: 100%; + overflow-y: scroll; + flex: 1; + cursor: pointer; + } + & ::-webkit-scrollbar { + display: none; + } + + .buttonPlace { + display: flex; + flex-direction: column; + width: 528px; + height: 56px; + margin-top: 28px; + align-items: flex-end; + gap: 8px; + align-self: stretch; + + a { + text-decoration: none; + } + + button { + display: flex; + width: 120px; + height: 56px; + padding: 0px 34px; + justify-content: center; + align-items: center; + border-radius: 6px; + background-color: #2d71f7; + color: #fff; + text-align: center; + font-feature-settings: + 'clig' off, + 'liga' off; + font-family: Apple SD Gothic Neo; + font-size: 16px; + font-style: normal; + font-weight: 800; + line-height: normal; + + &:hover { + border-radius: 6px; + background: #083e7f; + } + } + } +}
Unknown
๋ถ€๋ชจ ์„ ํƒ์ž(`&`)๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ•ด๋‹น ์š”์†Œ์—๋งŒ ์ ์šฉ๋˜๋Š” ์Šคํƒ€์ผ์ž„์„ ์ข€ ๋” ๊น”๋”ํ•˜๊ฒŒ ๋ช…์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค! ```suggestion .posts { overflow-y: scroll; flex: 1; &::-webkit-scrollbar { display: none; } } ```
@@ -1,7 +1,18 @@ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap'); - * { box-sizing: border-box; font-family: 'Noto Sans KR', sans-serif; -} \ No newline at end of file +} + +body { + width: 100vw; + height: 100vh; + display: flex; + align-items: center; + justify-content: center; +} + +button { + cursor: pointer; +}
Unknown
๊ณต์šฉ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์„œ ์˜ฌ๋ ค์ฃผ์…จ๋Š”๋ฐ, ๊ณต์šฉ ํŒŒ์ผ์˜ ์ˆ˜์ •์€ 1. ํŒ€์›๊ณผ์˜ ์ถฉ๋ถ„ํ•œ ์ƒ์˜ ํ›„์— 2. ํ•ด๋‹น ํŒŒ์ผ๋งŒ ์ˆ˜์ •ํ•˜๋Š” ๋‚ด์šฉ์˜ PR ์„ ์˜ฌ๋ ค์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!
@@ -1,9 +1,100 @@ -function Header(logo, searchBox) { +import Input from './Input'; +import Button from './Button'; +import { handleSearch } from '../services/handleSeach'; + +function Header({ logoSrc, logoAlt, onSearch }) { const headerElement = document.createElement('header'); - headerElement.classList.add('header'); - headerElement.appendChild(logo); - headerElement.appendChild(searchBox); + headerElement.innerHTML = ` + <h1><img src="${logoSrc}" alt="${logoAlt}" loading="lazy"></h1> + <div class="search-box"></div> + `; + + let page = 1; + + const searchInput = Input({ + id: 'search-input', + type: 'text', + placeholder: '๊ฒ€์ƒ‰', + onKeyDown: async (event) => { + if (event.code === 'Enter') { + document.getElementById('more-movies').remove(); + const sectionContainer = document.querySelector('.item-view'); + + sectionContainer.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleSearch(searchInput.value, page); + } + }) + ); + + await onSearch(event.target.value, page); + } + } + }); + + const searchButton = Button({ + classNames: ['search-button'], + name: '๊ฒ€์ƒ‰', + type: 'button', + onClick: async () => { + document.getElementById('more-movies').remove(); + const sectionContainer = document.querySelector('.item-view'); + + sectionContainer.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleSearch(searchInput.value, page); + } + }) + ); + + const inputValue = document.getElementById('search-input').value; + await onSearch(inputValue, page); + } + }); + + const searchBox = headerElement.querySelector('.search-box'); + + searchBox.addEventListener('mouseenter', () => { + const width = document.querySelector('body').getBoundingClientRect().width; + + if (width <= 390) { + const input = document.getElementById('search-input'); + const logo = document.querySelector('header h1'); + + searchBox.classList.add('search-box-toggle'); + input.classList.add('input-toggle'); + logo.classList.add('logo-toggle'); + } + }); + + searchBox.addEventListener('mouseleave', () => { + const width = document.querySelector('body').getBoundingClientRect().width; + + if (width <= 390) { + const input = document.getElementById('search-input'); + const logo = document.querySelector('header h1'); + + searchBox.classList.remove('search-box-toggle'); + input.classList.remove('input-toggle'); + logo.classList.remove('logo-toggle'); + } + }); + + searchBox.appendChild(searchInput); + searchBox.appendChild(searchButton); return headerElement; }
JavaScript
์ €๋Š” ์ด๋ฒคํŠธ์˜ ์ด๋ฆ„์ด ์˜๋ฏธํ•˜๋Š”๊ฒŒ "ํ–‰์œ„์˜ ๋ฐœ์ƒ" ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ด์š”. ๊ฐ€๋ น, `onChange` ๋Š” ์‹ค์ œ๋กœ change๊ฐ€ ์ผ์–ด๋‚ฌ์„ ๋•Œ์ด๊ณ , `onKeyDown` ์€ ํ‚ค๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ ์ž…๋‹ˆ๋‹ค. `onSearch`๋Š” "๊ฒ€์ƒ‰์ด ๋˜์—ˆ์„ ๋•Œ ๋ฐœ์ƒ" ์ธ๋ฐ, ์ด ์ปดํฌ๋„ŒํŠธ์—์„œ ์‹ค์ œ๋กœ "๊ฒ€์ƒ‰"์ด๋ผ๋Š” ํ–‰์œ„๊ฐ€ ์ผ์–ด๋‚ฌ๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”? ์ง€๊ธˆ์€ "๊ฒ€์ƒ‰"์ด๋ผ๋Š” ํ–‰์œ„๋ฅผ ๋ฐ–์—์„œ ์ฃผ์ž…ํ•ด์ฃผ๊ณ , ์ด ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์—์„œ ์ผ์–ด๋‚œ ์ผ์€ "์—”ํ„ฐํ‚ค๋ฅผ ๋ˆŒ๋ €์Œ" ์ž…๋‹ˆ๋‹ค. ์ฆ‰, ์ด๋ฒคํŠธ๋Š” "๊ฒ€์ƒ‰ํ–ˆ์„ ๋•Œ ๋ฐœ์ƒํ•จ"์„ ์ด์•ผ๊ธฐํ•˜๊ณ  ์žˆ๋Š”๋ฐ ๊ฒ€์ƒ‰์ด๋ผ๋Š” ๊ธฐ๋Šฅ์€ ๋ฐ–์—์„œ ์ฃผ์ž…ํ•ด์ค„ ์ˆ˜ ๋ฐ–์— ์—†๋Š” ์ƒํ™ฉ์ธ๊ฑฐ์ฃ .
@@ -1,9 +1,100 @@ -function Header(logo, searchBox) { +import Input from './Input'; +import Button from './Button'; +import { handleSearch } from '../services/handleSeach'; + +function Header({ logoSrc, logoAlt, onSearch }) { const headerElement = document.createElement('header'); - headerElement.classList.add('header'); - headerElement.appendChild(logo); - headerElement.appendChild(searchBox); + headerElement.innerHTML = ` + <h1><img src="${logoSrc}" alt="${logoAlt}" loading="lazy"></h1> + <div class="search-box"></div> + `; + + let page = 1; + + const searchInput = Input({ + id: 'search-input', + type: 'text', + placeholder: '๊ฒ€์ƒ‰', + onKeyDown: async (event) => { + if (event.code === 'Enter') { + document.getElementById('more-movies').remove(); + const sectionContainer = document.querySelector('.item-view'); + + sectionContainer.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleSearch(searchInput.value, page); + } + }) + ); + + await onSearch(event.target.value, page); + } + } + }); + + const searchButton = Button({ + classNames: ['search-button'], + name: '๊ฒ€์ƒ‰', + type: 'button', + onClick: async () => { + document.getElementById('more-movies').remove(); + const sectionContainer = document.querySelector('.item-view'); + + sectionContainer.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleSearch(searchInput.value, page); + } + }) + ); + + const inputValue = document.getElementById('search-input').value; + await onSearch(inputValue, page); + } + }); + + const searchBox = headerElement.querySelector('.search-box'); + + searchBox.addEventListener('mouseenter', () => { + const width = document.querySelector('body').getBoundingClientRect().width; + + if (width <= 390) { + const input = document.getElementById('search-input'); + const logo = document.querySelector('header h1'); + + searchBox.classList.add('search-box-toggle'); + input.classList.add('input-toggle'); + logo.classList.add('logo-toggle'); + } + }); + + searchBox.addEventListener('mouseleave', () => { + const width = document.querySelector('body').getBoundingClientRect().width; + + if (width <= 390) { + const input = document.getElementById('search-input'); + const logo = document.querySelector('header h1'); + + searchBox.classList.remove('search-box-toggle'); + input.classList.remove('input-toggle'); + logo.classList.remove('logo-toggle'); + } + }); + + searchBox.appendChild(searchInput); + searchBox.appendChild(searchButton); return headerElement; }
JavaScript
์ด ๋ถ€๋ถ„๋„ ๋™์ผํ•ฉ๋‹ˆ๋‹ค!
@@ -1,9 +1,100 @@ -function Header(logo, searchBox) { +import Input from './Input'; +import Button from './Button'; +import { handleSearch } from '../services/handleSeach'; + +function Header({ logoSrc, logoAlt, onSearch }) { const headerElement = document.createElement('header'); - headerElement.classList.add('header'); - headerElement.appendChild(logo); - headerElement.appendChild(searchBox); + headerElement.innerHTML = ` + <h1><img src="${logoSrc}" alt="${logoAlt}" loading="lazy"></h1> + <div class="search-box"></div> + `; + + let page = 1; + + const searchInput = Input({ + id: 'search-input', + type: 'text', + placeholder: '๊ฒ€์ƒ‰', + onKeyDown: async (event) => { + if (event.code === 'Enter') { + document.getElementById('more-movies').remove(); + const sectionContainer = document.querySelector('.item-view'); + + sectionContainer.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleSearch(searchInput.value, page); + } + }) + ); + + await onSearch(event.target.value, page); + } + } + }); + + const searchButton = Button({ + classNames: ['search-button'], + name: '๊ฒ€์ƒ‰', + type: 'button', + onClick: async () => { + document.getElementById('more-movies').remove(); + const sectionContainer = document.querySelector('.item-view'); + + sectionContainer.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleSearch(searchInput.value, page); + } + }) + ); + + const inputValue = document.getElementById('search-input').value; + await onSearch(inputValue, page); + } + }); + + const searchBox = headerElement.querySelector('.search-box'); + + searchBox.addEventListener('mouseenter', () => { + const width = document.querySelector('body').getBoundingClientRect().width; + + if (width <= 390) { + const input = document.getElementById('search-input'); + const logo = document.querySelector('header h1'); + + searchBox.classList.add('search-box-toggle'); + input.classList.add('input-toggle'); + logo.classList.add('logo-toggle'); + } + }); + + searchBox.addEventListener('mouseleave', () => { + const width = document.querySelector('body').getBoundingClientRect().width; + + if (width <= 390) { + const input = document.getElementById('search-input'); + const logo = document.querySelector('header h1'); + + searchBox.classList.remove('search-box-toggle'); + input.classList.remove('input-toggle'); + logo.classList.remove('logo-toggle'); + } + }); + + searchBox.appendChild(searchInput); + searchBox.appendChild(searchButton); return headerElement; }
JavaScript
์—ฌ๊ธฐ์„œ ์“ฐ์ด๋Š” 390 ์ด๋ผ๋Š” ์ˆซ์ž๋Š” ์ƒ์ˆ˜๋กœ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•ด์ฃผ๋ฉด ์–ด๋–จ๊นŒ์š”!?
@@ -1,9 +1,100 @@ -function Header(logo, searchBox) { +import Input from './Input'; +import Button from './Button'; +import { handleSearch } from '../services/handleSeach'; + +function Header({ logoSrc, logoAlt, onSearch }) { const headerElement = document.createElement('header'); - headerElement.classList.add('header'); - headerElement.appendChild(logo); - headerElement.appendChild(searchBox); + headerElement.innerHTML = ` + <h1><img src="${logoSrc}" alt="${logoAlt}" loading="lazy"></h1> + <div class="search-box"></div> + `; + + let page = 1; + + const searchInput = Input({ + id: 'search-input', + type: 'text', + placeholder: '๊ฒ€์ƒ‰', + onKeyDown: async (event) => { + if (event.code === 'Enter') { + document.getElementById('more-movies').remove(); + const sectionContainer = document.querySelector('.item-view'); + + sectionContainer.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleSearch(searchInput.value, page); + } + }) + ); + + await onSearch(event.target.value, page); + } + } + }); + + const searchButton = Button({ + classNames: ['search-button'], + name: '๊ฒ€์ƒ‰', + type: 'button', + onClick: async () => { + document.getElementById('more-movies').remove(); + const sectionContainer = document.querySelector('.item-view'); + + sectionContainer.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleSearch(searchInput.value, page); + } + }) + ); + + const inputValue = document.getElementById('search-input').value; + await onSearch(inputValue, page); + } + }); + + const searchBox = headerElement.querySelector('.search-box'); + + searchBox.addEventListener('mouseenter', () => { + const width = document.querySelector('body').getBoundingClientRect().width; + + if (width <= 390) { + const input = document.getElementById('search-input'); + const logo = document.querySelector('header h1'); + + searchBox.classList.add('search-box-toggle'); + input.classList.add('input-toggle'); + logo.classList.add('logo-toggle'); + } + }); + + searchBox.addEventListener('mouseleave', () => { + const width = document.querySelector('body').getBoundingClientRect().width; + + if (width <= 390) { + const input = document.getElementById('search-input'); + const logo = document.querySelector('header h1'); + + searchBox.classList.remove('search-box-toggle'); + input.classList.remove('input-toggle'); + logo.classList.remove('logo-toggle'); + } + }); + + searchBox.appendChild(searchInput); + searchBox.appendChild(searchButton); return headerElement; }
JavaScript
์ž˜ ๋ณด๋‹ˆ๊นŒ ๋กœ์ง์ด ๊ฑฐ์˜ ์œ ์‚ฌํ•˜๋„ค์š”!
@@ -0,0 +1,33 @@ +import handleMovie from '../services/handleMovie'; +import Button from './Button'; + +function MainContent(initialPage) { + let page = initialPage; + const mainElement = document.createElement('main'); + mainElement.id = 'main'; + + mainElement.innerHTML = ` + <section class="item-view"> + <h2>์ง€๊ธˆ ์ธ๊ธฐ ์žˆ๋Š” ์˜ํ™”</h2> + <ul class="item-list"></ul> + </section> + `; + + const sectionElement = mainElement.querySelector('.item-view'); + sectionElement.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleMovie(page); + } + }) + ); + + return mainElement; +} + +export default MainContent;
JavaScript
```suggestion const mainElement = html(` <main id="main"> <section class="item-view"> <h2>์ง€๊ธˆ ์ธ๊ธฐ ์žˆ๋Š” ์˜ํ™”</h2> <ul class="item-list"></ul> </section> <main> `); ``` ์ด๋ ‡๊ฒŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•จ์ˆ˜๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์ฃผ์‹œ๋ฉด ์–ด๋–จ๊นŒ์š”!?
@@ -0,0 +1,33 @@ +import handleMovie from '../services/handleMovie'; +import Button from './Button'; + +function MainContent(initialPage) { + let page = initialPage; + const mainElement = document.createElement('main'); + mainElement.id = 'main'; + + mainElement.innerHTML = ` + <section class="item-view"> + <h2>์ง€๊ธˆ ์ธ๊ธฐ ์žˆ๋Š” ์˜ํ™”</h2> + <ul class="item-list"></ul> + </section> + `; + + const sectionElement = mainElement.querySelector('.item-view'); + sectionElement.appendChild( + Button({ + classNames: ['btn', 'primary', 'full-width'], + type: 'button', + id: 'more-movies', + name: '๋” ๋ณด๊ธฐ', + onClick: () => { + page += 1; + handleMovie(page); + } + }) + ); + + return mainElement; +} + +export default MainContent;
JavaScript
์œ„์—์„œ๋Š” html template์œผ๋กœ ํ‘œํ˜„๋˜๊ณ  ์—ฌ๊ธฐ์„œ๋Š” ์ด๋ ‡๊ฒŒ ํ‘œํ˜„๋˜๊ณ  ์žˆ์–ด์„œ ์ฝ”๋“œ๋ฅผ ์ฝ๋Š” ์‚ฌ๋žŒ ์ž…์žฅ์—์„œ๋Š” ์กฐ๊ธˆ ํ—ท๊ฐˆ๋ฆฌ์ง€ ์•Š์„๊นŒ ์‹ถ์–ด์š”!
@@ -0,0 +1,47 @@ +import { BASE_URL } from '../constants/api'; +import { APIError } from '../apis/error'; + +interface ApiClientType { + method: 'GET' | 'POST' | 'PUT' | 'DELETE'; + endpoint: string; + params?: Record<string, string>; + headers?: Record<string, string>; + body?: Record<string, any>; +} + +class ApiClient { + static async request({ method, endpoint, params, headers = {}, body }: ApiClientType) { + const url = params + ? this.createUrlSearchParams({ baseUrl: `${BASE_URL}/${endpoint}`, params }) + : `${BASE_URL}/${endpoint}`; + + const options: RequestInit = { + method, + headers: { + 'Content-Type': 'application/json', + ...headers + }, + ...(body && { body: JSON.stringify(body) }) + }; + + try { + const response = await fetch(url, options); + const data = await response.json(); + + if (!response.ok) { + throw new APIError(data.status_code, data.status_message); + } + return data; + } catch (error: any) { + throw new APIError(400, error.message || 'An unknown error occurred'); + } + } + + static createUrlSearchParams({ baseUrl, params }: { baseUrl: string; params: Record<string, string> }) { + const url = new URL(baseUrl); + url.search = new URLSearchParams(params).toString(); + return url.toString(); + } +} + +export default ApiClient;
TypeScript
์•„ํ•˜.. ์ด ํŒŒ์ผ ๋•Œ๋ฌธ์— tsconfig๊ฐ€ ์ƒ๊ธด๊ฑฐ์˜€๊ตฐ์š”
@@ -0,0 +1,47 @@ +import { BASE_URL } from '../constants/api'; +import { APIError } from '../apis/error'; + +interface ApiClientType { + method: 'GET' | 'POST' | 'PUT' | 'DELETE'; + endpoint: string; + params?: Record<string, string>; + headers?: Record<string, string>; + body?: Record<string, any>; +} + +class ApiClient { + static async request({ method, endpoint, params, headers = {}, body }: ApiClientType) { + const url = params + ? this.createUrlSearchParams({ baseUrl: `${BASE_URL}/${endpoint}`, params }) + : `${BASE_URL}/${endpoint}`; + + const options: RequestInit = { + method, + headers: { + 'Content-Type': 'application/json', + ...headers + }, + ...(body && { body: JSON.stringify(body) }) + }; + + try { + const response = await fetch(url, options); + const data = await response.json(); + + if (!response.ok) { + throw new APIError(data.status_code, data.status_message); + } + return data; + } catch (error: any) { + throw new APIError(400, error.message || 'An unknown error occurred'); + } + } + + static createUrlSearchParams({ baseUrl, params }: { baseUrl: string; params: Record<string, string> }) { + const url = new URL(baseUrl); + url.search = new URLSearchParams(params).toString(); + return url.toString(); + } +} + +export default ApiClient;
TypeScript
try ๊ตฌ๊ฐ„์—์„œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ -> catch๋กœ ์ง„์ž… -> ๋ฌด์กฐ๊ฑด status๋Š” 400์œผ๋กœ ๊ณ ์ •ํ•˜์—ฌ ๋‹ค์‹œ error throw ์ด๋ ‡๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์œ ์˜๋ฏธํ•œ ์—๋Ÿฌ ํ”Œ๋กœ์šฐ์ผ๊นŒ์š”~?
@@ -0,0 +1,47 @@ +import { BASE_URL } from '../constants/api'; +import { APIError } from '../apis/error'; + +interface ApiClientType { + method: 'GET' | 'POST' | 'PUT' | 'DELETE'; + endpoint: string; + params?: Record<string, string>; + headers?: Record<string, string>; + body?: Record<string, any>; +} + +class ApiClient { + static async request({ method, endpoint, params, headers = {}, body }: ApiClientType) { + const url = params + ? this.createUrlSearchParams({ baseUrl: `${BASE_URL}/${endpoint}`, params }) + : `${BASE_URL}/${endpoint}`; + + const options: RequestInit = { + method, + headers: { + 'Content-Type': 'application/json', + ...headers + }, + ...(body && { body: JSON.stringify(body) }) + }; + + try { + const response = await fetch(url, options); + const data = await response.json(); + + if (!response.ok) { + throw new APIError(data.status_code, data.status_message); + } + return data; + } catch (error: any) { + throw new APIError(400, error.message || 'An unknown error occurred'); + } + } + + static createUrlSearchParams({ baseUrl, params }: { baseUrl: string; params: Record<string, string> }) { + const url = new URL(baseUrl); + url.search = new URLSearchParams(params).toString(); + return url.toString(); + } +} + +export default ApiClient;
TypeScript
๊ทธ๋Ÿฐ๋ฐ ์ด ํŒŒ์ผ์ด ์™œ domain ์— ํ•ด๋‹นํ•˜๋Š”๊ฑธ๊นŒ์š”~? domain์ด๋ผ๊ณ  ํ•˜๊ธฐ์—” ๋ง ๊ทธ๋Œ€๋กœ ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ(client)๋ฅผ ํ‘œํ˜„ํ•œ๊ฑฐ๋ผ์„œ... ์ „ํ˜€ ์—ฐ๊ด€์ด ์—†์–ด๋ณด์—ฌ์š”!
@@ -0,0 +1,24 @@ +import getMovieList from '../apis/getMovieList'; +import ConfirmModal from '../components/modal/ConfirmModal'; +import { Modal } from '../components/modal/container/Modal'; +import { NOT_MORE_MOVIES_MESSAGE } from '../constants/message'; +import renderMovies from '../view/renderMovies'; +import renderSkeletonMovies from '../view/renderSkeletonMovies'; + +export default async function handleMovie(page) { + try { + renderSkeletonMovies({ loading: true }); + const movieList = await getMovieList(page); + renderSkeletonMovies({ loading: false }); + + if (movieList.results.length === 0) { + document.getElementById('more-movies').remove(); + new Modal(document.querySelector('body'), ConfirmModal(NOT_MORE_MOVIES_MESSAGE)); + } + + renderMovies({ movieList: movieList.results, resetHTML: false }); + } catch (error) { + renderSkeletonMovies({ loading: false }); + new Modal(document.querySelector('body'), ConfirmModal(error.message)); + } +}
JavaScript
api์—์„œ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ ์ค‘์— message๋งŒ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ, CustomError๋ฅผ ๋งŒ๋“ค์–ด์„œ ์“ฐ๋Š” ์˜๋ฏธ๊ฐ€ ์žˆ๋Š”๊ฑด๊ฐ€ ์‹ถ์–ด์š”!
@@ -0,0 +1,47 @@ +import { BASE_URL } from '../constants/api'; +import { APIError } from '../apis/error'; + +interface ApiClientType { + method: 'GET' | 'POST' | 'PUT' | 'DELETE'; + endpoint: string; + params?: Record<string, string>; + headers?: Record<string, string>; + body?: Record<string, any>; +} + +class ApiClient { + static async request({ method, endpoint, params, headers = {}, body }: ApiClientType) { + const url = params + ? this.createUrlSearchParams({ baseUrl: `${BASE_URL}/${endpoint}`, params }) + : `${BASE_URL}/${endpoint}`; + + const options: RequestInit = { + method, + headers: { + 'Content-Type': 'application/json', + ...headers + }, + ...(body && { body: JSON.stringify(body) }) + }; + + try { + const response = await fetch(url, options); + const data = await response.json(); + + if (!response.ok) { + throw new APIError(data.status_code, data.status_message); + } + return data; + } catch (error: any) { + throw new APIError(400, error.message || 'An unknown error occurred'); + } + } + + static createUrlSearchParams({ baseUrl, params }: { baseUrl: string; params: Record<string, string> }) { + const url = new URL(baseUrl); + url.search = new URLSearchParams(params).toString(); + return url.toString(); + } +} + +export default ApiClient;
TypeScript
domain์ด apis๋ฅผ ์ฐธ์กฐํ•˜๋Š”๊ฑด ์–ด์ƒ‰ํ•ด๋ณด์—ฌ์š”!
@@ -1,2 +1 @@ export const BASE_URL = 'https://api.themoviedb.org'; -export const IMAGE_BASE_URL = 'https://image.tmdb.org/t/p/w500';
JavaScript
์ด๋Ÿฐ ์ •๋ณด๋Š” ์•„์˜ˆ API๋ฅผ ์š”์ฒญํ•˜๋Š” ์ชฝ์—์„œ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1 @@ +export const NOT_MORE_MOVIES_MESSAGE = '๋”์ด์ƒ ์˜ํ™”๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.';
JavaScript
์ด๋Ÿฐ ์—๋Ÿฌ ๋ฉ”์„ธ์ง€๋„ ๋ฉ”์„ธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ชฝ์—์„œ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉด ์–ด๋–จ๊นŒ์š”? ๋‹ค๋ฅธ ๊ตฌ๊ฐ„์—์„œ๋Š” ์•„์˜ˆ ์‚ฌ์šฉ๋  ๊ฒƒ ๊ฐ™์ง€ ์•Š์•„์„œ์š”!
@@ -0,0 +1,8 @@ +import "./css/reset.css"; +import "./css/common.css"; +import App from "./App"; + +addEventListener("DOMContentLoaded", async () => { + const app = new App(); + app.init(); +});
JavaScript
์š” ํ•จ์ˆ˜๊ฐ€ ๋ฐ”๋กœ ์•ฑ์„ ๊ตฌ๋™์‹œํ‚ค๋Š” Entry ํฌ์ธํŠธ๊ตฐ์š”! `controller`๋ฅผ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค? ๋ณด๋‹ค๋Š” `App`์„ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค๋Š” ๋А๋‚Œ์ด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,14 @@ +import { apiClient } from "./apiClient"; +import { BASE_URL } from "./constants"; + +export const fetchPopularMovies = async ({ page = 1 }) => { + const param = new URLSearchParams({ + api_key: process.env.TMDB_API_KEY, + language: "ko-KR", + page, + }); + + const response = await apiClient.get(`${BASE_URL}?${param}`); + + return response.results; +};
JavaScript
์˜ค ์ข‹์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,34 @@ +import { ApiError } from "./apiError"; + +export const apiClient = { + get: async (url, headers = {}) => { + return apiClient.request("GET", url, null, headers); + }, + + request: async (method, url, body = null, headers = {}) => { + const options = { + method, + headers: { + "Content-Type": "application/json", + ...headers, + }, + body: body && JSON.stringify(body), + }; + + try { + const response = await fetch(url, options); + + if (!response.ok) { + throw new ApiError(response.status); + } + + return await response.json(); + } catch (error) { + if (error instanceof ApiError) { + ApiError.handle(error); + } else { + throw error; + } + } + }, +};
JavaScript
`request()`์™€ `get()`์˜ ์ฐจ์ด๋Š” ๋ฌด์—‡์ด๊ณ  ๋‚˜๋ˆˆ ์ด์œ ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?
@@ -0,0 +1,31 @@ +import { ERROR_MSG } from "./constants"; + +export class ApiError extends Error { + constructor(message, details, status = -1) { + super(message); + this.details = details; + this.status = status; + } + + static handle(error) { + let errMsg; + let errDetails; + + switch (parseInt(error.message)) { + case 401: + errMsg = ERROR_MSG.INVALID_API_KEY.message; + errDetails = ERROR_MSG.INVALID_API_KEY.details; + break; + case 404: + errMsg = ERROR_MSG.INVALID_REQUEST.message; + errDetails = ERROR_MSG.INVALID_REQUEST.details; + break; + default: + errMsg = ERROR_MSG.DEFAULT.message; + errDetails = ERROR_MSG.DEFAULT.details; + break; + } + + throw new ApiError(errMsg, errDetails, error.status); + } +}
JavaScript
์˜ค ์ข‹์€ ์‹œ๋„์ž…๋‹ˆ๋‹ค ๐Ÿ‘
@@ -0,0 +1,16 @@ +import { mainTitle, mainMoreButton, movieCardsList } from "./index"; + +export const mainSection = { + render() { + const element = document.createElement("section"); + element.classList.add("item-view"); + + const title = mainTitle.render(); + const itemList = movieCardsList.render(); + const moreButton = mainMoreButton.render(); + + element.append(title, itemList, moreButton); + + return element; + }, +};
JavaScript
[append()](https://developer.mozilla.org/en-US/docs/Web/API/Element/append)๋ฅผ ํ™œ์šฉํ•ด๋ณด์„ธ์š”!
@@ -0,0 +1,46 @@ +describe("API ํ…Œ์ŠคํŠธ", () => { + it("์˜ํ™” ๋ชฉ๋ก API๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด 20๊ฐœ์”ฉ ์˜ํ™”๋ฅผ ๋ฐ›์•„์˜จ๋‹ค.", () => { + const baseUrl = "https://api.themoviedb.org/3/movie/popular"; + const param = new URLSearchParams({ + api_key: Cypress.env("TMDB_API_KEY"), + language: "ko-KR", + page: 1, + }); + + cy.request(`${baseUrl}?${param}`).then((response) => { + expect(response.status).to.eq(200); + expect(response.body.results).to.have.length(20); + }); + }); +}); + +describe("์˜ํ™” ๋ฆฌ๋ทฐ ์›น ํ…Œ์ŠคํŠธ", () => { + beforeEach(() => { + cy.visit("http://localhost:8080"); + }); + + it("์˜ํ™” ์นด๋“œ๋Š” ์ธ๋„ค์ผ, ๋ณ„์ , ์ œ๋ชฉ์„ ๊ฐ–๋Š”๋‹ค.", () => { + cy.get(".item-card").each(($el) => { + cy.wrap($el).within(() => { + cy.get(".item-thumbnail").should("be.visible"); + cy.get(".item-title").should("be.visible"); + cy.get(".item-score").should("be.visible"); + }); + }); + }); + + it("์˜ํ™” ๋ชฉ๋ก์€ ํ•œ ํŽ˜์ด์ง€์— 20๊ฐœ์”ฉ ๋‚˜์˜จ๋‹ค.", () => { + cy.get(".item-list li").should("have.length", 20); + }); + + it("๋”๋ณด๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด 20๊ฐœ์˜ ์˜ํ™”๊ฐ€ ์ถ”๊ฐ€๋กœ ์ƒ์„ฑ๋œ๋‹ค.", () => { + cy.get(".show-more").click(); + cy.get(".item-list li").should("have.length", 40); + }); + + it("์˜ํ™” ๋ชฉ๋ก์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋™์•ˆ ์Šค์ผˆ๋ ˆํ†ค UI๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.", () => { + cy.get(".skeleton-card").should("have.length", 20); + cy.wait(1000); + cy.get(".skeleton-card").should("have.length", 0); + }); +});
JavaScript
์˜คํ˜ธ? `exist`๋กœ ๊ฒ€์‚ฌํ•˜๋ฉด ๋ฌด์—‡์ด ๋‹ค๋ฅผ๊นŒ์š”?
@@ -0,0 +1,46 @@ +describe("API ํ…Œ์ŠคํŠธ", () => { + it("์˜ํ™” ๋ชฉ๋ก API๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด 20๊ฐœ์”ฉ ์˜ํ™”๋ฅผ ๋ฐ›์•„์˜จ๋‹ค.", () => { + const baseUrl = "https://api.themoviedb.org/3/movie/popular"; + const param = new URLSearchParams({ + api_key: Cypress.env("TMDB_API_KEY"), + language: "ko-KR", + page: 1, + }); + + cy.request(`${baseUrl}?${param}`).then((response) => { + expect(response.status).to.eq(200); + expect(response.body.results).to.have.length(20); + }); + }); +}); + +describe("์˜ํ™” ๋ฆฌ๋ทฐ ์›น ํ…Œ์ŠคํŠธ", () => { + beforeEach(() => { + cy.visit("http://localhost:8080"); + }); + + it("์˜ํ™” ์นด๋“œ๋Š” ์ธ๋„ค์ผ, ๋ณ„์ , ์ œ๋ชฉ์„ ๊ฐ–๋Š”๋‹ค.", () => { + cy.get(".item-card").each(($el) => { + cy.wrap($el).within(() => { + cy.get(".item-thumbnail").should("be.visible"); + cy.get(".item-title").should("be.visible"); + cy.get(".item-score").should("be.visible"); + }); + }); + }); + + it("์˜ํ™” ๋ชฉ๋ก์€ ํ•œ ํŽ˜์ด์ง€์— 20๊ฐœ์”ฉ ๋‚˜์˜จ๋‹ค.", () => { + cy.get(".item-list li").should("have.length", 20); + }); + + it("๋”๋ณด๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด 20๊ฐœ์˜ ์˜ํ™”๊ฐ€ ์ถ”๊ฐ€๋กœ ์ƒ์„ฑ๋œ๋‹ค.", () => { + cy.get(".show-more").click(); + cy.get(".item-list li").should("have.length", 40); + }); + + it("์˜ํ™” ๋ชฉ๋ก์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋™์•ˆ ์Šค์ผˆ๋ ˆํ†ค UI๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.", () => { + cy.get(".skeleton-card").should("have.length", 20); + cy.wait(1000); + cy.get(".skeleton-card").should("have.length", 0); + }); +});
JavaScript
40์œผ๋กœ ๊ฒ€์‚ฌํ•˜๋Š” ์ด์œ ๋Š” ์ดˆ๊ธฐ ๋ฆฌ์ŠคํŠธ 20 + ์ถ”๊ฐ€ ๋”๋ณด๊ธฐ 20์ผ๊นŒ์š”?
@@ -0,0 +1,34 @@ +import { ApiError } from "./apiError"; + +export const apiClient = { + get: async (url, headers = {}) => { + return apiClient.request("GET", url, null, headers); + }, + + request: async (method, url, body = null, headers = {}) => { + const options = { + method, + headers: { + "Content-Type": "application/json", + ...headers, + }, + body: body && JSON.stringify(body), + }; + + try { + const response = await fetch(url, options); + + if (!response.ok) { + throw new ApiError(response.status); + } + + return await response.json(); + } catch (error) { + if (error instanceof ApiError) { + ApiError.handle(error); + } else { + throw error; + } + } + }, +};
JavaScript
`request()`๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›๋Š” method๋ฅผ ํ†ตํ•ด API ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ํ•จ์ˆ˜์ด๊ณ , `get()`์€ ํ•ด๋‹น `request()` ํ•จ์ˆ˜์— `GET`์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ด๋ฒˆ ๊ณผ์ œ์—์„œ GET ์š”์ฒญ๋งŒ ์กด์žฌํ•˜์—ฌ ์ถ”๊ฐ€ํ•˜์ง„ ์•Š์•˜์ง€๋งŒ ์ถ”ํ›„์— ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ ์š”์ฒญ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,46 @@ +describe("API ํ…Œ์ŠคํŠธ", () => { + it("์˜ํ™” ๋ชฉ๋ก API๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด 20๊ฐœ์”ฉ ์˜ํ™”๋ฅผ ๋ฐ›์•„์˜จ๋‹ค.", () => { + const baseUrl = "https://api.themoviedb.org/3/movie/popular"; + const param = new URLSearchParams({ + api_key: Cypress.env("TMDB_API_KEY"), + language: "ko-KR", + page: 1, + }); + + cy.request(`${baseUrl}?${param}`).then((response) => { + expect(response.status).to.eq(200); + expect(response.body.results).to.have.length(20); + }); + }); +}); + +describe("์˜ํ™” ๋ฆฌ๋ทฐ ์›น ํ…Œ์ŠคํŠธ", () => { + beforeEach(() => { + cy.visit("http://localhost:8080"); + }); + + it("์˜ํ™” ์นด๋“œ๋Š” ์ธ๋„ค์ผ, ๋ณ„์ , ์ œ๋ชฉ์„ ๊ฐ–๋Š”๋‹ค.", () => { + cy.get(".item-card").each(($el) => { + cy.wrap($el).within(() => { + cy.get(".item-thumbnail").should("be.visible"); + cy.get(".item-title").should("be.visible"); + cy.get(".item-score").should("be.visible"); + }); + }); + }); + + it("์˜ํ™” ๋ชฉ๋ก์€ ํ•œ ํŽ˜์ด์ง€์— 20๊ฐœ์”ฉ ๋‚˜์˜จ๋‹ค.", () => { + cy.get(".item-list li").should("have.length", 20); + }); + + it("๋”๋ณด๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด 20๊ฐœ์˜ ์˜ํ™”๊ฐ€ ์ถ”๊ฐ€๋กœ ์ƒ์„ฑ๋œ๋‹ค.", () => { + cy.get(".show-more").click(); + cy.get(".item-list li").should("have.length", 40); + }); + + it("์˜ํ™” ๋ชฉ๋ก์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋™์•ˆ ์Šค์ผˆ๋ ˆํ†ค UI๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.", () => { + cy.get(".skeleton-card").should("have.length", 20); + cy.wait(1000); + cy.get(".skeleton-card").should("have.length", 0); + }); +});
JavaScript
์ƒ์„ฑ๋œ `movieCard`์—๋Š” ์ธ๋„ค์ผ, ๋ณ„์ , ์ œ๋ชฉ element๊ฐ€ `์กด์žฌ`ํ•œ๋‹ค๋Š” ์˜๋ฏธ์—์„œ ์‚ฌ์šฉํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ๋‹ค์‹œ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ, ํ•ด๋‹น element๊ฐ€ ์กด์žฌํ•˜์ง€๋งŒ ๋ณด์—ฌ์ง€์ง€ ์•Š๊ฑฐ๋‚˜ ์–ด๋–ค css issue๊ฐ€ ์ƒ๊ธธ ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ์ƒ๊ฐ์— `be.visible`๋กœ ๋Œ€์ฒดํ•˜์˜€์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,46 @@ +describe("API ํ…Œ์ŠคํŠธ", () => { + it("์˜ํ™” ๋ชฉ๋ก API๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด 20๊ฐœ์”ฉ ์˜ํ™”๋ฅผ ๋ฐ›์•„์˜จ๋‹ค.", () => { + const baseUrl = "https://api.themoviedb.org/3/movie/popular"; + const param = new URLSearchParams({ + api_key: Cypress.env("TMDB_API_KEY"), + language: "ko-KR", + page: 1, + }); + + cy.request(`${baseUrl}?${param}`).then((response) => { + expect(response.status).to.eq(200); + expect(response.body.results).to.have.length(20); + }); + }); +}); + +describe("์˜ํ™” ๋ฆฌ๋ทฐ ์›น ํ…Œ์ŠคํŠธ", () => { + beforeEach(() => { + cy.visit("http://localhost:8080"); + }); + + it("์˜ํ™” ์นด๋“œ๋Š” ์ธ๋„ค์ผ, ๋ณ„์ , ์ œ๋ชฉ์„ ๊ฐ–๋Š”๋‹ค.", () => { + cy.get(".item-card").each(($el) => { + cy.wrap($el).within(() => { + cy.get(".item-thumbnail").should("be.visible"); + cy.get(".item-title").should("be.visible"); + cy.get(".item-score").should("be.visible"); + }); + }); + }); + + it("์˜ํ™” ๋ชฉ๋ก์€ ํ•œ ํŽ˜์ด์ง€์— 20๊ฐœ์”ฉ ๋‚˜์˜จ๋‹ค.", () => { + cy.get(".item-list li").should("have.length", 20); + }); + + it("๋”๋ณด๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด 20๊ฐœ์˜ ์˜ํ™”๊ฐ€ ์ถ”๊ฐ€๋กœ ์ƒ์„ฑ๋œ๋‹ค.", () => { + cy.get(".show-more").click(); + cy.get(".item-list li").should("have.length", 40); + }); + + it("์˜ํ™” ๋ชฉ๋ก์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋™์•ˆ ์Šค์ผˆ๋ ˆํ†ค UI๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.", () => { + cy.get(".skeleton-card").should("have.length", 20); + cy.wait(1000); + cy.get(".skeleton-card").should("have.length", 0); + }); +});
JavaScript
๋„ค ๋งž์Šต๋‹ˆ๋‹ค! ์ด์ „ ํ…Œ์ŠคํŠธ์—์„œ 20๊ฐœ๊ฐ€ ๋ Œ๋”๋ง์ด ๋˜์—ˆ๊ณ  ๋ฒ„ํŠผ์„ ํด๋ฆญํ•œ ํ›„์—, 20๊ฐœ๊ฐ€ ๋” ์ถ”๊ฐ€๋˜์–ด 40๊ฐœ๋ฅผ ๊ฒ€์‚ฌํ•˜๊ฒŒ ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ƒˆ๋กญ๊ฒŒ ๋ Œ๋”๋ง๋œ 20๊ฐœ์— ๋Œ€ํ•ด์„œ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋Š” ๊ฒƒ์ด ๋” ์˜ฌ๋ฐ”๋ฅธ ๊ฒ€์‚ฌ์ผ๊นŒ์š”? +) ์ถ”๊ฐ€๋กœ, ๋‹จ์œ„ํ…Œ์ŠคํŠธ์—์„œ๋Š” ์ƒ˜ํ”Œ ๊ฐ’์„ ํ†ตํ•ด ๋„์ถœ๋˜๋Š” ๊ฐ’์„ ๊ฒ€์‚ฌํ•˜๋Š” ๊ณผ์ •์ด ํ…Œ์ŠคํŠธ์˜ ํ•ต์‹ฌ์ด์—ˆ๋‹ค๊ณ  ์ƒ๊ฐ๋˜๋Š”๋ฐ, ์ด๋ฒˆ์— e2e์—์„œ๋Š” ๊ฐ’์„ ์ด์šฉํ•˜์—ฌ ๊ฒ€์‚ฌํ•˜๋Š” ๋ฐฉํ–ฅ๋ณด๋‹ค ๋ Œ๋”๋ง๋˜๋Š” ์š”์†Œ์˜ ๊ฐœ์ˆ˜๋‚˜ ์ƒ์„ฑ ์—ฌ๋ถ€๋ฅผ ์ค‘์‹ฌ์ ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๊ณผ์ •์—์„œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” ๊ฐ’ ์ค‘์‹ฌ, e2e๋Š” ์ „์ฒด์ ์ธ DOM ๋ Œ๋”๋ง ์ค‘์‹ฌ ์ด๋ ‡๊ฒŒ ์ž์—ฐ์Šค๋ ˆ ์ƒ๊ฐ์ด ์ด์–ด์ง€๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ ์ด๊ฒŒ ๋งž๋Š” ์ƒ๊ฐ์ผ๊นŒ ์˜๊ตฌ์‹ฌ์ด ๋“ค๊ธด ํ•ฉ๋‹ˆ๋‹ค,,!
@@ -1,11 +1,29 @@ import { useState } from "react"; +import Header from "./components/Header/Header"; +import Product from "./pages/Product"; +import GlobalStyles from "./styles/Global.style"; +import Toast from "./components/common/Toast/Toast"; +import { QuantityContext } from "./store/QuantityContext"; +import { createPortal } from "react-dom"; function App() { - const [count, setCount] = useState(0); - + const [quantity, setQuantity] = useState(0); + const [showToast, setShowToast] = useState(false); + const [toastMessage, setToastMessage] = useState(""); + const handleError = (message: string) => { + setToastMessage(message); + setShowToast(true); + setTimeout(() => setShowToast(false), 3000); + }; return ( <> - <h1>React Shopping Products</h1> + <GlobalStyles /> + {showToast && + createPortal(<Toast message={toastMessage} />, document.body)} + <QuantityContext.Provider value={{ quantity, setQuantity }}> + <Header /> + <Product onError={handleError} /> + </QuantityContext.Provider> </> ); }
Unknown
์—ฌ๊ธฐ ์ด `showToast` ์ƒํƒœ๋ฅผ ํ† ์ŠคํŠธ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ฑ…์ž„์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ ์‹ถ์—ˆ๋Š”๋ฐ, ๊ทธ๋ ‡๋‹ค๋ฉด createPortal์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ฒŒ ๋˜๋‚˜์š”..? createPortal์„ ์‚ฌ์šฉํ•ด๋ณด์ง€ ์•Š์•„์„œ ์ž˜ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ, ๋ฏธ๋ฆฌ ์—ด์–ด๋‘˜ ์ˆ˜ ์žˆ๋‹ค๋ฉด ๊ทธ์ชฝ์œผ๋กœ ์ƒํƒœ๋ฅผ ์˜ฎ๊ฒจ๋ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,52 @@ +import { generateBasicToken } from "../util/auth"; +import { CART_ITEMS_ENDPOINT } from "./config"; + +const USER_PASSWORD = import.meta.env.VITE_USER_PASSWORD; +const USER_ID = import.meta.env.VITE_USER_ID; +const token = generateBasicToken(USER_ID, USER_PASSWORD); + +export async function requestFetchCartItemList() { + const response = await fetch(`${CART_ITEMS_ENDPOINT}?size=2000`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: token, + }, + }); + + if (!response.ok) { + throw new Error("Failed to fetch cart item list"); + } + + const data = await response.json(); + return data; +} + +export async function requestAddCartItem(productId: number, quantity: number) { + const response = await fetch(`${CART_ITEMS_ENDPOINT}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: token, + }, + body: JSON.stringify({ productId, quantity }), + }); + + if (!response.ok) { + throw new Error("Failed to add cart item"); + } +} + +export async function requestDeleteCartItem(cartItemId: number | undefined) { + const response = await fetch(`${CART_ITEMS_ENDPOINT}/${cartItemId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: token, + }, + }); + + if (!response.ok) { + throw new Error("Failed to delete cart item"); + } +}
TypeScript
ํ•„์ˆ˜๋Š” ์•„๋‹ˆ์ง€๋งŒ ๋ฐ˜๋ณต๋˜๋Š” fetch ๋กœ์ง๋“ค์€ ์ถ”์ƒํ™”ํ•ด๋ณด์…”๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!ใ…Žใ…Ž
@@ -0,0 +1,52 @@ +import { generateBasicToken } from "../util/auth"; +import { CART_ITEMS_ENDPOINT } from "./config"; + +const USER_PASSWORD = import.meta.env.VITE_USER_PASSWORD; +const USER_ID = import.meta.env.VITE_USER_ID; +const token = generateBasicToken(USER_ID, USER_PASSWORD); + +export async function requestFetchCartItemList() { + const response = await fetch(`${CART_ITEMS_ENDPOINT}?size=2000`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: token, + }, + }); + + if (!response.ok) { + throw new Error("Failed to fetch cart item list"); + } + + const data = await response.json(); + return data; +} + +export async function requestAddCartItem(productId: number, quantity: number) { + const response = await fetch(`${CART_ITEMS_ENDPOINT}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: token, + }, + body: JSON.stringify({ productId, quantity }), + }); + + if (!response.ok) { + throw new Error("Failed to add cart item"); + } +} + +export async function requestDeleteCartItem(cartItemId: number | undefined) { + const response = await fetch(`${CART_ITEMS_ENDPOINT}/${cartItemId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + Authorization: token, + }, + }); + + if (!response.ok) { + throw new Error("Failed to delete cart item"); + } +}
TypeScript
chat GPTํ•œํ…Œ '์ด ์ฝ”๋“œ ์ถ”์ƒํ™” ํ•ด๋ด'ํ•˜๋ฉด ๊ธฐ๊ฐ€๋ง‰ํžˆ๊ฒŒ ํ•ด์ฃผ๋”๋ผ๊ตฌ์š”
@@ -0,0 +1,10 @@ +import { generateBasicToken } from "../util/auth"; + +const API_URL = import.meta.env.VITE_API_URL; + +export const PRODUCTS_ENDPOINT = `${API_URL}/products`; +export const CART_ITEMS_ENDPOINT = `${API_URL}/cart-items`; + +export const USER_PASSWORD = import.meta.env.VITE_USER_PASSWORD; +export const USER_ID = import.meta.env.VITE_USER_ID; +export const token = generateBasicToken(USER_ID, USER_PASSWORD);
TypeScript
api์š”์ฒญ์— ํ•„์š”ํ•œ ๋ณ€์ˆ˜๋“ค์ด ์ž˜ ๋ชจ์—ฌ์žˆ์–ด ๊ด€๋ฆฌํ•˜๊ธฐ ํŽธํ•  ๊ฒƒ ๊ฐ™๋„ค์š”! ๐Ÿ‘
@@ -0,0 +1,87 @@ +import { useContext, useEffect, useRef } from "react"; +import { QuantityContext } from "../../store/QuantityContext"; +import useProductList from "../../hooks/useProductList"; +import useCartItemList from "../../hooks/useCartItemList"; +import ProductItem from "../ProductItem/ProductItem"; +import * as S from "./ProductItemList.style"; +import { Category } from "../../interfaces/Product"; +import { Sorting } from "../../interfaces/Sorting"; +import useIntersectionObserver from "../../hooks/useIntersectionObserver"; +import Spinner from "../common/Spinner/Spinner"; + +interface ProductItemListProp { + category: Category; + sortOption: Sorting; + onError: (error: string) => void; +} + +function ProductItemList({ + category, + sortOption, + onError, +}: ProductItemListProp) { + const { + productList, + productListError, + productListLoading, + page, + fetchNextPage, + isLastPage, + setPage, + } = useProductList({ + category, + sortOption, + }); + const { cartItemList, isInCart, toggleCartItem, cartItemListError } = + useCartItemList(); + const target = useRef(null); + const [observe, unobserve] = useIntersectionObserver(() => { + fetchNextPage(); + }); + + useEffect(() => { + setPage(0); + }, [category, sortOption]); + + useEffect(() => { + if (page === -1 || target.current === null) return; + observe(target.current); + + const N = productList.length; + + if (0 === N || isLastPage) { + unobserve(target.current); + } + }, [productList, page, observe, unobserve]); + const quantityContext = useContext(QuantityContext); + const setQuantity = quantityContext ? quantityContext.setQuantity : () => {}; + setQuantity(cartItemList.length); + + if (productListError) { + onError("์ƒํ’ˆ ๋ชฉ๋ก ์กฐํšŒ ์‹คํŒจ"); + } + if (cartItemListError) { + onError("์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋ชฉ๋ก ์กฐํšŒ ์‹คํŒจ"); + } + + return ( + <> + <S.ProductList> + {productList.map((product, idx) => { + return ( + <ProductItem + key={`${idx}_${product.id}`} + product={product} + isInCart={isInCart(product.id)} + toggleCartItem={() => toggleCartItem(product)} + /> + ); + })} + </S.ProductList> + <div ref={target} style={{ height: "1px" }}></div> + {productListLoading && <Spinner />} + </> + ); +} + +export default ProductItemList;
Unknown
ํŽ˜์ด์ง€๋„ค์ด์…˜ ๊ด€๋ จ ๋กœ์ง๋„ ์ปค์Šคํ…€ ํ›…์œผ๋กœ ๋ถ„๋ฆฌํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,87 @@ +import { useContext, useEffect, useRef } from "react"; +import { QuantityContext } from "../../store/QuantityContext"; +import useProductList from "../../hooks/useProductList"; +import useCartItemList from "../../hooks/useCartItemList"; +import ProductItem from "../ProductItem/ProductItem"; +import * as S from "./ProductItemList.style"; +import { Category } from "../../interfaces/Product"; +import { Sorting } from "../../interfaces/Sorting"; +import useIntersectionObserver from "../../hooks/useIntersectionObserver"; +import Spinner from "../common/Spinner/Spinner"; + +interface ProductItemListProp { + category: Category; + sortOption: Sorting; + onError: (error: string) => void; +} + +function ProductItemList({ + category, + sortOption, + onError, +}: ProductItemListProp) { + const { + productList, + productListError, + productListLoading, + page, + fetchNextPage, + isLastPage, + setPage, + } = useProductList({ + category, + sortOption, + }); + const { cartItemList, isInCart, toggleCartItem, cartItemListError } = + useCartItemList(); + const target = useRef(null); + const [observe, unobserve] = useIntersectionObserver(() => { + fetchNextPage(); + }); + + useEffect(() => { + setPage(0); + }, [category, sortOption]); + + useEffect(() => { + if (page === -1 || target.current === null) return; + observe(target.current); + + const N = productList.length; + + if (0 === N || isLastPage) { + unobserve(target.current); + } + }, [productList, page, observe, unobserve]); + const quantityContext = useContext(QuantityContext); + const setQuantity = quantityContext ? quantityContext.setQuantity : () => {}; + setQuantity(cartItemList.length); + + if (productListError) { + onError("์ƒํ’ˆ ๋ชฉ๋ก ์กฐํšŒ ์‹คํŒจ"); + } + if (cartItemListError) { + onError("์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋ชฉ๋ก ์กฐํšŒ ์‹คํŒจ"); + } + + return ( + <> + <S.ProductList> + {productList.map((product, idx) => { + return ( + <ProductItem + key={`${idx}_${product.id}`} + product={product} + isInCart={isInCart(product.id)} + toggleCartItem={() => toggleCartItem(product)} + /> + ); + })} + </S.ProductList> + <div ref={target} style={{ height: "1px" }}></div> + {productListLoading && <Spinner />} + </> + ); +} + +export default ProductItemList;
Unknown
์•„๋ฌด๋ž˜๋„ ์ด๋ฒˆ ๋ฏธ์…˜์—์„œ ๊ฐ€์žฅ ๋ฉ”์ธ์ด ๋˜๋Š”(?) ์ปดํฌ๋„ŒํŠธ์ธ ๊ฒƒ ๊ฐ™์•„์š”. ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๊ณผ UI ๋กœ์ง์ด ์ข€ ๋” ์ž˜ ๋ถ„๋ฆฌ๋˜๋ฉด ๋”์šฑ ์ฝ๊ธฐ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,13 @@ +package msa.customer.exception; + +public class DeliveryCustomerException extends RuntimeException { + + public DeliveryCustomerException(String message) { + super(message); + } + + public DeliveryCustomerException(String message, Throwable cause) { + super(message, cause); + } + +}
Java
(C) Exception์€ ์„œ๋น„์Šค์˜ `์ •์ฑ… ์œ„๋ฐ˜`์„ ๋‚˜ํƒ€๋‚ด๋Š” documentation์˜ ์—ญํ• ์„ ํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ Exception์„ ํ†ตํ•ด ์„œ๋น„์Šค ์ •์ฑ…์„ ์œ„๋ฐ˜ํ•˜๋Š” ๊ฒฝ์šฐ, ์ •์ฑ…์„ ๋ช…ํ™•ํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋Š” ์ž์ฒด exception์„ ์ •์˜ํ•˜๊ณค ํ•˜๋Š”๋ฐ delivery application์— ์ ์šฉํ•ด๋ณผ๋งŒํ•œ exception ๋ช‡ ๊ฐœ๋ฅผ ๊ฐ„๋žตํ•˜๊ฒŒ ๊ตฌ์„ฑํ•ด๋ดค์œผ๋‹ˆ ์ฐธ๊ณ ํ•ด๋ณด์‹œ๊ณ  Exception๋“ค์„ ์ž˜ ์ •์˜ํ•ด์ฃผ์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค :)
@@ -3,6 +3,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import msa.customer.entity.store.Store; +import msa.customer.exception.store.StoreEmptyException; import msa.customer.service.store.StoreService; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerMapping; @@ -11,6 +12,7 @@ import java.util.Optional; public class StoreCheckInterceptor implements HandlerInterceptor { + private final StoreService storeService; public StoreCheckInterceptor(StoreService storeService) { @@ -19,13 +21,14 @@ public StoreCheckInterceptor(StoreService storeService) { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - Map pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); - String storeId = (String) pathVariables.get("storeId"); + Map pathVariables = (Map)request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); + String storeId = (String)pathVariables.get("storeId"); Optional<Store> storeOptional = storeService.getStore(storeId); - if(storeOptional.isEmpty()){ - throw new NullPointerException("Store doesn't exist. " + storeId + " is not correct store id."); + if (storeOptional.isEmpty()) { + throw new StoreEmptyException(storeId); } request.setAttribute("storeEntity", storeOptional.get()); return true; } + }
Java
(C) optional์€ ๋ฒ—๊ฒจ์ง„ ์ƒํƒœ๋กœ ์˜ค๋Š”๊ฒŒ ์ข‹๊ฒ ์ง€๋งŒ, ์ผ๋‹จ ํ˜„์žฌ ์ƒํƒœ๋ฅผ ๊ฐ€์ •ํ•˜๊ณ  custom exception์„ throw ํ–ˆ์Šต๋‹ˆ๋‹ค
@@ -6,6 +6,7 @@ import msa.restaurant.dto.store.StoreResponseDto; import msa.restaurant.entity.store.Store; import msa.restaurant.dto.store.StoreSqsDto; +import msa.restaurant.exception.store.StoreCreationFailedException; import msa.restaurant.service.member.MemberService; import msa.restaurant.sqs.SendingMessageConverter; import msa.restaurant.service.store.StoreService; @@ -26,16 +27,19 @@ public class StoreController { private final SendingMessageConverter sendingMessageConverter; private final SqsService sqsService; - public StoreController(StoreService storeService, SendingMessageConverter sendingMessageConverter, MemberService memberService, SqsService sqsService) { + public StoreController(StoreService storeService, + SendingMessageConverter sendingMessageConverter, + MemberService memberService, + SqsService sqsService) { this.storeService = storeService; this.sendingMessageConverter = sendingMessageConverter; this.sqsService = sqsService; } @GetMapping @ResponseStatus(HttpStatus.OK) - public List<StorePartResponseDto> storeList ( - @RequestAttribute("cognitoUsername") String managerId) { + public List<StorePartResponseDto> storeList( + @RequestAttribute("cognitoUsername") String managerId) { List<Store> storeList = storeService.getStoreList(managerId); List<StorePartResponseDto> storeListDto = new ArrayList<>(); storeList.forEach(store -> { @@ -46,12 +50,12 @@ public List<StorePartResponseDto> storeList ( @PostMapping @ResponseStatus(HttpStatus.CREATED) - public void createStore (@RequestAttribute("cognitoUsername") String managerId, - @RequestBody StoreRequestDto data) { + public void createStore(@RequestAttribute("cognitoUsername") String managerId, + @RequestBody StoreRequestDto data) { String storeId = storeService.createStore(data, managerId); Optional<Store> storeOptional = storeService.getStore(storeId); - if (storeOptional.isEmpty()){ - throw new RuntimeException("Store creation failed."); + if (storeOptional.isEmpty()) { + throw new StoreCreationFailedException(storeId); } Store store = storeOptional.get(); StoreSqsDto storeSqsDto = new StoreSqsDto(store); @@ -62,16 +66,16 @@ public void createStore (@RequestAttribute("cognitoUsername") String managerId, @GetMapping("/{storeId}") @ResponseStatus(HttpStatus.OK) - public StoreResponseDto storeInfo (@RequestAttribute("cognitoUsername") String managerId, - @RequestAttribute("store") Store store) { + public StoreResponseDto storeInfo(@RequestAttribute("cognitoUsername") String managerId, + @RequestAttribute("store") Store store) { return new StoreResponseDto(store); } @PutMapping("/{storeId}") @ResponseStatus(HttpStatus.OK) public void updateStore(@RequestAttribute("cognitoUsername") String managerId, @PathVariable String storeId, - @RequestBody StoreRequestDto data) { + @RequestBody StoreRequestDto data) { storeService.updateStore(storeId, data); Optional<Store> storeOptional = storeService.getStore(storeId); Store store = storeOptional.get(); @@ -85,9 +89,9 @@ public void updateStore(@RequestAttribute("cognitoUsername") String managerId, @ResponseStatus(HttpStatus.CREATED) public void changeStoreStatus(@RequestAttribute("cognitoUsername") String managerId, @PathVariable String storeId, - @RequestBody boolean open){ + @RequestBody boolean open) { String messageToChangeStatus; - if (open){ + if (open) { storeService.openStore(storeId); messageToChangeStatus = sendingMessageConverter.createMessageToOpenStore(storeId); } else { @@ -101,11 +105,12 @@ public void changeStoreStatus(@RequestAttribute("cognitoUsername") String manage @DeleteMapping("/{storeId}") @ResponseStatus(HttpStatus.NO_CONTENT) public void deleteStore(@RequestAttribute("cognitoUsername") String managerId, - @PathVariable String storeId) { + @PathVariable String storeId) { storeService.deleteStore(storeId); String messageToDeleteStore = sendingMessageConverter.createMessageToDeleteStore(storeId); sqsService.sendToCustomer(messageToDeleteStore); sqsService.sendToRider(messageToDeleteStore); } + }
Java
(C) ์—ฌ๊ธฐ๋„ StoreCreationFailedException์„ ๋˜์ง€์ง€๋งŒ, storeService.createStore ๋‚ด๋ถ€์—์„œ exception ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ณ  ๋‚˜์˜ค๋Š” ๊ฒƒ์ด ๋” ๋ฐ”๋žŒ์งํ•ด๋ณด์ž…๋‹ˆ๋‹ค.
@@ -18,39 +18,30 @@ public OrderService(OrderRepository orderRepository) { this.orderRepository = orderRepository; } - public void createOrder(Order order){ + public void createOrder(Order order) { orderRepository.createOrder(order); } - public List<Order> getOrderList(String storeId){ + public List<Order> getOrderList(String storeId) { return orderRepository.readOrderList(storeId); } - public Optional<Order> getOrder(String orderId){ + public Optional<Order> getOrder(String orderId) { return orderRepository.readOrder(orderId); } - public OrderStatus changeOrderStatusToOrderAccept(String orderId, OrderStatus orderStatus){ - if(orderStatus.equals(OrderStatus.ORDER_REQUEST)){ - return orderRepository.updateOrderStatus(orderId, OrderStatus.ORDER_ACCEPT); - } else { - throw new IllegalStateException("The current order status is not changeable"); - } - } + public OrderStatus changeOrderStatus(Order order, OrderStatus status, OrderStatusUpdatePolicy orderStatusUpdatePolicy) { + orderStatusUpdatePolicy.checkStatusUpdatable(status); - public OrderStatus changeOrderStatusToFoodReady(String orderId, OrderStatus orderStatus){ - if (orderStatus.equals(OrderStatus.RIDER_ASSIGNED)) { - return orderRepository.updateOrderStatus(orderId, OrderStatus.FOOD_READY); - } else { - throw new IllegalStateException("The current order status is not changeable"); - } + return orderRepository.updateOrderStatus(order.getOrderId(), status); } - public void assignRiderToOrder(String orderId, OrderStatus orderStatus, RiderPartDto riderPartDto){ + public void assignRiderToOrder(String orderId, OrderStatus orderStatus, RiderPartDto riderPartDto) { orderRepository.updateRiderInfo(orderId, orderStatus, riderPartDto); } - public void changeOrderStatusFromOtherServer(String orderId, OrderStatus orderStatus){ + public void changeOrderStatusFromOtherServer(String orderId, OrderStatus orderStatus) { orderRepository.updateOrderStatus(orderId, orderStatus); } + }
Java
(C) changeOrderStatusTo~ ๋ฉ”์„œ๋“œ์˜ ๋‚ด์šฉ์ด ๋Œ€๋ถ€๋ถ„ ์ค‘๋ณต๋˜์–ด์„œ, ํ•ด๋‹น ๋ฉ”์„œ๋“œ๋“ค์„ changeOrderStatus๋ผ๋Š” ๋ฉ”์„œ๋“œ๋กœ ํ†ตํ•ฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ƒˆ๋กœ์šด ํด๋ž˜์Šค์ธ OrderStatusUpdatePolicy๊ฐ€ ๋งŒ๋“ค์–ด์กŒ๋Š”๋ฐ, ~Policy๋ผ๋Š” ๋ช…์นญ์€ ์„œ๋น„์Šค ์ •์ฑ…์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋ฒ”์šฉ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค ๋„ค์ด๋ฐ ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค. delivery-application์—๋„ ์„œ๋น„์Šค ์šด์˜์— ํ•„์š”ํ•œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ •์ฑ…๋“ค์„ ๊ฐ–๊ณ  ์žˆ์„ํ…๋ฐ์š”, ์ด๋Ÿฐ ์ •์ฑ…๋“ค์€ ํด๋ž˜์Šค๋กœ ๋“œ๋Ÿฌ๋‚ด์ง€ ์•Š๊ณ  ๋ฉ”์„œ๋“œ๋‚˜ ๋กœ์ง์œผ๋กœ๋งŒ ๋‚˜ํƒ€๋‚ด๋ฉด ์ •์ฑ…๋“ค์ด ๋ถ„์‚ฐ๋˜๊ณ , ์•”์‹œ์ ์œผ๋กœ ํ‘œํ˜„๋˜์–ด์„œ ์šฐ๋ฆฌ ์„œ๋น„์Šค๊ฐ€ ์–ด๋–ค ์ •์ฑ…๋“ค์„ ๊ฐ–๊ณ  ์žˆ๋Š”์ง€ ๋ช…ํ™•ํžˆ ํŒŒ์•…ํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค. (์ด๋ ‡๊ฒŒ ๋˜๋ฉด ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด์„œ ์ฝ”๋“œ๊ฐ€ ์„œ๋น„์Šค ์ •์ฑ…์„ ๋”ฐ๋ผ๊ฐ€์ง€ ๋ชปํ•˜๋Š” ์ƒํ™ฉ๋„ ์ข…์ข… ์ƒ๊น๋‹ˆ๋‹ค) DDD๋ฅผ ์•„์ง ์ฝ์–ด๋ณด์‹ ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ, [์•”์‹œ์ ์ธ ๊ฐœ๋…์„ ๋ช…ํ™•ํ•˜๊ฒŒ](https://dhsim86.github.io/programming/2019/05/16/domain_driven_design_09-post.html)๋ผ๋Š” chapter๊ฐ€ ์žˆ๋Š”๋ฐ ์‹œ๊ฐ„๋‚˜์‹ค ๋•Œ ๋งํฌ ํ•œ๋ฒˆ ์ฝ์–ด๋ณด์‹œ๊ณ , ํ˜„์žฌ ์šฐ๋ฆฌ ์„œ๋น„์Šค์— ์—ฌ๊ธฐ์ €๊ธฐ ์ˆจ์–ด์žˆ๋Š” ์ •์ฑ…๋“ค์€ ์–ด๋–ค ๊ฒƒ๋“ค์ด ์žˆ์„์ง€ ์ฐพ์•„๋ณด์…”์„œ ๋ช…ํ™•ํ•˜๊ฒŒ ํด๋ž˜์Šค๋กœ ๋‚˜ํƒ€๋‚ด๋ณด์‹ ๋‹ค๋ฉด ๋งŽ์€ ๋„์›€์ด ๋˜์‹ค ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค :)
@@ -0,0 +1,13 @@ +package msa.customer.exception; + +public class DeliveryCustomerException extends RuntimeException { + + public DeliveryCustomerException(String message) { + super(message); + } + + public DeliveryCustomerException(String message, Throwable cause) { + super(message, cause); + } + +}
Java
์ฐธ๊ณ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,152 @@ +package nextstep.subway.acceptance; + +import static nextstep.subway.acceptance.FavoritesSteps.์ฆ๊ฒจ์ฐพ๊ธฐ_๊ถŒํ•œ์ด_์—†์Œ; +import static nextstep.subway.acceptance.FavoritesSteps.์ฆ๊ฒจ์ฐพ๊ธฐ_๋ชฉ๋ก_์กฐํšŒ_์š”์ฒญ; +import static nextstep.subway.acceptance.FavoritesSteps.์ฆ๊ฒจ์ฐพ๊ธฐ_์‚ญ์ œ_์š”์ฒญ; +import static nextstep.subway.acceptance.FavoritesSteps.์ฆ๊ฒจ์ฐพ๊ธฐ_์‚ญ์ œ๋จ; +import static nextstep.subway.acceptance.FavoritesSteps.์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์š”์ฒญ; +import static nextstep.subway.acceptance.FavoritesSteps.์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ๋จ; +import static nextstep.subway.acceptance.FavoritesSteps.์ฆ๊ฒจ์ฐพ๊ธฐ_์ •๋ณด_์กฐํšŒ๋จ; +import static nextstep.subway.acceptance.LineSteps.์ง€ํ•˜์ฒ _๋…ธ์„ ์—_์ง€ํ•˜์ฒ _๊ตฌ๊ฐ„_์ƒ์„ฑ_์š”์ฒญ; +import static nextstep.subway.acceptance.MemberSteps.๋กœ๊ทธ์ธ_๋˜์–ด_์žˆ์Œ; +import static nextstep.subway.acceptance.MemberSteps.ํšŒ์›_์ƒ์„ฑ_์š”์ฒญ; +import static nextstep.subway.acceptance.StationSteps.์ง€ํ•˜์ฒ ์—ญ_์ƒ์„ฑ_์š”์ฒญ; + +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("์ฆ๊ฒจ์ฐพ๊ธฐ ๊ธฐ๋Šฅ") +public class FavoritesAcceptanceTest extends AcceptanceTest { + + public static final String EMAIL = "email@email.com"; + public static final String PASSWORD = "password"; + public static final int AGE = 20; + + private Long ๊ต๋Œ€์—ญ; + private Long ๊ฐ•๋‚จ์—ญ; + private Long ์–‘์žฌ์—ญ; + private Long ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ; + private Long ์ดํ˜ธ์„ ; + private Long ์‹ ๋ถ„๋‹น์„ ; + private Long ์‚ผํ˜ธ์„ ; + private String ๋กœ๊ทธ์ธํ† ํฐ; + + + /** + * ๊ต๋Œ€์—ญ --- *2ํ˜ธ์„ * --- ๊ฐ•๋‚จ์—ญ | | *3ํ˜ธ์„ * *์‹ ๋ถ„๋‹น์„ * | + * | ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ --- *3ํ˜ธ์„ * --- ์–‘์žฌ + */ + @BeforeEach + public void setUp() { + super.setUp(); + + ๊ต๋Œ€์—ญ = ์ง€ํ•˜์ฒ ์—ญ_์ƒ์„ฑ_์š”์ฒญ("๊ต๋Œ€์—ญ").jsonPath().getLong("id"); + ๊ฐ•๋‚จ์—ญ = ์ง€ํ•˜์ฒ ์—ญ_์ƒ์„ฑ_์š”์ฒญ("๊ฐ•๋‚จ์—ญ").jsonPath().getLong("id"); + ์–‘์žฌ์—ญ = ์ง€ํ•˜์ฒ ์—ญ_์ƒ์„ฑ_์š”์ฒญ("์–‘์žฌ์—ญ").jsonPath().getLong("id"); + ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ = ์ง€ํ•˜์ฒ ์—ญ_์ƒ์„ฑ_์š”์ฒญ("๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ").jsonPath().getLong("id"); + + ์ดํ˜ธ์„  = ์ง€ํ•˜์ฒ _๋…ธ์„ _์ƒ์„ฑ_์š”์ฒญ("2ํ˜ธ์„ ", "green", ๊ต๋Œ€์—ญ, ๊ฐ•๋‚จ์—ญ, 10); + ์‹ ๋ถ„๋‹น์„  = ์ง€ํ•˜์ฒ _๋…ธ์„ _์ƒ์„ฑ_์š”์ฒญ("์‹ ๋ถ„๋‹น์„ ", "red", ๊ฐ•๋‚จ์—ญ, ์–‘์žฌ์—ญ, 10); + ์‚ผํ˜ธ์„  = ์ง€ํ•˜์ฒ _๋…ธ์„ _์ƒ์„ฑ_์š”์ฒญ("3ํ˜ธ์„ ", "orange", ๊ต๋Œ€์—ญ, ๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ, 2); + + ์ง€ํ•˜์ฒ _๋…ธ์„ ์—_์ง€ํ•˜์ฒ _๊ตฌ๊ฐ„_์ƒ์„ฑ_์š”์ฒญ(์‚ผํ˜ธ์„ , createSectionCreateParams(๋‚จ๋ถ€ํ„ฐ๋ฏธ๋„์—ญ, ์–‘์žฌ์—ญ, 3)); + + ํšŒ์›_์ƒ์„ฑ_์š”์ฒญ(EMAIL, PASSWORD, AGE); + ๋กœ๊ทธ์ธํ† ํฐ = ๋กœ๊ทธ์ธ_๋˜์–ด_์žˆ์Œ(EMAIL, PASSWORD); + } + + @DisplayName("์ฆ๊ฒจ์ฐพ๊ธฐ ์ถ”๊ฐ€ ํ•˜๊ธฐ") + @Test + public void addFavorite() { + // when + ExtractableResponse<Response> response = ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ, ๊ฐ•๋‚จ์—ญ, ์–‘์žฌ์—ญ); + + // then + ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ๋จ(response); + } + + @DisplayName("์ฆ๊ฒจ์ฐพ๊ธฐ ์กฐํšŒ ํ•˜๊ธฐ") + @Test + public void getFavorites() { + // given + ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ, ๊ฐ•๋‚จ์—ญ, ์–‘์žฌ์—ญ); + ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ, ์–‘์žฌ์—ญ, ๊ต๋Œ€์—ญ); + + // when + ExtractableResponse<Response> response = ์ฆ๊ฒจ์ฐพ๊ธฐ_๋ชฉ๋ก_์กฐํšŒ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ); + + // then + ์ฆ๊ฒจ์ฐพ๊ธฐ_์ •๋ณด_์กฐํšŒ๋จ(response, new Long[]{๊ฐ•๋‚จ์—ญ, ์–‘์žฌ์—ญ}, new Long[]{์–‘์žฌ์—ญ, ๊ต๋Œ€์—ญ}); + } + + @DisplayName("์ฆ๊ฒจ์ฐพ๊ธฐ ์‚ญ์ œ ํ•˜๊ธฐ") + @Test + public void deleteFavorites() { + // given + ExtractableResponse<Response> createResponse = ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ, ๊ฐ•๋‚จ์—ญ, ์–‘์žฌ์—ญ); + + // when + ExtractableResponse<Response> response = ์ฆ๊ฒจ์ฐพ๊ธฐ_์‚ญ์ œ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ, createResponse); + + // then + ์ฆ๊ฒจ์ฐพ๊ธฐ_์‚ญ์ œ๋จ(response); + } + + @DisplayName("์ฆ๊ฒจ์ฐพ๊ธฐ ์ถ”๊ฐ€ ํ•˜๊ธฐ - ์œ ํšจํ•˜์ง€ ์•Š์€ ํ† ํฐ ์ผ ๊ฒฝ์šฐ") + @Test + public void addFavoriteWithInvalidToken() { + // when + ExtractableResponse<Response> response = ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์š”์ฒญ("invalid_token", ๊ฐ•๋‚จ์—ญ, ์–‘์žฌ์—ญ); + + // then + ์ฆ๊ฒจ์ฐพ๊ธฐ_๊ถŒํ•œ์ด_์—†์Œ(response); + } + + @DisplayName("์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์„ ๊ด€๋ฆฌํ•œ๋‹ค.") + @Test + public void manageFavorites() { + // when ์ฆ๊ฒจ์ฐพ๊ธฐ ์ƒ์„ฑ์„ ์š”์ฒญ + ExtractableResponse<Response> ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์‘๋‹ต = ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ, ๊ฐ•๋‚จ์—ญ, ์–‘์žฌ์—ญ); + // then ์ฆ๊ฒจ์ฐพ๊ธฐ ์ƒ์„ฑ๋จ + ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ๋จ(์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์‘๋‹ต); + + // when ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก ์กฐํšŒ ์š”์ฒญ + ExtractableResponse<Response> ์ฆ๊ฒจ์ฐพ๊ธฐ_๋ชฉ๋ก_์กฐํšŒ_์‘๋‹ต = ์ฆ๊ฒจ์ฐพ๊ธฐ_๋ชฉ๋ก_์กฐํšŒ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ); + // then ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก ์กฐํšŒ๋จ + ์ฆ๊ฒจ์ฐพ๊ธฐ_์ •๋ณด_์กฐํšŒ๋จ(์ฆ๊ฒจ์ฐพ๊ธฐ_๋ชฉ๋ก_์กฐํšŒ_์‘๋‹ต, new Long[]{ ๊ฐ•๋‚จ์—ญ }, new Long[]{ ์–‘์žฌ์—ญ }); + + // when ์ฆ๊ฒจ์ฐพ๊ธฐ ์‚ญ์ œ ์š”์ฒญ + ExtractableResponse<Response> ์ฆ๊ฒจ์ฐพ๊ธฐ_์‚ญ์ œ_์‘๋‹ต = ์ฆ๊ฒจ์ฐพ๊ธฐ_์‚ญ์ œ_์š”์ฒญ(๋กœ๊ทธ์ธํ† ํฐ, ์ฆ๊ฒจ์ฐพ๊ธฐ_์ƒ์„ฑ_์‘๋‹ต); + // then ์ฆ๊ฒจ์ฐพ๊ธฐ ์‚ญ์ œ๋จ + ์ฆ๊ฒจ์ฐพ๊ธฐ_์‚ญ์ œ๋จ(์ฆ๊ฒจ์ฐพ๊ธฐ_์‚ญ์ œ_์‘๋‹ต); + } + + + private Long ์ง€ํ•˜์ฒ _๋…ธ์„ _์ƒ์„ฑ_์š”์ฒญ(String name, String color, Long upStation, Long downStation, + int distance) { + Map<String, String> lineCreateParams; + lineCreateParams = new HashMap<>(); + lineCreateParams.put("name", name); + lineCreateParams.put("color", color); + lineCreateParams.put("upStationId", upStation + ""); + lineCreateParams.put("downStationId", downStation + ""); + lineCreateParams.put("distance", distance + ""); + + return LineSteps.์ง€ํ•˜์ฒ _๋…ธ์„ _์ƒ์„ฑ_์š”์ฒญ(lineCreateParams).jsonPath().getLong("id"); + } + + private Map<String, String> createSectionCreateParams(Long upStationId, Long downStationId, + int distance) { + Map<String, String> params = new HashMap<>(); + params.put("upStationId", upStationId + ""); + params.put("downStationId", downStationId + ""); + params.put("distance", distance + ""); + return params; + } + +}
Java
`์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์„ ๊ด€๋ฆฌํ•œ๋‹ค` ์—์„œ ์‹œ๋‚˜๋ฆฌ์˜ค ํ˜•์‹์œผ๋กœ ์ž˜ ์ž‘์„ฑํ•ด์ฃผ์…”์„œ ํ•ด๋‹น ํ…Œ์ŠคํŠธ๋“ค์€ ์ž‘์„ฑํ•ด์ฃผ์ง€ ์•Š์•„๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์•„์š” ๐Ÿ˜„
@@ -0,0 +1,50 @@ +package nextstep.subway.applicaion; + +import java.util.List; +import java.util.stream.Collectors; +import nextstep.member.application.MemberService; +import nextstep.member.domain.LoginMember; +import nextstep.member.domain.MemberRepository; +import nextstep.subway.applicaion.dto.FavoriteRequest; +import nextstep.subway.applicaion.dto.FavoriteResponse; +import nextstep.subway.domain.Favorite; +import nextstep.subway.domain.FavoriteRepository; +import nextstep.subway.domain.Station; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class FavoriteService { + private final StationService stationService; + private final PathService pathService; + private final MemberRepository memberRepository; + private final FavoriteRepository favoriteRepository; + + public FavoriteService(StationService stationService, PathService pathService, + MemberRepository memberRepository, FavoriteRepository favoriteRepository) { + this.stationService = stationService; + this.pathService = pathService; + this.memberRepository = memberRepository; + this.favoriteRepository = favoriteRepository; + } + + public FavoriteResponse createFavorite(FavoriteRequest favoriteRequest, Long memberId) { + Station source = stationService.findById(favoriteRequest.getSource()); + Station target = stationService.findById(favoriteRequest.getTarget()); + pathService.findPath(source, target); + Favorite favorite = favoriteRepository.save(Favorite.of(memberId, source, target)); + return FavoriteResponse.from(favorite); + } + + @Transactional(readOnly = true) + public List<FavoriteResponse> findFavorites(Long memberId) { + List<Favorite> favorites = favoriteRepository.findAllByMemberId(memberId); + return favorites.stream().map(FavoriteResponse::from).collect(Collectors.toList()); + } + + public void deleteFavorite(Long favoriteId, Long memberId) { + Favorite favorite = favoriteRepository.getById(favoriteId); + favorite.hasPermission(memberId); + favoriteRepository.delete(favorite); + } +}
Java
memberRepository ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์ง€ ์•Š๋Š”๋ฐ์š”, ์ฆ๊ฒจ์ฐพ๊ธฐ ์ƒ์„ฑ, ์กฐํšŒ, ์‚ญ์ œ ์‹œ ์œ ์š”ํ•œ memberId ์ธ์ง€ ํ™•์ธํ•˜์ง€ ์•Š์•„๋„ ๋ ๊นŒ์š”? ๐Ÿ˜„
@@ -22,10 +22,14 @@ public PathService(LineService lineService, StationService stationService) { public PathResponse findPath(Long source, Long target) { Station upStation = stationService.findById(source); Station downStation = stationService.findById(target); - List<Line> lines = lineService.findLines(); - SubwayMap subwayMap = new SubwayMap(lines); - Path path = subwayMap.findPath(upStation, downStation); + Path path = findPath(upStation, downStation); return PathResponse.of(path); } + + Path findPath(Station upStation, Station downStation) { + List<Line> lines = lineService.findLines(); + SubwayMap subwayMap = new SubwayMap(lines); + return subwayMap.findPath(upStation, downStation); + } }
Java
์ ‘๊ทผ์ œ์–ด์ž๋ฅผ ์ƒ๋žตํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์œผ์‹ ๊ฐ€์š”? ๐Ÿ˜„
@@ -0,0 +1,39 @@ +package nextstep.subway.applicaion.dto; + +import nextstep.subway.domain.Favorite; + +public class FavoriteResponse { + private Long id; + private Long memberId; + private StationResponse source; + private StationResponse target; + + private FavoriteResponse(Long id, Long memberId, + StationResponse source, StationResponse target) { + this.id = id; + this.memberId = memberId; + this.source = source; + this.target = target; + } + + public static FavoriteResponse from(Favorite favorite) { + return new FavoriteResponse(favorite.getId(), favorite.getMemberId(), + StationResponse.of(favorite.getSource()), StationResponse.of(favorite.getTarget())); + } + + public Long getId() { + return id; + } + + public Long getMemberId() { + return memberId; + } + + public StationResponse getSource() { + return source; + } + + public StationResponse getTarget() { + return target; + } +}
Java
์š”๊ตฌ์‚ฌํ•ญ์— memberId ๋Š” ์—†๋„ค์š”! ์š”๊ตฌ์‚ฌํ•ญ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š” ๐Ÿ˜„
@@ -0,0 +1,49 @@ +package nextstep.subway.ui; + +import java.net.URI; +import java.util.List; +import nextstep.auth.authorization.AuthenticationPrincipal; +import nextstep.member.domain.LoginMember; +import nextstep.subway.applicaion.FavoriteService; +import nextstep.subway.applicaion.dto.FavoriteRequest; +import nextstep.subway.applicaion.dto.FavoriteResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/favorites") +public class FavoriteController { + + private final FavoriteService favoriteService; + + public FavoriteController(FavoriteService favoriteService) { + this.favoriteService = favoriteService; + } + + @PostMapping + public ResponseEntity<FavoriteResponse> createFavorite( + @AuthenticationPrincipal LoginMember loginMember, + @RequestBody FavoriteRequest favoriteRequest) { + FavoriteResponse favoriteResponse = favoriteService.createFavorite(favoriteRequest, loginMember.getId()); + return ResponseEntity.created(URI.create("/favorites/" + favoriteResponse.getId())).body(favoriteResponse); + } + + @GetMapping + public ResponseEntity<List<FavoriteResponse>> getFavorites(@AuthenticationPrincipal LoginMember loginMember) { + List<FavoriteResponse> favoriteResponses = favoriteService.findFavorites(loginMember.getId()); + return ResponseEntity.ok(favoriteResponses); + } + + @DeleteMapping("/{favoriteId}") + public ResponseEntity<Void> deleteFavorite(@AuthenticationPrincipal LoginMember loginMember, @PathVariable Long favoriteId) { + favoriteService.deleteFavorite(favoriteId, loginMember.getId()); + return ResponseEntity.noContent().build(); + } + +}
Java
์ฆ๊ฒจ์ฐพ๊ธฐ ์ƒ์„ฑ ํ›„ ๋ฐ˜ํ™˜๊ฐ’์— ๋Œ€ํ•œ ์š”๊ตฌ์‚ฌํ•ญ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”! ๐Ÿ˜„ ![แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-02-22 แ„‹แ…ฉแ„’แ…ฎ 7 58 34](https://user-images.githubusercontent.com/48339310/155118827-d664b3b1-32e7-4255-a58c-e5d09ce3550d.png)
@@ -1,5 +1,6 @@ package nextstep.subway.domain; +import java.util.Optional; import org.jgrapht.GraphPath; import org.jgrapht.alg.shortestpath.DijkstraShortestPath; import org.jgrapht.graph.SimpleDirectedWeightedGraph; @@ -22,6 +23,11 @@ public Path findPath(Station source, Station target) { DijkstraShortestPath<Station, SectionEdge> dijkstraShortestPath = new DijkstraShortestPath<>(graph); GraphPath<Station, SectionEdge> result = dijkstraShortestPath.getPath(source, target); + Optional.ofNullable(result) + .orElseThrow(() -> { + throw new IllegalArgumentException("์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค."); + }); + List<Section> sections = result.getEdgeList().stream() .map(it -> it.getSection()) .collect(Collectors.toList());
Java
Optional ์„ ์‚ฌ์šฉํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์œผ์‹ ๊ฐ€์š”? ์–ด๋– ํ•œ ์ด์ ์ด ์žˆ๋‚˜์š”? ๐Ÿ˜„ ```suggestion if (Objects.isNull(result)) { throw new IllegalArgumentException("์ถœ๋ฐœ์—ญ๊ณผ ๋„์ฐฉ์—ญ์ด ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค."); } ```
@@ -1,4 +1,4 @@ -<!DOCTYPE html> +<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> @@ -7,6 +7,7 @@ <title>react-shopping-products</title> </head> <body> + <div id="toast"></div> <div id="root"></div> <script type="module" src="/src/main.tsx"></script> </body>
Unknown
์š”๊ฒƒ๋„ fileChanged์— ์˜ฌ๋ผ์™€์„œ ์‹ ๊ธฐํ•ด์„œ ๋‚จ๊ฒจ๋ด„ ใ…‹ใ…‹
@@ -0,0 +1,96 @@ +import objectToQueryString, { ObjectQueryParams } from '@/utils/objectToQueryString'; +import { generateBasicToken } from '../utils/auth'; + +type Method = 'GET' | 'POST' | 'PATCH' | 'DELETE'; + +type Body = ReadableStream | XMLHttpRequestBodyInit; +type HeadersType = [string, string][] | Record<string, string> | Headers; + +const USER_ID = process.env.VITE_API_USER_ID || 'id'; +const USER_PASSWORD = process.env.VITE_API_USER_PASSWORD || 'password'; + +type RequestProps = { + baseUrl: string; + endpoint: string; + headers?: HeadersType; + body?: Body | object | null; + queryParams?: ObjectQueryParams; +}; + +type FetcherProps = RequestProps & { + method: Method; +}; + +type Options = { + method: Method; + headers: HeadersType; + body?: Body | null; +}; + +export const requestGet = async <T>({ + baseUrl, + endpoint, + headers = {}, + queryParams, +}: RequestProps): Promise<T> => { + const response = await fetcher({ method: 'GET', baseUrl, endpoint, headers, queryParams }); + const data: T = await response.json(); + + return data; +}; + +export const requestPatch = ({ + baseUrl, + endpoint, + headers = {}, + body, + queryParams, +}: RequestProps) => { + return fetcher({ method: 'PATCH', baseUrl, endpoint, headers, body, queryParams }); +}; + +export const requestPost = ({ + baseUrl, + endpoint, + headers = {}, + body, + queryParams, +}: RequestProps) => { + return fetcher({ method: 'POST', baseUrl, endpoint, headers, body, queryParams }); +}; + +export const requestDelete = ({ baseUrl, endpoint, headers = {}, queryParams }: RequestProps) => { + return fetcher({ method: 'DELETE', baseUrl, endpoint, headers, queryParams }); +}; + +const fetcher = ({ method, baseUrl, endpoint, headers, body, queryParams }: FetcherProps) => { + const token = generateBasicToken(USER_ID, USER_PASSWORD); + const options = { + method, + headers: { + 'Content-Type': 'application/json', + Authorization: token, + ...headers, + }, + body: body ? JSON.stringify(body) : null, + }; + + let url = `${baseUrl}${endpoint}`; + + if (queryParams) url += `?${objectToQueryString(queryParams)}`; + + return errorHandler(url, options, endpoint); +}; + +const errorHandler = async (url: string, options: Options, endpoint: string) => { + try { + const response = await fetch(url, options); + + if (!response.ok) throw new Error('์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); + + return response; + } catch (error) { + console.error(`fail to fetch ${endpoint}\n error message: ${error}`); + throw new Error('๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); + } +};
TypeScript
์ด ํŒŒ์ผ์—์„œ ๊ฐ request๋ฅผ ์ถ”์ƒํ™”ํ•ด์ค€๊ฒŒ ์•„์ฃผ ์ธ์ƒ๊นŠ์—ˆ์Šต๋‹ˆ๋‹ค!!! ๋ฐฐ์›Œ๊ฐ ์ด์ด์ด,,
@@ -0,0 +1,96 @@ +import objectToQueryString, { ObjectQueryParams } from '@/utils/objectToQueryString'; +import { generateBasicToken } from '../utils/auth'; + +type Method = 'GET' | 'POST' | 'PATCH' | 'DELETE'; + +type Body = ReadableStream | XMLHttpRequestBodyInit; +type HeadersType = [string, string][] | Record<string, string> | Headers; + +const USER_ID = process.env.VITE_API_USER_ID || 'id'; +const USER_PASSWORD = process.env.VITE_API_USER_PASSWORD || 'password'; + +type RequestProps = { + baseUrl: string; + endpoint: string; + headers?: HeadersType; + body?: Body | object | null; + queryParams?: ObjectQueryParams; +}; + +type FetcherProps = RequestProps & { + method: Method; +}; + +type Options = { + method: Method; + headers: HeadersType; + body?: Body | null; +}; + +export const requestGet = async <T>({ + baseUrl, + endpoint, + headers = {}, + queryParams, +}: RequestProps): Promise<T> => { + const response = await fetcher({ method: 'GET', baseUrl, endpoint, headers, queryParams }); + const data: T = await response.json(); + + return data; +}; + +export const requestPatch = ({ + baseUrl, + endpoint, + headers = {}, + body, + queryParams, +}: RequestProps) => { + return fetcher({ method: 'PATCH', baseUrl, endpoint, headers, body, queryParams }); +}; + +export const requestPost = ({ + baseUrl, + endpoint, + headers = {}, + body, + queryParams, +}: RequestProps) => { + return fetcher({ method: 'POST', baseUrl, endpoint, headers, body, queryParams }); +}; + +export const requestDelete = ({ baseUrl, endpoint, headers = {}, queryParams }: RequestProps) => { + return fetcher({ method: 'DELETE', baseUrl, endpoint, headers, queryParams }); +}; + +const fetcher = ({ method, baseUrl, endpoint, headers, body, queryParams }: FetcherProps) => { + const token = generateBasicToken(USER_ID, USER_PASSWORD); + const options = { + method, + headers: { + 'Content-Type': 'application/json', + Authorization: token, + ...headers, + }, + body: body ? JSON.stringify(body) : null, + }; + + let url = `${baseUrl}${endpoint}`; + + if (queryParams) url += `?${objectToQueryString(queryParams)}`; + + return errorHandler(url, options, endpoint); +}; + +const errorHandler = async (url: string, options: Options, endpoint: string) => { + try { + const response = await fetch(url, options); + + if (!response.ok) throw new Error('์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); + + return response; + } catch (error) { + console.error(`fail to fetch ${endpoint}\n error message: ${error}`); + throw new Error('๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); + } +};
TypeScript
์ด๊ฑฐ ์™œ ์•ˆํ•จ ใ…‹ใ…‹ใ…‹
@@ -0,0 +1,96 @@ +import objectToQueryString, { ObjectQueryParams } from '@/utils/objectToQueryString'; +import { generateBasicToken } from '../utils/auth'; + +type Method = 'GET' | 'POST' | 'PATCH' | 'DELETE'; + +type Body = ReadableStream | XMLHttpRequestBodyInit; +type HeadersType = [string, string][] | Record<string, string> | Headers; + +const USER_ID = process.env.VITE_API_USER_ID || 'id'; +const USER_PASSWORD = process.env.VITE_API_USER_PASSWORD || 'password'; + +type RequestProps = { + baseUrl: string; + endpoint: string; + headers?: HeadersType; + body?: Body | object | null; + queryParams?: ObjectQueryParams; +}; + +type FetcherProps = RequestProps & { + method: Method; +}; + +type Options = { + method: Method; + headers: HeadersType; + body?: Body | null; +}; + +export const requestGet = async <T>({ + baseUrl, + endpoint, + headers = {}, + queryParams, +}: RequestProps): Promise<T> => { + const response = await fetcher({ method: 'GET', baseUrl, endpoint, headers, queryParams }); + const data: T = await response.json(); + + return data; +}; + +export const requestPatch = ({ + baseUrl, + endpoint, + headers = {}, + body, + queryParams, +}: RequestProps) => { + return fetcher({ method: 'PATCH', baseUrl, endpoint, headers, body, queryParams }); +}; + +export const requestPost = ({ + baseUrl, + endpoint, + headers = {}, + body, + queryParams, +}: RequestProps) => { + return fetcher({ method: 'POST', baseUrl, endpoint, headers, body, queryParams }); +}; + +export const requestDelete = ({ baseUrl, endpoint, headers = {}, queryParams }: RequestProps) => { + return fetcher({ method: 'DELETE', baseUrl, endpoint, headers, queryParams }); +}; + +const fetcher = ({ method, baseUrl, endpoint, headers, body, queryParams }: FetcherProps) => { + const token = generateBasicToken(USER_ID, USER_PASSWORD); + const options = { + method, + headers: { + 'Content-Type': 'application/json', + Authorization: token, + ...headers, + }, + body: body ? JSON.stringify(body) : null, + }; + + let url = `${baseUrl}${endpoint}`; + + if (queryParams) url += `?${objectToQueryString(queryParams)}`; + + return errorHandler(url, options, endpoint); +}; + +const errorHandler = async (url: string, options: Options, endpoint: string) => { + try { + const response = await fetch(url, options); + + if (!response.ok) throw new Error('์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); + + return response; + } catch (error) { + console.error(`fail to fetch ${endpoint}\n error message: ${error}`); + throw new Error('๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); + } +};
TypeScript
์—ฌ๊ธฐ์„œ ๋˜์ง€๋Š” ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๊ฐ€ showToast์—์„œ ๋ณด์ด๋Š” ๋ฉ”์‹œ์ง€์—์„œ๋Š” ํ™œ์šฉ์„ ์•ˆํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ํ†ต์ผ์‹œํ‚ค๋Š” ๋ฐฉ์‹์ด๋‚˜ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์ด๋Š” ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ์–ด๋–ป๊ฒŒ ๊ด€๋ฆฌํ• ์ง€๋„ ๊ณ ๋ฏผํ•ด๋ณด๋ฉด ์ข‹์„ ๋“ฏ์š”! (๋‚˜๋„ ํ•ด์•ผํ•จ ใ…‹)
@@ -0,0 +1,75 @@ +import { CartItem } from '@/types/cartItem.type'; +import { BASE_URL } from '../baseUrl'; +import { requestGet, requestPost, requestDelete } from '../fetcher'; +import { ENDPOINT } from '../endpoints'; + +type ResponseCartItemList = { + content: CartItem[]; + pageable: { + sort: { + sorted: false; + unsorted: true; + empty: true; + }; + pageNumber: 0; + pageSize: 20; + offset: 0; + paged: true; + unpaged: false; + }; + last: true; + totalPages: 1; + totalElements: 6; + sort: { + sorted: false; + unsorted: true; + empty: true; + }; + first: true; + number: 0; + numberOfElements: 6; + size: 20; + empty: false; +}; + +type QueryParams = { + page: number; + size: number; +}; + +export const requestCartItemList = async ( + page: number = 0, + size: number = 20, +): Promise<ResponseCartItemList> => { + const queryParams: QueryParams = { + page, + size, + }; + + return await requestGet<ResponseCartItemList>({ + baseUrl: BASE_URL.SHOP, + endpoint: ENDPOINT.CART_ITEM, + queryParams, + }); +}; + +export const requestAddCartItem = async (productId: number, quantity: number = 1) => { + await requestPost({ + baseUrl: BASE_URL.SHOP, + endpoint: ENDPOINT.CART_ITEM, + body: { + productId, + quantity, + }, + }); +}; + +export const requestDeleteCartItem = async (cartItemId: number) => { + await requestDelete({ + baseUrl: BASE_URL.SHOP, + endpoint: `${ENDPOINT.CART_ITEM}/${cartItemId}`, + body: { + id: cartItemId, + }, + }); +};
TypeScript
์‚ฌ์†Œํ•œ ์˜๊ฒฌ์ธ๋ฐ, ์ €๋Š” api ์‘๋‹ต์ด ์–ธ์ œ๋“  ๋ฐ”๋€” ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ์š”๋Ÿฐ ํƒ€์ž…์€ type๋ณด๋‹ค interface๋กœ ์„ ์–ธํ•˜๋ ค๋Š” ํŽธ์ด๊ธด ํ•จ๋‹ค ๊ทธ๋Ÿฌ๋ฉด pageable ๊ฐ™์ด ์•ˆ์“ฐ๊ณ  ๋ญ”๊ฐ€ ๋‹ค๋ฅธ ์ •๋ณด๋ž‘ ์ค‘๋ณต๋˜๋Š” ์นœ๊ตฌ๋“ค์€ ์•ˆ์จ์ค„ ์ˆ˜๋„ ์žˆ์–ด์„œ ์˜คํžˆ๋ ค ๋ฆฌ๋ทฐ์–ด์—๊ฒŒ ์“ธ ์นœ๊ตฌ๋“ค๋งŒ interface์— ์„ ์–ธํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ๋„ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šด๋‹ค. (interface์˜ ๋‹จ์ ์€ ์—†์„๊นŒ ์ƒ๊ฐ๋„ ๋˜๋Š”๋ฐ ํ•จ ์ฐพ์•„๋ด์•ผ๊ฒ ๋‹ค)
@@ -0,0 +1,29 @@ +.container { + position: relative; +} + +.cartIcon { + cursor: pointer; +} + +.amountContainer { + position: absolute; + bottom: 0; + right: 0; + width: 19px; + height: 19px; + background: #fff; + display: flex; + justify-content: center; + align-items: center; + border-radius: 50%; +} + +.amount { + color: black; + font-size: 10px; + font-weight: 700; + line-height: 12.19px; + text-align: left; + margin-top: 2px; +}
Unknown
์ด๊ฑฐ ๊ฐ ์ ์ธ ๊ถ๊ธˆ์ฆ์ธ๋ฐ ์ด๊ฑฐ ๋‘๊ฐœ ํ•„์š”ํ•จ?!
@@ -1,4 +1,4 @@ -<!DOCTYPE html> +<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> @@ -7,6 +7,7 @@ <title>react-shopping-products</title> </head> <body> + <div id="toast"></div> <div id="root"></div> <script type="module" src="/src/main.tsx"></script> </body>
Unknown
์ €๋„ ์ด๊ฒŒ ์™œ ๋œ์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š”.... ใ…‹.ใ…‹
@@ -0,0 +1,96 @@ +import objectToQueryString, { ObjectQueryParams } from '@/utils/objectToQueryString'; +import { generateBasicToken } from '../utils/auth'; + +type Method = 'GET' | 'POST' | 'PATCH' | 'DELETE'; + +type Body = ReadableStream | XMLHttpRequestBodyInit; +type HeadersType = [string, string][] | Record<string, string> | Headers; + +const USER_ID = process.env.VITE_API_USER_ID || 'id'; +const USER_PASSWORD = process.env.VITE_API_USER_PASSWORD || 'password'; + +type RequestProps = { + baseUrl: string; + endpoint: string; + headers?: HeadersType; + body?: Body | object | null; + queryParams?: ObjectQueryParams; +}; + +type FetcherProps = RequestProps & { + method: Method; +}; + +type Options = { + method: Method; + headers: HeadersType; + body?: Body | null; +}; + +export const requestGet = async <T>({ + baseUrl, + endpoint, + headers = {}, + queryParams, +}: RequestProps): Promise<T> => { + const response = await fetcher({ method: 'GET', baseUrl, endpoint, headers, queryParams }); + const data: T = await response.json(); + + return data; +}; + +export const requestPatch = ({ + baseUrl, + endpoint, + headers = {}, + body, + queryParams, +}: RequestProps) => { + return fetcher({ method: 'PATCH', baseUrl, endpoint, headers, body, queryParams }); +}; + +export const requestPost = ({ + baseUrl, + endpoint, + headers = {}, + body, + queryParams, +}: RequestProps) => { + return fetcher({ method: 'POST', baseUrl, endpoint, headers, body, queryParams }); +}; + +export const requestDelete = ({ baseUrl, endpoint, headers = {}, queryParams }: RequestProps) => { + return fetcher({ method: 'DELETE', baseUrl, endpoint, headers, queryParams }); +}; + +const fetcher = ({ method, baseUrl, endpoint, headers, body, queryParams }: FetcherProps) => { + const token = generateBasicToken(USER_ID, USER_PASSWORD); + const options = { + method, + headers: { + 'Content-Type': 'application/json', + Authorization: token, + ...headers, + }, + body: body ? JSON.stringify(body) : null, + }; + + let url = `${baseUrl}${endpoint}`; + + if (queryParams) url += `?${objectToQueryString(queryParams)}`; + + return errorHandler(url, options, endpoint); +}; + +const errorHandler = async (url: string, options: Options, endpoint: string) => { + try { + const response = await fetch(url, options); + + if (!response.ok) throw new Error('์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); + + return response; + } catch (error) { + console.error(`fail to fetch ${endpoint}\n error message: ${error}`); + throw new Error('๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'); + } +};
TypeScript
๋งž์•„์š”. ์‚ฌ์‹ค ์–ด๋””์„œ ๋˜์ง„ ์˜ค๋ฅ˜๊ฐ€ ์บ์น˜๋˜๊ณ  ๊ทธ๋Ÿฐ๊ฑธ ํ™•์ธ์„ ์•ˆํ•ด์„œ ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์™€ ๋น„์Šทํ•œ ์„ค๊ณ„๋กœ ์ด๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ ์‹ถ์Šต๋‹ˆ๋‹ค. ํ•œ๋ฒˆ ์‹œ๋„ํ•ด๋ณผ๊ฒŒ์š”!
@@ -0,0 +1,29 @@ +.container { + position: relative; +} + +.cartIcon { + cursor: pointer; +} + +.amountContainer { + position: absolute; + bottom: 0; + right: 0; + width: 19px; + height: 19px; + background: #fff; + display: flex; + justify-content: center; + align-items: center; + border-radius: 50%; +} + +.amount { + color: black; + font-size: 10px; + font-weight: 700; + line-height: 12.19px; + text-align: left; + margin-top: 2px; +}
Unknown
๊ธ์–ด์˜จ ๊ฒƒ ๊ฐ™๋„ค์š”. ํ•„์š” ์—†์„๋“ฏ...!
@@ -0,0 +1,99 @@ +## ์šฐ์•„ํ•œ ํ…Œํฌ์ฝ”์Šค ํ”„๋ฆฌ์ฝ”์Šค ํฌ๋ฆฌ์Šค๋งˆ์Šค ํ”„๋กœ๋ชจ์…˜ + +### ์ง„ํ–‰๋ฐฉ์‹ +- ์‹œ์ž‘ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ +- ๋ฐฉ๋ฌธ ๋‚ ์งœ ์ž…๋ ฅ +- ์ฃผ๋ฌธ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ž…๋ ฅ +- ์ž…๋ ฅ ์š”์ผ ์ด๋ฒคํŠธ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ +- ์ด๋ฒคํŠธ ํ˜œํƒ ์ถœ๋ ฅ + - ์ฃผ๋ฌธ ๋ฉ”๋‰ด + - ํ• ์ธ ์ „ ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก + - ์ฆ์ • ๋ฉ”๋‰ด ์—ฌ๋ถ€ + - ํ˜œํƒ ๋‚ด์—ญ ์—ฌ๋ถ€ + - ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก + - 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ์—ฌ๋ถ€ + +### ์ฃผ์š” ๊ตฌํ˜„ ์‚ฌํ•ญ +- [x] ์ž…๋ ฅ ๋ทฐ ๊ตฌํ˜„ +- [x] ์ถœ๋ ฅ ๋ทฐ ๊ตฌํ˜„ + +- [x] ๋‚ ์งœ ์ž…๋ ฅ ๋ฐ ์ €์žฅ ๊ฐ์ฒด ๊ตฌํ˜„ +- [x] ๋‚ ์งœ ์ž…๋ ฅ ์‹œ ๋‚ ์งœ๊ด€๋ จ ํ•ด๋‹น ์ด๋ฒคํŠธ ํ•ญ๋ชฉ ์ €์žฅ + - [x] ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ์ด ๊ธˆ์•ก ํ• ์ธ ํ•ญ๋ชฉ + - [x] ํ‰์ผ/์ฃผ๋ง ๊ตฌ๋ถ„ ํ• ์ธ ํƒ€์ž… ํ•ญ๋ณต + - [x] ๋‚ ์งœ๋‚˜ ๋‹ฌ๋ ฅ์˜ ๋ณ„์— ๋”ฐ๋ผ ์ŠคํŽ˜์…œ ํ• ์ธ ํ•ญ๋ชฉ +- [x] ๋‚ ์งœ ๊ด€๋ จ ์ด๋ฒคํŠธ ๋ฐ˜ํ™˜ DTO ๋ฐ˜ํ™˜ + +- [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ž…๋ ฅ ๋ฐ ์ €์žฅ ๊ฐ์ฒด ๊ตฌํ˜„ + - [x] ๊ฐ ๋ฉ”๋‰ด๋ฅผ ๊ธฐ๋ณธ ๊ธˆ์•ก๊ณผ ๋ฉ”๋‰ด ๋ช…์œผ๋กœ Enum ์œผ๋กœ ๊ด€๋ฆฌ + - [x] ์ฃผ๋ฌธํ•œ ๋ฉ”๋‰ด ์ž…๋ ฅ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์ง„ํ–‰ ํ›„ ์ €์žฅ ๊ฐ์ฒด์— ์ €์žฅ +- [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋‚ด์—ญ ๋ฐ˜ํ™˜ DTO ๋ฐ˜ํ™˜ + +- [x] ๋‚ ์งœ ์ด๋ฒคํŠธ์™€ ์ฃผ๋ฌธ ๋ฉ”๋‰ด DTO ๋ฅผ ํ†ตํ•œ ์ด๋ฒคํŠธ ํ˜œํƒ ์ ์šฉ +- [x] ์ด๋ฒคํŠธ ์ ์šฉ DTO ๋ฐ˜ํ™˜ ๋ฐ ์ถœ๋ ฅ + - [x] ํ• ์ธ ์ „ ๊ธˆ์•ก์„ ์ถœ๋ ฅ + - [x] ํ• ์ธ ์ „ ๊ธˆ์•ก์— ๋”ฐ๋ฅธ ์ฆ์ • ์—ฌ๋ถ€ ์ถœ๋ ฅ + - ์ฆ์ • ์—ฌ๋ถ€๊ฐ€ ์—†๋‹ค๋ฉด '์—†์Œ' ์ถœ๋ ฅ + - [x] ํ˜œํƒ ๋‚ด์—ญ ์ถœ๋ ฅ + - ์ ์šฉ๋œ ํ˜œํƒ ์—†๋‹ค๋ฉด '์—†์Œ' ์ถœ๋ ฅ + - [x] ํ˜œํƒ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ์ฆ์ • ํ˜œํƒ ๊ธˆ์•ก์„ ์ œ์™ธํ•œ ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ์ด ํ˜œํƒ ๊ธˆ์•ก์— ๋”ฐ๋ฅธ ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ๋ถ€์—ฌ ์—ฌ๋ถ€ ์ถœ๋ ฅ + - ์ด๋ฒคํŠธ ๋ฐฐ์ง€๊ฐ€ ์—†๋‹ค๋ฉด '์—†์Œ' ์ถœ๋ ฅ + +- ์ถ”๊ฐ€ ๊ตฌํ˜„ ์‚ฌํ•ญ + - ์ด๋ฒคํŠธ ๊ฒฐ๊ณผ ๋„๋ฉ”์ธ์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅ ๋ฌธ์ž์—ด์œผ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ Builder DTO ์ƒ์„ฑ/๋ฐ˜ํ™˜ + - ์ž˜๋ชป๋œ ์ž…๋ ฅ์„ ํ†ตํ•œ ๊ณผ์ •์€ ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ ๋ฐ ์žฌ์ž…๋ ฅ + - ์ด ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๊ธˆ์•ก์ด 10,000์› ์ดํ•˜์ผ ๊ฒฝ์šฐ ๋ชจ๋“  ํ• ์ธ ๊ธˆ์•ก 0์œผ๋กœ ์ง€์ • + +### ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- ๋‚ ์งœ ์ž…๋ ฅ ์˜ˆ์™ธ + - [x] ์ž˜๋ชป๋œ ๋‚ ์งœ ์ž…๋ ฅ์˜ ๊ฒฝ์šฐ + - [x] ๋‚ ์งœ๊ฐ€ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ณ€๊ฒฝ์ด ์•ˆ๋  ๋•Œ +- ๋ฉ”๋‰ด ์ž…๋ ฅ ์˜ˆ์™ธ + - [x] ๋ฉ”๋‰ด ์ž…๋ ฅ ์‹œ ์ •๊ทœํ‘œํ˜„์‹ ํŒจํ„ด์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ (TextProcessor ์ฒ˜๋ฆฌ) + - [x] ์ค‘๋ณต ๋ฉ”๋‰ด๋ช… ์ž…๋ ฅ์˜ ๊ฒฝ์šฐ (TextProcessor ์ฒ˜๋ฆฌ) + - [x] ์—†๋Š” ๋ฉ”๋‰ด๋ช… ์ž…๋ ฅ์˜ ๊ฒฝ์šฐ + - [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๊ฐ€ 1๋ณด๋‹ค ์ž‘์„ ๋•Œ + - [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด๊ฐ€ 20๊ฐœ๋ฅผ ๋„˜์„ ๋•Œ + - [x] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธ ์‹œ ์ฃผ๋ฌธ ๋ถˆ๊ฐ€๋Šฅ + +### ํด๋ž˜์Šค ๊ตฌ์กฐ +- InputView : ํ™”๋ฉด ์ž…๋ ฅ์„ ๋‹ด๋‹นํ•˜๋Š” ๋ทฐ + - InputViewMessage : ์ž…๋ ฅ์„ ์œ„ํ•œ ๋ฉ”์‹œ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Enum +- OutputView : ํ™”๋ฉด ์ถœ๋ ฅ์„ ๋‹ด๋‹นํ•˜๋Š” ๋ทฐ + - OutputViewMessage : ์ถœ๋ ฅ์„ ์œ„ํ•œ ๋ฉ”์‹œ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Enum +- PromotionRun : ๋ทฐ์™€ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ํด๋ž˜์Šค๋กœ ์š”์ฒญ ์ „๋‹ฌ +- PromotionController : ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์š”์ฒญ์„ ์ „๋‹ฌํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ +- PromotionService : ํ”„๋กœ๋ชจ์…˜ ์œ ํšจ์„ฑ ๊ฒ€์ฆ์„ ๊ฑฐ์นœ ๊ฐ์ฒด ์ƒ์„ฑ๊ณผ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์‹คํ–‰ํ•  ์„œ๋น„์Šค +- TextProcessor : ์ž…๋ ฅ๋ฐ›์€ ๋ฌธ์ž์—ด์„ ํŠน์ • ํƒ€์ž…์œผ๋กœ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ์œ„ํ•œ ์„œ๋น„์Šค +- OrderMenus : ์ฃผ๋ฌธ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ €์žฅํ•˜๋Š” ํด๋ž˜์Šค + - MenuItem : ๋ฉ”๋‰ด ์ด๋ฆ„๊ณผ ๊ฐ€๊ฒฉ, ๋ฉ”๋‰ด ์ข…๋ฅ˜๋ฅผ ์ €์žฅํ•˜๋Š” Enum + - MenuCategory : ๋ฉ”๋‰ด ์ข…๋ฅ˜๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” Enum +- ReservationDateEvent : ๋‚ ์งœ ๊ด€๋ จ ์ด๋ฒคํŠธ ์ €์žฅ ํด๋ž˜์Šค + - ReservationDate : ์ž…๋ ฅ๋œ ๋‚ ์งœ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ํด๋ž˜์Šค + - ChristmasDiscount : ํฌ๋ฆฌ์Šค๋งˆ์Šค D-day ํ• ์ธ ๊ด€๋ฆฌ ํด๋ž˜์Šค + - WeekDiscountType : ์ฃผ๋ง ํ• ์ธ, ํ‰์ผ ํ• ์ธ์„ ๊ตฌ๋ถ„ํ•˜๋Š” Enum + - SpecialDayDiscount : ํŠน๋ณ„ ํ• ์ธ ์ผ์ž๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” Enum +- EventResult : ์ ์šฉ ์ค‘์ธ ๋ชจ๋“  ์ด๋ฒคํŠธ๋ฅผ ์ €์žฅํ•˜๋Š” ํด๋ž˜์Šค + - DiscountDetail : ์ฃผ๋ฌธ ๊ธˆ์•ก๊ณผ ํ• ์ธ, ์˜ˆ์ƒ ๊ธˆ์•ก ๋“ฑ์„ ๋ณด๊ด€ํ•œ ํด๋ž˜์Šค + - GiftEvent : ์ฆ์ • ์ƒํ’ˆ ์—ฌ๋ถ€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Enum + - RewardBadge : ์ด๋ฒคํŠธ ๋ฐฐ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Enum +- PromotionException : ์ง€์ •๋œ Enum ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋ฅผ ํ†ตํ•ด ๊ฐ’๋ฅผ ๋‹ด์•„ IllegalArgumentException ์ƒ์„ฑ + - ExceptionMessage : ์˜ˆ์™ธ ๋ฐœ์ƒ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๊ด€ํ•œ Enum Class +- PromotionConverter : Service ์—์„œ Domain to DTO ์ปจ๋ฒ„ํ„ฐ +- EventResultTextFactory : EventResultDTO ๋ฐ˜ํ™˜์„ ์œ„ํ•œ ๋ฌธ์ž์—ด ์กฐ์ž‘ ์„œ๋น„์Šค + - EventResultText : EventResultDTO ์— ํ•„์š”ํ•œ ๋ฌธ์ž์—ด Enum +- ํ…Œ์ŠคํŠธ : ํด๋ž˜์Šค๋ณ„ ๋ฉ”์†Œ๋“œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ง„ํ–‰ + +### ์ด๋ฒˆ์— ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ณ ๋ฏผํ•œ ์š”์†Œ +- ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ๊ตฌ์กฐ ์„ค๊ณ„ + - ์ดํ›„ ํ•„์š”ํ•œ ํด๋ž˜์Šค๋“ค์„ ์ถ”๊ฐ€ํ•˜๋ฉฐ ์„ค๊ณ„ ๋ณ€๊ฒฝ +- ๋™์ผํ•œ ์ž…๋ ฅ๊ณผ ์ถœ๋ ฅ์„ ํ•˜๋Š” ๋ทฐ๋Š” ์‹ฑ๊ธ€ํ†ค์œผ๋กœ ๊ตฌํ˜„ +- ์ž…๋ ฅ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์™€ ๊ฐ์ฒด ์ƒ์„ฑ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๊ตฌ๋ถ„์— ๋Œ€ํ•œ ๊ณ ๋ฏผ +- ์ด๋ฒคํŠธ ์ ์šฉ ์‹œ ์ด๋ฒคํŠธ ๋‚ด์—ญ๊ณผ ์ฃผ๋ฌธ ๋‚ด์—ญ์„ ์‚ฌ์šฉํ•ด ๊ฐ’์„ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•์„ Service ์—์„œ ์ง„ํ–‰ํ• ์ง€ ๊ฐ์ฒด ๋‚ด๋ถ€์—์„œ ์ง„ํ–‰ํ• ์ง€ ๊ณ ๋ฏผ +- ์ถœ๋ ฅ์„ ์œ„ํ•œ DTO ์ƒ์„ฑ์— ๋Œ€ํ•œ ๊ณ ๋ฏผ + - DTO ๋ฃฐ ์ถœ๋ ฅํ•˜๊ณ  ํ•ด๋‹น DTO ํ†ตํ•ด ๋‹ค์‹œ ์ด๋ฒคํŠธ ๋‚ด์—ญ ํ™•์ธํ•˜๋Š”๋ฐ ์žˆ์–ด DTO ๊ฐ’์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• + - EventResultDTO ๋ทฐ์— ์ถœ๋ ฅํ•  ๋ฌธ์ž์—ด์„ ๊ฐ€์ง€๊ณ  ์žˆ์„ DTO ์ƒ์„ฑ ๋ฐฉ๋ฒ• ๊ณ ๋ฏผ ํ›„ Builder, EventResultTextFactory ์‚ฌ์šฉ +- ์ž˜๋ชป๋œ ์ž…๋ ฅ์— ๋Œ€ํ•œ ๋ฉ”์„œ๋“œ ์žฌ์‹คํ–‰ ๋กœ์ง์€ ์ง€๋‚œ์ฃผ [zangsu๋‹˜](https://github.com/zangsu) ์ฝ”๋“œ๋ฆฌ๋ทฐ๋กœ ๋ฐฐ์šด Supplier ๋ฐ˜๋ณต ์‚ฌ์šฉ +- ํ…Œ์ŠคํŠธ ์ฝ”๋“œ mock ๊ฐ์ฒด์— ๋Œ€ํ•œ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ๊ณ ๋ฏผ \ No newline at end of file
Unknown
README์— ํด๋ž˜์Šค์ด๋ฆ„์„ ์ž‘์„ฑํ•˜๊ธฐ๋ณด๋‹ค ์–ด๋–ค ์—ญํ• ์˜ ํด๋ž˜์Šค์ธ์ง€ ์ •๋„๋งŒ ์ž‘์„ฑํ•˜์‹œ๋Š”๊ฒŒ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์•„๋ฌด๋ž˜๋„ ํด๋ž˜์Šค์ด๋ฆ„์ด๋‚˜ ๋ฉ”์†Œ๋“œ ์ด๋ฆ„์€ ๊ฐ€๋ณ€์„ฑ์ด ๋†’๋‹ค๋ณด๋‹ˆ README๋„ ์ฃผ๊ธฐ์ ์œผ๋กœ ์—…๋ฐ์ดํŠธํ•ด์•ผํ•ด์„œ ๋ฒˆ๊ฑฐ๋กœ์›€์ด ํฌ๊ฑฐ๋“ ์š”
@@ -0,0 +1,20 @@ +package christmas.exception; + +public enum ExceptionMessage { + INVALID_INPUT_DATE("์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + INVALID_INPUT_ORDER("์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + INVALID_MENU_ITEM("ํ•ด๋‹น ๋ฉ”๋‰ด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."), + INVALID_WEEK_DISCOUNT_TYPE("์ž˜๋ชป๋œ ์ฃผ๊ฐ„ ํ• ์ธ ํƒ€์ž…์ž…๋‹ˆ๋‹ค."), + ; + + private static final String PREFIX = "[ERROR] "; + private final String errorMessage; + + ExceptionMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorMessage() { + return PREFIX + errorMessage; + } +}
Java
์ถ”๊ฐ€๋  enum์„ ๊ณ ๋ คํ•˜์…”์„œ ์ด๋ ‡๊ฒŒ ์ž‘์„ฑํ•œ ์˜๋„๋ผ๊ณ  ์ƒ๊ฐ์€ ๋˜์ง€๋งŒ, ๊ผผ๊ผผํ•˜๊ณ  ํŒŒ๊ณ ๋“ค์ž๋ฉด ,;๋ณด๋‹ค ;๋กœ ๋๋‚ด๋Š”๊ฒŒ ๋” ์ข‹์ง€ ์•Š์„๊นŒ์š”?? ๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค ใ…Žใ…Žใ…Ž
@@ -1,7 +1,20 @@ package christmas; + +import camp.nextstep.edu.missionutils.Console; +import christmas.run.PromotionRun; +import christmas.view.InputView; +import christmas.view.OutputView; + public class Application { public static void main(String[] args) { - // TODO: ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ + try { + InputView inputView = SingletonView.getInputView(); + OutputView outputView = SingletonView.getOutputView(); + PromotionRun promotionRun = new PromotionRun(inputView, outputView); + promotionRun.runPromotion(); + } finally { + Console.close(); + } } }
Java
๋ทฐ๋ฅผ ์‹ฑ๊ธ€ํ†ค์œผ๋กœ ๊ด€๋ฆฌํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,20 @@ +package christmas.exception; + +public enum ExceptionMessage { + INVALID_INPUT_DATE("์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + INVALID_INPUT_ORDER("์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + INVALID_MENU_ITEM("ํ•ด๋‹น ๋ฉ”๋‰ด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."), + INVALID_WEEK_DISCOUNT_TYPE("์ž˜๋ชป๋œ ์ฃผ๊ฐ„ ํ• ์ธ ํƒ€์ž…์ž…๋‹ˆ๋‹ค."), + ; + + private static final String PREFIX = "[ERROR] "; + private final String errorMessage; + + ExceptionMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorMessage() { + return PREFIX + errorMessage; + } +}
Java
์ถ”๊ฐ€์ ์œผ๋กœ ์š”๊ตฌ์‚ฌํ•ญ์— ์—๋Ÿฌ๋ฉ”์‹œ์ง€๋Š” "[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."์œผ๋กœ ํ†ต์ผํ•˜๋ผ๊ณ  ๊ธฐ์žฌ๋˜์–ด ์žˆ์–ด ์ตœ์ข…์ฝ”๋”ฉํ…Œ์ŠคํŠธ๋กœ ๊ฐ€์‹œ๊ฒŒ ๋˜๋ฉด ๊ผผ๊ผผํžˆ ๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,33 @@ +package christmas.model.event; + +import christmas.model.date.ReservationDate; + +public class ChristmasDiscount { + private static final int FIRST_DAY = 1; + private static final int CHRISTMAS_DAY = 25; + private static final int BASIC_DISCOUNT = 1000; + private static final int PLUS_DISCOUNT = 100; + private static final int NONE_DISCOUNT = 0; + + private final int discount; + + public ChristmasDiscount(ReservationDate date) { + this.discount = initDiscountAmount(date); + } + + private int initDiscountAmount(ReservationDate date) { + if (date.day() > CHRISTMAS_DAY) { + return NONE_DISCOUNT; + } + + return BASIC_DISCOUNT + getPlusDiscount(date.day()); + } + + private int getPlusDiscount(int day) { + return (day - FIRST_DAY) * PLUS_DISCOUNT; + } + + public int getDiscount() { + return discount; + } +}
Java
ReservationDate์—์„œ ์Šค์Šค๋กœ ์ž์‹ ์ด ๊ฐ€์ง„ ๊ฐ’์—๋Œ€ํ•ด ๊ฒ€์ฆํ•˜๋„๋ก ๋ฉ”์†Œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜์‹œ๋Š” ๊ฒƒ์ด ๋” ๊ฐ์ฒด์ง€ํ–ฅ์ ์ธ ์ฝ”๋“œ๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. date.isChristmasDay() ์™€ ๊ฐ™์ด ๋ง์ด์ฃ !! 'getter๋ฅผ ์ง€์–‘ํ•˜๋ผ'๋Š” ์˜๋ฏธ๋Š” VO์—๊ฒŒ๋„ ๋™์ผํ•˜๊ฒŒ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค. ๊ด€๋ จ ๋ฌธ์„œ๋ฅผ ์•„๋ž˜ ๋งํฌ๋กœ ๋‹ฌ์•„๋‘˜๊ฒŒ์š”! https://tecoble.techcourse.co.kr/post/2020-04-28-ask-instead-of-getter/
@@ -0,0 +1,62 @@ +package christmas.model.event; + +import christmas.model.event.dto.ReservationDateEventDTO; + +public class DiscountDetail { + private final int totalPriceBeforeDiscount; + private final int totalPriceAfterDiscount; + private final WeekDiscountType weekDiscountType; + private final int christmasDiscount; + private final int weekTypeDiscount; + private final int specialDiscount; + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount, int weekTypeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = dateEventDTO.getChristmasDiscount(); + this.specialDiscount = dateEventDTO.getSpecialDiscount(); + this.weekTypeDiscount = weekTypeDiscount; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = 0; + this.specialDiscount = 0; + this.weekTypeDiscount = 0; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + private int initTotalPriceAfterDiscount() { + return totalPriceBeforeDiscount - getTotalDiscount(); + } + + public int getTotalPriceBeforeDiscount() { + return totalPriceBeforeDiscount; + } + + public int getTotalPriceAfterDiscount() { + return totalPriceAfterDiscount; + } + + public int getChristmasDiscount() { + return christmasDiscount; + } + + public int getSpecialDiscount() { + return specialDiscount; + } + + public int getWeekTypeDiscount() { + return weekTypeDiscount; + } + + public WeekDiscountType getWeekDiscountType() { + return weekDiscountType; + } + + public int getTotalDiscount() { + return christmasDiscount + weekTypeDiscount + specialDiscount; + } +}
Java
DiscountDetil์˜ ํ•„๋“œ๋กœ ์ด ๊ฐ’๋“ค์„ ๊ตณ์ด ๊ฐ€์ ธ์•ผ ํ•  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”? ์žฌ์‚ฌ์šฉ์˜ ์—ฌ์ง€๊ฐ€ ์—†๋‹ค๋ฉด ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ๋ฉ”์‹œ์ง€๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ์‹์ด ๋” ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•ด์š”!
@@ -0,0 +1,62 @@ +package christmas.model.event; + +import christmas.model.event.dto.ReservationDateEventDTO; + +public class DiscountDetail { + private final int totalPriceBeforeDiscount; + private final int totalPriceAfterDiscount; + private final WeekDiscountType weekDiscountType; + private final int christmasDiscount; + private final int weekTypeDiscount; + private final int specialDiscount; + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount, int weekTypeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = dateEventDTO.getChristmasDiscount(); + this.specialDiscount = dateEventDTO.getSpecialDiscount(); + this.weekTypeDiscount = weekTypeDiscount; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = 0; + this.specialDiscount = 0; + this.weekTypeDiscount = 0; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + private int initTotalPriceAfterDiscount() { + return totalPriceBeforeDiscount - getTotalDiscount(); + } + + public int getTotalPriceBeforeDiscount() { + return totalPriceBeforeDiscount; + } + + public int getTotalPriceAfterDiscount() { + return totalPriceAfterDiscount; + } + + public int getChristmasDiscount() { + return christmasDiscount; + } + + public int getSpecialDiscount() { + return specialDiscount; + } + + public int getWeekTypeDiscount() { + return weekTypeDiscount; + } + + public WeekDiscountType getWeekDiscountType() { + return weekDiscountType; + } + + public int getTotalDiscount() { + return christmasDiscount + weekTypeDiscount + specialDiscount; + } +}
Java
์™ธ๋ถ€ ์ƒ์„ฑ์„ ๋ง‰๊ธฐ ์œ„ํ•ด ์ƒ์„ฑ์ž๋ฅผ protected๋กœ ๊ด€๋ฆฌํ•˜์‹  ๊ฒƒ์œผ๋กœ ๋ณด์ด๋Š”๋ฐ, private์œผ๋กœ ์ƒ์„ฑ์ž๋ฅผ ๋ง‰๊ณ  ์ •์ ํŒฉํ† ๋ฆฌ๋ฉ”์†Œ๋“œ ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋” ์—„๋ฐ€ํ•˜๊ฒŒ ์บก์Аํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค! ๊ด€๋ จ ์ž๋ฃŒ๋ฅผ ์•„๋ž˜ ๋งํฌ๋กœ ๋‹ฌ์•„๋‘˜๊ฒŒ์š”! https://hudi.blog/effective-java-static-factory-method/
@@ -0,0 +1,91 @@ +package christmas.model.event; + +import christmas.model.event.dto.ReservationDateEventDTO; +import christmas.model.menu.MenuItem; + +import java.util.*; +import java.util.stream.Stream; + +public class EventResult { + private static final int MIN_EVENT_AMOUNT = 10_000; + private static final int GIFT_AMOUNT = 120_000; + + private final Map<MenuItem, Integer> orderMenus; + private final DiscountDetail discountDetail; + private final GiftMenu giftMenu; + private final RewardBadge rewardBadge; + + public EventResult(ReservationDateEventDTO dateEventDTO, Map<MenuItem, Integer> orderMenus) { + this.orderMenus = orderMenus; + this.discountDetail = initDiscountDetail(dateEventDTO); + this.giftMenu = initGiftMenu(); + this.rewardBadge = initRewardBadge(); + } + + private DiscountDetail initDiscountDetail(ReservationDateEventDTO dateEventDTO) { + int totalPriceBeforeDiscount = getTotalPriceBeforeDiscount(); + if (totalPriceBeforeDiscount < MIN_EVENT_AMOUNT) { + return new DiscountDetail(dateEventDTO, totalPriceBeforeDiscount); + } + int weekDiscount = calculateWeekDiscount(dateEventDTO); + + return new DiscountDetail(dateEventDTO, totalPriceBeforeDiscount, weekDiscount); + } + + private GiftMenu initGiftMenu() { + if (discountDetail.getTotalPriceBeforeDiscount() < GIFT_AMOUNT) { + return GiftMenu.NONE; + } + + return GiftMenu.CHAMPAGNE; + } + + private RewardBadge initRewardBadge() { + int benefit = discountDetail.getTotalDiscount() + giftMenu.getGiftPrice(); + + return Arrays.stream(RewardBadge.values()) + .filter(badge -> + benefit >= badge.getBenefit()) + .max(Comparator.comparingInt(RewardBadge::getBenefit)) + .orElse(RewardBadge.NONE); + } + + private int getTotalPriceBeforeDiscount() { + return generateOrderMenuEntry(orderMenus) + .mapToInt(menu -> + menu.getKey().getItemPrice() * menu.getValue()) + .sum(); + } + + private int calculateWeekDiscount(ReservationDateEventDTO dateEventDTO) { + WeekDiscountType type = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + + return generateOrderMenuEntry(orderMenus) + .filter(menu -> + menu.getKey().getMenuCategory() == type.getDiscountCategory()) + .mapToInt(menu -> + menu.getValue() * type.getDiscountPrice()) + .sum(); + } + + private <K, V> Stream<Map.Entry<K, V>> generateOrderMenuEntry(Map<K, V> orderMenus) { + return orderMenus.entrySet() + .stream(); + } + + public Map<MenuItem, Integer> getOrderMenus() { + return Collections.unmodifiableMap(orderMenus); + } + + public DiscountDetail getDiscountDetail() { + return discountDetail; + } + + public GiftMenu getGiftMenu() { + return giftMenu; + } + + public RewardBadge getRewardBadge() { + return rewardBadge; + } +}
Java
ํ•„๋“œ ์ˆ˜๋ฅผ ์ค„์—ฌ ์‘์ง‘๋„๋ฅผ ๋‚ฎ์ถ”๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ฒ„๊ทธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ๋ฆฌํŽ™ํ† ๋งํ• ๋ถ€๋ถ„์ด ๋งŽ์•„์ ธ์š”!!
@@ -0,0 +1,91 @@ +package christmas.model.event; + +import christmas.model.event.dto.ReservationDateEventDTO; +import christmas.model.menu.MenuItem; + +import java.util.*; +import java.util.stream.Stream; + +public class EventResult { + private static final int MIN_EVENT_AMOUNT = 10_000; + private static final int GIFT_AMOUNT = 120_000; + + private final Map<MenuItem, Integer> orderMenus; + private final DiscountDetail discountDetail; + private final GiftMenu giftMenu; + private final RewardBadge rewardBadge; + + public EventResult(ReservationDateEventDTO dateEventDTO, Map<MenuItem, Integer> orderMenus) { + this.orderMenus = orderMenus; + this.discountDetail = initDiscountDetail(dateEventDTO); + this.giftMenu = initGiftMenu(); + this.rewardBadge = initRewardBadge(); + } + + private DiscountDetail initDiscountDetail(ReservationDateEventDTO dateEventDTO) { + int totalPriceBeforeDiscount = getTotalPriceBeforeDiscount(); + if (totalPriceBeforeDiscount < MIN_EVENT_AMOUNT) { + return new DiscountDetail(dateEventDTO, totalPriceBeforeDiscount); + } + int weekDiscount = calculateWeekDiscount(dateEventDTO); + + return new DiscountDetail(dateEventDTO, totalPriceBeforeDiscount, weekDiscount); + } + + private GiftMenu initGiftMenu() { + if (discountDetail.getTotalPriceBeforeDiscount() < GIFT_AMOUNT) { + return GiftMenu.NONE; + } + + return GiftMenu.CHAMPAGNE; + } + + private RewardBadge initRewardBadge() { + int benefit = discountDetail.getTotalDiscount() + giftMenu.getGiftPrice(); + + return Arrays.stream(RewardBadge.values()) + .filter(badge -> + benefit >= badge.getBenefit()) + .max(Comparator.comparingInt(RewardBadge::getBenefit)) + .orElse(RewardBadge.NONE); + } + + private int getTotalPriceBeforeDiscount() { + return generateOrderMenuEntry(orderMenus) + .mapToInt(menu -> + menu.getKey().getItemPrice() * menu.getValue()) + .sum(); + } + + private int calculateWeekDiscount(ReservationDateEventDTO dateEventDTO) { + WeekDiscountType type = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + + return generateOrderMenuEntry(orderMenus) + .filter(menu -> + menu.getKey().getMenuCategory() == type.getDiscountCategory()) + .mapToInt(menu -> + menu.getValue() * type.getDiscountPrice()) + .sum(); + } + + private <K, V> Stream<Map.Entry<K, V>> generateOrderMenuEntry(Map<K, V> orderMenus) { + return orderMenus.entrySet() + .stream(); + } + + public Map<MenuItem, Integer> getOrderMenus() { + return Collections.unmodifiableMap(orderMenus); + } + + public DiscountDetail getDiscountDetail() { + return discountDetail; + } + + public GiftMenu getGiftMenu() { + return giftMenu; + } + + public RewardBadge getRewardBadge() { + return rewardBadge; + } +}
Java
์ด ๋ถ€๋ถ„๋„ getter๋กœ ๊บผ๋‚ด์™€์„œ ๊ฒ€์ฆํ•˜๊ธฐ๋ณด๋‹ค ๊ฐ์ฒด ๋‚ด๋ถ€์—์„œ ์Šค์Šค๋กœ๊ฒ€์ฆํ•˜๋„๋ก ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,28 @@ +package christmas.model.event; + +public enum SpecialDayDiscount { + THIRD_DAY(3, 1000), + TENTH_DAY(10, 1000), + SEVENTEENTH_DAY(17, 1000), + TWENTY_FOURTH_DAY(24, 1000), + TWENTY_FIFTH_DAY(25, 1000), + THIRTY_FIRST_DAY(31, 1000), + OTHER_DAY(0, 0), + ; + + private final int day; + private final int discountPrice; + + SpecialDayDiscount(int day, int discountPrice) { + this.day = day; + this.discountPrice = discountPrice; + } + + public int getDay() { + return day; + } + + public int getDiscountPrice() { + return discountPrice; + } +}
Java
1000์›์ด๋ผ๋Š” ๋™์ผํ•œ ํ• ์ธ๊ธˆ์•ก์„ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋‹ˆ List๋กœ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,55 @@ +package christmas.model.menu; + +import christmas.exception.ExceptionMessage; +import christmas.exception.PromotionException; + +import java.util.Arrays; + +public enum MenuItem { + APPETIZER_MUSHROOM_SOUP("์–‘์†ก์ด์ˆ˜ํ”„", 6_000, MenuCategory.APPETIZER), + APPETIZER_TAPAS("ํƒ€ํŒŒ์Šค", 5_500, MenuCategory.APPETIZER), + APPETIZER_CAESAR_SALAD("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 8_000, MenuCategory.APPETIZER), + + MAIN_T_BONE_STEAK("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 55_000, MenuCategory.MAIN_COURSE), + MAIN_BBQ_RIB("๋ฐ”๋น„ํ๋ฆฝ", 54_000, MenuCategory.MAIN_COURSE), + MAIN_SEAFOOD_PASTA("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 35_000, MenuCategory.MAIN_COURSE), + MAIN_CHRISTMAS_PASTA("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 25_000, MenuCategory.MAIN_COURSE), + + DESSERT_CHOCO_CAKE("์ดˆ์ฝ”์ผ€์ดํฌ", 15_000, MenuCategory.DESSERT), + DESSERT_ICE_CREAM("์•„์ด์Šคํฌ๋ฆผ", 5_000, MenuCategory.DESSERT), + + BEVERAGE_ZERO_COLA("์ œ๋กœ์ฝœ๋ผ", 3_000, MenuCategory.BEVERAGE), + BEVERAGE_RED_WINE("๋ ˆ๋“œ์™€์ธ", 60_000, MenuCategory.BEVERAGE), + BEVERAGE_CHAMPAGNE("์ƒดํŽ˜์ธ", 25_000, MenuCategory.BEVERAGE), + ; + + private final String itemName; + private final int itemPrice; + private final MenuCategory menuCategory; + + MenuItem(String itemName, int itemPrice, MenuCategory menuCategory) { + this.itemName = itemName; + this.itemPrice = itemPrice; + this.menuCategory = menuCategory; + } + + public static MenuItem findMenuItemByName(String itemName, ExceptionMessage message) { + return Arrays.stream(MenuItem.values()) + .filter(menu -> menu.getItemName().equals(itemName)) + .findFirst() + .orElseThrow(() -> + new PromotionException(message)); + } + + public String getItemName() { + return itemName; + } + + public int getItemPrice() { + return itemPrice; + } + + public MenuCategory getMenuCategory() { + return menuCategory; + } +}
Java
MenuCategory, MenuItem์—์„œ ์ค‘๋ณต๋˜๋Š” ์š”์†Œ๋“ค์ด ์žˆ๋Š”๋ฐ ํ•˜๋‚˜๋กœ ๋ฌถ์–ด๋„ ๋  ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,79 @@ +package christmas.model.menu; + +import christmas.exception.ExceptionMessage; +import christmas.exception.PromotionException; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class OrderMenus { + private static final int MIN_ORDER_MENU_NUMBER = 1; + private static final int MAX_ORDER_MENUS_NUMBER = 20; + + private final Map<MenuItem, Integer> orderMenus; + + public OrderMenus(Map<String, Integer> orderMenus) { + this.orderMenus = validateOrderMenusByNames(orderMenus); + validateOrderMenus(); + } + + private Map<MenuItem, Integer> validateOrderMenusByNames(Map<String, Integer> orderMenus) { + return generateOrderMenuValues(orderMenus) + .collect(Collectors.toUnmodifiableMap( + entry -> MenuItem.findMenuItemByName(entry.getKey(), ExceptionMessage.INVALID_INPUT_ORDER), + Map.Entry::getValue + )); + } + + private void validateOrderMenus() { + validateOrderNumbers(); + validateTotalOrderNumbers(); + validateOrderAllBeverage(); + } + + private void validateOrderNumbers() { + generateOrderMenuValues(orderMenus) + .filter(menu -> + menu.getValue() < MIN_ORDER_MENU_NUMBER) + .findAny() + .ifPresent(menuName -> throwInvalidOrderException()); + } + + private void validateTotalOrderNumbers() { + int orderNumber = generateOrderMenuValues(orderMenus) + .mapToInt(Map.Entry::getValue) + .sum(); + + if (orderNumber > MAX_ORDER_MENUS_NUMBER) { + throwInvalidOrderException(); + } + } + + private void validateOrderAllBeverage() { + boolean allBeverage = generateOrderMenuValues(orderMenus) + .allMatch(orderMenu -> + orderMenu.getKey().getMenuCategory() == MenuCategory.BEVERAGE); + + if (allBeverage) { + throwInvalidOrderException(); + } + } + + private <K, V> Stream<Map.Entry<K, V>> generateOrderMenuValues(Map<K, V> orderMenus) { + return orderMenus.entrySet() + .stream(); + } + + private void throwInvalidOrderException() { + throw new PromotionException(ExceptionMessage.INVALID_INPUT_ORDER); + } + + public Map<String, Integer> getOrderMenus() { + Map<String, Integer> menuNames = new HashMap<>(); + orderMenus.forEach((menuItem, quantity) -> + menuNames.put(menuItem.getItemName(), quantity)); + + return Collections.unmodifiableMap(menuNames); + } +}
Java
Integer๋„ ์›์‹œ๊ฐ’์„ ํฌ์žฅํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์š”??
@@ -0,0 +1,76 @@ +package christmas.run; + +import christmas.controller.PromotionController; +import christmas.exception.PromotionException; +import christmas.model.event.dto.EventResultDTO; +import christmas.model.event.dto.ReservationDateEventDTO; +import christmas.model.menu.dto.OrderMenusDTO; +import christmas.view.InputView; +import christmas.view.OutputView; + +import java.util.function.Supplier; + +public class PromotionRun { + private final PromotionController controller = new PromotionController(); + private final InputView inputView; + private final OutputView outputView; + + public PromotionRun(InputView inputView, OutputView outputView) { + this.inputView = inputView; + this.outputView = outputView; + } + + public void runPromotion() { + ReservationDateEventDTO dateEventDto = inputCorrectReservationDate(); + OrderMenusDTO orderMenusDto = inputCorrectOrderMenus(); + displayEventPreview(dateEventDto); + + EventResultDTO responseDto = applyEventsAndGenerateResult(dateEventDto, orderMenusDto); + outputEventResult(responseDto); + } + + private ReservationDateEventDTO inputCorrectReservationDate() { + outputView.displayStartPromotion(); + + return getCorrectResult(this::generateDateEvent); + } + + private OrderMenusDTO inputCorrectOrderMenus() { + return getCorrectResult(this::receiveMenus); + } + + private ReservationDateEventDTO generateDateEvent() { + String inputDate = inputView.inputDate(); + + return controller.generateEvent(inputDate); + } + + private OrderMenusDTO receiveMenus() { + String inputMenus = inputView.inputOrderMenus(); + + return controller.receiveOrderMenus(inputMenus); + } + + private void displayEventPreview(ReservationDateEventDTO dateEventDto) { + outputView.displayPreviewEvent(dateEventDto.getDay()); + } + + private EventResultDTO applyEventsAndGenerateResult(ReservationDateEventDTO dateEventDTO, + OrderMenusDTO orderMenusDto) { + return controller.applyEvents(dateEventDTO, orderMenusDto); + } + + private void outputEventResult(EventResultDTO responseDto) { + outputView.outputEventResult(responseDto); + } + + private <T> T getCorrectResult(Supplier<T> supplier) { + while (true) { + try { + return supplier.get(); + } catch (PromotionException e) { + outputView.displayException(e); + } + } + } +}
Java
ํ•„๋“œ์ฃผ์ž…๋ณด๋‹ค ์ƒ์„ฑ์ž ์ฃผ์ž…์ด ์œ ์ง€๋ณด์ˆ˜ ๊ด€์ ์—์„œ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”.!!
@@ -0,0 +1,76 @@ +package christmas.run; + +import christmas.controller.PromotionController; +import christmas.exception.PromotionException; +import christmas.model.event.dto.EventResultDTO; +import christmas.model.event.dto.ReservationDateEventDTO; +import christmas.model.menu.dto.OrderMenusDTO; +import christmas.view.InputView; +import christmas.view.OutputView; + +import java.util.function.Supplier; + +public class PromotionRun { + private final PromotionController controller = new PromotionController(); + private final InputView inputView; + private final OutputView outputView; + + public PromotionRun(InputView inputView, OutputView outputView) { + this.inputView = inputView; + this.outputView = outputView; + } + + public void runPromotion() { + ReservationDateEventDTO dateEventDto = inputCorrectReservationDate(); + OrderMenusDTO orderMenusDto = inputCorrectOrderMenus(); + displayEventPreview(dateEventDto); + + EventResultDTO responseDto = applyEventsAndGenerateResult(dateEventDto, orderMenusDto); + outputEventResult(responseDto); + } + + private ReservationDateEventDTO inputCorrectReservationDate() { + outputView.displayStartPromotion(); + + return getCorrectResult(this::generateDateEvent); + } + + private OrderMenusDTO inputCorrectOrderMenus() { + return getCorrectResult(this::receiveMenus); + } + + private ReservationDateEventDTO generateDateEvent() { + String inputDate = inputView.inputDate(); + + return controller.generateEvent(inputDate); + } + + private OrderMenusDTO receiveMenus() { + String inputMenus = inputView.inputOrderMenus(); + + return controller.receiveOrderMenus(inputMenus); + } + + private void displayEventPreview(ReservationDateEventDTO dateEventDto) { + outputView.displayPreviewEvent(dateEventDto.getDay()); + } + + private EventResultDTO applyEventsAndGenerateResult(ReservationDateEventDTO dateEventDTO, + OrderMenusDTO orderMenusDto) { + return controller.applyEvents(dateEventDTO, orderMenusDto); + } + + private void outputEventResult(EventResultDTO responseDto) { + outputView.outputEventResult(responseDto); + } + + private <T> T getCorrectResult(Supplier<T> supplier) { + while (true) { + try { + return supplier.get(); + } catch (PromotionException e) { + outputView.displayException(e); + } + } + } +}
Java
์ œ๋„ˆ๋ฆญ์„ ์‚ฌ์šฉํ•˜์‹  ๋ถ€๋ถ„์ด ์ธ์ƒ๊นŠ์Šต๋‹ˆ๋‹ค.!
@@ -0,0 +1,27 @@ +package christmas.util; + +enum EventResultText { + ORDER_OUTPUT_REGEX("%s %d%s"), + EMPTY_TEXT(""), + SPACE(" "), + MENU_NUMBER("๊ฐœ"), + MENU_PRICE_UNIT("์›"), + CHRISTMAS_D_DAY_DISCOUNT("ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ"), + SPECIAL_DISCOUNT("ํŠน๋ณ„ ํ• ์ธ"), + GIFT_EVENT("์ฆ์ • ์ด๋ฒคํŠธ"), + NONE_BENEFIT("์—†์Œ"), + DISCOUNT_PRICE("-"), + BENEFIT_SEPARATOR(": "), + NEW_LINE("\n"), + ; + + private final String text; + + EventResultText(String text) { + this.text = text; + } + + public String getText() { + return text; + } +}
Java
์—ฐ๊ด€์„ฑ์ด ์—†๋Š” ์ƒ์ˆ˜๋“ค์€ static final๋กœ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ๋” ๊ฐ€๋…์„ฑ ์ธก๋ฉด์—์„œ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•ด์š” !
@@ -0,0 +1,99 @@ +## ์šฐ์•„ํ•œ ํ…Œํฌ์ฝ”์Šค ํ”„๋ฆฌ์ฝ”์Šค ํฌ๋ฆฌ์Šค๋งˆ์Šค ํ”„๋กœ๋ชจ์…˜ + +### ์ง„ํ–‰๋ฐฉ์‹ +- ์‹œ์ž‘ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ +- ๋ฐฉ๋ฌธ ๋‚ ์งœ ์ž…๋ ฅ +- ์ฃผ๋ฌธ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ž…๋ ฅ +- ์ž…๋ ฅ ์š”์ผ ์ด๋ฒคํŠธ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ +- ์ด๋ฒคํŠธ ํ˜œํƒ ์ถœ๋ ฅ + - ์ฃผ๋ฌธ ๋ฉ”๋‰ด + - ํ• ์ธ ์ „ ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก + - ์ฆ์ • ๋ฉ”๋‰ด ์—ฌ๋ถ€ + - ํ˜œํƒ ๋‚ด์—ญ ์—ฌ๋ถ€ + - ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก + - 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ์—ฌ๋ถ€ + +### ์ฃผ์š” ๊ตฌํ˜„ ์‚ฌํ•ญ +- [x] ์ž…๋ ฅ ๋ทฐ ๊ตฌํ˜„ +- [x] ์ถœ๋ ฅ ๋ทฐ ๊ตฌํ˜„ + +- [x] ๋‚ ์งœ ์ž…๋ ฅ ๋ฐ ์ €์žฅ ๊ฐ์ฒด ๊ตฌํ˜„ +- [x] ๋‚ ์งœ ์ž…๋ ฅ ์‹œ ๋‚ ์งœ๊ด€๋ จ ํ•ด๋‹น ์ด๋ฒคํŠธ ํ•ญ๋ชฉ ์ €์žฅ + - [x] ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ์ด ๊ธˆ์•ก ํ• ์ธ ํ•ญ๋ชฉ + - [x] ํ‰์ผ/์ฃผ๋ง ๊ตฌ๋ถ„ ํ• ์ธ ํƒ€์ž… ํ•ญ๋ณต + - [x] ๋‚ ์งœ๋‚˜ ๋‹ฌ๋ ฅ์˜ ๋ณ„์— ๋”ฐ๋ผ ์ŠคํŽ˜์…œ ํ• ์ธ ํ•ญ๋ชฉ +- [x] ๋‚ ์งœ ๊ด€๋ จ ์ด๋ฒคํŠธ ๋ฐ˜ํ™˜ DTO ๋ฐ˜ํ™˜ + +- [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ž…๋ ฅ ๋ฐ ์ €์žฅ ๊ฐ์ฒด ๊ตฌํ˜„ + - [x] ๊ฐ ๋ฉ”๋‰ด๋ฅผ ๊ธฐ๋ณธ ๊ธˆ์•ก๊ณผ ๋ฉ”๋‰ด ๋ช…์œผ๋กœ Enum ์œผ๋กœ ๊ด€๋ฆฌ + - [x] ์ฃผ๋ฌธํ•œ ๋ฉ”๋‰ด ์ž…๋ ฅ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์ง„ํ–‰ ํ›„ ์ €์žฅ ๊ฐ์ฒด์— ์ €์žฅ +- [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๋‚ด์—ญ ๋ฐ˜ํ™˜ DTO ๋ฐ˜ํ™˜ + +- [x] ๋‚ ์งœ ์ด๋ฒคํŠธ์™€ ์ฃผ๋ฌธ ๋ฉ”๋‰ด DTO ๋ฅผ ํ†ตํ•œ ์ด๋ฒคํŠธ ํ˜œํƒ ์ ์šฉ +- [x] ์ด๋ฒคํŠธ ์ ์šฉ DTO ๋ฐ˜ํ™˜ ๋ฐ ์ถœ๋ ฅ + - [x] ํ• ์ธ ์ „ ๊ธˆ์•ก์„ ์ถœ๋ ฅ + - [x] ํ• ์ธ ์ „ ๊ธˆ์•ก์— ๋”ฐ๋ฅธ ์ฆ์ • ์—ฌ๋ถ€ ์ถœ๋ ฅ + - ์ฆ์ • ์—ฌ๋ถ€๊ฐ€ ์—†๋‹ค๋ฉด '์—†์Œ' ์ถœ๋ ฅ + - [x] ํ˜œํƒ ๋‚ด์—ญ ์ถœ๋ ฅ + - ์ ์šฉ๋œ ํ˜œํƒ ์—†๋‹ค๋ฉด '์—†์Œ' ์ถœ๋ ฅ + - [x] ํ˜œํƒ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ์ฆ์ • ํ˜œํƒ ๊ธˆ์•ก์„ ์ œ์™ธํ•œ ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ์ด ํ˜œํƒ ๊ธˆ์•ก์— ๋”ฐ๋ฅธ ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ๋ถ€์—ฌ ์—ฌ๋ถ€ ์ถœ๋ ฅ + - ์ด๋ฒคํŠธ ๋ฐฐ์ง€๊ฐ€ ์—†๋‹ค๋ฉด '์—†์Œ' ์ถœ๋ ฅ + +- ์ถ”๊ฐ€ ๊ตฌํ˜„ ์‚ฌํ•ญ + - ์ด๋ฒคํŠธ ๊ฒฐ๊ณผ ๋„๋ฉ”์ธ์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅ ๋ฌธ์ž์—ด์œผ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ Builder DTO ์ƒ์„ฑ/๋ฐ˜ํ™˜ + - ์ž˜๋ชป๋œ ์ž…๋ ฅ์„ ํ†ตํ•œ ๊ณผ์ •์€ ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ ๋ฐ ์žฌ์ž…๋ ฅ + - ์ด ์ฃผ๋ฌธ ๋ฉ”๋‰ด ๊ธˆ์•ก์ด 10,000์› ์ดํ•˜์ผ ๊ฒฝ์šฐ ๋ชจ๋“  ํ• ์ธ ๊ธˆ์•ก 0์œผ๋กœ ์ง€์ • + +### ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- ๋‚ ์งœ ์ž…๋ ฅ ์˜ˆ์™ธ + - [x] ์ž˜๋ชป๋œ ๋‚ ์งœ ์ž…๋ ฅ์˜ ๊ฒฝ์šฐ + - [x] ๋‚ ์งœ๊ฐ€ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ณ€๊ฒฝ์ด ์•ˆ๋  ๋•Œ +- ๋ฉ”๋‰ด ์ž…๋ ฅ ์˜ˆ์™ธ + - [x] ๋ฉ”๋‰ด ์ž…๋ ฅ ์‹œ ์ •๊ทœํ‘œํ˜„์‹ ํŒจํ„ด์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ (TextProcessor ์ฒ˜๋ฆฌ) + - [x] ์ค‘๋ณต ๋ฉ”๋‰ด๋ช… ์ž…๋ ฅ์˜ ๊ฒฝ์šฐ (TextProcessor ์ฒ˜๋ฆฌ) + - [x] ์—†๋Š” ๋ฉ”๋‰ด๋ช… ์ž…๋ ฅ์˜ ๊ฒฝ์šฐ + - [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๊ฐ€ 1๋ณด๋‹ค ์ž‘์„ ๋•Œ + - [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด๊ฐ€ 20๊ฐœ๋ฅผ ๋„˜์„ ๋•Œ + - [x] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธ ์‹œ ์ฃผ๋ฌธ ๋ถˆ๊ฐ€๋Šฅ + +### ํด๋ž˜์Šค ๊ตฌ์กฐ +- InputView : ํ™”๋ฉด ์ž…๋ ฅ์„ ๋‹ด๋‹นํ•˜๋Š” ๋ทฐ + - InputViewMessage : ์ž…๋ ฅ์„ ์œ„ํ•œ ๋ฉ”์‹œ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Enum +- OutputView : ํ™”๋ฉด ์ถœ๋ ฅ์„ ๋‹ด๋‹นํ•˜๋Š” ๋ทฐ + - OutputViewMessage : ์ถœ๋ ฅ์„ ์œ„ํ•œ ๋ฉ”์‹œ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Enum +- PromotionRun : ๋ทฐ์™€ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ํด๋ž˜์Šค๋กœ ์š”์ฒญ ์ „๋‹ฌ +- PromotionController : ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์š”์ฒญ์„ ์ „๋‹ฌํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ +- PromotionService : ํ”„๋กœ๋ชจ์…˜ ์œ ํšจ์„ฑ ๊ฒ€์ฆ์„ ๊ฑฐ์นœ ๊ฐ์ฒด ์ƒ์„ฑ๊ณผ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์‹คํ–‰ํ•  ์„œ๋น„์Šค +- TextProcessor : ์ž…๋ ฅ๋ฐ›์€ ๋ฌธ์ž์—ด์„ ํŠน์ • ํƒ€์ž…์œผ๋กœ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ์œ„ํ•œ ์„œ๋น„์Šค +- OrderMenus : ์ฃผ๋ฌธ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ €์žฅํ•˜๋Š” ํด๋ž˜์Šค + - MenuItem : ๋ฉ”๋‰ด ์ด๋ฆ„๊ณผ ๊ฐ€๊ฒฉ, ๋ฉ”๋‰ด ์ข…๋ฅ˜๋ฅผ ์ €์žฅํ•˜๋Š” Enum + - MenuCategory : ๋ฉ”๋‰ด ์ข…๋ฅ˜๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” Enum +- ReservationDateEvent : ๋‚ ์งœ ๊ด€๋ จ ์ด๋ฒคํŠธ ์ €์žฅ ํด๋ž˜์Šค + - ReservationDate : ์ž…๋ ฅ๋œ ๋‚ ์งœ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ํด๋ž˜์Šค + - ChristmasDiscount : ํฌ๋ฆฌ์Šค๋งˆ์Šค D-day ํ• ์ธ ๊ด€๋ฆฌ ํด๋ž˜์Šค + - WeekDiscountType : ์ฃผ๋ง ํ• ์ธ, ํ‰์ผ ํ• ์ธ์„ ๊ตฌ๋ถ„ํ•˜๋Š” Enum + - SpecialDayDiscount : ํŠน๋ณ„ ํ• ์ธ ์ผ์ž๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” Enum +- EventResult : ์ ์šฉ ์ค‘์ธ ๋ชจ๋“  ์ด๋ฒคํŠธ๋ฅผ ์ €์žฅํ•˜๋Š” ํด๋ž˜์Šค + - DiscountDetail : ์ฃผ๋ฌธ ๊ธˆ์•ก๊ณผ ํ• ์ธ, ์˜ˆ์ƒ ๊ธˆ์•ก ๋“ฑ์„ ๋ณด๊ด€ํ•œ ํด๋ž˜์Šค + - GiftEvent : ์ฆ์ • ์ƒํ’ˆ ์—ฌ๋ถ€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Enum + - RewardBadge : ์ด๋ฒคํŠธ ๋ฐฐ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” Enum +- PromotionException : ์ง€์ •๋œ Enum ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋ฅผ ํ†ตํ•ด ๊ฐ’๋ฅผ ๋‹ด์•„ IllegalArgumentException ์ƒ์„ฑ + - ExceptionMessage : ์˜ˆ์™ธ ๋ฐœ์ƒ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๊ด€ํ•œ Enum Class +- PromotionConverter : Service ์—์„œ Domain to DTO ์ปจ๋ฒ„ํ„ฐ +- EventResultTextFactory : EventResultDTO ๋ฐ˜ํ™˜์„ ์œ„ํ•œ ๋ฌธ์ž์—ด ์กฐ์ž‘ ์„œ๋น„์Šค + - EventResultText : EventResultDTO ์— ํ•„์š”ํ•œ ๋ฌธ์ž์—ด Enum +- ํ…Œ์ŠคํŠธ : ํด๋ž˜์Šค๋ณ„ ๋ฉ”์†Œ๋“œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ง„ํ–‰ + +### ์ด๋ฒˆ์— ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ณ ๋ฏผํ•œ ์š”์†Œ +- ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ๊ตฌ์กฐ ์„ค๊ณ„ + - ์ดํ›„ ํ•„์š”ํ•œ ํด๋ž˜์Šค๋“ค์„ ์ถ”๊ฐ€ํ•˜๋ฉฐ ์„ค๊ณ„ ๋ณ€๊ฒฝ +- ๋™์ผํ•œ ์ž…๋ ฅ๊ณผ ์ถœ๋ ฅ์„ ํ•˜๋Š” ๋ทฐ๋Š” ์‹ฑ๊ธ€ํ†ค์œผ๋กœ ๊ตฌํ˜„ +- ์ž…๋ ฅ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์™€ ๊ฐ์ฒด ์ƒ์„ฑ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๊ตฌ๋ถ„์— ๋Œ€ํ•œ ๊ณ ๋ฏผ +- ์ด๋ฒคํŠธ ์ ์šฉ ์‹œ ์ด๋ฒคํŠธ ๋‚ด์—ญ๊ณผ ์ฃผ๋ฌธ ๋‚ด์—ญ์„ ์‚ฌ์šฉํ•ด ๊ฐ’์„ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•์„ Service ์—์„œ ์ง„ํ–‰ํ• ์ง€ ๊ฐ์ฒด ๋‚ด๋ถ€์—์„œ ์ง„ํ–‰ํ• ์ง€ ๊ณ ๋ฏผ +- ์ถœ๋ ฅ์„ ์œ„ํ•œ DTO ์ƒ์„ฑ์— ๋Œ€ํ•œ ๊ณ ๋ฏผ + - DTO ๋ฃฐ ์ถœ๋ ฅํ•˜๊ณ  ํ•ด๋‹น DTO ํ†ตํ•ด ๋‹ค์‹œ ์ด๋ฒคํŠธ ๋‚ด์—ญ ํ™•์ธํ•˜๋Š”๋ฐ ์žˆ์–ด DTO ๊ฐ’์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• + - EventResultDTO ๋ทฐ์— ์ถœ๋ ฅํ•  ๋ฌธ์ž์—ด์„ ๊ฐ€์ง€๊ณ  ์žˆ์„ DTO ์ƒ์„ฑ ๋ฐฉ๋ฒ• ๊ณ ๋ฏผ ํ›„ Builder, EventResultTextFactory ์‚ฌ์šฉ +- ์ž˜๋ชป๋œ ์ž…๋ ฅ์— ๋Œ€ํ•œ ๋ฉ”์„œ๋“œ ์žฌ์‹คํ–‰ ๋กœ์ง์€ ์ง€๋‚œ์ฃผ [zangsu๋‹˜](https://github.com/zangsu) ์ฝ”๋“œ๋ฆฌ๋ทฐ๋กœ ๋ฐฐ์šด Supplier ๋ฐ˜๋ณต ์‚ฌ์šฉ +- ํ…Œ์ŠคํŠธ ์ฝ”๋“œ mock ๊ฐ์ฒด์— ๋Œ€ํ•œ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ๊ณ ๋ฏผ \ No newline at end of file
Unknown
์•„ ์ข‹์€ ์ƒ๊ฐ์ด๋„ค์š”. ์ดํ›„ ๊ด€๋ฆฌ์—๋Š” ์ƒ๊ฐํ•˜์ง€ ์•Š์•˜๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -1,7 +1,20 @@ package christmas; + +import camp.nextstep.edu.missionutils.Console; +import christmas.run.PromotionRun; +import christmas.view.InputView; +import christmas.view.OutputView; + public class Application { public static void main(String[] args) { - // TODO: ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ + try { + InputView inputView = SingletonView.getInputView(); + OutputView outputView = SingletonView.getOutputView(); + PromotionRun promotionRun = new PromotionRun(inputView, outputView); + promotionRun.runPromotion(); + } finally { + Console.close(); + } } }
Java
ํ•œ๋ฒˆ๋งŒ ์ƒ์„ฑ๋˜๋ฉด ๋˜๊ณ  ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ํ•„์š”๊ฐ€ ์—†๊ฒ ๋‹ค ์‹ถ์–ด ์ ์šฉํ–ˆ๋Š”๋ฐ ์ปจํŠธ๋กค๋Ÿฌ, ์„œ๋น„์Šค ๋ชจ๋‘ ์ ์šฉํ•ด์•ผํ•˜๋‚˜ ์‹ถ๋‹ค๊ฐ€ ๋ทฐ๋งŒ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค..
@@ -0,0 +1,20 @@ +package christmas.exception; + +public enum ExceptionMessage { + INVALID_INPUT_DATE("์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + INVALID_INPUT_ORDER("์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + INVALID_MENU_ITEM("ํ•ด๋‹น ๋ฉ”๋‰ด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."), + INVALID_WEEK_DISCOUNT_TYPE("์ž˜๋ชป๋œ ์ฃผ๊ฐ„ ํ• ์ธ ํƒ€์ž…์ž…๋‹ˆ๋‹ค."), + ; + + private static final String PREFIX = "[ERROR] "; + private final String errorMessage; + + ExceptionMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorMessage() { + return PREFIX + errorMessage; + } +}
Java
์•„ ํ•ด๋‹น ์˜ˆ์™ธ๋Š” ์ด๋ฏธ ์ฒ˜๋ฆฌ๋œ ๊ฒฐ๊ณผ DTO ๋“ค์„ ๊ฐ€์ง€๊ณ  ๋ฐœ์ƒ๋˜๋Š” ์˜ˆ์™ธ๋ผ์„œ ์ •์ƒ์ ์ด๋ผ๋ฉด ํ„ฐ์ง€์ง€ ์•Š๋Š” ์˜ˆ์™ธ ์ž…๋‹ˆ๋‹ค. ์ผ๋‹จ ์ œ ์ƒ๊ฐ์œผ๋กœ๋Š” ๋ฌด์Šจ ์ง“์„ ํ•ด๋„ ์ž…๋ ฅ์— ๋Œ€ํ•ด ํ•ด๋‹น ์˜ˆ์™ธ๋Š” ํ„ฐ์ง€์ง€๋Š” ์•Š์„ ๊ฑฐ๋ผ ์ƒ๊ฐํ•˜๋Š”๋ฐ ํ•ด๋‹น ๊ธฐ๋Šฅ์—์„œ๋งŒ ํ„ฐ์ง€๋Š” ์˜ˆ์™ธ๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,33 @@ +package christmas.model.event; + +import christmas.model.date.ReservationDate; + +public class ChristmasDiscount { + private static final int FIRST_DAY = 1; + private static final int CHRISTMAS_DAY = 25; + private static final int BASIC_DISCOUNT = 1000; + private static final int PLUS_DISCOUNT = 100; + private static final int NONE_DISCOUNT = 0; + + private final int discount; + + public ChristmasDiscount(ReservationDate date) { + this.discount = initDiscountAmount(date); + } + + private int initDiscountAmount(ReservationDate date) { + if (date.day() > CHRISTMAS_DAY) { + return NONE_DISCOUNT; + } + + return BASIC_DISCOUNT + getPlusDiscount(date.day()); + } + + private int getPlusDiscount(int day) { + return (day - FIRST_DAY) * PLUS_DISCOUNT; + } + + public int getDiscount() { + return discount; + } +}
Java
์˜ˆ์•ฝ ์ผ์ž ๊ฐ์ฒด๋Š” ์˜ˆ์•ฝ๋œ ์ผ์ž์— ๋Œ€ํ•ด์„œ๋งŒ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด ํ• ์ธ์„ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ํ•ด๋‹น ํ• ์ธ ๊ฐ์ฒด๊ฐ€ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ๋„ฃ์—ˆ๋Š”๋ฐ ๊ณ ๋ฏผ์ด ๋˜๋„ค์š”..
@@ -0,0 +1,62 @@ +package christmas.model.event; + +import christmas.model.event.dto.ReservationDateEventDTO; + +public class DiscountDetail { + private final int totalPriceBeforeDiscount; + private final int totalPriceAfterDiscount; + private final WeekDiscountType weekDiscountType; + private final int christmasDiscount; + private final int weekTypeDiscount; + private final int specialDiscount; + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount, int weekTypeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = dateEventDTO.getChristmasDiscount(); + this.specialDiscount = dateEventDTO.getSpecialDiscount(); + this.weekTypeDiscount = weekTypeDiscount; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = 0; + this.specialDiscount = 0; + this.weekTypeDiscount = 0; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + private int initTotalPriceAfterDiscount() { + return totalPriceBeforeDiscount - getTotalDiscount(); + } + + public int getTotalPriceBeforeDiscount() { + return totalPriceBeforeDiscount; + } + + public int getTotalPriceAfterDiscount() { + return totalPriceAfterDiscount; + } + + public int getChristmasDiscount() { + return christmasDiscount; + } + + public int getSpecialDiscount() { + return specialDiscount; + } + + public int getWeekTypeDiscount() { + return weekTypeDiscount; + } + + public WeekDiscountType getWeekDiscountType() { + return weekDiscountType; + } + + public int getTotalDiscount() { + return christmasDiscount + weekTypeDiscount + specialDiscount; + } +}
Java
๊ฐ์ฒด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ƒํƒœ์˜ ๊ฐ์ฒด๋ฅผ ํ‘œํ˜„ํ•˜๋ ค ํ•˜๋‹ค๋ณด๋‹ˆ ์ด๋ ‡๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ ์•„์ง๋„ ๋ฉ”์„œ๋“œ๋กœ ๋ฉ”์‹œ์ง€๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„์ง ๋‚ฏ์„  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.. ์ค‘๊ฐ„์ค‘๊ฐ„ ์ธ์ง€ํ•˜๋ คํ•ด๋„ ๋†“์น˜๋Š” ๋ถ€๋ถ„์ด ๋งŽ๋„ค์š”..
@@ -0,0 +1,62 @@ +package christmas.model.event; + +import christmas.model.event.dto.ReservationDateEventDTO; + +public class DiscountDetail { + private final int totalPriceBeforeDiscount; + private final int totalPriceAfterDiscount; + private final WeekDiscountType weekDiscountType; + private final int christmasDiscount; + private final int weekTypeDiscount; + private final int specialDiscount; + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount, int weekTypeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = dateEventDTO.getChristmasDiscount(); + this.specialDiscount = dateEventDTO.getSpecialDiscount(); + this.weekTypeDiscount = weekTypeDiscount; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = 0; + this.specialDiscount = 0; + this.weekTypeDiscount = 0; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + private int initTotalPriceAfterDiscount() { + return totalPriceBeforeDiscount - getTotalDiscount(); + } + + public int getTotalPriceBeforeDiscount() { + return totalPriceBeforeDiscount; + } + + public int getTotalPriceAfterDiscount() { + return totalPriceAfterDiscount; + } + + public int getChristmasDiscount() { + return christmasDiscount; + } + + public int getSpecialDiscount() { + return specialDiscount; + } + + public int getWeekTypeDiscount() { + return weekTypeDiscount; + } + + public WeekDiscountType getWeekDiscountType() { + return weekDiscountType; + } + + public int getTotalDiscount() { + return christmasDiscount + weekTypeDiscount + specialDiscount; + } +}
Java
์—ฌ๋Ÿฌ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  static์œผ๋กœ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•๋ณด๋‹ค๋Š” ์ €๋Š” ๊ฐœ์ธ์ ์œผ๋กœ ํ•ด๋‹น ๊ธฐ๋Šฅ์€ ํ• ์ธ์ด ์—†์„ ๊ฒฝ์šฐ์˜ ๊ฐ์ฒด๋ฅผ ์˜ค๋ฒ„๋กœ๋”ฉ์„ ํ†ตํ•ด ์ƒ์„ฑํ•˜๋Š”๊ฒŒ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค
@@ -0,0 +1,91 @@ +package christmas.model.event; + +import christmas.model.event.dto.ReservationDateEventDTO; +import christmas.model.menu.MenuItem; + +import java.util.*; +import java.util.stream.Stream; + +public class EventResult { + private static final int MIN_EVENT_AMOUNT = 10_000; + private static final int GIFT_AMOUNT = 120_000; + + private final Map<MenuItem, Integer> orderMenus; + private final DiscountDetail discountDetail; + private final GiftMenu giftMenu; + private final RewardBadge rewardBadge; + + public EventResult(ReservationDateEventDTO dateEventDTO, Map<MenuItem, Integer> orderMenus) { + this.orderMenus = orderMenus; + this.discountDetail = initDiscountDetail(dateEventDTO); + this.giftMenu = initGiftMenu(); + this.rewardBadge = initRewardBadge(); + } + + private DiscountDetail initDiscountDetail(ReservationDateEventDTO dateEventDTO) { + int totalPriceBeforeDiscount = getTotalPriceBeforeDiscount(); + if (totalPriceBeforeDiscount < MIN_EVENT_AMOUNT) { + return new DiscountDetail(dateEventDTO, totalPriceBeforeDiscount); + } + int weekDiscount = calculateWeekDiscount(dateEventDTO); + + return new DiscountDetail(dateEventDTO, totalPriceBeforeDiscount, weekDiscount); + } + + private GiftMenu initGiftMenu() { + if (discountDetail.getTotalPriceBeforeDiscount() < GIFT_AMOUNT) { + return GiftMenu.NONE; + } + + return GiftMenu.CHAMPAGNE; + } + + private RewardBadge initRewardBadge() { + int benefit = discountDetail.getTotalDiscount() + giftMenu.getGiftPrice(); + + return Arrays.stream(RewardBadge.values()) + .filter(badge -> + benefit >= badge.getBenefit()) + .max(Comparator.comparingInt(RewardBadge::getBenefit)) + .orElse(RewardBadge.NONE); + } + + private int getTotalPriceBeforeDiscount() { + return generateOrderMenuEntry(orderMenus) + .mapToInt(menu -> + menu.getKey().getItemPrice() * menu.getValue()) + .sum(); + } + + private int calculateWeekDiscount(ReservationDateEventDTO dateEventDTO) { + WeekDiscountType type = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + + return generateOrderMenuEntry(orderMenus) + .filter(menu -> + menu.getKey().getMenuCategory() == type.getDiscountCategory()) + .mapToInt(menu -> + menu.getValue() * type.getDiscountPrice()) + .sum(); + } + + private <K, V> Stream<Map.Entry<K, V>> generateOrderMenuEntry(Map<K, V> orderMenus) { + return orderMenus.entrySet() + .stream(); + } + + public Map<MenuItem, Integer> getOrderMenus() { + return Collections.unmodifiableMap(orderMenus); + } + + public DiscountDetail getDiscountDetail() { + return discountDetail; + } + + public GiftMenu getGiftMenu() { + return giftMenu; + } + + public RewardBadge getRewardBadge() { + return rewardBadge; + } +}
Java
๊ทธ ๋ถ€๋ถ„์€ @Dongwoongkim ๋‹˜์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ํ™•์‹คํžˆ ๊ทธ๋ ‡๋‹ค๊ณ  ๋А๊ปด์กŒ๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ๊ฐ์ฒด ์•ˆ์— ์žˆ์–ด์•ผํ•œ๋‹ค๊ณ  ๋ฐ”๋ผ๋ณด๋‹ˆ ๊ทธ๋ ‡๊ฒŒ ์ƒ๊ฐ์„ ๋ชปํ–ˆ๋˜ ๊ฒƒ ๊ฐ™์•„์š”.. EventResult๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์ €๋„ ๋” ์˜ฌ๋ฐ”๋ฅธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,28 @@ +package christmas.model.event; + +public enum SpecialDayDiscount { + THIRD_DAY(3, 1000), + TENTH_DAY(10, 1000), + SEVENTEENTH_DAY(17, 1000), + TWENTY_FOURTH_DAY(24, 1000), + TWENTY_FIFTH_DAY(25, 1000), + THIRTY_FIRST_DAY(31, 1000), + OTHER_DAY(0, 0), + ; + + private final int day; + private final int discountPrice; + + SpecialDayDiscount(int day, int discountPrice) { + this.day = day; + this.discountPrice = discountPrice; + } + + public int getDay() { + return day; + } + + public int getDiscountPrice() { + return discountPrice; + } +}
Java
์ข‹์€ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค! enum์— ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ๋„ฃ์„ ์ƒ๊ฐ์„ ๋ชปํ–ˆ๋˜ ๊ฒƒ ๊ฐ™์•„์š”
@@ -0,0 +1,79 @@ +package christmas.model.menu; + +import christmas.exception.ExceptionMessage; +import christmas.exception.PromotionException; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class OrderMenus { + private static final int MIN_ORDER_MENU_NUMBER = 1; + private static final int MAX_ORDER_MENUS_NUMBER = 20; + + private final Map<MenuItem, Integer> orderMenus; + + public OrderMenus(Map<String, Integer> orderMenus) { + this.orderMenus = validateOrderMenusByNames(orderMenus); + validateOrderMenus(); + } + + private Map<MenuItem, Integer> validateOrderMenusByNames(Map<String, Integer> orderMenus) { + return generateOrderMenuValues(orderMenus) + .collect(Collectors.toUnmodifiableMap( + entry -> MenuItem.findMenuItemByName(entry.getKey(), ExceptionMessage.INVALID_INPUT_ORDER), + Map.Entry::getValue + )); + } + + private void validateOrderMenus() { + validateOrderNumbers(); + validateTotalOrderNumbers(); + validateOrderAllBeverage(); + } + + private void validateOrderNumbers() { + generateOrderMenuValues(orderMenus) + .filter(menu -> + menu.getValue() < MIN_ORDER_MENU_NUMBER) + .findAny() + .ifPresent(menuName -> throwInvalidOrderException()); + } + + private void validateTotalOrderNumbers() { + int orderNumber = generateOrderMenuValues(orderMenus) + .mapToInt(Map.Entry::getValue) + .sum(); + + if (orderNumber > MAX_ORDER_MENUS_NUMBER) { + throwInvalidOrderException(); + } + } + + private void validateOrderAllBeverage() { + boolean allBeverage = generateOrderMenuValues(orderMenus) + .allMatch(orderMenu -> + orderMenu.getKey().getMenuCategory() == MenuCategory.BEVERAGE); + + if (allBeverage) { + throwInvalidOrderException(); + } + } + + private <K, V> Stream<Map.Entry<K, V>> generateOrderMenuValues(Map<K, V> orderMenus) { + return orderMenus.entrySet() + .stream(); + } + + private void throwInvalidOrderException() { + throw new PromotionException(ExceptionMessage.INVALID_INPUT_ORDER); + } + + public Map<String, Integer> getOrderMenus() { + Map<String, Integer> menuNames = new HashMap<>(); + orderMenus.forEach((menuItem, quantity) -> + menuNames.put(menuItem.getItemName(), quantity)); + + return Collections.unmodifiableMap(menuNames); + } +}
Java
๊ฐœ์ˆ˜๋งŒ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฐ์ฒด๋‹ค ๋ณด๋‹ˆ ํด๋ž˜์Šค๊ฐ€ ๋งŽ์•„์ ธ ๋ฌด๊ฑฐ์›Œ์งˆ ๊ฒƒ ๊ฐ™์•„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ ๋ญ๊ฐ€ ๋” ๋‚˜์€์ง€๋Š” ๊ณ ๋ฏผ์ด ๋˜๋„ค์š”..
@@ -0,0 +1,76 @@ +package christmas.run; + +import christmas.controller.PromotionController; +import christmas.exception.PromotionException; +import christmas.model.event.dto.EventResultDTO; +import christmas.model.event.dto.ReservationDateEventDTO; +import christmas.model.menu.dto.OrderMenusDTO; +import christmas.view.InputView; +import christmas.view.OutputView; + +import java.util.function.Supplier; + +public class PromotionRun { + private final PromotionController controller = new PromotionController(); + private final InputView inputView; + private final OutputView outputView; + + public PromotionRun(InputView inputView, OutputView outputView) { + this.inputView = inputView; + this.outputView = outputView; + } + + public void runPromotion() { + ReservationDateEventDTO dateEventDto = inputCorrectReservationDate(); + OrderMenusDTO orderMenusDto = inputCorrectOrderMenus(); + displayEventPreview(dateEventDto); + + EventResultDTO responseDto = applyEventsAndGenerateResult(dateEventDto, orderMenusDto); + outputEventResult(responseDto); + } + + private ReservationDateEventDTO inputCorrectReservationDate() { + outputView.displayStartPromotion(); + + return getCorrectResult(this::generateDateEvent); + } + + private OrderMenusDTO inputCorrectOrderMenus() { + return getCorrectResult(this::receiveMenus); + } + + private ReservationDateEventDTO generateDateEvent() { + String inputDate = inputView.inputDate(); + + return controller.generateEvent(inputDate); + } + + private OrderMenusDTO receiveMenus() { + String inputMenus = inputView.inputOrderMenus(); + + return controller.receiveOrderMenus(inputMenus); + } + + private void displayEventPreview(ReservationDateEventDTO dateEventDto) { + outputView.displayPreviewEvent(dateEventDto.getDay()); + } + + private EventResultDTO applyEventsAndGenerateResult(ReservationDateEventDTO dateEventDTO, + OrderMenusDTO orderMenusDto) { + return controller.applyEvents(dateEventDTO, orderMenusDto); + } + + private void outputEventResult(EventResultDTO responseDto) { + outputView.outputEventResult(responseDto); + } + + private <T> T getCorrectResult(Supplier<T> supplier) { + while (true) { + try { + return supplier.get(); + } catch (PromotionException e) { + outputView.displayException(e); + } + } + } +}
Java
ํ•ด๋‹น ๋ถ€๋ถ„์€ ์ €๋„ ์ด์ „ ์ฝ”๋“œ๋ฆฌ๋ทฐ๋ฅผ ํ†ตํ•ด ๋ฐฐ์šด ๊ตฌํ˜„ ๋ฐฉ๋ฒ•์ธ๋ฐ ์ข‹์€ ๋ฐฉ๋ฒ•์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,27 @@ +package christmas.util; + +enum EventResultText { + ORDER_OUTPUT_REGEX("%s %d%s"), + EMPTY_TEXT(""), + SPACE(" "), + MENU_NUMBER("๊ฐœ"), + MENU_PRICE_UNIT("์›"), + CHRISTMAS_D_DAY_DISCOUNT("ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ"), + SPECIAL_DISCOUNT("ํŠน๋ณ„ ํ• ์ธ"), + GIFT_EVENT("์ฆ์ • ์ด๋ฒคํŠธ"), + NONE_BENEFIT("์—†์Œ"), + DISCOUNT_PRICE("-"), + BENEFIT_SEPARATOR(": "), + NEW_LINE("\n"), + ; + + private final String text; + + EventResultText(String text) { + this.text = text; + } + + public String getText() { + return text; + } +}
Java
๊ฒฐ๊ณผ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•ด์ฃผ๊ธฐ ์œ„ํ•œ ์ƒ์ˆ˜๋“ค์„ ๋ฌถ์–ด ๋‘” Enum ์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๊ณณ์—์„œ ์‚ฌ์šฉ๋˜์ง€๋Š” ์•Š์„ ๊ฒƒ ๊ฐ™์•„ default๋กœ enum์„ ์‚ฌ์šฉํ–ˆ์–ด์š”
@@ -0,0 +1,62 @@ +package christmas.model.event; + +import christmas.model.event.dto.ReservationDateEventDTO; + +public class DiscountDetail { + private final int totalPriceBeforeDiscount; + private final int totalPriceAfterDiscount; + private final WeekDiscountType weekDiscountType; + private final int christmasDiscount; + private final int weekTypeDiscount; + private final int specialDiscount; + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount, int weekTypeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = dateEventDTO.getChristmasDiscount(); + this.specialDiscount = dateEventDTO.getSpecialDiscount(); + this.weekTypeDiscount = weekTypeDiscount; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + protected DiscountDetail(ReservationDateEventDTO dateEventDTO, int totalPriceBeforeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + this.weekDiscountType = WeekDiscountType.checkWeekType(dateEventDTO.getDateWeek()); + this.christmasDiscount = 0; + this.specialDiscount = 0; + this.weekTypeDiscount = 0; + this.totalPriceAfterDiscount = initTotalPriceAfterDiscount(); + } + + private int initTotalPriceAfterDiscount() { + return totalPriceBeforeDiscount - getTotalDiscount(); + } + + public int getTotalPriceBeforeDiscount() { + return totalPriceBeforeDiscount; + } + + public int getTotalPriceAfterDiscount() { + return totalPriceAfterDiscount; + } + + public int getChristmasDiscount() { + return christmasDiscount; + } + + public int getSpecialDiscount() { + return specialDiscount; + } + + public int getWeekTypeDiscount() { + return weekTypeDiscount; + } + + public WeekDiscountType getWeekDiscountType() { + return weekDiscountType; + } + + public int getTotalDiscount() { + return christmasDiscount + weekTypeDiscount + specialDiscount; + } +}
Java
ํ•„๋“œ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๊ฒŒ ์—ฌ๋Ÿฌ๋ฒˆ ํ˜ธ์ถœ ๋  ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ๋งŒ ๊ฐ€์ง€๊ณ  ์˜ค๋Š” ๊ฒƒ์ด ์ข‹๋‹ค ์ƒ๊ฐํ•ด์„œ ํ•ด๋‹น ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ๋ช‡๋ช‡ ํ•„๋“œ๋Š” ๋ฉ”์„œ๋“œ๋กœ ํ•ด๋‹น ํ•„๋“œ๋งŒ์„ ๊ฐ€์ง€๊ณ  ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š”
@@ -0,0 +1,105 @@ +package christmas.model.event.dto; + +public class EventResultDTO { + private final String orderMenus; + private final String totalPriceBeforeDiscount; + private final String giftMenu; + private final String benefitHistory; + private final String totalBenefit; + private final String totalPriceAfterDiscount; + private final String rewardBadge; + + private EventResultDTO(Builder builder) { + this.orderMenus = builder.orderMenus; + this.totalPriceBeforeDiscount = builder.totalPriceBeforeDiscount; + this.giftMenu = builder.giftMenu; + this.benefitHistory = builder.benefitHistory; + this.totalBenefit = builder.totalBenefit; + this.totalPriceAfterDiscount = builder.totalPriceAfterDiscount; + this.rewardBadge = builder.rewardBadge; + } + + public static class Builder { + private String orderMenus; + private String totalPriceBeforeDiscount; + private String giftMenu; + private String benefitHistory; + private String totalBenefit; + private String totalPriceAfterDiscount; + private String rewardBadge; + + public Builder() { + } + + public Builder orderMenus(String orderMenus) { + this.orderMenus = orderMenus; + return this; + } + + public Builder totalPriceBeforeDiscount(String totalPriceBeforeDiscount) { + this.totalPriceBeforeDiscount = totalPriceBeforeDiscount; + return this; + } + + public Builder giftMenu(String giftMenu) { + this.giftMenu = giftMenu; + return this; + } + + public Builder benefitHistory(String benefitHistory) { + this.benefitHistory = benefitHistory; + return this; + } + + public Builder totalBenefit(String totalBenefit) { + this.totalBenefit = totalBenefit; + return this; + } + + public Builder totalPriceAfterDiscount(String totalPriceAfterDiscount) { + this.totalPriceAfterDiscount = totalPriceAfterDiscount; + return this; + } + + public Builder rewardBadge(String rewardBadge) { + this.rewardBadge = rewardBadge; + return this; + } + + public EventResultDTO build() { + return new EventResultDTO(this); + } + } + + public static Builder builder() { + return new Builder(); + } + + public String getOrderMenus() { + return orderMenus; + } + + public String getTotalPriceBeforeDiscount() { + return totalPriceBeforeDiscount; + } + + public String getGiftMenu() { + return giftMenu; + } + + public String getBenefitHistory() { + return benefitHistory; + } + + public String getTotalBenefit() { + return totalBenefit; + } + + public String getTotalPriceAfterDiscount() { + return totalPriceAfterDiscount; + } + + public String getRewardBadge() { + return rewardBadge; + } +}
Java
๋นŒ๋” ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๋ฉด null ์ธ ๊ฐ’์ด ์˜ฌ ์ˆ˜ ๋„ ์žˆ์„ํ…๋ฐ ์ „๋ถ€ ๋‹ค ํ•„์š”ํ•ด์ด๋Š” ๋ณ€์ˆ˜๋“ค์ธ๋ฐ ์ƒ์„ฑ์ž๋ฅผ ์ด์šฉํ•˜์ง€ ์•Š๊ณ  ๋นŒ๋”ํด๋ž˜์Šค๋ฅผ ํ™œ์šฉํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,55 @@ +package christmas.model.menu; + +import christmas.exception.ExceptionMessage; +import christmas.exception.PromotionException; + +import java.util.Arrays; + +public enum MenuItem { + APPETIZER_MUSHROOM_SOUP("์–‘์†ก์ด์ˆ˜ํ”„", 6_000, MenuCategory.APPETIZER), + APPETIZER_TAPAS("ํƒ€ํŒŒ์Šค", 5_500, MenuCategory.APPETIZER), + APPETIZER_CAESAR_SALAD("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 8_000, MenuCategory.APPETIZER), + + MAIN_T_BONE_STEAK("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 55_000, MenuCategory.MAIN_COURSE), + MAIN_BBQ_RIB("๋ฐ”๋น„ํ๋ฆฝ", 54_000, MenuCategory.MAIN_COURSE), + MAIN_SEAFOOD_PASTA("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 35_000, MenuCategory.MAIN_COURSE), + MAIN_CHRISTMAS_PASTA("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 25_000, MenuCategory.MAIN_COURSE), + + DESSERT_CHOCO_CAKE("์ดˆ์ฝ”์ผ€์ดํฌ", 15_000, MenuCategory.DESSERT), + DESSERT_ICE_CREAM("์•„์ด์Šคํฌ๋ฆผ", 5_000, MenuCategory.DESSERT), + + BEVERAGE_ZERO_COLA("์ œ๋กœ์ฝœ๋ผ", 3_000, MenuCategory.BEVERAGE), + BEVERAGE_RED_WINE("๋ ˆ๋“œ์™€์ธ", 60_000, MenuCategory.BEVERAGE), + BEVERAGE_CHAMPAGNE("์ƒดํŽ˜์ธ", 25_000, MenuCategory.BEVERAGE), + ; + + private final String itemName; + private final int itemPrice; + private final MenuCategory menuCategory; + + MenuItem(String itemName, int itemPrice, MenuCategory menuCategory) { + this.itemName = itemName; + this.itemPrice = itemPrice; + this.menuCategory = menuCategory; + } + + public static MenuItem findMenuItemByName(String itemName, ExceptionMessage message) { + return Arrays.stream(MenuItem.values()) + .filter(menu -> menu.getItemName().equals(itemName)) + .findFirst() + .orElseThrow(() -> + new PromotionException(message)); + } + + public String getItemName() { + return itemName; + } + + public int getItemPrice() { + return itemPrice; + } + + public MenuCategory getMenuCategory() { + return menuCategory; + } +}
Java
๋ฉ”๋‰ด ์•„์ดํ…œ CRUD API ๋ฅผ ๋งŒ๋“ค๋•Œ enum ์œผ๋กœ ํ•˜๊ฒŒ ๋˜๋ฉด ์ถ”๊ฐ€์— ๋Œ€ํ•ด ํ™•์žฅ์„ฑ์ด ๋–จ์–ด์ง€๋Š”๊ฒƒ์ด ์•„๋‹Œ๊ฐ€ ์ƒ๊ฐ์ด๋“ญ๋‹ˆ๋‹ค!
@@ -0,0 +1,57 @@ +package christmas.model.event; + +import christmas.model.date.ReservationDate; + +import java.util.Arrays; + +public class ReservationDateEvent { + private static final int WEEK = 7; + private static final int FRIDAY = 2; + private static final int SATURDAY = 3; + + private final ReservationDate reservationDate; + private final ChristmasDiscount christmasDiscount; + private final WeekDiscountType discountDateWeek; + private final SpecialDayDiscount specialDiscountDate; + + public ReservationDateEvent(int day) { + this.reservationDate = new ReservationDate(day); + this.christmasDiscount = new ChristmasDiscount(reservationDate); + this.discountDateWeek = initDiscountDateWeek(reservationDate); + this.specialDiscountDate = initSpecialDiscountDate(reservationDate); + } + + private WeekDiscountType initDiscountDateWeek(ReservationDate reservationDate) { + if (reservationDate.day() % WEEK == FRIDAY || + reservationDate.day() % WEEK == SATURDAY) { + + return WeekDiscountType.WEEKEND; + } + + return WeekDiscountType.WEEKDAY; + } + + private SpecialDayDiscount initSpecialDiscountDate(ReservationDate reservationDate) { + return Arrays.stream(SpecialDayDiscount.values()) + .filter(specialDay -> + reservationDate.day() == specialDay.getDay()) + .findFirst() + .orElse(SpecialDayDiscount.OTHER_DAY); + } + + public ReservationDate getReservationDate() { + return reservationDate; + } + + public ChristmasDiscount getChristmasDiscount() { + return christmasDiscount; + } + + public WeekDiscountType getDiscountDateWeek() { + return discountDateWeek; + } + + public SpecialDayDiscount getSpecialDiscountDate() { + return specialDiscountDate; + } +}
Java
์ด๋ ‡๊ฒŒ ๋˜๋ฉด ์ด๋ฒคํŠธ๊ฐ€ ์ˆ˜๋ฐฑ๊ฐœ๊ฐ€ ๋˜๋ฉด ์ˆ˜๋ฐฑ๊ฐœ๋ฅผ ์ง์ ‘ ๋‹ค ๊ตฌํ˜„ํ•ด์ค˜์•ผ ๋˜์„œ ๋น„ํšจ์œจ์  ์ธ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ๋ชจ๋‘ ํ• ์ธ์„ ์ ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ˆ inteface Discount ๋ฅผ ๋งŒ๋“ค์–ด ``` Discount ๋ฅผ ๊ตฌํ˜„ํ•œ ReservationDate implements Discount ChristmasDiscount implements Discount ........ ``` ์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด์„œ List<DIscount> discountList ์ด๋Ÿฐ์‹์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ๊ณตํ†ตํ•จ์ˆ˜ ๋ถ€๋ถ„๋งŒ ๋กœ์ง์— ๋„ฃ์–ด์ฃผ์‹œ๋ฉด ๊ด€๋ฆฌ๊ฐ€ ์‰ฌ์šธ๊ฒƒ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,58 @@ +package christmas.domain; + +import java.time.DayOfWeek; +import java.time.LocalDate; + +public class Date { + public static final String DATE_RE_READ_REQUEST_MESSAGE = "์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; + private static final LocalDate CHRISTMAS_DAY = LocalDate.of(2023, 12, 25); + private static final int YEAR = 2023; + private static final int MONTH = 12; + private static final int DATE_MIN_NUMBER = 1; + private static final int DATE_MAX_NUMBER = 31; + + private final int dayNumber; + + public Date(int dayNumber) { + validateRange(dayNumber); + this.dayNumber = dayNumber; + } + + private void validateRange(int dayNumber) { + if ((dayNumber < DATE_MIN_NUMBER) || (dayNumber > DATE_MAX_NUMBER)) { + throw new IllegalArgumentException(DATE_RE_READ_REQUEST_MESSAGE); + } + } + + public boolean isDDayDiscountActive() { + LocalDate localDate = LocalDate.of(YEAR, MONTH, dayNumber); + + return localDate.isBefore(CHRISTMAS_DAY.plusDays(1)); + } + + public boolean isWeekdayDiscountActive() { + LocalDate localDate = LocalDate.of(YEAR, MONTH, dayNumber); + DayOfWeek day = localDate.getDayOfWeek(); + + return (day.equals(DayOfWeek.MONDAY) || day.equals(DayOfWeek.TUESDAY) || day.equals(DayOfWeek.WEDNESDAY) + || day.equals(DayOfWeek.THURSDAY) || day.equals(DayOfWeek.SUNDAY)); + } + + public boolean isWeekendDiscountActive() { + LocalDate localDate = LocalDate.of(YEAR, MONTH, dayNumber); + DayOfWeek day = localDate.getDayOfWeek(); + + return (day.equals(DayOfWeek.FRIDAY) || day.equals(DayOfWeek.SATURDAY)); + } + + public boolean isSpecialDiscountActive() { + LocalDate localDate = LocalDate.of(YEAR, MONTH, dayNumber); + DayOfWeek day = localDate.getDayOfWeek(); + + return (day.equals(DayOfWeek.SUNDAY) || localDate.equals(CHRISTMAS_DAY)); + } + + public int getDayNumber() { + return dayNumber; + } +} \ No newline at end of file
Java
(์ด๋Ÿฐ ๋ฐฉ๋ฒ•๋„ ์žˆ์–ด์š”!) ```suggestion try { LocalDate.of(YEAR, MONTH, dayNumber); } catch (NumberFormatException exception) { throw new IllegalArgumentException(DATE_RE_READ_REQUEST_MESSAGE); } ``` ์ด๋Ÿฐ์‹์œผ๋กœ LocalDate๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,100 @@ +package christmas.domain; + +import java.util.HashMap; +import java.util.Map; + +public class EventProcess { + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT = 120000; + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT = 10000; + private static final int D_DAY_DISCOUNT_AMOUNT_PER_DAY = 100; + private static final int D_DAY_DISCOUNT_DEFAULT_AMOUNT = 1000; + private static final int FIRST_DAY_NUMBER = 1; + private static final int WEEKDAY_DESSERT_DISCOUNT_AMOUNT = 2023; + private static final int WEEKEND_MAIN_DISCOUNT_AMOUNT = 2023; + private static final int SPECIAL_DISCOUNT_AMOUNT = 1000; + + public EventResult takeAllBenefit(Date date, Order order) { + Map<BenefitType, Integer> allBenefit = new HashMap<>(); + allBenefit.put(BenefitType.GIFT, takeGift(order)); + allBenefit.put(BenefitType.D_DAY, takeDDayDiscount(date)); + allBenefit.put(BenefitType.WEEKDAY, takeWeekdayDiscount(date, order)); + allBenefit.put(BenefitType.WEEKEND, takeWeekendDiscount(date, order)); + allBenefit.put(BenefitType.SPECIAL, takeSpecialDiscount(date)); + + cancelAllBenefitIfMeetCondition(order, allBenefit); + + return new EventResult(allBenefit); + } + + private int takeGift(Order order) { + if (order.calculateTotalOrderPrice() >= MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT) { + return Menu.CHAMPAGNE.getPrice(); + } + + return 0; + } + + private int takeDDayDiscount(Date date) { + if (date.isDDayDiscountActive()) { + return D_DAY_DISCOUNT_DEFAULT_AMOUNT + + (calculateDifferenceBetweenFirstDay(date) * D_DAY_DISCOUNT_AMOUNT_PER_DAY); + } + + return 0; + } + + private int calculateDifferenceBetweenFirstDay(Date date) { + return date.getDayNumber() - FIRST_DAY_NUMBER; + } + + private int takeWeekdayDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekdayDiscountActive() && MenuType.decideMenuType(menu) == MenuType.DESSERT) { + discount += orderedMenu.getQuantity() * WEEKDAY_DESSERT_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeWeekendDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekendDiscountActive() && MenuType.decideMenuType(menu) == MenuType.MAIN) { + discount += orderedMenu.getQuantity() * WEEKEND_MAIN_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeSpecialDiscount(Date date) { + if (date.isSpecialDiscountActive()) { + return SPECIAL_DISCOUNT_AMOUNT; + } + + return 0; + } + + private Map<BenefitType, Integer> cancelAllBenefitIfMeetCondition(Order order, + Map<BenefitType, Integer> allBenefit) { + if (isInsufficientTotalOrderPriceForEvent(order)) { + allBenefit.replace(BenefitType.GIFT, 0); + allBenefit.replace(BenefitType.D_DAY, 0); + allBenefit.replace(BenefitType.WEEKDAY, 0); + allBenefit.replace(BenefitType.WEEKEND, 0); + allBenefit.replace(BenefitType.SPECIAL, 0); + } + + return allBenefit; + } + + private boolean isInsufficientTotalOrderPriceForEvent(Order order) { + return order.calculateTotalOrderPrice() < MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT; + } +} \ No newline at end of file
Java
(๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค!) ํ• ์ธ์„ ์ ์šฉํ•˜๊ณ  ์กฐ๊ฑด์— ๋งž์ง€ ์•Š์œผ๋ฉด ๋˜๋Œ๋ฆฌ๋Š” ๋ฐฉ๋ฒ•๋ณด๋‹ค๋Š” ์ฒ˜์Œ๋ถ€ํ„ฐ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜์ง€ ์•Š์œผ๋ฉด ํ• ์ธ์„ ์ ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ๋„ ํ•˜๋‚˜์˜ ๋ฐฉ๋ฒ•์ผ ๊ฒƒ ๊ฐ™์•„์š”! ```suggestion if (this.isInsufficientTotalOrderPriceForEvent(order)) { return EnumSet.allOf(BenefitType.class) .stream() .collect(collectingAndThen( toMap(Function.identity(), (benefit) -> 0), EventResult::new) ); } ``` ์œ„ ์ฝ”๋“œ์—์„œ stream์„ ํ™œ์šฉํ–ˆ๋Š”๋ฐ BenefitType์˜ ๋ชจ๋“  ์›์†Œ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค์Œ 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•˜๊ณ  ๋‚˜์˜จ ๊ฒฐ๊ณผ๋ฌผ์„ EventResult๋กœ ๋ž˜ํ•‘ํ•˜๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค :)
@@ -0,0 +1,100 @@ +package christmas.domain; + +import java.util.HashMap; +import java.util.Map; + +public class EventProcess { + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT = 120000; + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT = 10000; + private static final int D_DAY_DISCOUNT_AMOUNT_PER_DAY = 100; + private static final int D_DAY_DISCOUNT_DEFAULT_AMOUNT = 1000; + private static final int FIRST_DAY_NUMBER = 1; + private static final int WEEKDAY_DESSERT_DISCOUNT_AMOUNT = 2023; + private static final int WEEKEND_MAIN_DISCOUNT_AMOUNT = 2023; + private static final int SPECIAL_DISCOUNT_AMOUNT = 1000; + + public EventResult takeAllBenefit(Date date, Order order) { + Map<BenefitType, Integer> allBenefit = new HashMap<>(); + allBenefit.put(BenefitType.GIFT, takeGift(order)); + allBenefit.put(BenefitType.D_DAY, takeDDayDiscount(date)); + allBenefit.put(BenefitType.WEEKDAY, takeWeekdayDiscount(date, order)); + allBenefit.put(BenefitType.WEEKEND, takeWeekendDiscount(date, order)); + allBenefit.put(BenefitType.SPECIAL, takeSpecialDiscount(date)); + + cancelAllBenefitIfMeetCondition(order, allBenefit); + + return new EventResult(allBenefit); + } + + private int takeGift(Order order) { + if (order.calculateTotalOrderPrice() >= MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT) { + return Menu.CHAMPAGNE.getPrice(); + } + + return 0; + } + + private int takeDDayDiscount(Date date) { + if (date.isDDayDiscountActive()) { + return D_DAY_DISCOUNT_DEFAULT_AMOUNT + + (calculateDifferenceBetweenFirstDay(date) * D_DAY_DISCOUNT_AMOUNT_PER_DAY); + } + + return 0; + } + + private int calculateDifferenceBetweenFirstDay(Date date) { + return date.getDayNumber() - FIRST_DAY_NUMBER; + } + + private int takeWeekdayDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekdayDiscountActive() && MenuType.decideMenuType(menu) == MenuType.DESSERT) { + discount += orderedMenu.getQuantity() * WEEKDAY_DESSERT_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeWeekendDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekendDiscountActive() && MenuType.decideMenuType(menu) == MenuType.MAIN) { + discount += orderedMenu.getQuantity() * WEEKEND_MAIN_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeSpecialDiscount(Date date) { + if (date.isSpecialDiscountActive()) { + return SPECIAL_DISCOUNT_AMOUNT; + } + + return 0; + } + + private Map<BenefitType, Integer> cancelAllBenefitIfMeetCondition(Order order, + Map<BenefitType, Integer> allBenefit) { + if (isInsufficientTotalOrderPriceForEvent(order)) { + allBenefit.replace(BenefitType.GIFT, 0); + allBenefit.replace(BenefitType.D_DAY, 0); + allBenefit.replace(BenefitType.WEEKDAY, 0); + allBenefit.replace(BenefitType.WEEKEND, 0); + allBenefit.replace(BenefitType.SPECIAL, 0); + } + + return allBenefit; + } + + private boolean isInsufficientTotalOrderPriceForEvent(Order order) { + return order.calculateTotalOrderPrice() < MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT; + } +} \ No newline at end of file
Java
(๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค!) ```suggestion return new EventResult(new HashMap<>() {{ this.put(BenefitType.GIFT, takeGift(order)); this.put(BenefitType.D_DAY, takeDDayDiscount(date)); this.put(BenefitType.WEEKDAY, takeWeekdayDiscount(date, order)); this.put(BenefitType.WEEKEND, takeWeekendDiscount(date, order)); this.put(BenefitType.SPECIAL, takeSpecialDiscount(date)); }}); ``` ์ด๋Ÿฐ์‹์œผ๋กœ ์ƒ์„ฑ๊ณผ ๋™์‹œ์— HashMap์˜ ์›์†Œ๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์–ด์š” :)
@@ -0,0 +1,100 @@ +package christmas.domain; + +import java.util.HashMap; +import java.util.Map; + +public class EventProcess { + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT = 120000; + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT = 10000; + private static final int D_DAY_DISCOUNT_AMOUNT_PER_DAY = 100; + private static final int D_DAY_DISCOUNT_DEFAULT_AMOUNT = 1000; + private static final int FIRST_DAY_NUMBER = 1; + private static final int WEEKDAY_DESSERT_DISCOUNT_AMOUNT = 2023; + private static final int WEEKEND_MAIN_DISCOUNT_AMOUNT = 2023; + private static final int SPECIAL_DISCOUNT_AMOUNT = 1000; + + public EventResult takeAllBenefit(Date date, Order order) { + Map<BenefitType, Integer> allBenefit = new HashMap<>(); + allBenefit.put(BenefitType.GIFT, takeGift(order)); + allBenefit.put(BenefitType.D_DAY, takeDDayDiscount(date)); + allBenefit.put(BenefitType.WEEKDAY, takeWeekdayDiscount(date, order)); + allBenefit.put(BenefitType.WEEKEND, takeWeekendDiscount(date, order)); + allBenefit.put(BenefitType.SPECIAL, takeSpecialDiscount(date)); + + cancelAllBenefitIfMeetCondition(order, allBenefit); + + return new EventResult(allBenefit); + } + + private int takeGift(Order order) { + if (order.calculateTotalOrderPrice() >= MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT) { + return Menu.CHAMPAGNE.getPrice(); + } + + return 0; + } + + private int takeDDayDiscount(Date date) { + if (date.isDDayDiscountActive()) { + return D_DAY_DISCOUNT_DEFAULT_AMOUNT + + (calculateDifferenceBetweenFirstDay(date) * D_DAY_DISCOUNT_AMOUNT_PER_DAY); + } + + return 0; + } + + private int calculateDifferenceBetweenFirstDay(Date date) { + return date.getDayNumber() - FIRST_DAY_NUMBER; + } + + private int takeWeekdayDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekdayDiscountActive() && MenuType.decideMenuType(menu) == MenuType.DESSERT) { + discount += orderedMenu.getQuantity() * WEEKDAY_DESSERT_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeWeekendDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekendDiscountActive() && MenuType.decideMenuType(menu) == MenuType.MAIN) { + discount += orderedMenu.getQuantity() * WEEKEND_MAIN_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeSpecialDiscount(Date date) { + if (date.isSpecialDiscountActive()) { + return SPECIAL_DISCOUNT_AMOUNT; + } + + return 0; + } + + private Map<BenefitType, Integer> cancelAllBenefitIfMeetCondition(Order order, + Map<BenefitType, Integer> allBenefit) { + if (isInsufficientTotalOrderPriceForEvent(order)) { + allBenefit.replace(BenefitType.GIFT, 0); + allBenefit.replace(BenefitType.D_DAY, 0); + allBenefit.replace(BenefitType.WEEKDAY, 0); + allBenefit.replace(BenefitType.WEEKEND, 0); + allBenefit.replace(BenefitType.SPECIAL, 0); + } + + return allBenefit; + } + + private boolean isInsufficientTotalOrderPriceForEvent(Order order) { + return order.calculateTotalOrderPrice() < MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT; + } +} \ No newline at end of file
Java
(๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค!) ํ• ์ธ ๊ธˆ์•ก์„ ๊ณ„์‚ฐํ•˜๊ธฐ ์ „์— ์ฃผ๋ง์ด๋ฉด 0์›์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์•„์š”! ```suggestion if (date.isWeekendDiscountActive()) { return 0; } return order.getOrder() .stream() .filter(orderedMenu -> DESSERT.equals(MenuType.decideMenuType(Menu.decideMenu(orderedMenu.getMenuName())))) .mapToInt(orderMenu -> orderMenu.getQuantity() * WEEKDAY_DESSERT_DISCOUNT_AMOUNT) .sum(); ```
@@ -0,0 +1,85 @@ +package christmas.domain; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class EventResult { + private static final String NON_BADGE = "์—†์Œ"; + private static final String STAR_BADGE = "๋ณ„"; + private static final String TREE_BADGE = "ํŠธ๋ฆฌ"; + private static final String SANTA_BADGE = "์‚ฐํƒ€"; + private static final int STAR_BADGE_MINIMUM_AMOUNT = 5000; + private static final int STAR_BADGE_MAXIMUM_AMOUNT = 10000; + private static final int TREE_BADGE_MINIMUM_AMOUNT = 10000; + private static final int TREE_BADGE_MAXIMUM_AMOUNT = 20000; + private static final int SANTA_BADGE_MINIMUM_AMOUNT = 20000; + + private final Map<BenefitType, Integer> allBenefit; + + public EventResult(Map<BenefitType, Integer> allBenefit) { + this.allBenefit = allBenefit; + } + + public int calculateTotalBenefitAmount() { + int totalBenefitAmount = 0; + List<BenefitType> benefitTypes = List.of(BenefitType.values()); + + for (BenefitType benefitType : benefitTypes) { + totalBenefitAmount += allBenefit.get(benefitType); + } + + return totalBenefitAmount; + } + + public int calculateTotalDiscountAmount() { + int totalDiscountAmount = 0; + List<BenefitType> benefitTypes = List.of(BenefitType.values()); + + for (BenefitType benefitType : benefitTypes) { + totalDiscountAmount += allBenefit.get(benefitType); + } + if (allBenefit.get(BenefitType.GIFT) == Menu.CHAMPAGNE.getPrice()) { + totalDiscountAmount -= Menu.CHAMPAGNE.getPrice(); + } + + return totalDiscountAmount; + } + + public boolean isReceivedGiftBenefit() { + return allBenefit.get(BenefitType.GIFT) == Menu.CHAMPAGNE.getPrice(); + } + + public List<BenefitType> checkWhichBenefitExist() { + List<BenefitType> existingBenefit = new ArrayList<>(); + BenefitType[] benefitTypes = BenefitType.values(); + + for (BenefitType benefitType : benefitTypes) { + if (allBenefit.get(benefitType) != 0) { + existingBenefit.add(benefitType); + } + } + + return existingBenefit; + } + + public String decideEventBadge() { + int totalBenefitAmount = calculateTotalBenefitAmount(); + + if ((totalBenefitAmount >= STAR_BADGE_MINIMUM_AMOUNT) && (totalBenefitAmount < STAR_BADGE_MAXIMUM_AMOUNT)) { + return STAR_BADGE; + } + if ((totalBenefitAmount >= TREE_BADGE_MINIMUM_AMOUNT) && (totalBenefitAmount < TREE_BADGE_MAXIMUM_AMOUNT)) { + return TREE_BADGE; + } + if ((totalBenefitAmount >= SANTA_BADGE_MINIMUM_AMOUNT)) { + return SANTA_BADGE; + } + return NON_BADGE; + } + + public Map<BenefitType, Integer> getAllBenefit() { + return Collections.unmodifiableMap(allBenefit); + } +} \ No newline at end of file
Java
(์ถ”์ฒœ๋“œ๋ ค์š”!) EventResult์˜ badge๊ด€๋ จ ์ฝ”๋“œ๋Š” enum์œผ๋กœ ๋ถ„๋ฆฌํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,52 @@ +package christmas.ui; + +import static christmas.domain.Date.DATE_RE_READ_REQUEST_MESSAGE; +import static christmas.domain.OrderedMenu.ORDER_RE_READ_REQUEST_MESSAGE; + +import java.util.ArrayList; +import java.util.List; + +public class Converter { + private static final String ORDER_DELIMITER = ","; + private static final String NAME_AND_AMOUNT_DELIMITER = "-"; + + public static int convertDateNumeric(String Input) { + try { + return Integer.parseInt(Input); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(DATE_RE_READ_REQUEST_MESSAGE); + } + } + + public static List<String> separateOrder(String order) { + return new ArrayList<>(List.of(order.split(ORDER_DELIMITER))); + } + + public static List<String> separateNameAndAmount(String orderedMenu) { + validateAppropriateDelimiter(orderedMenu); + List<String> separatedNameAndAmount = new ArrayList<>(List.of(orderedMenu.split(NAME_AND_AMOUNT_DELIMITER))); + validateAppropriateForm(separatedNameAndAmount); + + return separatedNameAndAmount; + } + + private static void validateAppropriateDelimiter(String orderedMenu) { + if (!orderedMenu.contains(NAME_AND_AMOUNT_DELIMITER)) { + throw new IllegalArgumentException(ORDER_RE_READ_REQUEST_MESSAGE); + } + } + + private static void validateAppropriateForm(List<String> separatedNameAndAmount) { + if (separatedNameAndAmount.size() != 2) { + throw new IllegalArgumentException(ORDER_RE_READ_REQUEST_MESSAGE); + } + } + + public static int convertAmountNumeric(String input) { + try { + return Integer.parseInt(input); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(ORDER_RE_READ_REQUEST_MESSAGE); + } + } +} \ No newline at end of file
Java
(์ด๋ ‡๊ฒŒ๋„ ๊ฐ€๋Šฅํ•ด์š”!) ArrayList๋กœ ๋‹ค์‹œ ๊ฐ์‹ธ์ง€ ์•Š์•„๋„ ์ถฉ๋ถ„ํ•  ๊ฒƒ ๊ฐ™์•„์š” :) ```suggestion return List.of(order.split(ORDER_DELIMITER)); ```
@@ -0,0 +1,63 @@ +package christmas.ui; + +import camp.nextstep.edu.missionutils.Console; +import christmas.domain.Date; +import christmas.domain.Order; +import christmas.domain.OrderedMenu; +import java.util.ArrayList; +import java.util.List; + +public class InputView { + private static final String OPENING_MESSAGE = "์•ˆ๋…•ํ•˜์„ธ์š”! ์šฐํ…Œ์ฝ” ์‹๋‹น 12์›” ์ด๋ฒคํŠธ ํ”Œ๋ž˜๋„ˆ์ž…๋‹ˆ๋‹ค."; + private static final String DATE_REQUEST_MESSAGE = "12์›” ์ค‘ ์‹๋‹น ์˜ˆ์ƒ ๋ฐฉ๋ฌธ ๋‚ ์งœ๋Š” ์–ธ์ œ์ธ๊ฐ€์š”? (์ˆซ์ž๋งŒ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”!)"; + private static final String ORDER_REQUEST_MESSAGE + = "์ฃผ๋ฌธํ•˜์‹ค ๋ฉ”๋‰ด๋ฅผ ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜๋ฅผ ์•Œ๋ ค ์ฃผ์„ธ์š”. (e.g. ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€-2,๋ ˆ๋“œ์™€์ธ-1,์ดˆ์ฝ”์ผ€์ดํฌ-1)"; + + public static void notifyProgramStarted() { + System.out.println(OPENING_MESSAGE); + } + + public static Date inputDate() { + try { + return readDate(); + } catch (IllegalArgumentException e) { + OutputView.printErrorMessage(e); + return inputDate(); + } + } + + private static Date readDate() { + System.out.println(DATE_REQUEST_MESSAGE); + + String input = Console.readLine(); + int dayNumber = Converter.convertDateNumeric(input); + + return new Date(dayNumber); + } + + public static Order inputOrder() { + try { + return new Order(readOrder()); + } catch (IllegalArgumentException e) { + OutputView.printErrorMessage(e); + return inputOrder(); + } + } + + private static List<OrderedMenu> readOrder() { + System.out.println(ORDER_REQUEST_MESSAGE); + + String input = Console.readLine(); + List<String> separatedOrder = Converter.separateOrder(input); + List<OrderedMenu> order = new ArrayList<>(); + + for (String orderedMenu : separatedOrder) { + List<String> separatedNameAndAmount = Converter.separateNameAndAmount(orderedMenu); + String name = separatedNameAndAmount.get(0); + int amount = Converter.convertAmountNumeric(separatedNameAndAmount.get(1)); + order.add(new OrderedMenu(name, amount)); + } + + return order; + } +} \ No newline at end of file
Java
(์ด๋ ‡๊ฒŒ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์–ด์š”!) ```suggestion private static List<OrderedMenu> readOrder() { System.out.println(ORDER_REQUEST_MESSAGE); String input = Console.readLine(); List<String> separatedOrder = Converter.separateOrder(input); return separatedOrder.stream() .map(InputView::convertNameToOrderedMenu) .toList(); } private static OrderedMenu convertNameToOrderedMenu(String orderMenu) { List<String> separatedNameAndAmount = Converter.separateNameAndAmount(orderMenu); String name = separatedNameAndAmount.get(0); int amount = Converter.convertAmountNumeric(separatedNameAndAmount.get(1)); return new OrderedMenu(name, amount); } ```
@@ -0,0 +1,60 @@ +package christmas.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class EventProcessTest { + @DisplayName("์ด๋ฒคํŠธ์— ์ถฉ๋ถ„ํ•œ ์ „์ฒด ์ฃผ๋ฌธ ๊ธˆ์•ก์œผ๋กœ ์ „์ฒด ํ˜œํƒ ๋„์ถœ") + @Test + void takeAllBenefitWithSufficientTotalOrderPrice() { + Date dateInput = new Date(3); + Order orderInput = new Order(setUpSufficientTotalOrderPriceOrder()); + EventProcess eventProcess = new EventProcess(); + EventResult eventResult = eventProcess.takeAllBenefit(dateInput, orderInput); + Map<BenefitType, Integer> result = eventResult.getAllBenefit(); + + assertThat(result.get(BenefitType.GIFT)).isEqualTo(25000); + assertThat(result.get(BenefitType.D_DAY)).isEqualTo(1200); + assertThat(result.get(BenefitType.WEEKDAY)).isEqualTo(2023); + assertThat(result.get(BenefitType.WEEKEND)).isEqualTo(0); + assertThat(result.get(BenefitType.SPECIAL)).isEqualTo(1000); + } + + private List<OrderedMenu> setUpSufficientTotalOrderPriceOrder() { + List<OrderedMenu> orderedMenus = new ArrayList<>(); + orderedMenus.add(new OrderedMenu("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 2)); + orderedMenus.add(new OrderedMenu("๋ ˆ๋“œ์™€์ธ", 1)); + orderedMenus.add(new OrderedMenu("์ดˆ์ฝ”์ผ€์ดํฌ", 1)); + + return orderedMenus; + } + + @DisplayName("์ด๋ฒคํŠธ์— ์ถฉ๋ถ„ํ•˜์ง€ ์•Š์€ ์ „์ฒด ์ฃผ๋ฌธ ๊ธˆ์•ก์œผ๋กœ ์ „์ฒด ํ˜œํƒ ๋„์ถœ") + @Test + void takeAllBenefitWithInSufficientTotalOrderPrice() { + Date dateInput = new Date(26); + Order orderInput = new Order(setUpInSufficientTotalOrderPriceOrder()); + EventProcess eventProcess = new EventProcess(); + EventResult eventResult = eventProcess.takeAllBenefit(dateInput, orderInput); + Map<BenefitType, Integer> result = eventResult.getAllBenefit(); + + assertThat(result.get(BenefitType.GIFT)).isEqualTo(0); + assertThat(result.get(BenefitType.D_DAY)).isEqualTo(0); + assertThat(result.get(BenefitType.WEEKDAY)).isEqualTo(0); + assertThat(result.get(BenefitType.WEEKEND)).isEqualTo(0); + assertThat(result.get(BenefitType.SPECIAL)).isEqualTo(0); + } + + private List<OrderedMenu> setUpInSufficientTotalOrderPriceOrder() { + List<OrderedMenu> orderedMenus = new ArrayList<>(); + orderedMenus.add(new OrderedMenu("ํƒ€ํŒŒ์Šค", 1)); + orderedMenus.add(new OrderedMenu("์ œ๋กœ์ฝœ๋ผ", 1)); + + return orderedMenus; + } +} \ No newline at end of file
Java
(์ถ”์ฒœ๋“œ๋ ค์š”) assertThat๋งŒ ์‚ฌ์šฉํ•˜๋ฉด 21๋ฒˆ์งธ ์ค„์—์„œ ์‹คํŒจํ–ˆ์„ ๋•Œ ๋ฐ‘์— 22~25๋ฒˆ ๋ผ์ธ๊นŒ์ง€ ๊ฒ€์ฆํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค! ๋ฐ˜๋ฉด assertAll์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ชจ๋“  assertThat์„ ์‹คํ–‰์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ๋ฌด์—‡์ด ์‹คํŒจํ–ˆ๋Š”์ง€ ํ™•์‹คํ•˜๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค! ```suggestion assertAll( () -> assertThat(result.get(BenefitType.GIFT)).isEqualTo(25000), () -> assertThat(result.get(BenefitType.D_DAY)).isEqualTo(1200), () -> assertThat(result.get(BenefitType.WEEKDAY)).isEqualTo(2023), () -> assertThat(result.get(BenefitType.WEEKEND)).isEqualTo(0), () -> assertThat(result.get(BenefitType.SPECIAL)).isEqualTo(1000) ); ```
@@ -0,0 +1,23 @@ +package christmas.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class MenuTest { + @DisplayName("์ฃผ์–ด์ง„ ์ด๋ฆ„์„ ํ† ๋Œ€๋กœ ๋ฉ”๋‰ด๋ฅผ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค.") + @Test + void decideMenu() { + String inputTapas = "ํƒ€ํŒŒ์Šค"; + String inputSeafoodPasta = "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€"; + String inputRedWine = "๋ ˆ๋“œ์™€์ธ"; + Menu inputTapasResult = Menu.decideMenu(inputTapas); + Menu inputSeafoodPastaResult = Menu.decideMenu(inputSeafoodPasta); + Menu inputRedWineResult = Menu.decideMenu(inputRedWine); + + assertThat(inputTapasResult).isEqualTo(Menu.TAPAS); + assertThat(inputSeafoodPastaResult).isEqualTo(Menu.SEAFOOD_PASTA); + assertThat(inputRedWineResult).isEqualTo(Menu.RED_WINE); + } +} \ No newline at end of file
Java
(๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค!) ํ…Œ์ŠคํŠธ์ฝ”๋“œ๋ฅผ ๋‘˜๋Ÿฌ๋ณด๋‹ˆ ๋Œ€๋ถ€๋ถ„ ํ•ดํ”ผ์ผ€์ด์Šค๋งŒ ์žˆ๋”๋ผ๊ตฌ์š”! ์‹คํŒจ์— ๋Œ€ํ•œ ๊ฒ€์ฆ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋„ ์—ฐ์Šตํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,58 @@ +package christmas.domain; + +import java.time.DayOfWeek; +import java.time.LocalDate; + +public class Date { + public static final String DATE_RE_READ_REQUEST_MESSAGE = "์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; + private static final LocalDate CHRISTMAS_DAY = LocalDate.of(2023, 12, 25); + private static final int YEAR = 2023; + private static final int MONTH = 12; + private static final int DATE_MIN_NUMBER = 1; + private static final int DATE_MAX_NUMBER = 31; + + private final int dayNumber; + + public Date(int dayNumber) { + validateRange(dayNumber); + this.dayNumber = dayNumber; + } + + private void validateRange(int dayNumber) { + if ((dayNumber < DATE_MIN_NUMBER) || (dayNumber > DATE_MAX_NUMBER)) { + throw new IllegalArgumentException(DATE_RE_READ_REQUEST_MESSAGE); + } + } + + public boolean isDDayDiscountActive() { + LocalDate localDate = LocalDate.of(YEAR, MONTH, dayNumber); + + return localDate.isBefore(CHRISTMAS_DAY.plusDays(1)); + } + + public boolean isWeekdayDiscountActive() { + LocalDate localDate = LocalDate.of(YEAR, MONTH, dayNumber); + DayOfWeek day = localDate.getDayOfWeek(); + + return (day.equals(DayOfWeek.MONDAY) || day.equals(DayOfWeek.TUESDAY) || day.equals(DayOfWeek.WEDNESDAY) + || day.equals(DayOfWeek.THURSDAY) || day.equals(DayOfWeek.SUNDAY)); + } + + public boolean isWeekendDiscountActive() { + LocalDate localDate = LocalDate.of(YEAR, MONTH, dayNumber); + DayOfWeek day = localDate.getDayOfWeek(); + + return (day.equals(DayOfWeek.FRIDAY) || day.equals(DayOfWeek.SATURDAY)); + } + + public boolean isSpecialDiscountActive() { + LocalDate localDate = LocalDate.of(YEAR, MONTH, dayNumber); + DayOfWeek day = localDate.getDayOfWeek(); + + return (day.equals(DayOfWeek.SUNDAY) || localDate.equals(CHRISTMAS_DAY)); + } + + public int getDayNumber() { + return dayNumber; + } +} \ No newline at end of file
Java
์˜ค,, ์ด๋ฒˆ์— LocalDate๋ฅผ ์ฒ˜์Œ ์‚ฌ์šฉํ•ด๋ด์„œ ์ต์ˆ™ํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ์š” ์ด๋Ÿฐ ๋ฐฉ๋ฒ•๋„ ์žˆ์—ˆ๊ตฐ์š”,, ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,100 @@ +package christmas.domain; + +import java.util.HashMap; +import java.util.Map; + +public class EventProcess { + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT = 120000; + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT = 10000; + private static final int D_DAY_DISCOUNT_AMOUNT_PER_DAY = 100; + private static final int D_DAY_DISCOUNT_DEFAULT_AMOUNT = 1000; + private static final int FIRST_DAY_NUMBER = 1; + private static final int WEEKDAY_DESSERT_DISCOUNT_AMOUNT = 2023; + private static final int WEEKEND_MAIN_DISCOUNT_AMOUNT = 2023; + private static final int SPECIAL_DISCOUNT_AMOUNT = 1000; + + public EventResult takeAllBenefit(Date date, Order order) { + Map<BenefitType, Integer> allBenefit = new HashMap<>(); + allBenefit.put(BenefitType.GIFT, takeGift(order)); + allBenefit.put(BenefitType.D_DAY, takeDDayDiscount(date)); + allBenefit.put(BenefitType.WEEKDAY, takeWeekdayDiscount(date, order)); + allBenefit.put(BenefitType.WEEKEND, takeWeekendDiscount(date, order)); + allBenefit.put(BenefitType.SPECIAL, takeSpecialDiscount(date)); + + cancelAllBenefitIfMeetCondition(order, allBenefit); + + return new EventResult(allBenefit); + } + + private int takeGift(Order order) { + if (order.calculateTotalOrderPrice() >= MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT) { + return Menu.CHAMPAGNE.getPrice(); + } + + return 0; + } + + private int takeDDayDiscount(Date date) { + if (date.isDDayDiscountActive()) { + return D_DAY_DISCOUNT_DEFAULT_AMOUNT + + (calculateDifferenceBetweenFirstDay(date) * D_DAY_DISCOUNT_AMOUNT_PER_DAY); + } + + return 0; + } + + private int calculateDifferenceBetweenFirstDay(Date date) { + return date.getDayNumber() - FIRST_DAY_NUMBER; + } + + private int takeWeekdayDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekdayDiscountActive() && MenuType.decideMenuType(menu) == MenuType.DESSERT) { + discount += orderedMenu.getQuantity() * WEEKDAY_DESSERT_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeWeekendDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekendDiscountActive() && MenuType.decideMenuType(menu) == MenuType.MAIN) { + discount += orderedMenu.getQuantity() * WEEKEND_MAIN_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeSpecialDiscount(Date date) { + if (date.isSpecialDiscountActive()) { + return SPECIAL_DISCOUNT_AMOUNT; + } + + return 0; + } + + private Map<BenefitType, Integer> cancelAllBenefitIfMeetCondition(Order order, + Map<BenefitType, Integer> allBenefit) { + if (isInsufficientTotalOrderPriceForEvent(order)) { + allBenefit.replace(BenefitType.GIFT, 0); + allBenefit.replace(BenefitType.D_DAY, 0); + allBenefit.replace(BenefitType.WEEKDAY, 0); + allBenefit.replace(BenefitType.WEEKEND, 0); + allBenefit.replace(BenefitType.SPECIAL, 0); + } + + return allBenefit; + } + + private boolean isInsufficientTotalOrderPriceForEvent(Order order) { + return order.calculateTotalOrderPrice() < MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT; + } +} \ No newline at end of file
Java
๋ฏธ์…˜ ๋™์•ˆ์€ ์‹œ๊ฐ„์ด ์ด‰๋ฐ•ํ–ˆ์–ด์„œ stream๊ณต๋ถ€๋ฅผ ํ•˜์ง€ ๋ชปํ–ˆ๋Š”๋ฐ์š”, ์•ž์œผ๋กœ ๊ณต๋ถ€ํ•ด์„œ ์ถ”์ฒœํ•ด์ฃผ์‹  ๋ฐฉ๋ฒ• ์ดํ•ดํ•ด๋ณด๋„๋ก ํ• ๊ฒŒ์š” ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!
@@ -0,0 +1,100 @@ +package christmas.domain; + +import java.util.HashMap; +import java.util.Map; + +public class EventProcess { + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT = 120000; + private static final int MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT = 10000; + private static final int D_DAY_DISCOUNT_AMOUNT_PER_DAY = 100; + private static final int D_DAY_DISCOUNT_DEFAULT_AMOUNT = 1000; + private static final int FIRST_DAY_NUMBER = 1; + private static final int WEEKDAY_DESSERT_DISCOUNT_AMOUNT = 2023; + private static final int WEEKEND_MAIN_DISCOUNT_AMOUNT = 2023; + private static final int SPECIAL_DISCOUNT_AMOUNT = 1000; + + public EventResult takeAllBenefit(Date date, Order order) { + Map<BenefitType, Integer> allBenefit = new HashMap<>(); + allBenefit.put(BenefitType.GIFT, takeGift(order)); + allBenefit.put(BenefitType.D_DAY, takeDDayDiscount(date)); + allBenefit.put(BenefitType.WEEKDAY, takeWeekdayDiscount(date, order)); + allBenefit.put(BenefitType.WEEKEND, takeWeekendDiscount(date, order)); + allBenefit.put(BenefitType.SPECIAL, takeSpecialDiscount(date)); + + cancelAllBenefitIfMeetCondition(order, allBenefit); + + return new EventResult(allBenefit); + } + + private int takeGift(Order order) { + if (order.calculateTotalOrderPrice() >= MINIMUM_TOTAL_ORDER_PRICE_FOR_GIFT) { + return Menu.CHAMPAGNE.getPrice(); + } + + return 0; + } + + private int takeDDayDiscount(Date date) { + if (date.isDDayDiscountActive()) { + return D_DAY_DISCOUNT_DEFAULT_AMOUNT + + (calculateDifferenceBetweenFirstDay(date) * D_DAY_DISCOUNT_AMOUNT_PER_DAY); + } + + return 0; + } + + private int calculateDifferenceBetweenFirstDay(Date date) { + return date.getDayNumber() - FIRST_DAY_NUMBER; + } + + private int takeWeekdayDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekdayDiscountActive() && MenuType.decideMenuType(menu) == MenuType.DESSERT) { + discount += orderedMenu.getQuantity() * WEEKDAY_DESSERT_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeWeekendDiscount(Date date, Order order) { + int discount = 0; + + for (OrderedMenu orderedMenu : order.getOrder()) { + Menu menu = Menu.decideMenu(orderedMenu.getMenuName()); + if (date.isWeekendDiscountActive() && MenuType.decideMenuType(menu) == MenuType.MAIN) { + discount += orderedMenu.getQuantity() * WEEKEND_MAIN_DISCOUNT_AMOUNT; + } + } + + return discount; + } + + private int takeSpecialDiscount(Date date) { + if (date.isSpecialDiscountActive()) { + return SPECIAL_DISCOUNT_AMOUNT; + } + + return 0; + } + + private Map<BenefitType, Integer> cancelAllBenefitIfMeetCondition(Order order, + Map<BenefitType, Integer> allBenefit) { + if (isInsufficientTotalOrderPriceForEvent(order)) { + allBenefit.replace(BenefitType.GIFT, 0); + allBenefit.replace(BenefitType.D_DAY, 0); + allBenefit.replace(BenefitType.WEEKDAY, 0); + allBenefit.replace(BenefitType.WEEKEND, 0); + allBenefit.replace(BenefitType.SPECIAL, 0); + } + + return allBenefit; + } + + private boolean isInsufficientTotalOrderPriceForEvent(Order order) { + return order.calculateTotalOrderPrice() < MINIMUM_TOTAL_ORDER_PRICE_FOR_ALL_EVENT; + } +} \ No newline at end of file
Java
ํ›จ์”ฌ ๊น”๋”ํ•˜๋„ค์š”,, ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!
@@ -0,0 +1,85 @@ +package christmas.domain; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class EventResult { + private static final String NON_BADGE = "์—†์Œ"; + private static final String STAR_BADGE = "๋ณ„"; + private static final String TREE_BADGE = "ํŠธ๋ฆฌ"; + private static final String SANTA_BADGE = "์‚ฐํƒ€"; + private static final int STAR_BADGE_MINIMUM_AMOUNT = 5000; + private static final int STAR_BADGE_MAXIMUM_AMOUNT = 10000; + private static final int TREE_BADGE_MINIMUM_AMOUNT = 10000; + private static final int TREE_BADGE_MAXIMUM_AMOUNT = 20000; + private static final int SANTA_BADGE_MINIMUM_AMOUNT = 20000; + + private final Map<BenefitType, Integer> allBenefit; + + public EventResult(Map<BenefitType, Integer> allBenefit) { + this.allBenefit = allBenefit; + } + + public int calculateTotalBenefitAmount() { + int totalBenefitAmount = 0; + List<BenefitType> benefitTypes = List.of(BenefitType.values()); + + for (BenefitType benefitType : benefitTypes) { + totalBenefitAmount += allBenefit.get(benefitType); + } + + return totalBenefitAmount; + } + + public int calculateTotalDiscountAmount() { + int totalDiscountAmount = 0; + List<BenefitType> benefitTypes = List.of(BenefitType.values()); + + for (BenefitType benefitType : benefitTypes) { + totalDiscountAmount += allBenefit.get(benefitType); + } + if (allBenefit.get(BenefitType.GIFT) == Menu.CHAMPAGNE.getPrice()) { + totalDiscountAmount -= Menu.CHAMPAGNE.getPrice(); + } + + return totalDiscountAmount; + } + + public boolean isReceivedGiftBenefit() { + return allBenefit.get(BenefitType.GIFT) == Menu.CHAMPAGNE.getPrice(); + } + + public List<BenefitType> checkWhichBenefitExist() { + List<BenefitType> existingBenefit = new ArrayList<>(); + BenefitType[] benefitTypes = BenefitType.values(); + + for (BenefitType benefitType : benefitTypes) { + if (allBenefit.get(benefitType) != 0) { + existingBenefit.add(benefitType); + } + } + + return existingBenefit; + } + + public String decideEventBadge() { + int totalBenefitAmount = calculateTotalBenefitAmount(); + + if ((totalBenefitAmount >= STAR_BADGE_MINIMUM_AMOUNT) && (totalBenefitAmount < STAR_BADGE_MAXIMUM_AMOUNT)) { + return STAR_BADGE; + } + if ((totalBenefitAmount >= TREE_BADGE_MINIMUM_AMOUNT) && (totalBenefitAmount < TREE_BADGE_MAXIMUM_AMOUNT)) { + return TREE_BADGE; + } + if ((totalBenefitAmount >= SANTA_BADGE_MINIMUM_AMOUNT)) { + return SANTA_BADGE; + } + return NON_BADGE; + } + + public Map<BenefitType, Integer> getAllBenefit() { + return Collections.unmodifiableMap(allBenefit); + } +} \ No newline at end of file
Java
์ถœ๋ ฅ ํ—ค๋”๋“ค์„ enum์œผ๋กœ ๊ด€๋ฆฌํ•  ์ง€ badge๋ฅผ enum์œผ๋กœ ๊ด€๋ฆฌํ•  ์ง€ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ ์ถœ๋ ฅ ํ—ค๋”๋“ค๋งŒ enum์œผ๋กœ ๊ด€๋ฆฌํ–ˆ๋Š”๋ฐ์š”, ๋ฆฌ๋ทฐ ๋‚จ๊ฒจ๋“œ๋ฆฐ ๊ฒƒ์— ๋‹ต๋ณ€ ์ฃผ์‹  ํ•œ๋ฒˆ๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๋ฌธ์ž์—ด์„ ๊ตณ์ด enum์œผ๋กœ ๊ด€๋ฆฌ ํ•˜์ง€ ์•Š์•„๋„ ๋  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ๋ง์”€์— ๊ณต๊ณต๊ฐํ•ด์„œ ๋ฐ˜๋Œ€๋กœ badge๋Š” ๊ผญ enum์œผ๋กœ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์•˜์„ ๊ฒƒ์ด๋ผ๋Š” ์ƒ๊ฐ๋„ ๋“œ๋„ค์š”. ๊ฐ์‚ฌํ•ด์š”
@@ -0,0 +1,60 @@ +package christmas.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class EventProcessTest { + @DisplayName("์ด๋ฒคํŠธ์— ์ถฉ๋ถ„ํ•œ ์ „์ฒด ์ฃผ๋ฌธ ๊ธˆ์•ก์œผ๋กœ ์ „์ฒด ํ˜œํƒ ๋„์ถœ") + @Test + void takeAllBenefitWithSufficientTotalOrderPrice() { + Date dateInput = new Date(3); + Order orderInput = new Order(setUpSufficientTotalOrderPriceOrder()); + EventProcess eventProcess = new EventProcess(); + EventResult eventResult = eventProcess.takeAllBenefit(dateInput, orderInput); + Map<BenefitType, Integer> result = eventResult.getAllBenefit(); + + assertThat(result.get(BenefitType.GIFT)).isEqualTo(25000); + assertThat(result.get(BenefitType.D_DAY)).isEqualTo(1200); + assertThat(result.get(BenefitType.WEEKDAY)).isEqualTo(2023); + assertThat(result.get(BenefitType.WEEKEND)).isEqualTo(0); + assertThat(result.get(BenefitType.SPECIAL)).isEqualTo(1000); + } + + private List<OrderedMenu> setUpSufficientTotalOrderPriceOrder() { + List<OrderedMenu> orderedMenus = new ArrayList<>(); + orderedMenus.add(new OrderedMenu("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 2)); + orderedMenus.add(new OrderedMenu("๋ ˆ๋“œ์™€์ธ", 1)); + orderedMenus.add(new OrderedMenu("์ดˆ์ฝ”์ผ€์ดํฌ", 1)); + + return orderedMenus; + } + + @DisplayName("์ด๋ฒคํŠธ์— ์ถฉ๋ถ„ํ•˜์ง€ ์•Š์€ ์ „์ฒด ์ฃผ๋ฌธ ๊ธˆ์•ก์œผ๋กœ ์ „์ฒด ํ˜œํƒ ๋„์ถœ") + @Test + void takeAllBenefitWithInSufficientTotalOrderPrice() { + Date dateInput = new Date(26); + Order orderInput = new Order(setUpInSufficientTotalOrderPriceOrder()); + EventProcess eventProcess = new EventProcess(); + EventResult eventResult = eventProcess.takeAllBenefit(dateInput, orderInput); + Map<BenefitType, Integer> result = eventResult.getAllBenefit(); + + assertThat(result.get(BenefitType.GIFT)).isEqualTo(0); + assertThat(result.get(BenefitType.D_DAY)).isEqualTo(0); + assertThat(result.get(BenefitType.WEEKDAY)).isEqualTo(0); + assertThat(result.get(BenefitType.WEEKEND)).isEqualTo(0); + assertThat(result.get(BenefitType.SPECIAL)).isEqualTo(0); + } + + private List<OrderedMenu> setUpInSufficientTotalOrderPriceOrder() { + List<OrderedMenu> orderedMenus = new ArrayList<>(); + orderedMenus.add(new OrderedMenu("ํƒ€ํŒŒ์Šค", 1)); + orderedMenus.add(new OrderedMenu("์ œ๋กœ์ฝœ๋ผ", 1)); + + return orderedMenus; + } +} \ No newline at end of file
Java
์™€,, ํ™•์‹คํ•˜๊ฒŒ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š” ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!