code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -0,0 +1,27 @@ +import Button from "../atoms/Button"; +import TextContents from "../atoms/TextContents"; +import TitleTex from "../atoms/TitleText"; +import * as S from "./styled"; + +type MainPropsType = { + setIsInLogged: React.Dispatch<React.SetStateAction<boolean>>; +}; + +const Main = (props: MainPropsType) => { + return ( + <S.Container> + <TitleTex>{"ํ™ˆ"}</TitleTex> + <TextContents /> + <S.SignUpButtonContainer> + <Button + text={"๋กœ๊ทธ์•„์›ƒ"} + bgColor={"black"} + type={"button"} + onClick={() => props.setIsInLogged(false)} + /> + </S.SignUpButtonContainer> + </S.Container> + ); +}; + +export default Main;
Unknown
setState๋ฅผ ํ”„๋ž์Šค๋กœ ์ „๋‹ฌํ•˜์ง€์•Š๊ณ  setState๋ฅผ ๋ž˜ํ•‘ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌํ–ˆ์œผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ํŽธํ•˜๊ฒŒ ์ „๋‹ฌ์ด ๊ฐ€๋Šฅํ•˜์ง€์•Š์•˜์„๊นŒ์—ฌ? ```ts setIsInLogged: (state : boolean) => void ```
@@ -0,0 +1,190 @@ +/** + * + * ์ด๋ฆ„ + * ์ด๋ฉ”์ผ (์ค‘๋ณต ํ™•์ธ ๋ฒ„ํŠผ) + * ๋น„๋ฐ€๋ฒˆํ˜ธ + * ๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌํ™•์ธ + * ํšŒ์›๊ฐ€์ž… ๋ฒ„ํŠผ + * + */ + +import Button from "../atoms/Button"; +import Input from "../atoms/Input"; +import LabelText from "../atoms/LabelText"; +import TitleTex from "../atoms/TitleText"; +import InputAndButton from "../molecules/InputAndButton"; +import { useForm } from "react-hook-form"; +import * as S from "./styled"; +import { CONSTANTS } from "../../constants"; +import { useState } from "react"; + +type SignUpFormPropsType = { + setIsInLogged: React.Dispatch<React.SetStateAction<boolean>>; +}; +const SignUpForm = (props: SignUpFormPropsType) => { + const { setIsInLogged } = props; + const [isEmailPass, setIsEmailPass] = useState(false); + const { + REGEXP: { EMAIL_CHECK, PASSWORD_CHECK }, + } = CONSTANTS; + + const { getValues, watch, register, setValue } = useForm(); + + const emailRegex = EMAIL_CHECK; + const pwdRegex = PASSWORD_CHECK; + + const setLocalData = () => { + const userData = { + name: getValues("userName"), + phone: getValues("userPhoneNumber"), + password: getValues("userPwd"), + email: getValues("userEmail"), + }; + + const jsonUserData = JSON.stringify(userData); + + return localStorage.setItem("loginData", jsonUserData); + }; + + const submitData = () => { + // ๋“ฑ๋ก ํ›„ + if (!isEmailPass) { + return alert("์ด๋ฉ”์ผ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”."); + } + + alert("ํšŒ์›๊ฐ€์ž…์„ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค."); + setLocalData(); + return setIsInLogged(true); + }; + + const checkPwdVariable = () => { + const userPwd = getValues("userPwd") as string; + if (userPwd.length < 2 || userPwd.length > 20) { + return alert( + "๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ํŠน์ˆ˜๋ฌธ์ž 1๊ฐœ ํฌํ•จํ•˜์—ฌ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”(์ตœ์†Œ 2์ž~์ตœ๋Œ€20์ž)" + ); + } + + if (!pwdRegex.test(userPwd)) { + return alert( + "๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ํŠน์ˆ˜๋ฌธ์ž 1๊ฐœ ํฌํ•จํ•˜์—ฌ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”(์ตœ์†Œ 2์ž~์ตœ๋Œ€20์ž)" + ); + } + + if (!(getValues("checkUserPwd") === userPwd)) { + return alert("๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ์ด ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + return true; + }; + + const checkEmailVariable = () => { + // ์ด๋ฉ”์ผ check + if (!getValues("userEmail")) { + return alert("์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!emailRegex.test(getValues("userEmail"))) { + return alert("์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + const localUserEmail = JSON.parse( + localStorage.getItem("loginData") || "" + ).email; + + if (localUserEmail === getValues("userEmail")) { + return alert("์ค‘๋ณต๋œ ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + setIsEmailPass(true); + return true; + }; + + const checkUserData = ( + e: React.MouseEvent<HTMLButtonElement, MouseEvent> + ) => { + e.preventDefault(); + + if (getValues("userName").length < 3) { + return alert("์ด๋ฆ„์„ 3์ž์ด์ƒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!getValues("userPhoneNumber")) { + return alert("ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!checkEmailVariable()) { + return false; + } + + if (!checkPwdVariable()) { + return false; + } + + return submitData(); + }; + + return ( + <S.Container> + <S.Form> + <TitleTex>{"ํšŒ์›๊ฐ€์ž…"}</TitleTex> + <LabelText>{"์ด๋ฆ„"}</LabelText> + <Input + type={"text"} + name={"userName"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ"}</LabelText> + <Input + type={"number"} + name={"userPhoneNumber"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"์ด๋ฉ”์ผ"}</LabelText> + <InputAndButton + type={"button"} + name={"userEmail"} + onClick={checkEmailVariable} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + isEmailPass={isEmailPass} + /> + <LabelText>{"๋น„๋ฐ€๋ฒˆํ˜ธ"}</LabelText> + <Input + type={"password"} + name={"userPwd"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ"}</LabelText> + <Input + type={"password"} + name={"checkUserPwd"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <S.SignUpButtonContainer> + <Button + type={"submit"} + text={"ํšŒ์›๊ฐ€์ž…"} + bgColor={"black"} + onClick={(e) => checkUserData(e)} + /> + </S.SignUpButtonContainer> + </S.Form> + </S.Container> + ); +}; + +export default SignUpForm;
Unknown
Submit ํ•จ์ˆ˜๋‚ด๋ถ€์—์„œ ์œ ํšจ์„ฑ๊ฒ€์‚ฌ์˜ ๊ฒฐ๊ณผ๋กœ ์œ ์ €์—๊ฒŒ ๋…ธ์ถœ์‹œํ‚ค๋Š”๊ฒƒ์ด ์•„๋‹ˆ๋ผ Submit ์ด๋ฒคํŠธ๋ฅผ ๋ง‰์•„๋ฒ„๋ ธ์œผ๋ฉด ์–ด๋–จ๊นŒ์—ฌ? ์˜ˆ๋ฅผ๋“ค์–ด ์œ ํšจ์„ฑ๊ฒ€์‚ฌ๋ฅผ ์‹คํŒจํ–ˆ๋‹ค๋ฉด ๋ฒ„ํŠผ์˜ disabled์ฒ˜๋ฆฌ๋„ ๊ณ ๋ คํ•ด๋ณผ์ˆ˜์žˆ์„๊ฒƒ๊ฐ™์Šต๋‹ˆ๋‹ค ๊ทผ๋ฐ ์ด๊ฑด ๊ธฐํš๊ณผ ๋งž๋ฌผ๋ฆฌ๋Š”๊ฑฐ๋‹ˆ๊นŒ!
@@ -0,0 +1,190 @@ +/** + * + * ์ด๋ฆ„ + * ์ด๋ฉ”์ผ (์ค‘๋ณต ํ™•์ธ ๋ฒ„ํŠผ) + * ๋น„๋ฐ€๋ฒˆํ˜ธ + * ๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌํ™•์ธ + * ํšŒ์›๊ฐ€์ž… ๋ฒ„ํŠผ + * + */ + +import Button from "../atoms/Button"; +import Input from "../atoms/Input"; +import LabelText from "../atoms/LabelText"; +import TitleTex from "../atoms/TitleText"; +import InputAndButton from "../molecules/InputAndButton"; +import { useForm } from "react-hook-form"; +import * as S from "./styled"; +import { CONSTANTS } from "../../constants"; +import { useState } from "react"; + +type SignUpFormPropsType = { + setIsInLogged: React.Dispatch<React.SetStateAction<boolean>>; +}; +const SignUpForm = (props: SignUpFormPropsType) => { + const { setIsInLogged } = props; + const [isEmailPass, setIsEmailPass] = useState(false); + const { + REGEXP: { EMAIL_CHECK, PASSWORD_CHECK }, + } = CONSTANTS; + + const { getValues, watch, register, setValue } = useForm(); + + const emailRegex = EMAIL_CHECK; + const pwdRegex = PASSWORD_CHECK; + + const setLocalData = () => { + const userData = { + name: getValues("userName"), + phone: getValues("userPhoneNumber"), + password: getValues("userPwd"), + email: getValues("userEmail"), + }; + + const jsonUserData = JSON.stringify(userData); + + return localStorage.setItem("loginData", jsonUserData); + }; + + const submitData = () => { + // ๋“ฑ๋ก ํ›„ + if (!isEmailPass) { + return alert("์ด๋ฉ”์ผ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”."); + } + + alert("ํšŒ์›๊ฐ€์ž…์„ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค."); + setLocalData(); + return setIsInLogged(true); + }; + + const checkPwdVariable = () => { + const userPwd = getValues("userPwd") as string; + if (userPwd.length < 2 || userPwd.length > 20) { + return alert( + "๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ํŠน์ˆ˜๋ฌธ์ž 1๊ฐœ ํฌํ•จํ•˜์—ฌ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”(์ตœ์†Œ 2์ž~์ตœ๋Œ€20์ž)" + ); + } + + if (!pwdRegex.test(userPwd)) { + return alert( + "๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ํŠน์ˆ˜๋ฌธ์ž 1๊ฐœ ํฌํ•จํ•˜์—ฌ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”(์ตœ์†Œ 2์ž~์ตœ๋Œ€20์ž)" + ); + } + + if (!(getValues("checkUserPwd") === userPwd)) { + return alert("๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ์ด ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + return true; + }; + + const checkEmailVariable = () => { + // ์ด๋ฉ”์ผ check + if (!getValues("userEmail")) { + return alert("์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!emailRegex.test(getValues("userEmail"))) { + return alert("์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + const localUserEmail = JSON.parse( + localStorage.getItem("loginData") || "" + ).email; + + if (localUserEmail === getValues("userEmail")) { + return alert("์ค‘๋ณต๋œ ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + setIsEmailPass(true); + return true; + }; + + const checkUserData = ( + e: React.MouseEvent<HTMLButtonElement, MouseEvent> + ) => { + e.preventDefault(); + + if (getValues("userName").length < 3) { + return alert("์ด๋ฆ„์„ 3์ž์ด์ƒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!getValues("userPhoneNumber")) { + return alert("ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!checkEmailVariable()) { + return false; + } + + if (!checkPwdVariable()) { + return false; + } + + return submitData(); + }; + + return ( + <S.Container> + <S.Form> + <TitleTex>{"ํšŒ์›๊ฐ€์ž…"}</TitleTex> + <LabelText>{"์ด๋ฆ„"}</LabelText> + <Input + type={"text"} + name={"userName"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ"}</LabelText> + <Input + type={"number"} + name={"userPhoneNumber"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"์ด๋ฉ”์ผ"}</LabelText> + <InputAndButton + type={"button"} + name={"userEmail"} + onClick={checkEmailVariable} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + isEmailPass={isEmailPass} + /> + <LabelText>{"๋น„๋ฐ€๋ฒˆํ˜ธ"}</LabelText> + <Input + type={"password"} + name={"userPwd"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ"}</LabelText> + <Input + type={"password"} + name={"checkUserPwd"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <S.SignUpButtonContainer> + <Button + type={"submit"} + text={"ํšŒ์›๊ฐ€์ž…"} + bgColor={"black"} + onClick={(e) => checkUserData(e)} + /> + </S.SignUpButtonContainer> + </S.Form> + </S.Container> + ); +}; + +export default SignUpForm;
Unknown
setLocalData ํ•จ์ˆ˜๋„ค์ž„์„ ๋ณด๊ณ  ์ด๊ฒŒ ๋ญ”์—ญํ• ์„ํ•˜๋Š”๊ฑฐ์ง€ ์‹ถ๋„ค์š” setLocalStorageData๋ผ๊ณ  ์ž‘๋ช…ํ•˜๋Š”๊ฑด ์–ด๋• ์„๊นŒ์—ฌ
@@ -0,0 +1,190 @@ +/** + * + * ์ด๋ฆ„ + * ์ด๋ฉ”์ผ (์ค‘๋ณต ํ™•์ธ ๋ฒ„ํŠผ) + * ๋น„๋ฐ€๋ฒˆํ˜ธ + * ๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌํ™•์ธ + * ํšŒ์›๊ฐ€์ž… ๋ฒ„ํŠผ + * + */ + +import Button from "../atoms/Button"; +import Input from "../atoms/Input"; +import LabelText from "../atoms/LabelText"; +import TitleTex from "../atoms/TitleText"; +import InputAndButton from "../molecules/InputAndButton"; +import { useForm } from "react-hook-form"; +import * as S from "./styled"; +import { CONSTANTS } from "../../constants"; +import { useState } from "react"; + +type SignUpFormPropsType = { + setIsInLogged: React.Dispatch<React.SetStateAction<boolean>>; +}; +const SignUpForm = (props: SignUpFormPropsType) => { + const { setIsInLogged } = props; + const [isEmailPass, setIsEmailPass] = useState(false); + const { + REGEXP: { EMAIL_CHECK, PASSWORD_CHECK }, + } = CONSTANTS; + + const { getValues, watch, register, setValue } = useForm(); + + const emailRegex = EMAIL_CHECK; + const pwdRegex = PASSWORD_CHECK; + + const setLocalData = () => { + const userData = { + name: getValues("userName"), + phone: getValues("userPhoneNumber"), + password: getValues("userPwd"), + email: getValues("userEmail"), + }; + + const jsonUserData = JSON.stringify(userData); + + return localStorage.setItem("loginData", jsonUserData); + }; + + const submitData = () => { + // ๋“ฑ๋ก ํ›„ + if (!isEmailPass) { + return alert("์ด๋ฉ”์ผ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”."); + } + + alert("ํšŒ์›๊ฐ€์ž…์„ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค."); + setLocalData(); + return setIsInLogged(true); + }; + + const checkPwdVariable = () => { + const userPwd = getValues("userPwd") as string; + if (userPwd.length < 2 || userPwd.length > 20) { + return alert( + "๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ํŠน์ˆ˜๋ฌธ์ž 1๊ฐœ ํฌํ•จํ•˜์—ฌ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”(์ตœ์†Œ 2์ž~์ตœ๋Œ€20์ž)" + ); + } + + if (!pwdRegex.test(userPwd)) { + return alert( + "๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ํŠน์ˆ˜๋ฌธ์ž 1๊ฐœ ํฌํ•จํ•˜์—ฌ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”(์ตœ์†Œ 2์ž~์ตœ๋Œ€20์ž)" + ); + } + + if (!(getValues("checkUserPwd") === userPwd)) { + return alert("๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ์ด ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + return true; + }; + + const checkEmailVariable = () => { + // ์ด๋ฉ”์ผ check + if (!getValues("userEmail")) { + return alert("์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!emailRegex.test(getValues("userEmail"))) { + return alert("์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + const localUserEmail = JSON.parse( + localStorage.getItem("loginData") || "" + ).email; + + if (localUserEmail === getValues("userEmail")) { + return alert("์ค‘๋ณต๋œ ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + setIsEmailPass(true); + return true; + }; + + const checkUserData = ( + e: React.MouseEvent<HTMLButtonElement, MouseEvent> + ) => { + e.preventDefault(); + + if (getValues("userName").length < 3) { + return alert("์ด๋ฆ„์„ 3์ž์ด์ƒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!getValues("userPhoneNumber")) { + return alert("ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + if (!checkEmailVariable()) { + return false; + } + + if (!checkPwdVariable()) { + return false; + } + + return submitData(); + }; + + return ( + <S.Container> + <S.Form> + <TitleTex>{"ํšŒ์›๊ฐ€์ž…"}</TitleTex> + <LabelText>{"์ด๋ฆ„"}</LabelText> + <Input + type={"text"} + name={"userName"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ"}</LabelText> + <Input + type={"number"} + name={"userPhoneNumber"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"์ด๋ฉ”์ผ"}</LabelText> + <InputAndButton + type={"button"} + name={"userEmail"} + onClick={checkEmailVariable} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + isEmailPass={isEmailPass} + /> + <LabelText>{"๋น„๋ฐ€๋ฒˆํ˜ธ"}</LabelText> + <Input + type={"password"} + name={"userPwd"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <LabelText>{"๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ"}</LabelText> + <Input + type={"password"} + name={"checkUserPwd"} + register={register} + getValues={getValues} + setValue={setValue} + watch={watch} + /> + <S.SignUpButtonContainer> + <Button + type={"submit"} + text={"ํšŒ์›๊ฐ€์ž…"} + bgColor={"black"} + onClick={(e) => checkUserData(e)} + /> + </S.SignUpButtonContainer> + </S.Form> + </S.Container> + ); +}; + +export default SignUpForm;
Unknown
์ด๋Ÿฐ ์œ ํšจ์„ฑ๊ฒ€์‚ฌ๋กœ์ง์€ ์™ธ๋ถ€์— ๋ชจ๋“ˆํ™”ํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š”๊ฑด ์–ด๋–˜์„๊นŒ์š”? ๊ทธ๋ฆฌ๊ณ  ๋ฆฌ์•กํŠธ ํ›…ํผ ์‚ฌ์šฉํ•˜์‹ ๋‹ค๋ฉด https://www.react-hook-form.com/advanced-usage/#CustomHookwithResolver ์ด๋Ÿฐ๊ฒƒ๋„ ์žˆ์Šด๋‹ค
@@ -4,19 +4,20 @@ import { Routes, Route } from "react-router-dom"; // Components import Home from "./Home"; +import SignUp from "./SignUp"; const Router = () => { - const [isInLogged, setisInLogged] = useState(true); + const [isInLogged, setIsInLogged] = useState(false); return ( <> {isInLogged ? ( <Routes> - <Route path="/" element={<Home />} /> + <Route path="/" element={<Home setIsInLogged={setIsInLogged} />} /> </Routes> ) : ( <Routes> - <Route /> + <Route path="/" element={<SignUp setIsInLogged={setIsInLogged} />} /> </Routes> )} </>
Unknown
์ด๋ ‡๊ฒŒ ๋กœ๊ทธ์ธ ์ƒํƒœ์—ฌ๋ถ€๋ฅผ Router์—์„œ ํ•˜๋Š”๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์ „์—ญ์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š”๊ฒŒ ์–ด๋• ์„๊นŒ์—ฌ? ๋ผ์šฐํ„ฐ ์ปดํฌ๋„ŒํŠธ๋Š” url์— ๋งคํ•‘๋˜๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”ํ•ด์ฃผ๋Š” ์—ญํ• ์ด๋ผ๊ณ  ์ƒ๊ฐ๋˜์–ด์„œ์—ฌ! ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋กœ๊ทธ์ธ ์ƒํƒœ์—ฌ๋ถ€๊นŒ์ง€ ์•Œ์•„์•ผํ–ˆ์„๊นŒ์š”?
@@ -0,0 +1,11 @@ +import SignUpForm from "../components/organisms/SignUpForm"; + +type SignUpFormPropsType = { + setIsInLogged: React.Dispatch<React.SetStateAction<boolean>>; +}; + +const SignUp = (props: SignUpFormPropsType) => { + return <SignUpForm setIsInLogged={props.setIsInLogged} />; +}; + +export default SignUp;
Unknown
์ด๋ถ€๋ถ„๋„ ์ž˜ ์ดํ•ด๊ฐ€ ๋˜์ง€์•Š๋Š”๋ฐ Form ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋กœ๊ทธ์ธ์—ฌ๋ถ€๋ฅผ ์•Œ์•„์•ผํ•˜๋Š” ์ด์œ ๊ฐ€ ์—†๋‹ค๊ณ  ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค..! ์ปดํฌ๋„ŒํŠธ์—๊ฒŒ ์ „๋‹ฌ๋˜๋Š” prop์€ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์•Œ์•„์•ผํ•˜๋Š” ์ •๋ณด์˜ ๋ฒ”์œ„๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค๊ณ  ๋ด์š”
@@ -0,0 +1,61 @@ +import axiosInstance from "@/lib/axiosInstance"; +import { useInfiniteQuery } from "@tanstack/react-query"; + +type Gathering = { + teamId: number; + id: number; + type: "OFFICE_STRETCHING" | "MINDFULNESS" | "WORKATION"; + name: string; + dateTime: string; + location: string; + image: string; +}; + +type User = { + teamId: number; + id: number; + name: string; + image: string; +}; + +type DataItem = { + teamId: number; + id: number; + score: number; + comment: string; + createdAt: string; + Gathering: Gathering; + User: User; +}; + +type MyReviews = { + data: DataItem[]; + totalItemCount: number; + currentPage: number; + totalPages: number; +}; + +const fetchMyReviews = async ({ pageParam = 0, userId }: { pageParam: number; userId: number }) => { + const response = await axiosInstance.get<MyReviews>("reviews", { + params: { + limit: 5, + offset: pageParam, + userId, + }, + }); + + return { + data: response.data, + nextOffset: response.data.data.length === 5 ? pageParam + 5 : null, + }; +}; + +export const useGetMyReviews = (userId: number) => { + return useInfiniteQuery({ + queryKey: ["mypage", "reviews", "written"], + queryFn: ({ pageParam }) => fetchMyReviews({ pageParam, userId }), + initialPageParam: 0, + getNextPageParam: (lastPage) => lastPage.nextOffset, + staleTime: 60000, + }); +};
TypeScript
_:warning: Potential issue_ **์บ์‹œ ํ‚ค์— userId๋ฅผ ํฌํ•จ์‹œ์ผœ์ฃผ์„ธ์š”.** ํ˜„์žฌ queryKey๊ฐ€ ์‚ฌ์šฉ์ž๋ณ„๋กœ ๊ตฌ๋ถ„๋˜์ง€ ์•Š์•„ ์บ์‹œ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ```diff export const useGetMyReviews = (userId: number) => { return useInfiniteQuery({ - queryKey: ["my-reviews"], + queryKey: ["my-reviews", userId], queryFn: ({ pageParam }) => fetchMyReviews({ pageParam, userId }), initialPageParam: 0, getNextPageParam: (lastPage) => lastPage.nextOffset, staleTime: 60000, }); }; ``` <!-- suggestion_start --> <details> <summary>๐Ÿ“ Committable suggestion</summary> > โ€ผ๏ธ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion export const useGetMyReviews = (userId: number) => { return useInfiniteQuery({ queryKey: ["my-reviews", userId], queryFn: ({ pageParam }) => fetchMyReviews({ pageParam, userId }), initialPageParam: 0, getNextPageParam: (lastPage) => lastPage.nextOffset, staleTime: 60000, }); }; ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
@@ -0,0 +1,83 @@ +import { useGetMyReviews } from "@/app/(common)/mypage/_hooks/useGetMyReviews"; +import ListItem from "@/components/ListItem"; +import Score from "@/components/Score"; +import Spinner from "@/components/Spinner"; +import { useInfiniteScroll } from "@/hooks/useInfiniteScroll"; +import { useUserStore } from "@/stores/useUserStore"; +import Image from "next/image"; + +const GatheringType = { + OFFICE_STRETCHING: "๋‹ฌ๋žจํ• ์˜คํ”ผ์Šค ์ŠคํŠธ๋ ˆ์นญ", + MINDFULNESS: "๋‹ฌ๋žจํ• ๋งˆ์ธ๋“œํ’€๋‹ˆ์Šค", + WORKATION: "์›Œ์ผ€์ด์…˜", +}; +export default function MyReviews() { + const id = useUserStore((state) => state.user?.id) as number; + const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, error } = useGetMyReviews(id); + + const { observerRef } = useInfiniteScroll({ + hasNextPage, + isFetchingNextPage, + fetchNextPage, + }); + + const allReviews = data?.pages.flatMap((page) => page.data.data) ?? []; + + if (isLoading) + return ( + <div className="flex flex-1 items-center justify-center"> + <Spinner /> + </div> + ); + if (error) + return ( + <div className="flex flex-1 items-center justify-center"> + <p>๋ชฉ๋ก ์กฐํšŒ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.</p> + </div> + ); + return ( + <> + {allReviews.length ? ( + <> + <div className="w-full"> + <div className="flex-1 divide-y-2 divide-dashed"> + {allReviews.map((review) => ( + <div className="relative py-6" key={review.id}> + <ListItem + CardImage={ + <Image + src={review.Gathering.image} + alt="๋ชจ์ž„ ์ด๋ฏธ์ง€" + width={280} + height={156} + className="h-[156px] w-full rounded-3xl md:max-w-[280px]" + /> + } + className="justify-between" + > + <div className="flex flex-col gap-2"> + <div className="flex flex-col gap-2.5"> + <Score score={review.score} /> + <ListItem.Body>{review.comment}</ListItem.Body> + <ListItem.ServiceInfo> + {GatheringType[review.Gathering.type]} ์ด์šฉ ยท {review.Gathering.location} + </ListItem.ServiceInfo> + </div> + <ListItem.MetaInfo secondary={review.createdAt} /> + </div> + </ListItem> + </div> + ))} + </div> + <div ref={observerRef} className="h-10" /> + {isFetchingNextPage && <div className="text-center text-sm text-gray-500">๋” ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘...</div>} + </div> + </> + ) : ( + <div className="flex flex-1 items-center justify-center"> + <p>์•„์ง ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> + </div> + )} + </> + ); +}
Unknown
_:warning: Potential issue_ **๋นˆ ์ƒํƒœ ๋ฉ”์‹œ์ง€๊ฐ€ ๋ถ€์ •ํ™•ํ•ฉ๋‹ˆ๋‹ค.** ํ˜„์žฌ ํŽ˜์ด์ง€๋Š” "์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ"๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๊ณณ์ด๋ฏ€๋กœ, ๋ฉ”์‹œ์ง€๋ฅผ ๋งฅ๋ฝ์— ๋งž๊ฒŒ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”. ```diff <div className="flex flex-1 items-center justify-center"> - <p>์•„์ง ์ž‘์„ฑ ๊ฐ€๋Šฅํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> + <p>์•„์ง ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> </div> ``` <!-- suggestion_start --> <details> <summary>๐Ÿ“ Committable suggestion</summary> > โ€ผ๏ธ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion <div className="flex flex-1 items-center justify-center"> <p>์•„์ง ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> </div> ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
@@ -0,0 +1,83 @@ +import { useGetMyReviews } from "@/app/(common)/mypage/_hooks/useGetMyReviews"; +import ListItem from "@/components/ListItem"; +import Score from "@/components/Score"; +import Spinner from "@/components/Spinner"; +import { useInfiniteScroll } from "@/hooks/useInfiniteScroll"; +import { useUserStore } from "@/stores/useUserStore"; +import Image from "next/image"; + +const GatheringType = { + OFFICE_STRETCHING: "๋‹ฌ๋žจํ• ์˜คํ”ผ์Šค ์ŠคํŠธ๋ ˆ์นญ", + MINDFULNESS: "๋‹ฌ๋žจํ• ๋งˆ์ธ๋“œํ’€๋‹ˆ์Šค", + WORKATION: "์›Œ์ผ€์ด์…˜", +}; +export default function MyReviews() { + const id = useUserStore((state) => state.user?.id) as number; + const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, error } = useGetMyReviews(id); + + const { observerRef } = useInfiniteScroll({ + hasNextPage, + isFetchingNextPage, + fetchNextPage, + }); + + const allReviews = data?.pages.flatMap((page) => page.data.data) ?? []; + + if (isLoading) + return ( + <div className="flex flex-1 items-center justify-center"> + <Spinner /> + </div> + ); + if (error) + return ( + <div className="flex flex-1 items-center justify-center"> + <p>๋ชฉ๋ก ์กฐํšŒ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.</p> + </div> + ); + return ( + <> + {allReviews.length ? ( + <> + <div className="w-full"> + <div className="flex-1 divide-y-2 divide-dashed"> + {allReviews.map((review) => ( + <div className="relative py-6" key={review.id}> + <ListItem + CardImage={ + <Image + src={review.Gathering.image} + alt="๋ชจ์ž„ ์ด๋ฏธ์ง€" + width={280} + height={156} + className="h-[156px] w-full rounded-3xl md:max-w-[280px]" + /> + } + className="justify-between" + > + <div className="flex flex-col gap-2"> + <div className="flex flex-col gap-2.5"> + <Score score={review.score} /> + <ListItem.Body>{review.comment}</ListItem.Body> + <ListItem.ServiceInfo> + {GatheringType[review.Gathering.type]} ์ด์šฉ ยท {review.Gathering.location} + </ListItem.ServiceInfo> + </div> + <ListItem.MetaInfo secondary={review.createdAt} /> + </div> + </ListItem> + </div> + ))} + </div> + <div ref={observerRef} className="h-10" /> + {isFetchingNextPage && <div className="text-center text-sm text-gray-500">๋” ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘...</div>} + </div> + </> + ) : ( + <div className="flex flex-1 items-center justify-center"> + <p>์•„์ง ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> + </div> + )} + </> + ); +}
Unknown
_:hammer_and_wrench: Refactor suggestion_ **์ด๋ฏธ์ง€์— ์ ‘๊ทผ์„ฑ ์†์„ฑ์„ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.** ์Šคํฌ๋ฆฐ ๋ฆฌ๋” ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•ด ์ด๋ฏธ์ง€์— ๋” ์ž์„ธํ•œ ๋Œ€์ฒด ํ…์ŠคํŠธ๋ฅผ ์ œ๊ณตํ•ด์ฃผ์„ธ์š”. ```diff <Image src={review.Gathering.image} - alt="๋ชจ์ž„ ์ด๋ฏธ์ง€" + alt={`${GatheringType[review.Gathering.type]} - ${review.Gathering.name} ๋ชจ์ž„ ์ด๋ฏธ์ง€`} width={280} height={156} className="h-[156px] w-full rounded-3xl md:max-w-[280px]" /> ``` <!-- suggestion_start --> <details> <summary>๐Ÿ“ Committable suggestion</summary> > โ€ผ๏ธ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion <Image src={review.Gathering.image} alt={`${GatheringType[review.Gathering.type]} - ${review.Gathering.name} ๋ชจ์ž„ ์ด๋ฏธ์ง€`} width={280} height={156} className="h-[156px] w-full rounded-3xl md:max-w-[280px]" /> ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
@@ -0,0 +1,83 @@ +import { useGetMyReviews } from "@/app/(common)/mypage/_hooks/useGetMyReviews"; +import ListItem from "@/components/ListItem"; +import Score from "@/components/Score"; +import Spinner from "@/components/Spinner"; +import { useInfiniteScroll } from "@/hooks/useInfiniteScroll"; +import { useUserStore } from "@/stores/useUserStore"; +import Image from "next/image"; + +const GatheringType = { + OFFICE_STRETCHING: "๋‹ฌ๋žจํ• ์˜คํ”ผ์Šค ์ŠคํŠธ๋ ˆ์นญ", + MINDFULNESS: "๋‹ฌ๋žจํ• ๋งˆ์ธ๋“œํ’€๋‹ˆ์Šค", + WORKATION: "์›Œ์ผ€์ด์…˜", +}; +export default function MyReviews() { + const id = useUserStore((state) => state.user?.id) as number; + const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, error } = useGetMyReviews(id); + + const { observerRef } = useInfiniteScroll({ + hasNextPage, + isFetchingNextPage, + fetchNextPage, + }); + + const allReviews = data?.pages.flatMap((page) => page.data.data) ?? []; + + if (isLoading) + return ( + <div className="flex flex-1 items-center justify-center"> + <Spinner /> + </div> + ); + if (error) + return ( + <div className="flex flex-1 items-center justify-center"> + <p>๋ชฉ๋ก ์กฐํšŒ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.</p> + </div> + ); + return ( + <> + {allReviews.length ? ( + <> + <div className="w-full"> + <div className="flex-1 divide-y-2 divide-dashed"> + {allReviews.map((review) => ( + <div className="relative py-6" key={review.id}> + <ListItem + CardImage={ + <Image + src={review.Gathering.image} + alt="๋ชจ์ž„ ์ด๋ฏธ์ง€" + width={280} + height={156} + className="h-[156px] w-full rounded-3xl md:max-w-[280px]" + /> + } + className="justify-between" + > + <div className="flex flex-col gap-2"> + <div className="flex flex-col gap-2.5"> + <Score score={review.score} /> + <ListItem.Body>{review.comment}</ListItem.Body> + <ListItem.ServiceInfo> + {GatheringType[review.Gathering.type]} ์ด์šฉ ยท {review.Gathering.location} + </ListItem.ServiceInfo> + </div> + <ListItem.MetaInfo secondary={review.createdAt} /> + </div> + </ListItem> + </div> + ))} + </div> + <div ref={observerRef} className="h-10" /> + {isFetchingNextPage && <div className="text-center text-sm text-gray-500">๋” ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘...</div>} + </div> + </> + ) : ( + <div className="flex flex-1 items-center justify-center"> + <p>์•„์ง ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> + </div> + )} + </> + ); +}
Unknown
_:warning: Potential issue_ **๋ฉ”์‹œ์ง€๊ฐ€ ๋ถ€์ ์ ˆํ•ฉ๋‹ˆ๋‹ค.** ํ˜„์žฌ ๋ฉ”์‹œ์ง€๊ฐ€ "์ž‘์„ฑ ๊ฐ€๋Šฅํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”"๋กœ ๋˜์–ด ์žˆ๋Š”๋ฐ, ์ด๋Š” "์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ" ํƒญ์˜ ์ปจํ…์ŠคํŠธ์™€ ๋งž์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ```diff <div className="flex flex-1 items-center justify-center"> - <p>์•„์ง ์ž‘์„ฑ ๊ฐ€๋Šฅํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> + <p>์•„์ง ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> </div> ``` <!-- suggestion_start --> <details> <summary>๐Ÿ“ Committable suggestion</summary> > โ€ผ๏ธ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion <div className="flex flex-1 items-center justify-center"> <p>์•„์ง ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> </div> ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
@@ -0,0 +1,83 @@ +import { useGetMyReviews } from "@/app/(common)/mypage/_hooks/useGetMyReviews"; +import ListItem from "@/components/ListItem"; +import Score from "@/components/Score"; +import Spinner from "@/components/Spinner"; +import { useInfiniteScroll } from "@/hooks/useInfiniteScroll"; +import { useUserStore } from "@/stores/useUserStore"; +import Image from "next/image"; + +const GatheringType = { + OFFICE_STRETCHING: "๋‹ฌ๋žจํ• ์˜คํ”ผ์Šค ์ŠคํŠธ๋ ˆ์นญ", + MINDFULNESS: "๋‹ฌ๋žจํ• ๋งˆ์ธ๋“œํ’€๋‹ˆ์Šค", + WORKATION: "์›Œ์ผ€์ด์…˜", +}; +export default function MyReviews() { + const id = useUserStore((state) => state.user?.id) as number; + const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, error } = useGetMyReviews(id); + + const { observerRef } = useInfiniteScroll({ + hasNextPage, + isFetchingNextPage, + fetchNextPage, + }); + + const allReviews = data?.pages.flatMap((page) => page.data.data) ?? []; + + if (isLoading) + return ( + <div className="flex flex-1 items-center justify-center"> + <Spinner /> + </div> + ); + if (error) + return ( + <div className="flex flex-1 items-center justify-center"> + <p>๋ชฉ๋ก ์กฐํšŒ ์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.</p> + </div> + ); + return ( + <> + {allReviews.length ? ( + <> + <div className="w-full"> + <div className="flex-1 divide-y-2 divide-dashed"> + {allReviews.map((review) => ( + <div className="relative py-6" key={review.id}> + <ListItem + CardImage={ + <Image + src={review.Gathering.image} + alt="๋ชจ์ž„ ์ด๋ฏธ์ง€" + width={280} + height={156} + className="h-[156px] w-full rounded-3xl md:max-w-[280px]" + /> + } + className="justify-between" + > + <div className="flex flex-col gap-2"> + <div className="flex flex-col gap-2.5"> + <Score score={review.score} /> + <ListItem.Body>{review.comment}</ListItem.Body> + <ListItem.ServiceInfo> + {GatheringType[review.Gathering.type]} ์ด์šฉ ยท {review.Gathering.location} + </ListItem.ServiceInfo> + </div> + <ListItem.MetaInfo secondary={review.createdAt} /> + </div> + </ListItem> + </div> + ))} + </div> + <div ref={observerRef} className="h-10" /> + {isFetchingNextPage && <div className="text-center text-sm text-gray-500">๋” ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘...</div>} + </div> + </> + ) : ( + <div className="flex flex-1 items-center justify-center"> + <p>์•„์ง ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๊ฐ€ ์—†์–ด์š”</p> + </div> + )} + </> + ); +}
Unknown
_:hammer_and_wrench: Refactor suggestion_ **ํƒ€์ž… ๋‹จ์–ธ ๋Œ€์‹  ํƒ€์ž… ๊ฐ€๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.** `as number` ํƒ€์ž… ๋‹จ์–ธ ๋Œ€์‹  ํƒ€์ž… ๊ฐ€๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋” ์•ˆ์ „ํ•œ ํƒ€์ž… ์ฒดํฌ๋ฅผ ๊ตฌํ˜„ํ•˜์„ธ์š”. ```diff - const id = useUserStore((state) => state.user?.id) as number; + const user = useUserStore((state) => state.user); + + if (!user?.id) { + return ( + <div className="flex flex-1 items-center justify-center"> + <p>์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</p> + </div> + ); + } + + const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, error } = useGetMyReviews(user.id); ``` <!-- suggestion_start --> <details> <summary>๐Ÿ“ Committable suggestion</summary> > โ€ผ๏ธ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion const user = useUserStore((state) => state.user); if (!user?.id) { return ( <div className="flex flex-1 items-center justify-center"> <p>์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</p> </div> ); } const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, error } = useGetMyReviews(user.id); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
@@ -27,7 +27,8 @@ import { useGetMyGatherings } from "@/app/(common)/mypage/_hooks/useGetMyGatheri // isCompleted๊ฐ€ true, isReviewed๊ฐ€ true => ๋ฆฌ๋ทฐ ์ž‘์„ฑ x export default function MyGatherings() { const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, error } = useGetMyGatherings([ - "my-gatherings", + "mypage", + "gatherings", ]); const [isModalOpen, setModalOpen] = useState(false); const [selectedGathering, setSelectedGathering] = useState<number | null>(null); @@ -40,7 +41,7 @@ export default function MyGatherings() { setModalOpen(false); }; - const mutation = useLeaveGathering(["my-gatherings"]); + const mutation = useLeaveGathering(["gatherings"]); // ๋ฌดํ•œ ์Šคํฌ๋กค์„ ๊ฐ์ง€ํ•  ref const { observerRef } = useInfiniteScroll({
Unknown
_:hammer_and_wrench: Refactor suggestion_ **์ฟผ๋ฆฌ ํ‚ค ๊ตฌ์กฐ์˜ ์ผ๊ด€์„ฑ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.** `useLeaveGathering` ํ›…์˜ ์ฟผ๋ฆฌ ํ‚ค๊ฐ€ `["gatherings"]`๋กœ ๋˜์–ด์žˆ๋Š”๋ฐ, ๋‹ค๋ฅธ ์ฟผ๋ฆฌ ํ‚ค๋“ค๊ณผ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด `["mypage", "gatherings"]`๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค. ```diff -const mutation = useLeaveGathering(["gatherings"]); +const mutation = useLeaveGathering(["mypage", "gatherings"]); ``` <!-- suggestion_start --> <details> <summary>๐Ÿ“ Committable suggestion</summary> > โ€ผ๏ธ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion const mutation = useLeaveGathering(["mypage", "gatherings"]); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
@@ -0,0 +1,59 @@ +import accumulator.Accumulator; +import accumulator.PostFixAccumulator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +public class CalculatorTest { + + + @ParameterizedTest + @DisplayName("๋ง์…ˆ") + @CsvSource(value = {"1 2 + 3 + : 6", "10 20 + 30 + : 60", + "100 200 + 300 + : 600"}, delimiter = ':') + public void postFixAddCalculate(String expression, int expectResult) { + Accumulator postFixAccumulator = new PostFixAccumulator(); + int result = postFixAccumulator.calculate(expression); + Assertions.assertEquals(expectResult, result); + } + + @ParameterizedTest + @DisplayName("๋บผ์…ˆ") + @CsvSource(value = {"1 2 - 3 -: -4", "10 30 - 20 -: -40", "300 200 - 1 - : 99"}, delimiter = ':') + public void postFixMinusCalculate(String expression, int expectResult) { + Accumulator postFixAccumulator = new PostFixAccumulator(); + int result = postFixAccumulator.calculate(expression); + Assertions.assertEquals(expectResult, result); + } + + @ParameterizedTest + @DisplayName("๊ณฑ์…ˆ") + @CsvSource(value = {"1 2 * 3 *: 6", "10 20 * 30 *: 6000", + "100 200 * 300 * : 6000000"}, delimiter = ':') + public void postFixMultiplyCalculate(String expression, int expectResult) { + Accumulator postFixAccumulator = new PostFixAccumulator(); + int result = postFixAccumulator.calculate(expression); + Assertions.assertEquals(expectResult, result); + } + + @ParameterizedTest + @DisplayName("๋‚˜๋ˆ—์…ˆ") + @CsvSource(value = {"100 10 / 1 / : 10", "10 2 / : 5", "10000 20 / 10 / : 50"}, delimiter = ':') + public void postFixDivideCalculate(String expression, int expectResult) { + Accumulator postFixAccumulator = new PostFixAccumulator(); + int result = postFixAccumulator.calculate(expression); + Assertions.assertEquals(expectResult, result); + } + + @ParameterizedTest + @DisplayName("์‚ฌ์น™์—ฐ์‚ฐ") + @CsvSource(value = {"5 3 2 * + 8 4 / - : 9", "7 4 * 2 / 3 + 1 - : 16", + "9 5 - 2 * 6 3 / +: 10"}, delimiter = ':') + public void PostFixCalculate(String expression, int expectResult) { + PostFixAccumulator calculator = new PostFixAccumulator(); + int result = calculator.calculate(expression); + Assertions.assertEquals(expectResult, result); + } + +}
Java
์—ฌ๊ธฐ๋„ ์ปจ๋ฒค์…˜์ด ์ซŒ... ๊ฐ ๋ฉ”์„œ๋“œ ์‚ฌ์ด๋Š” ๋„์›Œ ์ฃผ์‹œ๋Š”๊ฒŒ ์›์น™์ด๊ณ  IDE๋ฌธ์ œ์ธ๊ฑด์ง€ ์ œ๊ฐ€ ๋ณด๋Š” ํ™˜๋ฉด์ด ๋ฌธ์ œ์ธ๊ฑด์ง€ class ๋‹จ์œ„์™€ ๋ฉ”์„œ๋“œ ๋‹จ์œ„์— ๋Œ€ํ•œ ๋ธ”๋Ÿญ์ด ๊ตฌ๋ถ„๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด ๋˜ํ•œ ์ง€์ผœ์ฃผ์…จ์œผ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ์ง€๊ธˆ ํ•˜๋‚˜์˜ ์˜ˆ์‹œ์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋งŒ ์ž‘์„ฑํ•˜์‹  ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. @ParameterizedTest ๋ฅผ ๊ณต๋ถ€ํ•ด๋ณด์‹œ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,117 @@ +# Created by https://www.toptal.com/developers/gitignore/api/intellij +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +# End of https://www.toptal.com/developers/gitignore/api/intellij \ No newline at end of file
Unknown
์ด์ชฝ ๋ถ€๋ถ„ ์˜ต์…˜์œผ๋กœ ์–ด๋– ํ•œ ๋‚ด์—ญ ์ถ”๊ฐ€ํ–ˆ๋Š”์ง€ ์•Œ๋ ค์ฃผ์‹ค ์ˆ˜ ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,9 @@ +package input; + +public interface Input { + + public String selectInput(); + + public String expressionInput(); + +}
Java
์ œ๋„ˆ๋ฆญ์„ ์‚ฌ์šฉํ•œ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”? Input์€ ๋ฐ”์ดํŠธ ํ˜น์€ ๋ฌธ์ž์—ด๋กœ ๋“ค์–ด์˜ฌํ…๋ฐ ์–ด๋– ํ•œ ์ƒ๊ฐ์œผ๋กœ ์ œ๋„ˆ๋ฆญ์„ ์‚ฌ์šฉํ–ˆ๋Š”์ง€๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹น
@@ -0,0 +1,9 @@ + +import calculator.Calculator; + +public class main { + + public static void main(String[] args) { + new Calculator().run(); + } +}
Java
IOException์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋˜๋Š” ๋ถ€๋ถ„๊นŒ์ง€ ์ „ํŒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌ๋ฉด ์ž…์ถœ๋ ฅ ์˜ˆ์™ธ ๋ฐœ์ƒ ์‹œ ํ”„๋กœ๊ทธ๋žจ์ด ๋น„์ •์ƒ์ ์œผ๋กœ ์ข…๋ฃŒ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๊ฒ ๋„ค์š”.
@@ -0,0 +1,20 @@ +package repository; + +import java.util.ArrayList; +import java.util.List; + +public class Repository { + + private List<String> list = new ArrayList<>(); + + public void store(String expression, String result) { + StringBuilder formattedExpression = new StringBuilder(expression).append(" = ").append(result); + list.add(formattedExpression.toString()); + + } + + public List<String> getResult() { + return new ArrayList<>(list); + } + +}
Java
์ €์žฅ์†Œ๋ฅผ List๋กœ ํ‘œํ˜„ํ•˜์‹  ์ด์œ ๋ฅผ ์•Œ ์ˆ˜ ์žˆ์„๊นŒ์š”? ๋™์ผํ•œ ์—ฐ์‚ฐ์‹์ด์—ฌ๋„ ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€ํ•˜๋Š”๊ฒŒ ๋งž์„๊นŒ์š”? ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ตœ๋Œ€ํ•œ ์•„๋‚„ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•ด๋ณด๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,19 @@ +import convertor.InfixToPostfixConverter; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +public class ChangToPostfixTest { + + @ParameterizedTest + @DisplayName("์ค‘์œ„ ํ‘œ๊ธฐ์‹ ํ›„์œ„ ํ‘œ๊ธฐ์‹ ๋ณ€ํ™˜") + @CsvSource(value = {"7 * 4 / 2 + 3 - 1 :'7 4 * 2 / 3 + 1 - '", + "9 - 5 * 2 + 6 / 3: '9 5 2 * - 6 3 / + '"}, delimiter = ':') + public void InfixToPostfixTest(String infixExpression, String postFinExpression) { + InfixToPostfixConverter calculator = new InfixToPostfixConverter(); + String result = calculator.changeToPostFix(infixExpression); + Assertions.assertEquals(postFinExpression, result); + } + +}
Java
ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ๋‚ด์šฉ์ด ๋งŽ์ด ๋ถ€์‹คํ•ฉ๋‹ˆ๋‹ค. ๋‹จ์œ„ ํ…Œ์ŠคํŠธ์— ๋Œ€ํ•ด์„œ ์ƒ๊ฐํ•ด๋ณด์…จ์œผ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค. ์ ์–ด๋„ ์ž‘์„ฑํ•˜์‹  ์ฝ”๋“œ์—์„œ View ์˜์—ญ์„ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ์˜์—ญ์€ ํ…Œ์ŠคํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,22 @@ +package christmas.config; + +public enum ErrorMessage { + WRONG_DATE("์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค."), + WRONG_ORDER("์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค."), + OVER_MAX_ORDER("๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."), + ONLY_DRINK_ORDER("์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + + private static final String PREFIX = "[ERROR]"; + private static final String SUFFIX = "๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; + private static final String DELIMITER = " "; + + private final String message; + + ErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return String.join(DELIMITER, PREFIX, message, SUFFIX); + } +}
Java
ํ•ด๋‹น ์—๋Ÿฌ๋ฉ”์‹œ์ง€๋Š” ์™œ enum์„ ์‚ฌ์šฉํ•˜์…จ๋‚˜์š”? ์ƒ์ˆ˜๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐ ์ผ๋ฐ˜ ํด๋ž˜์Šค์™€ enum ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์‹  ๊ธฐ์ค€์ด ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,57 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.dto.OrderDTO; +import christmas.util.IntParser; +import christmas.util.OrderParser; +import christmas.util.RetryExecutor; +import christmas.view.InputView; +import christmas.view.OutputView; + +import java.util.List; + +public class EventController { + private Bill bill; + private EventHandler eventHandler; + private final InputView inputView; + private final OutputView outputView; + + public EventController(InputView inputView, OutputView outputView) { + this.inputView = inputView; + this.outputView = outputView; + } + + public void run() { + outputView.printHelloMessage(); + RetryExecutor.execute(this::setBill, outputView::printErrorMessage); + RetryExecutor.execute(this::setOrder, error -> { + outputView.printErrorMessage(error); + bill.clearOrder(); + }); + printResult(); + } + + private void setBill() { + String input = inputView.inputDate().trim(); + bill = Bill.from(IntParser.parseIntOrThrow(input)); + eventHandler = EventHandler.from(bill); + } + + private void setOrder() { + String input = inputView.inputOrder(); + List<OrderDTO> orders = OrderParser.parseOrderOrThrow(input); + orders.forEach(it -> bill.add(Order.create(it.menuName(), it.count()))); + bill.validateOnlyDrink(); + } + + private void printResult() { + outputView.printEventPreviewTitle(bill.getDateValue()); + outputView.printOrder(bill.getAllOrders()); + outputView.printTotalPrice(bill.getTotalPrice()); + outputView.printGift(eventHandler.hasChampagneGift()); + outputView.printAllBenefit(eventHandler.getAllBenefit()); + outputView.printBenefitPrice(eventHandler.getTotalBenefitPrice()); + outputView.printAfterDiscountPrice(bill.getTotalPrice() - eventHandler.getTotalDiscountPrice()); + outputView.printBadge(Badge.getBadgeNameWithBenefitPrice(eventHandler.getTotalBenefitPrice())); + } +}
Java
์˜ค.. ์ด๋Ÿฐ ๋ฐฉ๋ฒ•์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์ฒ˜์Œ ๋ณด๋Š” ๊ฒƒ ๊ฐ™์•„์š” ๋ฐฐ์šธ ๋ถ€๋ถ„์ด ๋งŽ๋„ค์š” ใ…  ๐Ÿ‘๐Ÿ‘
@@ -0,0 +1,26 @@ +package christmas.domain; + +import java.util.Arrays; + +public enum Badge { + SANTA("์‚ฐํƒ€", 20000), + TREE("ํŠธ๋ฆฌ", 10000), + STAR("๋ณ„", 5000), + NOTHING("์—†์Œ", 0); + + private final String badgeName; + private final int threshold; + + Badge(String badgeName, int threshold) { + this.badgeName = badgeName; + this.threshold = threshold; + } + + public static String getBadgeNameWithBenefitPrice(int benefitPrice) { + return Arrays.stream(Badge.values()) + .filter(it -> it.threshold <= benefitPrice) + .map(it -> it.badgeName) + .findFirst() + .orElse(NOTHING.badgeName); + } +}
Java
stream ์‚ฌ์šฉ์„ ์ž˜ํ•˜์‹œ๋Š” ๊ฒƒ ๊ฐ™์•„์š”! ํ˜น์‹œ ์–ด๋–ป๊ฒŒ ๊ณต๋ถ€ํ•˜๋ฉด ์ข‹์„์ง€... ํŒ์ด ์žˆ์œผ์‹ค๊นŒ์š”?
@@ -0,0 +1,94 @@ +package christmas.domain; + +import christmas.config.Constant; +import christmas.dto.OrderDTO; +import christmas.config.ErrorMessage; +import christmas.config.MenuType; + +import java.util.ArrayList; +import java.util.List; + +public class Bill implements CheckEventDate { + private final List<Order> orders = new ArrayList<>(); + private final Date date; + + private Bill(Date date) { + this.date = date; + } + + public static Bill from(int date) { + return new Bill(Date.from(date)); + } + + public Bill add(Order order) { + validateDuplicates(order); + orders.add(order); + validateMaxOrder(); + return this; + } + + private void validateDuplicates(Order newOrder) { + long duplicated = orders.stream() + .filter(it -> it.isSameMenu(newOrder)) + .count(); + if (duplicated != Constant.FILTER_CONDITION) { + throw new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage()); + } + } + + private void validateMaxOrder() { + if (Order.accumulateCount(orders) > Constant.MAX_ORDER) { + throw new IllegalArgumentException(ErrorMessage.OVER_MAX_ORDER.getMessage()); + } + } + + public void validateOnlyDrink() { + if (Order.accumulateCount(orders) == getTypeCount(MenuType.DRINK)) { + throw new IllegalArgumentException(ErrorMessage.ONLY_DRINK_ORDER.getMessage()); + } + } + + public void clearOrder() { + orders.clear(); + } + + public int getTotalPrice() { + return orders.stream() + .map(Order::getPrice) + .reduce(Constant.INIT_VALUE, Integer::sum); + } + + public int getTypeCount(MenuType type) { + return Order.accumulateCount(orders, type); + } + + public List<OrderDTO> getAllOrders() { + return orders.stream().map(Order::getOrder).toList(); + } + + // ์•„๋ž˜๋Š” Date ๊ด€๋ จ method + + @Override + public boolean isWeekend() { + return date.isWeekend(); + } + + @Override + public boolean isSpecialDay() { + return date.isSpecialDay(); + } + + @Override + public boolean isNotPassedChristmas() { + return date.isNotPassedChristmas(); + } + + @Override + public int timePassedSinceFirstDay() { + return date.timePassedSinceFirstDay(); + } + + public int getDateValue() { + return date.getDateValue(); + } +}
Java
ํ•ด๋‹น ๋ฆฌ์ŠคํŠธ๋ฅผ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด ์„ ์–ธ ํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,75 @@ +package christmas.domain; + +import christmas.config.Menu; +import christmas.config.MenuType; + +import java.util.function.Function; +import java.util.function.Predicate; + +public enum Event { + CHRISTMAS( + "ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ", + true, + Bill::isNotPassedChristmas, + bill -> bill.timePassedSinceFirstDay() * 100 + 1000 + ), + WEEKDAY( + "ํ‰์ผ ํ• ์ธ", + true, + bill -> !bill.isWeekend(), + bill -> bill.getTypeCount(MenuType.DESSERT) * 2023 + ), + WEEKEND( + "์ฃผ๋ง ํ• ์ธ", + true, + Bill::isWeekend, + bill -> bill.getTypeCount(MenuType.MAIN) * 2023 + ), + SPECIAL( + "ํŠน๋ณ„ ํ• ์ธ", + true, + Bill::isSpecialDay, + bill -> 1000 + ), + CHAMPAGNE( + "์ฆ์ • ์ด๋ฒคํŠธ", + false, + bill -> bill.getTotalPrice() >= 120000, + bill -> Menu.CHAMPAGNE.getPrice() + ); + + private static final int ALL_EVENT_THRESHOLD = 10000; + + private final String eventName; + private final boolean isDiscount; + private final Predicate<Bill> condition; + private final Function<Bill, Integer> benefit; + + Event( + String eventName, + boolean isDiscount, + Predicate<Bill> condition, + Function<Bill, Integer> benefit + ) { + this.eventName = eventName; + this.isDiscount = isDiscount; + this.condition = condition; + this.benefit = benefit; + } + + public String getEventName() { + return eventName; + } + + public boolean isDiscount() { + return isDiscount; + } + + public boolean checkCondition(Bill bill) { + return condition.test(bill) && bill.getTotalPrice() >= ALL_EVENT_THRESHOLD; + } + + public int getBenefit(Bill bill) { + return benefit.apply(bill); + } +}
Java
์˜ค.. ํ• ์ธ ๋ฆฌ์ŠคํŠธ๋ฅผ enum ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ์„ ์–ธํ•œ ๊ฒƒ ๋˜๊ฒŒ ์ข‹์€ ์•„์ด๋””์–ด๋„ค์š” ๐Ÿ‘๐Ÿ‘
@@ -0,0 +1,38 @@ +package christmas.util; + +import christmas.config.ErrorMessage; + +public class IntParser { + private static final int MAX_STRING_LENGTH = 11; + + private IntParser() { + // ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐฉ์ง€ + } + + public static int parseIntOrThrow(String numeric) { + validateNumericStringLength(numeric); + long parsed = parseLongOrThrow(numeric); + validateIntRange(parsed); + return Integer.parseInt(numeric); + } + + private static long parseLongOrThrow(String numeric) { + try { + return Long.parseLong(numeric); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage()); + } + } + + private static void validateNumericStringLength(String numeric) { + if (numeric.length() > MAX_STRING_LENGTH) { + throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage()); + } + } + + private static void validateIntRange(long number) { + if (number > Integer.MAX_VALUE || number < Integer.MIN_VALUE) { + throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage()); + } + } +}
Java
์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐฉ์ง€๋ผ๋Š” ๊ฒƒ์ด ๋ฌด์—‡์ธ์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ ๋นˆ ์ƒ์„ฑ์ž๋ฅผ ๋งŒ๋“ค์–ด ๋‘๋ฉด ๋ฌด์—‡์ด ์ข‹๋‚˜์š”..??
@@ -0,0 +1,91 @@ +package christmas.view; + +import christmas.dto.BenefitDTO; +import christmas.dto.OrderDTO; + +import java.util.List; + +public class OutputView { + private void printMessage(ViewMessage message) { + System.out.println(message.getMessage()); + } + + private void printFormat(ViewMessage message, Object... args) { + System.out.printf(message.getMessage(), args); + newLine(); + } + + private void printTitle(ViewTitle title) { + System.out.println(title.getTitle()); + } + + public void printHelloMessage() { + printMessage(ViewMessage.HELLO); + } + + public void printEventPreviewTitle(int date) { + printFormat(ViewMessage.EVENT_PREVIEW_TITLE, date); + newLine(); + } + + public void printOrder(List<OrderDTO> orders) { + printTitle(ViewTitle.ORDER_MENU); + orders.forEach(it -> printFormat(ViewMessage.ORDER_FORMAT, it.menuName(), it.count())); + newLine(); + } + + public void printTotalPrice(int price) { + printTitle(ViewTitle.TOTAL_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, price); + newLine(); + } + + public void printGift(boolean hasGift) { + printTitle(ViewTitle.GIFT_MENU); + if (hasGift) { + printMessage(ViewMessage.CHAMPAGNE); + newLine(); + return; + } + printMessage(ViewMessage.NOTHING); + newLine(); + } + + public void printAllBenefit(List<BenefitDTO> benefits) { + printTitle(ViewTitle.BENEFIT_LIST); + if (benefits.isEmpty()) { + printMessage(ViewMessage.NOTHING); + newLine(); + return; + } + benefits.forEach(it -> printFormat(ViewMessage.BENEFIT_FORMAT, it.EventName(), it.price())); + newLine(); + } + + public void printBenefitPrice(int price) { + printTitle(ViewTitle.BENEFIT_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, -price); + newLine(); + } + + public void printAfterDiscountPrice(int price) { + printTitle(ViewTitle.AFTER_DISCOUNT_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, price); + newLine(); + } + + public void printBadge(String badge) { + printTitle(ViewTitle.BADGE); + System.out.println(badge); + } + + public void printErrorMessage(IllegalArgumentException error) { + newLine(); + System.out.println(error.getMessage()); + newLine(); + } + + public void newLine() { + System.out.println(); + } +}
Java
์ƒˆ๋กœ์šด ๋ผ์ธ์„ ๋งŒ๋“ค๋•Œ๋Š” System.lineSeperator()๋ฅผ ์ถ”์ฒœ ํ•ด์ฃผ์‹œ๋”๋ผ๊ตฌ์š”. ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,145 @@ +package christmas.domain; + +import christmas.dto.OrderDTO; +import christmas.config.ErrorMessage; +import christmas.config.MenuType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; + +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class BillTest { + @DisplayName("์ž˜๋ชป๋œ date ๊ฐ’ ์‚ฌ์šฉ ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ") + @ParameterizedTest + @ValueSource(ints = {-5, 0, 32, 75}) + void checkCreateFromWrongDate(int date) { + assertThatThrownBy(() -> Bill.from(date)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(ErrorMessage.WRONG_DATE.getMessage()); + } + + @DisplayName("add ๋™์ž‘ ํ™•์ธ") + @Test + void checkAddMethod() { + Bill bill = Bill.from(1) + .add(Order.create("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 3)) + .add(Order.create("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 1)) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 2)); + + List<OrderDTO> answer = List.of( + new OrderDTO("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 3), + new OrderDTO("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 1), + new OrderDTO("์ œ๋กœ์ฝœ๋ผ", 2) + ); + + assertThat(bill.getAllOrders()).isEqualTo(answer); + } + + @DisplayName("์ค‘๋ณต๋œ ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ") + @Test + void checkDuplicatedMenu() { + assertThatThrownBy(() -> Bill.from(1) + .add(Order.create("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 2)) + .add(Order.create("๋ฐ”๋น„ํ๋ฆฝ", 1)) + .add(Order.create("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 3)) + ).isInstanceOf(IllegalArgumentException.class).hasMessage(ErrorMessage.WRONG_ORDER.getMessage()); + } + + @DisplayName("๋ฉ”๋‰ด๊ฐ€ 20๊ฐœ๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ") + @ParameterizedTest + @MethodSource("overedOrder") + void checkOverOrder(List<Order> orders) { + Bill bill = Bill.from(1); + + assertThatThrownBy(() -> orders.forEach(bill::add)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(ErrorMessage.OVER_MAX_ORDER.getMessage()); + } + + static Stream<Arguments> overedOrder() { + return Stream.of( + Arguments.of(List.of( + Order.create("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 7), + Order.create("์ œ๋กœ์ฝœ๋ผ", 15) + )), + Arguments.of(List.of( + Order.create("์•„์ด์Šคํฌ๋ฆผ", 25) + )) + ); + } + + @DisplayName("clearOrder ๋™์ž‘ ํ™•์ธ") + @Test + void checkClearOrder() { + Bill bill = Bill.from(1) + .add(Order.create("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 3)) + .add(Order.create("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 1)) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 2)); + bill.clearOrder(); + assertThat(bill.getAllOrders()).isEqualTo(List.of()); + } + + @DisplayName("getTotalPrice ๋™์ž‘ ํ™•์ธ") + @Test + void checkTotalPrice() { + Bill bill = Bill.from(1) + .add(Order.create("ํƒ€ํŒŒ์Šค", 2)) + .add(Order.create("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 1)) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 2)); + assertThat(bill.getTotalPrice()).isEqualTo(72000); + } + + @DisplayName("getTypeCount ๋™์ž‘ ํ™•์ธ") + @ParameterizedTest + @MethodSource("typedBill") + void checkTypeCount(Bill bill, MenuType type, int answer) { + assertThat(bill.getTypeCount(type)).isEqualTo(answer); + } + + static Stream<Arguments> typedBill() { + return Stream.of( + Arguments.of( + Bill.from(1) + .add(Order.create("์–‘์†ก์ด์ˆ˜ํ”„", 3)) + .add(Order.create("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 1)) + .add(Order.create("๋ฐ”๋น„ํ๋ฆฝ", 2)), + MenuType.MAIN, + 3 + ), + Arguments.of( + Bill.from(1) + .add(Order.create("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 2)) + .add(Order.create("์ดˆ์ฝ”์ผ€์ดํฌ", 2)) + .add(Order.create("์•„์ด์Šคํฌ๋ฆผ", 3)) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 7)), + MenuType.DESSERT, + 5 + ) + ); + } + + @DisplayName("getDateValue ๋™์ž‘ ํ™•์ธ") + @ParameterizedTest + @ValueSource(ints = {1, 17, 25, 31}) + void checkDateValue(int date) { + assertThat(Bill.from(date).getDateValue()).isEqualTo(date); + } + + @DisplayName("์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•œ ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ") + @Test + void checkOnlyDrinkOrder() { + assertThatThrownBy(() -> Bill.from(1) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 3)) + .add(Order.create("๋ ˆ๋“œ์™€์ธ", 1)) + .validateOnlyDrink() + ).isInstanceOf(IllegalArgumentException.class).hasMessage(ErrorMessage.ONLY_DRINK_ORDER.getMessage()); + } +}
Java
isInstanceOf์™€ hasMessage๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ข€ ๋” ๊ผผ๊ผผํ•œ ํ…Œ์ŠคํŠธ๋ฅผ ํ•  ์ˆ˜ ์žˆ๊ตฐ์š”! ๋ฐฐ์›Œ ๊ฐ‘๋‹ˆ๋‹น ๐Ÿ‘๐Ÿ‘
@@ -0,0 +1,22 @@ +package christmas.config; + +public enum ErrorMessage { + WRONG_DATE("์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค."), + WRONG_ORDER("์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค."), + OVER_MAX_ORDER("๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."), + ONLY_DRINK_ORDER("์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + + private static final String PREFIX = "[ERROR]"; + private static final String SUFFIX = "๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; + private static final String DELIMITER = " "; + + private final String message; + + ErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return String.join(DELIMITER, PREFIX, message, SUFFIX); + } +}
Java
์‚ฌ์‹ค ์ €๋„ ์ƒ์ˆ˜๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ `enum`์„ ์‚ฌ์šฉํ• ์ง€ `class`๋ฅผ ์‚ฌ์šฉํ• ์ง€ ๊ณ ๋ฏผ์ด ๋งŽ์•˜์Šต๋‹ˆ๋‹ค. ์–ด๋–ค ๊ธฐ์ค€์„ ์„ธ์›Œ์•ผ ํ• ์ง€๋„ ์Šค์Šค๋กœ ํ™•๋ฆฝํ•˜์ง€ ๋ชปํ–ˆ๊ตฌ์š”. ๊ทธ๋ž˜์„œ ์šฐ์„ ์€ ์•„๋ฌด๋Ÿฐ ๊ธฐ๋Šฅ ์—†์ด ์ƒ์ˆ˜๊ฐ’๋งŒ ์ €์žฅํ•˜๋Š” ๊ฒฝ์šฐ๋Š” `class`๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ์•ฝ๊ฐ„์˜ ๊ธฐ๋Šฅ์ด๋ผ๋„ ํ•จ๊ป˜ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด `enum`์„ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•ด๋ดค์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ `ErrorMessage`์—์„œ๋Š” ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” prefix์™€ suffix๋ฅผ `getMessage()`๋ฉ”์„œ๋“œ์—์„œ ํ•จ๊ป˜ ํ•ฉ์ณ์„œ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๊ตฌ์ƒํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— `enum`์„ ์‚ฌ์šฉํ•ด๋ดค์Šต๋‹ˆ๋‹ค. ์‚ฌ์‹ค `class`๋กœ ์‚ฌ์šฉํ•ด๋„ ๋ฌด๋ฐฉํ• ๊ฑฐ ๊ฐ™๋„ค์š”. ๐Ÿ˜‚
@@ -0,0 +1,57 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.dto.OrderDTO; +import christmas.util.IntParser; +import christmas.util.OrderParser; +import christmas.util.RetryExecutor; +import christmas.view.InputView; +import christmas.view.OutputView; + +import java.util.List; + +public class EventController { + private Bill bill; + private EventHandler eventHandler; + private final InputView inputView; + private final OutputView outputView; + + public EventController(InputView inputView, OutputView outputView) { + this.inputView = inputView; + this.outputView = outputView; + } + + public void run() { + outputView.printHelloMessage(); + RetryExecutor.execute(this::setBill, outputView::printErrorMessage); + RetryExecutor.execute(this::setOrder, error -> { + outputView.printErrorMessage(error); + bill.clearOrder(); + }); + printResult(); + } + + private void setBill() { + String input = inputView.inputDate().trim(); + bill = Bill.from(IntParser.parseIntOrThrow(input)); + eventHandler = EventHandler.from(bill); + } + + private void setOrder() { + String input = inputView.inputOrder(); + List<OrderDTO> orders = OrderParser.parseOrderOrThrow(input); + orders.forEach(it -> bill.add(Order.create(it.menuName(), it.count()))); + bill.validateOnlyDrink(); + } + + private void printResult() { + outputView.printEventPreviewTitle(bill.getDateValue()); + outputView.printOrder(bill.getAllOrders()); + outputView.printTotalPrice(bill.getTotalPrice()); + outputView.printGift(eventHandler.hasChampagneGift()); + outputView.printAllBenefit(eventHandler.getAllBenefit()); + outputView.printBenefitPrice(eventHandler.getTotalBenefitPrice()); + outputView.printAfterDiscountPrice(bill.getTotalPrice() - eventHandler.getTotalDiscountPrice()); + outputView.printBadge(Badge.getBadgeNameWithBenefitPrice(eventHandler.getTotalBenefitPrice())); + } +}
Java
์ €๋„ ํ•จ์ˆ˜ํ˜• ์ธํ„ฐํŽ˜์ด์Šค๋ผ๋Š” ๊ฑธ ์ฒ˜์Œ ์จ๋ดค๋‹ต๋‹ˆ๋‹ค! 3์ฃผ์ฐจ ์ฝ”๋“œ๋ฆฌ๋ทฐ๋ฅผ ํ•˜๋ฉด์„œ ์–ด๊นจ๋„ˆ๋จธ๋กœ ๋ฐฐ์šด๊ฑฐ๋ผ, @HongYeseul ๋‹˜๋„ ์ด๋ฒˆ ์ฝ”๋“œ๋ฆฌ๋ทฐ๋ฅผ ๊ธฐํšŒ๋กœ ํ•œ๋ฒˆ ๊ณต๋ถ€ํ•ด๋ณด์‹œ๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”? ๐Ÿ˜
@@ -0,0 +1,26 @@ +package christmas.domain; + +import java.util.Arrays; + +public enum Badge { + SANTA("์‚ฐํƒ€", 20000), + TREE("ํŠธ๋ฆฌ", 10000), + STAR("๋ณ„", 5000), + NOTHING("์—†์Œ", 0); + + private final String badgeName; + private final int threshold; + + Badge(String badgeName, int threshold) { + this.badgeName = badgeName; + this.threshold = threshold; + } + + public static String getBadgeNameWithBenefitPrice(int benefitPrice) { + return Arrays.stream(Badge.values()) + .filter(it -> it.threshold <= benefitPrice) + .map(it -> it.badgeName) + .findFirst() + .orElse(NOTHING.badgeName); + } +}
Java
์ •๋ง ๋†€๋ž๊ฒŒ๋„ ์ €๋„ 1์ฃผ์ฐจ์™€ 2์ฃผ์ฐจ ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ํ•˜๋ฉด์„œ ๋Œ€๋ถ€๋ถ„์˜ ๋ฆฌ๋ทฐ์— `stream`์‚ฌ์šฉ์„ ์ž˜ ํ•˜์‹œ๋Š”๊ฒŒ ๋ถ€๋Ÿฝ๋‹ค! ๋ผ๋Š”์‹์œผ๋กœ ๋งŽ์ด ๋ฆฌ๋ทฐ๋ฅผ ๋‚จ๊ธฐ๊ณ  ๋‹ค๋…”์–ด์š”. ๊ทธ๋ ‡๊ฒŒ ๋งŽ์€ ๋ถ„๋“ค์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด์„œ `stream`๊ณผ ์ ์  ์นœ์ˆ™ํ•ด์ง€๋‹ค ๋ณด๋‹ˆ ์ €๋„ `stream`์„ ํ•œ๋ฒˆ ์จ๋ณผ๊นŒ? ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๊ณ , ๊ทธ๋ ‡๊ฒŒ ์ ์  ์ต์ˆ™ํ•ด์ง„ ๊ฒƒ ๊ฐ™์•„์š”! ๐Ÿ˜Š 4์ฃผ์ฐจ๊ฐ€ ๋๋‚œ ์ง€๊ธˆ์€ ํ•™๊ต ๋„์„œ๊ด€์—์„œ '์ด๊ฒƒ์ด ์ž๋ฐ”๋‹ค'๋ผ๋Š” ์ฑ…์„ ๋นŒ๋ ค์„œ ์ฝ๊ณ  ์žˆ์–ด์š”. ์ž๋ฐ”์— ์ต์ˆ™ํ•ด์ง€๊ธด ํ–ˆ์ง€๋งŒ, ๊ทธ๋ž˜๋„ ์ปฌ๋ ‰์…˜์ด๋‚˜ ์ŠคํŠธ๋ฆผ๊ณผ ๊ฐ™์€ ๋ถ€๋ถ„์„ ์ œ๋Œ€๋กœ ๊ณต๋ถ€ํ•˜๊ณ  ์‹ถ์–ด์„œ์š”. ์ด๋Ÿฐ ์ž๋ฐ” ์„œ์ ์„ ํ•˜๋‚˜ ์ •ํ•˜์…”์„œ ๊ธฐ๋ณธ ๋ฌธ๋ฒ•์„ ์ •๋ฆฌํ•˜์‹œ๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์ง€๋Š” ๊ฒƒ๋„ ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค! ๐Ÿ˜„
@@ -0,0 +1,38 @@ +package christmas.util; + +import christmas.config.ErrorMessage; + +public class IntParser { + private static final int MAX_STRING_LENGTH = 11; + + private IntParser() { + // ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐฉ์ง€ + } + + public static int parseIntOrThrow(String numeric) { + validateNumericStringLength(numeric); + long parsed = parseLongOrThrow(numeric); + validateIntRange(parsed); + return Integer.parseInt(numeric); + } + + private static long parseLongOrThrow(String numeric) { + try { + return Long.parseLong(numeric); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage()); + } + } + + private static void validateNumericStringLength(String numeric) { + if (numeric.length() > MAX_STRING_LENGTH) { + throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage()); + } + } + + private static void validateIntRange(long number) { + if (number > Integer.MAX_VALUE || number < Integer.MIN_VALUE) { + throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage()); + } + } +}
Java
๋ชจ๋“  ๋ฉ”์„œ๋“œ๊ฐ€ `static`์ธ ์œ ํ‹ธ๋ฆฌํ‹ฐ์„ฑ ํด๋ž˜์Šค์˜ ๊ฒฝ์šฐ `new` ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ํ•„์š”๊ฐ€ ์ „ํ˜€ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ํ˜น์‹œ๋ผ๋„ ์˜๋„์น˜ ์•Š๊ฒŒ ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋  ๊ฒฝ์šฐ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์ƒ์„ฑ์ž๋ฅผ `private`์œผ๋กœ ์„ ์–ธํ–ˆ๊ณ , ๋นˆ ์ƒ์„ฑ์ž๋กœ ๊ทธ๋ƒฅ ๋‘๊ธด ์ข€ ๋ฐ‹๋ฐ‹ํ•ด์„œ ์ฃผ์„์„ ์‚ด์ง ๋‹ฌ์•„๋ดค์Šต๋‹ˆ๋‹ค! ๐Ÿ˜
@@ -0,0 +1,91 @@ +package christmas.view; + +import christmas.dto.BenefitDTO; +import christmas.dto.OrderDTO; + +import java.util.List; + +public class OutputView { + private void printMessage(ViewMessage message) { + System.out.println(message.getMessage()); + } + + private void printFormat(ViewMessage message, Object... args) { + System.out.printf(message.getMessage(), args); + newLine(); + } + + private void printTitle(ViewTitle title) { + System.out.println(title.getTitle()); + } + + public void printHelloMessage() { + printMessage(ViewMessage.HELLO); + } + + public void printEventPreviewTitle(int date) { + printFormat(ViewMessage.EVENT_PREVIEW_TITLE, date); + newLine(); + } + + public void printOrder(List<OrderDTO> orders) { + printTitle(ViewTitle.ORDER_MENU); + orders.forEach(it -> printFormat(ViewMessage.ORDER_FORMAT, it.menuName(), it.count())); + newLine(); + } + + public void printTotalPrice(int price) { + printTitle(ViewTitle.TOTAL_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, price); + newLine(); + } + + public void printGift(boolean hasGift) { + printTitle(ViewTitle.GIFT_MENU); + if (hasGift) { + printMessage(ViewMessage.CHAMPAGNE); + newLine(); + return; + } + printMessage(ViewMessage.NOTHING); + newLine(); + } + + public void printAllBenefit(List<BenefitDTO> benefits) { + printTitle(ViewTitle.BENEFIT_LIST); + if (benefits.isEmpty()) { + printMessage(ViewMessage.NOTHING); + newLine(); + return; + } + benefits.forEach(it -> printFormat(ViewMessage.BENEFIT_FORMAT, it.EventName(), it.price())); + newLine(); + } + + public void printBenefitPrice(int price) { + printTitle(ViewTitle.BENEFIT_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, -price); + newLine(); + } + + public void printAfterDiscountPrice(int price) { + printTitle(ViewTitle.AFTER_DISCOUNT_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, price); + newLine(); + } + + public void printBadge(String badge) { + printTitle(ViewTitle.BADGE); + System.out.println(badge); + } + + public void printErrorMessage(IllegalArgumentException error) { + newLine(); + System.out.println(error.getMessage()); + newLine(); + } + + public void newLine() { + System.out.println(); + } +}
Java
์ข‹์€ ์ง€์  ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! `lineSeperator()`์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ด์•ผ๊ฒ ๋„ค์š”! ๐Ÿ˜Š
@@ -0,0 +1,94 @@ +package christmas.domain; + +import christmas.config.Constant; +import christmas.dto.OrderDTO; +import christmas.config.ErrorMessage; +import christmas.config.MenuType; + +import java.util.ArrayList; +import java.util.List; + +public class Bill implements CheckEventDate { + private final List<Order> orders = new ArrayList<>(); + private final Date date; + + private Bill(Date date) { + this.date = date; + } + + public static Bill from(int date) { + return new Bill(Date.from(date)); + } + + public Bill add(Order order) { + validateDuplicates(order); + orders.add(order); + validateMaxOrder(); + return this; + } + + private void validateDuplicates(Order newOrder) { + long duplicated = orders.stream() + .filter(it -> it.isSameMenu(newOrder)) + .count(); + if (duplicated != Constant.FILTER_CONDITION) { + throw new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage()); + } + } + + private void validateMaxOrder() { + if (Order.accumulateCount(orders) > Constant.MAX_ORDER) { + throw new IllegalArgumentException(ErrorMessage.OVER_MAX_ORDER.getMessage()); + } + } + + public void validateOnlyDrink() { + if (Order.accumulateCount(orders) == getTypeCount(MenuType.DRINK)) { + throw new IllegalArgumentException(ErrorMessage.ONLY_DRINK_ORDER.getMessage()); + } + } + + public void clearOrder() { + orders.clear(); + } + + public int getTotalPrice() { + return orders.stream() + .map(Order::getPrice) + .reduce(Constant.INIT_VALUE, Integer::sum); + } + + public int getTypeCount(MenuType type) { + return Order.accumulateCount(orders, type); + } + + public List<OrderDTO> getAllOrders() { + return orders.stream().map(Order::getOrder).toList(); + } + + // ์•„๋ž˜๋Š” Date ๊ด€๋ จ method + + @Override + public boolean isWeekend() { + return date.isWeekend(); + } + + @Override + public boolean isSpecialDay() { + return date.isSpecialDay(); + } + + @Override + public boolean isNotPassedChristmas() { + return date.isNotPassedChristmas(); + } + + @Override + public int timePassedSinceFirstDay() { + return date.timePassedSinceFirstDay(); + } + + public int getDateValue() { + return date.getDateValue(); + } +}
Java
๊ทธ๋ ‡๊ฒŒ๋„ ํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”! ์•„์˜ˆ `Orders`๋ผ๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค! ๋ฆฌํŒฉํ† ๋ง ํ• ๋งŒํ•œ ๋ถ€๋ถ„๋“ค์„ ์งš์–ด์ฃผ์…”์„œ ์ข‹์Šต๋‹ˆ๋‹ค!! ๐Ÿ˜
@@ -0,0 +1,456 @@ +# ์ด๋ฉ”์ผ ๋‹ต์žฅ + +> ์ œ๋ชฉ: 12์›” ์ด๋ฒคํŠธ ๊ฐœ๋ฐœ ๋ณด๊ณ  + +> ๋ณด๋‚ธ ์‚ฌ๋žŒ: ๊ฐœ๋ฐœํŒ€ <`dev@woowacourse.io`> +> +> ๋ฐ›๋Š” ์‚ฌ๋žŒ: ๋น„์ฆˆ๋‹ˆ์ŠคํŒ€ <`biz@woowacourse.io`> + +์•ˆ๋…•ํ•˜์„ธ์š”. ๊ฐœ๋ฐœํŒ€์ž…๋‹ˆ๋‹ค! + +12์›” ์ด๋ฒคํŠธ ํ”Œ๋ž˜๋„ˆ ๊ฐœ๋ฐœ ์š”์ฒญ ์‚ฌํ•ญ์€ ์ž˜ ๋ฐ›์•„ ๋ณด์•˜์Šต๋‹ˆ๋‹ค. +์š”์ฒญํ•˜์‹  ๋‚ด์šฉ๋“ค์„ ๋ชจ๋‘ ์ ์šฉํ•ด๋ณด์•˜๋Š”๋ฐ์š”. ํ˜น์‹œ ๋ˆ„๋ฝ๋œ ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ๋ฐ”๋กœ ๋ง์”€ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +#### ๋ฐฉ๋ฌธ ๋‚ ์งœ ์ž…๋ ฅ + +- ๋ฐฉ๋ฌธ ๋‚ ์งœ๋Š” 1 ์ด์ƒ 31 ์ดํ•˜์˜ ์ˆซ์ž๋กœ๋งŒ ์ž…๋ ฅ๋ฐ›๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ๋‹จ, ์‚ฌ์šฉ์ž์˜ ๋ถ€์ฃผ์˜๋กœ ์ž…๋ ฅ ์•ž๋’ค๋กœ ๊ณต๋ฐฑ์ด ์ƒ๊ธฐ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ข…์ข… ์žˆ๋Š”๋ฐ, ์ด๋Š” ํ”„๋กœ๊ทธ๋žจ ๋‚ด๋ถ€์—์„œ ์ž๋™ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - " 12 " (O) + - " 1 2" (X) +- ์ด์™ธ์˜ ๋ชจ๋“  ์ž˜๋ชป๋œ ์ž…๋ ฅ์€ ์š”์ฒญํ•˜์‹  ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜จ ๋‹ค์Œ์—๋Š” ๋‹ค์‹œ ์žฌ์ž…๋ ฅ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + +#### ์ฃผ๋ฌธ ์ž…๋ ฅ + +- ๋ชจ๋“  ์ฃผ๋ฌธ์€ "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€-2,๋ ˆ๋“œ์™€์ธ-1,์ดˆ์ฝ”์ผ€์ดํฌ-1" ์™€ ๊ฐ™์€ ํ˜•์‹์œผ๋กœ๋งŒ ์ž…๋ ฅ๋ฐ›๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ๋‹จ, ์‚ฌ์šฉ์ž์˜ ๋ถ€์ฃผ์˜๋กœ ์ž…๋ ฅ ์‚ฌ์ด์— ๊ณต๋ฐฑ์ด ์ƒ๊ธฐ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ข…์ข… ์žˆ๋Š”๋ฐ, ์ด๋Š” ํ”„๋กœ๊ทธ๋žจ ๋‚ด๋ถ€์—์„œ ์ž๋™ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - ๋„์›Œ์“ฐ๊ธฐ๊ฐ€ ํฌํ•จ๋œ ๋ฉ”๋‰ด๊ฐ€ ์—†์–ด์„œ ์ž…๋ ฅ์˜ ๋ชจ๋“  ๊ณต๋ฐฑ์„ ํ—ˆ์šฉํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€ - 2, ๋ ˆ๋“œ์™€์ธ - 3" (O) + - "ํ•ด ์‚ฐ ๋ฌผ ํŒŒ ์Šค ํƒ€ - 1 2 , ๋ ˆ๋“œ์™€์ธ-3" (O) +- ๋ฉ”๋‰ด ํ˜•์‹์ด ์˜ˆ์‹œ์™€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€ 2, ๋ ˆ๋“œ์™€์ธ 3" (X) + - "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€: 2, ๋ ˆ๋“œ์™€์ธ: 3" (X) + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๋ฅผ 0 ์ดํ•˜์˜ ์ˆซ์ž๋กœ ์ž…๋ ฅํ•˜๋ฉด ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ์ค‘๋ณต ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ๋ฉ”๋‰ดํŒ์— ์—†๋Š” ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๊ฐ€ ํ•ฉ์ณ์„œ 20๊ฐœ๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์ถ”๊ฐ€) +- ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธ ์‹œ, ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์ถ”๊ฐ€) +- ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜จ ๋‹ค์Œ์—๋Š” ๋‹ค์‹œ ์ฃผ๋ฌธ์„ ์žฌ์ž…๋ ฅ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + +#### ์ด๋ฒคํŠธ + +- ๋ชจ๋“  ์ด๋ฒคํŠธ๋Š” 10,000์› ์ด์ƒ๋ถ€ํ„ฐ ์ ์šฉ๋˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ๋ชจ๋“  ์ด๋ฒคํŠธ๋Š” ์ ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์ค‘๋ณต์œผ๋กœ ์ ์šฉ๋˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.25 + - ํ• ์ธ ๊ธˆ์•ก: 2023.12.01 1,000์›์œผ๋กœ ์‹œ์ž‘ํ•˜์—ฌ, ๋งค์ผ ํ• ์ธ ๊ธˆ์•ก์ด 100์›์”ฉ ์ฆ๊ฐ€ + - ํ• ์ธ ๋ฐฉ๋ฒ•: ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก์—์„œ ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ +- ํ‰์ผ ํ• ์ธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ์ผ์š”์ผ ~ ๋ชฉ์š”์ผ + - ํ• ์ธ ๊ธˆ์•ก: 2,023์› + - ํ• ์ธ ๋ฐฉ๋ฒ•: ๋””์ €ํŠธ ๋ฉ”๋‰ด๋ฅผ ๊ฐœ๋‹น ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ +- ์ฃผ๋ง ํ• ์ธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ๊ธˆ์š”์ผ, ํ† ์š”์ผ + - ํ• ์ธ ๊ธˆ์•ก: 2,023์› + - ํ• ์ธ ๋ฐฉ๋ฒ•: ๋ฉ”์ธ ๋ฉ”๋‰ด๋ฅผ ๊ฐœ๋‹น ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ +- ํŠน๋ณ„ ํ• ์ธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ์ผ์š”์ผ, 12์›” 25์ผ + - ํ• ์ธ ๊ธˆ์•ก: 1,000์› + - ํ• ์ธ ๋ฐฉ๋ฒ•: ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์—์„œ ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ +- ์ฆ์ • ์ด๋ฒคํŠธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 + - ์ด๋ฒคํŠธ: ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์ด 12๋งŒ์› ์ด์ƒ์ผ ๋•Œ, ์ƒดํŽ˜์ธ 1๊ฐœ ์ฆ์ • (25,000์›) +- ์ฆ์ • ์ด๋ฒคํŠธ๋Š” ์ดํ˜œํƒ ๊ธˆ์•ก์—๋Š” ํฌํ•จ๋˜์ง€๋งŒ, ์‹ค์ œ ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก์—๋Š” ์ ์šฉ๋˜์ง€ ์•Š๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ๋‚˜๋จธ์ง€ ์ด๋ฒคํŠธ๋Š” ์ดํ˜œํƒ ๊ธˆ์•ก์—๋„ ํฌํ•จ๋˜๊ณ  ์‹ค์ œ ํ• ์ธ์—๋„ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค. + +#### ์ด๋ฒคํŠธ ๋ฐฐ์ง€ + +- 5์ฒœ์› ๋ฏธ๋งŒ: ์—†์Œ +- 5์ฒœ์› ์ด์ƒ: ๋ณ„ +- 1๋งŒ์› ์ด์ƒ: ํŠธ๋ฆฌ +- 2๋งŒ์› ์ด์ƒ: ์‚ฐํƒ€ + +#### ๊ฒฐ๊ณผ ์ถœ๋ ฅ + +- ์ž…๋ ฅํ•œ ์ฃผ๋ฌธ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ์ฆ์ • ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ์ฆ์ • ๋ฉ”๋‰ด๊ฐ€ ์—†์œผ๋ฉด "์—†์Œ"์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ํ˜œํƒ ๋‚ด์—ญ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ํ˜œํƒ์ด ์—†์œผ๋ฉด "์—†์Œ"์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ์ดํ˜œํƒ ๊ธˆ์•ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ํ˜œํƒ์ด ์—†์œผ๋ฉด 0์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ๋ฐ›์„ ๋ฐฐ์ง€๊ฐ€ ์—†์œผ๋ฉด "์—†์Œ"์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. + +๊ฐœ๋ฐœํŒ€ ๋‚ด๋ถ€์—์„œ ์—ฌ๋Ÿฌ ์ƒํ™ฉ์„ ๊ณ ๋ คํ•ด์„œ ๋งŽ์€ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. +ํ•˜์ง€๋งŒ ๊ทธ๋Ÿผ์—๋„ ๋ฒ„๊ทธ๊ฐ€ ์žˆ๊ฑฐ๋‚˜ ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์€ ๊ธฐ๋Šฅ์ด ์žˆ์œผ์‹œ๋‹ค๋ฉด ๋ฐ”๋กœ ๋ง์”€ํ•ด์ฃผ์„ธ์š”. + +ํŠนํžˆ ์ƒˆ๋กœ์šด ์ด๋ฒคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜, ์ƒˆ๋กœ์šด ๋ฉ”๋‰ด๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฑด ์–ธ์ œ๋“  ํ™˜์˜์ž…๋‹ˆ๋‹ค! +ํ™•์žฅ์„ฑ์žˆ๊ฒŒ ์„ค๊ณ„๋ฅผ ํ•ด๋‘์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ํŽธํ•˜๊ฒŒ ์š”์ฒญํ•˜์…”๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค! + +๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :) + +--- + +# ์ด๋ฒคํŠธ ๋‚ด์šฉ + +## ์ด๋ฒคํŠธ ์ข…๋ฅ˜ + +### ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.25 + +ํ• ์ธ ๊ธˆ์•ก: 2023.12.01 1,000์›์œผ๋กœ ์‹œ์ž‘ํ•˜์—ฌ, ๋งค์ผ ํ• ์ธ ๊ธˆ์•ก์ด 100์›์”ฉ ์ฆ๊ฐ€ + +ํ• ์ธ ๋ฐฉ๋ฒ•: ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก์—์„œ ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ + +### ํ‰์ผ ํ• ์ธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ์ผ์š”์ผ ~ ๋ชฉ์š”์ผ + +ํ• ์ธ ๊ธˆ์•ก: 2,023์› + +ํ• ์ธ ๋ฐฉ๋ฒ•: ๋””์ €ํŠธ ๋ฉ”๋‰ด๋ฅผ ๊ฐœ๋‹น ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ + +### ์ฃผ๋ง ํ• ์ธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ๊ธˆ์š”์ผ, ํ† ์š”์ผ + +ํ• ์ธ ๊ธˆ์•ก: 2,023์› + +ํ• ์ธ ๋ฐฉ๋ฒ•: ๋ฉ”์ธ ๋ฉ”๋‰ด๋ฅผ ๊ฐœ๋‹น ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ + +### ํŠน๋ณ„ ํ• ์ธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ์ผ์š”์ผ, 12์›” 25์ผ + +ํ• ์ธ ๊ธˆ์•ก: 1,000์› + +ํ• ์ธ ๋ฐฉ๋ฒ•: ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์—์„œ ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ + +### ์ฆ์ • ์ด๋ฒคํŠธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 + +์ด๋ฒคํŠธ: ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์ด 12๋งŒ์› ์ด์ƒ์ผ ๋•Œ, ์ƒดํŽ˜์ธ 1๊ฐœ ์ฆ์ • (25,000์›) + +## ์ด๋ฒคํŠธ ๋ฐฐ์ง€ + +์ด๋ฒคํŠธ๋กœ ๋ฐ›์€ ์ดํ˜œํƒ ๊ธˆ์•ก์— ๋”ฐ๋ผ ๊ฐ๊ธฐ ๋‹ค๋ฅธ ์ด๋ฒคํŠธ ๋ฐฐ์ง€๋ฅผ ๋ถ€์—ฌ +(์ด๋•Œ `์ดํ˜œํƒ ๊ธˆ์•ก = ํ• ์ธ ๊ธˆ์•ก์˜ ํ•ฉ๊ณ„ + ์ฆ์ • ๋ฉ”๋‰ด์˜ ๊ฐ€๊ฒฉ`์œผ๋กœ ๊ณ„์‚ฐ) + +- 5์ฒœ์› ์ด์ƒ: ๋ณ„ +- 1๋งŒ์› ์ด์ƒ: ํŠธ๋ฆฌ +- 2๋งŒ์› ์ด์ƒ: ์‚ฐํƒ€ + +## ์ด๋ฒคํŠธ ์ฃผ์˜ ์‚ฌํ•ญ + +- ์ด์ฃผ๋ฌธ ๊ธˆ์•ก 10,000์› ์ด์ƒ๋ถ€ํ„ฐ ์ด๋ฒคํŠธ๊ฐ€ ์ ์šฉ +- ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธ ์‹œ, ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Œ +- ๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Œ (์ข…๋ฅ˜๊ฐ€ ์•„๋‹Œ ๊ฐœ์ˆ˜) + +# ๊ฐœ๋ฐœ ์š”์ฒญ ์‚ฌํ•ญ + +- [x] ๋ฐฉ๋ฌธํ•  ๋‚ ์งœ ์ž…๋ ฅ + - [x] 1 ์ด์ƒ 31 ์ดํ•˜์˜ ์ˆซ์ž๋งŒ ์ž…๋ ฅ๋ฐ›์Œ +- [x] ์ฃผ๋ฌธํ•  ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ž…๋ ฅ + - [x] ๋ฉ”๋‰ดํŒ์— ์žˆ๋Š” ๋ฉ”๋‰ด๋งŒ ์ž…๋ ฅ๋ฐ›์Œ + - [x] ์ •ํ•ด์ง„ ํ˜•์‹์˜ ๋ฉ”๋‰ด๋งŒ ์ž…๋ ฅ๋ฐ›์Œ + - [x] ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๋Š” 1 ์ด์ƒ์˜ ์ˆซ์ž๋งŒ ์ž…๋ ฅ๋ฐ›์Œ + - [x] ์ค‘๋ณต๋˜์ง€ ์•Š์€ ๋ฉ”๋‰ด๋งŒ ์ž…๋ ฅ๋ฐ›์Œ +- [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด ์ถœ๋ ฅ + - [x] ์ถœ๋ ฅ ์ˆœ์„œ๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถœ๋ ฅ +- [x] ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก ์ถœ๋ ฅ +- [x] ์ฆ์ • ๋ฉ”๋‰ด ์ถœ๋ ฅ + - [x] ์ฆ์ • ์ด๋ฒคํŠธ์— ํ•ด๋‹นํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ `์—†์Œ` ์ถœ๋ ฅ +- [x] ํ˜œํƒ ๋‚ด์—ญ ์ถœ๋ ฅ + - [x] ๊ณ ๊ฐ์—๊ฒŒ ์ ์šฉ๋œ ์ด๋ฒคํŠธ ๋‚ด์—ญ๋งŒ ์ถœ๋ ฅ + - [x] ์ ์šฉ๋œ ์ด๋ฒคํŠธ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ `์—†์Œ` ์ถœ๋ ฅ + - [x] ์ด๋ฒคํŠธ ์ถœ๋ ฅ ์ˆœ์„œ๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถœ๋ ฅ +- [x] ์ดํ˜œํƒ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] `์ดํ˜œํƒ ๊ธˆ์•ก = ํ• ์ธ ๊ธˆ์•ก์˜ ํ•ฉ๊ณ„ + ์ฆ์ • ๋ฉ”๋‰ด์˜ ๊ฐ€๊ฒฉ` +- [x] ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] `ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก = ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก - ํ• ์ธ๊ธˆ์•ก` +- [x] 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ์ถœ๋ ฅ + - [x] ์ด๋ฒคํŠธ ๋ฐฐ์ง€๊ฐ€ ๋ถ€์—ฌ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ `์—†์Œ` ์ถœ๋ ฅ + +# ์ž…๋ ฅ ์˜ˆ์™ธ ์‚ฌํ•ญ + +- [x] ๋ฐฉ๋ฌธํ•  ๋‚ ์งœ ์ž…๋ ฅ ์˜ˆ์™ธ + - [x] 1 ์ด์ƒ 31 ์ดํ•˜์˜ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- [x] ์ฃผ๋ฌธํ•  ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ž…๋ ฅ + - [x] ๋ฉ”๋‰ดํŒ์— ์—†๋Š” ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) + - [x] ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๊ฐ€ 1 ์ด์ƒ์˜ ์ •์ˆ˜๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) + - [x] ๋ฉ”๋‰ด์˜ ํ˜•์‹์ด ์ •ํ•ด์ง„ ํ˜•์‹์„ ๋ฒ—์–ด๋‚œ ๊ฒฝ์šฐ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) + - [x] ์ค‘๋ณต ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) + - [x] ๋ฉ”๋‰ด ๊ฐœ์ˆ˜๊ฐ€ 20๊ฐœ๋ฅผ ์ดˆ๊ณผํ•œ ๊ฒฝ์šฐ + - `[ERROR] ๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์ถ”๊ฐ€) + - [x] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•œ ๊ฒฝ์šฐ + - `[ERROR] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์ถ”๊ฐ€) +- ์ด์™ธ ๋ชจ๋“  ์˜ˆ์™ธ ์‚ฌํ•ญ์— `[ERROR]` Prefix ์‚ฌ์šฉ + +# ๊ธฐ๋Šฅ ๋ช…์„ธ + +## Config + +- [x] Menu + - [x] ๋ฉ”๋‰ด ์ด๋ฆ„์œผ๋กœ Menu ์ฐพ์•„ ๋ฐ˜ํ™˜ +- [x] MenuType +- [x] ErrorMessage + +## Controller + +- [x] EventController + - [x] ๋‚ ์งœ๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ `Bill`์„ ์ƒ์„ฑ + - [x] ์ฃผ๋ฌธ์„ ์ž…๋ ฅ๋ฐ›์•„ `Bill`์— ์ถ”๊ฐ€ + - [x] ์œ„ ๋‘ ๊ณผ์ • ์ค‘ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ ๋ฐ˜๋ณตํ•˜์—ฌ ์ž…๋ ฅ๋ฐ›์Œ + - [x] ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + +## Domain + +- [x] Order + - [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด์™€ ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰์„ ์ €์žฅ + - [x] 1์ด์ƒ์˜ ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰๋งŒ ์‚ฌ์šฉํ•˜๋„๋ก ๊ฒ€์ฆ + - [x] ๊ฐ€๊ฒฉ(`๋ฉ”๋‰ด ๊ฐ€๊ฒฉ x ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰`)์„ ๋ฐ˜ํ™˜ + - [x] ํŠน์ • `Order`์™€ ๊ฐ™์€ ๋ฉ”๋‰ด์ธ์ง€ ํ™•์ธ + - [x] `OrderDTO` ๋ฐ˜ํ™˜ + - [x] `List<Order>`์˜ ๋ชจ๋“  ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰์„ ๋ˆ„์ ํ•˜์—ฌ ํ•ฉ์‚ฐ + - [x] `MenuType`์„ ์กฐ๊ฑด์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์˜ค๋ฒ„๋กœ๋”ฉ +- [x] Bill + - [x] ์ฃผ๋ฌธ ๋ฆฌ์ŠคํŠธ์™€ ๋‚ ์งœ๋ฅผ ์ €์žฅ + - [x] ์ฃผ๋ฌธ์„ ์ถ”๊ฐ€ + - [x] ์ค‘๋ณต๋˜๋Š” ๋ฉ”๋‰ด๊ฐ€ ์žˆ๋Š” ์ฃผ๋ฌธ์ธ์ง€ ๊ฒ€์ฆ + - [x] ์ตœ๋Œ€ ์ฃผ๋ฌธ์ˆ˜๋ฅผ ๋„˜์ง€ ์•Š๋Š”์ง€ ๊ฒ€์ฆ + - [x] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ–ˆ๋Š”์ง€ ๊ฒ€์ฆ + - [x] ์ฃผ๋ฌธ์„ ์ดˆ๊ธฐํ™” + - [x] ์ „์ฒด ์ฃผ๋ฌธ ๊ธˆ์•ก์„ ๊ณ„์‚ฐ + - [x] ํŠน์ • ํƒ€์ž…์˜ ๋ฉ”๋‰ด ์ฃผ๋ฌธ๋Ÿ‰์„ ๋ฐ˜ํ™˜ + - [x] `CheckEventDate`์˜ ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋กœ๋”ฉ + - [x] ์ฃผ๋ฌธ ๋‚ ์งœ๋ฅผ ๋ฐ˜ํ™˜ +- [x] Date + - [x] ์ƒ์„ฑ์„ ์œ„ํ•œ ๋‚ ์งœ๊ฐ€ 1 ~ 31 ๋ฒ”์œ„์˜ ๊ฐ’์ธ์ง€ ๊ฒ€์ฆ + - [x] ์š”์ผ์„ ํ™•์ธ + - [x] ์ฃผ๋ง์ธ์ง€ ํ™•์ธ -> ํ‰์ผ ํ• ์ธ, ์ฃผ๋ง ํ• ์ธ + - [x] ๋‹ฌ๋ ฅ์— ๋ณ„์ด ์žˆ๋Š” ํŠน๋ณ„ํ•œ ๋‚ ์ธ์ง€ ํ™•์ธ -> ํŠน๋ณ„ ํ• ์ธ + - [x] ํฌ๋ฆฌ์Šค๋งˆ์Šค ์ด์ „์ธ์ง€ ํ™•์ธ -> ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + - [x] ์ฒซ์งธ๋‚ ๋กœ๋ถ€ํ„ฐ ์–ผ๋งˆ๋‚˜ ์ง€๋‚ฌ๋Š”์ง€ ํ™•์ธ -> ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + - [x] ๋‚ ์งœ๋ฅผ ๋ฐ˜ํ™˜ +- [x] EventHandler + - [x] ์ฆ์ • ๋ฉ”๋‰ด(์ƒดํŽ˜์ธ) ์กด์žฌ ์—ฌ๋ถ€ + - [x] ํ˜œํƒ ๋‚ด์—ญ + - [x] ํ• ์ธ ๊ธˆ์•ก + - [x] ์ดํ˜œํƒ ๊ธˆ์•ก +- [x] Event + - [x] ์ด๋ฒคํŠธ ์กฐ๊ฑด์— ๋งž๋Š”์ง€ ํ™•์ธ + - [x] ์ด๋ฒคํŠธ ํ˜œํƒ์„ ๋ฐ˜ํ™˜ +- [x] Badge + - [x] ๊ฐ€๊ฒฉ์— ๋งž๋Š” ์ด๋ฒคํŠธ ๋ฐฐ์ง€๋ฅผ ๋ฐ˜ํ™˜ + +## DTO + +- [x] BenefitDTO -> ํ˜œํƒ ์ด๋ฆ„, ํ˜œํƒ ๊ธˆ์•ก์„ ์ „๋‹ฌํ•˜๋Š” ๊ฐ์ฒด +- [x] OrderDTO -> ๋ฉ”๋‰ด ์ด๋ฆ„, ์ฃผ๋ฌธ ๊ฐœ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฐ์ฒด + +## View + +- [x] InputView + - [x] ๋‚ ์งœ ์ž…๋ ฅ + - [x] ์ฃผ๋ฌธ ์ž…๋ ฅ +- [x] OutputView + - [x] ๊ฐ ์ œ๋ชฉ ์ถœ๋ ฅ + - [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด ์ถœ๋ ฅ + - [x] ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ์ฆ์ • ๋ฉ”๋‰ด ์ถœ๋ ฅ + - [x] ํ˜œํƒ ๋‚ด์—ญ ์ถœ๋ ฅ + - [x] ์ดํ˜œํƒ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ์ถœ๋ ฅ +- [x] ViewMessage +- [x] ViewTitle + +## Util + +- [x] IntParser +- [x] OrderParser +- [x] RetryExecutor + +# ํ…Œ์ŠคํŠธ ์ฝ”๋“œ + +- [x] Badge + - [x] `getBadgeNameWithBenefitPrice` ๋™์ž‘ ํ™•์ธ + - [x] 0 -> ์—†์Œ + - [x] 2500 -> ์—†์Œ + - [x] 5000 -> ๋ณ„ + - [x] 9000 -> ๋ณ„ + - [x] 10000 -> ํŠธ๋ฆฌ + - [x] 17000 -> ํŠธ๋ฆฌ + - [x] 20000 -> ์‚ฐํƒ€ + - [x] 50000 -> ์‚ฐํƒ€ +- [x] Bill + - [x] `from` ๋™์ž‘ ํ™•์ธ + - [x] ์ž˜๋ชป๋œ date ๊ฐ’ ์‚ฌ์šฉ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ -> Date ํด๋ž˜์Šค์—์„œ ํ…Œ์ŠคํŠธ + - [x] `add` ๋™์ž‘ ํ™•์ธ + - [x] `add` ์ค‘๋ณต๋œ ๋ฉ”๋‰ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] `add` 20๊ฐœ ์ด์ƒ ๋ฉ”๋‰ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] ์—ฌ๋Ÿฌ ๋ฉ”๋‰ด์˜ ์ด ์ˆ˜๋Ÿ‰์ด 20๊ฐœ ์ด์ƒ์ธ ๊ฒฝ์šฐ + - [x] ํ•œ ๋ฉ”๋‰ด์˜ ์ˆ˜๋Ÿ‰์ด 20๊ฐœ ์ด์ƒ์ธ ๊ฒฝ์šฐ + - [x] `clearOrder` ๋™์ž‘ ํ™•์ธ + - [x] `getTotalPrice` ๋™์ž‘ ํ™•์ธ + - [x] `getTypeCount` ๋™์ž‘ ํ™•์ธ + - [x] DESSERT ํƒ€์ž… ํ™•์ธ + - [x] MAIN ํƒ€์ž… ํ™•์ธ + - [x] `getDateValue` ๋™์ž‘ ํ™•์ธ + - [x] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•œ ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] ์ด์™ธ์˜ Date ๊ด€๋ จ ๋ฉ”์„œ๋“œ๋Š” Date ํด๋ž˜์Šค์—์„œ ํ…Œ์ŠคํŠธ +- [x] Date + - [x] ์ƒ์„ฑ ์‹œ `validate` ๋™์ž‘ ํ™•์ธ + - [x] 1 -> ๋™์ž‘ + - [x] 25 -> ๋™์ž‘ + - [x] 31 -> ๋™์ž‘ + - [x] ์ƒ์„ฑ ์‹œ `validate` ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] -5 -> ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] 0 -> ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] 32 -> ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] 75 -> ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] `isWeekend` ๋™์ž‘ ํ™•์ธ + - [x] 1 -> true + - [x] 8 -> true + - [x] 16 -> true + - [x] 17 -> false + - [x] 25 -> false + - [x] 28 -> false + - [x] `isSpecialDay` ๋™์ž‘ ํ™•์ธ + - [x] 3 -> true + - [x] 25 -> true + - [x] 31 -> true + - [x] 13 -> false + - [x] 22 -> false + - [x] `isNotPassedChristmas` ๋™์ž‘ ํ™•์ธ + - [x] 1 -> true + - [x] 14 -> true + - [x] 25 -> true + - [x] 26 -> false + - [x] 31 -> false + - [x] `timePassedSinceFirstDay` ๋™์ž‘ ํ™•์ธ + - [x] 1 -> 0 + - [x] 18 -> 17 + - [x] 25 -> 24 +- [x] Event + - [x] `getEventName` ๋™์ž‘ ํ™•์ธ + - [x] `isDiscount` ๋™์ž‘ ํ™•์ธ + - [x] `checkCondition` ๋™์ž‘ ํ™•์ธ + - [x] ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ -> `isNotPassedChristmas`์—์„œ ํ…Œ์ŠคํŠธ + - [x] ํ‰์ผ ํ• ์ธ -> `isWeekend`์—์„œ ํ…Œ์ŠคํŠธ + - [x] ์ฃผ๋ง ํ• ์ธ -> `isWeekend`์—์„œ ํ…Œ์ŠคํŠธ + - [x] ํŠน๋ณ„ ํ• ์ธ -> `isSpecialDay`์—์„œ ํ…Œ์ŠคํŠธ + - [x] ์ฆ์ • ์ด๋ฒคํŠธ + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) = 120,000 -> true + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์‹œ์ €์ƒ๋Ÿฌ๋“œ(5) = 150,000 -> true + - [x] ๋ฐ”๋น„ํ๋ฆฝ(1) + ์–‘์†ก์ด์ˆ˜ํ”„(1) = 60,000 -> false + - [x] `getBenefit` ๋™์ž‘ ํ™•์ธ + - [x] ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + - [x] 1 -> 1000 + - [x] 11 -> 2000 + - [x] 25 -> 3400 + - [x] ํ‰์ผ ํ• ์ธ + - [x] ์–‘์†ก์ด์ˆ˜ํ”„(1) + ๋ฐ”๋น„ํ๋ฆฝ(1) -> 0 + - [x] ํƒ€ํŒŒ์Šค(1) + ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(1) + ์ดˆ์ฝ”์ผ€์ดํฌ(2) -> 4046 + - [x] ๋ฐ”๋น„ํ๋ฆฝ(2) + ์ดˆ์ฝ”์ผ€์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(3) -> 10115 + - [x] ์ฃผ๋ง ํ• ์ธ + - [x] ์–‘์†ก์ด์ˆ˜ํ”„(2) + ์ œ๋กœ์ฝœ๋ผ(2) -> 0 + - [x] ํƒ€ํŒŒ์Šค(1) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) -> 2023 + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ๋ฐ”๋น„ํ๋ฆฝ(2) + ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(3) + ์ œ๋กœ์ฝœ๋ผ(6) -> 12138 + - [x] ํŠน๋ณ„ ํ• ์ธ -> ํ•ญ์ƒ 1000 + - [x] ์ฆ์ • ์ด๋ฒคํŠธ -> ํ•ญ์ƒ 25000 + - [x] ๋ชจ๋“  ์ด๋ฒคํŠธ์—์„œ ์ด์ฃผ๋ฌธ๊ธˆ์•ก 10000์› ์ด์ƒ๋ถ€ํ„ฐ ์ด๋ฒคํŠธ ์ ์šฉ +- [x] EventHandler + - [x] `hasChampagneGift` ๋™์ž‘ ํ™•์ธ -> Event `checkCondition`์—์„œ ํ…Œ์ŠคํŠธ + - [x] `getTotalDiscountPrice` ๋™์ž‘ ํ™•์ธ + - [x] 1์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 5046 + - [x] 3์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 10292 + - [x] 13์ผ, ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(10) + ์ดˆ์ฝ”์ผ€์ดํฌ(1) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 8269 + - [x] 25์ผ, ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€(2) + ์ƒดํŽ˜์ธ(2) -> 4400 + - [x] 30์ผ, ์‹œ์ €์ƒ๋Ÿฌ๋“œ(5) + ๋ฐ”๋น„ํ๋ฆฝ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ๋ ˆ๋“œ์™€์ธ(2) -> 6069 + - [x] `getTotalBenefitPrice` ๋™์ž‘ ํ™•์ธ + - [x] 1์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 30046 + - [x] 3์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 10292 + - [x] 13์ผ, ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(10) + ์ดˆ์ฝ”์ผ€์ดํฌ(1) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 33269 + - [x] 25์ผ, ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€(2) + ์ƒดํŽ˜์ธ(2) -> 4400 + - [x] 30์ผ, ์‹œ์ €์ƒ๋Ÿฌ๋“œ(5) + ๋ฐ”๋น„ํ๋ฆฝ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ๋ ˆ๋“œ์™€์ธ(2) -> 31069 + - [x] `getAllBenefit` ๋™์ž‘ ํ™•์ธ + - [x] 1์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(1) -> ํฌ๋ฆฌ์Šค๋งˆ์Šค(1000), ์ฃผ๋ง(4046) + - [x] 3์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ์•„์ด์Šคํฌ๋ฆผ(4) -> ํฌ๋ฆฌ์Šค๋งˆ์Šค(1200), ํ‰์ผ(8092), ํŠน๋ณ„(1000) + - [x] 13์ผ, ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(10) + ์ดˆ์ฝ”์ผ€์ดํฌ(1) + ์•„์ด์Šคํฌ๋ฆผ(2) -> ํฌ๋ฆฌ์Šค๋งˆ์Šค(2200), ํ‰์ผ(6069), ์ฆ์ •(25000) + - [x] 25์ผ, ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€(2) + ์ƒดํŽ˜์ธ(2) -> ํฌ๋ฆฌ์Šค๋งˆ์Šค(3400), ํŠน๋ณ„(1000) + - [x] 30์ผ, ์‹œ์ €์ƒ๋Ÿฌ๋“œ(5) + ๋ฐ”๋น„ํ๋ฆฝ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ๋ ˆ๋“œ์™€์ธ(2) -> ์ฃผ๋ง(6069), ์ฆ์ •(25000) +- [x] Order + - [x] `create` ๋™์ž‘ ํ™•์ธ + - [x] ์ž˜๋ชป๋œ ๋ฉ”๋‰ด ์ด๋ฆ„ ์‚ฌ์šฉ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ -> Menu ํด๋ž˜์Šค์—์„œ ํ…Œ์ŠคํŠธ + - [x] ์ž˜๋ชป๋œ count ์‚ฌ์šฉ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] `getPrice` ๋™์ž‘ ํ™•์ธ + - [x] ํƒ€ํŒŒ์Šค(2) -> 11000 + - [x] ๋ฐ”๋น„ํ๋ฆฝ(3) -> 162000 + - [x] ์•„์ด์Šคํฌ๋ฆผ(5) -> 25000 + - [x] `isSameMenu` ๋™์ž‘ ํ™•์ธ + - [x] ํƒ€ํŒŒ์Šค, ํƒ€ํŒŒ์Šค -> true + - [x] ๋ ˆ๋“œ์™€์ธ, ๋ ˆ๋“œ์™€์ธ -> true + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ, ์•„์ด์Šคํฌ๋ฆผ -> false + - [x] ์ดˆ์ฝ”์ผ€์ดํฌ, ๋ฐ”๋น„ํ๋ฆฝ -> false + - [x] `accumulateCount` ๋™์ž‘ ํ™•์ธ + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(5) -> 5 + - [x] ์–‘์†ก์ด์ˆ˜ํ”„(3) + ๋ฐ”๋น„ํ๋ฆฝ(1) + ์•„์ด์Šคํฌ๋ฆผ(3) -> 7 + - [x] `accumulateCount` type ์‚ฌ์šฉํ•˜์—ฌ ๋™์ž‘ ํ™•์ธ + - [x] DESSERT, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์ œ๋กœ์ฝœ๋ผ(4) -> 0 + - [x] MAIN, ์–‘์†ก์ด์Šคํ”„(3) + ๋ฐ”๋น„ํ๋ฆฝ(1) + ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(2) + ์•„์ด์Šคํฌ๋ฆผ(5) -> 3 +- [x] Menu + - [x] `from` ๋™์ž‘ ํ™•์ธ + - [x] ์–‘์†ก์ด์ˆ˜ํ”„ -> Menu.SOUP + - [x] ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€ -> Menu.SEAFOOD_PASTA + - [x] ๋ฉ”๋‰ดํŒ์— ์—†๋Š” ๋ฉ”๋‰ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ํ™•์ธ +- [x] IntParser + - [x] `parseIntOrThrow` ๋™์ž‘ ํ™•์ธ + - [x] "123" -> 123 + - [x] "-123" -> -123 + - [x] "2147483647" -> 2147483647 (์ตœ๋Œ“๊ฐ’) + - [x] "-2147483648" -> -2147483648 (์ตœ์†Ÿ๊ฐ’) + - [x] ์ •์ˆ˜ํ˜•ํƒœ๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž์—ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] ABC + - [x] 12L + - [x] 13.5 + - [x] Integer ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚œ ๋ฌธ์ž์—ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] 2147483648 + - [x] -2147483649 + - [x] 999999999999999 +- [x] OrderParser + - [x] `parseOrderOrThrow` ๋™์ž‘ ํ™•์ธ + - [x] "ํƒ€ํŒŒ์Šค-1,์ œ๋กœ์ฝœ๋ผ-2,ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-5" -> ํƒ€ํŒŒ์Šค(1) + ์ œ๋กœ์ฝœ๋ผ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(5) + - [x] "ํƒ€ํŒŒ์Šค - 1, ์ œ๋กœ์ฝœ๋ผ- 2, ํ‹ฐ๋ณธ ์Šคํ…Œ์ดํฌ -5" -> ํƒ€ํŒŒ์Šค(1) + ์ œ๋กœ์ฝœ๋ผ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(5) + - [x] "ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-1" -> ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + - [x] "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€-3 , " -> ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(3) + - [x] ์ž˜๋ชป๋œ ํ˜•์‹์˜ ์ฃผ๋ฌธ์„ ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] "ํƒ€ํŒŒ์Šค: 1, ์ œ๋กœ์ฝœ๋ผ: 2" + - [x] "ํƒ€ํŒŒ์Šค-1 ์ œ๋กœ์ฝœ๋ผ-2 ํŒŒ์Šคํƒ€-3" + - [x] "ํƒ€ํŒŒ์Šค 1 ์ œ๋กœ์ฝœ๋ผ 2 ํŒŒ์Šคํƒ€ 3" + - [x] "ํƒ€ํŒŒ์Šค, ์ œ๋กœ์ฝœ๋ผ, ํŒŒ์Šคํƒ€" + - [x] "ํƒ€ํŒŒ์Šค -" + - [x] "- 3" +- [x] OutputView + - [x] `printHelloMessage` ๋™์ž‘ ํ™•์ธ + - [x] `printEventPreviewTitle` ๋™์ž‘ ํ™•์ธ + - [x] `printOrder` ๋™์ž‘ ํ™•์ธ + - [x] `printTotalPrice` ๋™์ž‘ ํ™•์ธ + - [x] `printGift` ๋™์ž‘ ํ™•์ธ + - [x] `printAllBenefit` ๋™์ž‘ ํ™•์ธ + - [x] `printBenefitPrice` ๋™์ž‘ ํ™•์ธ + - [x] `printAfterDiscountPrice` ๋™์ž‘ ํ™•์ธ + - [x] `printBadge` ๋™์ž‘ ํ™•์ธ
Unknown
Readme.md ๋ฅผ ๊ผผ๊ผผํžˆ ์ž˜ ์ž‘์„ฑํ•˜์‹  ๊ฒƒ ๊ฐ™์•„์š”๐Ÿ˜„
@@ -0,0 +1,47 @@ +package christmas.config; + +import java.util.Arrays; + +public enum Menu { + SOUP("์–‘์†ก์ด์ˆ˜ํ”„", 6000, MenuType.APPETIZER), + TAPAS("ํƒ€ํŒŒ์Šค", 5500, MenuType.APPETIZER), + SALAD("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 8000, MenuType.APPETIZER), + STEAK("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 55000, MenuType.MAIN), + BARBECUE("๋ฐ”๋น„ํ๋ฆฝ", 54000, MenuType.MAIN), + SEAFOOD_PASTA("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 35000, MenuType.MAIN), + CHRISTMAS_PASTA("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 25000, MenuType.MAIN), + CAKE("์ดˆ์ฝ”์ผ€์ดํฌ", 15000, MenuType.DESSERT), + ICE_CREAM("์•„์ด์Šคํฌ๋ฆผ", 5000, MenuType.DESSERT), + COLA("์ œ๋กœ์ฝœ๋ผ", 3000, MenuType.DRINK), + WINE("๋ ˆ๋“œ์™€์ธ", 60000, MenuType.DRINK), + CHAMPAGNE("์ƒดํŽ˜์ธ", 25000, MenuType.DRINK); + + private final String menuName; + private final int price; + private final MenuType type; + + Menu(String menuName, int price, MenuType type) { + this.menuName = menuName; + this.price = price; + this.type = type; + } + + public static Menu from(String menuName) { + return Arrays.stream(Menu.values()) + .filter(it -> menuName.equals(it.menuName)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage())); + } + + public String getMenuName() { + return menuName; + } + + public int getPrice() { + return price; + } + + public MenuType getType() { + return type; + } +}
Java
์ €๋„ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๋Š”๋ฐ Menu์˜ ํ™•์žฅ์„ฑ์„ ์ƒ๊ฐํ•ด์„œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์นดํ…Œ๊ณ ๋ฆฌ์— ํฌํ•จ๋  ์ˆ˜๋„ ์žˆ๋Š” ์ ์„ ์ƒ๊ฐํ•˜์—ฌ ์นดํ…Œ๊ณ ๋ฆฌ๋Š” ๋”ฐ๋กœ ๋นผ๋Š”๊ฒŒ ์ข‹๋‹ค๋Š” ์˜๊ฒฌ์„ ๋ดค์Šต๋‹ˆ๋‹ค! ์ฟ ํ‚ค๋‹˜์€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”?
@@ -0,0 +1,18 @@ +package christmas.util; + +import java.util.function.Consumer; + +public class RetryExecutor { + private RetryExecutor() { + // ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐฉ์ง€ + } + + public static void execute(Runnable action, Consumer<IllegalArgumentException> onError) { + try { + action.run(); + } catch (IllegalArgumentException error) { + onError.accept(error); + execute(action, onError); + } + } +}
Java
Retry๋ฅผ ์ €๋Š” Controller์—์„œ while๋ฌธ์œผ๋กœ ํ•˜์—ฌ ์ง€์ €๋ถ„ํ•œ ๊ฒƒ์ด ๊ณ ๋ฏผ์ด์—ˆ๋Š”๋ฐ ์ด๋Ÿฐ ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ๋„ค์š”! ๋ฐฐ์›Œ ๊ฐ‘๋‹ˆ๋‹ค!!
@@ -0,0 +1,91 @@ +package christmas.view; + +import christmas.dto.BenefitDTO; +import christmas.dto.OrderDTO; + +import java.util.List; + +public class OutputView { + private void printMessage(ViewMessage message) { + System.out.println(message.getMessage()); + } + + private void printFormat(ViewMessage message, Object... args) { + System.out.printf(message.getMessage(), args); + newLine(); + } + + private void printTitle(ViewTitle title) { + System.out.println(title.getTitle()); + } + + public void printHelloMessage() { + printMessage(ViewMessage.HELLO); + } + + public void printEventPreviewTitle(int date) { + printFormat(ViewMessage.EVENT_PREVIEW_TITLE, date); + newLine(); + } + + public void printOrder(List<OrderDTO> orders) { + printTitle(ViewTitle.ORDER_MENU); + orders.forEach(it -> printFormat(ViewMessage.ORDER_FORMAT, it.menuName(), it.count())); + newLine(); + } + + public void printTotalPrice(int price) { + printTitle(ViewTitle.TOTAL_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, price); + newLine(); + } + + public void printGift(boolean hasGift) { + printTitle(ViewTitle.GIFT_MENU); + if (hasGift) { + printMessage(ViewMessage.CHAMPAGNE); + newLine(); + return; + } + printMessage(ViewMessage.NOTHING); + newLine(); + } + + public void printAllBenefit(List<BenefitDTO> benefits) { + printTitle(ViewTitle.BENEFIT_LIST); + if (benefits.isEmpty()) { + printMessage(ViewMessage.NOTHING); + newLine(); + return; + } + benefits.forEach(it -> printFormat(ViewMessage.BENEFIT_FORMAT, it.EventName(), it.price())); + newLine(); + } + + public void printBenefitPrice(int price) { + printTitle(ViewTitle.BENEFIT_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, -price); + newLine(); + } + + public void printAfterDiscountPrice(int price) { + printTitle(ViewTitle.AFTER_DISCOUNT_PRICE); + printFormat(ViewMessage.PRICE_FORMAT, price); + newLine(); + } + + public void printBadge(String badge) { + printTitle(ViewTitle.BADGE); + System.out.println(badge); + } + + public void printErrorMessage(IllegalArgumentException error) { + newLine(); + System.out.println(error.getMessage()); + newLine(); + } + + public void newLine() { + System.out.println(); + } +}
Java
์ €๋Š” ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” newLine()์„ static์œผ๋กœ ์„ ์–ธํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ๋ง์”€๋“œ๋ฆฌ๋ ค ํ–ˆ๋Š”๋ฐ lineSeperator() ๋ผ๋Š”๊ฒŒ ์žˆ์—ˆ๊ตฐ์š”! ์ €๋„ ๋ฐฐ์›Œ๊ฐ€๊ฒ ์Šต๋‹ˆ๋‹ค๐Ÿ˜Š
@@ -0,0 +1,12 @@ +package christmas.config; + +public class Constant { + public static final int INIT_VALUE = 0; + public static final int FILTER_CONDITION = 0; + public static final int MIN_ORDER = 1; + public static final int MAX_ORDER = 20; + + private Constant() { + // ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐฉ์ง€ + } +}
Java
๊ฐœ์ธ์ ์œผ๋กœ Constant ํด๋ž˜์Šค์— ์ƒ์ˆ˜๋“ค์„ ๋ชจ์•„๋„ฃ๋Š” ๊ฒƒ ๋ณด๋‹ค๋Š” ๊ฐ ํด๋ž˜์Šค์— ํ•„์š”ํ•œ Constant ํด๋ž˜์Šค๋ฅผ ๊ฐ๊ฐ ๋งŒ๋“ค์–ด์„œ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์˜๋ฏธ๋ฅผ ๋” ๋ช…ํ™•ํžˆํ•˜๊ณ  ์•Œ์•„๋ณด๊ธฐ ์‰ฌ์šด ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,145 @@ +package christmas.domain; + +import christmas.dto.OrderDTO; +import christmas.config.ErrorMessage; +import christmas.config.MenuType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; + +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class BillTest { + @DisplayName("์ž˜๋ชป๋œ date ๊ฐ’ ์‚ฌ์šฉ ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ") + @ParameterizedTest + @ValueSource(ints = {-5, 0, 32, 75}) + void checkCreateFromWrongDate(int date) { + assertThatThrownBy(() -> Bill.from(date)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(ErrorMessage.WRONG_DATE.getMessage()); + } + + @DisplayName("add ๋™์ž‘ ํ™•์ธ") + @Test + void checkAddMethod() { + Bill bill = Bill.from(1) + .add(Order.create("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 3)) + .add(Order.create("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 1)) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 2)); + + List<OrderDTO> answer = List.of( + new OrderDTO("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 3), + new OrderDTO("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 1), + new OrderDTO("์ œ๋กœ์ฝœ๋ผ", 2) + ); + + assertThat(bill.getAllOrders()).isEqualTo(answer); + } + + @DisplayName("์ค‘๋ณต๋œ ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ") + @Test + void checkDuplicatedMenu() { + assertThatThrownBy(() -> Bill.from(1) + .add(Order.create("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 2)) + .add(Order.create("๋ฐ”๋น„ํ๋ฆฝ", 1)) + .add(Order.create("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 3)) + ).isInstanceOf(IllegalArgumentException.class).hasMessage(ErrorMessage.WRONG_ORDER.getMessage()); + } + + @DisplayName("๋ฉ”๋‰ด๊ฐ€ 20๊ฐœ๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ") + @ParameterizedTest + @MethodSource("overedOrder") + void checkOverOrder(List<Order> orders) { + Bill bill = Bill.from(1); + + assertThatThrownBy(() -> orders.forEach(bill::add)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(ErrorMessage.OVER_MAX_ORDER.getMessage()); + } + + static Stream<Arguments> overedOrder() { + return Stream.of( + Arguments.of(List.of( + Order.create("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 7), + Order.create("์ œ๋กœ์ฝœ๋ผ", 15) + )), + Arguments.of(List.of( + Order.create("์•„์ด์Šคํฌ๋ฆผ", 25) + )) + ); + } + + @DisplayName("clearOrder ๋™์ž‘ ํ™•์ธ") + @Test + void checkClearOrder() { + Bill bill = Bill.from(1) + .add(Order.create("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 3)) + .add(Order.create("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 1)) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 2)); + bill.clearOrder(); + assertThat(bill.getAllOrders()).isEqualTo(List.of()); + } + + @DisplayName("getTotalPrice ๋™์ž‘ ํ™•์ธ") + @Test + void checkTotalPrice() { + Bill bill = Bill.from(1) + .add(Order.create("ํƒ€ํŒŒ์Šค", 2)) + .add(Order.create("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 1)) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 2)); + assertThat(bill.getTotalPrice()).isEqualTo(72000); + } + + @DisplayName("getTypeCount ๋™์ž‘ ํ™•์ธ") + @ParameterizedTest + @MethodSource("typedBill") + void checkTypeCount(Bill bill, MenuType type, int answer) { + assertThat(bill.getTypeCount(type)).isEqualTo(answer); + } + + static Stream<Arguments> typedBill() { + return Stream.of( + Arguments.of( + Bill.from(1) + .add(Order.create("์–‘์†ก์ด์ˆ˜ํ”„", 3)) + .add(Order.create("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 1)) + .add(Order.create("๋ฐ”๋น„ํ๋ฆฝ", 2)), + MenuType.MAIN, + 3 + ), + Arguments.of( + Bill.from(1) + .add(Order.create("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 2)) + .add(Order.create("์ดˆ์ฝ”์ผ€์ดํฌ", 2)) + .add(Order.create("์•„์ด์Šคํฌ๋ฆผ", 3)) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 7)), + MenuType.DESSERT, + 5 + ) + ); + } + + @DisplayName("getDateValue ๋™์ž‘ ํ™•์ธ") + @ParameterizedTest + @ValueSource(ints = {1, 17, 25, 31}) + void checkDateValue(int date) { + assertThat(Bill.from(date).getDateValue()).isEqualTo(date); + } + + @DisplayName("์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•œ ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ") + @Test + void checkOnlyDrinkOrder() { + assertThatThrownBy(() -> Bill.from(1) + .add(Order.create("์ œ๋กœ์ฝœ๋ผ", 3)) + .add(Order.create("๋ ˆ๋“œ์™€์ธ", 1)) + .validateOnlyDrink() + ).isInstanceOf(IllegalArgumentException.class).hasMessage(ErrorMessage.ONLY_DRINK_ORDER.getMessage()); + } +}
Java
๋™์ž‘ ํ™•์ธ ๋ณด๋‹ค๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์ ์–ด์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š” ํƒ€ํŒŒ์Šค 2๊ฐœ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ 1๊ฐœ, ์ œ๋กœ์ฝœ๋ผ 2๊ฐœ์˜ ํ† ํƒˆ ์ฃผ๋ฌธ ๊ธˆ์•ก 72000์›์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค . ์•ฝ๊ฐ„ ์ด๋Ÿฐ์‹์œผ๋กœ?
@@ -0,0 +1,456 @@ +# ์ด๋ฉ”์ผ ๋‹ต์žฅ + +> ์ œ๋ชฉ: 12์›” ์ด๋ฒคํŠธ ๊ฐœ๋ฐœ ๋ณด๊ณ  + +> ๋ณด๋‚ธ ์‚ฌ๋žŒ: ๊ฐœ๋ฐœํŒ€ <`dev@woowacourse.io`> +> +> ๋ฐ›๋Š” ์‚ฌ๋žŒ: ๋น„์ฆˆ๋‹ˆ์ŠคํŒ€ <`biz@woowacourse.io`> + +์•ˆ๋…•ํ•˜์„ธ์š”. ๊ฐœ๋ฐœํŒ€์ž…๋‹ˆ๋‹ค! + +12์›” ์ด๋ฒคํŠธ ํ”Œ๋ž˜๋„ˆ ๊ฐœ๋ฐœ ์š”์ฒญ ์‚ฌํ•ญ์€ ์ž˜ ๋ฐ›์•„ ๋ณด์•˜์Šต๋‹ˆ๋‹ค. +์š”์ฒญํ•˜์‹  ๋‚ด์šฉ๋“ค์„ ๋ชจ๋‘ ์ ์šฉํ•ด๋ณด์•˜๋Š”๋ฐ์š”. ํ˜น์‹œ ๋ˆ„๋ฝ๋œ ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ๋ฐ”๋กœ ๋ง์”€ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. + +#### ๋ฐฉ๋ฌธ ๋‚ ์งœ ์ž…๋ ฅ + +- ๋ฐฉ๋ฌธ ๋‚ ์งœ๋Š” 1 ์ด์ƒ 31 ์ดํ•˜์˜ ์ˆซ์ž๋กœ๋งŒ ์ž…๋ ฅ๋ฐ›๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ๋‹จ, ์‚ฌ์šฉ์ž์˜ ๋ถ€์ฃผ์˜๋กœ ์ž…๋ ฅ ์•ž๋’ค๋กœ ๊ณต๋ฐฑ์ด ์ƒ๊ธฐ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ข…์ข… ์žˆ๋Š”๋ฐ, ์ด๋Š” ํ”„๋กœ๊ทธ๋žจ ๋‚ด๋ถ€์—์„œ ์ž๋™ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - " 12 " (O) + - " 1 2" (X) +- ์ด์™ธ์˜ ๋ชจ๋“  ์ž˜๋ชป๋œ ์ž…๋ ฅ์€ ์š”์ฒญํ•˜์‹  ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜จ ๋‹ค์Œ์—๋Š” ๋‹ค์‹œ ์žฌ์ž…๋ ฅ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + +#### ์ฃผ๋ฌธ ์ž…๋ ฅ + +- ๋ชจ๋“  ์ฃผ๋ฌธ์€ "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€-2,๋ ˆ๋“œ์™€์ธ-1,์ดˆ์ฝ”์ผ€์ดํฌ-1" ์™€ ๊ฐ™์€ ํ˜•์‹์œผ๋กœ๋งŒ ์ž…๋ ฅ๋ฐ›๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ๋‹จ, ์‚ฌ์šฉ์ž์˜ ๋ถ€์ฃผ์˜๋กœ ์ž…๋ ฅ ์‚ฌ์ด์— ๊ณต๋ฐฑ์ด ์ƒ๊ธฐ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ข…์ข… ์žˆ๋Š”๋ฐ, ์ด๋Š” ํ”„๋กœ๊ทธ๋žจ ๋‚ด๋ถ€์—์„œ ์ž๋™ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - ๋„์›Œ์“ฐ๊ธฐ๊ฐ€ ํฌํ•จ๋œ ๋ฉ”๋‰ด๊ฐ€ ์—†์–ด์„œ ์ž…๋ ฅ์˜ ๋ชจ๋“  ๊ณต๋ฐฑ์„ ํ—ˆ์šฉํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€ - 2, ๋ ˆ๋“œ์™€์ธ - 3" (O) + - "ํ•ด ์‚ฐ ๋ฌผ ํŒŒ ์Šค ํƒ€ - 1 2 , ๋ ˆ๋“œ์™€์ธ-3" (O) +- ๋ฉ”๋‰ด ํ˜•์‹์ด ์˜ˆ์‹œ์™€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€ 2, ๋ ˆ๋“œ์™€์ธ 3" (X) + - "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€: 2, ๋ ˆ๋“œ์™€์ธ: 3" (X) + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๋ฅผ 0 ์ดํ•˜์˜ ์ˆซ์ž๋กœ ์ž…๋ ฅํ•˜๋ฉด ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ์ค‘๋ณต ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ๋ฉ”๋‰ดํŒ์— ์—†๋Š” ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๊ฐ€ ํ•ฉ์ณ์„œ 20๊ฐœ๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์ถ”๊ฐ€) +- ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธ ์‹œ, ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์ด๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + - `[ERROR] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์ถ”๊ฐ€) +- ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜จ ๋‹ค์Œ์—๋Š” ๋‹ค์‹œ ์ฃผ๋ฌธ์„ ์žฌ์ž…๋ ฅ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. + +#### ์ด๋ฒคํŠธ + +- ๋ชจ๋“  ์ด๋ฒคํŠธ๋Š” 10,000์› ์ด์ƒ๋ถ€ํ„ฐ ์ ์šฉ๋˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ๋ชจ๋“  ์ด๋ฒคํŠธ๋Š” ์ ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์ค‘๋ณต์œผ๋กœ ์ ์šฉ๋˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.25 + - ํ• ์ธ ๊ธˆ์•ก: 2023.12.01 1,000์›์œผ๋กœ ์‹œ์ž‘ํ•˜์—ฌ, ๋งค์ผ ํ• ์ธ ๊ธˆ์•ก์ด 100์›์”ฉ ์ฆ๊ฐ€ + - ํ• ์ธ ๋ฐฉ๋ฒ•: ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก์—์„œ ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ +- ํ‰์ผ ํ• ์ธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ์ผ์š”์ผ ~ ๋ชฉ์š”์ผ + - ํ• ์ธ ๊ธˆ์•ก: 2,023์› + - ํ• ์ธ ๋ฐฉ๋ฒ•: ๋””์ €ํŠธ ๋ฉ”๋‰ด๋ฅผ ๊ฐœ๋‹น ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ +- ์ฃผ๋ง ํ• ์ธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ๊ธˆ์š”์ผ, ํ† ์š”์ผ + - ํ• ์ธ ๊ธˆ์•ก: 2,023์› + - ํ• ์ธ ๋ฐฉ๋ฒ•: ๋ฉ”์ธ ๋ฉ”๋‰ด๋ฅผ ๊ฐœ๋‹น ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ +- ํŠน๋ณ„ ํ• ์ธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ์ผ์š”์ผ, 12์›” 25์ผ + - ํ• ์ธ ๊ธˆ์•ก: 1,000์› + - ํ• ์ธ ๋ฐฉ๋ฒ•: ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์—์„œ ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ +- ์ฆ์ • ์ด๋ฒคํŠธ + - ๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 + - ์ด๋ฒคํŠธ: ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์ด 12๋งŒ์› ์ด์ƒ์ผ ๋•Œ, ์ƒดํŽ˜์ธ 1๊ฐœ ์ฆ์ • (25,000์›) +- ์ฆ์ • ์ด๋ฒคํŠธ๋Š” ์ดํ˜œํƒ ๊ธˆ์•ก์—๋Š” ํฌํ•จ๋˜์ง€๋งŒ, ์‹ค์ œ ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก์—๋Š” ์ ์šฉ๋˜์ง€ ์•Š๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. +- ๋‚˜๋จธ์ง€ ์ด๋ฒคํŠธ๋Š” ์ดํ˜œํƒ ๊ธˆ์•ก์—๋„ ํฌํ•จ๋˜๊ณ  ์‹ค์ œ ํ• ์ธ์—๋„ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค. + +#### ์ด๋ฒคํŠธ ๋ฐฐ์ง€ + +- 5์ฒœ์› ๋ฏธ๋งŒ: ์—†์Œ +- 5์ฒœ์› ์ด์ƒ: ๋ณ„ +- 1๋งŒ์› ์ด์ƒ: ํŠธ๋ฆฌ +- 2๋งŒ์› ์ด์ƒ: ์‚ฐํƒ€ + +#### ๊ฒฐ๊ณผ ์ถœ๋ ฅ + +- ์ž…๋ ฅํ•œ ์ฃผ๋ฌธ ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ์ฆ์ • ๋ฉ”๋‰ด๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ์ฆ์ • ๋ฉ”๋‰ด๊ฐ€ ์—†์œผ๋ฉด "์—†์Œ"์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ํ˜œํƒ ๋‚ด์—ญ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ํ˜œํƒ์ด ์—†์œผ๋ฉด "์—†์Œ"์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ์ดํ˜œํƒ ๊ธˆ์•ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ํ˜œํƒ์ด ์—†์œผ๋ฉด 0์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ๋ฐ›์„ ๋ฐฐ์ง€๊ฐ€ ์—†์œผ๋ฉด "์—†์Œ"์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. + +๊ฐœ๋ฐœํŒ€ ๋‚ด๋ถ€์—์„œ ์—ฌ๋Ÿฌ ์ƒํ™ฉ์„ ๊ณ ๋ คํ•ด์„œ ๋งŽ์€ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. +ํ•˜์ง€๋งŒ ๊ทธ๋Ÿผ์—๋„ ๋ฒ„๊ทธ๊ฐ€ ์žˆ๊ฑฐ๋‚˜ ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์€ ๊ธฐ๋Šฅ์ด ์žˆ์œผ์‹œ๋‹ค๋ฉด ๋ฐ”๋กœ ๋ง์”€ํ•ด์ฃผ์„ธ์š”. + +ํŠนํžˆ ์ƒˆ๋กœ์šด ์ด๋ฒคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜, ์ƒˆ๋กœ์šด ๋ฉ”๋‰ด๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฑด ์–ธ์ œ๋“  ํ™˜์˜์ž…๋‹ˆ๋‹ค! +ํ™•์žฅ์„ฑ์žˆ๊ฒŒ ์„ค๊ณ„๋ฅผ ํ•ด๋‘์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ํŽธํ•˜๊ฒŒ ์š”์ฒญํ•˜์…”๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค! + +๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :) + +--- + +# ์ด๋ฒคํŠธ ๋‚ด์šฉ + +## ์ด๋ฒคํŠธ ์ข…๋ฅ˜ + +### ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.25 + +ํ• ์ธ ๊ธˆ์•ก: 2023.12.01 1,000์›์œผ๋กœ ์‹œ์ž‘ํ•˜์—ฌ, ๋งค์ผ ํ• ์ธ ๊ธˆ์•ก์ด 100์›์”ฉ ์ฆ๊ฐ€ + +ํ• ์ธ ๋ฐฉ๋ฒ•: ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก์—์„œ ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ + +### ํ‰์ผ ํ• ์ธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ์ผ์š”์ผ ~ ๋ชฉ์š”์ผ + +ํ• ์ธ ๊ธˆ์•ก: 2,023์› + +ํ• ์ธ ๋ฐฉ๋ฒ•: ๋””์ €ํŠธ ๋ฉ”๋‰ด๋ฅผ ๊ฐœ๋‹น ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ + +### ์ฃผ๋ง ํ• ์ธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ๊ธˆ์š”์ผ, ํ† ์š”์ผ + +ํ• ์ธ ๊ธˆ์•ก: 2,023์› + +ํ• ์ธ ๋ฐฉ๋ฒ•: ๋ฉ”์ธ ๋ฉ”๋‰ด๋ฅผ ๊ฐœ๋‹น ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ + +### ํŠน๋ณ„ ํ• ์ธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 ์ค‘ ๋งค์ฃผ ์ผ์š”์ผ, 12์›” 25์ผ + +ํ• ์ธ ๊ธˆ์•ก: 1,000์› + +ํ• ์ธ ๋ฐฉ๋ฒ•: ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์—์„œ ํ• ์ธ ๊ธˆ์•ก๋งŒํผ ํ• ์ธ + +### ์ฆ์ • ์ด๋ฒคํŠธ + +๊ธฐ๊ฐ„: 2023.12.01 ~ 2023.12.31 + +์ด๋ฒคํŠธ: ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก์ด 12๋งŒ์› ์ด์ƒ์ผ ๋•Œ, ์ƒดํŽ˜์ธ 1๊ฐœ ์ฆ์ • (25,000์›) + +## ์ด๋ฒคํŠธ ๋ฐฐ์ง€ + +์ด๋ฒคํŠธ๋กœ ๋ฐ›์€ ์ดํ˜œํƒ ๊ธˆ์•ก์— ๋”ฐ๋ผ ๊ฐ๊ธฐ ๋‹ค๋ฅธ ์ด๋ฒคํŠธ ๋ฐฐ์ง€๋ฅผ ๋ถ€์—ฌ +(์ด๋•Œ `์ดํ˜œํƒ ๊ธˆ์•ก = ํ• ์ธ ๊ธˆ์•ก์˜ ํ•ฉ๊ณ„ + ์ฆ์ • ๋ฉ”๋‰ด์˜ ๊ฐ€๊ฒฉ`์œผ๋กœ ๊ณ„์‚ฐ) + +- 5์ฒœ์› ์ด์ƒ: ๋ณ„ +- 1๋งŒ์› ์ด์ƒ: ํŠธ๋ฆฌ +- 2๋งŒ์› ์ด์ƒ: ์‚ฐํƒ€ + +## ์ด๋ฒคํŠธ ์ฃผ์˜ ์‚ฌํ•ญ + +- ์ด์ฃผ๋ฌธ ๊ธˆ์•ก 10,000์› ์ด์ƒ๋ถ€ํ„ฐ ์ด๋ฒคํŠธ๊ฐ€ ์ ์šฉ +- ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธ ์‹œ, ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Œ +- ๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Œ (์ข…๋ฅ˜๊ฐ€ ์•„๋‹Œ ๊ฐœ์ˆ˜) + +# ๊ฐœ๋ฐœ ์š”์ฒญ ์‚ฌํ•ญ + +- [x] ๋ฐฉ๋ฌธํ•  ๋‚ ์งœ ์ž…๋ ฅ + - [x] 1 ์ด์ƒ 31 ์ดํ•˜์˜ ์ˆซ์ž๋งŒ ์ž…๋ ฅ๋ฐ›์Œ +- [x] ์ฃผ๋ฌธํ•  ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ž…๋ ฅ + - [x] ๋ฉ”๋‰ดํŒ์— ์žˆ๋Š” ๋ฉ”๋‰ด๋งŒ ์ž…๋ ฅ๋ฐ›์Œ + - [x] ์ •ํ•ด์ง„ ํ˜•์‹์˜ ๋ฉ”๋‰ด๋งŒ ์ž…๋ ฅ๋ฐ›์Œ + - [x] ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๋Š” 1 ์ด์ƒ์˜ ์ˆซ์ž๋งŒ ์ž…๋ ฅ๋ฐ›์Œ + - [x] ์ค‘๋ณต๋˜์ง€ ์•Š์€ ๋ฉ”๋‰ด๋งŒ ์ž…๋ ฅ๋ฐ›์Œ +- [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด ์ถœ๋ ฅ + - [x] ์ถœ๋ ฅ ์ˆœ์„œ๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถœ๋ ฅ +- [x] ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก ์ถœ๋ ฅ +- [x] ์ฆ์ • ๋ฉ”๋‰ด ์ถœ๋ ฅ + - [x] ์ฆ์ • ์ด๋ฒคํŠธ์— ํ•ด๋‹นํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ `์—†์Œ` ์ถœ๋ ฅ +- [x] ํ˜œํƒ ๋‚ด์—ญ ์ถœ๋ ฅ + - [x] ๊ณ ๊ฐ์—๊ฒŒ ์ ์šฉ๋œ ์ด๋ฒคํŠธ ๋‚ด์—ญ๋งŒ ์ถœ๋ ฅ + - [x] ์ ์šฉ๋œ ์ด๋ฒคํŠธ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ `์—†์Œ` ์ถœ๋ ฅ + - [x] ์ด๋ฒคํŠธ ์ถœ๋ ฅ ์ˆœ์„œ๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถœ๋ ฅ +- [x] ์ดํ˜œํƒ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] `์ดํ˜œํƒ ๊ธˆ์•ก = ํ• ์ธ ๊ธˆ์•ก์˜ ํ•ฉ๊ณ„ + ์ฆ์ • ๋ฉ”๋‰ด์˜ ๊ฐ€๊ฒฉ` +- [x] ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] `ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก = ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก - ํ• ์ธ๊ธˆ์•ก` +- [x] 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ์ถœ๋ ฅ + - [x] ์ด๋ฒคํŠธ ๋ฐฐ์ง€๊ฐ€ ๋ถ€์—ฌ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ `์—†์Œ` ์ถœ๋ ฅ + +# ์ž…๋ ฅ ์˜ˆ์™ธ ์‚ฌํ•ญ + +- [x] ๋ฐฉ๋ฌธํ•  ๋‚ ์งœ ์ž…๋ ฅ ์˜ˆ์™ธ + - [x] 1 ์ด์ƒ 31 ์ดํ•˜์˜ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) +- [x] ์ฃผ๋ฌธํ•  ๋ฉ”๋‰ด์™€ ๊ฐœ์ˆ˜ ์ž…๋ ฅ + - [x] ๋ฉ”๋‰ดํŒ์— ์—†๋Š” ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) + - [x] ๋ฉ”๋‰ด์˜ ๊ฐœ์ˆ˜๊ฐ€ 1 ์ด์ƒ์˜ ์ •์ˆ˜๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) + - [x] ๋ฉ”๋‰ด์˜ ํ˜•์‹์ด ์ •ํ•ด์ง„ ํ˜•์‹์„ ๋ฒ—์–ด๋‚œ ๊ฒฝ์šฐ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) + - [x] ์ค‘๋ณต ๋ฉ”๋‰ด๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - `[ERROR] ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์š”์ฒญ ์‚ฌํ•ญ) + - [x] ๋ฉ”๋‰ด ๊ฐœ์ˆ˜๊ฐ€ 20๊ฐœ๋ฅผ ์ดˆ๊ณผํ•œ ๊ฒฝ์šฐ + - `[ERROR] ๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์ถ”๊ฐ€) + - [x] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•œ ๊ฒฝ์šฐ + - `[ERROR] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.` (์ถ”๊ฐ€) +- ์ด์™ธ ๋ชจ๋“  ์˜ˆ์™ธ ์‚ฌํ•ญ์— `[ERROR]` Prefix ์‚ฌ์šฉ + +# ๊ธฐ๋Šฅ ๋ช…์„ธ + +## Config + +- [x] Menu + - [x] ๋ฉ”๋‰ด ์ด๋ฆ„์œผ๋กœ Menu ์ฐพ์•„ ๋ฐ˜ํ™˜ +- [x] MenuType +- [x] ErrorMessage + +## Controller + +- [x] EventController + - [x] ๋‚ ์งœ๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ `Bill`์„ ์ƒ์„ฑ + - [x] ์ฃผ๋ฌธ์„ ์ž…๋ ฅ๋ฐ›์•„ `Bill`์— ์ถ”๊ฐ€ + - [x] ์œ„ ๋‘ ๊ณผ์ • ์ค‘ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ ๋ฐ˜๋ณตํ•˜์—ฌ ์ž…๋ ฅ๋ฐ›์Œ + - [x] ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + +## Domain + +- [x] Order + - [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด์™€ ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰์„ ์ €์žฅ + - [x] 1์ด์ƒ์˜ ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰๋งŒ ์‚ฌ์šฉํ•˜๋„๋ก ๊ฒ€์ฆ + - [x] ๊ฐ€๊ฒฉ(`๋ฉ”๋‰ด ๊ฐ€๊ฒฉ x ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰`)์„ ๋ฐ˜ํ™˜ + - [x] ํŠน์ • `Order`์™€ ๊ฐ™์€ ๋ฉ”๋‰ด์ธ์ง€ ํ™•์ธ + - [x] `OrderDTO` ๋ฐ˜ํ™˜ + - [x] `List<Order>`์˜ ๋ชจ๋“  ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰์„ ๋ˆ„์ ํ•˜์—ฌ ํ•ฉ์‚ฐ + - [x] `MenuType`์„ ์กฐ๊ฑด์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์˜ค๋ฒ„๋กœ๋”ฉ +- [x] Bill + - [x] ์ฃผ๋ฌธ ๋ฆฌ์ŠคํŠธ์™€ ๋‚ ์งœ๋ฅผ ์ €์žฅ + - [x] ์ฃผ๋ฌธ์„ ์ถ”๊ฐ€ + - [x] ์ค‘๋ณต๋˜๋Š” ๋ฉ”๋‰ด๊ฐ€ ์žˆ๋Š” ์ฃผ๋ฌธ์ธ์ง€ ๊ฒ€์ฆ + - [x] ์ตœ๋Œ€ ์ฃผ๋ฌธ์ˆ˜๋ฅผ ๋„˜์ง€ ์•Š๋Š”์ง€ ๊ฒ€์ฆ + - [x] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ–ˆ๋Š”์ง€ ๊ฒ€์ฆ + - [x] ์ฃผ๋ฌธ์„ ์ดˆ๊ธฐํ™” + - [x] ์ „์ฒด ์ฃผ๋ฌธ ๊ธˆ์•ก์„ ๊ณ„์‚ฐ + - [x] ํŠน์ • ํƒ€์ž…์˜ ๋ฉ”๋‰ด ์ฃผ๋ฌธ๋Ÿ‰์„ ๋ฐ˜ํ™˜ + - [x] `CheckEventDate`์˜ ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋กœ๋”ฉ + - [x] ์ฃผ๋ฌธ ๋‚ ์งœ๋ฅผ ๋ฐ˜ํ™˜ +- [x] Date + - [x] ์ƒ์„ฑ์„ ์œ„ํ•œ ๋‚ ์งœ๊ฐ€ 1 ~ 31 ๋ฒ”์œ„์˜ ๊ฐ’์ธ์ง€ ๊ฒ€์ฆ + - [x] ์š”์ผ์„ ํ™•์ธ + - [x] ์ฃผ๋ง์ธ์ง€ ํ™•์ธ -> ํ‰์ผ ํ• ์ธ, ์ฃผ๋ง ํ• ์ธ + - [x] ๋‹ฌ๋ ฅ์— ๋ณ„์ด ์žˆ๋Š” ํŠน๋ณ„ํ•œ ๋‚ ์ธ์ง€ ํ™•์ธ -> ํŠน๋ณ„ ํ• ์ธ + - [x] ํฌ๋ฆฌ์Šค๋งˆ์Šค ์ด์ „์ธ์ง€ ํ™•์ธ -> ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + - [x] ์ฒซ์งธ๋‚ ๋กœ๋ถ€ํ„ฐ ์–ผ๋งˆ๋‚˜ ์ง€๋‚ฌ๋Š”์ง€ ํ™•์ธ -> ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + - [x] ๋‚ ์งœ๋ฅผ ๋ฐ˜ํ™˜ +- [x] EventHandler + - [x] ์ฆ์ • ๋ฉ”๋‰ด(์ƒดํŽ˜์ธ) ์กด์žฌ ์—ฌ๋ถ€ + - [x] ํ˜œํƒ ๋‚ด์—ญ + - [x] ํ• ์ธ ๊ธˆ์•ก + - [x] ์ดํ˜œํƒ ๊ธˆ์•ก +- [x] Event + - [x] ์ด๋ฒคํŠธ ์กฐ๊ฑด์— ๋งž๋Š”์ง€ ํ™•์ธ + - [x] ์ด๋ฒคํŠธ ํ˜œํƒ์„ ๋ฐ˜ํ™˜ +- [x] Badge + - [x] ๊ฐ€๊ฒฉ์— ๋งž๋Š” ์ด๋ฒคํŠธ ๋ฐฐ์ง€๋ฅผ ๋ฐ˜ํ™˜ + +## DTO + +- [x] BenefitDTO -> ํ˜œํƒ ์ด๋ฆ„, ํ˜œํƒ ๊ธˆ์•ก์„ ์ „๋‹ฌํ•˜๋Š” ๊ฐ์ฒด +- [x] OrderDTO -> ๋ฉ”๋‰ด ์ด๋ฆ„, ์ฃผ๋ฌธ ๊ฐœ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฐ์ฒด + +## View + +- [x] InputView + - [x] ๋‚ ์งœ ์ž…๋ ฅ + - [x] ์ฃผ๋ฌธ ์ž…๋ ฅ +- [x] OutputView + - [x] ๊ฐ ์ œ๋ชฉ ์ถœ๋ ฅ + - [x] ์ฃผ๋ฌธ ๋ฉ”๋‰ด ์ถœ๋ ฅ + - [x] ํ• ์ธ ์ „ ์ด์ฃผ๋ฌธ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ์ฆ์ • ๋ฉ”๋‰ด ์ถœ๋ ฅ + - [x] ํ˜œํƒ ๋‚ด์—ญ ์ถœ๋ ฅ + - [x] ์ดํ˜œํƒ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก ์ถœ๋ ฅ + - [x] ์ด๋ฒคํŠธ ๋ฐฐ์ง€ ์ถœ๋ ฅ +- [x] ViewMessage +- [x] ViewTitle + +## Util + +- [x] IntParser +- [x] OrderParser +- [x] RetryExecutor + +# ํ…Œ์ŠคํŠธ ์ฝ”๋“œ + +- [x] Badge + - [x] `getBadgeNameWithBenefitPrice` ๋™์ž‘ ํ™•์ธ + - [x] 0 -> ์—†์Œ + - [x] 2500 -> ์—†์Œ + - [x] 5000 -> ๋ณ„ + - [x] 9000 -> ๋ณ„ + - [x] 10000 -> ํŠธ๋ฆฌ + - [x] 17000 -> ํŠธ๋ฆฌ + - [x] 20000 -> ์‚ฐํƒ€ + - [x] 50000 -> ์‚ฐํƒ€ +- [x] Bill + - [x] `from` ๋™์ž‘ ํ™•์ธ + - [x] ์ž˜๋ชป๋œ date ๊ฐ’ ์‚ฌ์šฉ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ -> Date ํด๋ž˜์Šค์—์„œ ํ…Œ์ŠคํŠธ + - [x] `add` ๋™์ž‘ ํ™•์ธ + - [x] `add` ์ค‘๋ณต๋œ ๋ฉ”๋‰ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] `add` 20๊ฐœ ์ด์ƒ ๋ฉ”๋‰ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] ์—ฌ๋Ÿฌ ๋ฉ”๋‰ด์˜ ์ด ์ˆ˜๋Ÿ‰์ด 20๊ฐœ ์ด์ƒ์ธ ๊ฒฝ์šฐ + - [x] ํ•œ ๋ฉ”๋‰ด์˜ ์ˆ˜๋Ÿ‰์ด 20๊ฐœ ์ด์ƒ์ธ ๊ฒฝ์šฐ + - [x] `clearOrder` ๋™์ž‘ ํ™•์ธ + - [x] `getTotalPrice` ๋™์ž‘ ํ™•์ธ + - [x] `getTypeCount` ๋™์ž‘ ํ™•์ธ + - [x] DESSERT ํƒ€์ž… ํ™•์ธ + - [x] MAIN ํƒ€์ž… ํ™•์ธ + - [x] `getDateValue` ๋™์ž‘ ํ™•์ธ + - [x] ์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•œ ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] ์ด์™ธ์˜ Date ๊ด€๋ จ ๋ฉ”์„œ๋“œ๋Š” Date ํด๋ž˜์Šค์—์„œ ํ…Œ์ŠคํŠธ +- [x] Date + - [x] ์ƒ์„ฑ ์‹œ `validate` ๋™์ž‘ ํ™•์ธ + - [x] 1 -> ๋™์ž‘ + - [x] 25 -> ๋™์ž‘ + - [x] 31 -> ๋™์ž‘ + - [x] ์ƒ์„ฑ ์‹œ `validate` ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] -5 -> ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] 0 -> ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] 32 -> ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] 75 -> ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] `isWeekend` ๋™์ž‘ ํ™•์ธ + - [x] 1 -> true + - [x] 8 -> true + - [x] 16 -> true + - [x] 17 -> false + - [x] 25 -> false + - [x] 28 -> false + - [x] `isSpecialDay` ๋™์ž‘ ํ™•์ธ + - [x] 3 -> true + - [x] 25 -> true + - [x] 31 -> true + - [x] 13 -> false + - [x] 22 -> false + - [x] `isNotPassedChristmas` ๋™์ž‘ ํ™•์ธ + - [x] 1 -> true + - [x] 14 -> true + - [x] 25 -> true + - [x] 26 -> false + - [x] 31 -> false + - [x] `timePassedSinceFirstDay` ๋™์ž‘ ํ™•์ธ + - [x] 1 -> 0 + - [x] 18 -> 17 + - [x] 25 -> 24 +- [x] Event + - [x] `getEventName` ๋™์ž‘ ํ™•์ธ + - [x] `isDiscount` ๋™์ž‘ ํ™•์ธ + - [x] `checkCondition` ๋™์ž‘ ํ™•์ธ + - [x] ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ -> `isNotPassedChristmas`์—์„œ ํ…Œ์ŠคํŠธ + - [x] ํ‰์ผ ํ• ์ธ -> `isWeekend`์—์„œ ํ…Œ์ŠคํŠธ + - [x] ์ฃผ๋ง ํ• ์ธ -> `isWeekend`์—์„œ ํ…Œ์ŠคํŠธ + - [x] ํŠน๋ณ„ ํ• ์ธ -> `isSpecialDay`์—์„œ ํ…Œ์ŠคํŠธ + - [x] ์ฆ์ • ์ด๋ฒคํŠธ + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) = 120,000 -> true + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์‹œ์ €์ƒ๋Ÿฌ๋“œ(5) = 150,000 -> true + - [x] ๋ฐ”๋น„ํ๋ฆฝ(1) + ์–‘์†ก์ด์ˆ˜ํ”„(1) = 60,000 -> false + - [x] `getBenefit` ๋™์ž‘ ํ™•์ธ + - [x] ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ + - [x] 1 -> 1000 + - [x] 11 -> 2000 + - [x] 25 -> 3400 + - [x] ํ‰์ผ ํ• ์ธ + - [x] ์–‘์†ก์ด์ˆ˜ํ”„(1) + ๋ฐ”๋น„ํ๋ฆฝ(1) -> 0 + - [x] ํƒ€ํŒŒ์Šค(1) + ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(1) + ์ดˆ์ฝ”์ผ€์ดํฌ(2) -> 4046 + - [x] ๋ฐ”๋น„ํ๋ฆฝ(2) + ์ดˆ์ฝ”์ผ€์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(3) -> 10115 + - [x] ์ฃผ๋ง ํ• ์ธ + - [x] ์–‘์†ก์ด์ˆ˜ํ”„(2) + ์ œ๋กœ์ฝœ๋ผ(2) -> 0 + - [x] ํƒ€ํŒŒ์Šค(1) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) -> 2023 + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ๋ฐ”๋น„ํ๋ฆฝ(2) + ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(3) + ์ œ๋กœ์ฝœ๋ผ(6) -> 12138 + - [x] ํŠน๋ณ„ ํ• ์ธ -> ํ•ญ์ƒ 1000 + - [x] ์ฆ์ • ์ด๋ฒคํŠธ -> ํ•ญ์ƒ 25000 + - [x] ๋ชจ๋“  ์ด๋ฒคํŠธ์—์„œ ์ด์ฃผ๋ฌธ๊ธˆ์•ก 10000์› ์ด์ƒ๋ถ€ํ„ฐ ์ด๋ฒคํŠธ ์ ์šฉ +- [x] EventHandler + - [x] `hasChampagneGift` ๋™์ž‘ ํ™•์ธ -> Event `checkCondition`์—์„œ ํ…Œ์ŠคํŠธ + - [x] `getTotalDiscountPrice` ๋™์ž‘ ํ™•์ธ + - [x] 1์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 5046 + - [x] 3์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 10292 + - [x] 13์ผ, ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(10) + ์ดˆ์ฝ”์ผ€์ดํฌ(1) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 8269 + - [x] 25์ผ, ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€(2) + ์ƒดํŽ˜์ธ(2) -> 4400 + - [x] 30์ผ, ์‹œ์ €์ƒ๋Ÿฌ๋“œ(5) + ๋ฐ”๋น„ํ๋ฆฝ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ๋ ˆ๋“œ์™€์ธ(2) -> 6069 + - [x] `getTotalBenefitPrice` ๋™์ž‘ ํ™•์ธ + - [x] 1์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 30046 + - [x] 3์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 10292 + - [x] 13์ผ, ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(10) + ์ดˆ์ฝ”์ผ€์ดํฌ(1) + ์•„์ด์Šคํฌ๋ฆผ(2) -> 33269 + - [x] 25์ผ, ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€(2) + ์ƒดํŽ˜์ธ(2) -> 4400 + - [x] 30์ผ, ์‹œ์ €์ƒ๋Ÿฌ๋“œ(5) + ๋ฐ”๋น„ํ๋ฆฝ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ๋ ˆ๋“œ์™€์ธ(2) -> 31069 + - [x] `getAllBenefit` ๋™์ž‘ ํ™•์ธ + - [x] 1์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์•„์ด์Šคํฌ๋ฆผ(1) -> ํฌ๋ฆฌ์Šค๋งˆ์Šค(1000), ์ฃผ๋ง(4046) + - [x] 3์ผ, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ์•„์ด์Šคํฌ๋ฆผ(4) -> ํฌ๋ฆฌ์Šค๋งˆ์Šค(1200), ํ‰์ผ(8092), ํŠน๋ณ„(1000) + - [x] 13์ผ, ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(10) + ์ดˆ์ฝ”์ผ€์ดํฌ(1) + ์•„์ด์Šคํฌ๋ฆผ(2) -> ํฌ๋ฆฌ์Šค๋งˆ์Šค(2200), ํ‰์ผ(6069), ์ฆ์ •(25000) + - [x] 25์ผ, ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€(2) + ์ƒดํŽ˜์ธ(2) -> ํฌ๋ฆฌ์Šค๋งˆ์Šค(3400), ํŠน๋ณ„(1000) + - [x] 30์ผ, ์‹œ์ €์ƒ๋Ÿฌ๋“œ(5) + ๋ฐ”๋น„ํ๋ฆฝ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + ๋ ˆ๋“œ์™€์ธ(2) -> ์ฃผ๋ง(6069), ์ฆ์ •(25000) +- [x] Order + - [x] `create` ๋™์ž‘ ํ™•์ธ + - [x] ์ž˜๋ชป๋œ ๋ฉ”๋‰ด ์ด๋ฆ„ ์‚ฌ์šฉ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ -> Menu ํด๋ž˜์Šค์—์„œ ํ…Œ์ŠคํŠธ + - [x] ์ž˜๋ชป๋œ count ์‚ฌ์šฉ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] `getPrice` ๋™์ž‘ ํ™•์ธ + - [x] ํƒ€ํŒŒ์Šค(2) -> 11000 + - [x] ๋ฐ”๋น„ํ๋ฆฝ(3) -> 162000 + - [x] ์•„์ด์Šคํฌ๋ฆผ(5) -> 25000 + - [x] `isSameMenu` ๋™์ž‘ ํ™•์ธ + - [x] ํƒ€ํŒŒ์Šค, ํƒ€ํŒŒ์Šค -> true + - [x] ๋ ˆ๋“œ์™€์ธ, ๋ ˆ๋“œ์™€์ธ -> true + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ, ์•„์ด์Šคํฌ๋ฆผ -> false + - [x] ์ดˆ์ฝ”์ผ€์ดํฌ, ๋ฐ”๋น„ํ๋ฆฝ -> false + - [x] `accumulateCount` ๋™์ž‘ ํ™•์ธ + - [x] ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(5) -> 5 + - [x] ์–‘์†ก์ด์ˆ˜ํ”„(3) + ๋ฐ”๋น„ํ๋ฆฝ(1) + ์•„์ด์Šคํฌ๋ฆผ(3) -> 7 + - [x] `accumulateCount` type ์‚ฌ์šฉํ•˜์—ฌ ๋™์ž‘ ํ™•์ธ + - [x] DESSERT, ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(2) + ์ œ๋กœ์ฝœ๋ผ(4) -> 0 + - [x] MAIN, ์–‘์†ก์ด์Šคํ”„(3) + ๋ฐ”๋น„ํ๋ฆฝ(1) + ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(2) + ์•„์ด์Šคํฌ๋ฆผ(5) -> 3 +- [x] Menu + - [x] `from` ๋™์ž‘ ํ™•์ธ + - [x] ์–‘์†ก์ด์ˆ˜ํ”„ -> Menu.SOUP + - [x] ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€ -> Menu.SEAFOOD_PASTA + - [x] ๋ฉ”๋‰ดํŒ์— ์—†๋Š” ๋ฉ”๋‰ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ํ™•์ธ +- [x] IntParser + - [x] `parseIntOrThrow` ๋™์ž‘ ํ™•์ธ + - [x] "123" -> 123 + - [x] "-123" -> -123 + - [x] "2147483647" -> 2147483647 (์ตœ๋Œ“๊ฐ’) + - [x] "-2147483648" -> -2147483648 (์ตœ์†Ÿ๊ฐ’) + - [x] ์ •์ˆ˜ํ˜•ํƒœ๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž์—ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] ABC + - [x] 12L + - [x] 13.5 + - [x] Integer ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚œ ๋ฌธ์ž์—ด ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] 2147483648 + - [x] -2147483649 + - [x] 999999999999999 +- [x] OrderParser + - [x] `parseOrderOrThrow` ๋™์ž‘ ํ™•์ธ + - [x] "ํƒ€ํŒŒ์Šค-1,์ œ๋กœ์ฝœ๋ผ-2,ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-5" -> ํƒ€ํŒŒ์Šค(1) + ์ œ๋กœ์ฝœ๋ผ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(5) + - [x] "ํƒ€ํŒŒ์Šค - 1, ์ œ๋กœ์ฝœ๋ผ- 2, ํ‹ฐ๋ณธ ์Šคํ…Œ์ดํฌ -5" -> ํƒ€ํŒŒ์Šค(1) + ์ œ๋กœ์ฝœ๋ผ(2) + ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(5) + - [x] "ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-1" -> ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ(1) + - [x] "ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€-3 , " -> ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€(3) + - [x] ์ž˜๋ชป๋œ ํ˜•์‹์˜ ์ฃผ๋ฌธ์„ ์ž…๋ ฅ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ + - [x] "ํƒ€ํŒŒ์Šค: 1, ์ œ๋กœ์ฝœ๋ผ: 2" + - [x] "ํƒ€ํŒŒ์Šค-1 ์ œ๋กœ์ฝœ๋ผ-2 ํŒŒ์Šคํƒ€-3" + - [x] "ํƒ€ํŒŒ์Šค 1 ์ œ๋กœ์ฝœ๋ผ 2 ํŒŒ์Šคํƒ€ 3" + - [x] "ํƒ€ํŒŒ์Šค, ์ œ๋กœ์ฝœ๋ผ, ํŒŒ์Šคํƒ€" + - [x] "ํƒ€ํŒŒ์Šค -" + - [x] "- 3" +- [x] OutputView + - [x] `printHelloMessage` ๋™์ž‘ ํ™•์ธ + - [x] `printEventPreviewTitle` ๋™์ž‘ ํ™•์ธ + - [x] `printOrder` ๋™์ž‘ ํ™•์ธ + - [x] `printTotalPrice` ๋™์ž‘ ํ™•์ธ + - [x] `printGift` ๋™์ž‘ ํ™•์ธ + - [x] `printAllBenefit` ๋™์ž‘ ํ™•์ธ + - [x] `printBenefitPrice` ๋™์ž‘ ํ™•์ธ + - [x] `printAfterDiscountPrice` ๋™์ž‘ ํ™•์ธ + - [x] `printBadge` ๋™์ž‘ ํ™•์ธ
Unknown
ํด๋ž˜์Šค๋ณ„๋กœ ์˜ˆ์™ธ์‚ฌํ•ญ ์˜ˆ์‹œ๋‚˜ ๊ธฐ๋Šฅ์„ ๊ผผ๊ผผํžˆ ์ž‘์„ฑํ•ด์„œ ์ข‹์•˜์Šต๋‹ˆ๋‹ค! ํ”„๋กœ๊ทธ๋žจ์„ ์กฐ๊ธˆ ์š”์•ฝํ•ด์„œ ์ •๋ฆฌํ•œ ์ •๋ณด๋„ ์žˆ์œผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,12 @@ +package christmas.config; + +public class Constant { + public static final int INIT_VALUE = 0; + public static final int FILTER_CONDITION = 0; + public static final int MIN_ORDER = 1; + public static final int MAX_ORDER = 20; + + private Constant() { + // ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐฉ์ง€ + } +}
Java
์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰์— ๋Œ€ํ•œ ์ƒ์ˆ˜๋“ค์„ ์ €์žฅํ•˜์…จ๋Š”๋ฐ, ํด๋ž˜์Šค๋ช…์ด Constant์—ฌ์„œ init value ๋‚˜ filter condition ์ƒ์ˆ˜๋ช…์€ ์˜๋ฏธ๊ฐ€ ์ข€ ๋ช…ํ™•ํ•˜์ง€ ์•Š์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํƒ€์ธ์ด ์ฝ๊ธฐ์— ์šฉ๋„๊ฐ€ ๋ช…ํ™•ํ•˜์ง€ ์•Š์€๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ํด๋ž˜์Šค๋ช…์„ OrderConstatns ์™€ ๊ฐ™์ด ํ•˜๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™๋„ค์š”. ์ตœ๋Œ€ ์ฃผ๋ฌธ ๊ฐฏ์ˆ˜๋ฅผ ์–ธ์ œ๋“  ์ •์ฑ…๋ณ€๊ฒฝ์— ๋”ฐ๋ผ ๋ฐ”๊พธ์‹œ๋ ค๊ณ  ๋นผ๋‘” ๊ฒƒ์ด๋ผ๋ฉด ํŒจํ‚ค์ง€ ์œ„์น˜๋ฅผ ๊ณ ๋ คํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,22 @@ +package christmas.config; + +public enum ErrorMessage { + WRONG_DATE("์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค."), + WRONG_ORDER("์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค."), + OVER_MAX_ORDER("๋ฉ”๋‰ด๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 20๊ฐœ๊นŒ์ง€๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."), + ONLY_DRINK_ORDER("์Œ๋ฃŒ๋งŒ ์ฃผ๋ฌธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + + private static final String PREFIX = "[ERROR]"; + private static final String SUFFIX = "๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; + private static final String DELIMITER = " "; + + private final String message; + + ErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return String.join(DELIMITER, PREFIX, message, SUFFIX); + } +}
Java
์ €๋Š” `class`๋กœ ๊ตฌํ˜„ํ–ˆ๋Š”๋ฐ ๋‹ค๋ฅธ ๋ถ„๋“ค ๋ณด๊ณ  `enum`์œผ๋กœ ๊ตฌํ˜„ํ•ด๋ณด๋ ค๊ตฌ์š”! ์—ด๊ฑฐํ˜•์œผ๋กœ ๊ตฌํ˜„ํ–ˆ์„ ๋•Œ๋งŒ์˜ ์žฅ์ ์ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! "์—๋Ÿฌ ๋ชจ์Œ์ง‘์—์„œ ์ด๋Ÿฐ ์—๋Ÿฌ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ตฌ๋‚˜~" ๋ผ๊ณ  ์ฝ๊ธฐ ๋” ์ข‹์€ ๊ฒƒ ๊ฐ™์•„์š”
@@ -0,0 +1,47 @@ +package christmas.config; + +import java.util.Arrays; + +public enum Menu { + SOUP("์–‘์†ก์ด์ˆ˜ํ”„", 6000, MenuType.APPETIZER), + TAPAS("ํƒ€ํŒŒ์Šค", 5500, MenuType.APPETIZER), + SALAD("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 8000, MenuType.APPETIZER), + STEAK("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 55000, MenuType.MAIN), + BARBECUE("๋ฐ”๋น„ํ๋ฆฝ", 54000, MenuType.MAIN), + SEAFOOD_PASTA("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 35000, MenuType.MAIN), + CHRISTMAS_PASTA("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 25000, MenuType.MAIN), + CAKE("์ดˆ์ฝ”์ผ€์ดํฌ", 15000, MenuType.DESSERT), + ICE_CREAM("์•„์ด์Šคํฌ๋ฆผ", 5000, MenuType.DESSERT), + COLA("์ œ๋กœ์ฝœ๋ผ", 3000, MenuType.DRINK), + WINE("๋ ˆ๋“œ์™€์ธ", 60000, MenuType.DRINK), + CHAMPAGNE("์ƒดํŽ˜์ธ", 25000, MenuType.DRINK); + + private final String menuName; + private final int price; + private final MenuType type; + + Menu(String menuName, int price, MenuType type) { + this.menuName = menuName; + this.price = price; + this.type = type; + } + + public static Menu from(String menuName) { + return Arrays.stream(Menu.values()) + .filter(it -> menuName.equals(it.menuName)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage())); + } + + public String getMenuName() { + return menuName; + } + + public int getPrice() { + return price; + } + + public MenuType getType() { + return type; + } +}
Java
```suggestion SOUP("์–‘์†ก์ด์ˆ˜ํ”„", 6_000, MenuType.APPETIZER), ``` ๋ณ„๊ฑฐ ์•„๋‹ˆ์ง€๋งŒ ๊ฐ€๊ฒฉ์€ 3์ž๋ฆฌ ์ˆซ์ž ๋งˆ๋‹ค '-' ์–ธ๋”๋ฐ” ๋„ฃ์–ด์ฃผ์‹œ๋ฉด ๊ฐ€๋…์„ฑ์— ์ข‹์€๊ฒƒ๊ฐ™์Šต๋‹ˆ๋‹ค. ์‹ค์ˆ˜๋„ ์ค„์—ฌ์ฃผ๊ณ ์š”
@@ -0,0 +1,47 @@ +package christmas.config; + +import java.util.Arrays; + +public enum Menu { + SOUP("์–‘์†ก์ด์ˆ˜ํ”„", 6000, MenuType.APPETIZER), + TAPAS("ํƒ€ํŒŒ์Šค", 5500, MenuType.APPETIZER), + SALAD("์‹œ์ €์ƒ๋Ÿฌ๋“œ", 8000, MenuType.APPETIZER), + STEAK("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ", 55000, MenuType.MAIN), + BARBECUE("๋ฐ”๋น„ํ๋ฆฝ", 54000, MenuType.MAIN), + SEAFOOD_PASTA("ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€", 35000, MenuType.MAIN), + CHRISTMAS_PASTA("ํฌ๋ฆฌ์Šค๋งˆ์ŠคํŒŒ์Šคํƒ€", 25000, MenuType.MAIN), + CAKE("์ดˆ์ฝ”์ผ€์ดํฌ", 15000, MenuType.DESSERT), + ICE_CREAM("์•„์ด์Šคํฌ๋ฆผ", 5000, MenuType.DESSERT), + COLA("์ œ๋กœ์ฝœ๋ผ", 3000, MenuType.DRINK), + WINE("๋ ˆ๋“œ์™€์ธ", 60000, MenuType.DRINK), + CHAMPAGNE("์ƒดํŽ˜์ธ", 25000, MenuType.DRINK); + + private final String menuName; + private final int price; + private final MenuType type; + + Menu(String menuName, int price, MenuType type) { + this.menuName = menuName; + this.price = price; + this.type = type; + } + + public static Menu from(String menuName) { + return Arrays.stream(Menu.values()) + .filter(it -> menuName.equals(it.menuName)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage())); + } + + public String getMenuName() { + return menuName; + } + + public int getPrice() { + return price; + } + + public MenuType getType() { + return type; + } +}
Java
```suggestion public static Menu getMenuBy(String menuName) { ``` ์ •๋ง ๊ฐ์ž ์Šคํƒ€์ผ์ด ๋‹ฌ๋ผ์„œ ์ œ๊ฐ€ ๊ผญ ์ •๋‹ต์€ ์•„๋‹ˆ์ง€๋งŒ ๋ฉ”์„œ๋“œ๋ช… ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค!
@@ -0,0 +1,5 @@ +package christmas.config; + +public enum MenuType { + APPETIZER, MAIN, DESSERT, DRINK +}
Java
์นดํ…Œ๊ณ ๋ฆฌ ๋”ฐ๋กœ ์—ด๊ฑฐํ•ด์„œ ๊ตฌ๋ถ„ํ•˜์‹ ๊ฒŒ ๋‚˜์ค‘์— ๋ฌธ์ž๋กœ ๋น„๊ตํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์•ˆ์ •์„ฑ ์žˆ๊ฒŒ ๊ตฌํ˜„ํ•˜์‹ ๊ฒƒ ๊ฐ™์•„์š”
@@ -0,0 +1,26 @@ +package christmas.domain; + +import java.util.Arrays; + +public enum Badge { + SANTA("์‚ฐํƒ€", 20000), + TREE("ํŠธ๋ฆฌ", 10000), + STAR("๋ณ„", 5000), + NOTHING("์—†์Œ", 0); + + private final String badgeName; + private final int threshold; + + Badge(String badgeName, int threshold) { + this.badgeName = badgeName; + this.threshold = threshold; + } + + public static String getBadgeNameWithBenefitPrice(int benefitPrice) { + return Arrays.stream(Badge.values()) + .filter(it -> it.threshold <= benefitPrice) + .map(it -> it.badgeName) + .findFirst() + .orElse(NOTHING.badgeName); + } +}
Java
์ €๋„ ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ–ˆ๋Š”๋ฐ ๊ณ ๋ฏผํ•˜๋‹ค๋ณด๋‹ˆ ๋ฑƒ์ง€๊ฐ€ ๊ฐ€์ง„ ๊ฐœ๋…์ด `๊ฐ€๊ฒฉ` ์ธ์ง€ `๋ฒ”์œ„`์ธ์ง€ ์ทจํ–ฅ ์ฐจ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ ์ €๋Š” `๋ฒ”์œ„`๊ฐ€ ์กฐ๊ธˆ๋” ๋ฑƒ์ง€๊ฐ€ ๊ฐ€์ง„ ๊ฐœ๋…์ด๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ค๋”๋ผ๊ตฌ์š” ๊ทธ๋ž˜์„œ ์•ˆ์— ๊ธฐ์ค€ ๊ฐ€๊ฒฉ๋Œ€์‹  ๋ฒ”์œ„๋ฅผ ๋„ฃ์–ด๋ณด๋Š” ๊ณ ๋ฏผ๋„ ํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,81 @@ +package christmas.domain; + +import christmas.config.ErrorMessage; + +import java.util.Arrays; + +public class Date implements CheckEventDate { + private static final int WEEK_NUM = 7; + private static final int WEEK_DIFF = 4; + private static final int FIRST_DAY = 1; + private static final int LAST_DAY = 31; + private static final int CHRISTMAS = 25; + + private final int date; + + private Date(int date) { + validate(date); + this.date = date; + } + + public static Date from(int date) { + return new Date(date); + } + + private void validate(int date) { + if (date < FIRST_DAY || date > LAST_DAY) { + throw new IllegalArgumentException(ErrorMessage.WRONG_DATE.getMessage()); + } + } + + private enum DayOfWeek { + SUN(0), MON(1), TUE(2), WED(3), THU(4), FRI(5), SAT(6); + + private final int value; + + DayOfWeek(int value) { + this.value = value; + } + + public static DayOfWeek from(int value) { + return Arrays.stream(DayOfWeek.values()) + .filter(it -> value == it.value) + .findAny() + .orElse(null); + } + } + + /** + * 2023๋…„ 12์›”์„ ๊ธฐ์ค€์œผ๋กœ ํ˜„์žฌ ๋‚ ์งœ์— ๋งž๋Š” ์š”์ผ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. + * @return DayOfWeek (0: ์ผ์š”์ผ ~ 6: ํ† ์š”์ผ) + */ + private DayOfWeek getDayOfWeek() { + int dayValue = (date + WEEK_DIFF) % WEEK_NUM; + return DayOfWeek.from(dayValue); + } + + @Override + public boolean isWeekend() { + DayOfWeek dayOfWeek = getDayOfWeek(); + return dayOfWeek == DayOfWeek.FRI || dayOfWeek == DayOfWeek.SAT; + } + + @Override + public boolean isSpecialDay() { + return getDayOfWeek() == DayOfWeek.SUN || date == CHRISTMAS; + } + + @Override + public boolean isNotPassedChristmas() { + return date <= CHRISTMAS; + } + + @Override + public int timePassedSinceFirstDay() { + return date - FIRST_DAY; + } + + public int getDateValue() { + return date; + } +}
Java
์ด ํด๋ž˜์Šค ๊ต‰์žฅํžˆ ์ข‹์€ ๊ฒƒ ๊ฐ™์•„์š” Date๋ผ๋Š” ๊ฐœ๋…๋„ ์ž˜ ๋‹ด๊ฒจ์žˆ๊ณ  ํฌ๋ฆฌ์Šค๋งˆ์Šค๋‚˜ ์‹œ์ž‘ ์š”์ผ์„ ๋‹ค๋ฅธ ๊ณณ์—์„œ ๋ฐ›์•„์˜ค๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ฐ”๊พผ๋‹ค๋ฉด ํ•ด๋‹น ์ •๋ณด๋งŒ ๊ฐˆ์•„๋ผ์šฐ๋ฉด ๊ณ„์† ๋™์ž‘๋˜๋Š” ํด๋ž˜์Šค ๊ฐ™์•„์š”. java.time ์ด๋ผ๋Š” ์ž๋ฐ” ํŒจํ‚ค์ง€๋ฅผ ํ•˜๋‚˜ ์ถ”์ฒœํ•ด๋“œ๋ฆด๊ฒŒ์š” ``` import java.time.LocalDate; import java.time.DayOfWeek; import java.time.format.TextStyle; import java.util.Locale; public class Main { public static void main(String[] args) { // ํŠน์ • ๋‚ ์งœ ์„ค์ • LocalDate date = LocalDate.of(2023, 11, 24); // ์˜ˆ: 2023๋…„ 11์›” 24์ผ // ํ•ด๋‹น ๋‚ ์งœ์˜ ์š”์ผ์„ ๊ฐ€์ ธ์˜ด DayOfWeek dayOfWeek = date.getDayOfWeek(); // ์š”์ผ์„ ๋ฌธ์ž์—ด๋กœ ์ถœ๋ ฅ (์˜ˆ: ํ•œ๊ตญ์–ด๋กœ ์งง์€ ํ˜•์‹) String dayOfWeekInKorean = dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.KOREAN); System.out.println("์š”์ผ (ํ•œ๊ตญ์–ด): " + dayOfWeekInKorean); } } ```
@@ -0,0 +1,75 @@ +package christmas.domain; + +import christmas.config.Menu; +import christmas.config.MenuType; + +import java.util.function.Function; +import java.util.function.Predicate; + +public enum Event { + CHRISTMAS( + "ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ", + true, + Bill::isNotPassedChristmas, + bill -> bill.timePassedSinceFirstDay() * 100 + 1000 + ), + WEEKDAY( + "ํ‰์ผ ํ• ์ธ", + true, + bill -> !bill.isWeekend(), + bill -> bill.getTypeCount(MenuType.DESSERT) * 2023 + ), + WEEKEND( + "์ฃผ๋ง ํ• ์ธ", + true, + Bill::isWeekend, + bill -> bill.getTypeCount(MenuType.MAIN) * 2023 + ), + SPECIAL( + "ํŠน๋ณ„ ํ• ์ธ", + true, + Bill::isSpecialDay, + bill -> 1000 + ), + CHAMPAGNE( + "์ฆ์ • ์ด๋ฒคํŠธ", + false, + bill -> bill.getTotalPrice() >= 120000, + bill -> Menu.CHAMPAGNE.getPrice() + ); + + private static final int ALL_EVENT_THRESHOLD = 10000; + + private final String eventName; + private final boolean isDiscount; + private final Predicate<Bill> condition; + private final Function<Bill, Integer> benefit; + + Event( + String eventName, + boolean isDiscount, + Predicate<Bill> condition, + Function<Bill, Integer> benefit + ) { + this.eventName = eventName; + this.isDiscount = isDiscount; + this.condition = condition; + this.benefit = benefit; + } + + public String getEventName() { + return eventName; + } + + public boolean isDiscount() { + return isDiscount; + } + + public boolean checkCondition(Bill bill) { + return condition.test(bill) && bill.getTotalPrice() >= ALL_EVENT_THRESHOLD; + } + + public int getBenefit(Bill bill) { + return benefit.apply(bill); + } +}
Java
์˜ค ํ• ์ธ์ด ์ ์šฉ ๋˜์—ˆ๋Š”์ง€ ๋ถˆ๋ฆฐ๊ฐ’์„ ๋„ฃ์–ด๋‘์‹  ๊ฒƒ์ด ๋งค์šฐ ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค! ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค. ํ•ด๋‹น ๋‚ด์šฉ์„ ๋ฑƒ์ง€์—๋„ ์ ์šฉํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,52 @@ +package christmas.util; + +import christmas.dto.OrderDTO; +import christmas.config.ErrorMessage; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +public class OrderParser { + private static final String SEQUENCE_DELIMITER = ","; + private static final String ORDER_DELIMITER = "-"; + private static final String ORDER_PATTERN = "[^-]+-[0-9]+"; + private static final String REPLACE_TARGET = " "; + private static final String REPLACEMENT = ""; + + private OrderParser() { + // ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐฉ์ง€ + } + + public static List<OrderDTO> parseOrderOrThrow(String orderSequence) { + List<OrderDTO> result = new ArrayList<>(); + for (String order : splitOrder(trimAll(orderSequence))) { + result.add(parseOrderDTO(order)); + } + return result; + } + + private static List<String> splitOrder(String orderSequence) { + return List.of(orderSequence.split(SEQUENCE_DELIMITER)); + } + + private static OrderDTO parseOrderDTO(String order) { + validateOrderPattern(order); + String[] split = order.split(ORDER_DELIMITER); + try { + return new OrderDTO(split[0], IntParser.parseIntOrThrow(split[1])); + } catch (IndexOutOfBoundsException e) { + throw new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage()); + } + } + + private static String trimAll(String target) { + return target.replaceAll(REPLACE_TARGET, REPLACEMENT); + } + + private static void validateOrderPattern(String order) { + if (!Pattern.matches(ORDER_PATTERN, order)) { + throw new IllegalArgumentException(ErrorMessage.WRONG_ORDER.getMessage()); + } + } +}
Java
```suggestion private static final Pattern ORDER_PATTERN = Pattern.compile("[^-]+-[0-9]+"); // ์ปดํŒŒ์ผ๋œ ํŒจํ„ด ```
@@ -0,0 +1,110 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.utils.EventSettings; +import christmas.parser.EventDetailsParser; +import christmas.view.EventView; + +import java.math.BigDecimal; +import java.util.Map; + +public class ChristmasEventController implements EventController { + private static final String WEEKDAY_DISCOUNT_TYPE = "dessert"; + private static final String WEEKEND_DISCOUNT_TYPE = "main"; + private static final DecemberCalendar decemberCalendar = new DecemberCalendar(); + + private boolean canPresent = false; + private BigDecimal totalBenefitAmount = new BigDecimal(0); + private Map<Menu, Integer> orderDetails; + private Badge badge; + private String eventResultDetails = ""; + private BigDecimal beforeEventApplied; + + public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) { + beforeEventApplied = bill.getTotalPrice(); + if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) { + this.orderDetails = order.getOrderDetails(); + presentEvent(bill); + dDayDiscountEvent(reservationDay, bill); + weekdayDiscountEvent(reservationDay, bill); + weekendDiscountEvent(reservationDay, bill); + specialDayDiscountEvent(reservationDay, bill); + badgeEvent(totalBenefitAmount); + } + } + + public void presentEvent(Bill bill) { + if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) { + canPresent = true; + BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount(); + + totalBenefitAmount = totalBenefitAmount.add(benefitValue); + eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue); + } + } + + public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) { + if (reservationDay.dDayDiscountEventPeriod()) { + BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1); + BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount(). + add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay))); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue); + } + } + + public void weekdayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekday(day.getDay())) { + long dessertCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(dessertCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue); + } + } + + public void weekendDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekend(day.getDay())) { + long mainDishCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(mainDishCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue); + } + } + + public void specialDayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isSpecialDay(day.getDay())) { + BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount(); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue); + } + } + + public void badgeEvent(BigDecimal totalBenefitAmount) { + badge = Badge.getBadge(totalBenefitAmount); + } + + public void showEventDiscountDetails(Bill bill) { + EventView.printPriceBeforeDiscount(beforeEventApplied); + EventView.printPresentDetails(canPresent); + EventView.printEventResultDetails(eventResultDetails); + EventView.printTotalBenefitAmount(totalBenefitAmount); + EventView.printPriceAfterDiscount(bill); + EventView.printBadge(badge); + } +}
Java
3์ฃผ ์ฐจ ์›น ๋ฐฑ์—”๋“œ ๊ณตํ†ต ํ”ผ๋“œ๋ฐฑ์œผ๋กœ ํ•„๋“œ(์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜)์˜ ์ˆ˜๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•œ๋‹ค๋ผ๋Š” ํ•ญ๋ชฉ์ด ์žˆ์—ˆ๋Š”๋ฐ์š” ์ค‘๋ณต๋˜๋Š” ํ•ญ๋ชฉ๋“ค์€ ํ•˜๋‚˜์˜ result๋กœ ๋ฌถ์–ด์„œ ํ•œ๋ฒˆ ๊ด€๋ฆฌ๋ฅผ ํ•ด๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,110 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.utils.EventSettings; +import christmas.parser.EventDetailsParser; +import christmas.view.EventView; + +import java.math.BigDecimal; +import java.util.Map; + +public class ChristmasEventController implements EventController { + private static final String WEEKDAY_DISCOUNT_TYPE = "dessert"; + private static final String WEEKEND_DISCOUNT_TYPE = "main"; + private static final DecemberCalendar decemberCalendar = new DecemberCalendar(); + + private boolean canPresent = false; + private BigDecimal totalBenefitAmount = new BigDecimal(0); + private Map<Menu, Integer> orderDetails; + private Badge badge; + private String eventResultDetails = ""; + private BigDecimal beforeEventApplied; + + public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) { + beforeEventApplied = bill.getTotalPrice(); + if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) { + this.orderDetails = order.getOrderDetails(); + presentEvent(bill); + dDayDiscountEvent(reservationDay, bill); + weekdayDiscountEvent(reservationDay, bill); + weekendDiscountEvent(reservationDay, bill); + specialDayDiscountEvent(reservationDay, bill); + badgeEvent(totalBenefitAmount); + } + } + + public void presentEvent(Bill bill) { + if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) { + canPresent = true; + BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount(); + + totalBenefitAmount = totalBenefitAmount.add(benefitValue); + eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue); + } + } + + public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) { + if (reservationDay.dDayDiscountEventPeriod()) { + BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1); + BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount(). + add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay))); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue); + } + } + + public void weekdayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekday(day.getDay())) { + long dessertCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(dessertCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue); + } + } + + public void weekendDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekend(day.getDay())) { + long mainDishCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(mainDishCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue); + } + } + + public void specialDayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isSpecialDay(day.getDay())) { + BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount(); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue); + } + } + + public void badgeEvent(BigDecimal totalBenefitAmount) { + badge = Badge.getBadge(totalBenefitAmount); + } + + public void showEventDiscountDetails(Bill bill) { + EventView.printPriceBeforeDiscount(beforeEventApplied); + EventView.printPresentDetails(canPresent); + EventView.printEventResultDetails(eventResultDetails); + EventView.printTotalBenefitAmount(totalBenefitAmount); + EventView.printPriceAfterDiscount(bill); + EventView.printBadge(badge); + } +}
Java
๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์œผ๋กœ๋Š” ์ปจํŠธ๋กค๋Ÿฌ์—์„œ ๋„๋ฉ”์ธ์—์„œ ํ•ด์•ผ ํ•  ์—ญํ• ๋“ค์„ ๋งŽ์ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„์š” ์ด๋Ÿฐ ๊ณ„์‚ฐ์ด๋‚˜ ํ• ์ธ์— ๋Œ€ํ•œ ๋‚ด์šฉ๋“ค์€ ๋”ฐ๋กœ ์ด ์—ญํ• ์„ ๋‹ด๋‹นํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ทธ๊ณณ์—์„œ ์Šค์Šค๋กœ ์ผ์„ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ฐ์ฒด์ง€ํ–ฅ์ ์œผ๋กœ ์„ค๊ณ„ํ•ด ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,110 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.utils.EventSettings; +import christmas.parser.EventDetailsParser; +import christmas.view.EventView; + +import java.math.BigDecimal; +import java.util.Map; + +public class ChristmasEventController implements EventController { + private static final String WEEKDAY_DISCOUNT_TYPE = "dessert"; + private static final String WEEKEND_DISCOUNT_TYPE = "main"; + private static final DecemberCalendar decemberCalendar = new DecemberCalendar(); + + private boolean canPresent = false; + private BigDecimal totalBenefitAmount = new BigDecimal(0); + private Map<Menu, Integer> orderDetails; + private Badge badge; + private String eventResultDetails = ""; + private BigDecimal beforeEventApplied; + + public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) { + beforeEventApplied = bill.getTotalPrice(); + if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) { + this.orderDetails = order.getOrderDetails(); + presentEvent(bill); + dDayDiscountEvent(reservationDay, bill); + weekdayDiscountEvent(reservationDay, bill); + weekendDiscountEvent(reservationDay, bill); + specialDayDiscountEvent(reservationDay, bill); + badgeEvent(totalBenefitAmount); + } + } + + public void presentEvent(Bill bill) { + if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) { + canPresent = true; + BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount(); + + totalBenefitAmount = totalBenefitAmount.add(benefitValue); + eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue); + } + } + + public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) { + if (reservationDay.dDayDiscountEventPeriod()) { + BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1); + BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount(). + add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay))); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue); + } + } + + public void weekdayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekday(day.getDay())) { + long dessertCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(dessertCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue); + } + } + + public void weekendDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekend(day.getDay())) { + long mainDishCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(mainDishCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue); + } + } + + public void specialDayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isSpecialDay(day.getDay())) { + BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount(); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue); + } + } + + public void badgeEvent(BigDecimal totalBenefitAmount) { + badge = Badge.getBadge(totalBenefitAmount); + } + + public void showEventDiscountDetails(Bill bill) { + EventView.printPriceBeforeDiscount(beforeEventApplied); + EventView.printPresentDetails(canPresent); + EventView.printEventResultDetails(eventResultDetails); + EventView.printTotalBenefitAmount(totalBenefitAmount); + EventView.printPriceAfterDiscount(bill); + EventView.printBadge(badge); + } +}
Java
ํ•˜๋‚˜์˜ ํ•จ์ˆ˜์—์„œ ๋‹ค์–‘ํ•œ ์ผ์„ ํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ ๊ธฐ๋Šฅ์„ ๋ถ„๋ฆฌํ•ด ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,26 @@ +package christmas.controller; + +import christmas.domain.Bill; +import christmas.domain.Order; +import christmas.domain.ReservationDay; + +import java.math.BigDecimal; + +public interface EventController { + + void applyEvent(ReservationDay day, Order order, Bill bill); + + void showEventDiscountDetails(Bill bill); + + void presentEvent(Bill bill); + + void dDayDiscountEvent(ReservationDay reservationDay, Bill bill); + + void weekdayDiscountEvent(ReservationDay day, Bill bill); + + void weekendDiscountEvent(ReservationDay day, Bill bill); + + void specialDayDiscountEvent(ReservationDay day, Bill bill); + + void badgeEvent(BigDecimal totalBenefitAmount); +}
Java
EventController๋ฅผ interface๋กœ ๋งŒ๋“ค์–ด์„œ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ๋กœ์ง์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ด๋ฒคํŠธ ๊ด€๋ จ ๋„๋ฉ”์ธ์„ interface๋กœ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•ด ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”? ๊ฐ์ฒด์ง€ํ–ฅ์„ ๋‹ค๋ฃฌ ์˜ค๋ธŒ์ ํŠธ ์„œ์ ์—์„œ ๋น„์Šทํ•œ ๋‚ด์šฉ์ด ์žˆ์–ด์„œ ๋งํฌ ๋‚จ๊น๋‹ˆ๋‹ค. https://github.com/eternity-oop/object/tree/master/chapter13/src/main/java/org/eternity/movie/step02
@@ -0,0 +1,32 @@ +package christmas.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.*; + +class BadgeTest { + + @Test + @DisplayName("์‚ฐํƒ€_๋ฑƒ์ง€_๊ฒฝ๊ณ„๊ฐ’_ํ…Œ์ŠคํŠธ") + void getBadge_SantaBadgeAmount_ShouldReturnSantaBadge() { + BigDecimal santaBadgeAmount = new BigDecimal(20000); + assertEquals(Badge.SANTA_BADGE, Badge.getBadge(santaBadgeAmount)); + } + + @Test + @DisplayName("ํŠธ๋ฆฌ_๋ฑƒ์ง€_๊ฒฝ๊ณ„๊ฐ’_ํ…Œ์ŠคํŠธ") + void getBadge_BetweenTreeAndSantaAmount_ShouldReturnTreeBadge() { + BigDecimal betweenTreeAndSantaAmount = new BigDecimal(15000); + assertEquals(Badge.TREE_BADGE, Badge.getBadge(betweenTreeAndSantaAmount)); + } + + @Test + @DisplayName("๋ณ„_๋ฑƒ์ง€_๊ฒฝ๊ณ„๊ฐ’_ํ…Œ์ŠคํŠธ") + void getBadge_StarBadgeAmount_ShouldReturnStarBadge() { + BigDecimal starBadgeAmount = new BigDecimal(5000); + assertEquals(Badge.STAR_BADGE, Badge.getBadge(starBadgeAmount)); + } +}
Java
import static org.junit.jupiter.api.Assertions.*; ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋ณด๋‹ค ๋” ๊ฐ„ํŽธํ•˜๊ฒŒ ํ…Œ์ŠคํŠธ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋Š” import static org.junit.jupiter.api.Assertions.*;๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”? https://jwkim96.tistory.com/168
@@ -0,0 +1,36 @@ +package christmas.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.*; + +public class BillTest { + Order testOrder = new Order(); + + @Test + @DisplayName("์ „์ฒด_๊ฐ€๊ฒฉ_๊ณ„์‚ฐ_ํ…Œ์ŠคํŠธ") + public void testBillTotalPriceCalculation() { + testOrder.takeOrder("์–‘์†ก์ด์ˆ˜ํ”„-1,ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-2,์ดˆ์ฝ”์ผ€์ดํฌ-3"); + Bill bill = new Bill(testOrder); + + BigDecimal expectedTotalPrice = BigDecimal + .valueOf(1).multiply(Menu.APPETIZER_MUSHROOM_SOUP.getPrice()) + .add(BigDecimal.valueOf(2).multiply(Menu.MAIN_T_BONE_STEAK.getPrice())) + .add(BigDecimal.valueOf(3).multiply(Menu.DESSERT_CHOCO_CAKE.getPrice())); + + assertEquals(expectedTotalPrice, bill.getTotalPrice()); + } + + @Test + @DisplayName("๊ฐ€๊ฒฉ_ํ• ์ธ_์ ์šฉ_ํ…Œ์ŠคํŠธ") + public void testBillDiscountPrice() { + testOrder.takeOrder("์–‘์†ก์ด์ˆ˜ํ”„-5"); //30,000์› + Bill bill = new Bill(testOrder); + bill.discountPrice(new BigDecimal(10000)); //30,000 - 10,000 ์› + + assertEquals(bill.getTotalPrice(), new BigDecimal(20000)); + } +}
Java
given when then ํŒจํ„ด์„ ์‚ฌ์šฉํ•ด์„œ ํ…Œ์ŠคํŠธ์ฝ”๋“œ๋ฅผ ๋‚˜๋ˆ  ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”? https://brunch.co.kr/@springboot/292
@@ -0,0 +1,89 @@ +package christmas.domain; + +import christmas.utils.ErrorMessage; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +class OrderTest { + String validInput = "ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-2,์–‘์†ก์ด์ˆ˜ํ”„-2"; + + @Test + @DisplayName("์ฃผ๋ฌธ_์œ ํšจ๊ฐ’_์ž…๋ ฅ_ํ…Œ์ŠคํŠธ") + void takeOrder_ValidInput_ShouldNotThrowException() { + Order order = new Order(); + assertDoesNotThrow(() -> order.takeOrder(validInput)); + } + + @Test + @DisplayName("์ฃผ๋ฌธ_์ค‘๋ณต_์˜ˆ์™ธ_ํ…Œ์ŠคํŠธ") + void takeOrder_DuplicateMenu_ShouldThrowException() { + Order order = new Order(); + String duplicateMenuInput = "ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-2,ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-2"; + + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () + -> order.takeOrder(duplicateMenuInput)); + assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage()); + } + + @Test + @DisplayName("์ฃผ๋ฌธ_์ž…๋ ฅํ˜•์‹_์˜ˆ์™ธ_ํ…Œ์ŠคํŠธ") + void takeOrder_InvalidOrderFormat_ShouldThrowException() { + Order order = new Order(); + String invalidFormatInput = "ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ+2"; + + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () + -> order.takeOrder(invalidFormatInput)); + assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage()); + } + + @Test + @DisplayName("์ฃผ๋ฌธ_๊ฐœ์ˆ˜์ดˆ๊ณผ_์˜ˆ์™ธ_ํ…Œ์ŠคํŠธ") + void takeOrder_ExceedMaximumQuantity_ShouldThrowException() { + Order order = new Order(); + String exceedQuantityInput = "ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-20,์–‘์†ก์ด์ˆ˜ํ”„-10"; + + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () + -> order.takeOrder(exceedQuantityInput)); + assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage()); + } + + @Test + @DisplayName("์ฃผ๋ฌธ_์Œ๋ฃŒ_์˜ˆ์™ธ_ํ…Œ์ŠคํŠธ") + void takeOrder_OnlyBeverage_ValidInput_ShouldNotThrowException() { + Order order = new Order(); + String onlyBeverageInput = "์ œ๋กœ์ฝœ๋ผ-10"; + + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () + -> order.takeOrder(onlyBeverageInput)); + assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage()); + } + + @Test + @DisplayName("์ฃผ๋ฌธ_๊ณต๋ฐฑ_์˜ˆ์™ธ_ํ…Œ์ŠคํŠธ") + void toString_OrderDetailsEmpty_ShouldReturnEmptyString() { + Order order = new Order(); + + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () + -> order.takeOrder("")); + assertEquals(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage(), exception.getMessage()); + assertEquals("", order.toString()); + } + + @Test + @DisplayName("์ฃผ๋ฌธ_๋‚ด์—ญ_์ถœ๋ ฅ_ํ…Œ์ŠคํŠธ") + void getOrderDetails_OrderDetailsNotEmpty_ShouldReturnOrderDetails() { + Order order = new Order(); + order.takeOrder(validInput); + + Map<Menu, Integer> expectedOrderDetails = new HashMap<>(); + expectedOrderDetails.put(Menu.findMenu("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ"), 2); + expectedOrderDetails.put(Menu.findMenu("์–‘์†ก์ด์ˆ˜ํ”„"), 2); + + assertEquals(expectedOrderDetails, order.getOrderDetails()); + } +}
Java
๋ฐ˜๋ณต๋˜๋Š” Order order = new Order(); ๋Š” @BeforeAll void setUp()์„ ํ™œ์šฉํ•˜์—ฌ์„œ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด ์ฃผ๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,110 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.utils.EventSettings; +import christmas.parser.EventDetailsParser; +import christmas.view.EventView; + +import java.math.BigDecimal; +import java.util.Map; + +public class ChristmasEventController implements EventController { + private static final String WEEKDAY_DISCOUNT_TYPE = "dessert"; + private static final String WEEKEND_DISCOUNT_TYPE = "main"; + private static final DecemberCalendar decemberCalendar = new DecemberCalendar(); + + private boolean canPresent = false; + private BigDecimal totalBenefitAmount = new BigDecimal(0); + private Map<Menu, Integer> orderDetails; + private Badge badge; + private String eventResultDetails = ""; + private BigDecimal beforeEventApplied; + + public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) { + beforeEventApplied = bill.getTotalPrice(); + if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) { + this.orderDetails = order.getOrderDetails(); + presentEvent(bill); + dDayDiscountEvent(reservationDay, bill); + weekdayDiscountEvent(reservationDay, bill); + weekendDiscountEvent(reservationDay, bill); + specialDayDiscountEvent(reservationDay, bill); + badgeEvent(totalBenefitAmount); + } + } + + public void presentEvent(Bill bill) { + if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) { + canPresent = true; + BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount(); + + totalBenefitAmount = totalBenefitAmount.add(benefitValue); + eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue); + } + } + + public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) { + if (reservationDay.dDayDiscountEventPeriod()) { + BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1); + BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount(). + add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay))); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue); + } + } + + public void weekdayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekday(day.getDay())) { + long dessertCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(dessertCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue); + } + } + + public void weekendDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekend(day.getDay())) { + long mainDishCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(mainDishCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue); + } + } + + public void specialDayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isSpecialDay(day.getDay())) { + BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount(); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue); + } + } + + public void badgeEvent(BigDecimal totalBenefitAmount) { + badge = Badge.getBadge(totalBenefitAmount); + } + + public void showEventDiscountDetails(Bill bill) { + EventView.printPriceBeforeDiscount(beforeEventApplied); + EventView.printPresentDetails(canPresent); + EventView.printEventResultDetails(eventResultDetails); + EventView.printTotalBenefitAmount(totalBenefitAmount); + EventView.printPriceAfterDiscount(bill); + EventView.printBadge(badge); + } +}
Java
ํŠน์ • ๋ฉ”์„œ๋“œ์—์„œ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ํ•„๋“œ๋Š” ๋กœ์ปฌํ™”ํ•˜๊ณ  ๋‚˜๋จธ์ง„ ๊ฐ์ฒดํ™”ํ•˜์—ฌ ํ•„๋“œ ์ˆ˜๋ฅผ ์ค„์—ฌ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”? ์ถ”๊ฐ€๋กœ `final` ํ‚ค์›Œ๋“œ๋ฅผ ์ƒ๋žตํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,69 @@ +package christmas.controller; + +import christmas.domain.Bill; +import christmas.domain.Order; +import christmas.domain.ReservationDay; +import christmas.view.InputView; +import christmas.view.OutputView; + +public class PlannerController { + private final Order order; + private final ReservationDay reservationDay; + private final EventController eventController; + + private Bill bill; + + public PlannerController(EventController eventController) { + this.eventController = eventController; + this.reservationDay = new ReservationDay(); + this.order = new Order(); + } + + public void run() { + OutputView.printStartMessage(); + + try { + inputDay(); + inputOrder(); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + return; + } + + processEvent(); + } + + private void inputDay() { + while (true) { + try { + String dayInput = InputView.inputDate(); + reservationDay.reserveDay(dayInput); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private void inputOrder() { + while (true) { + try { + String orderInput = InputView.inputOrder(); + order.takeOrder(orderInput.replace(" ", "")); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private void processEvent() { + OutputView.printEventPreviewMessage(reservationDay.getDay()); + OutputView.printOrderDetails(order); + + bill = new Bill(order); + + eventController.applyEvent(reservationDay, order, bill); + eventController.showEventDiscountDetails(bill); + } +}
Java
์˜ˆ์™ธ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ๋„ `OutputView` ์—์„œ ์ฒ˜๋ฆฌํ•˜๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,69 @@ +package christmas.controller; + +import christmas.domain.Bill; +import christmas.domain.Order; +import christmas.domain.ReservationDay; +import christmas.view.InputView; +import christmas.view.OutputView; + +public class PlannerController { + private final Order order; + private final ReservationDay reservationDay; + private final EventController eventController; + + private Bill bill; + + public PlannerController(EventController eventController) { + this.eventController = eventController; + this.reservationDay = new ReservationDay(); + this.order = new Order(); + } + + public void run() { + OutputView.printStartMessage(); + + try { + inputDay(); + inputOrder(); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + return; + } + + processEvent(); + } + + private void inputDay() { + while (true) { + try { + String dayInput = InputView.inputDate(); + reservationDay.reserveDay(dayInput); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private void inputOrder() { + while (true) { + try { + String orderInput = InputView.inputOrder(); + order.takeOrder(orderInput.replace(" ", "")); + break; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private void processEvent() { + OutputView.printEventPreviewMessage(reservationDay.getDay()); + OutputView.printOrderDetails(order); + + bill = new Bill(order); + + eventController.applyEvent(reservationDay, order, bill); + eventController.showEventDiscountDetails(bill); + } +}
Java
ํ•„๋“œ๊ฐ€ ์ƒ์„ฑ์ž๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ์—์„œ ์ดˆ๊ธฐํ™”๋˜๋Š”๊ฒŒ ์–ด์ƒ‰ํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,35 @@ +package christmas.domain; + +import java.math.BigDecimal; + +public enum Badge { + SANTA_BADGE("์‚ฐํƒ€", new BigDecimal(20000)), + TREE_BADGE("ํŠธ๋ฆฌ", new BigDecimal(10000)), + STAR_BADGE("๋ณ„", new BigDecimal(5000)); + + private final String name; + private final BigDecimal standardAmount; + + Badge(String name, BigDecimal standardAmount) { + this.name = name; + this.standardAmount = standardAmount; + } + + public String getName() { + if (this == null) return ""; + return name; + } + + public static Badge getBadge(BigDecimal totalBenefit) { + if (totalBenefit.compareTo(SANTA_BADGE.standardAmount) >= 0) { + return SANTA_BADGE; + } + if (totalBenefit.compareTo(TREE_BADGE.standardAmount) >= 0) { + return TREE_BADGE; + } + if (totalBenefit.compareTo(STAR_BADGE.standardAmount) >= 0) { + return STAR_BADGE; + } + return null; + } +}
Java
์ด๋ฆ„์ด `null`์ด ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,110 @@ +package christmas.controller; + +import christmas.domain.*; +import christmas.utils.EventSettings; +import christmas.parser.EventDetailsParser; +import christmas.view.EventView; + +import java.math.BigDecimal; +import java.util.Map; + +public class ChristmasEventController implements EventController { + private static final String WEEKDAY_DISCOUNT_TYPE = "dessert"; + private static final String WEEKEND_DISCOUNT_TYPE = "main"; + private static final DecemberCalendar decemberCalendar = new DecemberCalendar(); + + private boolean canPresent = false; + private BigDecimal totalBenefitAmount = new BigDecimal(0); + private Map<Menu, Integer> orderDetails; + private Badge badge; + private String eventResultDetails = ""; + private BigDecimal beforeEventApplied; + + public void applyEvent(ReservationDay reservationDay, Order order, Bill bill) { + beforeEventApplied = bill.getTotalPrice(); + if (bill.getTotalPrice().compareTo(EventSettings.EVENT_APPLY_STAND.getAmount()) >= 0) { + this.orderDetails = order.getOrderDetails(); + presentEvent(bill); + dDayDiscountEvent(reservationDay, bill); + weekdayDiscountEvent(reservationDay, bill); + weekendDiscountEvent(reservationDay, bill); + specialDayDiscountEvent(reservationDay, bill); + badgeEvent(totalBenefitAmount); + } + } + + public void presentEvent(Bill bill) { + if (bill.getTotalPrice().compareTo(EventSettings.PRESENT_STANDARD_AMOUNT.getAmount()) == 1) { + canPresent = true; + BigDecimal benefitValue = EventSettings.PRESENT_VALUE.getAmount(); + + totalBenefitAmount = totalBenefitAmount.add(benefitValue); + eventResultDetails += EventDetailsParser.parsePresentEventDetail(benefitValue); + } + } + + public void dDayDiscountEvent(ReservationDay reservationDay, Bill bill) { + if (reservationDay.dDayDiscountEventPeriod()) { + BigDecimal eventDay = new BigDecimal(reservationDay.getDay() - 1); + BigDecimal discountValue = EventSettings.D_DAY_DISCOUNT_START_VALUE.getAmount(). + add((EventSettings.D_DAY_DISCOUNT_VALUE.getAmount().multiply(eventDay))); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseDDayDiscountEventDetail(discountValue); + } + } + + public void weekdayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekday(day.getDay())) { + long dessertCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKDAY_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(dessertCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekdayDiscountEventDetail(discountValue); + } + } + + public void weekendDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isWeekend(day.getDay())) { + long mainDishCount = orderDetails.entrySet().stream() + .filter(entry -> WEEKEND_DISCOUNT_TYPE.equals(entry.getKey().getMenuItem().getMenuType())) + .mapToLong(Map.Entry::getValue) + .sum(); + BigDecimal discountValue = new BigDecimal(mainDishCount) + .multiply(EventSettings.STANDARD_DISCOUNT_VALUE.getAmount()); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.parseWeekendDiscountEventDetail(discountValue); + } + } + + public void specialDayDiscountEvent(ReservationDay day, Bill bill) { + if (decemberCalendar.isSpecialDay(day.getDay())) { + BigDecimal discountValue = EventSettings.SPECIAL_DAY_DISCOUNT_VALUE.getAmount(); + + bill.discountPrice(discountValue); + totalBenefitAmount = totalBenefitAmount.add(discountValue); + eventResultDetails += EventDetailsParser.paresSpecialDayDiscountEventDetail(discountValue); + } + } + + public void badgeEvent(BigDecimal totalBenefitAmount) { + badge = Badge.getBadge(totalBenefitAmount); + } + + public void showEventDiscountDetails(Bill bill) { + EventView.printPriceBeforeDiscount(beforeEventApplied); + EventView.printPresentDetails(canPresent); + EventView.printEventResultDetails(eventResultDetails); + EventView.printTotalBenefitAmount(totalBenefitAmount); + EventView.printPriceAfterDiscount(bill); + EventView.printBadge(badge); + } +}
Java
`BigDecimal` ์˜ ๊ฒฝ์šฐ ์ผ๋ถ€ ๊ฐ’์„ ์บ์‹ฑํ•˜๊ณ  ์žˆ์–ด ์ƒ์„ฑ์ž ๋Œ€์‹  `valueOf()` ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด๋ฅผ ์–ป๋Š”๊ฒŒ ๋” ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค!
@@ -0,0 +1,35 @@ +package christmas.domain; + +import java.math.BigDecimal; + +public enum Badge { + SANTA_BADGE("์‚ฐํƒ€", new BigDecimal(20000)), + TREE_BADGE("ํŠธ๋ฆฌ", new BigDecimal(10000)), + STAR_BADGE("๋ณ„", new BigDecimal(5000)); + + private final String name; + private final BigDecimal standardAmount; + + Badge(String name, BigDecimal standardAmount) { + this.name = name; + this.standardAmount = standardAmount; + } + + public String getName() { + if (this == null) return ""; + return name; + } + + public static Badge getBadge(BigDecimal totalBenefit) { + if (totalBenefit.compareTo(SANTA_BADGE.standardAmount) >= 0) { + return SANTA_BADGE; + } + if (totalBenefit.compareTo(TREE_BADGE.standardAmount) >= 0) { + return TREE_BADGE; + } + if (totalBenefit.compareTo(STAR_BADGE.standardAmount) >= 0) { + return STAR_BADGE; + } + return null; + } +}
Java
`null` ๋ฐ˜ํ™˜์ด ์œ„ํ—˜ํ•œ ๊ฒƒ ๊ฐ™์•„์š”! `NONE` ๊ณผ ๊ฐ™์€ ์ธ์Šคํ„ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,32 @@ +package christmas.domain; + +import java.math.BigDecimal; +import java.util.Map; + +public class Bill { + private final Map<Menu, Integer> orderDetails; + + private BigDecimal totalPrice = new BigDecimal(0); + + public Bill(Order order) { + this.orderDetails = order.getOrderDetails(); + calculateTotalPrice(); + } + + private void calculateTotalPrice() { + for (Map.Entry<Menu, Integer> entry : orderDetails.entrySet()) { + Menu menu = entry.getKey(); + int count = entry.getValue(); + BigDecimal price = menu.getPrice().multiply(BigDecimal.valueOf(count)); + totalPrice = totalPrice.add(price); + } + } + + public void discountPrice(BigDecimal discountValue) { + totalPrice = totalPrice.subtract(discountValue); + } + + public BigDecimal getTotalPrice() { + return totalPrice; + } +}
Java
๋ฉ”๋‰ด ์ž…๋ ฅ ์‹œ ์ด๋ฆ„, ์ˆ˜๋Ÿ‰ ์™ธ์— ๋‹ค๋ฅธ ๊ฐ’์ด ์ถ”๊ฐ€๋˜๋Š”๊ฑธ ๊ฐ์•ˆํ•˜์—ฌ `Map<K, V>` ๋Œ€์‹  ๋ณ„๋„์˜ ํด๋ž˜์Šค ์‚ฌ์šฉ์€ ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,29 @@ +package christmas.domain; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class DecemberCalendar { + private final List<Integer> weekdays = Stream.of(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31) + .collect(Collectors.toList()); + private final List<Integer> weekends = Stream.of(1, 2, 8, 9, 15, 16, 22, 23, 29, 30) + .collect(Collectors.toList()); + private final List<Integer> specialDays = Stream.of(3, 10, 17, 24, 25, 31) + .collect(Collectors.toList()); + + public boolean isWeekday(int day) { + if (weekdays.contains(day)) return true; + return false; + } + + public boolean isWeekend(int day) { + if (weekends.contains(day)) return true; + return false; + } + + public boolean isSpecialDay(int day) { + if (specialDays.contains(day)) return true; + return false; + } +}
Java
`Arrays.asList()` ๋Œ€์‹  Stream์„ ์‚ฌ์šฉํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,62 @@ +package christmas.domain; + +import christmas.utils.ErrorMessage; +import christmas.parser.Parser; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static christmas.domain.validator.OrderValidator.*; + +public class Order { + private final Map<Menu, Integer> orderDetails = new HashMap<>(); + private int quantity = 0; + + public void takeOrder(String input) { + List<String> eachOrderedMenu = Parser.inputToEachOrderedMenu(input); + try { + eachOrderedMenu.forEach(menuInformation -> processOrderedMenu(menuInformation)); + + calculateMenuQuantity(); + validateOnlyBeverage(orderDetails); + validateMaximumQuantity(quantity); + } catch (Exception e) { + throw new IllegalArgumentException(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage()); + } + } + + private void processOrderedMenu(String menuInformation) { + String[] menuNameAndNumber = Parser.inputToMenu(menuInformation); + String menuName = menuNameAndNumber[0]; + int menuNumber = Parser.stringToIntPaser(menuNameAndNumber[1]); + Menu orderedMenu = Menu.findMenu(menuName); + + validateDuplicateMenu(orderDetails, orderedMenu); + validateOrderFormat(menuNameAndNumber); + orderDetails.put(orderedMenu, menuNumber); + } + + private void calculateMenuQuantity() { + for (int count : orderDetails.values()) { + quantity += count; + } + } + + public String toString() { + StringBuilder output = new StringBuilder(); + for (Map.Entry<Menu, Integer> entry : orderDetails.entrySet()) { + Menu menu = entry.getKey(); + int count = entry.getValue(); + output.append(menu.getMenuItem().getName()) + .append(" ") + .append(count) + .append("๊ฐœ\n"); + } + return output.toString(); + } + + public Map<Menu, Integer> getOrderDetails() { + return orderDetails; + } +}
Java
`int`์˜ ๊ฒฝ์šฐ ํ•„๋“œ์—์„œ ๊ฐ’์„ ๋Œ€์ž…ํ•˜์ง€ ์•Š์•„๋„ ๊ฐ์ฒด ์ƒ์„ฑ์‹œ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ๋ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,62 @@ +package christmas.domain; + +import christmas.utils.ErrorMessage; +import christmas.parser.Parser; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static christmas.domain.validator.OrderValidator.*; + +public class Order { + private final Map<Menu, Integer> orderDetails = new HashMap<>(); + private int quantity = 0; + + public void takeOrder(String input) { + List<String> eachOrderedMenu = Parser.inputToEachOrderedMenu(input); + try { + eachOrderedMenu.forEach(menuInformation -> processOrderedMenu(menuInformation)); + + calculateMenuQuantity(); + validateOnlyBeverage(orderDetails); + validateMaximumQuantity(quantity); + } catch (Exception e) { + throw new IllegalArgumentException(ErrorMessage.INPUT_ORDER_ERROR_MESSAGE.getMessage()); + } + } + + private void processOrderedMenu(String menuInformation) { + String[] menuNameAndNumber = Parser.inputToMenu(menuInformation); + String menuName = menuNameAndNumber[0]; + int menuNumber = Parser.stringToIntPaser(menuNameAndNumber[1]); + Menu orderedMenu = Menu.findMenu(menuName); + + validateDuplicateMenu(orderDetails, orderedMenu); + validateOrderFormat(menuNameAndNumber); + orderDetails.put(orderedMenu, menuNumber); + } + + private void calculateMenuQuantity() { + for (int count : orderDetails.values()) { + quantity += count; + } + } + + public String toString() { + StringBuilder output = new StringBuilder(); + for (Map.Entry<Menu, Integer> entry : orderDetails.entrySet()) { + Menu menu = entry.getKey(); + int count = entry.getValue(); + output.append(menu.getMenuItem().getName()) + .append(" ") + .append(count) + .append("๊ฐœ\n"); + } + return output.toString(); + } + + public Map<Menu, Integer> getOrderDetails() { + return orderDetails; + } +}
Java
๋„๋ฉ”์ธ์ด View์— ์˜์กดํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! `OutputView`์—์„œ `Order`์— ๋Œ€ํ•œ ๊ฐ’์„ ๊ฐ€์ ธ์˜จ ํ›„ ์ถœ๋ ฅํ•˜๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,27 @@ +package racingcar.dao; + +import java.util.HashMap; +import java.util.Map; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.simple.SimpleJdbcInsert; +import racingcar.dao.entity.GameEntity; + +public class InsertGameDao { + + private final SimpleJdbcInsert insertActor; + + public InsertGameDao(final JdbcTemplate jdbcTemplate) { + insertActor = new SimpleJdbcInsert(jdbcTemplate) + .withTableName("game") + .usingGeneratedKeyColumns("game_id"); + } + + public GameEntity insert(final GameEntity gameEntity) { + final Map<String, Object> parameters = new HashMap<>(3); + parameters.put("game_id", gameEntity.getGameId().getValue()); + parameters.put("trial_count", gameEntity.getTrialCount()); + parameters.put("created_at", gameEntity.getCreatedAt()); + + return new GameEntity(insertActor.executeAndReturnKey(parameters).intValue(), gameEntity.getTrialCount()); + } +}
Java
์ด๊ฑฐ ์™ธ ์•Š ๋Š ?
@@ -0,0 +1,24 @@ +package com.requestrealpiano.songrequest.controller; + +import com.requestrealpiano.songrequest.service.AccountService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/accounts") +public class AccountController { + + private final AccountService accountService; + + @GetMapping("/auth") + public ResponseEntity<Void> generateToken(@RequestHeader HttpHeaders httpHeaders) { + String jwtToken = accountService.generateJwtToken(httpHeaders.getFirst(HttpHeaders.AUTHORIZATION)); + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HttpHeaders.AUTHORIZATION, jwtToken); + return new ResponseEntity<>(responseHeaders, HttpStatus.NO_CONTENT); + } +}
Java
๋‹ค๋ฅธ ์ปจํŠธ๋กค๋Ÿฌ์—์„œ๋Š” ResponseStatus๋กœ ์ง€์ •ํ–ˆ๋Š”๋ฐ ์—ฌ๊ธด ResponseEntity๋กœ ์ง€์ •ํ–ˆ๊ตฐ์š” ์–ด๋–ค ์ด์œ ๋กœ ์ง€์ •ํ–ˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
@@ -2,18 +2,18 @@ import com.requestrealpiano.songrequest.domain.song.searchapi.response.SearchApiResponse; import com.requestrealpiano.songrequest.global.response.ApiResponse; +import com.requestrealpiano.songrequest.global.response.StatusCode; import com.requestrealpiano.songrequest.service.SongService; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.validation.constraints.Size; import static com.requestrealpiano.songrequest.global.constant.ValidationCondition.*; -import static com.requestrealpiano.songrequest.global.response.ApiResponse.OK; +import static com.requestrealpiano.songrequest.global.response.ApiResponse.SUCCESS; +import static com.requestrealpiano.songrequest.global.response.StatusCode.OK; @RequiredArgsConstructor @Validated @@ -23,12 +23,13 @@ public class SongController { private final SongService songService; + @ResponseStatus(HttpStatus.OK) @GetMapping public ApiResponse<SearchApiResponse> search(@RequestParam(defaultValue = "artist") @Size(max = ARTIST_MAX) String artist, @RequestParam(defaultValue = "title") @Size(max = TITLE_MAX) String title) { SearchApiResponse searchApiResponse = songService.searchSong(artist, title); - return OK(searchApiResponse); + return SUCCESS(OK, searchApiResponse); } }
Java
์ด ๋ถ€๋ถ„์€ ์ปจํŠธ๋กค๋Ÿฌ์—์„œ Validation์„ ์žก๊ธฐ๋ณด๋‹จ Validation DTO๋ฅผ ์ƒ์„ฑํ•ด์„œ ํ•ด๋‹น ๊ฐ์ฒด์—์„œ ๊ด€๋ฆฌํ•˜๋ฉด ๋”์šฑ ํŽธ๋ฆฌํ•˜๊ณ  ๋ณด๊ธฐ๊ฐ€ ์ข‹์„๋“ฏ ํ•ฉ๋‹ˆ๋‹ค.
@@ -1,5 +1,6 @@ package com.requestrealpiano.songrequest.domain.account; +import com.requestrealpiano.songrequest.security.oauth.OAuthAttributes; import com.requestrealpiano.songrequest.domain.base.BaseTimeEntity; import com.requestrealpiano.songrequest.domain.letter.Letter; import lombok.AccessLevel; @@ -8,9 +9,6 @@ import lombok.NoArgsConstructor; import javax.persistence.*; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.List; @@ -25,7 +23,7 @@ public class Account extends BaseTimeEntity { private Long id; @Column(name = "google_oauth_id") - private Long googleOauthId; + private String googleOauthId; private String name; @@ -44,12 +42,36 @@ public class Account extends BaseTimeEntity { private List<Letter> letters = new ArrayList<>(); @Builder - private Account(Long googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) { + private Account(String googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) { this.googleOauthId = googleOauthId; this.name = name; this.email = email; this.role = role; this.avatarUrl = avatarUrl; this.requestCount = requestCount; } + + public String getRoleKey() { return role.getKey(); } + + public String getRoleValue() { + return role.getValue(); + } + + public Account updateProfile(OAuthAttributes attributes) { + this.name = attributes.getName(); + this.email = attributes.getEmail(); + this.avatarUrl = attributes.getAvatarUrl(); + return this; + } + + public static Account from(OAuthAttributes oAuthAttributes) { + return Account.builder() + .googleOauthId(oAuthAttributes.getGoogleOauthId()) + .name(oAuthAttributes.getName()) + .email(oAuthAttributes.getEmail()) + .role(Role.MEMBER) + .avatarUrl(oAuthAttributes.getAvatarUrl()) + .requestCount(0) + .build(); + } }
Java
์—Œใ…‹ใ…‹ใ…‹ใ…‹ OAuthId๋ฅผ ํ™•์ธํ•˜์‹œ๊ณ  ๋ฐ”๊พธ์…จ๊ตฐ์š”.
@@ -1,5 +1,6 @@ package com.requestrealpiano.songrequest.domain.account; +import com.requestrealpiano.songrequest.security.oauth.OAuthAttributes; import com.requestrealpiano.songrequest.domain.base.BaseTimeEntity; import com.requestrealpiano.songrequest.domain.letter.Letter; import lombok.AccessLevel; @@ -8,9 +9,6 @@ import lombok.NoArgsConstructor; import javax.persistence.*; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.List; @@ -25,7 +23,7 @@ public class Account extends BaseTimeEntity { private Long id; @Column(name = "google_oauth_id") - private Long googleOauthId; + private String googleOauthId; private String name; @@ -44,12 +42,36 @@ public class Account extends BaseTimeEntity { private List<Letter> letters = new ArrayList<>(); @Builder - private Account(Long googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) { + private Account(String googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) { this.googleOauthId = googleOauthId; this.name = name; this.email = email; this.role = role; this.avatarUrl = avatarUrl; this.requestCount = requestCount; } + + public String getRoleKey() { return role.getKey(); } + + public String getRoleValue() { + return role.getValue(); + } + + public Account updateProfile(OAuthAttributes attributes) { + this.name = attributes.getName(); + this.email = attributes.getEmail(); + this.avatarUrl = attributes.getAvatarUrl(); + return this; + } + + public static Account from(OAuthAttributes oAuthAttributes) { + return Account.builder() + .googleOauthId(oAuthAttributes.getGoogleOauthId()) + .name(oAuthAttributes.getName()) + .email(oAuthAttributes.getEmail()) + .role(Role.MEMBER) + .avatarUrl(oAuthAttributes.getAvatarUrl()) + .requestCount(0) + .build(); + } }
Java
์—ฌ๊ธฐ ์ ํ˜€์žˆ๋Š” MaginNumber 0์€ ์–ด๋–ค์˜๋ฏธ์ธ๊ฐ€์š”?
@@ -11,6 +11,12 @@ public enum ErrorCode { METHOD_NOT_ALLOWED(405, "์ง€์›ํ•˜์ง€ ์•Š๋Š” ์š”์ฒญ ๋ฉ”์†Œ๋“œ ์ž…๋‹ˆ๋‹ค."), INTERNAL_SERVER_ERROR(500, "์„œ๋ฒ„์—์„œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค."), + // Auth + UNAUTHENTICATED_ERROR(401, "์ธ์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋กœ๊ทธ์ธ ์ดํ›„ ๋‹ค์‹œ ์‹œ๋„ ํ•ด์ฃผ์„ธ์š”."), + JWT_INVALID_ERROR(400, "์˜ฌ๋ฐ”๋ฅธ ์ธ์ฆ ์ •๋ณด๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธ ํ•ด์ฃผ์„ธ์š”."), + JWT_EXPIRATION_ERROR(401, "์ธ์ฆ ์ •๋ณด๊ฐ€ ๋งŒ๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธ ํ•ด์ฃผ์„ธ์š”."), + ACCESS_DENIED_ERROR(403, "ํ•ด๋‹น ์š”์ฒญ์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."), + // Account ACCOUNT_NOT_FOUND(404, "ํ•ด๋‹น ๊ณ„์ •์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
Java
์—ฌ๊ธฐ์„œ JWT ์ธ์ฆํ•  ๋•Œ ๋‘๊ฐ€์ง€ ์กฐ๊ฑด์ด ์žˆ๋”๊ตฐ์š”. 1. JWT๊ฐ€ ์•„๋‹Œ Token์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ - 400 2. JWT๋Š” ๋งž๋Š”๋ฐ ์˜ฌ๋ฐ”๋ฅธ JWT๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ - 401 ๋‘๊ฐ€์ง€ ๊ณ ๋ คํ•˜์‹œ๋Š”๊ฑด ์–ด๋– ์‹ ์ง€ ๋ž™๋Œ ์˜๊ฒฌ์ด ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
@@ -11,6 +11,12 @@ public enum ErrorCode { METHOD_NOT_ALLOWED(405, "์ง€์›ํ•˜์ง€ ์•Š๋Š” ์š”์ฒญ ๋ฉ”์†Œ๋“œ ์ž…๋‹ˆ๋‹ค."), INTERNAL_SERVER_ERROR(500, "์„œ๋ฒ„์—์„œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค."), + // Auth + UNAUTHENTICATED_ERROR(401, "์ธ์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋กœ๊ทธ์ธ ์ดํ›„ ๋‹ค์‹œ ์‹œ๋„ ํ•ด์ฃผ์„ธ์š”."), + JWT_INVALID_ERROR(400, "์˜ฌ๋ฐ”๋ฅธ ์ธ์ฆ ์ •๋ณด๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธ ํ•ด์ฃผ์„ธ์š”."), + JWT_EXPIRATION_ERROR(401, "์ธ์ฆ ์ •๋ณด๊ฐ€ ๋งŒ๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธ ํ•ด์ฃผ์„ธ์š”."), + ACCESS_DENIED_ERROR(403, "ํ•ด๋‹น ์š”์ฒญ์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."), + // Account ACCOUNT_NOT_FOUND(404, "ํ•ด๋‹น ๊ณ„์ •์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
Java
์—ฌ๊ธฐ์„œ๋„ ์ด์•ผ๊ธฐ ํ•˜๊ณ  ์‹ถ์€๊ฒƒ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น API๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๊ถŒํ•œ์„ ๋ง‰๋Š” ๊ฒƒ์ด 403์ด์ง€๋งŒ ๋งŒ์•ฝ ๋น„๊ณต๊ฐœ๋œ ์ •๋ณด๋ฅผ API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€์ ธ์˜ฌ๋•Œ๋Š” 404๋กœ Not Found๋กœ ๋„์›Œ์•ผํ•œ๋‹ค๊ณ  ํ•˜๋”๊ตฐ์š”. ๊ทธ์— ๋Œ€ํ•œ ๋Œ€๋น„์ฑ…๋„ ํ•„์š”ํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.
@@ -0,0 +1,105 @@ +package com.requestrealpiano.songrequest.security; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.requestrealpiano.songrequest.domain.account.Role; +import com.requestrealpiano.songrequest.security.filter.JwtAuthorizationFilter; +import com.requestrealpiano.songrequest.security.jwt.JwtTokenProvider; +import com.requestrealpiano.songrequest.security.oauth.CustomAccessDeniedHandler; +import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationEntryPoint; +import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationSuccessHandler; +import com.requestrealpiano.songrequest.security.oauth.CustomOAuth2UserService; +import com.requestrealpiano.songrequest.domain.account.AccountRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.csrf.CsrfFilter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CharacterEncodingFilter; + +import java.util.Arrays; +import java.util.Collections; + +import static org.springframework.security.config.Customizer.withDefaults; + +@RequiredArgsConstructor +@Configuration +@EnableWebSecurity +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + private final CustomOAuth2UserService customOAuth2UserService; + private final CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler; + private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint; + private final CustomAccessDeniedHandler customAccessDeniedHandler; + private final AccountRepository accountRepository; + private final JwtTokenProvider jwtTokenProvider; + private final ObjectMapper objectMapper; + + @Override + public void configure(WebSecurity web) throws Exception { + web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations()); + + web.ignoring().antMatchers(HttpMethod.GET, "/api/accounts/auth") + .antMatchers(HttpMethod.GET, "/api/letters/**") + ; + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.cors(withDefaults()); + + http.csrf().disable() + .httpBasic().disable(); + + http.authorizeRequests() +// .antMatchers("/**").permitAll() + .antMatchers("/api/letters").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey()) + .antMatchers("/api/songs").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey()) + .anyRequest().authenticated(); + + http.sessionManagement() + .sessionCreationPolicy(SessionCreationPolicy.STATELESS); + + http.addFilterBefore(characterEncodingFilter(), CsrfFilter.class) + .addFilterBefore(JwtAuthorizationFilter.of(accountRepository, jwtTokenProvider, objectMapper), UsernamePasswordAuthenticationFilter.class); + + http.oauth2Login() + .userInfoEndpoint() + .userService(customOAuth2UserService) + .and() + .successHandler(customAuthenticationSuccessHandler); + + http.exceptionHandling() + .authenticationEntryPoint(customAuthenticationEntryPoint) + .accessDeniedHandler(customAccessDeniedHandler); + } + + public CharacterEncodingFilter characterEncodingFilter() { + CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); + encodingFilter.setEncoding("UTF-8"); + encodingFilter.setForceEncoding(true); + return encodingFilter; + } + + @Bean + CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration configuration = new CorsConfiguration(); + configuration.setAllowedOrigins(Collections.singletonList("*")); + configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); + configuration.setAllowedHeaders(Collections.singletonList("*")); + configuration.setExposedHeaders(Collections.singletonList("Authorization")); + configuration.setAllowCredentials(true); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); + return source; + } +}
Java
์‚ฌ์šฉํ•˜์‹œ์ง€ ์•Š์„ ์ฝ”๋“œ๋ฉด ์‚ญ์ œํ•˜๊ณ  ๊ทธ๋ž˜๋„ ์ฃผ์„์ฒ˜๋ฆฌ๋ฅผ ๋‚จ๊ธฐ๊ณ  ์‹ถ๋‹ค๋ฉด ์™œ ์ฃผ์„์ฒ˜๋ฆฌํ–ˆ๋Š”์ง€์— ๋Œ€ํ•œ ์„ค๋ช…์„ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,105 @@ +package com.requestrealpiano.songrequest.security; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.requestrealpiano.songrequest.domain.account.Role; +import com.requestrealpiano.songrequest.security.filter.JwtAuthorizationFilter; +import com.requestrealpiano.songrequest.security.jwt.JwtTokenProvider; +import com.requestrealpiano.songrequest.security.oauth.CustomAccessDeniedHandler; +import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationEntryPoint; +import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationSuccessHandler; +import com.requestrealpiano.songrequest.security.oauth.CustomOAuth2UserService; +import com.requestrealpiano.songrequest.domain.account.AccountRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.csrf.CsrfFilter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CharacterEncodingFilter; + +import java.util.Arrays; +import java.util.Collections; + +import static org.springframework.security.config.Customizer.withDefaults; + +@RequiredArgsConstructor +@Configuration +@EnableWebSecurity +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + private final CustomOAuth2UserService customOAuth2UserService; + private final CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler; + private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint; + private final CustomAccessDeniedHandler customAccessDeniedHandler; + private final AccountRepository accountRepository; + private final JwtTokenProvider jwtTokenProvider; + private final ObjectMapper objectMapper; + + @Override + public void configure(WebSecurity web) throws Exception { + web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations()); + + web.ignoring().antMatchers(HttpMethod.GET, "/api/accounts/auth") + .antMatchers(HttpMethod.GET, "/api/letters/**") + ; + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.cors(withDefaults()); + + http.csrf().disable() + .httpBasic().disable(); + + http.authorizeRequests() +// .antMatchers("/**").permitAll() + .antMatchers("/api/letters").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey()) + .antMatchers("/api/songs").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey()) + .anyRequest().authenticated(); + + http.sessionManagement() + .sessionCreationPolicy(SessionCreationPolicy.STATELESS); + + http.addFilterBefore(characterEncodingFilter(), CsrfFilter.class) + .addFilterBefore(JwtAuthorizationFilter.of(accountRepository, jwtTokenProvider, objectMapper), UsernamePasswordAuthenticationFilter.class); + + http.oauth2Login() + .userInfoEndpoint() + .userService(customOAuth2UserService) + .and() + .successHandler(customAuthenticationSuccessHandler); + + http.exceptionHandling() + .authenticationEntryPoint(customAuthenticationEntryPoint) + .accessDeniedHandler(customAccessDeniedHandler); + } + + public CharacterEncodingFilter characterEncodingFilter() { + CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); + encodingFilter.setEncoding("UTF-8"); + encodingFilter.setForceEncoding(true); + return encodingFilter; + } + + @Bean + CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration configuration = new CorsConfiguration(); + configuration.setAllowedOrigins(Collections.singletonList("*")); + configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); + configuration.setAllowedHeaders(Collections.singletonList("*")); + configuration.setExposedHeaders(Collections.singletonList("Authorization")); + configuration.setAllowCredentials(true); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); + return source; + } +}
Java
Role์„ ์ž์ฃผ ์‚ฌ์šฉํ•˜์‹ค ๋“ฏํ•œ๋ฐ import static์œผ๋กœ ์„ ์–ธํ•˜๋Š” ๊ฒƒ๋„ ๋‚˜์˜์ง€ ์•Š๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,105 @@ +package com.requestrealpiano.songrequest.security; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.requestrealpiano.songrequest.domain.account.Role; +import com.requestrealpiano.songrequest.security.filter.JwtAuthorizationFilter; +import com.requestrealpiano.songrequest.security.jwt.JwtTokenProvider; +import com.requestrealpiano.songrequest.security.oauth.CustomAccessDeniedHandler; +import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationEntryPoint; +import com.requestrealpiano.songrequest.security.oauth.CustomAuthenticationSuccessHandler; +import com.requestrealpiano.songrequest.security.oauth.CustomOAuth2UserService; +import com.requestrealpiano.songrequest.domain.account.AccountRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.csrf.CsrfFilter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CharacterEncodingFilter; + +import java.util.Arrays; +import java.util.Collections; + +import static org.springframework.security.config.Customizer.withDefaults; + +@RequiredArgsConstructor +@Configuration +@EnableWebSecurity +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + private final CustomOAuth2UserService customOAuth2UserService; + private final CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler; + private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint; + private final CustomAccessDeniedHandler customAccessDeniedHandler; + private final AccountRepository accountRepository; + private final JwtTokenProvider jwtTokenProvider; + private final ObjectMapper objectMapper; + + @Override + public void configure(WebSecurity web) throws Exception { + web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations()); + + web.ignoring().antMatchers(HttpMethod.GET, "/api/accounts/auth") + .antMatchers(HttpMethod.GET, "/api/letters/**") + ; + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.cors(withDefaults()); + + http.csrf().disable() + .httpBasic().disable(); + + http.authorizeRequests() +// .antMatchers("/**").permitAll() + .antMatchers("/api/letters").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey()) + .antMatchers("/api/songs").hasAnyRole(Role.MEMBER.getKey(), Role.ADMIN.getKey()) + .anyRequest().authenticated(); + + http.sessionManagement() + .sessionCreationPolicy(SessionCreationPolicy.STATELESS); + + http.addFilterBefore(characterEncodingFilter(), CsrfFilter.class) + .addFilterBefore(JwtAuthorizationFilter.of(accountRepository, jwtTokenProvider, objectMapper), UsernamePasswordAuthenticationFilter.class); + + http.oauth2Login() + .userInfoEndpoint() + .userService(customOAuth2UserService) + .and() + .successHandler(customAuthenticationSuccessHandler); + + http.exceptionHandling() + .authenticationEntryPoint(customAuthenticationEntryPoint) + .accessDeniedHandler(customAccessDeniedHandler); + } + + public CharacterEncodingFilter characterEncodingFilter() { + CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); + encodingFilter.setEncoding("UTF-8"); + encodingFilter.setForceEncoding(true); + return encodingFilter; + } + + @Bean + CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration configuration = new CorsConfiguration(); + configuration.setAllowedOrigins(Collections.singletonList("*")); + configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); + configuration.setAllowedHeaders(Collections.singletonList("*")); + configuration.setExposedHeaders(Collections.singletonList("Authorization")); + configuration.setAllowCredentials(true); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); + return source; + } +}
Java
`WebConfig`์—์„œ๋„ CORS ์—๋Ÿฌ์— ๋Œ€ํ•œ ๋Œ€๋น„์ฑ…์„ ์„ค์ •ํ•˜์…จ๋Š”๋ฐ ์—ฌ๊ธฐ์„œ๋„ ์„ค์ •ํ•œ ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,115 @@ +package com.requestrealpiano.songrequest.security.jwt; + +import com.requestrealpiano.songrequest.domain.account.Account; +import com.requestrealpiano.songrequest.global.error.exception.jwt.JwtExpirationException; +import com.requestrealpiano.songrequest.global.error.exception.jwt.JwtInvalidTokenException; +import com.requestrealpiano.songrequest.global.error.exception.jwt.JwtRequiredException; +import com.requestrealpiano.songrequest.security.jwt.claims.AccountClaims; +import io.jsonwebtoken.*; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.Date; + +@RequiredArgsConstructor +@Component +public class JwtTokenProvider { + + private final JwtProperties jwtProperties; + + private final String ID = "id"; + private final String EMAIL = "email"; + private final String NAME = "name"; + private final String AVATAR_URL = "avatarUrl"; + private final String ROLE = "role"; + + public String createGenerationKey(String email) { + Date now = new Date(); + return Jwts.builder() + .setHeaderParam(Header.TYPE, Header.JWT_TYPE) + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + Long.parseLong(jwtProperties.getGenerationKeyExpiration()))) + .claim(EMAIL, email) + .signWith(SignatureAlgorithm.HS256, jwtProperties.getGenerationKeySecret()) + .compact(); + } + + public String parseGenerationKey(String authorization) { + String generationKey = extractToken(authorization); + try { + Jws<Claims> claims = Jwts.parser() + .setSigningKey(jwtProperties.getGenerationKeySecret()) + .parseClaimsJws(generationKey); + return claims.getBody() + .get(EMAIL, String.class); + } catch (ExpiredJwtException exception) { + throw new JwtExpirationException(); + } catch (JwtException exception) { + throw new JwtInvalidTokenException(); + } + } + + public String createJwtToken(Account account) { + Date now = new Date(); + String jwtToken = Jwts.builder() + .setHeaderParam(Header.TYPE, Header.JWT_TYPE) + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + Long.parseLong(jwtProperties.getTokenExpiration()))) + .claim(ID, account.getId()) + .claim(EMAIL, account.getEmail()) + .claim(NAME, account.getName()) + .claim(AVATAR_URL, account.getAvatarUrl()) + .claim(ROLE, account.getRoleKey()) + .signWith(SignatureAlgorithm.HS256, jwtProperties.getTokenSecret()) + .compact(); + return jwtProperties.getHeaderPrefix() + jwtToken; + } + + public boolean validateJwtToken(String authorization) { + String jwtToken = extractToken(authorization); + try { + Jws<Claims> claims = Jwts.parser() + .setSigningKey(jwtProperties.getTokenSecret()) + .parseClaimsJws(jwtToken); + return claims.getBody() + .getExpiration() + .after(new Date()); + } catch (ExpiredJwtException exception) { + throw new JwtExpirationException(); + } catch (JwtException exception) { + throw new JwtInvalidTokenException(); + } + } + + public AccountClaims parseJwtToken(String jwtToken) { + try { + Jws<Claims> claims = Jwts.parser() + .setSigningKey(jwtProperties.getTokenSecret()) + .parseClaimsJws(jwtToken); + Claims body = claims.getBody(); + + return AccountClaims.from(body); + } catch (ExpiredJwtException exception) { + throw new JwtExpirationException(); + } catch (JwtException exception) { + throw new JwtInvalidTokenException(); + } + } + + public String extractToken(String authorizationHeader) { + if (isTokenContained(authorizationHeader)) { + int tokenBeginIndex = jwtProperties.getHeaderPrefix().length(); + return StringUtils.substring(authorizationHeader, tokenBeginIndex); + } + throw new JwtRequiredException(); + } + + private boolean isTokenContained(String authorization) { + if (StringUtils.isEmpty(authorization)) { + return false; + } + + return authorization.startsWith(jwtProperties.getHeaderPrefix()); + } +}
Java
Date ํƒ€์ž…์„ ์“ฐ์…จ๋Š”๋ฐ LocalDate ํƒ€์ž…์ด ์•„๋‹Œ ์ด์œ ๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€์š”?
@@ -0,0 +1,21 @@ +package com.requestrealpiano.songrequest.security.jwt; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; + +@RequiredArgsConstructor +@Getter +@ConstructorBinding +@ConfigurationProperties(prefix = "jwt") +public class JwtProperties { + + private final String tokenSecret; + private final String tokenExpiration; + private final String header; + private final String headerPrefix; + private final String tokenUrl; + private final String generationKeySecret; + private final String generationKeyExpiration; +}
Java
์ƒ์„ฑ์ž๊ฐ€ ํ•„์š”ํ•œ๊ฐ€์š”? ๋ถˆํ•„์š”ํ•œ ์ƒ์„ฑ์ž๊ฐ™์•„์š”
@@ -0,0 +1,33 @@ +package com.requestrealpiano.songrequest.security.oauth; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.requestrealpiano.songrequest.global.error.response.ErrorCode; +import com.requestrealpiano.songrequest.global.error.response.ErrorResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@RequiredArgsConstructor +@Component +public class CustomAccessDeniedHandler implements AccessDeniedHandler { + + private final ObjectMapper objectMapper; + + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { + ErrorCode accessDeniedError = ErrorCode.ACCESS_DENIED_ERROR; + String errorResponse = objectMapper.writeValueAsString(ErrorResponse.from(accessDeniedError)); + response.getWriter().print(errorResponse); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.setStatus(accessDeniedError.getStatusCode()); + response.getWriter().flush(); + response.getWriter().close(); + } +}
Java
์ด์ •๋„ ๊ธธ์–ด์ง€๋ฉด throws๋ถ€ํ„ฐ ํ•œ์นธ ๋‚ด๋ ค์„œ ๋ณด๊ธฐ ์‰ฝ๊ฒŒ ํ•ด์ฃผ์„ธ์šฉ
@@ -0,0 +1,33 @@ +package com.requestrealpiano.songrequest.security.oauth; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.requestrealpiano.songrequest.global.error.response.ErrorCode; +import com.requestrealpiano.songrequest.global.error.response.ErrorResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@RequiredArgsConstructor +@Component +public class CustomAccessDeniedHandler implements AccessDeniedHandler { + + private final ObjectMapper objectMapper; + + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { + ErrorCode accessDeniedError = ErrorCode.ACCESS_DENIED_ERROR; + String errorResponse = objectMapper.writeValueAsString(ErrorResponse.from(accessDeniedError)); + response.getWriter().print(errorResponse); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.setStatus(accessDeniedError.getStatusCode()); + response.getWriter().flush(); + response.getWriter().close(); + } +}
Java
์—ฌ๊ธฐ์„œ ๊ถ๊ธˆํ•œ๊ฒŒ ์ด๋Œ€๋กœ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ์—๋Ÿฌ์ฒ˜๋ฆฌ๋Š” ๋ฐœ์ƒ์ด ์ž˜ ๋˜๊ฒ ์œผ๋‚˜ ์Šคํ”„๋ง ๋กœ๊ทธ์—๋„ ์ฐํžˆ๋Š” ์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค. ์ œ๊ฐ€ ์ด์ „ ์ฝ”๋“œ์Šค์ฟผ๋“œ ๋„์„œ๊ด€ ํ”„๋กœ์ ํŠธ์—์„œ๋„ ์ด๋Ÿฐ์‹์œผ๋กœ ์ฒ˜๋ฆฌํ–ˆ์„ ๋•Œ ๋กœ๊ทธ์— ์ฐํžˆ์ง€ ์•Š๋Š” ์‚ฌ์†Œํ•œ ๋ฌธ์ œ์ ์ด ์ƒ๊ฒผ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,33 @@ +package com.requestrealpiano.songrequest.security.oauth; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.requestrealpiano.songrequest.global.error.response.ErrorCode; +import com.requestrealpiano.songrequest.global.error.response.ErrorResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@RequiredArgsConstructor +@Component +public class CustomAccessDeniedHandler implements AccessDeniedHandler { + + private final ObjectMapper objectMapper; + + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { + ErrorCode accessDeniedError = ErrorCode.ACCESS_DENIED_ERROR; + String errorResponse = objectMapper.writeValueAsString(ErrorResponse.from(accessDeniedError)); + response.getWriter().print(errorResponse); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.setStatus(accessDeniedError.getStatusCode()); + response.getWriter().flush(); + response.getWriter().close(); + } +}
Java
๊ทธ๋ž˜์„œ ์ƒ๊ฐํ•ด๋‚ธ ๊ฒƒ์ด `AccessDeniedException`์„ ๋ฐ›๋Š” ์—๋Ÿฌํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ํ•ด๋‹น ์—๋Ÿฌ๋ฅผ ์ƒ์†๋ฐ›์•„ ์—ฌ๊ธฐ์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค๋ฅธ exceptionHandler์ฒ˜๋Ÿผ ํ•œ๋ฒˆ์— ๊ด€๋ฆฌํ•˜๊ธฐ๋„ ํŽธํ•˜๊ณ  ๋กœ๊ทธ๋„ ์ฐํž ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ```java @Component("restAuthenticationEntryPoint") public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint { @Autowired private HandlerExceptionResolver resolver; @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { resolver.resolveException(request, response, null, exception); } } ```
@@ -0,0 +1,14 @@ +package com.requestrealpiano.songrequest.security.oauth; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@AuthenticationPrincipal +public @interface LoginAccount { +}
Java
์ด๊ฒƒ๋งŒ ๋‹ฌ์•„๋„ GlobalAdvice ์„ค์ •์„ ํ•  ํ•„์š”๊ฐ€ ์—†์–ด์„œ ์ข‹์ฃ !
@@ -0,0 +1,24 @@ +package com.requestrealpiano.songrequest.controller; + +import com.requestrealpiano.songrequest.service.AccountService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/accounts") +public class AccountController { + + private final AccountService accountService; + + @GetMapping("/auth") + public ResponseEntity<Void> generateToken(@RequestHeader HttpHeaders httpHeaders) { + String jwtToken = accountService.generateJwtToken(httpHeaders.getFirst(HttpHeaders.AUTHORIZATION)); + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HttpHeaders.AUTHORIZATION, jwtToken); + return new ResponseEntity<>(responseHeaders, HttpStatus.NO_CONTENT); + } +}
Java
๋ถ„๋ช… ๋ชจ๋“  ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋™์‹œ์— ์ˆ˜์ •์„ ํ–ˆ์„ํ…๋ฐ ์—ฌ๊ธฐ๋Š” ์ƒํƒœ์ฝ”๋“œ๋งŒ ๋ฐ”๊พธ๊ณ  ํ˜•์‹์€ ์ด๋ ‡๊ฒŒ ๋‚จ๊ฒจ ๋‘์—ˆ์—ˆ๋„ค์š”. ํ†ต์ผ์„ฑ์„ ์œ„ํ•ด ์ˆ˜์ • ํ•˜๊ฒ ์Šต๋‹ˆ๋‹คใ…Žใ…Ž
@@ -2,18 +2,18 @@ import com.requestrealpiano.songrequest.domain.song.searchapi.response.SearchApiResponse; import com.requestrealpiano.songrequest.global.response.ApiResponse; +import com.requestrealpiano.songrequest.global.response.StatusCode; import com.requestrealpiano.songrequest.service.SongService; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.validation.constraints.Size; import static com.requestrealpiano.songrequest.global.constant.ValidationCondition.*; -import static com.requestrealpiano.songrequest.global.response.ApiResponse.OK; +import static com.requestrealpiano.songrequest.global.response.ApiResponse.SUCCESS; +import static com.requestrealpiano.songrequest.global.response.StatusCode.OK; @RequiredArgsConstructor @Validated @@ -23,12 +23,13 @@ public class SongController { private final SongService songService; + @ResponseStatus(HttpStatus.OK) @GetMapping public ApiResponse<SearchApiResponse> search(@RequestParam(defaultValue = "artist") @Size(max = ARTIST_MAX) String artist, @RequestParam(defaultValue = "title") @Size(max = TITLE_MAX) String title) { SearchApiResponse searchApiResponse = songService.searchSong(artist, title); - return OK(searchApiResponse); + return SUCCESS(OK, searchApiResponse); } }
Java
์ง€๋‚œ๋ฒˆ ๋ฆฌ๋ทฐ์— ๊ฐ™์€ ์˜๊ฒฌ์„ ์ฃผ์…”์„œ ๋ณ€๊ฒฝ์„ ๊ณ ๋ ค ํ•ด๋ดค์—ˆ๋Š”๋ฐ์š”. ์—ฌ๊ธฐ ์ด ๋‘ ๊ฐ’์€ ๋นˆ ๊ฐ’์œผ๋กœ ์š”์ฒญ์ด ์™”์„ ๋•Œ `NotEmpty` ์™€ ๊ฐ™์€ ์ฒ˜๋ฆฌ๋กœ ์—๋Ÿฌ๋ฅผ ๋ฐ˜ํ™˜ํ• ๊ฒŒ ์•„๋‹ˆ๋ผ default value๋กœ ๊ฒ€์ƒ‰์„ ๊ณ„์† ์ง„ํ–‰ ์‹œํ‚ฌ ์ƒ๊ฐ ์ž…๋‹ˆ๋‹ค. ๋งŒ์•ฝ `@ModelAttribute` DTO๋กœ ๋ฐ›์„ ๊ฒฝ์šฐ์—๋Š” setter๋กœ ๊ฐ’์„ ๋ฐ”์ธ๋”ฉ ํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ  ์žˆ๋Š”๋ฐ์š”. ๊ทธ๋ ‡๋‹ค๋ฉด setter์—์„œ ๋นˆ ๊ฐ’์ผ ๊ฒฝ์šฐ ๊ธฐ๋ณธ ๊ฐ’์„ ์ฃผ๋Š” ๋กœ์ง์ด ํ•„์š”ํ•  ๋“ฏ ๋ณด์ด๋Š”๋ฐ, ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด `@RequestParam` ์ฒ˜๋Ÿผ `@Something(defaultValue = "Default value")` ์ด๋Ÿฐ์‹์œผ๋กœ ์• ๋…ธํ…Œ์ด์…˜ ๊ธฐ๋ฐ˜์œผ๋กœ ์ˆ˜์ • ํ•˜๊ณ  ์‹ถ์€๋ฐ ์›๋ž˜ ์ŠคํŽ™์— ์—†๋Š”๊ฑด์ง€ ์ œ๊ฐ€ ๋ชป ์ฐพ๋Š”๊ฑด์ง€...ใ…Žใ…Ž setter์—์„œ ์ง์ ‘ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ ๋ง๊ณ  ํ˜น์‹œ ์•Œ๊ณ  ๊ณ„์‹œ๋Š” ๋” ์ข‹์€ ๋ฐฉ๋ฒ•์ด ์žˆ์„๊นŒ์š”?
@@ -1,5 +1,6 @@ package com.requestrealpiano.songrequest.domain.account; +import com.requestrealpiano.songrequest.security.oauth.OAuthAttributes; import com.requestrealpiano.songrequest.domain.base.BaseTimeEntity; import com.requestrealpiano.songrequest.domain.letter.Letter; import lombok.AccessLevel; @@ -8,9 +9,6 @@ import lombok.NoArgsConstructor; import javax.persistence.*; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.List; @@ -25,7 +23,7 @@ public class Account extends BaseTimeEntity { private Long id; @Column(name = "google_oauth_id") - private Long googleOauthId; + private String googleOauthId; private String name; @@ -44,12 +42,36 @@ public class Account extends BaseTimeEntity { private List<Letter> letters = new ArrayList<>(); @Builder - private Account(Long googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) { + private Account(String googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) { this.googleOauthId = googleOauthId; this.name = name; this.email = email; this.role = role; this.avatarUrl = avatarUrl; this.requestCount = requestCount; } + + public String getRoleKey() { return role.getKey(); } + + public String getRoleValue() { + return role.getValue(); + } + + public Account updateProfile(OAuthAttributes attributes) { + this.name = attributes.getName(); + this.email = attributes.getEmail(); + this.avatarUrl = attributes.getAvatarUrl(); + return this; + } + + public static Account from(OAuthAttributes oAuthAttributes) { + return Account.builder() + .googleOauthId(oAuthAttributes.getGoogleOauthId()) + .name(oAuthAttributes.getName()) + .email(oAuthAttributes.getEmail()) + .role(Role.MEMBER) + .avatarUrl(oAuthAttributes.getAvatarUrl()) + .requestCount(0) + .build(); + } }
Java
๊ณ„์ •์„ ์ตœ์ดˆ ์ƒ์„ฑ ํ–ˆ์„ ๋•Œ์˜ ๊ธฐ๋ณธ ๊ฐ’ (์‹ ์ฒญ๊ณก ๋“ฑ๋ก ์ˆ˜) ์ž…๋‹ˆ๋‹ค. ์ด์ „ ๋ฆฌ๋ทฐ์—์„œ ์ด๋ ‡๊ฒŒ ์ง๊ด€์ ์œผ๋กœ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ์ด๋Ÿฐ ๊ฐ’์€ ๋ณ€์ˆ˜๋กœ ๋นผ์ง€ ์•Š์•„๋„ ๋ ๊ฑฐ ๊ฐ™๋‹ค๋Š” ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์•˜์—ˆ๋Š”๋ฐ, ๊ทธ๊ฑธ ๋ฐ˜์˜ํ•ด์„œ ์ฝ”๋“œ ์ž‘์„ฑ์„ ํ–ˆ๋˜ ๋“ฏ ์‹ถ์Šต๋‹ˆ๋‹ค. ์šฐ์„  ์ด ์ฝ”๋“œ๋Š” ์ปฌ๋Ÿผ์— ๊ธฐ๋ณธ ๊ฐ’์„ ์ถ”๊ฐ€ ํ•  ์˜ˆ์ •์ด๊ธฐ ๋•Œ๋ฌธ์— ์—†์–ด์งˆ ์ฝ”๋“œ๊ฐ€ ๋  ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ํ˜น์‹œ ์จ๋‹ˆ๋Š” ๋งค์ง๋„˜๋ฒ„๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์— ๋Œ€ํ•œ ์–ด๋–ค ๊ธฐ์ค€์ด ์žˆ์œผ์‹ค๊นŒ์š”? ์˜ˆ์ „์— ํŒ€ ํ”„๋กœ์ ํŠธ ํ•  ๋•Œ๋„ ๋งค์ง ๋„˜๋ฒ„ ์‚ฌ์šฉ์„ ๋ฌด์กฐ๊ฑด ํ”ผํ•˜๋ ค๊ณ  ๋ชจ๋‘ ๋ณ€์ˆ˜๋กœ ์ง€์ • ํ–ˆ๋‹ค๊ฐ€ ์˜คํžˆ๋ ค ์˜๋ฏธ ํ•ด์„์ด ์–ด๋ ค์›Œ์กŒ๋‹ค๋Š” ํ”ผ๋“œ๋ฐฑ์„ ๋ฆฌ๋ทฐ์–ด ๋ถ„๊ป˜ ๋ฐ›์€์ ์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ์—๋Š” ๊ทธ๋ƒฅ ์ˆซ์ž ๊ฐ’์„ ์‚ฌ์šฉํ•˜๊ณ  ์ฃผ์„์œผ๋กœ ๋ถ€๊ฐ€ ์„ค๋ช…์„ ์ ๋Š” ๊ฒƒ๋„ ๊ดœ์ฐฎ๋‹ค๊ณ  ํ•˜์‹œ๋”๋ผ๊ตฌ์š”. ์จ๋‹ˆ๋Š” ์–ด๋–ค ๊ธฐ์ค€์„ ๊ฐ€์ง€๊ณ  ๊ณ„์‹œ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
@@ -1,5 +1,6 @@ package com.requestrealpiano.songrequest.domain.account; +import com.requestrealpiano.songrequest.security.oauth.OAuthAttributes; import com.requestrealpiano.songrequest.domain.base.BaseTimeEntity; import com.requestrealpiano.songrequest.domain.letter.Letter; import lombok.AccessLevel; @@ -8,9 +9,6 @@ import lombok.NoArgsConstructor; import javax.persistence.*; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.List; @@ -25,7 +23,7 @@ public class Account extends BaseTimeEntity { private Long id; @Column(name = "google_oauth_id") - private Long googleOauthId; + private String googleOauthId; private String name; @@ -44,12 +42,36 @@ public class Account extends BaseTimeEntity { private List<Letter> letters = new ArrayList<>(); @Builder - private Account(Long googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) { + private Account(String googleOauthId, String name, String email, Role role, String avatarUrl, Integer requestCount) { this.googleOauthId = googleOauthId; this.name = name; this.email = email; this.role = role; this.avatarUrl = avatarUrl; this.requestCount = requestCount; } + + public String getRoleKey() { return role.getKey(); } + + public String getRoleValue() { + return role.getValue(); + } + + public Account updateProfile(OAuthAttributes attributes) { + this.name = attributes.getName(); + this.email = attributes.getEmail(); + this.avatarUrl = attributes.getAvatarUrl(); + return this; + } + + public static Account from(OAuthAttributes oAuthAttributes) { + return Account.builder() + .googleOauthId(oAuthAttributes.getGoogleOauthId()) + .name(oAuthAttributes.getName()) + .email(oAuthAttributes.getEmail()) + .role(Role.MEMBER) + .avatarUrl(oAuthAttributes.getAvatarUrl()) + .requestCount(0) + .build(); + } }
Java
์ €๋Š” ๋ถ€๊ฐ€์  ์„ค๋ช…์œผ๋กœ ์ฃผ์„๋„ฃ๋Š”๊ฒƒ๋„ ๊ดœ์ฐฎ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์š” ๊ทธ๋Ÿฌ๋‚˜ ๋งŒ์•ฝ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์—์„œ ์—ฌ๋Ÿฌ๋ฒˆ ์ค‘๋ณต๋์„๋•Œ๋Š” ๋”ฐ๋กœ ๊ด€๋ฆฌํ•˜๋Š”๊ฒŒ ๋‚ซ๊ฒ ๋„ค์š”
@@ -11,6 +11,12 @@ public enum ErrorCode { METHOD_NOT_ALLOWED(405, "์ง€์›ํ•˜์ง€ ์•Š๋Š” ์š”์ฒญ ๋ฉ”์†Œ๋“œ ์ž…๋‹ˆ๋‹ค."), INTERNAL_SERVER_ERROR(500, "์„œ๋ฒ„์—์„œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค."), + // Auth + UNAUTHENTICATED_ERROR(401, "์ธ์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋กœ๊ทธ์ธ ์ดํ›„ ๋‹ค์‹œ ์‹œ๋„ ํ•ด์ฃผ์„ธ์š”."), + JWT_INVALID_ERROR(400, "์˜ฌ๋ฐ”๋ฅธ ์ธ์ฆ ์ •๋ณด๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธ ํ•ด์ฃผ์„ธ์š”."), + JWT_EXPIRATION_ERROR(401, "์ธ์ฆ ์ •๋ณด๊ฐ€ ๋งŒ๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธ ํ•ด์ฃผ์„ธ์š”."), + ACCESS_DENIED_ERROR(403, "ํ•ด๋‹น ์š”์ฒญ์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."), + // Account ACCOUNT_NOT_FOUND(404, "ํ•ด๋‹น ๊ณ„์ •์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
Java
JWT ๊ด€๋ จ ์˜ˆ์™ธ๋ฅผ ๊ตฌ์ƒํ•  ๋•Œ ์•„๋ž˜์˜ ๋„ค๊ฐ€์ง€ ์˜ˆ์™ธ๊ฐ€ ๋งจ ์ฒ˜์Œ ๊ณ ๋ คํ–ˆ๋˜ JWT ๊ด€๋ จ ์˜ˆ์™ธ์˜€์Šต๋‹ˆ๋‹ค. 1. ExpiredJwtException : ์œ ํšจ๊ธฐ๊ฐ„์ด ์ง€๋‚œ Token์œผ๋กœ ์š”์ฒญ 2. InvalidClaimException : Claim ํŒŒ์‹ฑ ์‹คํŒจ๋กœ ์ธํ•œ ์˜ˆ์™ธ 3. MalformedJwtException : ๊ตฌ์กฐ์  ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” JWT ํ† ํฐ์œผ๋กœ ์ธํ•œ ์˜ˆ์™ธ 4. SignatureException : ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ JWT ์‹œ๊ทธ๋‹ˆ์ฒ˜๋กœ ์ธํ•œ ๊ฒ€์ฆ ์‹คํŒจ ์ด ๋•Œ 1๋ฒˆ '์œ ํšจ๊ธฐ๊ฐ„ ๋งŒ๋ฃŒ' ์™€ 2, 3, 4์— ํ•ด๋‹นํ•˜๋Š” 'JWT ๊ฒ€์ฆ ์‹คํŒจ' ๋‘๊ฐ€์ง€ ์œ ํ˜•์œผ๋กœ๋งŒ ๋‚˜๋ˆ„์–ด์„œ ์ฒ˜๋ฆฌ๋ฅผ ํ•œ ๋’ค ํด๋ผ์ด์–ธํŠธ์— ์•Œ๋ ค์ฃผ๋ฉด ๋ ๊ฑฐ๋ผ ์ƒ๊ฐํ•˜๊ณ  ๋‹ค์Œ์˜ ๋‘๊ฐ€์ง€๋กœ ์ฒ˜๋ฆฌ ํ•˜๋„๋ก ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค. `JWT_INVALID_ERROR(400, "์˜ฌ๋ฐ”๋ฅธ ์ธ์ฆ ์ •๋ณด๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธ ํ•ด์ฃผ์„ธ์š”.") - JwtException` `JWT_EXPIRATION_ERROR(401, "์ธ์ฆ ์ •๋ณด๊ฐ€ ๋งŒ๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋กœ๊ทธ์ธ ํ•ด์ฃผ์„ธ์š”.") - ExpiredJwtException` ๋ง์”€ํ•˜์‹  `JWT๊ฐ€ ์•„๋‹Œ Token ์‚ฌ์šฉ์œผ๋กœ ์ธํ•œ ์—๋Ÿฌ`์™€ `JWT ์ด์ง€๋งŒ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ JWT๋ฅผ ์‚ฌ์šฉ` ๋‘ ๊ฐ€์ง€ ๊ฒฝ์šฐ๋ฅผ ๊ตฌ๋ถ„ ํ•  ๋•Œ ์–ด๋–ค ๋ถ€๋ถ„์—์„œ ์žฅ์ ์ด ์žˆ๋Š” ๊ฒƒ์ธ์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹คใ…Žใ…Ž ๋ฌผ๋ก  ์ด๋Ÿฐ ์ธ์ฆ๊ณผ ๋ณด์•ˆ์— ๋Œ€ํ•œ ๊ฒƒ์€ ์ตœ๋Œ€ํ•œ ๊ฒฌ๊ณ ํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค๋Š” ์ƒ๊ฐ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋ฐ์š”. ํ˜น์‹œ ์ด ๋‘˜์„ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š์•˜์„ ๋•Œ ์–ด๋–ค ํฐ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธธ ์—ฌ์ง€๊ฐ€ ์žˆ์„๊นŒ์š”? ์ œ๊ฐ€ ๋ชจ๋ฅด๊ณ  ์ง€๋‚˜์น˜๊ณ  ์žˆ๋Š” ๊ฒƒ์ด ์žˆ๋Š”์ง€์— ๋Œ€ํ•œ ์šฐ๋ ค์™€ ์จ๋‹ˆ์˜ ์˜๊ฒฌ์ด ๊ถ๊ธˆํ•ด์„œ ์—ฌ์ญˆ์–ด ๋ด…๋‹ˆ๋‹ค!
@@ -0,0 +1,63 @@ +language: java +jdk: + - openjdk11 + +branches: + only: + - main + +cache: + directories: + - '$HOME/.m2/repository' + - '$HOME/.gradle' + +script: "./gradlew clean build" + +before_deploy: + - mkdir -p before-deploy + - cp scripts/*.sh before-deploy/ + - cp appspec.yml before-deploy/ + - cp build/libs/*.jar before-deploy + - cd before-deploy && zip -r before-deploy * + - cd ../ && mkdir -p deploy + - mv before-deploy/before-deploy.zip deploy/songrequest-backend.zip + +deploy: + - provider: s3 + access_key_id: $AWS_ACCESS_KEY + secret_access_key: $AWS_SECRET_KEY + + bucket: songrequest-backend-build + region: ap-northeast-2 + + skip_cleanup: true + acl: private + local_dir: deploy + + wait-until-deployed: true + + on: + all_branches: true + + - provider: codedeploy + access_key_id: $AWS_ACCESS_KEY + secret_access_key: $AWS_SECRET_KEY + + bucket: songrequest-backend-build + key: songrequest-backend.zip + + bundle_type: zip + application: songrequest-backend + + deployment_group: songrequest-backend-group + + region: ap-northeast-2 + wait-until-deployed: true + + on: + all_branches: true + +notifications: + email: + recipients: + - museopkim0214@gmail.com
Unknown
travis CI ์ด๊ตฐ์š”. ์ €๋„ ์จ๋ดค์ง€๋งŒ Github Actions๋ณด๋‹ค ๋А๋ฆฌ๊ณ  ๋””๋ฒ„๊น…ํ•˜๋Š”๋ฐ ๋ถˆํŽธํ•ด์„œ ์ „ ์“ฐ๋‹ค๊ฐ€ ๋ฐ”๊ฟจ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ๋Š” Github Actions + AWS CodeBuild๋ฅผ ๋ณ‘ํ•ฉํ•ด์„œ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ CIํˆด ์ค‘ travis ci๋ฅผ ์‚ฌ์šฉํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,18 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ubuntu/app/songrequest/zip/ + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + ApplicationStart: + - location: deploy.sh + timeout: 60 + runas: ubuntu
Unknown
์—ฌ๊ธฐ์„œ ์•„์…”์•ผํ• ๊ฑด ๋งŒ์•ฝ blue/green ๋ฐฐํฌ๋ฅผ ํ•˜์‹ค ๊ฒฝ์šฐ overwrite๊ฐ€ ๋จน์งˆ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ beforeInstall ์‰˜์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜์…”์„œ ํŒŒ์ผ ์‚ญ์ œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์งœ์…”์•ผํ•ฉ๋‹ˆ๋‹ค. ์ด ๋‚ด์šฉ์€ ์–ธ์  ๊ฐ€ ์ œ ๋ธ”๋กœ๊ทธ์— ์ ์„ ์˜ˆ์ •์ด๋‹ˆ ๊ถ๊ธˆํ•˜์‹œ๋ฉด ๋ณด์„ธ์šฉ
@@ -0,0 +1,18 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ubuntu/app/songrequest/zip/ + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + ApplicationStart: + - location: deploy.sh + timeout: 60 + runas: ubuntu
Unknown
๋งŒ์•ฝ ๋ณธ์ธ์ด blue/green ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ๋ฅผ ํ•˜์‹ค๊ฒฝ์šฐ ์—ฌ๊ธฐ์„œ BeforeInstall ์‰˜์Šคํฌ๋ฆฝํŠธ ๋„ฃ์œผ์…”์„œ ์ด์ „ ๋นŒ๋“œ๋œํŒŒ์ผ ์‚ญ์ œํ•˜์‹œ๋Š” ์‰˜์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋„ฃ์–ด์•ผ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™๋˜๋‹ˆ ๊ผญ ๊ธฐ์–ตํ•˜์„ธ์š”
@@ -23,13 +23,33 @@ ext { set('snippetsDir', file("build/generated-snippets")) } +bootJar { + dependsOn asciidoctor + from("${asciidoctor.outputDir}/html5") { + into 'static/docs' + } +} + +test { + outputs.dir snippetsDir + useJUnitPlatform() +} + +asciidoctor { + inputs.dir snippetsDir + dependsOn test + attributes 'snippets': snippetsDir +} + dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' - compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1' - compile 'org.apache.commons:commons-lang3:3.11' + implementation 'javax.validation:validation-api:2.0.1.Final' + implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1' + implementation 'org.hibernate.validator:hibernate-validator:6.1.7.Final' + implementation 'org.apache.commons:commons-lang3:3.11' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.h2database:h2' runtimeOnly 'mysql:mysql-connector-java'
Unknown
์ด๊ฒƒ๋„ ์ข‹์ง€๋งŒ DTO <-> Entity์—ญํ• ์„ ํ•˜๋Š” ๊ธฐ์กด์˜ modelmapper๋„ ์ข‹์ง€๋งŒ Mapstruct๋„ ํ›จ์”ฌ ์„ฑ๋Šฅ๋„ ์ข‹์Šต๋‹ˆ๋‹ค. ์‹ค๋ฌด์—์„œ๋„ ์‚ฌ์šฉํ•˜๋Š” ์ค‘์ž…๋‹ˆ๋‹ค. https://huisam.tistory.com/entry/mapStruct
@@ -0,0 +1,38 @@ +#!/bin/bash + +REPOSITORY=/home/ubuntu/app/songrequest +PROJECT_NAME=song-request + +echo "> Build ํŒŒ์ผ ๋ณต์‚ฌ" + +cp $REPOSITORY/zip/*.jar $REPOSITORY/ + +echo "> ํ˜„์žฌ ๊ตฌ๋™ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ pid ํ™•์ธ" + +CURRENT_PID=$(pgrep -fl song-request | grep jar | awk '{print $1}') + +echo "ํ˜„์žฌ ๊ตฌ๋™ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ pid : $CURRENT_PID" + +if [ -z "$CURRENT_PID" ]; then + echo "> ํ˜„์žฌ ๊ตฌ๋™ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์—†์œผ๋ฏ€๋กœ ์ข…๋ฃŒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค." +else + echo "> kill -15 $CURRENT_PID" + kill -15 $CURRENT_PID + sleep 5 +fi + +echo "> ์ƒˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ" + +JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tail -n 1) + +echo "> JAR Name : $JAR_NAME" + +echo "> $JAR_NAME์— ์‹คํ–‰ ๊ถŒํ•œ ์ถ”๊ฐ€" + +chmod +x $JAR_NAME + +echo "> $JAR_NAME ์‹คํ–‰" + +nohup java -jar \ + -Dspring.profiles.active=prod \ + $JAR_NAME > $REPOSITORY/nohup.out 2>&1 &
Unknown
home์— ๊ทธ๋Œ€๋กœ ๋ฐฐํฌํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ํด๋”๋ฅผ ์ƒ์„ฑํ•ด์„œ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค. ์ž˜ ์ ์šฉํ•˜์…จ๋„ค์š”
@@ -9,14 +9,16 @@ import javax.annotation.PostConstruct; import java.util.TimeZone; +import static com.requestrealpiano.songrequest.global.constant.JpaProperties.ASIA_SEOUL; + @EnableConfigurationProperties(value = {ManiaDbProperties.class, LastFmProperties.class}) @SpringBootApplication public class SongRequestApplication { @PostConstruct public void setTimeZone() { - String SEOUL = "Asia/Seoul"; - TimeZone.setDefault(TimeZone.getTimeZone(SEOUL)); + TimeZone KST = TimeZone.getTimeZone(ASIA_SEOUL); + TimeZone.setDefault(KST); } public static void main(String[] args) {
Java
```suggestion Timezone.setDefault(TimeZone.getTimeZone(ASIA_SEOUL)); ``` ์œผ๋กœ ๋ฐ”๊พธ๋ฉด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜์š”?
@@ -1,27 +1,33 @@ package com.requestrealpiano.songrequest.controller; -import com.fasterxml.jackson.core.JsonProcessingException; import com.requestrealpiano.songrequest.domain.song.searchapi.response.SearchApiResponse; import com.requestrealpiano.songrequest.global.response.ApiResponse; import com.requestrealpiano.songrequest.service.SongService; import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.validation.constraints.Size; + +import static com.requestrealpiano.songrequest.global.constant.ValidationCondition.*; import static com.requestrealpiano.songrequest.global.response.ApiResponse.OK; @RequiredArgsConstructor +@Validated @RestController -@RequestMapping("/songs") +@RequestMapping("/api/songs") public class SongController { private final SongService songService; @GetMapping - public ApiResponse<SearchApiResponse> search(@RequestParam String artist, - @RequestParam String title) throws JsonProcessingException { + public ApiResponse<SearchApiResponse> search(@RequestParam(defaultValue = "artist") @Size(max = ARTIST_MAX) + String artist, + @RequestParam(defaultValue = "title") @Size(max = TITLE_MAX) + String title) { SearchApiResponse searchApiResponse = songService.searchSong(artist, title); return OK(searchApiResponse); }
Java
RequestParam๋„ ์ข‹์ง€๋งŒ artist, title๋„ ํ•œ๋ฒˆ์— ๊ด€๋ฆฌํ•˜๋Š” DTO๋ฅผ ๋งŒ๋“ค๋ฉด ์–ด๋–ค๊ฐ€์š”? ์ž์ฃผ ์“ฐ์ผ์ง€ ๋ชจ๋ฅด๋‹ˆ DTO๋ฅผ ๋งŒ๋“ค๊ณ  ๊ฑฐ๊ธฐ์„œ Validation์ฒ˜๋ฆฌํ•ด๋„ ๊ดœ์ฐฎ์•„ ๋ณด์ž…๋‹ˆ๋‹ค.
@@ -0,0 +1,32 @@ +package com.requestrealpiano.songrequest.domain.letter.request.inner; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; + +import static com.requestrealpiano.songrequest.global.constant.ValidationCondition.*; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +public class SongRequest { + + @NotEmpty(message = NOT_EMPTY_MESSAGE) + @Size(min = TITLE_MIN, max = TITLE_MAX, message = TITLE_MESSAGE) + private String title; + + @NotEmpty(message = NOT_EMPTY_MESSAGE) + @Size(min = ARTIST_MIN, max = ARTIST_MAX, message = ARTIST_MESSAGE) + private String artist; + + @Size(max = IMAGE_MAX, message = IMAGE_MESSAGE) + private String imageUrl; + + SongRequest(String title, String artist, String imageUrl) { + this.title = title; + this.artist = artist; + this.imageUrl = imageUrl; + } +}
Java
validation ๊ดœ์ฐฎ๋„ค์š”
@@ -0,0 +1,25 @@ +package com.requestrealpiano.songrequest.global.constant; + +public interface ValidationCondition { + + // Common + String NOT_EMPTY_MESSAGE = "ํ•„์ˆ˜ ์ž…๋ ฅ ์ •๋ณด ์ž…๋‹ˆ๋‹ค."; + + // Artist + String ARTIST_MESSAGE = "์•„ํ‹ฐ์ŠคํŠธ๋Š” 30์ž ๋ฏธ๋งŒ ์ž…๋‹ˆ๋‹ค."; + int ARTIST_MAX = 30; + int ARTIST_MIN = 1; + + // Title + String TITLE_MESSAGE = "์ œ๋ชฉ์€ 30์ž ๋ฏธ๋งŒ ์ž…๋‹ˆ๋‹ค."; + int TITLE_MAX = 30; + int TITLE_MIN = 1; + + // Image URL + String IMAGE_MESSAGE = "์œ ํšจํ•œ ์ด๋ฏธ์ง€ ์ •๋ณด๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค."; + int IMAGE_MAX = 100; + + // Song Story + String SONG_STORY_MESSAGE = "์‚ฌ์—ฐ์€ 500์ž ๋ฏธ๋งŒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."; + int SONG_STORY_MAX = 500; +}
Java
interface์— ๊ทธ๋Œ€๋กœ value๊ฐ’์„ ์ง€์ •ํ•˜๋ฉด ์ข‹์ง€์•Š์Šต๋‹ˆ๋‹ค. ์ดํŽ™ํ‹ฐ๋ธŒ ์ž๋ฐ”์—์„œ ๋ณธ ๊ฑฐ๊ฐ™์€๋ฐ ๋‚ด์šฉ์ด ์ •ํ™•ํ•˜๊ฒŒ ๊ธฐ์–ต์€ ์•ˆ๋‚˜์ง€๋งŒ ์ด๋ ‡๊ฒŒ ํ•˜์ง€๋ง๋ผ๊ณ  ๊ฐ•ํ•˜๊ฒŒ ๊ฒฝ๊ณ ํ–ˆ๋˜ ๊ธฐ์–ต์ด ๋‚˜๋„ค์š”. ๊ทธ๋ฆฌ๊ณ  ๋‚ด์šฉ์ƒ interface๋ณด๋‹จ enum์— ์–ด์šธ๋ฆฌ๋Š”๋ฐ enum์€ ์–ด๋–ค๊ฐ€์š”?
@@ -0,0 +1,64 @@ +package com.requestrealpiano.songrequest.global.error; + +import com.requestrealpiano.songrequest.global.error.exception.BusinessException; +import com.requestrealpiano.songrequest.global.error.exception.ParsingFailedException; +import com.requestrealpiano.songrequest.global.error.response.ErrorCode; +import com.requestrealpiano.songrequest.global.error.response.ErrorResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import javax.validation.ConstraintViolationException; + +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(ConstraintViolationException.class) + protected ResponseEntity<ErrorResponse> handleConstraintViolationException(ConstraintViolationException exception) { + log.error("handleConstraintViolationException", exception); + ErrorResponse errorResponse = ErrorResponse.from(ErrorCode.INVALID_INPUT_VALUE); + return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + protected ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException exception){ + log.error("handleMethodArgumentNotValidException", exception); + ErrorResponse errorResponse = ErrorResponse.of(ErrorCode.INVALID_INPUT_VALUE, exception.getBindingResult()); + return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + protected ResponseEntity<ErrorResponse> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) { + log.error("handleHttpRequestMethodNotSupportedException", exception); + ErrorResponse errorResponse = ErrorResponse.from(ErrorCode.METHOD_NOT_ALLOWED); + return new ResponseEntity<>(errorResponse, HttpStatus.METHOD_NOT_ALLOWED); + } + + @ExceptionHandler(ParsingFailedException.class) + protected ResponseEntity<ErrorResponse> handleParsingFailedException(ParsingFailedException exception) { + log.error("handleJsonProcessingException", exception); + ErrorCode errorCode = exception.getErrorCode(); + ErrorResponse errorResponse = ErrorResponse.from(errorCode); + return new ResponseEntity<>(errorResponse, HttpStatus.valueOf(errorResponse.getStatusCode())); + } + + @ExceptionHandler(BusinessException.class) + protected ResponseEntity<ErrorResponse> handleBusinessException(BusinessException exception) { + log.error("handleBusinessException", exception); + ErrorCode errorCode = exception.getErrorCode(); + ErrorResponse errorResponse = ErrorResponse.from(errorCode); + return new ResponseEntity<>(errorResponse, HttpStatus.valueOf(errorCode.getStatusCode())); + } + + @ExceptionHandler(Exception.class) + protected ResponseEntity<ErrorResponse> handleException(Exception exception) { + log.error("handleException", exception); + ErrorResponse errorResponse = ErrorResponse.from(ErrorCode.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR); + } +}
Java
์ด ์ฝ”๋“œ๊ฐ€ validation ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋กœ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ž‘๋™์ด ์ž˜๋˜๋‚˜์š”? ํ•œ๋ฒˆ ํ…Œ์ŠคํŠธ์ฝ”๋“œ์—์„œ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,38 @@ +#!/bin/bash + +REPOSITORY=/home/ubuntu/app/songrequest +PROJECT_NAME=song-request + +echo "> Build ํŒŒ์ผ ๋ณต์‚ฌ" + +cp $REPOSITORY/zip/*.jar $REPOSITORY/ + +echo "> ํ˜„์žฌ ๊ตฌ๋™ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ pid ํ™•์ธ" + +CURRENT_PID=$(pgrep -fl song-request | grep jar | awk '{print $1}') + +echo "ํ˜„์žฌ ๊ตฌ๋™ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ pid : $CURRENT_PID" + +if [ -z "$CURRENT_PID" ]; then + echo "> ํ˜„์žฌ ๊ตฌ๋™ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์—†์œผ๋ฏ€๋กœ ์ข…๋ฃŒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค." +else + echo "> kill -15 $CURRENT_PID" + kill -15 $CURRENT_PID + sleep 5 +fi + +echo "> ์ƒˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ" + +JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tail -n 1) + +echo "> JAR Name : $JAR_NAME" + +echo "> $JAR_NAME์— ์‹คํ–‰ ๊ถŒํ•œ ์ถ”๊ฐ€" + +chmod +x $JAR_NAME + +echo "> $JAR_NAME ์‹คํ–‰" + +nohup java -jar \ + -Dspring.profiles.active=prod \ + $JAR_NAME > $REPOSITORY/nohup.out 2>&1 &
Unknown
p4 : ์ž๋™ ๋ฐฐํฌ ์Šคํฌ๋ฆฝํŠธ ๊ตฐ์š” ๐Ÿ‘ ๊ฐ„๋‹จํ•œ ํŒ์ด์ง€๋งŒ.. ์—ฌ๊ธฐ์„œ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” `tail`, `grep`๋“ฑ๋“ฑ ์— ๋Œ€ํ•œ ๊ธฐ๋ณธ์ ์ธ ์ดํ•ด ์ •๋„๋Š” ์žˆ์œผ์‹œ๋ฉด ์ข‹์„๋“ฏ ํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,25 @@ +package com.requestrealpiano.songrequest.global.constant; + +public interface ValidationCondition { + + // Common + String NOT_EMPTY_MESSAGE = "ํ•„์ˆ˜ ์ž…๋ ฅ ์ •๋ณด ์ž…๋‹ˆ๋‹ค."; + + // Artist + String ARTIST_MESSAGE = "์•„ํ‹ฐ์ŠคํŠธ๋Š” 30์ž ๋ฏธ๋งŒ ์ž…๋‹ˆ๋‹ค."; + int ARTIST_MAX = 30; + int ARTIST_MIN = 1; + + // Title + String TITLE_MESSAGE = "์ œ๋ชฉ์€ 30์ž ๋ฏธ๋งŒ ์ž…๋‹ˆ๋‹ค."; + int TITLE_MAX = 30; + int TITLE_MIN = 1; + + // Image URL + String IMAGE_MESSAGE = "์œ ํšจํ•œ ์ด๋ฏธ์ง€ ์ •๋ณด๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค."; + int IMAGE_MAX = 100; + + // Song Story + String SONG_STORY_MESSAGE = "์‚ฌ์—ฐ์€ 500์ž ๋ฏธ๋งŒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."; + int SONG_STORY_MAX = 500; +}
Java
p3: ์ €๋„ enum์ด๋‚˜ ๋‹ค๋ฅธ class์œผ๋กœ ๊ด€๋ฆฌํ•˜์‹œ๋Š” ๊ฒŒ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐ๋˜๋„ค์š”!
@@ -0,0 +1,63 @@ +language: java +jdk: + - openjdk11 + +branches: + only: + - main + +cache: + directories: + - '$HOME/.m2/repository' + - '$HOME/.gradle' + +script: "./gradlew clean build" + +before_deploy: + - mkdir -p before-deploy + - cp scripts/*.sh before-deploy/ + - cp appspec.yml before-deploy/ + - cp build/libs/*.jar before-deploy + - cd before-deploy && zip -r before-deploy * + - cd ../ && mkdir -p deploy + - mv before-deploy/before-deploy.zip deploy/songrequest-backend.zip + +deploy: + - provider: s3 + access_key_id: $AWS_ACCESS_KEY + secret_access_key: $AWS_SECRET_KEY + + bucket: songrequest-backend-build + region: ap-northeast-2 + + skip_cleanup: true + acl: private + local_dir: deploy + + wait-until-deployed: true + + on: + all_branches: true + + - provider: codedeploy + access_key_id: $AWS_ACCESS_KEY + secret_access_key: $AWS_SECRET_KEY + + bucket: songrequest-backend-build + key: songrequest-backend.zip + + bundle_type: zip + application: songrequest-backend + + deployment_group: songrequest-backend-group + + region: ap-northeast-2 + wait-until-deployed: true + + on: + all_branches: true + +notifications: + email: + recipients: + - museopkim0214@gmail.com
Unknown
travis CI๋ฅผ ์‚ฌ์šฉํ•œ ๊ธฐ์ˆ ์ ์ธ ์ด์œ ๋Š” ์—†์—ˆ์Šต๋‹ˆ๋‹คใ…Žใ…Ž CI / CD๋ฅผ ๋‹ค์–‘ํ•œ ํˆด๋กœ ๊ฒฝํ—˜ ํ•ด๋ณด๊ณ  ์‹ถ์–ด์„œ ๋ฐฑ์—”๋“œ๋Š” travis CI, ํ”„๋ก ํŠธ๋Š” Github Actions๋กœ ๋ฐฐํฌ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑ ํ–ˆ์Šต๋‹ˆ๋‹ค. travis CI๋ฅผ ์จ๋ณด๊ณ  ๋А๋‚€ ๊ฒƒ์€... ๋””๋ฒ„๊น… ๊ณผ์ •์—์„œ ๋ถˆํŽธํ•จ์€ ์—†์—ˆ๊ณ , ๋‹ค๋งŒ ๋ง์”€ ํ•˜์‹  ๊ฒƒ์ฒ˜๋Ÿผ ์กฐ๊ธˆ ๋А๋ฆฐ ๊ฒƒ์ด ์•ฝ๊ฐ„ ๋ถˆํŽธ ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ”„๋ก ํŠธ์™€ ๋นŒ๋“œ ๊ณผ์ •์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ์ ˆ๋Œ€์ ์ธ ๋น„๊ต๋Š” ๋ถˆ๊ฐ€ ํ•˜์ง€๋งŒ ์ €๋„ Github Actions๊ฐ€ ์•ฝ๊ฐ„ ๋” ๋น ๋ฅธ ๋А๋‚Œ์ด์—ˆ๋„ค์š”.
@@ -0,0 +1,18 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ubuntu/app/songrequest/zip/ + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + ApplicationStart: + - location: deploy.sh + timeout: 60 + runas: ubuntu
Unknown
๋งŒ์•ฝ ๊ฐœ์ธ ํ”„๋กœ์ ํŠธ๋กœ blue / green ๋ฐฐํฌ๊นŒ์ง€ ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ๋งค์šฐ ํฐ ์„ฑ๊ณผ๊ฒ ๋„ค์š”ใ…Žใ…Ž ์จ๋‹ˆ ๋ธ”๋กœ๊ทธ์— ์ž˜ ๋ณด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜„ ์ข‹์€ ํŒ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.