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 ๋ฐฐํฌ๊น์ง ํ๊ฒ ๋๋ค๋ฉด ๋งค์ฐ ํฐ ์ฑ๊ณผ๊ฒ ๋ค์ใ
ใ
์จ๋ ๋ธ๋ก๊ทธ์ ์ ๋ณด๊ณ ์์ต๋๋ค. ๐ ์ข์ ํ ๊ฐ์ฌํฉ๋๋ค. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.