code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,412 @@
+* {
+ margin: 0;
+ padding: 0;
+}
+nav {
+ position: fixed;
+ width: 100%;
+ top: 0px;
+ left: 0px;
+ right: 0px;
+ background-color: #fff;
+ border-bottom: 1px solid #dbdbdb;
+ .navcontents {
+ width: 935px;
+ height: 54px;
+ background-color: #fff;
+ margin: 0 auto;
+ display: flex;
+ justify-content: space-between;
+ .navleft {
+ width: 360px;
+ .navleftcontents {
+ display: flex;
+ justify-content: flex-start;
+ .logo {
+ font-size: 23px;
+ margin-top: 12px;
+ }
+ .logoname {
+ border-left: 1px solid #bbbbbb;
+ font-family: "Lobster", cursive;
+ margin-left: 15px;
+ margin-top: 7px;
+ padding-left: 15px;
+ }
+ }
+ }
+ .navcenter {
+ width: 215px;
+ .navcentercontents {
+ position: relative;
+ .search {
+ width: 213px;
+ height: 26px;
+ background-color: #fafafa;
+ border: 1px solid #dbdbdb;
+ border-radius: 3px;
+ text-align: center;
+ position: absolute;
+ top: 14px;
+ }
+
+ .searchimg {
+ font-size: 10px;
+ color: #bbbbbb;
+ position: absolute;
+ top: 24px;
+ left: 83px;
+ }
+ }
+ }
+ .navright {
+ width: 360px;
+ .navrightcontents {
+ display: flex;
+ justify-content: flex-end;
+ margin-top: 14px;
+ .navexplore {
+ width: 25px;
+ height: 25px;
+ margin-right: 20px;
+ }
+
+ .navheart {
+ width: 25px;
+ height: 25px;
+ margin-right: 20px;
+ }
+
+ .navprofile {
+ width: 25px;
+ height: 25px;
+ }
+ }
+ }
+ }
+}
+
+
+
+.main {
+ border: 1px solid #fafafa;
+ background-color: #fafafa;
+ .feeds {
+ width: 935px;
+ margin: 0 auto;
+ margin-top: 84px;
+ .story {
+ width: 612px;
+ height: 116px;
+ background-color: #fff;
+ border: 1px solid #dbdbdb;
+ border-radius: 3px;
+ display: flex;
+ align-items: center;
+ .storyimgbox {
+ width: 612px;
+ height: 84px;
+ .storycontents {
+ display: flex;
+ justify-content: space-around;
+ .storylastbox {
+ display: flex;
+ justify-content: center;
+ .storylast {
+ width: 80px;
+ height: 122px;
+ .storyimg1 {
+ width: 56px;
+ height: 56px;
+ border: 1px solid #ececec;
+ border-radius: 50%;
+ padding: 3px;
+ object-fit: cover;
+ }
+
+ .storyp1 {
+ color: #8e8e8e;
+ font-size: 12px;
+ margin-left: 18px;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+
+article {
+ width: 612px;
+ height: auto;
+ background-color: #fff;
+ margin-top: 24px;
+ border: 1px solid #dbdbdb;
+ border-radius: 3px;
+ .articleheader {
+ width: 612px;
+ height: 59px;
+ border: 1px solid #dbdbdb;
+ .articleheadercontents {
+ width: 582px;
+ height: 27px;
+ margin: 15px auto 15px auto;
+ display: flex;
+ justify-content: space-between;
+ .headerimg {
+ width: 32px;
+ height: 32px;
+ border-radius: 50%;
+ object-fit: cover;
+ }
+
+ .headername {
+ width: 536px;
+ height: 26px;
+ .headerlast {
+ height: 26px;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ .hname {
+ font-size: 14px;
+ color: #262626;
+ font-weight: bold;
+ }
+ }
+ }
+ }
+ }
+ .articleimg {
+ width: 612px;
+ height: 612px;
+ object-fit: cover;
+ }
+
+ .article_button {
+ width: 582px;
+ height: 49px;
+ margin: 0 auto;
+ display: flex;
+ justify-content: space-between;
+ .article_button_left{
+ .left_button {
+ margin: 8px;
+ }
+ }
+ .article_button_right {
+ .right_button {
+ margin: 8px;
+ }
+ }
+ }
+
+ .number_of_likes {
+ width: 582px;
+ height: 18px;
+ margin: 0 auto;
+ padding-left: 5px;
+ .likes_friend {
+ font-size: 14px;
+ .like_font {
+ color: #262626;
+ font-weight: bold;
+ }
+ }
+ }
+ .friend_comment {
+ width: 582px;
+ height: auto;
+ margin: 0 auto;
+ margin-top: 8px;
+ padding-left: 5px;
+ .explanation {
+ font-size: 14px;
+ .like_font {
+ color: #262626;
+ font-weight: bold;
+ }
+ }
+ .commentBox {
+ list-style: none;
+ }
+ }
+ .time {
+ width: 598px;
+ padding-left: 18px;
+ .a_few_hours_ago {
+ font-size: 10px;
+ color: #8e8e8e;
+ }
+ }
+ .leave_comment_box {
+ border-top: 1px solid #dbdbdb;
+ margin-top: 10px;
+ .leave_comment {
+ width: 582px;
+ height: 55px;
+ margin: 0 auto;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ .smilebox {
+ padding: 8px 15px 8px 0px;
+ }
+ .inputcomment {
+ width: 510px;
+ border: 0;
+ }
+ .inputcomment:focus {
+ outline: none;
+ }
+ .posting_button {
+ background-color: #fff;
+ color: #0095f6;
+ border: 0;
+ }
+ .posting_button:focus{
+ outline: none;
+ }
+ }
+ }
+}
+
+
+
+
+.main-right {
+ width: 293px;
+ height: 612px;
+ position: fixed;
+ top: 85px;
+ left: 885px;
+ .my_profile {
+ width: 293px;
+ height: 56px;
+ margin: 18px 0px 10px 0px;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ .my_profileimg {
+ width: 56px;
+ height: 56px;
+ border-radius: 50%;
+ }
+
+ .my_info {
+ width: 202px;
+ height: 30px;
+ .mynickname {
+ width: 190px;
+ font-size: 14px;
+ font-weight: bold;
+ margin-left: 12px;
+ color: #262626;
+ }
+
+ .myname {
+ width: 190px;
+ font-size: 14px;
+ margin-left: 12px;
+ color: #8e8e8e;
+ }
+ }
+ .profile_transform {
+ font-weight: 600;
+ font-size: 12px;
+ border: 0;
+ color: #0095f6;
+ }
+ }
+ .recommendation {
+ width: 291px;
+ height: 325px;
+ .recommendation_header {
+ width: 293px;
+ height: 11px;
+ margin-top: 18px;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ .recommendation_left {
+ width: 248px;
+ font-size: 14px;
+ color: #8e8e8e;
+ font-weight: 600;
+ }
+
+ .recommendation_right {
+ width: 45px;
+ font-size: 12px;
+ color: #262626;
+ font-weight: 600;
+ }
+ }
+ .recommendation_info {
+ width: 289px;
+ height: 240px;
+ margin-top: 20px;
+ .recommendation_box {
+ width: 289px;
+ margin-bottom: 16px;
+ display: flex;
+ justify-content: space-between;
+ flex-wrap: wrap;
+ align-content: flex-start;
+ .friend_profile {
+ width: 32px;
+ height: 32px;
+ border-radius: 50%;
+ }
+
+ .friend_info {
+ width: 206px;
+ height: 28px;
+ .friend_nickname {
+ width: 205px;
+ color: #262626;
+ font-weight: bold;
+ font-size: 14px;
+ }
+
+ .other_friend {
+ width: 205px;
+ color: #8e8e8e;
+ font-weight: 400;
+ font-size: 12px;
+ }
+ }
+ .follow {
+ height: 15px;
+ font-weight: 600;
+ font-size: 12px;
+ margin-top: 10px;
+ border: 0;
+ color: #0095f6;
+ }
+ }
+ }
+ }
+ aside {
+ width: 293px;
+ height: 68px;
+ .westagram_contents_box {
+ width: 293px;
+ .westagram_contents {
+ color: #c7c7c7;
+ font-size: 11px;
+ font-weight: 400;
+ display: inline;
+ }
+ }
+ .westagram_facebook {
+ width: 205px;
+ color: #c7c7c7;
+ font-size: 11px;
+ font-weight: 400;
+ margin-top: 20px;
+ }
+ }
+}
\ No newline at end of file | Unknown | ```suggestion
```
๋น์นธ์ ์ค์ด๋ ๊ฒ๋ ์ข์ ์ต๊ด์ด๋ผ๊ณ ํ๋ค์! |
@@ -0,0 +1,85 @@
+* {
+ box-sizing: border-box;
+}
+
+.loginContainer {
+ border: 2px solid #e6e6e6;
+ width: 350px;
+ height: 380px;
+ margin: 0 auto;
+ .logoName {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ h1 {
+ font-family: "Lobster", cursive;
+ width: 175px;
+ height: 52px;
+ text-align: center;
+ padding-top: 6px;
+ }
+ }
+ .loginInfo {
+ height: 213px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding-top: 10px;
+ .loginId {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginPs {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginBt {
+ width: 268px;
+ height: 30px;
+ margin-top: 5px;
+ border-radius: 3px;
+ background-color: #2795f6;
+ color: #ffffff;
+ border-style: none;
+
+ &:focus {
+ outline: none;
+ }
+
+ &:disabled {
+ background-color: #b2dffc;
+ }
+ }
+ }
+ .forgetPassword{
+ display: flex;
+ justify-content: center;
+ margin-top: 20px;
+ a {
+ color: #043569; text-decoration: none;
+ }
+ }
+
+
+} | Unknown | ๋ ๋ํ
์ผํ css ์์ฑ๊ฐ .. ์ฌ์๋ ๋
ธ๊ณ ์ ๊ฒฝ์๋ฅผ..๐๐ป |
@@ -0,0 +1,50 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import './Login.scss';
+
+
+class LoginJaeyoung extends React.Component {
+ constructor () {
+ super();
+ this.state = {
+ id: '',
+ pw : '',
+ };
+ }
+
+ handleInput = (e) => {
+ const { name,value} = e.target;
+ this.setState({
+ [name]: value
+ })
+ }
+
+ goToMain = () => {
+ this.props.history.push('/main-jaeyoung')
+ }
+
+
+ render () {
+ const { handleInput } = this
+ const isBtnAble = this.state.id.includes('@') && this.state.pw.length >= 5;
+
+
+ return (
+ <div className="loginContainer">
+ <div className="logoName">
+ <h1>Instargram</h1>
+ </div>
+ <div className="loginInfo">
+ <input type="text" name="id" onChange={handleInput} className="loginId" placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ" />
+ <input type="password" name="pw" onChange={handleInput} className="loginPs" placeholder="๋น๋ฐ๋ฒํธ"/>
+ <button className="loginBt" onClick={this.goToMain} disabled={!isBtnAble}>๋ก๊ทธ์ธ</button>
+ </div>
+ <div className="forgetPassword">
+ <a href="https://www.naver.com/">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ )
+ }
+}
+
+export default withRouter( LoginJaeyoung );
\ No newline at end of file | JavaScript | target ๋ณด๋ค๋ ์ง๊ด์ ์ธ ํค๋ค์์ผ๋ก ๋ณ๊ฒฝํ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,85 @@
+* {
+ box-sizing: border-box;
+}
+
+.loginContainer {
+ border: 2px solid #e6e6e6;
+ width: 350px;
+ height: 380px;
+ margin: 0 auto;
+ .logoName {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ h1 {
+ font-family: "Lobster", cursive;
+ width: 175px;
+ height: 52px;
+ text-align: center;
+ padding-top: 6px;
+ }
+ }
+ .loginInfo {
+ height: 213px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding-top: 10px;
+ .loginId {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginPs {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginBt {
+ width: 268px;
+ height: 30px;
+ margin-top: 5px;
+ border-radius: 3px;
+ background-color: #2795f6;
+ color: #ffffff;
+ border-style: none;
+
+ &:focus {
+ outline: none;
+ }
+
+ &:disabled {
+ background-color: #b2dffc;
+ }
+ }
+ }
+ .forgetPassword{
+ display: flex;
+ justify-content: center;
+ margin-top: 20px;
+ a {
+ color: #043569; text-decoration: none;
+ }
+ }
+
+
+} | Unknown | - ํ๋์ ์์์ ์ฌ๋ฌ๊ฐ์ง ์์ฑ์ ๋ถ์ฌํ๋ ๊ฒฝ์ฐ ์ค์๋, ๊ด๋ จ๋์ ๋ฐ๋ผ์ ๋๋ฆ์ convention์ ์ง์ผ์ ์์ฑํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
- ์ผ๋ฐ์ ์ธ convention ์ ์๋์ ๊ฐ์ต๋๋ค. ์๋์ ๊ฐ์ด ์์ ์ ์ฉํด์ฃผ์ธ์.
[CSS property ์์]
- Layout Properties (position, float, clear, display)
- Box Model Properties (width, height, margin, padding)
- Visual Properties (color, background, border, box-shadow)
- Typography Properties (font-size, font-family, text-align, text-transform)
- Misc Properties (cursor, overflow, z-index) |
@@ -3,7 +3,10 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
- <title>React App</title>
+ <meta name="description" content="Web site created using create-react-app"/>
+ <link href="https://fonts.googleapis.com/css2?family=Lobster&display=swap" rel="stylesheet">
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
+ <title>Westagram</title>
</head>
<body>
<div id="root"></div> | Unknown | meta ํ๊ทธ์ ์ข
๋ฅ๊ฐ ๋ง๊ธฐ ๋๋ฌธ์ ์ด๋ค ๋ฐ์ดํฐ์ธ์ง ๋ช
์ํ๋ ์ฐจ์์์๋ ์๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -3,7 +3,10 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
- <title>React App</title>
+ <meta name="description" content="Web site created using create-react-app"/>
+ <link href="https://fonts.googleapis.com/css2?family=Lobster&display=swap" rel="stylesheet">
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
+ <title>Westagram</title>
</head>
<body>
<div id="root"></div> | Unknown | ๋ถํ์ํ ์ํฐ ์ฒ๋ฆฌ๋ ์ญ์ ํด์ฃผ์ธ์! |
@@ -0,0 +1,50 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import './Login.scss';
+
+
+class LoginJaeyoung extends React.Component {
+ constructor () {
+ super();
+ this.state = {
+ id: '',
+ pw : '',
+ };
+ }
+
+ handleInput = (e) => {
+ const { name,value} = e.target;
+ this.setState({
+ [name]: value
+ })
+ }
+
+ goToMain = () => {
+ this.props.history.push('/main-jaeyoung')
+ }
+
+
+ render () {
+ const { handleInput } = this
+ const isBtnAble = this.state.id.includes('@') && this.state.pw.length >= 5;
+
+
+ return (
+ <div className="loginContainer">
+ <div className="logoName">
+ <h1>Instargram</h1>
+ </div>
+ <div className="loginInfo">
+ <input type="text" name="id" onChange={handleInput} className="loginId" placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ" />
+ <input type="password" name="pw" onChange={handleInput} className="loginPs" placeholder="๋น๋ฐ๋ฒํธ"/>
+ <button className="loginBt" onClick={this.goToMain} disabled={!isBtnAble}>๋ก๊ทธ์ธ</button>
+ </div>
+ <div className="forgetPassword">
+ <a href="https://www.naver.com/">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ )
+ }
+}
+
+export default withRouter( LoginJaeyoung );
\ No newline at end of file | JavaScript | Import ์์ ์์ ํด์ฃผ์ธ์! ์ผ๋ฐ์ ์ธ convention์ ๋ฐ๋ฅด๋ ์ด์ ๋ ์์ง๋ง ์์๋ง ์ ์ง์ผ์ฃผ์
๋ ๊ฐ๋
์ฑ์ด ์ข์์ง๋๋ค. ์๋ ์์ ์ฐธ๊ณ ํด์ฃผ์ธ์.
- React โ Library(Package) โ Component โ ๋ณ์ / ์ด๋ฏธ์ง โ css ํ์ผ(scss ํ์ผ) |
@@ -0,0 +1,50 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import './Login.scss';
+
+
+class LoginJaeyoung extends React.Component {
+ constructor () {
+ super();
+ this.state = {
+ id: '',
+ pw : '',
+ };
+ }
+
+ handleInput = (e) => {
+ const { name,value} = e.target;
+ this.setState({
+ [name]: value
+ })
+ }
+
+ goToMain = () => {
+ this.props.history.push('/main-jaeyoung')
+ }
+
+
+ render () {
+ const { handleInput } = this
+ const isBtnAble = this.state.id.includes('@') && this.state.pw.length >= 5;
+
+
+ return (
+ <div className="loginContainer">
+ <div className="logoName">
+ <h1>Instargram</h1>
+ </div>
+ <div className="loginInfo">
+ <input type="text" name="id" onChange={handleInput} className="loginId" placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ" />
+ <input type="password" name="pw" onChange={handleInput} className="loginPs" placeholder="๋น๋ฐ๋ฒํธ"/>
+ <button className="loginBt" onClick={this.goToMain} disabled={!isBtnAble}>๋ก๊ทธ์ธ</button>
+ </div>
+ <div className="forgetPassword">
+ <a href="https://www.naver.com/">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ )
+ }
+}
+
+export default withRouter( LoginJaeyoung );
\ No newline at end of file | JavaScript | ```js
// render ์๋์์
const isBtnAble = idValue.includes('@') && psValue.length > 5;
<button disabled={!isBtnAble} />
```
- ์ด๋ฐ์์ผ๋ก ๋ณ์๋ฅผ ํ์ฉํ๋ฉด ์ข ๋ ๊น๋ํด์ง ์ ์๊ฒ ๋ค์!
- Boolean ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์๋ ๊ตณ์ด true, false ํ์ํด์ค ํ์ ์์ต๋๋ค! (์ผํญ ์ฐ์ฐ์ ์กฐ๊ฑด์ ํด๋น๋๋ ๋ถ๋ถ์ด ์ด๋ฏธ t/f ๊ฐ์ ๊ฐ๊ธฐ ๋๋ฌธ์) |
@@ -0,0 +1,85 @@
+* {
+ box-sizing: border-box;
+}
+
+.loginContainer {
+ border: 2px solid #e6e6e6;
+ width: 350px;
+ height: 380px;
+ margin: 0 auto;
+ .logoName {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ h1 {
+ font-family: "Lobster", cursive;
+ width: 175px;
+ height: 52px;
+ text-align: center;
+ padding-top: 6px;
+ }
+ }
+ .loginInfo {
+ height: 213px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding-top: 10px;
+ .loginId {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginPs {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginBt {
+ width: 268px;
+ height: 30px;
+ margin-top: 5px;
+ border-radius: 3px;
+ background-color: #2795f6;
+ color: #ffffff;
+ border-style: none;
+
+ &:focus {
+ outline: none;
+ }
+
+ &:disabled {
+ background-color: #b2dffc;
+ }
+ }
+ }
+ .forgetPassword{
+ display: flex;
+ justify-content: center;
+ margin-top: 20px;
+ a {
+ color: #043569; text-decoration: none;
+ }
+ }
+
+
+} | Unknown | ๊ฐ๋
์ฑ์ ์ํด selector ์ฌ์ด์ ํ ์ค ๋์์ฃผ์๋ฉด ์ข์ต๋๋ค. |
@@ -0,0 +1,85 @@
+* {
+ box-sizing: border-box;
+}
+
+.loginContainer {
+ border: 2px solid #e6e6e6;
+ width: 350px;
+ height: 380px;
+ margin: 0 auto;
+ .logoName {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ h1 {
+ font-family: "Lobster", cursive;
+ width: 175px;
+ height: 52px;
+ text-align: center;
+ padding-top: 6px;
+ }
+ }
+ .loginInfo {
+ height: 213px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding-top: 10px;
+ .loginId {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginPs {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginBt {
+ width: 268px;
+ height: 30px;
+ margin-top: 5px;
+ border-radius: 3px;
+ background-color: #2795f6;
+ color: #ffffff;
+ border-style: none;
+
+ &:focus {
+ outline: none;
+ }
+
+ &:disabled {
+ background-color: #b2dffc;
+ }
+ }
+ }
+ .forgetPassword{
+ display: flex;
+ justify-content: center;
+ margin-top: 20px;
+ a {
+ color: #043569; text-decoration: none;
+ }
+ }
+
+
+} | Unknown | ๊ณตํต๋๋ ์์ฑ์ด ๋ง์ด ๋ณด์ด๋ค์! ์ค์ฌ๋ด
์๋ค ๐ ํ๋์ ์์์ ๋ณต์์ className์ ๋ถ์ฌํ ์ ์์ต๋๋ค. |
@@ -0,0 +1,190 @@
+import React from 'react';
+import FeedComponent from './FeedComponent/FeedComponent';
+import './Main.scss';
+import explore from '../../../images/jaeyoungLee/Main/explore.jpg';
+import heart from '../../../images/jaeyoungLee/Main/heart.jpg';
+import profile from '../../../images/jaeyoungLee/Main/profile.jpg';
+import heungminSon from '../../../images/jaeyoungLee/Main/์ํฅ๋ฏผ.jpg';
+class MainJaeyoung extends React.Component {
+ constructor () {
+ super();
+ this.state = {
+ commentFeed : [],
+ }
+ }
+
+ componentDidMount() {
+ fetch('http://localhost:3000/data/feedData.json', {
+ method: 'GET'
+ })
+ .then(res => res.json())
+ .then(data => {
+ this.setState({
+ commentFeed: data,
+ });
+ });
+ }
+
+
+
+ render(){
+ const { commentFeed } = this.state;
+ return(
+ <>
+ <nav>
+ <div className="navcontents">
+ <div className="navleft">
+ <div className="navleftcontents">
+ <span className="logo"><i className="fab fa-instagram"></i></span>
+ <h1 className="logoname">westagram</h1>
+ </div>
+ </div>
+ <div className="navcenter">
+ <div className="navcentercontents">
+ <input className="search" type="text" placeholder="๊ฒ์"/>
+ <span className="searchimg"><i className="fas fa-search"></i></span>
+ </div>
+ </div>
+ <div className="navright">
+ <div className="navrightcontents">
+ <img className="navexplore" src={explore} alt="ํํ"/>
+ <img className="navheart" src={heart} alt="ํํธ"/>
+ <img className="navprofile" src={profile} alt="ํ๋กํ"/>
+ </div>
+ </div>
+ </div>
+ </nav>
+ <div className="main">
+ <div className="feeds">
+ <div className="story">
+ <div className="storyimgbox">
+ <div className="storycontents">
+ <div className="storyprofile">
+ <div className="storylastbox">
+ <div className="storylast">
+ <img className="storyimg1" src={heungminSon} alt="ํ๋กํ1"/>
+ <p className="storyp1">์ํฅ๋ฏผ</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://instagram.famm6-1.fna.fbcdn.net/v/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=instagram.famm6-1.fna.fbcdn.net&_nc_ohc=mhDR9_0DpXIAX_KX0iq&ccb=7-4&oh=dcbb150241d6b1336dd54a4a20417b2a&oe=608B680F&_nc_sid=712cc3&ig_cache_key=YW5vbnltb3VzX3Byb2ZpbGVfcGlj.2-ccb7-4" alt="ํ๋กํ1"/>
+ <p className="storyp1">2wo0</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/35999304_258159611658935_7092278198804676608_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=et4sZhNbgpAAX-qKBH9&ccb=7-4&oh=0b254f6fb3e4182513c3e20ed1a326d0&oe=608BC5C1&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">geg</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/150675895_144233967522798_7515094658452540248_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=xslO4Za0644AX9cwObZ&ccb=7-4&oh=0f5cb82fd80b51b47d74e160e228aa1c&oe=608D7B5E&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">h._.j</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/135771971_1881013862054625_6713353513169410837_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=SxJIiqRh4rcAX8RSLYk&ccb=7-4&oh=6dec08c37a69cb2c2a14f21bc36b5eef&oe=608C0912&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">idon</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/155951500_335125831259326_3729086392261698560_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=3nnTQdlVU98AX_4fVMv&ccb=7-4&oh=4a596fc0e33f2ece37634ae50d38cdde&oe=608C5901&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">dfewg</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/37828240_293117218102022_6759937585105076224_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=jzs6QvrGtHAAX_qFR80&ccb=7-4&oh=f4984cbce61bc445f02622a5468278b3&oe=608B09A1&_nc_sid=57d425" alt="ํ๋กํ1"/>
+ <p className="storyp1">33gg</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ {commentFeed.map((feed,id) =>{
+ return (
+ <FeedComponent key={feed.id} profileimg={feed.profileimg} userName={feed.userName} feedimg={feed.feedimg} feedcontent={feed.feedcontent} />
+ );
+ })}
+
+ </div>
+ <div className="main-right">
+ <div className="my_profile">
+ <img className="my_profileimg" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/141997127_1523884024669097_6148385093252095280_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=ldPmBqcpW3kAX9esSCC&ccb=7-4&oh=6503a99b1b0096ad362012fef7e72aed&oe=6085537E&_nc_sid=7b02f1" alt="ํ๋กํ"/>
+ <div className="my_info">
+ <p className="mynickname">2wo0_0</p>
+ <p className="myname">์ด์ฌ์</p>
+ </div>
+ <button className="profile_transform" disabled>์ ํ</button>
+ </div>
+ <div className="recommendation">
+ <div className="recommendation_header">
+ <p className="recommendation_left">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p className="recommendation_right">๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="recommendation_info">
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/156650140_116853317083347_8770042214751161261_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=-evbCZABANYAX_WcDzP&edm=AEF8tYYAAAAA&ccb=7-4&oh=5eb6e52a64b2ad8c98bff45dab473831&oe=60880D5B&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">ryu_d_g</p>
+ <p className="other_friend">1996yunsi๋ ์ธ 13๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/159992110_105322351555148_1839915921172216453_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=xfLIvYCwwiIAX8AJI08&ccb=7-4&oh=7bdaf0e022e88f0dd5079c1995892031&oe=608D9B9E&_nc_sid=57d425" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">2s2_f</p>
+ <p className="other_friend">_sihyeon___๋ ์ธ 49๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/160716680_272942871038831_8108440433038115559_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=VmeF5WmeLg4AX-jiUAL&ccb=7-4&oh=cf29d0253e8afb755a9d26ad13a6deda&oe=608D4A0C&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">rdfe_g</p>
+ <p className="other_friend">111_fkdn๋ ์ธ 5๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/164274433_776408706413539_3215024154205561736_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=gCCfowKp9OMAX9_NBIP&ccb=7-4&oh=afbada353869184275b4d3be70f38605&oe=608BE909&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">cat_2d_g</p>
+ <p className="other_friend">cjdtkseh๋ ์ธ 15๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src=" https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/164520013_834814623778500_398528442563386719_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=iLm66uEJKQ4AX88GkVl&ccb=7-4&oh=4fe271ebb6f627b328cb3d24bb811776&oe=608E6098&_nc_sid=86f79a" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">tksdkdnENr</p>
+ <p className="other_friend">cjfcjfgme1๋ ์ธ 32๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ </div>
+ <aside>
+ <ul className="westagram_contents_box">
+ {CONTENTS.map((el,id) =>
+ <li key={id} className="westagram_contents">{el.content}</li>
+ )}
+
+ </ul>
+ <p className="westagram_facebook">ยฉ 2021 INSTAGRAM FROM FACEBOOK</p>
+ </aside>
+ </div>
+ </div>
+ </>
+ )
+ }
+}
+export default MainJaeyoung ;
+
+const CONTENTS = [
+ {id: 1, content: "์๊ฐ"},
+ {id: 2, content: "๋์๋ง"},
+ {id: 3, content: "ํ๋ณด ์ผํฐ"},
+ {id: 4, content: "API"},
+ {id: 5, content: "์ฑ์ฉ์ ๋ณด"},
+ {id: 6, content: "๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ"},
+ {id: 7, content: "์ฝ๊ด"},
+ {id: 8, content: "์์น"},
+ {id: 9, content: "์ธ๊ธฐ ๊ณ์ "},
+ {id: 10, content: "ํด์ํ๊ทธ"},
+ {id: 11, content: "์ธ์ด"},
+]
\ No newline at end of file | JavaScript | addComment์ ๊ฐ์ด ๊ธฐ๋ฅ์ ์๋ฏธ๊ฐ ๋ค์ด๋๋ ์ด๋ฆ์ผ๋ก ํจ์๋ช
์ ์์ฑํด์ฃผ์ธ์! |
@@ -0,0 +1,190 @@
+import React from 'react';
+import FeedComponent from './FeedComponent/FeedComponent';
+import './Main.scss';
+import explore from '../../../images/jaeyoungLee/Main/explore.jpg';
+import heart from '../../../images/jaeyoungLee/Main/heart.jpg';
+import profile from '../../../images/jaeyoungLee/Main/profile.jpg';
+import heungminSon from '../../../images/jaeyoungLee/Main/์ํฅ๋ฏผ.jpg';
+class MainJaeyoung extends React.Component {
+ constructor () {
+ super();
+ this.state = {
+ commentFeed : [],
+ }
+ }
+
+ componentDidMount() {
+ fetch('http://localhost:3000/data/feedData.json', {
+ method: 'GET'
+ })
+ .then(res => res.json())
+ .then(data => {
+ this.setState({
+ commentFeed: data,
+ });
+ });
+ }
+
+
+
+ render(){
+ const { commentFeed } = this.state;
+ return(
+ <>
+ <nav>
+ <div className="navcontents">
+ <div className="navleft">
+ <div className="navleftcontents">
+ <span className="logo"><i className="fab fa-instagram"></i></span>
+ <h1 className="logoname">westagram</h1>
+ </div>
+ </div>
+ <div className="navcenter">
+ <div className="navcentercontents">
+ <input className="search" type="text" placeholder="๊ฒ์"/>
+ <span className="searchimg"><i className="fas fa-search"></i></span>
+ </div>
+ </div>
+ <div className="navright">
+ <div className="navrightcontents">
+ <img className="navexplore" src={explore} alt="ํํ"/>
+ <img className="navheart" src={heart} alt="ํํธ"/>
+ <img className="navprofile" src={profile} alt="ํ๋กํ"/>
+ </div>
+ </div>
+ </div>
+ </nav>
+ <div className="main">
+ <div className="feeds">
+ <div className="story">
+ <div className="storyimgbox">
+ <div className="storycontents">
+ <div className="storyprofile">
+ <div className="storylastbox">
+ <div className="storylast">
+ <img className="storyimg1" src={heungminSon} alt="ํ๋กํ1"/>
+ <p className="storyp1">์ํฅ๋ฏผ</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://instagram.famm6-1.fna.fbcdn.net/v/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=instagram.famm6-1.fna.fbcdn.net&_nc_ohc=mhDR9_0DpXIAX_KX0iq&ccb=7-4&oh=dcbb150241d6b1336dd54a4a20417b2a&oe=608B680F&_nc_sid=712cc3&ig_cache_key=YW5vbnltb3VzX3Byb2ZpbGVfcGlj.2-ccb7-4" alt="ํ๋กํ1"/>
+ <p className="storyp1">2wo0</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/35999304_258159611658935_7092278198804676608_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=et4sZhNbgpAAX-qKBH9&ccb=7-4&oh=0b254f6fb3e4182513c3e20ed1a326d0&oe=608BC5C1&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">geg</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/150675895_144233967522798_7515094658452540248_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=xslO4Za0644AX9cwObZ&ccb=7-4&oh=0f5cb82fd80b51b47d74e160e228aa1c&oe=608D7B5E&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">h._.j</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/135771971_1881013862054625_6713353513169410837_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=SxJIiqRh4rcAX8RSLYk&ccb=7-4&oh=6dec08c37a69cb2c2a14f21bc36b5eef&oe=608C0912&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">idon</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/155951500_335125831259326_3729086392261698560_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=3nnTQdlVU98AX_4fVMv&ccb=7-4&oh=4a596fc0e33f2ece37634ae50d38cdde&oe=608C5901&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">dfewg</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/37828240_293117218102022_6759937585105076224_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=jzs6QvrGtHAAX_qFR80&ccb=7-4&oh=f4984cbce61bc445f02622a5468278b3&oe=608B09A1&_nc_sid=57d425" alt="ํ๋กํ1"/>
+ <p className="storyp1">33gg</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ {commentFeed.map((feed,id) =>{
+ return (
+ <FeedComponent key={feed.id} profileimg={feed.profileimg} userName={feed.userName} feedimg={feed.feedimg} feedcontent={feed.feedcontent} />
+ );
+ })}
+
+ </div>
+ <div className="main-right">
+ <div className="my_profile">
+ <img className="my_profileimg" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/141997127_1523884024669097_6148385093252095280_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=ldPmBqcpW3kAX9esSCC&ccb=7-4&oh=6503a99b1b0096ad362012fef7e72aed&oe=6085537E&_nc_sid=7b02f1" alt="ํ๋กํ"/>
+ <div className="my_info">
+ <p className="mynickname">2wo0_0</p>
+ <p className="myname">์ด์ฌ์</p>
+ </div>
+ <button className="profile_transform" disabled>์ ํ</button>
+ </div>
+ <div className="recommendation">
+ <div className="recommendation_header">
+ <p className="recommendation_left">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p className="recommendation_right">๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="recommendation_info">
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/156650140_116853317083347_8770042214751161261_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=-evbCZABANYAX_WcDzP&edm=AEF8tYYAAAAA&ccb=7-4&oh=5eb6e52a64b2ad8c98bff45dab473831&oe=60880D5B&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">ryu_d_g</p>
+ <p className="other_friend">1996yunsi๋ ์ธ 13๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/159992110_105322351555148_1839915921172216453_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=xfLIvYCwwiIAX8AJI08&ccb=7-4&oh=7bdaf0e022e88f0dd5079c1995892031&oe=608D9B9E&_nc_sid=57d425" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">2s2_f</p>
+ <p className="other_friend">_sihyeon___๋ ์ธ 49๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/160716680_272942871038831_8108440433038115559_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=VmeF5WmeLg4AX-jiUAL&ccb=7-4&oh=cf29d0253e8afb755a9d26ad13a6deda&oe=608D4A0C&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">rdfe_g</p>
+ <p className="other_friend">111_fkdn๋ ์ธ 5๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/164274433_776408706413539_3215024154205561736_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=gCCfowKp9OMAX9_NBIP&ccb=7-4&oh=afbada353869184275b4d3be70f38605&oe=608BE909&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">cat_2d_g</p>
+ <p className="other_friend">cjdtkseh๋ ์ธ 15๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src=" https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/164520013_834814623778500_398528442563386719_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=iLm66uEJKQ4AX88GkVl&ccb=7-4&oh=4fe271ebb6f627b328cb3d24bb811776&oe=608E6098&_nc_sid=86f79a" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">tksdkdnENr</p>
+ <p className="other_friend">cjfcjfgme1๋ ์ธ 32๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ </div>
+ <aside>
+ <ul className="westagram_contents_box">
+ {CONTENTS.map((el,id) =>
+ <li key={id} className="westagram_contents">{el.content}</li>
+ )}
+
+ </ul>
+ <p className="westagram_facebook">ยฉ 2021 INSTAGRAM FROM FACEBOOK</p>
+ </aside>
+ </div>
+ </div>
+ </>
+ )
+ }
+}
+export default MainJaeyoung ;
+
+const CONTENTS = [
+ {id: 1, content: "์๊ฐ"},
+ {id: 2, content: "๋์๋ง"},
+ {id: 3, content: "ํ๋ณด ์ผํฐ"},
+ {id: 4, content: "API"},
+ {id: 5, content: "์ฑ์ฉ์ ๋ณด"},
+ {id: 6, content: "๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ"},
+ {id: 7, content: "์ฝ๊ด"},
+ {id: 8, content: "์์น"},
+ {id: 9, content: "์ธ๊ธฐ ๊ณ์ "},
+ {id: 10, content: "ํด์ํ๊ทธ"},
+ {id: 11, content: "์ธ์ด"},
+]
\ No newline at end of file | JavaScript | - ํด๋น ํ์ผ์ ๋ฐ์ดํฐ๋ฅผ ๋ฐฐ์ด๋ก ๋ง๋ค์ด์ map ํจ์ ์ ์ฉํ๋ฉด ์ข์ ๋ถ๋ถ์ด ๋ง์ด ๋ณด์ด๋ค์! ์ฐ์ ์ด ๊ฒ ๋ถํฐ ์์ ํด๋ณด์๊ธฐ ๋ฐ๋๋๋ค.
- https://www.notion.so/wecode/React-Refactoring-Check-List-aea297cf88ed4601b769e4b2c2cfd4e1#ef5cf308f13f48458f69175875c239e9 |
@@ -0,0 +1,17 @@
+import React from 'react';
+import './CommentComponent.scss';
+
+class CommentComponent extends React.Component {
+ render() {
+ const { key, name, comment} = this.props
+ return (
+ <li className="CommentComponent">
+ {key}
+ <strong>{name}</strong>
+ {comment}
+ </li>
+ )
+ }
+}
+
+export default CommentComponent;
\ No newline at end of file | JavaScript | commentList๋ ul ํ๊ทธ๋ฅผ ์๋ฏธํ๋ ๊ฒ ๊ฐ์์ props ์ด๋ฆ์ comment๋ก ํ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,412 @@
+* {
+ margin: 0;
+ padding: 0;
+}
+nav {
+ position: fixed;
+ width: 100%;
+ top: 0px;
+ left: 0px;
+ right: 0px;
+ background-color: #fff;
+ border-bottom: 1px solid #dbdbdb;
+ .navcontents {
+ width: 935px;
+ height: 54px;
+ background-color: #fff;
+ margin: 0 auto;
+ display: flex;
+ justify-content: space-between;
+ .navleft {
+ width: 360px;
+ .navleftcontents {
+ display: flex;
+ justify-content: flex-start;
+ .logo {
+ font-size: 23px;
+ margin-top: 12px;
+ }
+ .logoname {
+ border-left: 1px solid #bbbbbb;
+ font-family: "Lobster", cursive;
+ margin-left: 15px;
+ margin-top: 7px;
+ padding-left: 15px;
+ }
+ }
+ }
+ .navcenter {
+ width: 215px;
+ .navcentercontents {
+ position: relative;
+ .search {
+ width: 213px;
+ height: 26px;
+ background-color: #fafafa;
+ border: 1px solid #dbdbdb;
+ border-radius: 3px;
+ text-align: center;
+ position: absolute;
+ top: 14px;
+ }
+
+ .searchimg {
+ font-size: 10px;
+ color: #bbbbbb;
+ position: absolute;
+ top: 24px;
+ left: 83px;
+ }
+ }
+ }
+ .navright {
+ width: 360px;
+ .navrightcontents {
+ display: flex;
+ justify-content: flex-end;
+ margin-top: 14px;
+ .navexplore {
+ width: 25px;
+ height: 25px;
+ margin-right: 20px;
+ }
+
+ .navheart {
+ width: 25px;
+ height: 25px;
+ margin-right: 20px;
+ }
+
+ .navprofile {
+ width: 25px;
+ height: 25px;
+ }
+ }
+ }
+ }
+}
+
+
+
+.main {
+ border: 1px solid #fafafa;
+ background-color: #fafafa;
+ .feeds {
+ width: 935px;
+ margin: 0 auto;
+ margin-top: 84px;
+ .story {
+ width: 612px;
+ height: 116px;
+ background-color: #fff;
+ border: 1px solid #dbdbdb;
+ border-radius: 3px;
+ display: flex;
+ align-items: center;
+ .storyimgbox {
+ width: 612px;
+ height: 84px;
+ .storycontents {
+ display: flex;
+ justify-content: space-around;
+ .storylastbox {
+ display: flex;
+ justify-content: center;
+ .storylast {
+ width: 80px;
+ height: 122px;
+ .storyimg1 {
+ width: 56px;
+ height: 56px;
+ border: 1px solid #ececec;
+ border-radius: 50%;
+ padding: 3px;
+ object-fit: cover;
+ }
+
+ .storyp1 {
+ color: #8e8e8e;
+ font-size: 12px;
+ margin-left: 18px;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+
+article {
+ width: 612px;
+ height: auto;
+ background-color: #fff;
+ margin-top: 24px;
+ border: 1px solid #dbdbdb;
+ border-radius: 3px;
+ .articleheader {
+ width: 612px;
+ height: 59px;
+ border: 1px solid #dbdbdb;
+ .articleheadercontents {
+ width: 582px;
+ height: 27px;
+ margin: 15px auto 15px auto;
+ display: flex;
+ justify-content: space-between;
+ .headerimg {
+ width: 32px;
+ height: 32px;
+ border-radius: 50%;
+ object-fit: cover;
+ }
+
+ .headername {
+ width: 536px;
+ height: 26px;
+ .headerlast {
+ height: 26px;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ .hname {
+ font-size: 14px;
+ color: #262626;
+ font-weight: bold;
+ }
+ }
+ }
+ }
+ }
+ .articleimg {
+ width: 612px;
+ height: 612px;
+ object-fit: cover;
+ }
+
+ .article_button {
+ width: 582px;
+ height: 49px;
+ margin: 0 auto;
+ display: flex;
+ justify-content: space-between;
+ .article_button_left{
+ .left_button {
+ margin: 8px;
+ }
+ }
+ .article_button_right {
+ .right_button {
+ margin: 8px;
+ }
+ }
+ }
+
+ .number_of_likes {
+ width: 582px;
+ height: 18px;
+ margin: 0 auto;
+ padding-left: 5px;
+ .likes_friend {
+ font-size: 14px;
+ .like_font {
+ color: #262626;
+ font-weight: bold;
+ }
+ }
+ }
+ .friend_comment {
+ width: 582px;
+ height: auto;
+ margin: 0 auto;
+ margin-top: 8px;
+ padding-left: 5px;
+ .explanation {
+ font-size: 14px;
+ .like_font {
+ color: #262626;
+ font-weight: bold;
+ }
+ }
+ .commentBox {
+ list-style: none;
+ }
+ }
+ .time {
+ width: 598px;
+ padding-left: 18px;
+ .a_few_hours_ago {
+ font-size: 10px;
+ color: #8e8e8e;
+ }
+ }
+ .leave_comment_box {
+ border-top: 1px solid #dbdbdb;
+ margin-top: 10px;
+ .leave_comment {
+ width: 582px;
+ height: 55px;
+ margin: 0 auto;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ .smilebox {
+ padding: 8px 15px 8px 0px;
+ }
+ .inputcomment {
+ width: 510px;
+ border: 0;
+ }
+ .inputcomment:focus {
+ outline: none;
+ }
+ .posting_button {
+ background-color: #fff;
+ color: #0095f6;
+ border: 0;
+ }
+ .posting_button:focus{
+ outline: none;
+ }
+ }
+ }
+}
+
+
+
+
+.main-right {
+ width: 293px;
+ height: 612px;
+ position: fixed;
+ top: 85px;
+ left: 885px;
+ .my_profile {
+ width: 293px;
+ height: 56px;
+ margin: 18px 0px 10px 0px;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ .my_profileimg {
+ width: 56px;
+ height: 56px;
+ border-radius: 50%;
+ }
+
+ .my_info {
+ width: 202px;
+ height: 30px;
+ .mynickname {
+ width: 190px;
+ font-size: 14px;
+ font-weight: bold;
+ margin-left: 12px;
+ color: #262626;
+ }
+
+ .myname {
+ width: 190px;
+ font-size: 14px;
+ margin-left: 12px;
+ color: #8e8e8e;
+ }
+ }
+ .profile_transform {
+ font-weight: 600;
+ font-size: 12px;
+ border: 0;
+ color: #0095f6;
+ }
+ }
+ .recommendation {
+ width: 291px;
+ height: 325px;
+ .recommendation_header {
+ width: 293px;
+ height: 11px;
+ margin-top: 18px;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ .recommendation_left {
+ width: 248px;
+ font-size: 14px;
+ color: #8e8e8e;
+ font-weight: 600;
+ }
+
+ .recommendation_right {
+ width: 45px;
+ font-size: 12px;
+ color: #262626;
+ font-weight: 600;
+ }
+ }
+ .recommendation_info {
+ width: 289px;
+ height: 240px;
+ margin-top: 20px;
+ .recommendation_box {
+ width: 289px;
+ margin-bottom: 16px;
+ display: flex;
+ justify-content: space-between;
+ flex-wrap: wrap;
+ align-content: flex-start;
+ .friend_profile {
+ width: 32px;
+ height: 32px;
+ border-radius: 50%;
+ }
+
+ .friend_info {
+ width: 206px;
+ height: 28px;
+ .friend_nickname {
+ width: 205px;
+ color: #262626;
+ font-weight: bold;
+ font-size: 14px;
+ }
+
+ .other_friend {
+ width: 205px;
+ color: #8e8e8e;
+ font-weight: 400;
+ font-size: 12px;
+ }
+ }
+ .follow {
+ height: 15px;
+ font-weight: 600;
+ font-size: 12px;
+ margin-top: 10px;
+ border: 0;
+ color: #0095f6;
+ }
+ }
+ }
+ }
+ aside {
+ width: 293px;
+ height: 68px;
+ .westagram_contents_box {
+ width: 293px;
+ .westagram_contents {
+ color: #c7c7c7;
+ font-size: 11px;
+ font-weight: 400;
+ display: inline;
+ }
+ }
+ .westagram_facebook {
+ width: 205px;
+ color: #c7c7c7;
+ font-size: 11px;
+ font-weight: 400;
+ margin-top: 20px;
+ }
+ }
+}
\ No newline at end of file | Unknown | ์ ์ฒด์ ์ผ๋ก camelCase, snake_case ํผ์ฉํด์ ์ฌ์ฉํ๊ณ ๊ณ์ ๋ฐ ๋ค์์๋ ํ์๋ค๊ณผ ์ ํ ๊ท์น๋๋ก ์ ์ฉํด์ฃผ์ธ์! ์ต์ํ ๋ด๊ฐ ์์ฑํ ์ฝ๋ ์์์๋ ์ผ๊ด์ฑ์ด ์์ด์ผ ํฉ๋๋ค. |
@@ -0,0 +1,85 @@
+* {
+ box-sizing: border-box;
+}
+
+.loginContainer {
+ border: 2px solid #e6e6e6;
+ width: 350px;
+ height: 380px;
+ margin: 0 auto;
+ .logoName {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ h1 {
+ font-family: "Lobster", cursive;
+ width: 175px;
+ height: 52px;
+ text-align: center;
+ padding-top: 6px;
+ }
+ }
+ .loginInfo {
+ height: 213px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding-top: 10px;
+ .loginId {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginPs {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginBt {
+ width: 268px;
+ height: 30px;
+ margin-top: 5px;
+ border-radius: 3px;
+ background-color: #2795f6;
+ color: #ffffff;
+ border-style: none;
+
+ &:focus {
+ outline: none;
+ }
+
+ &:disabled {
+ background-color: #b2dffc;
+ }
+ }
+ }
+ .forgetPassword{
+ display: flex;
+ justify-content: center;
+ margin-top: 20px;
+ a {
+ color: #043569; text-decoration: none;
+ }
+ }
+
+
+} | Unknown | ๋ต! ์๊ฒ ์ต๋๋ค! |
@@ -3,7 +3,10 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
- <title>React App</title>
+ <meta name="description" content="Web site created using create-react-app"/>
+ <link href="https://fonts.googleapis.com/css2?family=Lobster&display=swap" rel="stylesheet">
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
+ <title>Westagram</title>
</head>
<body>
<div id="root"></div> | Unknown | ์ญ์ ํ์ต๋๋ค! ๊ฐ์ฌํฉ๋๋ค |
@@ -0,0 +1,50 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import './Login.scss';
+
+
+class LoginJaeyoung extends React.Component {
+ constructor () {
+ super();
+ this.state = {
+ id: '',
+ pw : '',
+ };
+ }
+
+ handleInput = (e) => {
+ const { name,value} = e.target;
+ this.setState({
+ [name]: value
+ })
+ }
+
+ goToMain = () => {
+ this.props.history.push('/main-jaeyoung')
+ }
+
+
+ render () {
+ const { handleInput } = this
+ const isBtnAble = this.state.id.includes('@') && this.state.pw.length >= 5;
+
+
+ return (
+ <div className="loginContainer">
+ <div className="logoName">
+ <h1>Instargram</h1>
+ </div>
+ <div className="loginInfo">
+ <input type="text" name="id" onChange={handleInput} className="loginId" placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ" />
+ <input type="password" name="pw" onChange={handleInput} className="loginPs" placeholder="๋น๋ฐ๋ฒํธ"/>
+ <button className="loginBt" onClick={this.goToMain} disabled={!isBtnAble}>๋ก๊ทธ์ธ</button>
+ </div>
+ <div className="forgetPassword">
+ <a href="https://www.naver.com/">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ )
+ }
+}
+
+export default withRouter( LoginJaeyoung );
\ No newline at end of file | JavaScript | ์์ ํ์ต๋๋ค! |
@@ -0,0 +1,50 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import './Login.scss';
+
+
+class LoginJaeyoung extends React.Component {
+ constructor () {
+ super();
+ this.state = {
+ id: '',
+ pw : '',
+ };
+ }
+
+ handleInput = (e) => {
+ const { name,value} = e.target;
+ this.setState({
+ [name]: value
+ })
+ }
+
+ goToMain = () => {
+ this.props.history.push('/main-jaeyoung')
+ }
+
+
+ render () {
+ const { handleInput } = this
+ const isBtnAble = this.state.id.includes('@') && this.state.pw.length >= 5;
+
+
+ return (
+ <div className="loginContainer">
+ <div className="logoName">
+ <h1>Instargram</h1>
+ </div>
+ <div className="loginInfo">
+ <input type="text" name="id" onChange={handleInput} className="loginId" placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ" />
+ <input type="password" name="pw" onChange={handleInput} className="loginPs" placeholder="๋น๋ฐ๋ฒํธ"/>
+ <button className="loginBt" onClick={this.goToMain} disabled={!isBtnAble}>๋ก๊ทธ์ธ</button>
+ </div>
+ <div className="forgetPassword">
+ <a href="https://www.naver.com/">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ )
+ }
+}
+
+export default withRouter( LoginJaeyoung );
\ No newline at end of file | JavaScript | ์...์์ ํ์ต๋๋ค! |
@@ -0,0 +1,85 @@
+* {
+ box-sizing: border-box;
+}
+
+.loginContainer {
+ border: 2px solid #e6e6e6;
+ width: 350px;
+ height: 380px;
+ margin: 0 auto;
+ .logoName {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ h1 {
+ font-family: "Lobster", cursive;
+ width: 175px;
+ height: 52px;
+ text-align: center;
+ padding-top: 6px;
+ }
+ }
+ .loginInfo {
+ height: 213px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding-top: 10px;
+ .loginId {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginPs {
+ width: 268px;
+ height: 38px;
+ margin-bottom: 5px;
+ padding-left: 10px;
+ border-radius: 3px;
+ border: 1px solid #efefef;
+ background: #fafafa;
+ color: #9c9c9c;
+ font-size: 14px;
+ &:focus {
+ outline-color: gray;
+ }
+ }
+ .loginBt {
+ width: 268px;
+ height: 30px;
+ margin-top: 5px;
+ border-radius: 3px;
+ background-color: #2795f6;
+ color: #ffffff;
+ border-style: none;
+
+ &:focus {
+ outline: none;
+ }
+
+ &:disabled {
+ background-color: #b2dffc;
+ }
+ }
+ }
+ .forgetPassword{
+ display: flex;
+ justify-content: center;
+ margin-top: 20px;
+ a {
+ color: #043569; text-decoration: none;
+ }
+ }
+
+
+} | Unknown | ์์ ํ์ต๋๋ค! ๊ฐ์ฌํฉ๋๋น |
@@ -0,0 +1,190 @@
+import React from 'react';
+import FeedComponent from './FeedComponent/FeedComponent';
+import './Main.scss';
+import explore from '../../../images/jaeyoungLee/Main/explore.jpg';
+import heart from '../../../images/jaeyoungLee/Main/heart.jpg';
+import profile from '../../../images/jaeyoungLee/Main/profile.jpg';
+import heungminSon from '../../../images/jaeyoungLee/Main/์ํฅ๋ฏผ.jpg';
+class MainJaeyoung extends React.Component {
+ constructor () {
+ super();
+ this.state = {
+ commentFeed : [],
+ }
+ }
+
+ componentDidMount() {
+ fetch('http://localhost:3000/data/feedData.json', {
+ method: 'GET'
+ })
+ .then(res => res.json())
+ .then(data => {
+ this.setState({
+ commentFeed: data,
+ });
+ });
+ }
+
+
+
+ render(){
+ const { commentFeed } = this.state;
+ return(
+ <>
+ <nav>
+ <div className="navcontents">
+ <div className="navleft">
+ <div className="navleftcontents">
+ <span className="logo"><i className="fab fa-instagram"></i></span>
+ <h1 className="logoname">westagram</h1>
+ </div>
+ </div>
+ <div className="navcenter">
+ <div className="navcentercontents">
+ <input className="search" type="text" placeholder="๊ฒ์"/>
+ <span className="searchimg"><i className="fas fa-search"></i></span>
+ </div>
+ </div>
+ <div className="navright">
+ <div className="navrightcontents">
+ <img className="navexplore" src={explore} alt="ํํ"/>
+ <img className="navheart" src={heart} alt="ํํธ"/>
+ <img className="navprofile" src={profile} alt="ํ๋กํ"/>
+ </div>
+ </div>
+ </div>
+ </nav>
+ <div className="main">
+ <div className="feeds">
+ <div className="story">
+ <div className="storyimgbox">
+ <div className="storycontents">
+ <div className="storyprofile">
+ <div className="storylastbox">
+ <div className="storylast">
+ <img className="storyimg1" src={heungminSon} alt="ํ๋กํ1"/>
+ <p className="storyp1">์ํฅ๋ฏผ</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://instagram.famm6-1.fna.fbcdn.net/v/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=instagram.famm6-1.fna.fbcdn.net&_nc_ohc=mhDR9_0DpXIAX_KX0iq&ccb=7-4&oh=dcbb150241d6b1336dd54a4a20417b2a&oe=608B680F&_nc_sid=712cc3&ig_cache_key=YW5vbnltb3VzX3Byb2ZpbGVfcGlj.2-ccb7-4" alt="ํ๋กํ1"/>
+ <p className="storyp1">2wo0</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/35999304_258159611658935_7092278198804676608_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=et4sZhNbgpAAX-qKBH9&ccb=7-4&oh=0b254f6fb3e4182513c3e20ed1a326d0&oe=608BC5C1&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">geg</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/150675895_144233967522798_7515094658452540248_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=xslO4Za0644AX9cwObZ&ccb=7-4&oh=0f5cb82fd80b51b47d74e160e228aa1c&oe=608D7B5E&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">h._.j</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/135771971_1881013862054625_6713353513169410837_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=SxJIiqRh4rcAX8RSLYk&ccb=7-4&oh=6dec08c37a69cb2c2a14f21bc36b5eef&oe=608C0912&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">idon</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/155951500_335125831259326_3729086392261698560_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=3nnTQdlVU98AX_4fVMv&ccb=7-4&oh=4a596fc0e33f2ece37634ae50d38cdde&oe=608C5901&_nc_sid=48a2a6" alt="ํ๋กํ1"/>
+ <p className="storyp1">dfewg</p>
+ </div>
+ <div className="storylast">
+ <img className="storyimg1" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/37828240_293117218102022_6759937585105076224_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=jzs6QvrGtHAAX_qFR80&ccb=7-4&oh=f4984cbce61bc445f02622a5468278b3&oe=608B09A1&_nc_sid=57d425" alt="ํ๋กํ1"/>
+ <p className="storyp1">33gg</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ {commentFeed.map((feed,id) =>{
+ return (
+ <FeedComponent key={feed.id} profileimg={feed.profileimg} userName={feed.userName} feedimg={feed.feedimg} feedcontent={feed.feedcontent} />
+ );
+ })}
+
+ </div>
+ <div className="main-right">
+ <div className="my_profile">
+ <img className="my_profileimg" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/141997127_1523884024669097_6148385093252095280_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=ldPmBqcpW3kAX9esSCC&ccb=7-4&oh=6503a99b1b0096ad362012fef7e72aed&oe=6085537E&_nc_sid=7b02f1" alt="ํ๋กํ"/>
+ <div className="my_info">
+ <p className="mynickname">2wo0_0</p>
+ <p className="myname">์ด์ฌ์</p>
+ </div>
+ <button className="profile_transform" disabled>์ ํ</button>
+ </div>
+ <div className="recommendation">
+ <div className="recommendation_header">
+ <p className="recommendation_left">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p className="recommendation_right">๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="recommendation_info">
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/156650140_116853317083347_8770042214751161261_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=-evbCZABANYAX_WcDzP&edm=AEF8tYYAAAAA&ccb=7-4&oh=5eb6e52a64b2ad8c98bff45dab473831&oe=60880D5B&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">ryu_d_g</p>
+ <p className="other_friend">1996yunsi๋ ์ธ 13๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/159992110_105322351555148_1839915921172216453_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=xfLIvYCwwiIAX8AJI08&ccb=7-4&oh=7bdaf0e022e88f0dd5079c1995892031&oe=608D9B9E&_nc_sid=57d425" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">2s2_f</p>
+ <p className="other_friend">_sihyeon___๋ ์ธ 49๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/160716680_272942871038831_8108440433038115559_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=VmeF5WmeLg4AX-jiUAL&ccb=7-4&oh=cf29d0253e8afb755a9d26ad13a6deda&oe=608D4A0C&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">rdfe_g</p>
+ <p className="other_friend">111_fkdn๋ ์ธ 5๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/164274433_776408706413539_3215024154205561736_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=gCCfowKp9OMAX9_NBIP&ccb=7-4&oh=afbada353869184275b4d3be70f38605&oe=608BE909&_nc_sid=a9513d" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">cat_2d_g</p>
+ <p className="other_friend">cjdtkseh๋ ์ธ 15๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ <div className="recommendation_box">
+ <img className="friend_profile" src=" https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/164520013_834814623778500_398528442563386719_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=iLm66uEJKQ4AX88GkVl&ccb=7-4&oh=4fe271ebb6f627b328cb3d24bb811776&oe=608E6098&_nc_sid=86f79a" alt="๋ค๋ฅธํ๋กํ"/>
+ <div className="friend_info">
+ <p className="friend_nickname">tksdkdnENr</p>
+ <p className="other_friend">cjfcjfgme1๋ ์ธ 32๋ช
์ด ํ๋ก์ฐํฉ๋๋ค</p>
+ </div>
+ <button className="follow" disabled>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ </div>
+ <aside>
+ <ul className="westagram_contents_box">
+ {CONTENTS.map((el,id) =>
+ <li key={id} className="westagram_contents">{el.content}</li>
+ )}
+
+ </ul>
+ <p className="westagram_facebook">ยฉ 2021 INSTAGRAM FROM FACEBOOK</p>
+ </aside>
+ </div>
+ </div>
+ </>
+ )
+ }
+}
+export default MainJaeyoung ;
+
+const CONTENTS = [
+ {id: 1, content: "์๊ฐ"},
+ {id: 2, content: "๋์๋ง"},
+ {id: 3, content: "ํ๋ณด ์ผํฐ"},
+ {id: 4, content: "API"},
+ {id: 5, content: "์ฑ์ฉ์ ๋ณด"},
+ {id: 6, content: "๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ"},
+ {id: 7, content: "์ฝ๊ด"},
+ {id: 8, content: "์์น"},
+ {id: 9, content: "์ธ๊ธฐ ๊ณ์ "},
+ {id: 10, content: "ํด์ํ๊ทธ"},
+ {id: 11, content: "์ธ์ด"},
+]
\ No newline at end of file | JavaScript | ์์ ํ์ต๋๋ค! ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="ko">
+ <head>
+ <meta charset="UTF-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+
+ <title>์ํ๊ด</title>
+ <script defer src="./bundle.js"></script></head>
+ <body>
+ <div id="app"></div>
+ </body>
+</html> | Unknown | ์๋ง ๋ฐฐํฌ ๋๋ฌธ์ dist ํด๋๋ฅผ ์ด๋ ๊ฒ ์ฌ๋ ค์ฃผ์ ๊ฒ ๊ฐ๋ค์ ใ
ใ
gh-pages ๋ธ๋์น๋ฅผ ์ด์ฉํ๋ฉด ์ด๋จ๊น ์ถ์ด์! |
@@ -0,0 +1,20 @@
+import { createComponent } from "../createComponent";
+import { Header } from "./Header";
+import { Main } from "./Main";
+
+export async function App() {
+ const header = await createComponent(Header);
+ const main = await createComponent(Main);
+
+ const bindEvents = () => {
+ main.bindEvents();
+ };
+
+ return {
+ element: `
+ ${header.element}
+ ${main.element}
+ `,
+ bindEvents,
+ };
+} | JavaScript | ์ด์ ๋ณด๋ header๋ main ๋๋ฌธ์ด๊ตฐ์ ใ
ใ
|
@@ -0,0 +1,13 @@
+export let currentComponent = null;
+
+export async function createComponent(component, props) {
+ const previousComponent = currentComponent;
+
+ currentComponent = { name: component.name, stateIndex: 0 };
+
+ const componentInstance = await component(props);
+
+ currentComponent = previousComponent;
+
+ return componentInstance;
+} | JavaScript | ์ฌ๊ธฐ์ previousComponent๊ฐ ํ๋ ์ญํ ์ ๋ฌด์์ผ๊น์? |
@@ -0,0 +1,55 @@
+import { createComponent, currentComponent } from "../createComponent";
+import { fetchMovies } from "../fetch";
+import { useState } from "../state";
+import { MovieCard } from "./MovieCard";
+
+export async function MovieList() {
+ const [page, setPage] = useState(1);
+
+ const movieData = await fetchMovies({ page });
+
+ const [movies, setMovies] = useState([...movieData.results]);
+ const [totalPage] = useState(movieData.total_page);
+
+ const movieCards = await Promise.all(
+ movies.map((movie, index) =>
+ createComponent(MovieCard, {
+ index,
+ title: movie.title,
+ score: movie.vote_average,
+ thumbnailUrl: `https://image.tmdb.org/t/p/w200/${movie.poster_path}`,
+ })
+ )
+ );
+
+ const handleMoreButton = async () => {
+ if (page >= totalPage) {
+ return;
+ }
+
+ await setPage(page + 1);
+
+ const movieData = await fetchMovies({ page: page + 1 });
+ const newMovies = [...movies, ...movieData.results];
+
+ await setMovies(newMovies);
+ };
+
+ const bindEvents = () => {
+ movieCards.forEach((movieCard) => movieCard.bindEvents());
+
+ const $moreButton = document.querySelector("#more-button");
+
+ $moreButton.addEventListener("click", handleMoreButton);
+ };
+
+ return {
+ element: /* html */ `
+ <ul class="item-list">
+ ${movieCards.map((movieCard) => movieCard.element).join("")}
+ </ul>
+ <button id="more-button" class="btn primary full-width">๋ ๋ณด๊ธฐ</button>
+ `,
+ bindEvents,
+ };
+} | JavaScript | ๋ง์ฝ ํ ํ์ด์ง์ ์นดํ
๊ณ ๋ฆฌ๋ณ๋ก ์ฌ๋ฌ ๊ฐ์ ์ํ๋ชฉ๋ก์ ๋์์ค๋ค๊ณ ํ์ ๋,
์ด ์ปดํฌ๋ํธ๋ฅผ ์ฌํ์ฉํ ์ ์์๊น์? |
@@ -0,0 +1,55 @@
+import { createComponent, currentComponent } from "../createComponent";
+import { fetchMovies } from "../fetch";
+import { useState } from "../state";
+import { MovieCard } from "./MovieCard";
+
+export async function MovieList() {
+ const [page, setPage] = useState(1);
+
+ const movieData = await fetchMovies({ page });
+
+ const [movies, setMovies] = useState([...movieData.results]);
+ const [totalPage] = useState(movieData.total_page);
+
+ const movieCards = await Promise.all(
+ movies.map((movie, index) =>
+ createComponent(MovieCard, {
+ index,
+ title: movie.title,
+ score: movie.vote_average,
+ thumbnailUrl: `https://image.tmdb.org/t/p/w200/${movie.poster_path}`,
+ })
+ )
+ );
+
+ const handleMoreButton = async () => {
+ if (page >= totalPage) {
+ return;
+ }
+
+ await setPage(page + 1);
+
+ const movieData = await fetchMovies({ page: page + 1 });
+ const newMovies = [...movies, ...movieData.results];
+
+ await setMovies(newMovies);
+ };
+
+ const bindEvents = () => {
+ movieCards.forEach((movieCard) => movieCard.bindEvents());
+
+ const $moreButton = document.querySelector("#more-button");
+
+ $moreButton.addEventListener("click", handleMoreButton);
+ };
+
+ return {
+ element: /* html */ `
+ <ul class="item-list">
+ ${movieCards.map((movieCard) => movieCard.element).join("")}
+ </ul>
+ <button id="more-button" class="btn primary full-width">๋ ๋ณด๊ธฐ</button>
+ `,
+ bindEvents,
+ };
+} | JavaScript | ๋ชจ๋ ๊ตฌ๊ฐ์ด ๋ค async/await ์ผ๋ก ๋ง๋ค์ด์ง ์ด์ ๊ฐ ์ฌ๊ธฐ์ ์ถ๋ฐ์ด ๋๋ค์.
์ด ๋ถ๋ถ๋ง ๊ฐ์ ํ๋ฉด async/awiat ์ ์ ์ฒด์ ์ผ๋ก ์ ๊ฑฐํ ์ ์์ง ์์๊น์? |
@@ -0,0 +1,55 @@
+import { createComponent, currentComponent } from "../createComponent";
+import { fetchMovies } from "../fetch";
+import { useState } from "../state";
+import { MovieCard } from "./MovieCard";
+
+export async function MovieList() {
+ const [page, setPage] = useState(1);
+
+ const movieData = await fetchMovies({ page });
+
+ const [movies, setMovies] = useState([...movieData.results]);
+ const [totalPage] = useState(movieData.total_page);
+
+ const movieCards = await Promise.all(
+ movies.map((movie, index) =>
+ createComponent(MovieCard, {
+ index,
+ title: movie.title,
+ score: movie.vote_average,
+ thumbnailUrl: `https://image.tmdb.org/t/p/w200/${movie.poster_path}`,
+ })
+ )
+ );
+
+ const handleMoreButton = async () => {
+ if (page >= totalPage) {
+ return;
+ }
+
+ await setPage(page + 1);
+
+ const movieData = await fetchMovies({ page: page + 1 });
+ const newMovies = [...movies, ...movieData.results];
+
+ await setMovies(newMovies);
+ };
+
+ const bindEvents = () => {
+ movieCards.forEach((movieCard) => movieCard.bindEvents());
+
+ const $moreButton = document.querySelector("#more-button");
+
+ $moreButton.addEventListener("click", handleMoreButton);
+ };
+
+ return {
+ element: /* html */ `
+ <ul class="item-list">
+ ${movieCards.map((movieCard) => movieCard.element).join("")}
+ </ul>
+ <button id="more-button" class="btn primary full-width">๋ ๋ณด๊ธฐ</button>
+ `,
+ bindEvents,
+ };
+} | JavaScript | movieData๋ฅผ props๋ก ๋ฐ์์ค๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,13 @@
+export async function fetchMovies({ page }) {
+ const baseUrl = "https://api.themoviedb.org/3/movie/popular";
+ const param = new URLSearchParams({
+ page,
+ language: "ko-KR",
+ });
+
+ const response = await fetch(`${baseUrl}?${param}`, {
+ headers: { authorization: `Bearer ${process.env.API_KEY}` },
+ });
+
+ return await response.json();
+} | JavaScript | ์ฌ์ค ๋ฐฐํฌ๋ ์ฌ์ดํธ์ ๋คํธ์ํฌ ์์ฒญ์ ๊น๋ณด๋ฉด API_KEY ๊ฐ ๊ทธ๋๋ก ๋
ธ์ถ๋๋๊ฑธ ํ์ธํ ์ ์๋ต๋๋ค ใ
ใ
์ด๊ฑด ์ด๋ป๊ฒ ๋ฐฉ์งํ ์ ์์๊น์? |
@@ -0,0 +1,13 @@
+export async function fetchMovies({ page }) {
+ const baseUrl = "https://api.themoviedb.org/3/movie/popular";
+ const param = new URLSearchParams({
+ page,
+ language: "ko-KR",
+ });
+
+ const response = await fetch(`${baseUrl}?${param}`, {
+ headers: { authorization: `Bearer ${process.env.API_KEY}` },
+ });
+
+ return await response.json();
+} | JavaScript | ์ฌ๊ธฐ์ await์ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ์ฌ์ฉํ์ง ์๋๊ฒ ์ด๋ค ์ฐจ์ด๊ฐ ์๋์ง ํน์ ์์ค๊น์~? |
@@ -0,0 +1,50 @@
+package christmas.domain;
+
+public enum Calendar {
+ WEEKEND(1, 2, 8, 9, 15, 16, 22, 23, 29, 30),
+ WEEKDAY(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31),
+ SPECIAL_DAY(3, 10, 17, 24, 25, 31);
+
+ private final int[] days;
+
+ Calendar(int... days) {
+ this.days = days;
+ }
+
+ public int[] getDays() {
+ return days;
+ }
+
+ public static boolean isWeekday(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekday : calendar.getDays()) {
+ if (weekday == date && calendar == WEEKDAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isWeekend(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekend : calendar.getDays()) {
+ if (weekend == date && calendar == WEEKEND) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isSpecialDay(int date) {
+ for (Calendar calendar : values()) {
+ for (int specialDay : calendar.getDays()) {
+ if (specialDay == date && calendar == SPECIAL_DAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+} | Java | ๋ ์ง ๊ด๋ จ๋ ๋ก์ง์ `LocalDate`์ `DayOfWeek`๋ฅผ ์ ์ฉํ๋ฉด ํจ์ฌ ๊ฐ๊ฒฐํ๊ฒ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์ต๋๋ค!! |
@@ -0,0 +1,50 @@
+package christmas.domain;
+
+public enum Calendar {
+ WEEKEND(1, 2, 8, 9, 15, 16, 22, 23, 29, 30),
+ WEEKDAY(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31),
+ SPECIAL_DAY(3, 10, 17, 24, 25, 31);
+
+ private final int[] days;
+
+ Calendar(int... days) {
+ this.days = days;
+ }
+
+ public int[] getDays() {
+ return days;
+ }
+
+ public static boolean isWeekday(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekday : calendar.getDays()) {
+ if (weekday == date && calendar == WEEKDAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isWeekend(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekend : calendar.getDays()) {
+ if (weekend == date && calendar == WEEKEND) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isSpecialDay(int date) {
+ for (Calendar calendar : values()) {
+ for (int specialDay : calendar.getDays()) {
+ if (specialDay == date && calendar == SPECIAL_DAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+} | Java | ํด๋น ๋ก์ง์ depth๊ฐ 3์ด๊ธฐ์ ์ ์ ํ ๋ฉ์๋ ์ถ์ถ, ๋๋ ๋ฆฌํฉํ ๋ง์ด ํ์ํ ๊ฒ ๊ฐ์๋ฐ์.
์ฃผ๋ง์ ํ์ธํ๊ธฐ ์ํด์ ๋ชจ๋ `Calandar`์ `enum` ์์๋ฅผ ํ์ํ ํ์๋ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ํ, ์คํธ๋ฆผ์ ์ฌ์ฉํ๋ค๋ฉด ๋๋ก ์ฒด์ธ๋ค๋ก ๊ฐ๊ฐ์ ๋จ๊ณ๊ฐ ๊ตฌ๋ถ๋๊ธฐ์ ๊ฐ๋
์ฑ์ด ์ข์์ง๊ธฐ๋ ํ๋ ์คํธ๋ฆผ์ ์ ๊ทน ํ์ฉํ์๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
```suggestion
return Arrays.stream(WEEKEND.days)
.anyMatch(day -> day == date);
``` |
@@ -0,0 +1,37 @@
+package christmas.domain;
+
+import java.util.Arrays;
+
+public enum Menu {
+ ์์ก์ด์ํ(6_000), ํํ์ค(5_500), ์์ ์๋ฌ๋(8_000),
+ ํฐ๋ณธ์คํ
์ดํฌ(55_000), ๋ฐ๋นํ๋ฆฝ(54_000), ํด์ฐ๋ฌผํ์คํ(35_000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25_000),
+ ์ด์ฝ์ผ์ดํฌ(15_000), ์์ด์คํฌ๋ฆผ(5_000),
+ ์ ๋ก์ฝ๋ผ(3_000), ๋ ๋์์ธ(60_000), ์ดํ์ธ(25_000);
+
+ private final int price;
+
+ Menu(int price) {
+ this.price = price;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public boolean isBeverage() {
+ return this == ์ ๋ก์ฝ๋ผ || this == ๋ ๋์์ธ || this == ์ดํ์ธ;
+ }
+
+ public boolean isDessert() {
+ return this == ์ด์ฝ์ผ์ดํฌ || this == ์์ด์คํฌ๋ฆผ;
+ }
+
+ public boolean isMain() {
+ return this == ํฐ๋ณธ์คํ
์ดํฌ || this == ๋ฐ๋นํ๋ฆฝ || this == ํด์ฐ๋ฌผํ์คํ || this == ํฌ๋ฆฌ์ค๋ง์คํ์คํ;
+ }
+
+ public static boolean contains(String itemName) {
+ return Arrays.stream(Menu.values())
+ .anyMatch(menu -> menu.name().equalsIgnoreCase(itemName));
+ }
+} | Java | ์ด ๊ฒฝ์ฐ ๋ฉ๋ด์ ์ถ๊ฐ ๋ฐ ๋ณ๊ฒฝ์ด ์์ ๋ ๋ง๋ค ๋ฉ์๋ ๋ก์ง์ ๋ณ๊ฒฝ ๋ํ ํจ๊ป ๋ฐ์ํด์ผ ํ๋๋ฐ์.
๊ฐ ๋ฉ๋ด์ ์ ๋ณด๊ฐ ๋ฉ๋ด ํ์
์ ํจ๊ป ์ ์ฅํ๊ณ ์๊ฑฐ๋, ๋ฉ๋ด ํ์
์ด ๋ฆฌ์คํธ ํ์์ผ๋ก ๋ฉ๋ด๋ค์ ์ ์ฅํ๊ณ ์๋๋ก ํ๋ฉด `public boolean isTypeOf(MenuType expectedType)`๊ณผ ๊ฐ์ ๋ฉ์๋ ํ๋๋ง ์ ๊ณตํด ์ฃผ๋ ๊ฒ์ผ๋ก ๋ณํ์ ์ฝ๊ฒ ๋์ํ ์๊ฐ ์์ด์! |
@@ -0,0 +1,24 @@
+package christmas.domain;
+
+public enum DiscountType {
+ MIN_EVENT_CONDITION(10000),
+ CHAMPAGNE_CONDITION(120000),
+ CHAMPAGNE(25000),
+ SERVICE_MENU_CONDITION(1),
+ DDAY_CONDITION(25),
+ BASE_AMOUNT(900),
+ DAY_BONUS(100),
+ SPECIALDAY_CONDITION(2023),
+ INIT_COUNT(0),
+ SPECIAL_DISCOUNT(1000);
+
+ private final int type;
+
+ DiscountType(int type) {
+ this.type = type;
+ }
+
+ public int getType() {
+ return type;
+ }
+} | Java | ์ซ์์ ์๋ฆฌ์๊ฐ ๋ง์์ง๋ค๋ฉด _ ์ผ๋ก ์๋ฆฌ์ ๊ตฌ๋ถ์ด ๊ฐ๋ฅํฉ๋๋ค!
```suggestion
CHAMPAGNE_CONDITION(120_000),
``` |
@@ -0,0 +1,36 @@
+package christmas.view;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.domain.Menu;
+import christmas.domain.Order;
+import christmas.domain.Reservation;
+import christmas.exception.ValidatorException;
+import christmas.validator.Validator;
+import java.util.Map;
+
+public class InputView {
+
+ public static Reservation createReservation() {
+ try {
+ String input = Console.readLine();
+ int date = Validator.convertDateStringToInt(input);
+
+ return Reservation.from(date);
+ } catch (ValidatorException exception) {
+ OutputView.println(exception.getMessage());
+ return createReservation();
+ }
+ }
+
+ public static Order createOrder() {
+ try {
+ String input = Console.readLine();
+ Validator.isValidOrderFormat(input);
+ Map<Menu, Integer> order = Validator.parseOrder(input);
+ return Order.from(order);
+ } catch (ValidatorException exception) {
+ OutputView.println(exception.getMessage());
+ return createOrder();
+ }
+ }
+} | Java | `InputView`์ ์กด์ฌํ๋ ์ฝ๋ ํ๋ฆ์ ์ค๋ณต์ ๋ค์๊ณผ ๊ฐ์ด ์ ๊ฑฐํ ์ ์์ต๋๋ค!
๋์ ํ๋ผ๋ฏธํฐํ๋ก ๋ณ๊ฒฝ์ด ํ์ํ ๋ก์ง์ ๋ถ๋ถ๋ง ์ค๋ณต๋๋ ํ๋ฆ ์ฌ์ด์ ์ ๋ฌํด ์ฃผ๋ ๋ฐฉ์์ด์์!
```suggestion
public static Order createOrder() {
return getResult(() -> {
String input = Console.readLine();
Validator.isValidOrderFormat(input);
Map<Menu, Integer> order = Validator.parseOrder(input);
return Order.from(order);
});
}
public static <T> T getResult(Supplier<T> supplier){
try{
return supplier.get();
} catch (ValidatorException e){
OutputView.println(e.getMessage());
return getResult(supplier);
}
}
``` |
@@ -0,0 +1,36 @@
+package christmas.view;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.domain.Menu;
+import christmas.domain.Order;
+import christmas.domain.Reservation;
+import christmas.exception.ValidatorException;
+import christmas.validator.Validator;
+import java.util.Map;
+
+public class InputView {
+
+ public static Reservation createReservation() {
+ try {
+ String input = Console.readLine();
+ int date = Validator.convertDateStringToInt(input);
+
+ return Reservation.from(date);
+ } catch (ValidatorException exception) {
+ OutputView.println(exception.getMessage());
+ return createReservation();
+ }
+ }
+
+ public static Order createOrder() {
+ try {
+ String input = Console.readLine();
+ Validator.isValidOrderFormat(input);
+ Map<Menu, Integer> order = Validator.parseOrder(input);
+ return Order.from(order);
+ } catch (ValidatorException exception) {
+ OutputView.println(exception.getMessage());
+ return createOrder();
+ }
+ }
+} | Java | `View`์์ ๋๋ฉ์ธ ํด๋์ค ์์ฒด๊ฐ ์์ฑ๋์ด ๋ฐํ๋๋ ๊ฒ์ด `View` ํด๋์ค์ ๋๋ฌด ๋ง์ ์ฑ
์์ด ์กด์ฌํ๋ ๊ฒ ์ฒ๋ผ ๋ณด์ด๊ธฐ๋ ํ๋๋ฐ ์ด ๋ถ๋ถ์ ๋ํด์ ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,48 @@
+package christmas.view.messages;
+
+public enum PrintMessage {
+ INPUT_INTRODUCE("์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค."),
+ INPUT_RESERVATION("12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)"),
+ INPUT_ORDER("์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)"),
+
+ OUTPUT_RESULT("12์ 26์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!"),
+ OUTPUT_ORDER("<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ OUTPUT_TOTAL_BEFORE_DISCOUNT("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ OUTPUT_GIFT_MENU("<์ฆ์ ๋ฉ๋ด>"),
+ OUTPUT_BENEFIT("<ํํ ๋ด์ญ>"),
+ OUTPUT_TOTAL_BENEFIT("<์ดํํ ๊ธ์ก>"),
+ OUTPUT_TOTAL_AFTER_DISCOUNT("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ OUTPUT_EVENT_BADGE("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>"),
+ OUTPUT_PRECAUTIONS("์ด์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์๋ถํฐ ์ด๋ฒคํธ๊ฐ ์ ์ฉ๋ฉ๋๋ค.\n"
+ + "์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.\n"
+ + "๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.\n"
+ + "(e.g. ์์ ์๋ฌ๋-1, ํฐ๋ณธ์คํ
์ดํฌ-1, ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1, ์ ๋ก์ฝ๋ผ-3, ์์ด์คํฌ๋ฆผ-1์ ์ด๊ฐ์๋ 7๊ฐ)\n"),
+ MONEY("์"),
+ COUNT("๊ฐ"),
+ NONE("์์"),
+ PREVIEW("12์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!"),
+ CHRISTMAS_DISCOUNT("ํฌ๋ฆฌ์ค๋ง์ค ํ ์ธ: -"),
+ WEEKDAY_DISCOUNT("ํ์ผ ํ ์ธ: -"),
+ WEEKEND_DISCOUNT("์ฃผ๋ง ํ ์ธ: -"),
+ SPECIAL_DISCOUNT("ํน๋ณ ํ ์ธ: -"),
+ SERVICE_DISCOUNT("์ฆ์ ์ด๋ฒคํธ: -"),
+ BENEFIT_ALL_DISCOUNT("<์ดํํ ๊ธ์ก>"),
+ AFTER_BENEFIT_DISCOUNT("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ BADGE_DISCOUNT("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>"),
+ SERVICE_MENU("์ดํ์ธ 1๊ฐ");
+
+
+ private final String message;
+
+ PrintMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String getMessage(int day) {
+ return String.format(message, day);
+ }
+} | Java | ์ฌ๋ฌ ์ค๋ก ๊ตฌ์ฑ๋ `String`์ `"""`๋ก ๊ฐ์ธ์ค ์ ์๋ ๊ฒ์ผ๋ก ์๊ณ ์์ต๋๋ค! |
@@ -0,0 +1,150 @@
+package christmas.validator;
+
+import christmas.domain.Menu;
+import christmas.exception.ErrorMessage;
+import christmas.exception.ValidatorException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Validator {
+ private static final String DELIMITER = ",";
+ private static final int FIRST_DAY = 1;
+ private static final int LAST_DAY = 31;
+ private static final int MAX_MENU_COUNT = 20;
+ private static final int MIN_MUST_COUNT = 1;
+ private static final int TRUE = 1;
+ private static final int FALSE = 0;
+ public static int convertDateStringToInt(String input) {
+ try {
+ isNumeric(input);
+ return Integer.parseInt(input);
+ } catch (NumberFormatException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_DATE, exception);
+ }
+ }
+
+ public static int convertOrderStringToInt(String input) {
+ try {
+ isNumeric(input);
+ return Integer.parseInt(input);
+ } catch (NumberFormatException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+ private static boolean isNumeric(String input) {
+ return input.matches("\\d+");
+ }
+
+ public static void isInRange(int date) {
+ if (date < FIRST_DAY || date > LAST_DAY) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ public static boolean isValidOrderFormat(String order) {
+ try {
+ String regex = "([\\w๊ฐ-ํฃ]+-\\d+,)*[\\w๊ฐ-ํฃ]+-\\d+";
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(order);
+ return matcher.matches();
+ } catch (IllegalArgumentException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+
+ public static Map<Menu, Integer> parseOrder(String order) {
+ try {
+ Map<Menu, Integer> orderMap = new HashMap<>();
+ Set<Menu> uniqueMenus = new HashSet<>();
+ String[] items = order.split(",");
+ int count = 0;
+ int beverageFlag = FALSE;
+ for (String item : items) {
+ String[] parts = item.split("-");
+ validateNonNumericString(parts[0]); // ์ฒ์ ๋ค์ด์จ ๊ฐ์ด ์ซ์๋ฉด ์๋ฌ
+ Menu menu = getMenuByName(parts[0]);
+ if (!menu.isBeverage()) {
+ beverageFlag = TRUE;
+ }
+ isDuplicate(uniqueMenus, menu);
+ if (parts.length == 2) {
+ int quantity = convertOrderStringToInt(parts[1]);
+ isMinCount(quantity);
+ count += quantity;
+ orderMap.put(menu, quantity);
+ }
+ }
+ isOnlyBeverageOrder(beverageFlag);
+ isMaxCount(count);
+ return orderMap;
+ } catch (IllegalArgumentException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+ private static void isOnlyBeverageOrder(int beverageFlag) {
+ if (beverageFlag == FALSE) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isDuplicate(Set<Menu> uniqueMenus, Menu menu) {
+ if (!uniqueMenus.add(menu)) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isMinCount(int quantity) {
+ if (quantity < MIN_MUST_COUNT) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isMaxCount(int count) {
+ if (count > MAX_MENU_COUNT) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ public static void validateNonNumericString(String input) {
+ if (isNumeric(input)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ public static Menu getMenuByName(String menuName) {
+ for (Menu menu : Menu.values()) {
+ if (menu.name().equalsIgnoreCase(menuName)) {
+ return menu;
+ }
+ }
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+
+
+ public static void validateContainWhiteSpace(String input) {
+ if (hasWhiteSpace(input)) {
+ throw ValidatorException.from(ErrorMessage.CONTAIN_WHITESPACE);
+ }
+ }
+
+ public static void validateEndsWithDelimiter(String input) {
+ if (isEndsWithDelimiter(input)) {
+ throw ValidatorException.from(ErrorMessage.ENDS_WITH_DELIMITER);
+ }
+ }
+
+ private static boolean hasWhiteSpace(String input) {
+ return input.chars().anyMatch(Character::isWhitespace);
+ }
+
+ private static boolean isEndsWithDelimiter(String input) {
+ return input.endsWith(DELIMITER);
+ }
+} | Java | ํด๋น ๋ก์ง์ 26๋ผ์ธ์ผ๋ก ๊ตฌ์ฑ๋์ด ์์ด์.
๊ฐ ๋จ๊ณ๋ฅผ ๋ฉ์๋๋ก ์ถ์ถํด ๋ณด๋ ๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,50 @@
+package christmas.domain;
+
+public enum Calendar {
+ WEEKEND(1, 2, 8, 9, 15, 16, 22, 23, 29, 30),
+ WEEKDAY(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31),
+ SPECIAL_DAY(3, 10, 17, 24, 25, 31);
+
+ private final int[] days;
+
+ Calendar(int... days) {
+ this.days = days;
+ }
+
+ public int[] getDays() {
+ return days;
+ }
+
+ public static boolean isWeekday(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekday : calendar.getDays()) {
+ if (weekday == date && calendar == WEEKDAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isWeekend(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekend : calendar.getDays()) {
+ if (weekend == date && calendar == WEEKEND) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isSpecialDay(int date) {
+ for (Calendar calendar : values()) {
+ for (int specialDay : calendar.getDays()) {
+ if (specialDay == date && calendar == SPECIAL_DAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+} | Java | ์๊ฐํ์ง ๋ชปํ๋ ๋ถ๋ถ์ธ๋ฐ ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,50 @@
+package christmas.domain;
+
+public enum Calendar {
+ WEEKEND(1, 2, 8, 9, 15, 16, 22, 23, 29, 30),
+ WEEKDAY(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31),
+ SPECIAL_DAY(3, 10, 17, 24, 25, 31);
+
+ private final int[] days;
+
+ Calendar(int... days) {
+ this.days = days;
+ }
+
+ public int[] getDays() {
+ return days;
+ }
+
+ public static boolean isWeekday(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekday : calendar.getDays()) {
+ if (weekday == date && calendar == WEEKDAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isWeekend(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekend : calendar.getDays()) {
+ if (weekend == date && calendar == WEEKEND) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isSpecialDay(int date) {
+ for (Calendar calendar : values()) {
+ for (int specialDay : calendar.getDays()) {
+ if (specialDay == date && calendar == SPECIAL_DAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+} | Java | ํ.. ๊ทธ๋ ์ง ์์๋ Stream์ ๋ํด ๊ณ์ ๊ณต๋ถํ๊ณ ์๋๋ฐ ๋ณต์ตํ๋ฉฐ ์ ์ฉํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,24 @@
+package christmas.domain;
+
+public enum DiscountType {
+ MIN_EVENT_CONDITION(10000),
+ CHAMPAGNE_CONDITION(120000),
+ CHAMPAGNE(25000),
+ SERVICE_MENU_CONDITION(1),
+ DDAY_CONDITION(25),
+ BASE_AMOUNT(900),
+ DAY_BONUS(100),
+ SPECIALDAY_CONDITION(2023),
+ INIT_COUNT(0),
+ SPECIAL_DISCOUNT(1000);
+
+ private final int type;
+
+ DiscountType(int type) {
+ this.type = type;
+ }
+
+ public int getType() {
+ return type;
+ }
+} | Java | ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,37 @@
+package christmas.domain;
+
+import java.util.Arrays;
+
+public enum Menu {
+ ์์ก์ด์ํ(6_000), ํํ์ค(5_500), ์์ ์๋ฌ๋(8_000),
+ ํฐ๋ณธ์คํ
์ดํฌ(55_000), ๋ฐ๋นํ๋ฆฝ(54_000), ํด์ฐ๋ฌผํ์คํ(35_000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25_000),
+ ์ด์ฝ์ผ์ดํฌ(15_000), ์์ด์คํฌ๋ฆผ(5_000),
+ ์ ๋ก์ฝ๋ผ(3_000), ๋ ๋์์ธ(60_000), ์ดํ์ธ(25_000);
+
+ private final int price;
+
+ Menu(int price) {
+ this.price = price;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public boolean isBeverage() {
+ return this == ์ ๋ก์ฝ๋ผ || this == ๋ ๋์์ธ || this == ์ดํ์ธ;
+ }
+
+ public boolean isDessert() {
+ return this == ์ด์ฝ์ผ์ดํฌ || this == ์์ด์คํฌ๋ฆผ;
+ }
+
+ public boolean isMain() {
+ return this == ํฐ๋ณธ์คํ
์ดํฌ || this == ๋ฐ๋นํ๋ฆฝ || this == ํด์ฐ๋ฌผํ์คํ || this == ํฌ๋ฆฌ์ค๋ง์คํ์คํ;
+ }
+
+ public static boolean contains(String itemName) {
+ return Arrays.stream(Menu.values())
+ .anyMatch(menu -> menu.name().equalsIgnoreCase(itemName));
+ }
+} | Java | ์ข ๋ ๊ฐ์ฒด์งํฅ์ ์ผ๋ก ์ค๊ณ๊ฐ ๊ฐ๋ฅํ ๋ถ๋ถ์ด๋ค์. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,150 @@
+package christmas.validator;
+
+import christmas.domain.Menu;
+import christmas.exception.ErrorMessage;
+import christmas.exception.ValidatorException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Validator {
+ private static final String DELIMITER = ",";
+ private static final int FIRST_DAY = 1;
+ private static final int LAST_DAY = 31;
+ private static final int MAX_MENU_COUNT = 20;
+ private static final int MIN_MUST_COUNT = 1;
+ private static final int TRUE = 1;
+ private static final int FALSE = 0;
+ public static int convertDateStringToInt(String input) {
+ try {
+ isNumeric(input);
+ return Integer.parseInt(input);
+ } catch (NumberFormatException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_DATE, exception);
+ }
+ }
+
+ public static int convertOrderStringToInt(String input) {
+ try {
+ isNumeric(input);
+ return Integer.parseInt(input);
+ } catch (NumberFormatException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+ private static boolean isNumeric(String input) {
+ return input.matches("\\d+");
+ }
+
+ public static void isInRange(int date) {
+ if (date < FIRST_DAY || date > LAST_DAY) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ public static boolean isValidOrderFormat(String order) {
+ try {
+ String regex = "([\\w๊ฐ-ํฃ]+-\\d+,)*[\\w๊ฐ-ํฃ]+-\\d+";
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(order);
+ return matcher.matches();
+ } catch (IllegalArgumentException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+
+ public static Map<Menu, Integer> parseOrder(String order) {
+ try {
+ Map<Menu, Integer> orderMap = new HashMap<>();
+ Set<Menu> uniqueMenus = new HashSet<>();
+ String[] items = order.split(",");
+ int count = 0;
+ int beverageFlag = FALSE;
+ for (String item : items) {
+ String[] parts = item.split("-");
+ validateNonNumericString(parts[0]); // ์ฒ์ ๋ค์ด์จ ๊ฐ์ด ์ซ์๋ฉด ์๋ฌ
+ Menu menu = getMenuByName(parts[0]);
+ if (!menu.isBeverage()) {
+ beverageFlag = TRUE;
+ }
+ isDuplicate(uniqueMenus, menu);
+ if (parts.length == 2) {
+ int quantity = convertOrderStringToInt(parts[1]);
+ isMinCount(quantity);
+ count += quantity;
+ orderMap.put(menu, quantity);
+ }
+ }
+ isOnlyBeverageOrder(beverageFlag);
+ isMaxCount(count);
+ return orderMap;
+ } catch (IllegalArgumentException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+ private static void isOnlyBeverageOrder(int beverageFlag) {
+ if (beverageFlag == FALSE) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isDuplicate(Set<Menu> uniqueMenus, Menu menu) {
+ if (!uniqueMenus.add(menu)) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isMinCount(int quantity) {
+ if (quantity < MIN_MUST_COUNT) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isMaxCount(int count) {
+ if (count > MAX_MENU_COUNT) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ public static void validateNonNumericString(String input) {
+ if (isNumeric(input)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ public static Menu getMenuByName(String menuName) {
+ for (Menu menu : Menu.values()) {
+ if (menu.name().equalsIgnoreCase(menuName)) {
+ return menu;
+ }
+ }
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+
+
+ public static void validateContainWhiteSpace(String input) {
+ if (hasWhiteSpace(input)) {
+ throw ValidatorException.from(ErrorMessage.CONTAIN_WHITESPACE);
+ }
+ }
+
+ public static void validateEndsWithDelimiter(String input) {
+ if (isEndsWithDelimiter(input)) {
+ throw ValidatorException.from(ErrorMessage.ENDS_WITH_DELIMITER);
+ }
+ }
+
+ private static boolean hasWhiteSpace(String input) {
+ return input.chars().anyMatch(Character::isWhitespace);
+ }
+
+ private static boolean isEndsWithDelimiter(String input) {
+ return input.endsWith(DELIMITER);
+ }
+} | Java | 15๋ผ์ธ์ผ๋ก ์ค์ด๋๋ก ๋
ธ๋ ฅํด๋ณด๊ฒ ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,36 @@
+package christmas.view;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.domain.Menu;
+import christmas.domain.Order;
+import christmas.domain.Reservation;
+import christmas.exception.ValidatorException;
+import christmas.validator.Validator;
+import java.util.Map;
+
+public class InputView {
+
+ public static Reservation createReservation() {
+ try {
+ String input = Console.readLine();
+ int date = Validator.convertDateStringToInt(input);
+
+ return Reservation.from(date);
+ } catch (ValidatorException exception) {
+ OutputView.println(exception.getMessage());
+ return createReservation();
+ }
+ }
+
+ public static Order createOrder() {
+ try {
+ String input = Console.readLine();
+ Validator.isValidOrderFormat(input);
+ Map<Menu, Integer> order = Validator.parseOrder(input);
+ return Order.from(order);
+ } catch (ValidatorException exception) {
+ OutputView.println(exception.getMessage());
+ return createOrder();
+ }
+ }
+} | Java | ์ต๊ทผ์ ๊ณต๋ถํ๋ฉฐ View๋ ์ปจํธ๋กค๋ฌ์์ Model์ ๋ฐ๊ธฐ๋ง ํด์ผ ํ๋ค๋ ์๊ฐ์ด ๋ค์์ต๋๋ค. ์ด ๋น์์๋ View์์ Model์ ์์ฑํด์ ๋ฐํํ๋ ๋ฐฉ๋ฒ์ด ์ ๋ ๋ง๋๊ฑด๊ฐ? ์๊ฐ์ ํ์๋๋ฐ ๊ฐ๋ง ๋ฐํํด์ฃผ๋ ํ์์ผ๋ก ์์ ํด๋ด์ผ๊ฒ ๋ค์. ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,36 @@
+package christmas.view;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.domain.Menu;
+import christmas.domain.Order;
+import christmas.domain.Reservation;
+import christmas.exception.ValidatorException;
+import christmas.validator.Validator;
+import java.util.Map;
+
+public class InputView {
+
+ public static Reservation createReservation() {
+ try {
+ String input = Console.readLine();
+ int date = Validator.convertDateStringToInt(input);
+
+ return Reservation.from(date);
+ } catch (ValidatorException exception) {
+ OutputView.println(exception.getMessage());
+ return createReservation();
+ }
+ }
+
+ public static Order createOrder() {
+ try {
+ String input = Console.readLine();
+ Validator.isValidOrderFormat(input);
+ Map<Menu, Integer> order = Validator.parseOrder(input);
+ return Order.from(order);
+ } catch (ValidatorException exception) {
+ OutputView.println(exception.getMessage());
+ return createOrder();
+ }
+ }
+} | Java | ํ ์ด๋ฐ์์ผ๋ก ์ฝ๋๋ฅผ ์์ฑํ ์ ์๊ตฐ์. ์๋ ค์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. ์ข ๋ ๊ณต๋ถํด์ ์ ์ฉํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,48 @@
+package christmas.view.messages;
+
+public enum PrintMessage {
+ INPUT_INTRODUCE("์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค."),
+ INPUT_RESERVATION("12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)"),
+ INPUT_ORDER("์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)"),
+
+ OUTPUT_RESULT("12์ 26์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!"),
+ OUTPUT_ORDER("<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ OUTPUT_TOTAL_BEFORE_DISCOUNT("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ OUTPUT_GIFT_MENU("<์ฆ์ ๋ฉ๋ด>"),
+ OUTPUT_BENEFIT("<ํํ ๋ด์ญ>"),
+ OUTPUT_TOTAL_BENEFIT("<์ดํํ ๊ธ์ก>"),
+ OUTPUT_TOTAL_AFTER_DISCOUNT("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ OUTPUT_EVENT_BADGE("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>"),
+ OUTPUT_PRECAUTIONS("์ด์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์๋ถํฐ ์ด๋ฒคํธ๊ฐ ์ ์ฉ๋ฉ๋๋ค.\n"
+ + "์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.\n"
+ + "๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.\n"
+ + "(e.g. ์์ ์๋ฌ๋-1, ํฐ๋ณธ์คํ
์ดํฌ-1, ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1, ์ ๋ก์ฝ๋ผ-3, ์์ด์คํฌ๋ฆผ-1์ ์ด๊ฐ์๋ 7๊ฐ)\n"),
+ MONEY("์"),
+ COUNT("๊ฐ"),
+ NONE("์์"),
+ PREVIEW("12์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!"),
+ CHRISTMAS_DISCOUNT("ํฌ๋ฆฌ์ค๋ง์ค ํ ์ธ: -"),
+ WEEKDAY_DISCOUNT("ํ์ผ ํ ์ธ: -"),
+ WEEKEND_DISCOUNT("์ฃผ๋ง ํ ์ธ: -"),
+ SPECIAL_DISCOUNT("ํน๋ณ ํ ์ธ: -"),
+ SERVICE_DISCOUNT("์ฆ์ ์ด๋ฒคํธ: -"),
+ BENEFIT_ALL_DISCOUNT("<์ดํํ ๊ธ์ก>"),
+ AFTER_BENEFIT_DISCOUNT("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ BADGE_DISCOUNT("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>"),
+ SERVICE_MENU("์ดํ์ธ 1๊ฐ");
+
+
+ private final String message;
+
+ PrintMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String getMessage(int day) {
+ return String.format(message, day);
+ }
+} | Java | ์! ๊น๋จน๊ณ ์์๋ค์. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,15 @@
+package christmas.controller;
+
+import christmas.domain.Order;
+import christmas.domain.Reservation;
+import christmas.domain.Result;
+
+public class EventPlannerController {
+ public static void run() {
+ Reservation reservation = ReservationController.inputReservation();
+ Order order = OrderController.inputOrder();
+ Result result = ResultController.createResult(order, reservation);
+ ResultController.printResult(result);
+
+ }
+} | Java | ์ด๋ค ์ด์ ๋ก static ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์
จ์๊น์?
static๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ํธ๋ฆฌํ ์ ์๋๋ฐ ๋ค๋ฅธ ์ฌ์ด๋ ์ดํํธ๊ฐ ์์๊น์? |
@@ -0,0 +1,20 @@
+package christmas.controller;
+
+import christmas.domain.Order;
+import christmas.domain.Reservation;
+import christmas.domain.Result;
+import christmas.view.OutputView;
+
+public class ResultController {
+
+ public static Result createResult(Order order, Reservation reservation) {
+ OutputView.printIntroduce(reservation.getDate());
+ OutputView.printOrder(order);
+ System.out.println();
+ return Result.from(order.getOrderedItems(), reservation.getDate());
+ }
+
+ public static void printResult(Result result) {
+ OutputView.printAllEvents(result);
+ }
+} | Java | ์ฌ๋ฌ ์ปจํธ๋กค๋ฌ ํด๋์ค๋ฅผ ๋ถ๋ฆฌํ์ ์ด์ ๊ฐ ๋ฌด์์ธ๊ฐ์? |
@@ -0,0 +1,50 @@
+package christmas.domain;
+
+public enum Calendar {
+ WEEKEND(1, 2, 8, 9, 15, 16, 22, 23, 29, 30),
+ WEEKDAY(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31),
+ SPECIAL_DAY(3, 10, 17, 24, 25, 31);
+
+ private final int[] days;
+
+ Calendar(int... days) {
+ this.days = days;
+ }
+
+ public int[] getDays() {
+ return days;
+ }
+
+ public static boolean isWeekday(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekday : calendar.getDays()) {
+ if (weekday == date && calendar == WEEKDAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isWeekend(int date) {
+ for (Calendar calendar : values()) {
+ for (int weekend : calendar.getDays()) {
+ if (weekend == date && calendar == WEEKEND) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isSpecialDay(int date) {
+ for (Calendar calendar : values()) {
+ for (int specialDay : calendar.getDays()) {
+ if (specialDay == date && calendar == SPECIAL_DAY) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+} | Java | calendar๋ผ๋ enum์ด 2023๋
12์์ ๋ ์ง๋ง ์์ผ๋ ์กฐ๊ธ ์ด์ํ ๊ฒ ๊ฐ์์ ํด๋์ค ๋ช
์ ์ข ๋ ๋ช
ํํ๊ฒ ํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,29 @@
+package christmas.domain;
+
+public enum EventBadge {
+ SANTA(20000, "์ฐํ"),
+ TREE(10000, "ํธ๋ฆฌ"),
+ STAR(5000, "๋ณ"),
+ NONE(0, "์์");
+
+ private final int threshold;
+ private final String description;
+
+ EventBadge(int threshold, String description) {
+ this.threshold = threshold;
+ this.description = description;
+ }
+
+ public static EventBadge getBadge(int totalAfterBenefit) {
+ for (EventBadge badge : values()) {
+ if (totalAfterBenefit >= badge.threshold) {
+ return badge;
+ }
+ }
+ return EventBadge.NONE;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+} | Java | ์ด๊ฒ๋ ์คํธ๋ฆผ์ผ๋ก ํด๊ฒฐํ ์ ์๊ฒ ๋ค์
ํด๋ํฐ์ผ๋ก ํ๋ ๊ฒ์ด๋ผ ์ฝ๋์น๊ธฐ๊ฐ ๋ถํธํด์ ์คํธ๋ฆผ, filter, findAny, orElseGet ์ ์ฌ์ฉํ๋ฉด ๋ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,37 @@
+package christmas.domain;
+
+import java.util.Arrays;
+
+public enum Menu {
+ ์์ก์ด์ํ(6_000), ํํ์ค(5_500), ์์ ์๋ฌ๋(8_000),
+ ํฐ๋ณธ์คํ
์ดํฌ(55_000), ๋ฐ๋นํ๋ฆฝ(54_000), ํด์ฐ๋ฌผํ์คํ(35_000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25_000),
+ ์ด์ฝ์ผ์ดํฌ(15_000), ์์ด์คํฌ๋ฆผ(5_000),
+ ์ ๋ก์ฝ๋ผ(3_000), ๋ ๋์์ธ(60_000), ์ดํ์ธ(25_000);
+
+ private final int price;
+
+ Menu(int price) {
+ this.price = price;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public boolean isBeverage() {
+ return this == ์ ๋ก์ฝ๋ผ || this == ๋ ๋์์ธ || this == ์ดํ์ธ;
+ }
+
+ public boolean isDessert() {
+ return this == ์ด์ฝ์ผ์ดํฌ || this == ์์ด์คํฌ๋ฆผ;
+ }
+
+ public boolean isMain() {
+ return this == ํฐ๋ณธ์คํ
์ดํฌ || this == ๋ฐ๋นํ๋ฆฝ || this == ํด์ฐ๋ฌผํ์คํ || this == ํฌ๋ฆฌ์ค๋ง์คํ์คํ;
+ }
+
+ public static boolean contains(String itemName) {
+ return Arrays.stream(Menu.values())
+ .anyMatch(menu -> menu.name().equalsIgnoreCase(itemName));
+ }
+} | Java | ์ฌ๊ธฐ๋ง ๋ณ์๋ช
์ ํ๊ธ๋ก ํ์ ์ด์ ๊ฐ ์๋์? ์ ๋ ํ๊ธ ๋ณ์๊ฐ ๊ฐ๋
์ฑ์ด ์ข๋ค๊ณ ์๊ฐํ์ง๋ง ์๋์์ฑ์์ ๋ถํธํ๋๋ผ๊ณ ์
๊ทธ๋ฆฌ๊ณ ์๋์ is~~~ ๋ฉ์๋๊ฐ ๋ง์๋ฐ ๋ฉ๋ด์ ๊ฐ๊ฒฉ๊ณผ ํ์
๋ ๊ฐ์ด ๊ฐ์ง๊ณ ์๋ค๋ฉด ์ข ๋ ๊น๋ํ๊ฒ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์ ๊ฒ ๊ฐ๋ค์ |
@@ -0,0 +1,25 @@
+package christmas.domain;
+
+import christmas.validator.Validator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Order {
+
+ private Map<Menu, Integer> orderedItems;
+
+ private Order(Map<Menu, Integer> orderedItems ) {
+ this.orderedItems = orderedItems;
+ }
+
+ public static Order from(Map<Menu, Integer> orderMap) {
+// Map<Menu, Integer> orderMap = parseOrder(order);
+ return new Order(orderMap);
+ }
+
+ public Map<Menu, Integer> getOrderedItems() {
+ return orderedItems;
+ }
+} | Java | ์ ๊ฐ์ ๋ฉ์๋๊ฐ ๋๊ฐ์ผ๊น์? |
@@ -0,0 +1,20 @@
+package christmas.domain;
+
+import christmas.validator.Validator;
+
+public class Reservation {
+ private final int date;
+
+ private Reservation(int date) {
+ Validator.isInRange(date);
+ this.date = date;
+ }
+
+ public static Reservation from(int date) {
+ return new Reservation(date);
+ }
+
+ public int getDate() {
+ return date;
+ }
+} | Java | ์ฌ๊ธฐ๋ ๊ทธ๋ ๋ค์ ์ด๋ค ์ด์ ๋ก ์์ฑ์๋ฅผ private์ผ๋ก ๋ง์๋์๊ณ static ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์
จ์๊น์ |
@@ -0,0 +1,171 @@
+package christmas.domain;
+
+import static christmas.domain.DiscountType.*;
+
+import java.util.Map;
+
+public class Result {
+
+ private int totalBeforeDiscount;
+ private int serviceMenu;
+ private int dDayDiscount;
+ private int weekdayDiscount;
+ private int weekendDiscount;
+ private int specialDiscount;
+ private int totalBenefit;
+ private int totalAfterBenefit;
+ private String badge = EventBadge.NONE.getDescription();
+
+ private Map<Menu, Integer> orderedItems;
+ private int date;
+
+ private Result(Map<Menu, Integer> orderedItems, int date) {
+ this.orderedItems = orderedItems;
+ this.date = date;
+ calculateTotalBeforeDiscount(); // ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก
+ checkEventExecutionConditions();
+ calculateETCEvents();
+ }
+
+ private void calculateETCEvents() {
+ calculateTotalAfterBenefit();
+ calculateEventBadge();
+ }
+
+ private void checkEventExecutionConditions() {
+ if (totalBeforeDiscount >= MIN_EVENT_CONDITION.getType()) {
+ calculateAllEvents();
+ }
+ }
+
+ private void calculateAllEvents() {
+ calculateServiceMenu(); // ์ฆ์ ๋ฉ๋ด
+ calculateBenefit();
+ calculateWeekday();
+ calculateWeekend();
+ calculateSpecialDay();
+ calculateAllBenefit();
+ }
+
+ public static Result from(Map<Menu, Integer> orderedItems, int date) {
+ return new Result(orderedItems, date);
+ }
+
+ public void calculateTotalBeforeDiscount() {
+ for (Map.Entry<Menu, Integer> entry : orderedItems.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+ int menuPrice = menu.getPrice();
+ int subtotal = menuPrice * quantity;
+
+ totalBeforeDiscount += subtotal;
+ }
+ }
+
+ public void calculateServiceMenu() {
+ if (totalBeforeDiscount >= CHAMPAGNE_CONDITION.getType()) {
+ serviceMenu = SERVICE_MENU_CONDITION.getType();
+ }
+ }
+
+ public void calculateBenefit() {
+ if (date <= DDAY_CONDITION.getType()) {
+ dDayDiscount = BASE_AMOUNT.getType() + (date * DAY_BONUS.getType());
+ }
+ }
+
+ public void calculateWeekday() {
+ if (Calendar.isWeekday(date)) {
+ int totalDessertCount = INIT_COUNT.getType(); // ๋์ ํธ ์นดํ
๊ณ ๋ฆฌ์ ์ด ๊ฐ์
+
+ for (Map.Entry<Menu, Integer> entry : orderedItems.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ // ๋์ ํธ ์นดํ
๊ณ ๋ฆฌ์ธ ๊ฒฝ์ฐ ๊ฐ์ ํฉ์ฐ
+ if (menu.isDessert()) {
+ totalDessertCount += quantity;
+ }
+ }
+ weekdayDiscount = totalDessertCount * SPECIALDAY_CONDITION.getType();
+ }
+ }
+
+ public void calculateWeekend() {
+ if (Calendar.isWeekend(date)) {
+ int totalMainCount = INIT_COUNT.getType();
+
+ for (Map.Entry<Menu, Integer> entry : orderedItems.entrySet()) {
+ Menu menu = entry.getKey();
+ int quantity = entry.getValue();
+
+ // ๋ฉ์ธ ์๋ฆฌ์ธ ๊ฒฝ์ฐ ๊ฐ์ ํฉ์ฐ
+ if (menu.isMain()) {
+ totalMainCount += quantity;
+ }
+ }
+ weekendDiscount = totalMainCount * SPECIALDAY_CONDITION.getType();
+ }
+ }
+
+ public void calculateSpecialDay() {
+ if (Calendar.isSpecialDay(date)) {
+ specialDiscount = SPECIAL_DISCOUNT.getType();
+ }
+ }
+
+ public void calculateAllBenefit() {
+ totalBenefit = dDayDiscount + weekdayDiscount + weekendDiscount + specialDiscount + (serviceMenu * CHAMPAGNE.getType());
+ }
+
+ public void calculateTotalAfterBenefit() {
+ totalAfterBenefit = totalBeforeDiscount - (totalBenefit - (serviceMenu * CHAMPAGNE.getType()));
+ }
+
+ public void calculateEventBadge() {
+ EventBadge badge = EventBadge.getBadge(totalBenefit);
+ if (badge != null) {
+ this.badge = badge.getDescription();
+ }
+ }
+
+ public int getTotalBeforeDiscount() {
+ return totalBeforeDiscount;
+ }
+
+ public int getServiceMenu() {
+ return serviceMenu;
+ }
+
+ public int getdDayDiscount() {
+ return dDayDiscount;
+ }
+
+ public int getWeekdayDiscount() {
+ return weekdayDiscount;
+ }
+
+ public int getWeekendDiscount() {
+ return weekendDiscount;
+ }
+
+ public int getSpecialDiscount() {
+ return specialDiscount;
+ }
+
+ public int getTotalBenefit() {
+ return totalBenefit;
+ }
+
+ public int getTotalAfterBenefit() {
+ return totalAfterBenefit;
+ }
+
+ public String getBadge() {
+ return badge;
+ }
+
+ public int getDate() {
+ return date;
+ }
+} | Java | ํ ๊ฐ์ฒด์ ๋๋ฌด ๋ง์ ํ๋๋ฅผ ์ ์ธํ๋๋ฐ ์ฑ
์์ ๋ถ๋ฆฌํ ์ ์์ง ์์๊น์? |
@@ -0,0 +1,150 @@
+package christmas.validator;
+
+import christmas.domain.Menu;
+import christmas.exception.ErrorMessage;
+import christmas.exception.ValidatorException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Validator {
+ private static final String DELIMITER = ",";
+ private static final int FIRST_DAY = 1;
+ private static final int LAST_DAY = 31;
+ private static final int MAX_MENU_COUNT = 20;
+ private static final int MIN_MUST_COUNT = 1;
+ private static final int TRUE = 1;
+ private static final int FALSE = 0;
+ public static int convertDateStringToInt(String input) {
+ try {
+ isNumeric(input);
+ return Integer.parseInt(input);
+ } catch (NumberFormatException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_DATE, exception);
+ }
+ }
+
+ public static int convertOrderStringToInt(String input) {
+ try {
+ isNumeric(input);
+ return Integer.parseInt(input);
+ } catch (NumberFormatException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+ private static boolean isNumeric(String input) {
+ return input.matches("\\d+");
+ }
+
+ public static void isInRange(int date) {
+ if (date < FIRST_DAY || date > LAST_DAY) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ public static boolean isValidOrderFormat(String order) {
+ try {
+ String regex = "([\\w๊ฐ-ํฃ]+-\\d+,)*[\\w๊ฐ-ํฃ]+-\\d+";
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(order);
+ return matcher.matches();
+ } catch (IllegalArgumentException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+
+ public static Map<Menu, Integer> parseOrder(String order) {
+ try {
+ Map<Menu, Integer> orderMap = new HashMap<>();
+ Set<Menu> uniqueMenus = new HashSet<>();
+ String[] items = order.split(",");
+ int count = 0;
+ int beverageFlag = FALSE;
+ for (String item : items) {
+ String[] parts = item.split("-");
+ validateNonNumericString(parts[0]); // ์ฒ์ ๋ค์ด์จ ๊ฐ์ด ์ซ์๋ฉด ์๋ฌ
+ Menu menu = getMenuByName(parts[0]);
+ if (!menu.isBeverage()) {
+ beverageFlag = TRUE;
+ }
+ isDuplicate(uniqueMenus, menu);
+ if (parts.length == 2) {
+ int quantity = convertOrderStringToInt(parts[1]);
+ isMinCount(quantity);
+ count += quantity;
+ orderMap.put(menu, quantity);
+ }
+ }
+ isOnlyBeverageOrder(beverageFlag);
+ isMaxCount(count);
+ return orderMap;
+ } catch (IllegalArgumentException exception) {
+ throw ValidatorException.of(ErrorMessage.INVALID_ORDER, exception);
+ }
+ }
+
+ private static void isOnlyBeverageOrder(int beverageFlag) {
+ if (beverageFlag == FALSE) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isDuplicate(Set<Menu> uniqueMenus, Menu menu) {
+ if (!uniqueMenus.add(menu)) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isMinCount(int quantity) {
+ if (quantity < MIN_MUST_COUNT) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void isMaxCount(int count) {
+ if (count > MAX_MENU_COUNT) {
+ throw ValidatorException.from(ErrorMessage.INVALID_ORDER);
+ }
+ }
+
+ public static void validateNonNumericString(String input) {
+ if (isNumeric(input)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ public static Menu getMenuByName(String menuName) {
+ for (Menu menu : Menu.values()) {
+ if (menu.name().equalsIgnoreCase(menuName)) {
+ return menu;
+ }
+ }
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+
+
+ public static void validateContainWhiteSpace(String input) {
+ if (hasWhiteSpace(input)) {
+ throw ValidatorException.from(ErrorMessage.CONTAIN_WHITESPACE);
+ }
+ }
+
+ public static void validateEndsWithDelimiter(String input) {
+ if (isEndsWithDelimiter(input)) {
+ throw ValidatorException.from(ErrorMessage.ENDS_WITH_DELIMITER);
+ }
+ }
+
+ private static boolean hasWhiteSpace(String input) {
+ return input.chars().anyMatch(Character::isWhitespace);
+ }
+
+ private static boolean isEndsWithDelimiter(String input) {
+ return input.endsWith(DELIMITER);
+ }
+} | Java | validator๋ผ๋ static ๋ฉ์๋๋ง ๊ฐ์ง๊ณ ์๋ ํด๋์ค๋ฅผ ๋ง๋์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค |
@@ -0,0 +1,87 @@
+package christmas.domain;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+class CalendarTest {
+
+ @DisplayName("ํ์ผ์ ํด๋นํ๋ ๋ ์ง๋ฅผ ์
๋ ฅํ์ ๋ ๊ฒ์ฆ")
+ @Test
+ public void testIsWeekday() {
+ // Given
+ int weekday = 5;
+
+ // When
+ boolean result = Calendar.isWeekday(weekday);
+
+ // Then
+ assertTrue(result, "ํ์ผ์ด ๋ง์");
+ }
+
+ @DisplayName("ํ์ผ์ ํด๋นํ์ง ์๋ ๋ ์ง๋ฅผ ์
๋ ฅํ์ ๋ ๊ฒ์ฆ")
+ @Test
+ public void testIsNotWeekday() {
+ // Given
+ int weekday = 9;
+
+ // When
+ boolean result = Calendar.isWeekday(weekday);
+
+ // Then
+ assertFalse(result, "ํ์ผ์ด ์๋");
+ }
+
+ @DisplayName("์ฃผ๋ง์ ํด๋นํ๋ ๋ ์ง๋ฅผ ์
๋ ฅํ์ ๋ ๊ฒ์ฆ")
+ @Test
+ public void testIsWeekend() {
+ // Given
+ int weekend = 9;
+
+ // When
+ boolean result = Calendar.isWeekend(weekend);
+
+ // Then
+ assertTrue(result, "์ฃผ๋ง์ด ๋ง์");
+ }
+
+ @DisplayName("์ฃผ๋ง์ ํด๋นํ์ง ์๋ ๋ ์ง๋ฅผ ์
๋ ฅํ์ ๋ ๊ฒ์ฆ")
+ @Test
+ public void testIsNotWeekend() {
+ // Given
+ int weekend = 3;
+
+ // When
+ boolean result = Calendar.isWeekend(weekend);
+
+ // Then
+ assertFalse(result, "์ฃผ๋ง์ด ์๋");
+ }
+
+ @DisplayName("ํน๋ณํ ๋ ์ ํด๋นํ๋ ๋ ์ง๋ฅผ ์
๋ ฅํ์ ๋ ๊ฒ์ฆ")
+ @Test
+ public void testIsSpecialDay() {
+ // Given
+ int specialDay = 25;
+
+ // When
+ boolean result = Calendar.isSpecialDay(specialDay);
+
+ // Then
+ assertTrue(result, "ํน๋ณํ ๋ ");
+ }
+
+ @DisplayName("ํน๋ณํ ๋ ์ ํด๋นํ์ง ์๋ ๋ ์ง๋ฅผ ์
๋ ฅํ์ ๋ ๊ฒ์ฆ")
+ @Test
+ public void testIsNotSpecialDay() {
+ // Given
+ int specialDay = 19;
+
+ // When
+ boolean result = Calendar.isSpecialDay(specialDay);
+
+ // Then
+ assertFalse(result, "ํน๋ณํ ๋ ");
+ }
+}
\ No newline at end of file | Java | assertJ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค |
@@ -0,0 +1,88 @@
+package christmas.domain;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+class MenuTest {
+
+ @DisplayName("์์ก์ด ์ํ ๊ฐ๊ฒฉ ๋์ผํ์ง ๊ฒ์ฆ")
+ @Test
+ public void testGetPrice() {
+ // Given
+ Menu menu = Menu.์์ก์ด์ํ;
+
+ // When
+ int price = menu.getPrice();
+
+ // Then
+ assertEquals(6_000, price, "์์ก์ด์ํ์ ๊ฐ๊ฒฉ์ด ๊ฐ์");
+ }
+
+ @DisplayName("์๋ฃ์ธ์ง ๊ฒ์ฆ")
+ @Test
+ public void testIsBeverage() {
+ // Given
+ Menu cola = Menu.์ ๋ก์ฝ๋ผ;
+ Menu wine = Menu.๋ ๋์์ธ;
+ Menu champagne = Menu.์ดํ์ธ;
+ Menu pasta = Menu.ํฌ๋ฆฌ์ค๋ง์คํ์คํ;
+
+ // Then
+ assertTrue(cola.isBeverage(), "์ ๋ก์ฝ๋ผ๋ ์๋ฃ์");
+ assertTrue(wine.isBeverage(), "๋ ๋์์ธ์ ์๋ฃ์");
+ assertTrue(champagne.isBeverage(), "์ดํ์ธ์ ์๋ฃ์");
+ assertFalse(pasta.isBeverage(), "ํฌ๋ฆฌ์ค๋ง์คํ์คํ๋ ์๋ฃ์๊ฐ ์๋");
+ }
+
+ @DisplayName("๋์ ํธ์ธ์ง ๊ฒ์ฆ")
+ @Test
+ public void testIsDessert() {
+ // Given
+ Menu cake = Menu.์ด์ฝ์ผ์ดํฌ;
+ Menu iceCream = Menu.์์ด์คํฌ๋ฆผ;
+ Menu pasta = Menu.ํฌ๋ฆฌ์ค๋ง์คํ์คํ;
+
+ // Then
+ assertTrue(cake.isDessert(), "์ด์ฝ์ผ์ดํฌ๋ ๋์ ํธ");
+ assertTrue(iceCream.isDessert(), "์์ด์คํฌ๋ฆผ์ ๋์ ํธ");
+ assertFalse(pasta.isDessert(), "ํฌ๋ฆฌ์ค๋ง์คํ์คํ๋ ๋์ ํธ๊ฐ ์๋");
+ }
+
+ @DisplayName("๋ฉ์ธ์๋ฆฌ์ธ์ง ๊ฒ์ฆ")
+ @Test
+ public void testIsMain() {
+ // Given
+ Menu steak = Menu.ํฐ๋ณธ์คํ
์ดํฌ;
+ Menu ribs = Menu.๋ฐ๋นํ๋ฆฝ;
+ Menu pasta = Menu.ํฌ๋ฆฌ์ค๋ง์คํ์คํ;
+ Menu soup = Menu.์์ก์ด์ํ;
+
+ // Then
+ assertTrue(steak.isMain(), "ํฐ๋ณธ์คํ
์ดํฌ๋ ๋ฉ์ธ์๋ฆฌ");
+ assertTrue(ribs.isMain(), "๋ฐ๋นํ๋ฆฝ์ ๋ฉ์ธ์๋ฆฌ");
+ assertTrue(pasta.isMain(), "ํฌ๋ฆฌ์ค๋ง์คํ์คํ๋ ๋ฉ์ธ์๋ฆฌ");
+ assertFalse(soup.isMain(), "์์ก์ด์ํ๋ ๋ฉ์ธ์๋ฆฌ๊ฐ ์๋");
+ }
+
+ @DisplayName("์ฃผ๋ฌธ ๋ฉ๋ด๊ฐ ๋ฉ๋ด์ ํฌํจ๋์ด ์๋์ง ๊ฒ์ฆ")
+ @Test
+ public void testContains_ValidItem() {
+ // Given
+ String itemName = "์์ด์คํฌ๋ฆผ";
+
+ // Then
+ assertTrue(Menu.contains(itemName), "๋ฉ๋ด์ ์์ด์คํฌ๋ฆผ์ด ์์ด์ผ ํจ");
+ }
+
+ @DisplayName("์ฃผ๋ฌธ ๋ฉ๋ด๊ฐ ๋ฉ๋ด์ ํฌํจ๋์ด ์์ง ์์์ง ๊ฒ์ฆ")
+ @Test
+ public void testContains_InvalidItem() {
+ // Given
+ String itemName = "ํผ์";
+
+ // Then
+ assertFalse(Menu.contains(itemName), "๋ฉ๋ด์ ํผ์๊ฐ ์์ด์ผ ํจ");
+ }
+}
\ No newline at end of file | Java | softAssertion์ด๋ assertAll์ ๋ํด ์์๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,241 @@
+# ๋ฏธ์
- ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
๐
+
+## โ
ย ๊ธฐ๋ฅ ๋ชฉ๋ก
+
+### 1. ๊ฒ์ ์์
+
+- [X] ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์
๋ ฅ ๋ฐ๋๋ค.
+ - [X] ๋ฐฉ๋ฌธํ ๋ ์ง๋ 1 ์ด์ 31 ์ดํ์ ์ซ์๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+ - [X] ์๋ชป๋ ๊ฐ์ ์
๋ ฅํ ๊ฒฝ์ฐ ์์ธ ์ฒ๋ฆฌํ๋ค.
+
+- [X] ๊ณ ๊ฐ์๊ฒ ์๋ดํ ์ด๋ฒคํธ ์ฃผ์ ์ฌํญ์ ์ถ๋ ฅํ๋ค.
+
+- [X] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋๋ค.
+ - [X] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅ ์ ์์ธ ์ฒ๋ฆฌํ๋ค.
+ - [X] ๋ฉ๋ด์ ๊ฐ์๋ 1 ์ด์์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ ์์ธ ์ฒ๋ฆฌํ๋ค.
+ - [X] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์๋ค.
+ - [X] ์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์ฃผ๋ฌธํ ์ ์๋ค.
+ - [X] ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ ์์ธ ์ฒ๋ฆฌํ๋ค.
+ - [X] ์ด ์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์์ด ์๋ ๊ฒฝ์ฐ ์ด๋ฒคํธ๋ฅผ ์ ์ฉํ์ง ์๋๋ค.
+
+### 2. ๊ฒ์ ์งํ
+
+- [X] ์์ ๋ฐฉ๋ฌธ ๋ ์ง, ๋ฉ๋ด, ๊ฐ์๋ฅผ ๊ณ์ฐํ๊ณ ๋ค์ ์ด๋ฒคํธ๋ฅผ ๊ฒ์ฌํ๋ค.
+ - [X] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - [X] ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ)
+ - [X] ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ)
+ - [X] ํน๋ณ ํ ์ธ
+ - [X] ์ฆ์ ์ด๋ฒคํธ
+ - [X] ์ด๋ฒคํธ ๊ธฐ๊ฐ
+
+- [X] ํํ ๊ธ์ก์ ๋ฐ๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง ๋ถ์ฌ
+ - [X] 5์ฒ ์ ์ด์: ๋ณ
+ - [X] 1๋ง ์ ์ด์: ํธ๋ฆฌ
+ - [X] 2๋ง ์ ์ด์: ์ฐํ
+
+### 3. ๊ฒ์ ์ข
๋ฃ
+
+- [X] ์๋น์ ๋ฐฉ๋ฌธํ ๋ ์ง์ ๋ฉ๋ด๋ฅผ ๋ฏธ๋ฆฌ ์ ํํ๋ฉด ์ด๋ฒคํธ ํ๋๋๊ฐ ์๋์ ํญ๋ชฉ๋ค์ ์ถ๋ ฅํ๋ค.
+ - [X] ์ฃผ๋ฌธ ๋ฉ๋ด
+ - [X] ์ฃผ๋ฌธ ๋ฉ๋ด์ ์ถ๋ ฅ ์์๋ ์์ ๋กญ๊ฒ ์ถ๋ ฅํ๋ค.
+ - [X] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก
+ - [X] ์ฆ์ ๋ฉ๋ด
+ - [X] ์ฆ์ ์ด๋ฒคํธ์ ํด๋นํ์ง ์๋ ๊ฒฝ์ฐ, ์ฆ์ ๋ฉ๋ด โ์์โ์ผ๋ก ์ถ๋ ฅํ๋ค.
+ - [X] ํํ ๋ด์ญ
+ - [X] ๊ณ ๊ฐ์๊ฒ ์ ์ฉ๋ ์ด๋ฒคํธ ๋ด์ญ๋ง ์ถ๋ ฅํ๋ค.
+ - [X] ์ ์ฉ๋ ์ด๋ฒคํธ๊ฐ ํ๋๋ ์๋ค๋ฉด ํํ ๋ด์ญ โ์์โ์ผ๋ก ์ถ๋ ฅํ๋ค.
+ - [X] ์ฌ๋ฌ ๊ฐ์ ์ด๋ฒคํธ๊ฐ ์ ์ฉ๋ ๊ฒฝ์ฐ, ์ถ๋ ฅ ์์๋ ์์ ๋กญ๊ฒ ์ถ๋ ฅํ๋ค.
+ - [X] ์ดํํ ๊ธ์ก
+ - [X] ์ดํํ ๊ธ์ก์ ๋ฐ๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง์ ์ด๋ฆ์ ๋ค๋ฅด๊ฒ ์ถ๋ ฅํ๋ค.
+ - [X] ์ดํํ ๊ธ์ก = ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ
+ - [X] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก
+ - [X] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก = ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก - ํ ์ธ ๊ธ์ก
+ - [X] ์ฆ์ ์ด๋ฒคํธ์ ํฌํจ๋ ๊ธ์ก์ ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์ ํฌํจ์ํค์ง ์๋๋ค.
+ - [X] 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ๋ด์ฉ
+ - [X] ์ด๋ฒคํธ ๋ฐฐ์ง๊ฐ ๋ถ์ฌ๋์ง ์๋ ๊ฒฝ์ฐ, โ์์โ์ผ๋ก ์ถ๋ ฅํ๋ค.
+
+### 4. ์์ธ
+
+- ์ฌ์ฉ์๊ฐ ์๋ชป๋ ๊ฐ์ ์
๋ ฅํ ๊ฒฝ์ฐย `IllegalArgumentException`๋ฅผ ๋ฐ์์ํค๊ณ , "[ERROR]"๋ก ์์ํ๋ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅ ํ **๊ทธ ๋ถ๋ถ๋ถํฐ ์
๋ ฅ์ ๋ค์ ๋ฐ๋๋ค.**
+ - `Exception`์ด ์๋ย `IllegalArgumentException`,ย `IllegalStateException`ย ๋ฑ๊ณผ ๊ฐ์ ๋ช
ํํ ์ ํ์ ์ฒ๋ฆฌํ๋ค.
+ - ์์ธ ์ํฉ ์ ์๋ฌ ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํด์ผ ํ๋ค. ๋จ, ์๋ฌ ๋ฌธ๊ตฌ๋ "[ERROR]"๋ก ์์ํด์ผ ํ๋ค.
+
+### 5. ๋ชฉํ (ํผ๋๋ฐฑ)
+
+- ํด๋์ค(๊ฐ์ฒด)๋ฅผ ๋ถ๋ฆฌํ๋ค.
+- ๋๋ฉ์ธ ๋ก์ง์ ๋ํ ๋จ์ ํ
์คํธ๋ฅผ ์์ฑํ๋ค.
+- ๋ฐ์ํ ์ ์๋ ์์ธ ์ํฉ์ ๋ํด ๊ณ ๋ฏผํ๋ค.
+- ๋น์ฆ๋์ค ๋ก์ง๊ณผ UI ๋ก์ง์ ๋ถ๋ฆฌํ๋ค.
+- ์ฐ๊ด์ฑ์ด ์๋ ์์๋ static final ๋์ enum์ ํ์ฉํ๋ค.
+- final ํค์๋๋ฅผ ์ฌ์ฉํด ๊ฐ์ ๋ณ๊ฒฝ์ ๋ง๋๋ค.
+- ๊ฐ์ฒด์ ์ํ ์ ๊ทผ์ ์ ํํ๋ค.
+- ๊ฐ์ฒด๋ ๊ฐ์ฒด์ค๋ฝ๊ฒ ์ฌ์ฉํ๋ค.
+- ํ๋(์ธ์คํด์ค ๋ณ์)์ ์๋ฅผ ์ค์ด๊ธฐ ์ํด ๋
ธ๋ ฅํ๋ค.
+- ์ฑ๊ณตํ๋ ์ผ์ด์ค ๋ฟ๋ง ์๋๋ผ ์์ธ์ ๋ํ ์ผ์ด์ค๋ ํ
์คํธํ๋ค.
+- ํ
์คํธ ์ฝ๋๋ ์ฝ๋์ด๋ฏ๋ก ๋ฆฌํฉํฐ๋ง์ ํตํด ๊ฐ์ ํด ๋๊ฐ๋ค.
+- ํ
์คํธ๋ฅผ ์ํ ์ฝ๋๋ ๊ตฌํ ์ฝ๋์์ ๋ถ๋ฆฌ๋์ด์ผ ํ๋ค. ์๋์ ์์์ฒ๋ผ ํ
์คํธ๋ฅผ ํต๊ณผํ๊ธฐ ์ํด ๊ตฌํ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋ ํ
์คํธ์์๋ง ์ฌ์ฉ๋๋ ๋ก์ง์ ๋ง๋ค์ง ์๋๋ค.
+ - ํ
์คํธ๋ฅผ ์ํด ์ ๊ทผ ์ ์ด์๋ฅผ ๋ฐ๊พธ๋ ๊ฒฝ์ฐ
+ - ํ
์คํธ ์ฝ๋์์๋ง ์ฌ์ฉ๋๋ ๋ฉ์๋
+- ๋จ์ ํ
์คํธํ๊ธฐ ์ด๋ ค์ด ์ฝ๋๋ฅผ ๋จ์ ํ
์คํธํ๊น
+- private ํจ์๋ฅผ ํ
์คํธ ํ๊ณ ์ถ๋ค๋ฉด ํด๋์ค(๊ฐ์ฒด) ๋ถ๋ฆฌ๋ฅผ ๊ณ ๋ คํ๋ค.
+### 6. 3์ฃผ ์ฐจ ๋ฏธ์
(๋ก๋ ๊ฒ์ ๐) ์ฝ๋ ๋ฆฌ๋ทฐ๋ฅผ ํตํด ๊ฐ์ ํ ์
+
+- ์ง๋ ๋ฏธ์
์์ ๊ฐ์ ํ ํ์๊ฐ ์๋ ๋ฆฌ๋ทฐ๋ฅผ ์ ๋ฆฌํ์ฌ ์ด๋ฒ ๋ฏธ์
์์ ๊ณ ๋ฏผํ๋ฉฐ ๊ฐ์ ํ๋ ค๊ณ ๋
ธ๋ ฅํ์ต๋๋ค.
+
+<table>
+ <tr>
+ <th align="center">Type</th>
+ <th align="center">Review</th>
+ <th align="center">Reviewer</th>
+ </tr>
+ <tr><td colspan="3"></td></tr>
+ <tr>
+ <td rowspan="15"><b>โ๏ธ ์ฝ๋ ๋ฆฌ๋ทฐ</b></td>
+ <td>01. ํ์ํ ๋ก์ง์๋ง ์์ธ ์ฒ๋ฆฌ๋ฅผ ํ๋๋ก ํ์.</td>
+ <td><b>@wns312</b></td>
+ </tr>
+ <tr>
+ <td>02. ํด๋์ค๊ฐ ๋๋ฌด ๋ง์ ์์๋ฅผ ๊ฐ์ง๋ฉด ๊ฐ๋
์ฑ์ด ๋จ์ด์ง๊ธฐ ๋๋ฌธ์ ๋ณ๋์ ํด๋์ค๋ enum์ผ๋ก ๋ถ๋ฆฌํด๋ณด์.</td>
+ <td><b>@gywns0417</b></td>
+ </tr>
+ <tr>
+ <td>03. ํ ๋ฉ์๋๊ฐ ํ๋์ ์ญํ ์ ๊ฐ์ง๋๋ก ๋ณ๋์ ํด๋์ค๋ ๋ฉ์๋๋ก ์ฑ
์์ ๋ถ๋ฆฌํ์.</td>
+ <td><b>@gywns0417</b></td>
+ </tr>
+ <tr>
+ <td>04. ๋ณ๊ฒฝ๋ ์ ์๋ ์ ๋ณด๋ ์์๋ enum์ผ๋ก ๊ด๋ฆฌํ๊ณ , ํด๋น ๋ฉ์์ง์์ ๊ฐ๋ค์ ์ฐธ์กฐํ๋ ๋ฐฉํฅ์ผ๋ก ๊ฐ์ ํ์.</td>
+ <td><b>@gywns0417</b></td>
+ </tr>
+ <tr>
+ <td>05. View๊ฐ Model์ ๋๋ฌด ์์กดํ๊ฒ ํ์ง ๋ง๊ณ , ์จ์ ํ View์ ์ญํ ๋ง ํ๊ฒ ํ๋๋ก ๊ณ ๋ คํ์.</td>
+ <td><b>@twkwon0417 @youngsu5582</b></td>
+ </tr>
+ <tr>
+ <td>06. [ERROR]์ ํด๋นํ๋ prefix ๋ถ๋ถ์ ์์๋ก ์ ์ธํ๊ณ , getMessage() ํ ๋ PREFIX + message ํ๋ ์์ผ๋ก ์ฌ์ฉํด๋ณด์.</td>
+ <td><b>@youngsu5582</b></td>
+ </tr>
+ <tr>
+ <td>07. ๋ณ๊ฒฝ ๊ฐ๋ฅ์ฑ์ด ์๋ ๋ณ์์ ๋ํด์ ํ์ฅ์ฑ์ ๋ํด ์ข ๋ ๊ณ ๋ฏผํด ๋ณด์.</td>
+ <td><b>@youngsu5582 @OiKimiO</b></td>
+ </tr>
+ <tr>
+ <td>08. ์ค๋ฅ ๋ฐ์์ ํด๋น ๋ถ๋ถ์์ ๋ค์ ์
๋ ฅ ๋ฐ์ ์ ์๋๋ก ์ ๊ฒฝ์ฐ์.</td>
+ <td><b>@guswlsdl0121</b></td>
+ </tr>
+ <tr>
+ <td>09. ์ ์ ๋ฉ์๋๋ฅผ ํ์ฉํ์ฌ ๊ฐ์ฒด ์์กด์ฑ์ ์ค์ฌ๋ณด์.</td>
+ <td><b>@OiKimiO</b></td>
+ </tr>
+ <tr>
+ <td>10. String matches๋ฅผ ๋ฉ์๋ ๋ด๋ถ์์ ์ฌ์ฉํ๋ ๊ฒ ๋ณด๋ค๋ Pattern.matches๋ฅผ static final๋ก ๊ด๋ฆฌํ๋ ๊ฒ์ด ์ฑ๋ฅ์ ์ด์ ์ด ์์ผ๋ ํ์ฉํด๋ณด์.</td>
+ <td><b>@OiKimiO</b></td>
+ </tr>
+ <tr>
+ <td>11. ํฌ๋ฉํ
์ ํ์ฉํ์ฌ ์ฒ๋ฆฌํด๋ณด์.</td>
+ <td><b>@Seol-JY</b></td>
+ </tr>
+ <tr>
+ <td>12. stream์ ํ์ฉํ๋ฉด ์ค๋ณต์ ์ ๊ฑฐํ ๋ ๊ฒฐ๊ณผ๊ฐ์ ๋ฐ๋ก ๋ฐ์ ์ ์๋ค.</td>
+ <td><b>@YejiGong</b></td>
+ </tr>
+ <tr>
+ <td>13. ๋งค์ง ๋๋ฒ๋ฅผ ์์๋ก ์ ์ธํ๋ ๊ฒ์ ์ข์ผ๋ ZERO๋ FIVE๊ฐ์ ์ง์ ์ ์ธ ๋ณ์๋ช
๋ณด๋ค๋ ํด๋น ๊ฐ์ ์๋ฏธ๋ฅผ ์๋ ค์ฃผ๋ ๋ณ์๋ช
์ผ๋ก ์ง์ด๋ณด์.</td>
+ <td><b>@YejiGong</b></td>
+ </tr>
+</table>
+
+### 7. ํจํค์ง ๊ตฌ์กฐ
+- ์๋ ํ
์ด๋ธ ํ์์ <b>@h-beeen</b>๋์ README๋ฅผ ์ฐธ๊ณ ํ์ต๋๋ค.
+## ๐ฆ ํจํค์ง ๊ตฌ์กฐ
+
+[//]: # (<img align="center" src="https://github.com/woowacourse-precourse/java-racingcar-6/assets/112257466/3ef9d8a2-d4bb-42a1-900f-754799cac3fd" height="32px"> FinalResponse</b>)
+
+<div align="center">
+<table>
+ <tr>
+ <th align="center">Package</th>
+ <th align="center">Class</th>
+ <th align="center">Description</th>
+ </tr>
+ <tr>
+ <td rowspan="4"><b><img align="center" src="https://github.com/woowacourse-precourse/java-racingcar-6/assets/112257466/2f32b4cd-187c-4b92-a136-2d86cd3341cd" width="20px"> controller</b></td>
+ <td><b><img align="center" height="32px"> EventPlannerController</b></td>
+ <td>์ด๋ฒคํธ ํ๋๋ ๋ก์ง์ ๋ฉ์ธ์ผ๋ก ๋์ํ๋ ์ปจํธ๋กค๋ฌ</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> OrderController</b></td>
+ <td>์ฃผ๋ฌธ์ ๋ฐ๋ ๋ก์ง์ ๋์ํ๋ ์ปจํธ๋กค๋ฌ</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> ReservationController</b></td>
+ <td>๋ฐฉ๋ฌธ ๋ ์ง ์์ฝ์ ๋ฐ๋ ๋ก์ง์ ๋์ํ๋ ์ปจํธ๋กค๋ฌ</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> ResultController</b></td>
+ <td>๋ฐฉ๋ฌธ ๋ ์ง์ ์ฃผ๋ฌธ์ ํ ๋๋ก ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๊ธฐ ์ํ ๋ก์ง์ ๋์ํ๋ ์ปจํธ๋กค๋ฌ</td>
+ </tr>
+ <tr><td colspan="3"></td></tr>
+ <tr>
+ <td rowspan="7"><img align="center" src="https://github.com/woowacourse-precourse/java-racingcar-6/assets/112257466/f16a8719-281f-4535-a958-c1c62d69cfa2" width="20px"> <b>domain<br></b></td>
+ <td><b><img align="center" height="32px"> Calendar</b></td>
+ <td>12์ ๋ฌ๋ ฅ์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ enum ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> DiscountType</b></td>
+ <td>ํ ์ธ ์ด๋ฒคํธ์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ enum ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> EventBadge</b></td>
+ <td>์ด๋ฒคํธ ๋ฐฐ์ง ๋ถ์ฌ์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ enum ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> Menu</b></td>
+ <td>์ฃผ๋ฌธ ๋ฉ๋ด์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ enum ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> Order</b></td>
+ <td>์ฃผ๋ฌธ์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> Reservation</b></td>
+ <td>์์ฝ ๋ ์ง์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> Result</b></td>
+ <td>์ด๋ฒคํธ ๊ฒฐ๊ณผ์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ ํด๋์ค</td>
+ </tr>
+ <tr><td colspan="3"></td></tr>
+ <tr>
+ <td rowspan="2"><img align="center" src="https://github.com/woowacourse-precourse/java-racingcar-6/assets/112257466/219d6ae0-19c4-4984-970d-ea244700b6a9" width="20px"> <b>exception</b></td>
+ <td><b><img align="center" height="32px"> ErrorMessage</b></td>
+ <td>์๋ฌ ๋ฉ์์ง์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ enum ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> ValidatorException</b></td>
+ <td>์๋ฌ ๋ฉ์์ง๋ฅผ ๊ด๋ฆฌํ๋ ํด๋์ค</td>
+ </tr>
+ <tr><td colspan="3"></td></tr>
+ <tr>
+ <td rowspan="1"><img align="center" src="https://github.com/woowacourse-precourse/java-racingcar-6/assets/112257466/219d6ae0-19c4-4984-970d-ea244700b6a9"width="20px"> <b>validator</b></td>
+ <td><b><img align="center" height="32px"> Validator</b></td>
+ <td>์ ๋ฐ์ ์ธ ๊ฒ์ฆ์ ๋ํ ๊ด๋ฆฌ๋ฅผ ํ๋ ํด๋์ค</td>
+ </tr>
+ <tr><td colspan="3"></td></tr>
+ <tr>
+ <td rowspan="3"><img align="center" src="https://github.com/woowacourse-precourse/java-racingcar-6/assets/112257466/219d6ae0-19c4-4984-970d-ea244700b6a9" width="20px"> <b>view</b></td>
+ <td><b><img align="center" height="32px"> PrintMessage</b></td>
+ <td>์
์ถ๋ ฅ์ ๊ดํ ๋ฉ์์ง ์์์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ๋ enum ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> InputView</b></td>
+ <td>์
๋ ฅ์ ๋ด๋นํ๋ View ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td><b><img align="center" height="32px"> OutputView</b></td>
+ <td>์ถ๋ ฅ์ ๋ด๋นํ๋ View ํด๋์ค</td>
+ </tr>
+
+</table>
+</div>
+
+
\ No newline at end of file | Unknown | ๊ฒ์์ด๋ผ๊ณ ํ์ ์ด์ ๊ฐ ๋ฐ๋ก ์์๊น์? |
@@ -0,0 +1,15 @@
+package christmas.controller;
+
+import christmas.domain.Order;
+import christmas.domain.Reservation;
+import christmas.domain.Result;
+
+public class EventPlannerController {
+ public static void run() {
+ Reservation reservation = ReservationController.inputReservation();
+ Order order = OrderController.inputOrder();
+ Result result = ResultController.createResult(order, reservation);
+ ResultController.printResult(result);
+
+ }
+} | Java | static ๋ฉ์๋๋ง ์๋ ํด๋์ค๋ผ๋ฉด ์ธ์คํด์ค๋ฅพ ๋ง๋ค ํ์๊ฐ ์์ํ
๋ฐ์, ์ด๋ฅผ ์ด๋ป๊ฒ ๋ฐฉ์งํ ์ ์์๊น์? |
@@ -0,0 +1,117 @@
+package christmas.view;
+
+import static christmas.view.messages.PrintMessage.*;
+
+import christmas.domain.Menu;
+import christmas.domain.Order;
+import christmas.domain.Result;
+import christmas.view.messages.PrintMessage;
+import java.util.Map;
+
+public class OutputView {
+ private static final int TRUE = 1;
+ private static final int FALSE = 0;
+ private static final int CHAMPAGNE = 25000;
+ public static void println(Object data) {
+ System.out.println(data);
+
+ }
+ public static void printMessage(final PrintMessage message) {
+ System.out.println(message.getMessage());
+ }
+
+ public static void printOrder(Order order) {
+ Map<Menu, Integer> orderedItems = order.getOrderedItems();
+ printMessage(OUTPUT_ORDER);
+ for (Map.Entry<Menu, Integer> entry : orderedItems.entrySet()) {
+ System.out.println(entry.getKey() + " " + entry.getValue() + COUNT.getMessage());
+ }
+ }
+
+ public static void printAllEvents(Result result) {
+ printTotalBeforeDiscount(result);
+ printServiceMenu(result);
+ printBenefit(result);
+ printWeekday(result);
+ printWeekend(result);
+ printSpecialDay(result);
+ printAllBenefit(result);
+ printTotalAfterBenefit(result);
+ printEventBadge(result);
+ }
+
+ public static void printIntroduce(int date) {
+ System.out.println(PREVIEW.getMessage(date));
+ System.out.println();
+ }
+
+ public static void printTotalBeforeDiscount(Result result) {
+ System.out.println(OUTPUT_TOTAL_BEFORE_DISCOUNT.getMessage());
+ System.out.println(result.getTotalBeforeDiscount() + "" + MONEY.getMessage());
+ System.out.println();
+ }
+
+
+ public static void printServiceMenu(Result result) {
+ System.out.println(OUTPUT_GIFT_MENU.getMessage());
+ if (result.getServiceMenu() == TRUE) {
+ System.out.println(SERVICE_MENU.getMessage());
+ }
+ if (result.getServiceMenu() == FALSE) {
+ System.out.println(NONE.getMessage());
+ }
+ System.out.println();
+ }
+
+ public static void printBenefit(Result result) {
+ System.out.println(OUTPUT_BENEFIT.getMessage());
+ if (result.getdDayDiscount() == FALSE) {
+ System.out.println(NONE.getMessage());
+ }
+ if (result.getdDayDiscount() != FALSE) {
+ System.out.println(CHRISTMAS_DISCOUNT.getMessage() + result.getdDayDiscount() + "" + MONEY.getMessage());
+ }
+ }
+
+ public static void printWeekday(Result result) {
+ if (result.getWeekdayDiscount() != FALSE) {
+ System.out.println(WEEKDAY_DISCOUNT.getMessage() + result.getWeekdayDiscount() + MONEY.getMessage());
+ }
+ }
+
+ public static void printWeekend(Result result) {
+ if (result.getWeekendDiscount() != FALSE) {
+ System.out.println(WEEKEND_DISCOUNT.getMessage() + result.getWeekendDiscount() + MONEY.getMessage());
+ }
+ }
+
+ public static void printSpecialDay(Result result) {
+ if (result.getServiceMenu() == TRUE) {
+ System.out.println(SPECIAL_DISCOUNT.getMessage() + result.getSpecialDiscount() + MONEY.getMessage());
+ System.out.println(SERVICE_DISCOUNT.getMessage() + CHAMPAGNE + MONEY.getMessage());
+ }
+ System.out.println();
+ }
+
+ public static void printAllBenefit(Result result) {
+ System.out.println(BENEFIT_ALL_DISCOUNT.getMessage());
+ if (result.getTotalBenefit() != FALSE) {
+ System.out.println("-" + result.getTotalBenefit() + MONEY.getMessage());
+ }
+ if (result.getTotalBenefit() == FALSE) {
+ System.out.println(result.getTotalBenefit() + MONEY.getMessage());
+ }
+ System.out.println();
+ }
+
+ public static void printTotalAfterBenefit(Result result) {
+ System.out.println(AFTER_BENEFIT_DISCOUNT.getMessage());
+ System.out.println(result.getTotalAfterBenefit() + MONEY.getMessage());
+ System.out.println();
+ }
+
+ public static void printEventBadge(Result result) {
+ System.out.println(BADGE_DISCOUNT.getMessage());
+ System.out.println(result.getBadge());
+ }
+} | Java | ๋ถํ์ํ ๊ฐํ์ ์ง์์ฃผ์ธ์..! |
@@ -1,6 +1,9 @@
package bridge;
+import bridge.domain.constant.MoveCommand;
import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
/**
* ๋ค๋ฆฌ์ ๊ธธ์ด๋ฅผ ์
๋ ฅ ๋ฐ์์ ๋ค๋ฆฌ๋ฅผ ์์ฑํด์ฃผ๋ ์ญํ ์ ํ๋ค.
@@ -18,6 +21,10 @@ public BridgeMaker(BridgeNumberGenerator bridgeNumberGenerator) {
* @return ์
๋ ฅ๋ฐ์ ๊ธธ์ด์ ํด๋นํ๋ ๋ค๋ฆฌ ๋ชจ์. ์ ์นธ์ด๋ฉด "U", ์๋ ์นธ์ด๋ฉด "D"๋ก ํํํด์ผ ํ๋ค.
*/
public List<String> makeBridge(int size) {
- return null;
+ return IntStream
+ .generate(bridgeNumberGenerator::generate)
+ .limit(size)
+ .mapToObj(MoveCommand::convertCommand)
+ .collect(Collectors.toList());
}
} | Java | ์ด ๋ถ๋ถ ๊ฐ์ฒด์งํฅ์ ์ผ๋ก ์ค๊ณ๋ฅผ ์ํ์
จ๋ค์!! ๊ฐ๋
์ฑ ์์ฃผ ๊ตฟ์
๋๋ค |
@@ -0,0 +1,95 @@
+package bridge.controller;
+
+import bridge.domain.model.Bridge;
+import bridge.domain.model.BridgeGame;
+import bridge.domain.constant.MoveCommand;
+import bridge.domain.constant.RetryCommand;
+import bridge.domain.constant.Status;
+import bridge.view.InputView;
+import bridge.view.OutputView;
+
+public class BridgeController {
+
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final BridgeGame bridgeGame;
+
+ public BridgeController() {
+ this.inputView = new InputView();
+ this.outputView = new OutputView();
+ this.bridgeGame = new BridgeGame();
+ }
+
+ public void crossBridge() {
+ outputView.printStartMessage();
+ Bridge bridge = createBridge();
+ startCrossingTheBridge(bridge);
+ }
+
+ private void startCrossingTheBridge(Bridge bridge) {
+ int count = 1;
+ Status status;
+ while (true) {
+ status = startGame(bridge);
+ if (status == Status.FAIL) {
+ if (restartGame() == RetryCommand.RETRY) {
+ count++;
+ continue;
+ }
+ }
+ break;
+ }
+ outputView.printResult(count, status, bridgeGame);
+ }
+
+ private RetryCommand restartGame() {
+ outputView.printRestart();
+ while (true) {
+ try {
+ String command = inputView.readGameCommand();
+ return RetryCommand.from(command);
+ } catch (IllegalArgumentException e) {
+ outputView.printError(e);
+ }
+ }
+ }
+
+ private Status startGame(Bridge bridge) {
+ Status status = Status.SUCCESS;
+ for (int idx = 0; idx < bridge.getSize(); idx++) {
+ MoveCommand moveCommand = getMoveCommand();
+ status = bridgeGame.move(idx, moveCommand, bridge);
+ outputView.printMap(bridgeGame);
+ if (bridgeGame.retry(status)) {
+ break;
+ }
+ }
+ return status;
+ }
+
+ private Bridge createBridge() {
+ outputView.printInputSize();
+ while (true) {
+ try {
+ int bridgeSize = inputView.readBridgeSize();
+ Bridge bridge = Bridge.createBridge(bridgeSize);
+ bridge.setBridge(bridgeSize);
+ return bridge;
+ } catch (IllegalArgumentException e) {
+ outputView.printError(e);
+ }
+ }
+ }
+
+ private MoveCommand getMoveCommand() {
+ outputView.printInputMoveCommand();
+ while (true) {
+ try {
+ String command = inputView.readMoving();
+ return MoveCommand.from(command);
+ } catch (IllegalArgumentException e) {
+ outputView.printError(e);
+ }
+ }
+ }
+} | Java | depth๊ฐ 3์ด๋ค์ ใ
ใ
ํจ์๋ฅผ ๋ถ๋ฆฌํ์
์ผํ ๊ฑฐ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,41 @@
+package bridge.domain.model;
+
+import bridge.domain.constant.MoveCommand;
+import bridge.domain.constant.Status;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class GameDashboard {
+
+ private final List<Status> upResult = new ArrayList<>();
+ private final List<Status> downResult = new ArrayList<>();
+
+ public void updateResult(Status status, MoveCommand moveCommand) {
+ if (status == Status.SUCCESS) {
+ checkResult(status, moveCommand);
+ }
+ if (status == Status.FAIL) {
+ checkResult(status, moveCommand);
+ }
+ }
+
+ private void checkResult(Status status, MoveCommand moveCommand) {
+ if (moveCommand == MoveCommand.UP) {
+ upResult.add(status);
+ downResult.add(Status.SPACE);
+ }
+ if (moveCommand == MoveCommand.DOWN) {
+ upResult.add(Status.SPACE);
+ downResult.add(status);
+ }
+ }
+
+ public List<Status> getUpResult() {
+ return Collections.unmodifiableList(upResult);
+ }
+
+ public List<Status> getDownResult() {
+ return Collections.unmodifiableList(downResult);
+ }
+} | Java | ์ด ๋ถ๋ถ ์ข๋ค์! ์ ๋ Map ์ ์ธ๋ถ๋ก ๋บ์ง ๋ง์ง ๊ณ ๋ฏผํ๋ค๊ฐ ์๋บ๋๋ฐ ๋บ ํ์ Player๊ฐ ๊ฐ์ง๊ณ ์๋ ๊ธฐ๋ฅ๋ค์ ์ฎ๊ฒจ์ฃผ๋๊ฒ ๋ ์ข์์๊ฑฐ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,95 @@
+package bridge.controller;
+
+import bridge.domain.model.Bridge;
+import bridge.domain.model.BridgeGame;
+import bridge.domain.constant.MoveCommand;
+import bridge.domain.constant.RetryCommand;
+import bridge.domain.constant.Status;
+import bridge.view.InputView;
+import bridge.view.OutputView;
+
+public class BridgeController {
+
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final BridgeGame bridgeGame;
+
+ public BridgeController() {
+ this.inputView = new InputView();
+ this.outputView = new OutputView();
+ this.bridgeGame = new BridgeGame();
+ }
+
+ public void crossBridge() {
+ outputView.printStartMessage();
+ Bridge bridge = createBridge();
+ startCrossingTheBridge(bridge);
+ }
+
+ private void startCrossingTheBridge(Bridge bridge) {
+ int count = 1;
+ Status status;
+ while (true) {
+ status = startGame(bridge);
+ if (status == Status.FAIL) {
+ if (restartGame() == RetryCommand.RETRY) {
+ count++;
+ continue;
+ }
+ }
+ break;
+ }
+ outputView.printResult(count, status, bridgeGame);
+ }
+
+ private RetryCommand restartGame() {
+ outputView.printRestart();
+ while (true) {
+ try {
+ String command = inputView.readGameCommand();
+ return RetryCommand.from(command);
+ } catch (IllegalArgumentException e) {
+ outputView.printError(e);
+ }
+ }
+ }
+
+ private Status startGame(Bridge bridge) {
+ Status status = Status.SUCCESS;
+ for (int idx = 0; idx < bridge.getSize(); idx++) {
+ MoveCommand moveCommand = getMoveCommand();
+ status = bridgeGame.move(idx, moveCommand, bridge);
+ outputView.printMap(bridgeGame);
+ if (bridgeGame.retry(status)) {
+ break;
+ }
+ }
+ return status;
+ }
+
+ private Bridge createBridge() {
+ outputView.printInputSize();
+ while (true) {
+ try {
+ int bridgeSize = inputView.readBridgeSize();
+ Bridge bridge = Bridge.createBridge(bridgeSize);
+ bridge.setBridge(bridgeSize);
+ return bridge;
+ } catch (IllegalArgumentException e) {
+ outputView.printError(e);
+ }
+ }
+ }
+
+ private MoveCommand getMoveCommand() {
+ outputView.printInputMoveCommand();
+ while (true) {
+ try {
+ String command = inputView.readMoving();
+ return MoveCommand.from(command);
+ } catch (IllegalArgumentException e) {
+ outputView.printError(e);
+ }
+ }
+ }
+} | Java | ์ด ๋ถ๋ถ์ BridgeGame์์ ์งํํ๋ ๋ฐฉ๋ฒ์ ์์์๊น์??? |
@@ -0,0 +1,64 @@
+package bridge.view;
+
+import static bridge.view.ViewMessage.*;
+
+import bridge.domain.model.BridgeGame;
+import bridge.domain.model.GameDashboard;
+import bridge.domain.constant.Status;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * ์ฌ์ฉ์์๊ฒ ๊ฒ์ ์งํ ์ํฉ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ ์ญํ ์ ํ๋ค.
+ */
+public class OutputView {
+
+ public void printError(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ public void printStartMessage() {
+ System.out.println(START_MESSAGE.getMessage());
+ }
+
+ public void printInputSize() {
+ System.out.println(INPUT_BRIDGE_SIZE_MESSAGE.getMessage());
+ }
+
+ public void printInputMoveCommand() {
+ System.out.println(INPUT_MOVE_COMMAND_MESSAGE.getMessage());
+ }
+
+ public void printRestart() {
+ System.out.println(INPUT_RETRY_COMMAND_MESSAGE.getMessage());
+ }
+
+ /**
+ * ํ์ฌ๊น์ง ์ด๋ํ ๋ค๋ฆฌ์ ์ํ๋ฅผ ์ ํด์ง ํ์์ ๋ง์ถฐ ์ถ๋ ฅํ๋ค.
+ * <p>
+ * ์ถ๋ ฅ์ ์ํด ํ์ํ ๋ฉ์๋์ ์ธ์(parameter)๋ ์์ ๋กญ๊ฒ ์ถ๊ฐํ๊ฑฐ๋ ๋ณ๊ฒฝํ ์ ์๋ค.
+ */
+ public void printMap(BridgeGame bridgeGame) {
+ GameDashboard dashboard = bridgeGame.getGameDashboard();
+ System.out.printf(RESULT_FORMAT.getMessage(), convertToString(dashboard.getUpResult()));
+ System.out.printf(RESULT_FORMAT.getMessage(), convertToString(dashboard.getDownResult()));
+ }
+
+ /**
+ * ๊ฒ์์ ์ต์ข
๊ฒฐ๊ณผ๋ฅผ ์ ํด์ง ํ์์ ๋ง์ถฐ ์ถ๋ ฅํ๋ค.
+ * <p>
+ * ์ถ๋ ฅ์ ์ํด ํ์ํ ๋ฉ์๋์ ์ธ์(parameter)๋ ์์ ๋กญ๊ฒ ์ถ๊ฐํ๊ฑฐ๋ ๋ณ๊ฒฝํ ์ ์๋ค.
+ */
+ public void printResult(int count, Status status, BridgeGame bridgeGame) {
+ System.out.println(RESULT_MESSAGE.getMessage());
+ printMap(bridgeGame);
+ System.out.printf(SUCCESS_OR_FAIL.getMessage(), status.getMessage());
+ System.out.printf(TOTAL_ATTEMPTS_COUNT.getMessage(), count);
+ }
+
+ private String convertToString(List<Status> result) {
+ List<String> convertResult = result.stream().map(Status::getStatus)
+ .collect(Collectors.toList());
+ return String.join(DELIMITER.getMessage(), convertResult);
+ }
+} | Java | ๋งค๊ฐ๊ฐ์ BridgeGame์ด ์๋ GameDashBoard๋ก ๋ฐ์์ผ๋ฉด ์ด๋ ์๊น์??? |
@@ -0,0 +1,23 @@
+package bridge.view;
+
+public enum ViewMessage {
+ START_MESSAGE("๋ค๋ฆฌ ๊ฑด๋๊ธฐ ๊ฒ์์ ์์ํฉ๋๋ค."),
+ INPUT_BRIDGE_SIZE_MESSAGE("๋ค๋ฆฌ์ ๊ธธ์ด๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."),
+ INPUT_MOVE_COMMAND_MESSAGE("์ด๋ํ ์นธ์ ์ ํํด์ฃผ์ธ์. (์: U, ์๋: D)"),
+ INPUT_RETRY_COMMAND_MESSAGE("๊ฒ์์ ๋ค์ ์๋ํ ์ง ์ฌ๋ถ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์. (์ฌ์๋: R, ์ข
๋ฃ: Q)"),
+ RESULT_MESSAGE("์ต์ข
๊ฒ์ ๊ฒฐ๊ณผ"),
+ SUCCESS_OR_FAIL("๊ฒ์ ์ฑ๊ณต ์ฌ๋ถ: %s%n"),
+ TOTAL_ATTEMPTS_COUNT("์ด ์๋ํ ํ์: %d%n"),
+ DELIMITER(" | "),
+ RESULT_FORMAT("[ %s ]%n");
+
+ private final String message;
+
+ ViewMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | StringJoiner ๋ฅผ ์ฐ๋ฉด ํด๋น ๋ถ๋ถ์ ํ๋ฒ์ ํด๊ฒฐํ ์ ์๋๋ผ๊ตฌ์! |
@@ -0,0 +1,18 @@
+const GATHERING_TYPE = ["DALLAEMFIT", "OFFICE_STRETCHING", "MINDFULNESS", "WORKATION"] as const;
+
+export type ScoresQuery = {
+ gatheringId?: number;
+ type?: (typeof GATHERING_TYPE)[number];
+};
+
+export type ScoresResponse = {
+ teamId: number;
+ gatheringId: number;
+ type?: (typeof GATHERING_TYPE)[number];
+ averageScore: number;
+ oneStar: number;
+ twoStars: number;
+ threeStars: number;
+ fourStars: number;
+ fiveStars: number;
+}; | TypeScript | _:warning: Potential issue_
**ScoresQuery์ type ํ๋ ํ์
์ด ์๋ชป ์ ์๋์ด ์์ต๋๋ค.**
ํ์ฌ `type?: typeof GATHERING_TYPE`๋ ๋ฐฐ์ด ํ์
์ ์๋ฏธํ๋ฉฐ, ์ด๋ ์๋ํ ํ์
์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ์์ ํ๋ ๊ฒ์ ์ ์๋๋ฆฝ๋๋ค:
```diff
export type ScoresQuery = {
gatheringId?: number;
- type?: typeof GATHERING_TYPE;
+ type?: (typeof GATHERING_TYPE)[number];
};
```
๋๋ ๋ ๋ช
์์ ์ผ๋ก:
```typescript
export const GATHERING_TYPE = {
DALLAEMFIT: "DALLAEMFIT",
OFFICE_STRETCHING: "OFFICE_STRETCHING",
MINDFULNESS: "MINDFULNESS",
WORKATION: "WORKATION",
} as const;
export type GatheringType = (typeof GATHERING_TYPE)[keyof typeof GATHERING_TYPE];
export type ScoresQuery = {
gatheringId?: number;
type?: GatheringType;
};
```
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -0,0 +1,18 @@
+const GATHERING_TYPE = ["DALLAEMFIT", "OFFICE_STRETCHING", "MINDFULNESS", "WORKATION"] as const;
+
+export type ScoresQuery = {
+ gatheringId?: number;
+ type?: (typeof GATHERING_TYPE)[number];
+};
+
+export type ScoresResponse = {
+ teamId: number;
+ gatheringId: number;
+ type?: (typeof GATHERING_TYPE)[number];
+ averageScore: number;
+ oneStar: number;
+ twoStars: number;
+ threeStars: number;
+ fourStars: number;
+ fiveStars: number;
+}; | TypeScript | _:warning: Potential issue_
**ScoresResponse์๋ ๋์ผํ ํ์
์ด์๊ฐ ์์ต๋๋ค.**
ScoresResponse์ type ํ๋๋ ๊ฐ์ ๋ฌธ์ ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ์์ ํด ์ฃผ์ธ์:
```diff
export type ScoresResponse = {
teamId: number;
gatheringId: number;
- type?: typeof GATHERING_TYPE;
+ type?: (typeof GATHERING_TYPE)[number];
averageScore: number;
oneStar: number;
twoStars: number;
threeStars: number;
fourStars: number;
fiveStars: number;
};
```
<!-- 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 type ScoresResponse = {
teamId: number;
gatheringId: number;
type?: (typeof GATHERING_TYPE)[number];
averageScore: number;
oneStar: number;
twoStars: number;
threeStars: number;
fourStars: number;
fiveStars: number;
};
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -0,0 +1,31 @@
+import { fetchReviewsScores } from "../_utils/api";
+import ScoreProgressBar from "./ScoreProgressBar";
+import Score from "@/components/Score";
+
+export default async function ReviewsAverage() {
+ const [scores] = await fetchReviewsScores();
+
+ const { averageScore, oneStar, twoStars, threeStars, fourStars, fiveStars } = scores;
+ const total = oneStar + twoStars + threeStars + fourStars + fiveStars;
+ const stars = [fiveStars, fourStars, threeStars, twoStars, oneStar];
+
+ return (
+ <div className="flex w-full max-w-[995px] justify-center border-y-2 border-gray-200 bg-white px-6 py-8">
+ <div className="flex w-full max-w-[610px] justify-between">
+ <div className="flex flex-col items-center justify-center gap-2 pr-5">
+ <div className="flex items-center justify-center text-xl font-semibold md:text-2xl">
+ <span>{averageScore}</span>
+ <span className="text-gray-400">/5</span>
+ </div>
+ <Score score={averageScore} />
+ </div>
+
+ <div className="flex max-w-[302px] flex-1 flex-col gap-1">
+ {stars.map((count, index) => (
+ <ScoreProgressBar key={index} score={5 - index} stars={count} total={total} />
+ ))}
+ </div>
+ </div>
+ </div>
+ );
+} | Unknown | _:warning: Potential issue_
**map ํจ์์ key prop์ด ํ์ํฉ๋๋ค.**
React ๋ฐฐ์ด ๋ ๋๋ง ์ ๊ฐ ์์๋ฅผ ์๋ณํ๊ธฐ ์ํ key prop์ด ๋๋ฝ๋์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ์์ ํ๋ ๊ฒ์ ์ ์๋๋ฆฝ๋๋ค:
```diff
{stars.map((count, index) => (
- <ScoreProgressBar score={5 - index} stars={count} total={total} />
+ <ScoreProgressBar
+ key={5 - index}
+ score={5 - index}
+ stars={count}
+ total={total}
+ />
))}
```
<!-- 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
{stars.map((count, index) => (
<ScoreProgressBar
key={5 - index}
score={5 - index}
stars={count}
total={total}
/>
))}
`````
</details>
<!-- suggestion_end -->
<details>
<summary>๐งฐ Tools</summary>
<details>
<summary>๐ช Biome (1.9.4)</summary>
[error] 25-25: Missing key property for this element in iterable.
The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.
(lint/correctness/useJsxKeyInIterable)
</details>
</details>
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -0,0 +1,31 @@
+import { fetchReviewsScores } from "../_utils/api";
+import ScoreProgressBar from "./ScoreProgressBar";
+import Score from "@/components/Score";
+
+export default async function ReviewsAverage() {
+ const [scores] = await fetchReviewsScores();
+
+ const { averageScore, oneStar, twoStars, threeStars, fourStars, fiveStars } = scores;
+ const total = oneStar + twoStars + threeStars + fourStars + fiveStars;
+ const stars = [fiveStars, fourStars, threeStars, twoStars, oneStar];
+
+ return (
+ <div className="flex w-full max-w-[995px] justify-center border-y-2 border-gray-200 bg-white px-6 py-8">
+ <div className="flex w-full max-w-[610px] justify-between">
+ <div className="flex flex-col items-center justify-center gap-2 pr-5">
+ <div className="flex items-center justify-center text-xl font-semibold md:text-2xl">
+ <span>{averageScore}</span>
+ <span className="text-gray-400">/5</span>
+ </div>
+ <Score score={averageScore} />
+ </div>
+
+ <div className="flex max-w-[302px] flex-1 flex-col gap-1">
+ {stars.map((count, index) => (
+ <ScoreProgressBar key={index} score={5 - index} stars={count} total={total} />
+ ))}
+ </div>
+ </div>
+ </div>
+ );
+} | Unknown | _:warning: Potential issue_
**๋ฐ์ดํฐ ๋ก๋ฉ ๋ฐ ์๋ฌ ์ํ ์ฒ๋ฆฌ๊ฐ ํ์ํฉ๋๋ค.**
๋น๋๊ธฐ ๋ฐ์ดํฐ ํ์นญ ์ ๋ฐ์ํ ์ ์๋ ์๋ฌ์ ๋ก๋ฉ ์ํ์ ๋ํ ์ฒ๋ฆฌ๊ฐ ๋๋ฝ๋์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ ์ ์๋๋ฆฝ๋๋ค:
```diff
export default async function ReviewsAverage() {
- const [scores] = await fetchReviewsScores();
+ try {
+ const [scores] = await fetchReviewsScores();
+ } catch (error) {
+ console.error('๋ฆฌ๋ทฐ ์ ์๋ฅผ ๋ถ๋ฌ์ค๋๋ฐ ์คํจํ์ต๋๋ค:', error);
+ return <div>๋ฆฌ๋ทฐ ์ ์๋ฅผ ๋ถ๋ฌ์ค๋๋ฐ ์คํจํ์ต๋๋ค. ๋ค์ ์๋ํด ์ฃผ์ธ์.</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
export default async function ReviewsAverage() {
try {
const [scores] = await fetchReviewsScores();
} catch (error) {
console.error('๋ฆฌ๋ทฐ ์ ์๋ฅผ ๋ถ๋ฌ์ค๋๋ฐ ์คํจํ์ต๋๋ค:', error);
return <div>๋ฆฌ๋ทฐ ์ ์๋ฅผ ๋ถ๋ฌ์ค๋๋ฐ ์คํจํ์ต๋๋ค. ๋ค์ ์๋ํด ์ฃผ์ธ์.</div>;
}
// ... rest of the component logic
}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -0,0 +1,18 @@
+const GATHERING_TYPE = ["DALLAEMFIT", "OFFICE_STRETCHING", "MINDFULNESS", "WORKATION"] as const;
+
+export type ScoresQuery = {
+ gatheringId?: number;
+ type?: (typeof GATHERING_TYPE)[number];
+};
+
+export type ScoresResponse = {
+ teamId: number;
+ gatheringId: number;
+ type?: (typeof GATHERING_TYPE)[number];
+ averageScore: number;
+ oneStar: number;
+ twoStars: number;
+ threeStars: number;
+ fourStars: number;
+ fiveStars: number;
+}; | TypeScript | ์ฝ๋๋๋น ๋ง๋๋ก type์ด (typeof GATHERING_TYPE)[number]; ๊ฐ ๋์ด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,31 @@
+import { fetchReviewsScores } from "../_utils/api";
+import ScoreProgressBar from "./ScoreProgressBar";
+import Score from "@/components/Score";
+
+export default async function ReviewsAverage() {
+ const [scores] = await fetchReviewsScores();
+
+ const { averageScore, oneStar, twoStars, threeStars, fourStars, fiveStars } = scores;
+ const total = oneStar + twoStars + threeStars + fourStars + fiveStars;
+ const stars = [fiveStars, fourStars, threeStars, twoStars, oneStar];
+
+ return (
+ <div className="flex w-full max-w-[995px] justify-center border-y-2 border-gray-200 bg-white px-6 py-8">
+ <div className="flex w-full max-w-[610px] justify-between">
+ <div className="flex flex-col items-center justify-center gap-2 pr-5">
+ <div className="flex items-center justify-center text-xl font-semibold md:text-2xl">
+ <span>{averageScore}</span>
+ <span className="text-gray-400">/5</span>
+ </div>
+ <Score score={averageScore} />
+ </div>
+
+ <div className="flex max-w-[302px] flex-1 flex-col gap-1">
+ {stars.map((count, index) => (
+ <ScoreProgressBar key={index} score={5 - index} stars={count} total={total} />
+ ))}
+ </div>
+ </div>
+ </div>
+ );
+} | Unknown | ์ฌ๊ธฐ key prop์ด ํ์ํ ๊ฒ ๊ฐ์ต๋๋ค... ๊ทผ๋ฐ ์ฝ๋๋๋น์ด ์ด๋ฏธ ๋ฆฌ๋ทฐํด์คฌ๋ค์ |
@@ -0,0 +1,141 @@
+package com.fourseason.delivery.domain.review.service;
+
+import com.fourseason.delivery.domain.order.entity.Order;
+import com.fourseason.delivery.domain.order.entity.OrderStatus;
+import com.fourseason.delivery.domain.order.repository.OrderRepository;
+import com.fourseason.delivery.domain.review.dto.request.ReviewRequestDto;
+import com.fourseason.delivery.domain.review.dto.response.ReviewResponseDto;
+import com.fourseason.delivery.domain.review.entity.Review;
+import com.fourseason.delivery.domain.review.entity.ReviewImage;
+import com.fourseason.delivery.domain.review.exception.ReviewErrorCode;
+import com.fourseason.delivery.domain.review.repository.ReviewImageRepository;
+import com.fourseason.delivery.domain.review.repository.ReviewRepository;
+import com.fourseason.delivery.domain.shop.entity.Shop;
+import com.fourseason.delivery.domain.shop.repository.ShopRepository;
+import com.fourseason.delivery.global.exception.CustomException;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+@Service
+@RequiredArgsConstructor
+public class ReviewService {
+
+ private final ReviewRepository reviewRepository;
+ private final ReviewImageRepository reviewImageRepository;
+ private final OrderRepository orderRepository;
+ private final ShopRepository shopRepository;
+ private final ReviewImageService imageUploadService;
+
+ @Transactional
+ public void createReview(String orderId, ReviewRequestDto reviewRequestDto) {
+ // 1) Order ์กฐํ
+ Order order = orderRepository.findById(UUID.fromString(orderId))
+ .orElseThrow(() -> new CustomException(ReviewErrorCode.ORDER_NOT_FOUND));
+
+ // 2) ์ฃผ๋ฌธ์ํ ํ์ธ
+ if(order.getOrderStatus() != OrderStatus.COMPLETED) {
+ throw new CustomException(ReviewErrorCode.ORDER_NOT_COMPLETED);
+ }
+
+ // 3) Review ์ ์ฅ
+ Review review = Review.addOf(reviewRequestDto, order);
+ reviewRepository.save(review);
+
+ // 4) ์ด๋ฏธ์ง ์
๋ก๋, ReviewImage ์ ์ฅ
+ if(reviewRequestDto.images() != null && !reviewRequestDto.images().isEmpty()) {
+ for(MultipartFile image : reviewRequestDto.images()) {
+ String imageUrl = imageUploadService.uploadImage(image);
+ ReviewImage reviewImage = ReviewImage.of(review, imageUrl);
+ reviewImageRepository.save(reviewImage);
+ }
+ }
+ }
+
+ @Transactional(readOnly = true)
+ public ReviewResponseDto getReview(String orderId, String reviewId) {
+ // 1) ๋ฆฌ๋ทฐ ์กฐํ
+ Review review = reviewRepository.findByIdAndOrderId(UUID.fromString(reviewId), UUID.fromString(orderId))
+ .orElseThrow(() -> new CustomException(ReviewErrorCode.REVIEW_NOT_FOUND));
+
+ // 2) ๋ฆฌ๋ทฐ ์ด๋ฏธ์ง ๋ฆฌ์คํธ ์กฐํ
+ List<ReviewImage> reviewImages = reviewImageRepository.findByReviewId(UUID.fromString(reviewId));
+
+ return ReviewResponseDto.of(review, reviewImages);
+ }
+
+ @Transactional
+ public ReviewResponseDto updateReview(String orderId, String reviewId, ReviewRequestDto reviewRequestDto) {
+ // 1) ๋ฆฌ๋ทฐ ์กฐํ ๋ฐ ๋ฆฌ๋ทฐ ๋ด์ฉ, ํ์ ์
๋ฐ์ดํธ
+ Review review = reviewRepository.findByIdAndOrderId(UUID.fromString(reviewId), UUID.fromString(orderId))
+ .orElseThrow(() -> new CustomException(ReviewErrorCode.REVIEW_NOT_FOUND));
+
+ review.updateOf(reviewRequestDto);
+
+ // 2) ์๋ก์ด ์ด๋ฏธ์ง๊ฐ ์์ ๊ฒฝ์ฐ ๊ธฐ์กด ์ด๋ฏธ์ง ์ญ์
+ List<ReviewImage> existingImages = reviewImageRepository.findByReviewId(UUID.fromString(reviewId));
+ if(!existingImages.isEmpty()) {
+ for(ReviewImage image : existingImages) {
+ reviewImageRepository.delete(image);
+ }
+ }
+
+ // 3) ์๋ก์ด ์ด๋ฏธ์ง ์ถ๊ฐ
+ List<ReviewImage> images = new ArrayList<>();
+ if(reviewRequestDto.images() != null && !reviewRequestDto.images().isEmpty()) {
+ for(MultipartFile image : reviewRequestDto.images()) {
+ String imageUrl = imageUploadService.uploadImage(image);
+ ReviewImage reviewImage = ReviewImage.of(review, imageUrl);
+ images.add(reviewImage);
+ reviewImageRepository.save(reviewImage);
+ }
+ }
+
+ return ReviewResponseDto.of(review, images);
+ }
+
+ @Transactional
+ public void deleteReview(String orderId, String reviewId) {
+ Review review = reviewRepository.findByIdAndOrderId(UUID.fromString(reviewId), UUID.fromString(orderId))
+ .orElseThrow(() -> new CustomException(ReviewErrorCode.REVIEW_NOT_FOUND));
+
+ List<ReviewImage> existingImages = reviewImageRepository.findByReviewId(UUID.fromString(reviewId));
+ if(!existingImages.isEmpty()) {
+ for(ReviewImage image : existingImages) {
+ reviewImageRepository.delete(image);
+ }
+ }
+
+ reviewRepository.delete(review);
+ }
+
+
+ public List<ReviewResponseDto> getReviewList(String shopId) {
+ Shop shop = shopRepository.findById(UUID.fromString(shopId))
+ .orElseThrow(() -> new CustomException(ReviewErrorCode.SHOP_NOT_FOUND));
+
+ List<Review> reviews = reviewRepository.findByShop(shop);
+ List<ReviewImage> images = reviewImageRepository.findByReviewId(UUID.fromString(shopId));
+
+ // ๊ฐ ๋ฆฌ๋ทฐ๋ง๋ค ํด๋นํ๋ ์ด๋ฏธ์ง ์ฐพ์์ ReviewResponseDto์ ๋ฃ๊ธฐ
+ List<ReviewResponseDto> responseList = new ArrayList<>();
+ for(Review review : reviews) {
+ List<ReviewImage> imagesForReview = new ArrayList<>();
+ for(ReviewImage image : images) {
+ if(review.equals(image.getReview())) {
+ imagesForReview.add(image);
+ }
+ }
+
+ responseList.add(ReviewResponseDto.of(review, imagesForReview));
+ }
+
+ return responseList;
+ }
+} | Java | collect(Collectors.toList()) ๋ณด๋ค๋ Stream.toList()๋ฅผ ์ ์ฉํ๋ ๊ฒ์ด ์ด๋จ๊น์?
toList()๋ฅผ ์ฌ์ฉํ๋ฉด UnmodifiableList ๋ฅผ ๋ฐํํด List ์ ๋ํ ๋ณ๊ฒฝ์ด ๋ถ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ์ ์ค๊ฐ์ ์์ ๋ ์ํ์ ์ค์ผ ์ ์์๊ฑฐ ๊ฐ์์! |
@@ -0,0 +1,19 @@
+package com.fourseason.delivery.domain.review.dto.request;
+
+
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.PositiveOrZero;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+
+public record ReviewRequestDto(
+ String content,
+
+ @NotNull(message = "ํ์ ์ ํ์ ์
๋ ฅ ๊ฐ์
๋๋ค.")
+ @PositiveOrZero(message = "ํ์ ์ 0 ์ด์์ด์ด์ผ ํฉ๋๋ค.")
+ int rating,
+
+ List<MultipartFile> images
+) {
+} | Java | dto์ ๊ฒฝ์ฐ record๋ก ์์ฑํ๊ธฐ๋ก ํ๋๊ฑธ๋ก ๊ธฐ์ตํฉ๋๋น. |
@@ -0,0 +1,17 @@
+package com.fourseason.delivery.domain.review.repository;
+
+import com.fourseason.delivery.domain.order.entity.Order;
+import com.fourseason.delivery.domain.review.entity.Review;
+import com.fourseason.delivery.domain.shop.entity.Shop;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+
+public interface ReviewRepository extends JpaRepository<Review, UUID> {
+ Optional<Review> findByIdAndOrderId(UUID reviewId, UUID orderId);
+
+ List<Review> findByShop(Shop shop);
+
+} | Java | ๋ฐ์ดํฐ๋ค์ ์ค์ ๋ก ์ญ์ ํ์ง ์๊ณ ๋
ผ๋ฆฌ์ ์ญ์ ์ฒ๋ฆฌ ํ๊ธฐ๋ก ํ๋ ๋ถ๋ถ์ด๋ผ
findByIdAndDeletedAtIsNotNull ๊ณผ ๊ฐ์ ํํ๋ก ์กฐํํด์ฃผ์
์ผ...
์ ๋ ์ด ๋ถ๋ถ ์ฒ์์ ๊น๋จน์์ต๋๋ค. |
@@ -0,0 +1,62 @@
+package com.fourseason.delivery.domain.review.controller;
+
+import com.fourseason.delivery.domain.review.dto.request.ReviewRequestDto;
+import com.fourseason.delivery.domain.review.dto.response.ReviewResponseDto;
+import com.fourseason.delivery.domain.review.service.ReviewService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/orders/{order_id}/reviews")
+@RequiredArgsConstructor
+public class ReviewController {
+
+ private final ReviewService reviewService;
+
+ /**
+ * ๋ฆฌ๋ทฐ ๋ฑ๋ก
+ */
+ @PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
+ public ResponseEntity<Void> createReview(@PathVariable String orderId,
+ @RequestPart("review") ReviewRequestDto reviewRequestDto) {
+ reviewService.createReview(orderId, reviewRequestDto);
+ return ResponseEntity.ok().build();
+ }
+
+
+ /**
+ * ํน์ ๋ฆฌ๋ทฐ ์กฐํ
+ */
+ @GetMapping("/{review_id}")
+ public ResponseEntity<ReviewResponseDto> getReview(@PathVariable String orderId,
+ @PathVariable String reviewId) {
+ return ResponseEntity.ok(reviewService.getReview(orderId, reviewId));
+ }
+
+ /**
+ * ๋ฆฌ๋ทฐ ์์
+ */
+ @PostMapping("/{review_id}")
+ public ResponseEntity<ReviewResponseDto> updateReview(@PathVariable String orderId,
+ @PathVariable String reviewId,
+ @RequestBody ReviewRequestDto reviewRequestDto) {
+ return ResponseEntity.ok(reviewService.updateReview(orderId, reviewId, reviewRequestDto));
+ }
+
+
+ /**
+ * ๋ฆฌ๋ทฐ ์ญ์
+ */
+ @DeleteMapping("/{review_id}")
+ public ResponseEntity<Void> deleteReview(@PathVariable String orderId,
+ @PathVariable String reviewId) {
+ reviewService.deleteReview(orderId, reviewId);
+ return ResponseEntity.ok().build();
+ }
+
+} | Java | `String order_id` ๋ ์์ง `Order`๋ฅผ ํธ์ ์ํ๊ธฐ ๋๋ฌธ์ `UUID` ํ์
์ผ๋ก ๋ฐ๊พธ์ง ์์ผ์ ๊ฑธ๊น์? |
@@ -0,0 +1,62 @@
+package com.fourseason.delivery.domain.review.controller;
+
+import com.fourseason.delivery.domain.review.dto.request.ReviewRequestDto;
+import com.fourseason.delivery.domain.review.dto.response.ReviewResponseDto;
+import com.fourseason.delivery.domain.review.service.ReviewService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/orders/{order_id}/reviews")
+@RequiredArgsConstructor
+public class ReviewController {
+
+ private final ReviewService reviewService;
+
+ /**
+ * ๋ฆฌ๋ทฐ ๋ฑ๋ก
+ */
+ @PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
+ public ResponseEntity<Void> createReview(@PathVariable String orderId,
+ @RequestPart("review") ReviewRequestDto reviewRequestDto) {
+ reviewService.createReview(orderId, reviewRequestDto);
+ return ResponseEntity.ok().build();
+ }
+
+
+ /**
+ * ํน์ ๋ฆฌ๋ทฐ ์กฐํ
+ */
+ @GetMapping("/{review_id}")
+ public ResponseEntity<ReviewResponseDto> getReview(@PathVariable String orderId,
+ @PathVariable String reviewId) {
+ return ResponseEntity.ok(reviewService.getReview(orderId, reviewId));
+ }
+
+ /**
+ * ๋ฆฌ๋ทฐ ์์
+ */
+ @PostMapping("/{review_id}")
+ public ResponseEntity<ReviewResponseDto> updateReview(@PathVariable String orderId,
+ @PathVariable String reviewId,
+ @RequestBody ReviewRequestDto reviewRequestDto) {
+ return ResponseEntity.ok(reviewService.updateReview(orderId, reviewId, reviewRequestDto));
+ }
+
+
+ /**
+ * ๋ฆฌ๋ทฐ ์ญ์
+ */
+ @DeleteMapping("/{review_id}")
+ public ResponseEntity<Void> deleteReview(@PathVariable String orderId,
+ @PathVariable String reviewId) {
+ reviewService.deleteReview(orderId, reviewId);
+ return ResponseEntity.ok().build();
+ }
+
+} | Java | ์ด ๋ถ๋ถ์ ์ ํํ ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง, `reviewId` ์ฒ๋ผ ์นด๋ฉ์ผ์ด์ค๋ก ์์ฑ๋๋ ๊ฒ์ด ๋ ์ข์ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ค์ด์.
๊ทธ๋ ๊ฒ ์๊ฐํ๋ ์ด์ ๋ `@PathVariable` ์์๋ `String review_id` ์ ๊ฐ์ด ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ด์์. |
@@ -0,0 +1,28 @@
+package com.fourseason.delivery.domain.review.controller;
+
+import com.fourseason.delivery.domain.review.dto.response.ReviewResponseDto;
+import com.fourseason.delivery.domain.review.repository.ReviewRepository;
+import com.fourseason.delivery.domain.review.service.ReviewService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController
+@RequiredArgsConstructor
+public class ShopReviewController {
+
+ private final ReviewRepository reviewRepository;
+ private final ReviewService reviewService;
+
+ /**
+ * ํน์ ๊ฐ๊ฒ ๋ฆฌ๋ทฐ ๋ฆฌ์คํธ ์กฐํ
+ */
+ @GetMapping("/api/shops/{shop_id}/reviews")
+ public ResponseEntity<List<ReviewResponseDto>> getReviewList(@PathVariable String shopId) {
+ return ResponseEntity.ok(reviewService.getReviewList(shopId));
+ }
+} | Java | `/api/shops` ๋ถ๋ถ์ ๊ณตํต์ผ๋ก ํด๋ ๋ ๊ฒ ๊ฐ์์!
์๋๋ฉด, `ShopController`์ ๊ฒน์น๊ธฐ ๋๋ฌธ์ผ๊น์? |
@@ -0,0 +1,17 @@
+package com.fourseason.delivery.domain.review.repository;
+
+import com.fourseason.delivery.domain.order.entity.Order;
+import com.fourseason.delivery.domain.review.entity.Review;
+import com.fourseason.delivery.domain.shop.entity.Shop;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+
+public interface ReviewRepository extends JpaRepository<Review, UUID> {
+ Optional<Review> findByIdAndOrderId(UUID reviewId, UUID orderId);
+
+ List<Review> findByShop(Shop shop);
+
+} | Java | ์ํํธ ๋๋ฆฌํธ์ ๋ํด ์ฐพ์๋ณด๋๊น JPA์์ `@SQLDelte` ๋ `@Where`๋ฅผ ์ํฐํฐ ํด๋์ค์ ๋ถ์์ผ๋ก์จ, ์ฝ๊ฒ ๊ตฌํํ ์ ์๋ ๊ฒ ๊ฐ์์. ๊ฐ์ด ๋
ผ์ํด๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ชจ๋ ์ญ์ ์ฟผ๋ฆฌ๋ฉ์๋๋ฅผ update๋ก ํ๊ฑฐ๋, ์กฐํ ์ `DeleteAtIsNotNull` ์ ์ ๋ฏธ์ฌ๋ก ๋ถ์ธ๋ค๋ฉด, ๋์ค์ ์ ์ฑ
์ด ๋ฐ๋์์ ๋, ์ฝ๋ ์์ ์ด ๋ฒ๊ฑฐ๋ก์ธ ๊ฒ ๊ฐ์์.
์ด๋ ํ ๊ณณ์์ ์ญ์ ์ ์ฑ
์ ๋ฐ๋ผ ๊ณตํต์ผ๋ก ์ฒ๋ฆฌ๋๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ค์์ต๋๋ค. |
@@ -0,0 +1,14 @@
+package step1;
+
+public class Print {
+
+ private int calculateResult;
+
+ public Print(int calculateResult) {
+ this.calculateResult = calculateResult;
+ }
+
+ public void printResult() {
+ System.out.println("calculateResult = " + calculateResult);
+ }
+} | Java | Print๊ฐ ํ๋์ ๊ณ์ฐ๊ฒฐ๊ณผ๋ฅผ ์ํ๋ก ๊ฐ์ง๋๋ก ๊ตฌํํ์
จ๋ค์!
๋ง์ฝ Print๋ฅผ ํตํด ๋ ๋ค๋ฅธ ๊ณ์ฐ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํด์ผํ๋ค๋ฉด ์ด๋ป๊ฒ ๋ ๊น์? Print๋ผ๋ ํด๋์ค์ ์ฑ
์์ ๋ง๋ ์ญํ ์ ํ๊ณ ์๋ค๊ณ ๋ณผ ์ ์์๊น์? |
@@ -0,0 +1,50 @@
+package step1;
+
+import java.util.List;
+
+public class Calculator {
+
+ private CalculatorResource calculatorResource;
+
+ public Calculator(String stringCalculatorSentence) {
+ this.calculatorResource = new CalculatorResource(stringCalculatorSentence);
+ }
+
+ public int calculate() {
+
+ List<Integer> numberList = calculatorResource.getNumberArray();
+ List<String> operatorList = calculatorResource.getOperatorArray();
+
+ int operatorListIndex = 0;
+ int result = 0;
+
+ for (int i = 1; i < numberList.size(); i++) {
+
+ result = calcualteInit(numberList, result, i);
+
+ result = getResult(numberList, operatorList, operatorListIndex, result, i);
+ operatorListIndex++;
+ }
+ return result;
+ }
+
+ private int calcualteInit(List<Integer> numberList, int result, int i) {
+ if (i == 1) {
+ result = (numberList.get(i - 1));
+ }
+ return result;
+ }
+
+ private int getResult(List<Integer> numberList, List<String> operatorList, int operatorListIndex, int result, int i) {
+ if (operatorList.get(operatorListIndex).equals("+")) {
+ result = result + (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("-")) {
+ result = result - (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("*")) {
+ result = result * (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("/")) {
+ result = result / (numberList.get(i));
+ }
+ return result;
+ }
+} | Java | java์ Enum ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ฉด ์ํ์ ํ์๋ฅผ ํ๊ณณ์์ ๊ด๋ฆฌํ ์ ์๋๋ฐ์!
๋งํฌ๋ฅผ ๋ณด์๊ณ ์ฐธ๊ณ ํ์
์ enum ํด๋์ค๋ฅผ ์ฌ์ฉํด๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค :)
https://techblog.woowahan.com/2527/ |
@@ -0,0 +1,50 @@
+package step1;
+
+import java.util.List;
+
+public class Calculator {
+
+ private CalculatorResource calculatorResource;
+
+ public Calculator(String stringCalculatorSentence) {
+ this.calculatorResource = new CalculatorResource(stringCalculatorSentence);
+ }
+
+ public int calculate() {
+
+ List<Integer> numberList = calculatorResource.getNumberArray();
+ List<String> operatorList = calculatorResource.getOperatorArray();
+
+ int operatorListIndex = 0;
+ int result = 0;
+
+ for (int i = 1; i < numberList.size(); i++) {
+
+ result = calcualteInit(numberList, result, i);
+
+ result = getResult(numberList, operatorList, operatorListIndex, result, i);
+ operatorListIndex++;
+ }
+ return result;
+ }
+
+ private int calcualteInit(List<Integer> numberList, int result, int i) {
+ if (i == 1) {
+ result = (numberList.get(i - 1));
+ }
+ return result;
+ }
+
+ private int getResult(List<Integer> numberList, List<String> operatorList, int operatorListIndex, int result, int i) {
+ if (operatorList.get(operatorListIndex).equals("+")) {
+ result = result + (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("-")) {
+ result = result - (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("*")) {
+ result = result * (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("/")) {
+ result = result / (numberList.get(i));
+ }
+ return result;
+ }
+} | Java | ๋ฉ์๋์ ํ๋ผ๋ฏธํฐ์ ๊ฐ์๋ฅผ 2๊ฐ ์ดํ๋ก ๋ฆฌํฉํฐ๋งํด๋ณด๋๊ฑด ์ด๋จ๊น์?
ํด๋ฆฐ ์ฝ๋ ์ฑ
์์๋ ๋ฉ์๋์ ํ๋ผ๋ฏธํฐ ๊ฐ์๋ 0~2๊ฐ๊ฐ ์ ์ ํ๋ฉฐ 4๊ฐ ์ด์์ ๋ฌด์กฐ๊ฑด์ ์ผ๋ก ํผํด์ผํ๋ค๊ณ ์ด์ผ๊ธฐํฉ๋๋ค.
ํ๋ผ๋ฏธํฐ์ ๊ฐ์๊ฐ ๋ง์ ์๋ก ํ๋์ ๋ฉ์๋์์ ํ๋ ์ผ์ด ๋ง์์ง ์ ์๊ณ ์ฝ๋๋ฅผ ์ฝ๊ธฐ ์ด๋ ค์์ง๊ธฐ ๋๋ฌธ์
๋๋ค :) |
@@ -0,0 +1,50 @@
+package step1;
+
+import java.util.List;
+
+public class Calculator {
+
+ private CalculatorResource calculatorResource;
+
+ public Calculator(String stringCalculatorSentence) {
+ this.calculatorResource = new CalculatorResource(stringCalculatorSentence);
+ }
+
+ public int calculate() {
+
+ List<Integer> numberList = calculatorResource.getNumberArray();
+ List<String> operatorList = calculatorResource.getOperatorArray();
+
+ int operatorListIndex = 0;
+ int result = 0;
+
+ for (int i = 1; i < numberList.size(); i++) {
+
+ result = calcualteInit(numberList, result, i);
+
+ result = getResult(numberList, operatorList, operatorListIndex, result, i);
+ operatorListIndex++;
+ }
+ return result;
+ }
+
+ private int calcualteInit(List<Integer> numberList, int result, int i) {
+ if (i == 1) {
+ result = (numberList.get(i - 1));
+ }
+ return result;
+ }
+
+ private int getResult(List<Integer> numberList, List<String> operatorList, int operatorListIndex, int result, int i) {
+ if (operatorList.get(operatorListIndex).equals("+")) {
+ result = result + (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("-")) {
+ result = result - (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("*")) {
+ result = result * (numberList.get(i));
+ } else if (operatorList.get(operatorListIndex).equals("/")) {
+ result = result / (numberList.get(i));
+ }
+ return result;
+ }
+} | Java | `๊ณ์ฐ๊ธฐ`๊ฐ ํ๋์ `๊ณ์ฐ๊ธฐ ์์`์ ์ํ๋ก ๊ฐ์ง๋๋ก ๊ตฌํํ์
จ๋ค์ !
๋ง์ฝ ๊ณ์ฐ๊ธฐ๊ฐ ๋ ๋ค๋ฅธ ์์์ ๋ํ ๊ณ์ฐ์ ํด์ผํ๋ ์ํฉ์ด๋ผ๋ฉด ์ด๋ป๊ฒ ํด์ผํ ๊น์?
ํ์ฌ ์ํ์์๋ ํ๋์ ๊ณ์ฐ๊ธฐ ๊ฐ์ฒด๊ฐ ํ๋์ ์์๋ง์ ๊ณ์ฐํ ์ ์๋๋ฐ์.
์ฌ๋ฌ ๊ฐ์ ์์์ ๋ํด ๊ณ์ฐํ ์ ์๋๋ก ๊ฐ์ ํด๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค :) |
@@ -0,0 +1,64 @@
+package step1;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CalculatorResource {
+
+ private String sentence;
+ private String[] sentenceArray;
+ private List<Integer> numberArray;
+ private List<String> operatorArray;
+
+ public List<Integer> getNumberArray() {
+ return numberArray;
+ }
+
+ public List<String> getOperatorArray() {
+ return operatorArray;
+ }
+
+ public CalculatorResource(String sentence) {
+ this.sentence = sentence;
+ splitSentence();
+ creatNumberList();
+ creatOperatorList();
+ }
+
+ private void splitSentence() {
+ this.sentenceArray = this.sentence.split(" ");
+ }
+
+ public void creatNumberList() {
+ this.numberArray = new ArrayList<>();
+
+ for (String s : sentenceArray) {
+ char numberCheck = s.charAt(0);
+ validateNumber(numberArray, s, numberCheck);
+ }
+ this.numberArray = numberArray;
+ }
+
+ private void validateNumber(List<Integer> numberArray, String s, char numberCheck) {
+ if (numberCheck > 48 && numberCheck < 58) {
+ this.numberArray.add(Integer.parseInt(s));
+ }
+ }
+
+ public void creatOperatorList() {
+ this.operatorArray = new ArrayList<>();
+
+ for (String s : sentenceArray) {
+ char operatorCheck = s.charAt(0);
+ validateOperator(operatorArray, s, operatorCheck);
+ }
+ }
+
+ private void validateOperator(List<String> operatorArray, String s, char operatorCheck) {
+ if (operatorCheck < 48 || operatorCheck > 58) {
+ this.operatorArray.add(s);
+ }
+ }
+
+
+} | Java | CalculatorResource ํด๋์ค ๋ค์ด๋ฐ์ ์ถ์ํ๊ฐ ๋ง์ด ๋์ด ์๋ ํด๋์ค ๋ช
์
๋๋ค.
ํด๋์ค ๋ด๋ถ๋ฅผ ๋ณด์ง ์์ผ๋ฉด ์ด๋ค ์ํ๋ฅผ ๊ฐ์ง๊ณ ์๋์ง ์ ์ถํ๊ธฐ ํ๋ญ๋๋ค. ์กฐ๊ธ ๋ ๊ตฌ์ฒด์ ์ธ ํด๋์ค ๋ช
์ ๋ง๋ค์ด๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์์ :) |
@@ -0,0 +1,64 @@
+package step1;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CalculatorResource {
+
+ private String sentence;
+ private String[] sentenceArray;
+ private List<Integer> numberArray;
+ private List<String> operatorArray;
+
+ public List<Integer> getNumberArray() {
+ return numberArray;
+ }
+
+ public List<String> getOperatorArray() {
+ return operatorArray;
+ }
+
+ public CalculatorResource(String sentence) {
+ this.sentence = sentence;
+ splitSentence();
+ creatNumberList();
+ creatOperatorList();
+ }
+
+ private void splitSentence() {
+ this.sentenceArray = this.sentence.split(" ");
+ }
+
+ public void creatNumberList() {
+ this.numberArray = new ArrayList<>();
+
+ for (String s : sentenceArray) {
+ char numberCheck = s.charAt(0);
+ validateNumber(numberArray, s, numberCheck);
+ }
+ this.numberArray = numberArray;
+ }
+
+ private void validateNumber(List<Integer> numberArray, String s, char numberCheck) {
+ if (numberCheck > 48 && numberCheck < 58) {
+ this.numberArray.add(Integer.parseInt(s));
+ }
+ }
+
+ public void creatOperatorList() {
+ this.operatorArray = new ArrayList<>();
+
+ for (String s : sentenceArray) {
+ char operatorCheck = s.charAt(0);
+ validateOperator(operatorArray, s, operatorCheck);
+ }
+ }
+
+ private void validateOperator(List<String> operatorArray, String s, char operatorCheck) {
+ if (operatorCheck < 48 || operatorCheck > 58) {
+ this.operatorArray.add(s);
+ }
+ }
+
+
+} | Java | ๊ฐ์ฒด๊ฐ ์์ฑ๋ ์ดํ์ ๋ ๋ณ์๋ ์ฌ์ฉ๋์ง ์๊ณ ์๋ค์! ๐ค
๊ทธ๋ ๋ค๋ฉด ๊ณ์ฐ๊ธฐ ์์ํด๋์ค์์ sentence์ sentenceArray๋ฅผ ์ํ๋ก ๊ฐ์ง๊ณ ์์ ํ์๊ฐ ์์๊น์? |
@@ -0,0 +1,21 @@
+import { EOL as LINE_SEPARATOR } from 'os';
+import { TIME, UNITS } from './system.js';
+
+export const OUTPUT_MESSAGES = Object.freeze({
+ intro: `์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น ${TIME.month}${UNITS.month} ์ด๋ฒคํธ ํ๋๋์
๋๋ค.`,
+ outro: `์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!`,
+});
+
+export const INPUT_MESSAGES = Object.freeze({
+ date: `${TIME.month}${UNITS.month} ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)${LINE_SEPARATOR}`,
+ order: `์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)${LINE_SEPARATOR}`,
+});
+
+export const ERROR_MESSAGES = Object.freeze({
+ prefix: '[ERROR]',
+ invalidDate: '์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ invalidMenu: '์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ exceedQuantity:
+ '๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ onlyBeverage: '์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+}); | JavaScript | ์ด๋ฒคํธ๋ฅผ ์งํํ๋ ๋ฌ์ด ๋ฐ๋๋ ๊ฒ์ ๊ณ ๋ คํด `TIME.month` ์์๋ฅผ ๋ฐ๋ก ์์ฑํ ์ ์ด ์ธ์ ๊น์ด์!
`12์ ์ด๋ฒคํธ ์ฐธ์ฌ ๊ณ ๊ฐ์ 5%๊ฐ ๋ด๋
1์ ์ํด ์ด๋ฒคํธ์ ์ฌ์ฐธ์ฌํ๋ ๊ฒ`
์ด๋ฉ์ผ์ ์ด๋ฌํ ๋ฌธ์ฅ์ด ์ ๋ ๋์ ๋ฐํ๊ธด ํ๋๋ฐ ๊ทธ๋ฅ ๊ธฐ๋ฅ ๊ตฌํ์ ์ง์คํ๋๋ผ ์์ด๋ฒ๋ ธ๊ฑฐ๋ ์..
์ ๋ง ์ฌ์ธํ๊ฒ ๊ณ ๋ฏผํ์๋ฉด์ ๊ตฌํํ์ ๊ฒ ๊ฐ์ต๋๋ค! ๊ฐํ๋ง ๋์ค๋ค์ ๐ฎ |
@@ -0,0 +1,28 @@
+export const TIME = Object.freeze({
+ year: '2023',
+ month: '12',
+ dateFormat: `2023-12-`,
+});
+
+export const PROMOTION_TITLES = Object.freeze({
+ 1: '์ํด',
+ 12: 'ํฌ๋ฆฌ์ค๋ง์ค',
+});
+
+export const SYMBOLS = Object.freeze({
+ comma: ',',
+ dash: '-',
+ colon: ':',
+ blank: '',
+});
+
+export const UNITS = Object.freeze({
+ quantity: '๊ฐ',
+ won: '์',
+ month: '์',
+ year: '๋
',
+});
+
+export const NONE = '์์';
+
+export const FILE_PATH = 'src/data/dec-promotion.json'; | JavaScript | ํ์ฅ์ ๊ณ ๋ คํ์
จ๊ตฐ์! ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค ๐
์ค์ ํ์ฌ์๋ค๋ฉด ์ด๋ฒคํธ ๊ธฐํ์๊ฐ ๋๋ฌด ์ข์ํ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,28 @@
+export const TIME = Object.freeze({
+ year: '2023',
+ month: '12',
+ dateFormat: `2023-12-`,
+});
+
+export const PROMOTION_TITLES = Object.freeze({
+ 1: '์ํด',
+ 12: 'ํฌ๋ฆฌ์ค๋ง์ค',
+});
+
+export const SYMBOLS = Object.freeze({
+ comma: ',',
+ dash: '-',
+ colon: ':',
+ blank: '',
+});
+
+export const UNITS = Object.freeze({
+ quantity: '๊ฐ',
+ won: '์',
+ month: '์',
+ year: '๋
',
+});
+
+export const NONE = '์์';
+
+export const FILE_PATH = 'src/data/dec-promotion.json'; | JavaScript | ๊ทธ๋ฅ ๊ฐํ๋ง ๋์ค๋ค์... ํ ๋ง์ด ์๋ค์... ์ต์ข
์ฝํ
์ด๋ฐ๋ถ์ด ๊ฐ์๋๊ตฌ๋... |
@@ -0,0 +1,87 @@
+import VisitDate from '../domain/VisitDate.js';
+import Order from '../domain/Order.js';
+import InputView from '../views/InputView.js';
+import OutputView from '../views/OutputView.js';
+import EventPlanner from '../domain/EventPlanner.js';
+import Save from '../domain/Save.js';
+
+class EventController {
+ #inputView;
+
+ #outputView;
+
+ #dayIndex;
+
+ #eventPlanner;
+
+ constructor() {
+ this.#inputView = InputView;
+ this.#outputView = OutputView;
+ }
+
+ async startEvent() {
+ this.#outputView.printIntro();
+
+ const visitDate = await this.#requestVisitDate();
+ const orderList = await this.#requestOrderList();
+
+ this.#eventPlanner = this.#showEventPlanner(visitDate, orderList);
+ this.#saveResult(this.#eventPlanner);
+ }
+
+ /**
+ * ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์
๋ ฅ ๋ฐ์ ๋ฐํ, ์์ผ ์ธ๋ฑ์ค ๋ฉค๋ฒ ๋ณ์ ํ ๋น
+ * @returns {number} - ์์ผ ์ธ๋ฑ์ค
+ */
+ async #requestVisitDate() {
+ try {
+ const visitDate = await this.#inputView.readDate();
+ this.#dayIndex = new VisitDate(visitDate).getDayIndex();
+
+ return visitDate;
+ } catch ({ message }) {
+ this.#outputView.print(message);
+
+ return this.#requestVisitDate();
+ }
+ }
+
+ /**
+ * ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ์ ๊ฐ๊ณตํ ์ฃผ๋ฌธ ๋ฉ๋ด๋ฅผ ๋ฆฌํด
+ * @returns {Set<{ menu: string, quantity: number }>}
+ */
+ async #requestOrderList() {
+ try {
+ const orderInput = await this.#inputView.readOrder();
+
+ return new Order(orderInput).getOrderList();
+ } catch ({ message }) {
+ this.#outputView.print(message);
+
+ return this.#requestOrderList();
+ }
+ }
+
+ /**
+ * ์ ์ ์ ์
๋ ฅ ๊ฐ์ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฒคํธ ํ๋๋๋ฅผ ๊ตฌ์ฑํ๊ณ ์ถ๋ ฅ
+ * @param {number} visitDate - ์์ผ ์ธ๋ฑ์ค
+ * @param {Set<{ menu: string, quantity: number }>} orderList - ์ฃผ๋ฌธ ๋ฉ๋ด์ ์๋์ ๋ํ๋ด๋ Set ๊ฐ์ฒด
+ * @returns
+ */
+ #showEventPlanner(visitDate, orderList) {
+ this.#outputView.printOutro(visitDate);
+ this.#eventPlanner = new EventPlanner(visitDate, this.#dayIndex, orderList);
+ this.#outputView.printPlanner(orderList, this.#eventPlanner);
+
+ return this.#eventPlanner;
+ }
+
+ /**
+ * ์ด๋ฒคํธ ํ๋๋์ ์ฃผ์ ๋ฐ์ดํฐ๋ฅผ Save ํด๋์ค์ ๋๊ฒจ ์ ์ฅ
+ */
+ #saveResult() {
+ new Save(this.#eventPlanner);
+ }
+}
+
+export default EventController; | JavaScript | ์๋ฌ๋ฉ์์ง ์ถ๋ ฅ ๊ธฐ๋ฅ์ `outputView`๊ฐ ์ฑ
์์ ๋งก๋๋ก ํ๊ตฐ์! ๋ฆฌํฉํ ๋ง ํ ๋ ์ ๋ ๋ฐ์ํด๋ด์ผ๊ฒ ์ต๋๋ค ๐ |
@@ -0,0 +1,32 @@
+import { ERROR_MESSAGES } from '../constants/messages.js';
+import { TIME } from '../constants/system.js';
+import validationErrorHandler from '../errors/index.js';
+import { isPositiveInteger, isValidDate } from '../validators/index.js';
+
+class VisitDate {
+ #visitDate;
+
+ constructor(date) {
+ this.#validateDate(date);
+ this.#visitDate = date;
+ }
+
+ #validateDate(date) {
+ if (!isPositiveInteger(date) || !isValidDate(date)) {
+ validationErrorHandler(ERROR_MESSAGES.invalidDate);
+ }
+ }
+
+ getDayIndex() {
+ return this.#calculateDayIndex();
+ }
+
+ // ์ด๋ฒคํธ ์ฐ-์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ๊ณ์ฐํ์ฌ ์์ผ ์ธ๋ฑ์ค๋ฅผ ๋ฐํ
+ #calculateDayIndex() {
+ const date = new Date(`${TIME.dateFormat}${this.#visitDate}`);
+
+ return date.getDay();
+ }
+}
+
+export default VisitDate; | JavaScript | ๊ธฐ๋ณธ ์ ๊ณต๋๋ `Date` ๊ฐ์ฒด๋ฅผ ํ์ฉํ ์๊ฐ์ ๋ชปํ๋ค์!
์ด๋ ๊ฒ ์ ๋ฐํ ๋ฐฉ๋ฒ๋ ์๋ค๋ ๊ฒ์ ์์๊ฐ๋๋ค ๐ |
@@ -0,0 +1,9 @@
+import { ERROR_MESSAGES } from '../constants/messages.js';
+
+class AppError extends Error {
+ constructor(message) {
+ super(`${ERROR_MESSAGES.prefix} ${message}`);
+ }
+}
+
+export default AppError; | JavaScript | ์๋ฌ๋ฅผ ์์ํ์
จ๊ตฐ์! ์ ๋ง ์ฒด๊ณ์ ์ธ ์ฝ๋์ธ ๊ฒ ๊ฐ์์!
`Error`๋ฅผ ์์ํด `AppError` ํด๋์ค๋ฅผ ๋ฐ๋ก ๋ง๋์๊ฒ ๋ ๊ณ๊ธฐ๋ฅผ ์ฌ์ญค๋ด๋ ๋ ๊น์? |
@@ -0,0 +1,12 @@
+import MENUS from '../constants/menus.js';
+
+/**
+ * ๋ฉ๋ด ์ด๋ฆ์ ์
๋ ฅํ๋ฉด ์นดํ
๊ณ ๋ฆฌ ๋ด ๋ฉ๋ด์ ๊ฐ๊ฒฉ ๊ฐ์ ๋ฐํ
+ * @param {string} menu - ๋ฉ๋ด ์ด๋ฆ
+ * @returns {number | undefined}
+ */
+const menuPriceFinder = menu => {
+ return Object.values(MENUS).find(category => menu in category)[menu];
+};
+
+export default menuPriceFinder; | JavaScript | ๊ธฐ๋ฅ์ ๊ตฌํํ๋ค๋ณด๋ฉด ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ ์์ฃผ ๊ฐ์ ธ๋ค ์ฐ๊ฒ ๋๋๋ฐ utils ํด๋์ ๋ฐ๋ก ํจ์๋ฅผ ๊ตฌํํด๋๋ ์ข์ ๊ฒ ๊ฐ์์!
๋ฐฐ์๊ฐ๋๋ค ๐ |
@@ -0,0 +1,15 @@
+import { UNITS } from '../constants/system.js';
+
+/**
+ * number type์ ๊ฐ๊ฒฉ์ ์
๋ ฅ๋ฐ์ ๊ฐ๊ฒฉ์ ๋ณํ ํ '์'์ ํฌํจํ string type์ผ๋ก ๋ณํ
+ * 20000์ด๋ผ๋ ๋งค๊ฐ๋ณ์๋ฅผ ํตํด '20,000์'์ ๋ฐํ
+ * @param {number} price ๊ฐ๊ฒฉ
+ * @returns {string}
+ */
+const priceFormatter = price => {
+ const formattedPrice = new Intl.NumberFormat().format(price);
+
+ return `${formattedPrice}${UNITS.won}`;
+};
+
+export default priceFormatter; | JavaScript | `Intl.NumberFormat` ๋ฅผ ์ฒ์ ์ ํ๋๋ฐ ์ด๋ ๊ฒ ๊ฐ๊ฒฉ์ ํฌ๋งทํ๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ด ์์๊ตฐ์!
์ ๋ ์ ๊ทํํ์์ผ๋ก ๊ตฌํํ๋๋ฐ ์๋ก์ด ๋ฐฉ๋ฒ์ ์์๊ฐ๊ฒ ๋ผ์ ์ข์์! |
@@ -0,0 +1,68 @@
+import { ERROR_MESSAGES } from '../constants/messages.js';
+import { SYMBOLS } from '../constants/system.js';
+import validationErrorHandler from '../errors/index.js';
+import { isValidMenuName } from '../validators/index.js';
+import { isOnlyBeverage } from '../validators/is-valid-menu/name.js';
+import {
+ isValidEachMenuQuantity,
+ isValidTotalMenuQuantity,
+} from '../validators/is-valid-menu/quantity.js';
+
+class Order {
+ #orderList = new Set();
+
+ constructor(orderInput) {
+ this.#validate(orderInput);
+ this.#orderList = this.#parse(orderInput);
+ }
+
+ /**
+ * ์ฌ์ฉ์ ์
๋ ฅํ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ํ์ฑํ์ฌ ๋ฐฐ์ด๋ก ๋ฐํ
+ * @param {string} orderInput - ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ๋ชจ๋ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์
+ * @returns {{ key: string, value: string }[]} - ์ฃผ๋ฌธ์ด ํ์ฑ๋ ๋ฐฐ์ด
+ */
+ #parse(orderInput) {
+ this.#splitOrder(orderInput);
+
+ return [...this.#orderList];
+ }
+
+ /**
+ * orderInput ๋ด ๊ฐ๋ณ ์ฃผ๋ฌธ๋ค์ ํ์ฑ
+ * @param {string} orderInput - ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ๋ชจ๋ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์
+ * @returns {Set<{ menu: string, quantity: number }>} - ์ฃผ๋ฌธ์ด ํ์ฑ๋ Set
+ */
+ #splitOrder(orderInput) {
+ return orderInput.split(SYMBOLS.comma).map(order => this.#splitMenu(order));
+ }
+
+ /**
+ * ์ฃผ๋ฌธ ๋ฉ๋ด๋ช
๊ณผ ๊ฐ์๋ฅผ orderList Set์ ์ถ๊ฐ
+ * @param {string} order ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ํน์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์
+ */
+ #splitMenu(order) {
+ const [menu, quantity] = order.split(SYMBOLS.dash);
+
+ this.#orderList.add({ menu: menu.trim(), quantity: Number(quantity) });
+ }
+
+ #validate(orderInput) {
+ if (!isValidMenuName(orderInput) || !isValidEachMenuQuantity(orderInput)) {
+ validationErrorHandler(ERROR_MESSAGES.invalidMenu);
+ }
+
+ if (!isValidTotalMenuQuantity(orderInput)) {
+ validationErrorHandler(ERROR_MESSAGES.exceedQuantity);
+ }
+
+ if (isOnlyBeverage(orderInput)) {
+ validationErrorHandler(ERROR_MESSAGES.onlyBeverage);
+ }
+ }
+
+ getOrderList() {
+ return this.#orderList;
+ }
+}
+
+export default Order; | JavaScript | ๋ฉ์๋ ์์๋ฅผ ์ ์ ํ์
์ ์ดํดํ๊ธฐ ์ ๋ง ์ข์์ต๋๋ค!
์ด, ์ด ๋ฉ์๋๋ ๋ญ์ง? ์ถ์ผ๋ฉด ๋ฐ๋ก ๋ฐ์ ๊ทธ ๋ฉ์๋๊ฐ ์์ด์ ์ ์ ์ฝํ์ด์!
๋ฉ์๋ ์์๋ ์ปจ๋ฒค์
์ด๋ผ๊ณ ํ๋ ๊ณตํต ํผ๋๋ฐฑ์ด ์์๋๋ฐ ๊ทธ๊ฑธ ์ ๋ฐ์ํ์ ๊ฒ ๊ฐ์์ ๐ |
@@ -0,0 +1,57 @@
+import { GIVEAWAYS, TITLES } from '../constants/events.js';
+import { NONE } from '../constants/system.js';
+import menuPriceFinder from '../utils/menuPriceFinder.js';
+
+class Benefit {
+ #isFitGiveaway;
+
+ #benefitList;
+
+ #totalPrice;
+
+ constructor(discountList, isFitGiveaway) {
+ this.#isFitGiveaway = isFitGiveaway;
+ this.#benefitList = this.#setBenefitList(discountList);
+ this.#totalPrice = this.#calculateTotalPrice();
+ }
+
+ /**
+ * ์ฆ์ ์ด๋ฒคํธ ๊ธฐ์ค ์ด์์ด๋ฉด ํํ ๋ด์ญ์ ์ฆ์ ๋ฉ๋ด๋ฅผ ์ถ๊ฐํ๊ณ , ๋ฏธ๋ง์ด๋ฉด '์์'์ ์ถ๊ฐ
+ * @param {Array<{ title: string, price: number }>} benefitList - ํํ ๋ฆฌ์คํธ
+ * @returns
+ */
+ #setBenefitList(discountList) {
+ if (this.#isFitGiveaway) {
+ return [...discountList, this.#createGiveawayBenefit()];
+ }
+
+ return discountList;
+ }
+
+ #createGiveawayBenefit() {
+ return {
+ title: TITLES.giveaway,
+ price: menuPriceFinder(GIVEAWAYS.giveaway),
+ };
+ }
+
+ /**
+ * ํํ ๋ด์ญ์ด '์์'์ด๋ฉด ์ด ๊ธ์ก 0์ ๋ฐํ, ํํ ๋ด์ญ์ด ์์ผ๋ฉด ์ด ๊ธ์ก์ ๋์ฐํ์ฌ ๋ฐํ
+ * @returns
+ */
+ #calculateTotalPrice() {
+ if (this.#benefitList === NONE) return 0;
+
+ return this.#benefitList.reduce((acc, benefit) => acc + benefit.price, 0);
+ }
+
+ getList() {
+ return this.#benefitList;
+ }
+
+ getTotalPrice() {
+ return this.#totalPrice;
+ }
+}
+
+export default Benefit; | JavaScript | 3์ฃผ์ฐจ ๊ณตํต ํผ๋๋ฐฑ์ `ํ๋์ ์๋ฅผ ์ค์ด๊ธฐ ์ํด ๋
ธ๋ ฅํ๋ค`๋ผ๋ ๋ง์ด ์์์ฃ !
`#benefitList`์ `#totalPrice`๋
์์ฑ์์ ์ธ์๋ก ์ ๋ฌ๋ `discountList`, `isFitGiveaway`์ผ๋ก ๋ง๋ค ์ ์๊ธฐ ๋๋ฌธ์
๊ผญ ํ๋๋ก ์ ์ธํด์ผ ํ๋ ๊ฑด์ง์ ๋ํ ์๋ฌธ์ด ์๊น๋๋ค!
ํ๋์ ๊ฐ์๋ฅผ ์ต๋ํ ์ค์ด๋ ๊ฒ ์ ๋ง ์ณ์ ๊ฒ์ธ์ง ๊ณ ๋ฏผ์ด ๋ง์์ง๋ค์
ํฌํ๋ ์๊ฐ์ ์ด๋ ์ ๊ฐ์?! |
@@ -0,0 +1,106 @@
+import { BADGES, GIVEAWAYS } from '../constants/events.js';
+import { NONE } from '../constants/system.js';
+import menuPriceFinder from '../utils/menuPriceFinder.js';
+import Benefit from './Benefit.js';
+import Discount from './Discount.js';
+
+class EventPlanner {
+ #benefit;
+
+ #preTotalPrice;
+
+ #totalBenefitPrice;
+
+ constructor(visitDate, dayIndex, orderList) {
+ this.discount = new Discount(visitDate, dayIndex, orderList);
+ this.#preTotalPrice = this.#setPreTotalPrice(orderList);
+ this.isFitGiveaway = this.#checkIsFitGiveAway();
+ this.#benefit = new Benefit(
+ this.discount.getDiscounts(this.#preTotalPrice),
+ this.isFitGiveaway,
+ );
+ }
+
+ /**
+ * ์ฃผ๋ฌธ ๋ด์ญ์ ์ํํ๋ฉฐ ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ ๋ฐํ
+ * @param {Array<{ menu: string, quantity: number }>} orderList - ์ฃผ๋ฌธ ๋ด์ญ
+ * @returns
+ */
+ #setPreTotalPrice(orderList) {
+ return orderList.reduce(
+ (acc, order) => this.#calculateTotalPrice(acc, order),
+ 0,
+ );
+ }
+
+ /**
+ * ํน์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ๊ณผ ์๋์ ๊ณฑํ์ฌ ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ ๊ณ์ฐ
+ * @param {number} acc - ๋์ ๊ธ์ก
+ * @param {{ menu: string, quantity: number }} order - ํน์ ์ฃผ๋ฌธ ๋ด์ญ
+ * @returns
+ */
+ #calculateTotalPrice(acc, order) {
+ const price = menuPriceFinder(order.menu);
+
+ return acc + price * order.quantity;
+ }
+
+ getPreTotalPrice() {
+ return this.#preTotalPrice;
+ }
+
+ // ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก๊ณผ ์ฆ์ ์ด๋ฒคํธ ๊ธฐ์ค ๊ธ์ก์ ๋น๊ตํ์ฌ boolean ๋ฐํ
+ #checkIsFitGiveAway() {
+ return this.#preTotalPrice >= GIVEAWAYS.giveawayPrice;
+ }
+
+ // ์ฆ์ ์ด๋ฒคํธ ๊ธฐ์ค ๊ธ์ก ์ด์์ด๋ฉด ์ฆ์ ์ด๋ฒคํธ ์ํ ๋ฐํ, ๋ฏธ๋ง์ด๋ฉด '์์' ๋ฐํ
+ getGiveaway() {
+ return this.isFitGiveaway ? [this.#createGiveaway()] : NONE;
+ }
+
+ #createGiveaway() {
+ return { menu: GIVEAWAYS.giveaway, quantity: GIVEAWAYS.giveawayUnit };
+ }
+
+ getBenefitList() {
+ const benefitList = this.#benefit.getList();
+
+ return benefitList.length ? benefitList : NONE;
+ }
+
+ getTotalBenefitPrice() {
+ this.#totalBenefitPrice = this.#benefit.getTotalPrice();
+
+ return this.#totalBenefitPrice;
+ }
+
+ /**
+ * ์ด ํ ์ธ ๊ธ์ก์ด ์กด์ฌํ๋ฉด ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ๋ฐํ, ๊ทธ๋ ์ง ์๋ค๋ฉด ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ๋ฐํ
+ * @returns
+ */
+ getTotalPrice() {
+ const totalDiscountPrice = this.discount.getTotalDiscountPrice();
+
+ return this.#preTotalPrice - totalDiscountPrice;
+ }
+
+ /**
+ * ์ดํํ ๊ธ์ก์ ๋ฐ๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง ๋ฐํ
+ * @returns
+ */
+ getBadge() {
+ switch (true) {
+ case this.#totalBenefitPrice > BADGES.santa.price:
+ return BADGES.santa.title;
+ case this.#totalBenefitPrice > BADGES.tree.price:
+ return BADGES.tree.title;
+ case this.#totalBenefitPrice > BADGES.star.price:
+ return BADGES.star.title;
+ default:
+ return NONE;
+ }
+ }
+}
+
+export default EventPlanner; | JavaScript | `switch`๋ฌธ์ ์ฌ์ฉํ๋ ์ ๋ง ๊น๋ํ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,43 @@
+import fs from 'fs';
+import { FILE_PATH } from '../constants/system.js';
+
+class Save {
+ #eventPlanner;
+
+ #filePath;
+
+ constructor(eventPlanner) {
+ this.#eventPlanner = eventPlanner;
+ this.#filePath = FILE_PATH;
+ this.#writeData();
+ }
+
+ // ๊ธฐ์กด JSON ๋ฐ์ดํฐ์ ์ ๊ท ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ๊ณ ์ ์ฅ
+ #writeData() {
+ const readData = this.#readData();
+ const userData = {
+ user: readData.length,
+ badge: this.#eventPlanner.getBadge(),
+ total: this.#eventPlanner.getPreTotalPrice(),
+ benefit: this.#eventPlanner.getTotalBenefitPrice(),
+ payment: this.#eventPlanner.getTotalPrice(),
+ };
+ readData.push(userData);
+ const jsonData = JSON.stringify(readData, null, 2);
+
+ fs.writeFileSync(this.#filePath, jsonData, 'utf-8');
+ }
+
+ // ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์ ํ์ฑํ์ฌ ๋ฐํ, ๊ธฐ์กด์ ๋ฐ์ดํฐ๊ฐ ์๋ค๋ฉด ๋น ๋ฐฐ์ด ์ถ๊ฐ
+ #readData() {
+ try {
+ const data = fs.readFileSync(this.#filePath, 'utf-8');
+
+ return JSON.parse(data);
+ } catch (error) {
+ return [];
+ }
+ }
+}
+
+export default Save; | JavaScript | ๋ฐฉ๋ฌธํ ์๋๋ค์ ๋ํ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ๊ธฐ๋ฅ์ ์๊ฐ ๋ชป ํ๋๋ฐ
๋๋ฌด ์ข์ ์์ด๋์ด์
๋๋ค โจ |
@@ -0,0 +1,21 @@
+import { EOL as LINE_SEPARATOR } from 'os';
+import { TIME, UNITS } from './system.js';
+
+export const OUTPUT_MESSAGES = Object.freeze({
+ intro: `์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น ${TIME.month}${UNITS.month} ์ด๋ฒคํธ ํ๋๋์
๋๋ค.`,
+ outro: `์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!`,
+});
+
+export const INPUT_MESSAGES = Object.freeze({
+ date: `${TIME.month}${UNITS.month} ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)${LINE_SEPARATOR}`,
+ order: `์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)${LINE_SEPARATOR}`,
+});
+
+export const ERROR_MESSAGES = Object.freeze({
+ prefix: '[ERROR]',
+ invalidDate: '์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ invalidMenu: '์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ exceedQuantity:
+ '๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ onlyBeverage: '์๋ฃ๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+}); | JavaScript | ์ด๋ฒ ๋ฏธ์
์์๋ ํ์ฅ์ฑ์ ์ ๊ฒฝ์ฐ๊ณ ์ ๋
ธ๋ ฅํ๋๋ฐ ์์๋ด์ฃผ์
์ ๊ฐ์ฌํ ๋ฐ๋ฆ์
๋๋ค! ๐ |
@@ -0,0 +1,32 @@
+import { ERROR_MESSAGES } from '../constants/messages.js';
+import { TIME } from '../constants/system.js';
+import validationErrorHandler from '../errors/index.js';
+import { isPositiveInteger, isValidDate } from '../validators/index.js';
+
+class VisitDate {
+ #visitDate;
+
+ constructor(date) {
+ this.#validateDate(date);
+ this.#visitDate = date;
+ }
+
+ #validateDate(date) {
+ if (!isPositiveInteger(date) || !isValidDate(date)) {
+ validationErrorHandler(ERROR_MESSAGES.invalidDate);
+ }
+ }
+
+ getDayIndex() {
+ return this.#calculateDayIndex();
+ }
+
+ // ์ด๋ฒคํธ ์ฐ-์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ๊ณ์ฐํ์ฌ ์์ผ ์ธ๋ฑ์ค๋ฅผ ๋ฐํ
+ #calculateDayIndex() {
+ const date = new Date(`${TIME.dateFormat}${this.#visitDate}`);
+
+ return date.getDay();
+ }
+}
+
+export default VisitDate; | JavaScript | ์๋ง ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์์๊ฒ๋๋ค! :) ์ ๋ `Date` ๊ฐ์ฒด๋ฅผ ์ ํ์ฉํ์ง ๋ชปํ ๊ฒ ๊ฐ์์ ๋ ๊ณต๋ถํด๋ณด๋ ค๊ตฌ์! |
@@ -0,0 +1,9 @@
+import { ERROR_MESSAGES } from '../constants/messages.js';
+
+class AppError extends Error {
+ constructor(message) {
+ super(`${ERROR_MESSAGES.prefix} ${message}`);
+ }
+}
+
+export default AppError; | JavaScript | ์๋ฌด๋๋ `[ERROR]` ๋ผ๋ prefix๋ฅผ ํตํด ์๋ฌ ๋ฉ์์ง๋ฅผ ์ ์ํ๋ ๊ณผ์ ์์ ๋ง๋ค๊ฒ ๋์๋๋ฐ์, ์ง์ ์๋ฌ ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ฉด ์ถํ์ ๋ ์ฝ๊ฒ ํ์ฅํ ์ ์๋ ์ฅ์ ์ด ์์ง ์์๊น๋ผ๋ ์๊ฐ์ด์์ต๋๋ค! |
@@ -0,0 +1,15 @@
+import { UNITS } from '../constants/system.js';
+
+/**
+ * number type์ ๊ฐ๊ฒฉ์ ์
๋ ฅ๋ฐ์ ๊ฐ๊ฒฉ์ ๋ณํ ํ '์'์ ํฌํจํ string type์ผ๋ก ๋ณํ
+ * 20000์ด๋ผ๋ ๋งค๊ฐ๋ณ์๋ฅผ ํตํด '20,000์'์ ๋ฐํ
+ * @param {number} price ๊ฐ๊ฒฉ
+ * @returns {string}
+ */
+const priceFormatter = price => {
+ const formattedPrice = new Intl.NumberFormat().format(price);
+
+ return `${formattedPrice}${UNITS.won}`;
+};
+
+export default priceFormatter; | JavaScript | `Intl.NumberFormat` ์์ฑ์๋ฅผ ํตํด ๋ค์ํ ํตํ ์์์ ๋ณํํ ์ ์๋๋ผ๊ตฌ์!
[Intl.NumberFormat](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat)
๋์์ด ๋ ๊น์ถ์ด ๋งํฌ ์ฒจ๋ถํด๋์์ต๋๋ค :) |
@@ -0,0 +1,57 @@
+import { GIVEAWAYS, TITLES } from '../constants/events.js';
+import { NONE } from '../constants/system.js';
+import menuPriceFinder from '../utils/menuPriceFinder.js';
+
+class Benefit {
+ #isFitGiveaway;
+
+ #benefitList;
+
+ #totalPrice;
+
+ constructor(discountList, isFitGiveaway) {
+ this.#isFitGiveaway = isFitGiveaway;
+ this.#benefitList = this.#setBenefitList(discountList);
+ this.#totalPrice = this.#calculateTotalPrice();
+ }
+
+ /**
+ * ์ฆ์ ์ด๋ฒคํธ ๊ธฐ์ค ์ด์์ด๋ฉด ํํ ๋ด์ญ์ ์ฆ์ ๋ฉ๋ด๋ฅผ ์ถ๊ฐํ๊ณ , ๋ฏธ๋ง์ด๋ฉด '์์'์ ์ถ๊ฐ
+ * @param {Array<{ title: string, price: number }>} benefitList - ํํ ๋ฆฌ์คํธ
+ * @returns
+ */
+ #setBenefitList(discountList) {
+ if (this.#isFitGiveaway) {
+ return [...discountList, this.#createGiveawayBenefit()];
+ }
+
+ return discountList;
+ }
+
+ #createGiveawayBenefit() {
+ return {
+ title: TITLES.giveaway,
+ price: menuPriceFinder(GIVEAWAYS.giveaway),
+ };
+ }
+
+ /**
+ * ํํ ๋ด์ญ์ด '์์'์ด๋ฉด ์ด ๊ธ์ก 0์ ๋ฐํ, ํํ ๋ด์ญ์ด ์์ผ๋ฉด ์ด ๊ธ์ก์ ๋์ฐํ์ฌ ๋ฐํ
+ * @returns
+ */
+ #calculateTotalPrice() {
+ if (this.#benefitList === NONE) return 0;
+
+ return this.#benefitList.reduce((acc, benefit) => acc + benefit.price, 0);
+ }
+
+ getList() {
+ return this.#benefitList;
+ }
+
+ getTotalPrice() {
+ return this.#totalPrice;
+ }
+}
+
+export default Benefit; | JavaScript | ์ ๋ ์ฐ์ ๋ชจ๋ ๋ฉ์๋์ ํ๋๋ฅผ `private`์ผ๋ก ์ง์ ํ๊ณ ๋์, ์ดํ์ `public`์ผ๋ก ์ ๊ทผ์ ํด์ผ๋ง ํ ๋ `public`์ผ๋ก ์ ํํ์์ต๋๋ค!
์๋ง ์ด ๊ณผ์ ์์๋ ํด๋์ค ๋ด ๋ฉ์๋๊ฐ `benefitList`์ `totalPrice`๋ฅผ ์ฌ์ฉํจ์ ์์ด์ `public`์ผ๋ก ์ ํํ์ง ์์๋ ๋ ๊ฒ ๊ฐ์์ ๊ทธ๋๋ก ๋์์ต๋๋ค :)
์ ๋ ์ฌ์ค ๊ณตํต ํผ๋๋ฐฑ์ ๋ฐ๊ณ ๋์ ํ๋์ ๊ฐ์๋ฅผ ์ต๋ํ ์ค์ฌ์ผํ๋ ๊ฒ๊ณผ, ์ต๋ํ private ํ๋๋ก ์บก์ํ๋ฅผ ๊ตฌํํ๋ ๊ฒ ์ฌ์ด์์์ ์ค๊ฐ์ ์ ๋ชป์ฐพ๊ฒ ๋๋ผ๊ตฌ์!
์ข์ ํผ๋๋ฐฑ ๊ฐ์ฌ๋๋ฆฝ๋๋ค! `benefitList`์ `totalPrice`๋ฅผ ๊ตณ์ด private ํ๋๋ก ์ ์ธํด์ผํ๋ ๊ทผ๊ฑฐ๊ฐ ์์ผ๋ฉด ์ค์ด๋๊ฒ๋ ๋ง๋ค๊ณ ์๊ฐ์ด ๋ญ๋๋ค. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.