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&amp;_nc_ht=scontent-ssn1-1.cdninstagram.com&amp;_nc_ohc=ldPmBqcpW3kAX9esSCC&amp;ccb=7-4&amp;oh=6503a99b1b0096ad362012fef7e72aed&amp;oe=6085537E&amp;_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&amp;_nc_ht=scontent-ssn1-1.cdninstagram.com&amp;_nc_ohc=-evbCZABANYAX_WcDzP&amp;edm=AEF8tYYAAAAA&amp;ccb=7-4&amp;oh=5eb6e52a64b2ad8c98bff45dab473831&amp;oe=60880D5B&amp;_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&amp;_nc_ht=scontent-ssn1-1.cdninstagram.com&amp;_nc_ohc=ldPmBqcpW3kAX9esSCC&amp;ccb=7-4&amp;oh=6503a99b1b0096ad362012fef7e72aed&amp;oe=6085537E&amp;_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&amp;_nc_ht=scontent-ssn1-1.cdninstagram.com&amp;_nc_ohc=-evbCZABANYAX_WcDzP&amp;edm=AEF8tYYAAAAA&amp;ccb=7-4&amp;oh=5eb6e52a64b2ad8c98bff45dab473831&amp;oe=60880D5B&amp;_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&amp;_nc_ht=scontent-ssn1-1.cdninstagram.com&amp;_nc_ohc=ldPmBqcpW3kAX9esSCC&amp;ccb=7-4&amp;oh=6503a99b1b0096ad362012fef7e72aed&amp;oe=6085537E&amp;_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&amp;_nc_ht=scontent-ssn1-1.cdninstagram.com&amp;_nc_ohc=-evbCZABANYAX_WcDzP&amp;edm=AEF8tYYAAAAA&amp;ccb=7-4&amp;oh=5eb6e52a64b2ad8c98bff45dab473831&amp;oe=60880D5B&amp;_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>โœ๏ธ&nbsp;์ฝ”๋“œ ๋ฆฌ๋ทฐ</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๋ฅผ ์ฐธ๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค. +## ๐Ÿ“ฆ&nbsp;&nbsp;ํŒจํ‚ค์ง€ ๊ตฌ์กฐ + +[//]: # (<img align="center" src="https://github.com/woowacourse-precourse/java-racingcar-6/assets/112257466/3ef9d8a2-d4bb-42a1-900f-754799cac3fd" height="32px">&nbsp;&nbsp;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">&nbsp;&nbsp;controller</b></td> + <td><b><img align="center" height="32px">&nbsp;&nbsp;EventPlannerController</b></td> + <td>์ด๋ฒคํŠธ ํ”Œ๋ž˜๋„ˆ ๋กœ์ง์„ ๋ฉ”์ธ์œผ๋กœ ๋™์ž‘ํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;OrderController</b></td> + <td>์ฃผ๋ฌธ์„ ๋ฐ›๋Š” ๋กœ์ง์„ ๋™์ž‘ํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;ReservationController</b></td> + <td>๋ฐฉ๋ฌธ ๋‚ ์งœ ์˜ˆ์•ฝ์„ ๋ฐ›๋Š” ๋กœ์ง์„ ๋™์ž‘ํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;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">&nbsp;&nbsp;<b>domain<br></b></td> + <td><b><img align="center" height="32px">&nbsp;&nbsp;Calendar</b></td> + <td>12์›” ๋‹ฌ๋ ฅ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” enum ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;DiscountType</b></td> + <td>ํ• ์ธ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” enum ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;EventBadge</b></td> + <td>์ด๋ฒคํŠธ ๋ฐฐ์ง€ ๋ถ€์—ฌ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” enum ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;Menu</b></td> + <td>์ฃผ๋ฌธ ๋ฉ”๋‰ด์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” enum ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;Order</b></td> + <td>์ฃผ๋ฌธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;Reservation</b></td> + <td>์˜ˆ์•ฝ ๋‚ ์งœ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;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">&nbsp;&nbsp;<b>exception</b></td> + <td><b><img align="center" height="32px">&nbsp;&nbsp;ErrorMessage</b></td> + <td>์—๋Ÿฌ ๋ฉ”์‹œ์ง€์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” enum ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;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">&nbsp;&nbsp;<b>validator</b></td> + <td><b><img align="center" height="32px">&nbsp;&nbsp;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">&nbsp;&nbsp;<b>view</b></td> + <td><b><img align="center" height="32px">&nbsp;&nbsp;PrintMessage</b></td> + <td>์ž…์ถœ๋ ฅ์— ๊ด€ํ•œ ๋ฉ”์‹œ์ง€ ์ƒ์ˆ˜์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” enum ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;InputView</b></td> + <td>์ž…๋ ฅ์„ ๋‹ด๋‹นํ•˜๋Š” View ํด๋ž˜์Šค</td> + </tr> + <tr> + <td><b><img align="center" height="32px">&nbsp;&nbsp;OutputView</b></td> + <td>์ถœ๋ ฅ์„ ๋‹ด๋‹นํ•˜๋Š” View ํด๋ž˜์Šค</td> + </tr> + +</table> +</div> + +![img.png](img.png) \ 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 ํ•„๋“œ๋กœ ์„ ์–ธํ•ด์•ผํ•˜๋Š” ๊ทผ๊ฑฐ๊ฐ€ ์—†์œผ๋ฉด ์ค„์ด๋Š”๊ฒƒ๋„ ๋งž๋‹ค๊ณ  ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค.