code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -61,7 +61,10 @@ class Nav extends React.Component { </a> <a href="/"> <div className="profile-image"> - <img src="images/profile/me.jpeg" alt="me" /> + <img + src="/images/hyunchanpark//images/user-icon.jpg" + alt="me" + /> </div> </a> </div>
JavaScript
[์ฐธ๊ณ ](https://stackoverflow.com/questions/43087007/react-link-vs-a-tag-and-arrow-function) `<a>`๋Š” ์‚ฌ์šฉํ•˜๋ฉด ์ƒˆ๋กœ๊ณ ์นจ ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ html์„ ์ƒˆ๋กœ ๋‹ค ๋ฐ›์•„ ์˜ค๋Š” ๋ฐ˜๋ฉด, `<Link>`๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ปดํฌ๋„ŒํŠธ๋งŒ ๋ฐ”๊ฟ”์ค๋‹ˆ๋‹ค. ๋ Œ๋”๋ง ์ตœ์ ํ™”๋ฅผ ์œ„ํ•ด์„œ `<Link>` ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”!
@@ -22,6 +22,7 @@ nav { .title { margin: 0; font-size: 30px; + font-weight: 400; font-family: 'Lobster', cursive; } @@ -44,5 +45,30 @@ nav { font-weight: 300; } } + + .path-icon { + display: flex; + + a { + margin-left: 24px; + background-color: transparent; + border: none; + + &:hover { + text-decoration: none; + } + + .profile-image { + width: 22px; + height: 22px; + + img { + width: 22px; + height: 22px; + border-radius: 50%; + } + } + } + } } }
Unknown
font-weight:400์ด ๊ธฐ๋ณธ์†์„ฑ์ธ๋ฐ ๋”ฐ๋กœ ๋ถ€์—ฌํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
์ด ๊ฐ’์€ ์ปดํฌ๋„ŒํŠธ๋‚ด๋ถ€์— ๊ฐ’์œผ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๊ฒŒ ์ข‹์•„๋ณด์ด๋Š”๋ฐ ์ปดํฌ๋„ŒํŠธ ๋ฐ”๊นฅ์—์„œ ์„ ์–ธํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
```suggestion return reg.test(value) ``` test method์˜ return๊ฐ’ ์ž์ฒด๊ฐ€ boolean์ด๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์ด ๊ฐ„๊ฒฐํ•˜๊ฒŒ ํ‘œํ˜„ ๊ฐ€๋Šฅํ•ด๋ณด์ž…๋‹ˆ๋‹ค!
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
๊ธฐ๋Šฅ๋ณ„ ํ•จ์ˆ˜ ๋ถ„๋ฆฌํ•˜๊ณ  ์ž˜ ์žฌํ™œ์šฉํ•˜์‹  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!๐Ÿ‘
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
validateInputData ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  ๊ณ„์‹œ์ง€๋งŒ ์ด ํ•จ์ˆ˜๋Š” ์‹คํ–‰๋˜๊ธฐ๋งŒ ํ•˜๊ณ  ๋ฆฌํ„ด๊ฐ’์„ ์–ด๋””์—๋„ ํ™œ์šฉํ•˜์ง€ ์•Š๊ณ  ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์‹ค์งˆ์ ์œผ๋กœ ์–ด๋–ค ์˜๋ฏธ๋„ ์—†๋Š” ์ฝ”๋“œ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
`const {name, value} = e.target;` ์œผ๋กœ ๊ตฌ์กฐ๋ถ„ํ•ดํ•ด์„œ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ์ข€ ๋” ๊ฐ„๊ฒฐํ•˜๊ฒ ๋„ค์š”!
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
๐Ÿ‘ state๊ฐ’๋„ ๊ตฌ์กฐ๋ถ„ํ•ดํ•ด์„œ ์‚ฌ์šฉํ•˜๋ฉด ์ข€ ๋” ๊ฐ„๊ฒฐํ•ด๋ณด์ผ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
๊ฑด์šฐ๋‹˜์ด ๋ฆฌ๋ทฐ ์ž˜ ๋‚จ๊ฒจ์ฃผ์…จ๋„ค์š” ํ™•์ธํ•˜๊ณ  ๋ฐ˜์˜ํ•ด๋ณด์„ธ์š”!๐Ÿ‘
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
์• ์ดˆ์— boolean์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜์ด๊ธฐ ๋•Œ๋ฌธ์— not ์—ฐ์‚ฐ์ž๋ฅผ ํ™œ์šฉํ•ด์„œ ```suggestion const isDisabled = !this.validateInputData(userId, userPw) ``` button tag์—์„œ ํ•œ๋ฒˆ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ๊ฐ’์ด๋ผ๋ฉด ๋”ฐ๋กœ ๋ณ€์ˆ˜์„ ์–ธ ํ• ๋‹น๊ณผ์ • ๊ฑฐ์น  ํ•„์š” ์—†์ด ๋ฒ„ํŠผ ํƒœ๊ทธ ๋‚ด์— ๋ฐ”๋กœ ์ ์–ด์ค˜๋„ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,121 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withRouter } from 'react-router'; +import './Login.scss'; + +const REGEXP = { + emailRegExp: + /[a-zA-Z0-9.-_+!]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]{2,}(?:.[a-zA-Z0-9]{2,3})?/, + passwordRegExp: /[a-zA-Z0-9]{5,100}/, +}; + +class Login extends React.Component { + constructor(props) { + super(props); + + this.state = { userId: '', userPw: '' }; + } + + validate = (value, regExp) => { + const reg = new RegExp(regExp); + return reg.test(value); + }; + + validateInputData = (id, pw) => { + return ( + this.validate(id, REGEXP.emailRegExp) && + this.validate(pw, REGEXP.passwordRegExp) + ); + }; + + handleInput = e => { + const { name, value } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleSubmit = e => { + e.preventDefault(); + + const { userId, userPw } = this.state; + if (!this.validateInputData(userId, userPw)) return; + + this.props.history.push('/main'); + }; + + render() { + const { userId, userPw } = this.state; + + return ( + <> + <section className="entire-container"> + <div className="entire"> + <div className="entire_top content"> + <div className="login_container"> + <h1>westagram</h1> + <div className="form_container"> + <form onSubmit={this.handleSubmit}> + <input + type="text" + name="userId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + value={userId} + onChange={this.handleInput} + /> + <input + type="password" + name="userPw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + value={userPw} + onChange={this.handleInput} + /> + <Link to="/main"> + <button + className="login-button" + type="submit" + disabled={!this.validateInputData(userId, userPw)} + onClick={this.handleSubmit} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + + <div className="line_container"> + <div className="line"></div> + <div className="line-word">๋˜๋Š”</div> + <div className="line"></div> + </div> + + <button className="social-login-button"> + <img + src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDQ1NS43MyA0NTUuNzMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQ1NS43MyA0NTUuNzM7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIHN0eWxlPSJmaWxsOiMzQTU1OUY7IiBkPSJNMCwwdjQ1NS43M2gyNDIuNzA0VjI3OS42OTFoLTU5LjMzdi03MS44NjRoNTkuMzN2LTYwLjM1M2MwLTQzLjg5MywzNS41ODItNzkuNDc1LDc5LjQ3NS03OS40NzUNCgloNjIuMDI1djY0LjYyMmgtNDQuMzgyYy0xMy45NDcsMC0yNS4yNTQsMTEuMzA3LTI1LjI1NCwyNS4yNTR2NDkuOTUzaDY4LjUyMWwtOS40Nyw3MS44NjRoLTU5LjA1MVY0NTUuNzNINDU1LjczVjBIMHoiLz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjwvc3ZnPg0K" + alt="facebook button" + /> + <span>Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</span> + </button> + </div> + + <Link to="/" className="search-password"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </div> + </div> + + <div className="entire_bottom content"> + <p> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”?&nbsp; + <a href="https://www.instagram.com/accounts/emailsignup/"> + ๊ฐ€์ž…ํ•˜๊ธฐ + </a> + </p> + </div> + </div> + </section> + </> + ); + } +} + +export default withRouter(Login);
JavaScript
```suggestion disabled={!this.validateInputData(userId, userPw)} ``` ์œ„์— ๋‹ฌ์•„๋“œ๋ฆฐ ์ฝ”๋ฉ˜ํŠธ์™€ ์ด์–ด์ง€๋Š” ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค!
@@ -0,0 +1,156 @@ +@import '../Styles/common.scss'; + +.entire-container { + @include flex-set(row, center, center); + width: 100%; + height: 100vh; + background-color: $background-default-color; + + .entire { + width: 350px; + background-color: $background-default-color; + + .entire_top { + height: 380px; + + &.content { + padding: 10px 0; + margin: 0 0 10px; + border: $border-default-set; + + .login_container { + @include flex-set(column, center, center); + + h1 { + width: 175px; + height: 51px; + line-height: 51px; + margin: 22px auto 12px; + font-family: 'Lobster', cursive; + @include font-set(40px, 100, null); + } + + .form_container { + @include flex-set(column); + margin: 20px 0 0; + + form { + @include flex-set(column); + + input { + width: 268px; + height: 38px; + padding: 9px 0 7px 8px; + margin: 0 0 7px 0; + border: $border-default-set; + + background: $background-default-color; + color: #8e8e8e; + + @include font-set($font-small-size, inherit, 36px); + overflow: hidden; + outline: 0; + text-overflow: ellipsis; + } + + a { + margin: 9px 0 18px; + + .login-button { + width: 268px; + height: 30px; + background-color: rgb(0, 149, 246); + border-radius: 4px; + color: #fff; + font-weight: $font-bold-weight; + opacity: 1; + + &:disabled { + cursor: default; + opacity: 0.3; + } + } + } + } + + .line_container { + display: flex; + width: 268px; + margin: 0 0 28px 0; + + .line { + position: relative; + top: 0.45em; + height: 1px; + flex-grow: 1; + background-color: #dbdbdb; + } + + .line-word { + color: #8e8e8e; + @include font-set($font-small-size, $font-bold-weight, 15px); + margin: 0 25px; + } + } + + .social-login-button { + display: inline; + margin-bottom: 20px; + border: none; + background-color: #fff; + + &:hover { + cursor: pointer; + } + + img { + position: relative; + top: 3px; + display: inline-block; + width: 16px; + height: 16px; + margin-right: 8px; + } + + span { + color: rgb(56, 81, 133); + @include font-set($font-default-size, $font-bold-weight); + } + } + } + + .search-password { + color: #00376b; + text-align: center; + } + } + } + } + + .entire_bottom { + @include flex-set(); + height: 63px; + color: $font-default-color; + + @include font-set($font-default-size, inherit, 63px); + text-align: center; + + &.content { + padding: 10px 0; + margin: 0 0 10px; + border: $border-default-set; + } + + p { + color: $font-default-color; + font-size: $font-default-size; + + a { + color: #0095f6; + font-weight: 600; + text-decoration: none; + } + } + } + } +}
Unknown
์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์œผ๋กœ nesting ์ ์šฉํ•ด์ฃผ์„ธ์š”! ์ด๋ ‡๊ฒŒ ๋˜๋ฉด ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ๋“ค์˜ ์Šคํƒ€์ผ์—๋„ ์˜ํ–ฅ์„ ๋ฏธ์น  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,156 @@ +@import '../Styles/common.scss'; + +.entire-container { + @include flex-set(row, center, center); + width: 100%; + height: 100vh; + background-color: $background-default-color; + + .entire { + width: 350px; + background-color: $background-default-color; + + .entire_top { + height: 380px; + + &.content { + padding: 10px 0; + margin: 0 0 10px; + border: $border-default-set; + + .login_container { + @include flex-set(column, center, center); + + h1 { + width: 175px; + height: 51px; + line-height: 51px; + margin: 22px auto 12px; + font-family: 'Lobster', cursive; + @include font-set(40px, 100, null); + } + + .form_container { + @include flex-set(column); + margin: 20px 0 0; + + form { + @include flex-set(column); + + input { + width: 268px; + height: 38px; + padding: 9px 0 7px 8px; + margin: 0 0 7px 0; + border: $border-default-set; + + background: $background-default-color; + color: #8e8e8e; + + @include font-set($font-small-size, inherit, 36px); + overflow: hidden; + outline: 0; + text-overflow: ellipsis; + } + + a { + margin: 9px 0 18px; + + .login-button { + width: 268px; + height: 30px; + background-color: rgb(0, 149, 246); + border-radius: 4px; + color: #fff; + font-weight: $font-bold-weight; + opacity: 1; + + &:disabled { + cursor: default; + opacity: 0.3; + } + } + } + } + + .line_container { + display: flex; + width: 268px; + margin: 0 0 28px 0; + + .line { + position: relative; + top: 0.45em; + height: 1px; + flex-grow: 1; + background-color: #dbdbdb; + } + + .line-word { + color: #8e8e8e; + @include font-set($font-small-size, $font-bold-weight, 15px); + margin: 0 25px; + } + } + + .social-login-button { + display: inline; + margin-bottom: 20px; + border: none; + background-color: #fff; + + &:hover { + cursor: pointer; + } + + img { + position: relative; + top: 3px; + display: inline-block; + width: 16px; + height: 16px; + margin-right: 8px; + } + + span { + color: rgb(56, 81, 133); + @include font-set($font-default-size, $font-bold-weight); + } + } + } + + .search-password { + color: #00376b; + text-align: center; + } + } + } + } + + .entire_bottom { + @include flex-set(); + height: 63px; + color: $font-default-color; + + @include font-set($font-default-size, inherit, 63px); + text-align: center; + + &.content { + padding: 10px 0; + margin: 0 0 10px; + border: $border-default-set; + } + + p { + color: $font-default-color; + font-size: $font-default-size; + + a { + color: #0095f6; + font-weight: 600; + text-decoration: none; + } + } + } + } +}
Unknown
๊ณตํ†ต์ ์œผ๋กœ ์ ์šฉ๋˜์–ด์•ผ ํ•˜๋Š” ์†์„ฑ์ด๋ผ๋ฉด common์— ๋„ฃ์–ด์ฃผ์‹œ๋Š” ๊ฒŒ ๋งž์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,156 @@ +@import '../Styles/common.scss'; + +.entire-container { + @include flex-set(row, center, center); + width: 100%; + height: 100vh; + background-color: $background-default-color; + + .entire { + width: 350px; + background-color: $background-default-color; + + .entire_top { + height: 380px; + + &.content { + padding: 10px 0; + margin: 0 0 10px; + border: $border-default-set; + + .login_container { + @include flex-set(column, center, center); + + h1 { + width: 175px; + height: 51px; + line-height: 51px; + margin: 22px auto 12px; + font-family: 'Lobster', cursive; + @include font-set(40px, 100, null); + } + + .form_container { + @include flex-set(column); + margin: 20px 0 0; + + form { + @include flex-set(column); + + input { + width: 268px; + height: 38px; + padding: 9px 0 7px 8px; + margin: 0 0 7px 0; + border: $border-default-set; + + background: $background-default-color; + color: #8e8e8e; + + @include font-set($font-small-size, inherit, 36px); + overflow: hidden; + outline: 0; + text-overflow: ellipsis; + } + + a { + margin: 9px 0 18px; + + .login-button { + width: 268px; + height: 30px; + background-color: rgb(0, 149, 246); + border-radius: 4px; + color: #fff; + font-weight: $font-bold-weight; + opacity: 1; + + &:disabled { + cursor: default; + opacity: 0.3; + } + } + } + } + + .line_container { + display: flex; + width: 268px; + margin: 0 0 28px 0; + + .line { + position: relative; + top: 0.45em; + height: 1px; + flex-grow: 1; + background-color: #dbdbdb; + } + + .line-word { + color: #8e8e8e; + @include font-set($font-small-size, $font-bold-weight, 15px); + margin: 0 25px; + } + } + + .social-login-button { + display: inline; + margin-bottom: 20px; + border: none; + background-color: #fff; + + &:hover { + cursor: pointer; + } + + img { + position: relative; + top: 3px; + display: inline-block; + width: 16px; + height: 16px; + margin-right: 8px; + } + + span { + color: rgb(56, 81, 133); + @include font-set($font-default-size, $font-bold-weight); + } + } + } + + .search-password { + color: #00376b; + text-align: center; + } + } + } + } + + .entire_bottom { + @include flex-set(); + height: 63px; + color: $font-default-color; + + @include font-set($font-default-size, inherit, 63px); + text-align: center; + + &.content { + padding: 10px 0; + margin: 0 0 10px; + border: $border-default-set; + } + + p { + color: $font-default-color; + font-size: $font-default-size; + + a { + color: #0095f6; + font-weight: 600; + text-decoration: none; + } + } + } + } +}
Unknown
mixin ์ž˜ ํ™œ์šฉํ•ด์ฃผ์…จ๋„ค์š”!
@@ -0,0 +1,12 @@ +package develop.baminchan; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SidedishApplication { + + public static void main(String[] args) { + SpringApplication.run(SidedishApplication.class, args); + } +}
Java
Security ์„ค์ •์ด ๋ณ„๋„ ํด๋ž˜์Šค๋กœ ๋…๋ฆฝํ•˜๋ฉด ์กฐ๊ธˆ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š”.
@@ -0,0 +1,75 @@ +package develop.baminchan.controller; + +import develop.baminchan.dto.BanchanDto; +import develop.baminchan.dto.CategoryDto; +import develop.baminchan.dto.banchan.BanchanDetailDto; +import develop.baminchan.entity.Banchan; +import develop.baminchan.service.BanchanService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api") +public class BanchanController { + + private BanchanService banchanService; + + public BanchanController(BanchanService banchanService) { + this.banchanService = banchanService; + } + + @GetMapping("/main") + public ResponseEntity<Message> findMain() { + List<BanchanDto> banchanDtoList = banchanService.findBanchansByTag("main"); + Message message = new Message(Message.OK, banchanDtoList); + return new ResponseEntity(message, HttpStatus.OK); + } + + @GetMapping("/soup") + public ResponseEntity<Message> findSoup() { + List<BanchanDto> banchanDtoList = banchanService.findBanchansByTag("soup"); + Message message = new Message(Message.OK, banchanDtoList); + return new ResponseEntity(message, HttpStatus.OK); + } + + @GetMapping("/side") + public ResponseEntity<Message> findSide() { + List<BanchanDto> banchanDtoList = banchanService.findBanchansByTag("side"); + Message message = new Message(Message.OK, banchanDtoList); + return new ResponseEntity(message, HttpStatus.OK); + } + @GetMapping("/main/{detail_hash}") + public BanchanDto findOneMain(@PathVariable String detail_hash) { + BanchanDto banchanDto = banchanService.findBanchanByDetailHash(detail_hash); + return banchanDto; + } + + @GetMapping("/soup/{detail_hash}") + public BanchanDto findOneSoup(@PathVariable String detail_hash) { + BanchanDto banchanDto = banchanService.findBanchanByDetailHash(detail_hash); + return banchanDto; + } + + @GetMapping("/side/{detail_hash}") + public BanchanDto findOneSide(@PathVariable String detail_hash) { + BanchanDto banchanDto = banchanService.findBanchanByDetailHash(detail_hash); + return banchanDto; + } + + + @GetMapping("/detail/{detail_hash}") + public BanchanDetailDto findOneDetail(@PathVariable String detail_hash) { + BanchanDetailDto banchanDetailDto = banchanService.findBanchanDetailByDetailHash(detail_hash); + System.out.println(banchanDetailDto); + return banchanDetailDto; + } + + @PostMapping("/create") + public String create(@RequestBody Banchan banchan) { + banchanService.createBanchan(banchan); + return "success"; + } +}
Java
`@PathVariable` ์•ˆ์— path variable name์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ํ•„๋“œ๊ฐ€ ์žˆ์„ ๊ฑฐ๋ผ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์–ด๋– ํ•œ ์ˆœ๊ฐ„์—๋„ ์ž๋ฐ”์˜ ๊ธฐ๋ณธ์  ์ฝ”๋”ฉ ์ปจ๋ฒค์…˜์„ ๊ณ„์† ์ค€์ˆ˜ํ•ด์ฃผ์„ธ์š”.
@@ -0,0 +1,24 @@ +package develop.baminchan.controller; + +public class Message { + public static final int OK = 200; + public static final int BAD_REQUEST = 400; + public static final int NOT_FOUND = 404; + public static final int INTERNAL_SERVER_ERROR = 500; + + private int statusCode; + private Object body; + + public Message(int statusCode, Object body) { + this.statusCode = statusCode; + this.body = body; + } + + public int getStatusCode() { + return statusCode; + } + + public Object getBody() { + return body; + } +}
Java
`enum` ์œผ๋กœ ๊ด€๋ฆฌํ•ด๋ณด์‹œ๋ฉด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,78 @@ +package develop.baminchan.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import develop.baminchan.entity.Banchan; + +import java.util.Set; + +import static develop.baminchan.dto.util.StringConvertor.convertToSet; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BanchanDto { + private String detail_hash; + private String image; + private String alt; + private Set<String> delivery_type; + private String title; + private String description; + private String n_price; + private String s_price; + private Set<String> badge; + + protected BanchanDto() { + + } + + private BanchanDto(Banchan banchan) { + this.detail_hash = banchan.getDetail_hash(); + this.image = banchan.getImage(); + this.alt = banchan.getAlt(); + this.delivery_type = convertToSet(banchan.getDelivery_type()); + this.title = banchan.getTitle(); + this.description = banchan.getDescription(); + this.n_price = banchan.getN_price(); + this.s_price = banchan.getS_price(); + this.badge = convertToSet(banchan.getBadge()); + } + + // Entity -> DTO + public static BanchanDto of(Banchan banchan) { + return new BanchanDto(banchan); + } + + public String getDetail_hash() { + return detail_hash; + } + + public String getImage() { + return image; + } + + public String getAlt() { + return alt; + } + + public Set<String> getDelivery_type() { + return delivery_type; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public String getN_price() { + return n_price; + } + + public String getS_price() { + return s_price; + } + + public Set<String> getBadge() { + return badge; + } +}
Java
`@JsonProperty` ๋ฅผ ํ†ตํ•ด JSON field์˜ ์ด๋ฆ„ ์ •ํ•ด์ฃผ์‹œ๋ฉด ๋  ๊ฒƒ ๊ฐ™์•„์š”. ์–ธ๋”์Šค์ฝ”์–ด๋Š” ์ž๋ฐ” ์ฝ”๋“œ์— ์—†์—ˆ์œผ๋ฉด ํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,78 @@ +package develop.baminchan.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import develop.baminchan.entity.Banchan; + +import java.util.Set; + +import static develop.baminchan.dto.util.StringConvertor.convertToSet; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BanchanDto { + private String detail_hash; + private String image; + private String alt; + private Set<String> delivery_type; + private String title; + private String description; + private String n_price; + private String s_price; + private Set<String> badge; + + protected BanchanDto() { + + } + + private BanchanDto(Banchan banchan) { + this.detail_hash = banchan.getDetail_hash(); + this.image = banchan.getImage(); + this.alt = banchan.getAlt(); + this.delivery_type = convertToSet(banchan.getDelivery_type()); + this.title = banchan.getTitle(); + this.description = banchan.getDescription(); + this.n_price = banchan.getN_price(); + this.s_price = banchan.getS_price(); + this.badge = convertToSet(banchan.getBadge()); + } + + // Entity -> DTO + public static BanchanDto of(Banchan banchan) { + return new BanchanDto(banchan); + } + + public String getDetail_hash() { + return detail_hash; + } + + public String getImage() { + return image; + } + + public String getAlt() { + return alt; + } + + public Set<String> getDelivery_type() { + return delivery_type; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public String getN_price() { + return n_price; + } + + public String getS_price() { + return s_price; + } + + public Set<String> getBadge() { + return badge; + } +}
Java
`private` ์œผ๋กœ ๊ฐ€๋ ค๋†จ์œผ๋ฏ€๋กœ ๋ชจ๋“  ํ•„๋“œ์— ํ•ด๋‹นํ•˜๋Š” ํŒŒ๋ผ๋ฉ”ํ„ฐ๋ฅผ ๋‹ค ์„ ์–ธํ•ด์ฃผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค. ๋˜ ๊ทธ๋ ‡๊ฒŒ ํ•ด์•ผ ์ถ”ํ›„ ํ™•์žฅ์„ฑ ์ธก๋ฉด์—์„œ๋„ ์ข‹์„ ๊ฑฐ๋ผ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. `Banchan` ์„ ๋ฐ›์•„์„œ ํ•˜๋‚˜์”ฉ ์ •๋ณด๋ฅผ ๊บผ๋‚ด๋Š” ์ฑ…์ž„์€ `.of()` ์—๊ฒŒ ๋งก๊ธฐ๊ณ  ์ƒ์„ฑ์ž์—์„  ๋‹จ์ˆœ ๊ฐ’ ํ• ๋‹น์— ์ง‘์ค‘ํ•˜๋ฉด ์–ด๋–จ๊นŒ์š”.
@@ -0,0 +1,45 @@ +package develop.baminchan.dto; + +import develop.baminchan.entity.Category; +import org.springframework.data.annotation.Id; + +import java.util.ArrayList; +import java.util.List; + +public class CategoryDto { + @Id + private int id; + + private String category_id; + private String name; + + private List<BanchanDto> items = new ArrayList<>(); + + public CategoryDto(String category_id, String name) { + this.category_id = category_id; + this.name = name; + } + + public CategoryDto(Category category, List<BanchanDto> banchanDtoList) { + this.category_id = category.getCategory_id(); + this.name = category.getName(); + this.items = banchanDtoList; + } + + // Entity -> DTO + public static CategoryDto of(Category category, List<BanchanDto> banchanDtoList) { + return new CategoryDto(category, banchanDtoList); + } + + public String getCategory_id() { + return category_id; + } + + public String getName() { + return name; + } + + public List<BanchanDto> getItems() { + return items; + } +}
Java
DTO์ธ๋ฐ `@Id`.... ๊ดœ์ฐฎ์„๊นŒ์š”?
@@ -0,0 +1,20 @@ +package develop.baminchan.dto.util; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class StringConvertor { + private StringConvertor() { + } + + public static Set<String> convertToSet(String column) { + if (column == null) { + return null; + } + Set<String> set = new HashSet<>(); + String[] arr = column.split(", "); + set.addAll(Arrays.asList(arr)); + return set; + } +}
Java
[์ด ๋งํฌ](https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#jdbc.custom-converters) ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์‹œ๊ณ  ํ‘œ์ค€ ์ŠคํŽ™์— ๋งž๋Š” ํด๋ž˜์Šค๋กœ ์ „ํ™˜์„ ๋ถ€ํƒ๋“œ๋ฆด๊ฒŒ์š”.
@@ -0,0 +1,35 @@ +package develop.baminchan.entity; + +import org.springframework.data.annotation.Id; + +public class Order { + @Id + private Long id; + + private String client_id; + private String detail_hash; + private int quantity; + + public Order(Long id, String client_id, String detail_hash, int quantity) { + this.id = id; + this.client_id = client_id; + this.detail_hash = detail_hash; + this.quantity = quantity; + } + + public Long getId() { + return id; + } + + public String getClient_id() { + return client_id; + } + + public String getDetail_hash() { + return detail_hash; + } + + public int getQuantity() { + return quantity; + } +}
Java
๊ตณ์ด ์•ฝ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์‹ค ํ•„์š”๋Š” ์—†์–ด ๋ณด์ด๊ธฐ๋Š” ํ•ฉ๋‹ˆ๋‹ค. ํ…Œ์ด๋ธ” ์ƒ์—๋„ ์ด ์ด๋ฆ„์œผ๋กœ ์นผ๋Ÿผ์ด ๋“ค์–ด๊ฐ€์žˆ๋‚˜์š”? ๊ทธ๋ ‡๋‹ค๋ฉด ํ’€ ๋„ค์ž„์ธ `quantity` ๋กœ์˜ ์ „ํ™˜์„ ์ œ์•ˆ๋“œ๋ฆฝ๋‹ˆ๋‹ค.
@@ -0,0 +1,57 @@ +package develop.baminchan.service; + +import develop.baminchan.dto.BanchanDto; +import develop.baminchan.dto.CategoryDto; +import develop.baminchan.entity.Banchan; +import develop.baminchan.entity.Category; +import develop.baminchan.repository.BanchanRepository; +import develop.baminchan.repository.CategoryRepository; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Service +public class CategoryService { + private CategoryRepository categoryRepository; + private BanchanRepository banchanRepository; + + public CategoryService(CategoryRepository categoryRepository, BanchanRepository banchanRepository) { + this.categoryRepository = categoryRepository; + this.banchanRepository = banchanRepository; + } + + public List<CategoryDto> findAllBestBanchansByCategories() { + Iterable<Category> categoryList = categoryRepository.findAll(); + Set<String> setOfCategoryIds = new HashSet<>(); + for (Category category : categoryList) { + setOfCategoryIds.add(category.getCategory_id()); + } + System.out.println(setOfCategoryIds); //ํ…Œ์ŠคํŠธ // null๋„ ๋“ค์–ด๊ฐ€๋‚˜? + + List<CategoryDto> categoryDtoList = new ArrayList<>(); + for (String category_id : setOfCategoryIds) { + categoryDtoList.add(findBestBanchansByCategory(category_id)); + } + return categoryDtoList; + } + + public CategoryDto findBestBanchansByCategory(String category_id) { + Category category = categoryRepository.findCategoryByCategory_id(category_id); + CategoryDto categoryDto = CategoryDto.of(category, findBanchanListByCategoryId(category_id)); + return categoryDto; + } + + private List<BanchanDto> findBanchanListByCategoryId(String catrgory_id) { + List<BanchanDto> banchanDtoList = new ArrayList<>(); + List<Banchan> banchanList = new ArrayList<>(); + + banchanList = banchanRepository.findBanchansByCategory_id(catrgory_id); + for (int i = 0; i < banchanList.size(); i++) { + banchanDtoList.add(BanchanDto.of(banchanList.get(i))); + } + return banchanDtoList; + } +}
Java
`logger` ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”.
@@ -0,0 +1,57 @@ +package develop.baminchan.service; + +import develop.baminchan.dto.BanchanDto; +import develop.baminchan.dto.CategoryDto; +import develop.baminchan.entity.Banchan; +import develop.baminchan.entity.Category; +import develop.baminchan.repository.BanchanRepository; +import develop.baminchan.repository.CategoryRepository; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Service +public class CategoryService { + private CategoryRepository categoryRepository; + private BanchanRepository banchanRepository; + + public CategoryService(CategoryRepository categoryRepository, BanchanRepository banchanRepository) { + this.categoryRepository = categoryRepository; + this.banchanRepository = banchanRepository; + } + + public List<CategoryDto> findAllBestBanchansByCategories() { + Iterable<Category> categoryList = categoryRepository.findAll(); + Set<String> setOfCategoryIds = new HashSet<>(); + for (Category category : categoryList) { + setOfCategoryIds.add(category.getCategory_id()); + } + System.out.println(setOfCategoryIds); //ํ…Œ์ŠคํŠธ // null๋„ ๋“ค์–ด๊ฐ€๋‚˜? + + List<CategoryDto> categoryDtoList = new ArrayList<>(); + for (String category_id : setOfCategoryIds) { + categoryDtoList.add(findBestBanchansByCategory(category_id)); + } + return categoryDtoList; + } + + public CategoryDto findBestBanchansByCategory(String category_id) { + Category category = categoryRepository.findCategoryByCategory_id(category_id); + CategoryDto categoryDto = CategoryDto.of(category, findBanchanListByCategoryId(category_id)); + return categoryDto; + } + + private List<BanchanDto> findBanchanListByCategoryId(String catrgory_id) { + List<BanchanDto> banchanDtoList = new ArrayList<>(); + List<Banchan> banchanList = new ArrayList<>(); + + banchanList = banchanRepository.findBanchansByCategory_id(catrgory_id); + for (int i = 0; i < banchanList.size(); i++) { + banchanDtoList.add(BanchanDto.of(banchanList.get(i))); + } + return banchanDtoList; + } +}
Java
`.stream().map()` ์‚ฌ์šฉ์œผ๋กœ ์•ž์„  for loop์ด๋ž‘ ์—ฌ๊ธฐ๊นŒ์ง€ ์—†์•จ ์ˆ˜ ์žˆ์–ด ๋ณด์ž…๋‹ˆ๋‹ค.
@@ -0,0 +1,57 @@ +package develop.baminchan.service; + +import develop.baminchan.dto.BanchanDto; +import develop.baminchan.dto.CategoryDto; +import develop.baminchan.entity.Banchan; +import develop.baminchan.entity.Category; +import develop.baminchan.repository.BanchanRepository; +import develop.baminchan.repository.CategoryRepository; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Service +public class CategoryService { + private CategoryRepository categoryRepository; + private BanchanRepository banchanRepository; + + public CategoryService(CategoryRepository categoryRepository, BanchanRepository banchanRepository) { + this.categoryRepository = categoryRepository; + this.banchanRepository = banchanRepository; + } + + public List<CategoryDto> findAllBestBanchansByCategories() { + Iterable<Category> categoryList = categoryRepository.findAll(); + Set<String> setOfCategoryIds = new HashSet<>(); + for (Category category : categoryList) { + setOfCategoryIds.add(category.getCategory_id()); + } + System.out.println(setOfCategoryIds); //ํ…Œ์ŠคํŠธ // null๋„ ๋“ค์–ด๊ฐ€๋‚˜? + + List<CategoryDto> categoryDtoList = new ArrayList<>(); + for (String category_id : setOfCategoryIds) { + categoryDtoList.add(findBestBanchansByCategory(category_id)); + } + return categoryDtoList; + } + + public CategoryDto findBestBanchansByCategory(String category_id) { + Category category = categoryRepository.findCategoryByCategory_id(category_id); + CategoryDto categoryDto = CategoryDto.of(category, findBanchanListByCategoryId(category_id)); + return categoryDto; + } + + private List<BanchanDto> findBanchanListByCategoryId(String catrgory_id) { + List<BanchanDto> banchanDtoList = new ArrayList<>(); + List<Banchan> banchanList = new ArrayList<>(); + + banchanList = banchanRepository.findBanchansByCategory_id(catrgory_id); + for (int i = 0; i < banchanList.size(); i++) { + banchanDtoList.add(BanchanDto.of(banchanList.get(i))); + } + return banchanDtoList; + } +}
Java
์—ฌ๊ธฐ๋„ `.stream().map()` ์œผ๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,20 @@ +package develop.baminchan.dto.util; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class StringConvertor { + private StringConvertor() { + } + + public static Set<String> convertToSet(String column) { + if (column == null) { + return null; + } + Set<String> set = new HashSet<>(); + String[] arr = column.split(", "); + set.addAll(Arrays.asList(arr)); + return set; + } +}
Java
๋ฐ์ดํ„ฐ ๋ณ€ํ™˜์„ ์œ„ํ•œ ์ปจ๋ฒ„ํ„ฐ์— ๋Œ€ํ•œ ํ‘œ์ค€ ์ŠคํŽ™์ด ์žˆ์—ˆ๊ตฐ์š”..์Šคํ”„๋ง ๋ฌธ์„œ ์ „์ฒด์ ์œผ๋กœ ๊ผญ ํ•œ๋ฒˆ ์ฝ์–ด๋ด์•ผ๊ฒ ๋„ค์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,94 @@ +package develop.baminchan.entity; + +import develop.baminchan.entity.banchan.BanchanDetail; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Embedded; + +public class Banchan { + @Id + private Long id; + + private String detail_hash; + private String image; + private String alt; + private String delivery_type; + private String title; + private String description; + private String n_price; + private String s_price; + private String badge; + + private String tag; + private String category_id; + + @Embedded.Nullable + private BanchanDetail banchanDetail; + + public Banchan(Long id, String detail_hash, String image, String alt, String delivery_type, String title, String description, String n_price, String s_price, String badge, String tag, String category_id, BanchanDetail banchanDetail) { + this.id = id; + this.detail_hash = detail_hash; + this.image = image; + this.alt = alt; + this.delivery_type = delivery_type; + this.title = title; + this.description = description; + this.n_price = n_price; + this.s_price = s_price; + this.badge = badge; + this.tag = tag; + this.category_id = category_id; + this.banchanDetail = banchanDetail; + } + + public Long getId() { + return id; + } + + public String getDetail_hash() { + return detail_hash; + } + + public String getImage() { + return image; + } + + public String getAlt() { + return alt; + } + + public String getDelivery_type() { + return delivery_type; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public String getN_price() { + return n_price; + } + + public String getS_price() { + return s_price; + } + + public String getBadge() { + return badge; + } + + public String getTag() { + return tag; + } + + public String getCategory_id() { + return category_id; + } + + public BanchanDetail getBanchanDetail() { + return banchanDetail; + } +}
Java
๋‹ค๋ฅธ ๋ฆฌ๋ทฐ์—์„œ ์ด๋Ÿฐ ๋ฅ˜์˜ ์ƒ์„ฑ์ž๋ฅผ ๊ต‰์žฅํžˆ ์‹ซ์–ดํ•˜์‹ ๋‹ค๊ณ  ํ–ˆ์—ˆ๋Š”๋ฐ ์—ฌ๊ธฐ๋„ ๋˜‘๊ฐ™์€ ๋ถ€๋ถ„ ๋งž๋‚˜์š”?
@@ -0,0 +1,30 @@ +package nextstep.security.context; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.web.filter.GenericFilterBean; + +import java.io.IOException; + +public class SecurityContextHolderFilter extends GenericFilterBean { + private final SecurityContextRepository securityContextRepository = HttpSessionSecurityContextRepository.getInstance(); + + @Override + public void doFilter( + ServletRequest request, + ServletResponse response, + FilterChain chain + ) throws IOException, ServletException { + try { + SecurityContextHolder.setContext( + securityContextRepository.loadContext((HttpServletRequest) request) + ); + chain.doFilter(request, response); + } finally { + SecurityContextHolder.clearContext(); + } + } +}
Java
chain.doFilter(request, response) ์ค‘ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด clearContext()๊ฐ€ ํ˜ธ์ถœ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š” finally ๋ธ”๋ก์—์„œ ํ˜ธ์ถœํ•˜๋„๋ก ๋ณ€๊ฒฝํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ๐Ÿ˜„
@@ -0,0 +1,9 @@ +package nextstep.security.exception; + +public class AuthenticationException extends RuntimeException { + public AuthenticationException() {} + + public AuthenticationException(String message) { + super(message); + } +}
Java
ํ˜„์žฌ `AuthenticationException`์„ ์‹ฑ๊ธ€ํ„ด ์ธ์Šคํ„ด์Šค๋กœ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋‘๊ณ  ์žˆ๋Š”๋ฐ์š”. ์ด ๋ฐฉ์‹์€ ๋ถˆํ•„์š”ํ•œ ๊ฐ์ฒด ์ƒ์„ฑ์„ ๋ฐฉ์ง€ํ•˜๊ณ  ์ผ๊ด€๋œ ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€ ์ œ๊ณต์ด๋ผ๋Š” ์žฅ์ ์ด ์žˆ์ง€๋งŒ, ์Šคํƒ ํŠธ๋ ˆ์ด์Šค๊ฐ€ ๋‚จ์ง€ ์•Š๋Š”๋‹ค๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ํ˜น์‹œ ์ด ๋ถ€๋ถ„์„ ์ธ์ง€ํ•˜๊ณ  ๊ณ„์‹ค๊นŒ์š”? ๐Ÿ˜„
@@ -0,0 +1,24 @@ +package nextstep.security.authentication.manager; + +import nextstep.security.authentication.Authentication; +import nextstep.security.authentication.provider.AuthenticationProvider; +import nextstep.security.exception.AuthenticationProviderException; + +import java.util.List; + +public class ProviderManager implements AuthenticationManager { + private final List<AuthenticationProvider> providers; + + public ProviderManager(List<AuthenticationProvider> providers) { + this.providers = providers; + } + + @Override + public Authentication authenticate(Authentication authenticationToken) { + return providers.stream() + .filter(provider -> provider.supports(authenticationToken.getClass())) + .findFirst() + .orElseThrow(AuthenticationProviderException::new) + .authenticate(authenticationToken); + } +}
Java
์†Œ์†Œํ•˜์ง€๋งŒ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐœํ–‰์„ ํ•˜๋ฉด ์ข€๋” ๊ฐ€๋…์„ฑ์ด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š” ๐Ÿ˜„ ```suggestion @Override public Authentication authenticate(Authentication authenticationToken) { return providers.stream() .filter(provider -> provider.supports(authenticationToken.getClass())) .findFirst() .orElseThrow(AuthenticationException::notSupported) .authenticate(authenticationToken); } ```
@@ -0,0 +1,9 @@ +package nextstep.security.exception; + +public class AuthenticationException extends RuntimeException { + public AuthenticationException() {} + + public AuthenticationException(String message) { + super(message); + } +}
Java
์•— ์Šคํƒ ํŠธ๋ ˆ์ด์Šค ๋ถ€๋ถ„์„ ์ƒ๊ฐ์„ ๋ชปํ–ˆ๋„ค์š”. [394ed26](https://github.com/next-step/spring-security-authentication/pull/28/commits/394ed26a7c3b3dea8c17c1192cbed19393315d0f) ์ปค๋ฐ‹์—์„œ ๋งค๋ฒˆ ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋Š” ๊น€์— ์ปค์Šคํ…€ ์˜ˆ์™ธ๋ฅผ ๋” ์„ธ๋ถ„ํ™”ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,24 @@ +package nextstep.security.authentication.manager; + +import nextstep.security.authentication.Authentication; +import nextstep.security.authentication.provider.AuthenticationProvider; +import nextstep.security.exception.AuthenticationProviderException; + +import java.util.List; + +public class ProviderManager implements AuthenticationManager { + private final List<AuthenticationProvider> providers; + + public ProviderManager(List<AuthenticationProvider> providers) { + this.providers = providers; + } + + @Override + public Authentication authenticate(Authentication authenticationToken) { + return providers.stream() + .filter(provider -> provider.supports(authenticationToken.getClass())) + .findFirst() + .orElseThrow(AuthenticationProviderException::new) + .authenticate(authenticationToken); + } +}
Java
[58614f1](https://github.com/next-step/spring-security-authentication/pull/28/commits/58614f1d4af41421b2f16d76eb1323fbf34c3bf9) ์ปค๋ฐ‹์—์„œ indentation ์Šคํƒ€์ผ ๋ณ€๊ฒฝ ๋ฐ˜์˜ํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,30 @@ +package nextstep.security.context; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.web.filter.GenericFilterBean; + +import java.io.IOException; + +public class SecurityContextHolderFilter extends GenericFilterBean { + private final SecurityContextRepository securityContextRepository = HttpSessionSecurityContextRepository.getInstance(); + + @Override + public void doFilter( + ServletRequest request, + ServletResponse response, + FilterChain chain + ) throws IOException, ServletException { + try { + SecurityContextHolder.setContext( + securityContextRepository.loadContext((HttpServletRequest) request) + ); + chain.doFilter(request, response); + } finally { + SecurityContextHolder.clearContext(); + } + } +}
Java
์•— ์ •๋ง๋กœ ๊ทธ๋ ‡๊ฒ ๋„ค์š”. Filter ์—์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ๋•Œ๋ฌธ์— ๊ณ ์ƒํ•œ์ ์ด ์žˆ๋Š”๋ฐ, ์ง€์ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! โค๏ธ ํ•ญ์ƒ ๋™์ž‘ํ•ด์•ผํ•˜๋Š” ๋กœ์ง์€ finally ๋ฌธ๋ฒ• ํ™œ์šฉํ•˜๋Š” ์Šต๊ด€์„ ๊ฐ€์ ธ์•ผ๊ฒ ๋„ค์š”. ์‹ค๋ฌด์—์„œ ๋‹น์žฅ ํ™œ์šฉํ•ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“œ๋Š” ์œ ์šฉํ•œ ํ”ผ๋“œ๋ฐฑ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. [9e5ef93](https://github.com/next-step/spring-security-authentication/pull/28/commits/9e5ef934299204a6fd37b266e7dbb52f0e2b294a) ์ปค๋ฐ‹์—์„œ finally ๋ธ”๋ก์—์„œ clearContext ๊ฐ€ ํ˜ธ์ถœ๋˜๋„๋ก ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,41 @@ +package nextstep.security.authentication.token; + +import jakarta.servlet.http.HttpServletRequest; +import nextstep.security.authentication.Authentication; +import nextstep.security.exception.AuthenticationTokenException; + +import java.util.Base64; + +import static org.springframework.http.HttpHeaders.AUTHORIZATION; + +public class BasicAuthenticationTokenConverter implements AuthenticationTokenConverter { + private BasicAuthenticationTokenConverter() {} + + public static AuthenticationTokenConverter getInstance() { + return SingletonHolder.INSTANCE; + } + + @Override + public Authentication convert(HttpServletRequest request) { + try { + final byte[] decoded = Base64.getDecoder().decode( + request.getHeader(AUTHORIZATION).trim().split(" ")[1] + ); + final String[] usernameAndPassword = new String(decoded).split(":"); + return new UsernamePasswordAuthenticationToken(usernameAndPassword[0], usernameAndPassword[1]); + } catch (Exception e) { + throw new AuthenticationTokenException(); + } + } + + @Override + public boolean supports(HttpServletRequest request) { + final String authorizationHeader = request.getHeader(AUTHORIZATION); + return authorizationHeader != null + && authorizationHeader.trim().startsWith("Basic "); + } + + private static final class SingletonHolder { + private static final BasicAuthenticationTokenConverter INSTANCE = new BasicAuthenticationTokenConverter(); + } +}
Java
`HttpHeaders.AUTHORIZATION`๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿ˜„
@@ -0,0 +1,41 @@ +package nextstep.security.authentication.token; + +import jakarta.servlet.http.HttpServletRequest; +import nextstep.security.authentication.Authentication; +import nextstep.security.exception.AuthenticationTokenException; + +import java.util.Base64; + +import static org.springframework.http.HttpHeaders.AUTHORIZATION; + +public class BasicAuthenticationTokenConverter implements AuthenticationTokenConverter { + private BasicAuthenticationTokenConverter() {} + + public static AuthenticationTokenConverter getInstance() { + return SingletonHolder.INSTANCE; + } + + @Override + public Authentication convert(HttpServletRequest request) { + try { + final byte[] decoded = Base64.getDecoder().decode( + request.getHeader(AUTHORIZATION).trim().split(" ")[1] + ); + final String[] usernameAndPassword = new String(decoded).split(":"); + return new UsernamePasswordAuthenticationToken(usernameAndPassword[0], usernameAndPassword[1]); + } catch (Exception e) { + throw new AuthenticationTokenException(); + } + } + + @Override + public boolean supports(HttpServletRequest request) { + final String authorizationHeader = request.getHeader(AUTHORIZATION); + return authorizationHeader != null + && authorizationHeader.trim().startsWith("Basic "); + } + + private static final class SingletonHolder { + private static final BasicAuthenticationTokenConverter INSTANCE = new BasicAuthenticationTokenConverter(); + } +}
Java
[65922ab](https://github.com/next-step/spring-security-authentication/pull/28/commits/65922ab2a9189e06adb07bd8950a96416d723db0) ์ปค๋ฐ‹์—์„œ ๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,80 @@ +import React from 'react'; +import Comment from './Comment'; +import './CommentList.scss'; + +class CommentList extends React.Component { + constructor(props) { + super(props); + this.state = { + commentInput: '', + newComment: [], + nickname: '', + commentList: [], + commentValue: '', + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/commentData.json', { + method: 'GET', // GET method๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + }) // ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ธฐ์ž…ํ•ด๋’€์Šต๋‹ˆ๋‹ค. + .then(res => res.json()) + .then(data => { + this.setState({ + commentList: data, + }); + }); + } + + checkInput = e => { + this.setState({ + commentInput: e.target.value, + }); + }; + + inputToComment = () => { + const { newComment, commentInput } = this.state; + this.setState({ + nickname: 'wecode_bootcamp', + newComment: newComment.concat(commentInput), + }); + }; + + enterPress = e => { + if (e.key === 'Enter') { + this.inputToComment(); + } + e.target.value = ''; + }; + + render() { + const { commentValue, commentList } = this.state; + return ( + <div className="commentList"> + {commentList.map(comment => { + return ( + <Comment + key={comment.id} + nickname={comment.userName} + comment={comment.content} + /> + ); + })} + + <div className="newText"> + <input + id="typingText" + value={commentValue} + onChange={this.checkInput} + onKeyPress={this.enterPress} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...." + /> + <button onClick={this.checkInput}>๊ฒŒ์‹œ</button> + </div> + </div> + ); + } +} + +export default CommentList;
JavaScript
๋น„๊ตฌ์กฐํ™” ํ• ๋‹น์„ ์ ์šฉํ•˜๋ฉด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,23 @@ +import React from 'react'; +import './Comment.scss'; + +class NewComment extends React.Component { + render() { + // const newArray = this.props.newComment.map((commentarray, index) => ( + // <li key={index}> + // <span className="newCommentid">{this.props.nickname}</span> + // <span className="newComments">{commentarray}</span> + // </li> + // )); + return ( + <div className="comment"> + <div className="newComment"> + <span className="newCommentid">{this.props.nickname}</span> + <span className="newComments">{this.props.comment}</span> + </div> + </div> + ); + } +} + +export default NewComment;
JavaScript
- state ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, constructor ์˜ ์„ ์–ธ์ด ํ•„์š” ์—†์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,15 @@ +.comment { + .newComment { + margin-bottom: 5px; + } + + .newCommentid { + font-weight: bold; + margin-bottom: 0; + } + + .newComments { + font-weight: normal; + margin-left: 5px; + } +}
Unknown
- `.comment` ์•„๋ž˜๋กœ ๋„ค์ŠคํŒ… ํ•ด์ฃผ์„ธ์š”!
@@ -0,0 +1,80 @@ +import React from 'react'; +import Comment from './Comment'; +import './CommentList.scss'; + +class CommentList extends React.Component { + constructor(props) { + super(props); + this.state = { + commentInput: '', + newComment: [], + nickname: '', + commentList: [], + commentValue: '', + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/commentData.json', { + method: 'GET', // GET method๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + }) // ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ธฐ์ž…ํ•ด๋’€์Šต๋‹ˆ๋‹ค. + .then(res => res.json()) + .then(data => { + this.setState({ + commentList: data, + }); + }); + } + + checkInput = e => { + this.setState({ + commentInput: e.target.value, + }); + }; + + inputToComment = () => { + const { newComment, commentInput } = this.state; + this.setState({ + nickname: 'wecode_bootcamp', + newComment: newComment.concat(commentInput), + }); + }; + + enterPress = e => { + if (e.key === 'Enter') { + this.inputToComment(); + } + e.target.value = ''; + }; + + render() { + const { commentValue, commentList } = this.state; + return ( + <div className="commentList"> + {commentList.map(comment => { + return ( + <Comment + key={comment.id} + nickname={comment.userName} + comment={comment.content} + /> + ); + })} + + <div className="newText"> + <input + id="typingText" + value={commentValue} + onChange={this.checkInput} + onKeyPress={this.enterPress} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...." + /> + <button onClick={this.checkInput}>๊ฒŒ์‹œ</button> + </div> + </div> + ); + } +} + +export default CommentList;
JavaScript
- ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น ํ•ด์ฃผ์„ธ์š”! ```suggestion inputToComment = () => { const { comment, commentInput } = this.state; this.setState({ id: 'wecode_bootcamp', comment: comment.concat(commentInput), }); }; ```
@@ -0,0 +1,23 @@ +import React from 'react'; +import './Comment.scss'; + +class NewComment extends React.Component { + render() { + // const newArray = this.props.newComment.map((commentarray, index) => ( + // <li key={index}> + // <span className="newCommentid">{this.props.nickname}</span> + // <span className="newComments">{commentarray}</span> + // </li> + // )); + return ( + <div className="comment"> + <div className="newComment"> + <span className="newCommentid">{this.props.nickname}</span> + <span className="newComments">{this.props.comment}</span> + </div> + </div> + ); + } +} + +export default NewComment;
JavaScript
- ์ปดํฌ๋„ŒํŠธ์™€ ๋™์ผํ•˜๊ฒŒ ํด๋ž˜์Šค๋„ค์ž„ ์ง€์–ด์ฃผ์‹œ๊ณ , ์ฒซ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ์ž‘์„ฑํ•˜๋Š” ์ปจ๋ฒค์…˜์€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋„ค์ด๋ฐ ํ•˜๊ธฐ ์œ„ํ•œ ์ปจ๋ฒค์…˜ ์ž…๋‹ˆ๋‹ค! ```suggestion <div className="comment"> ```
@@ -0,0 +1,80 @@ +import React from 'react'; +import Comment from './Comment'; +import './CommentList.scss'; + +class CommentList extends React.Component { + constructor(props) { + super(props); + this.state = { + commentInput: '', + newComment: [], + nickname: '', + commentList: [], + commentValue: '', + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/commentData.json', { + method: 'GET', // GET method๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + }) // ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ธฐ์ž…ํ•ด๋’€์Šต๋‹ˆ๋‹ค. + .then(res => res.json()) + .then(data => { + this.setState({ + commentList: data, + }); + }); + } + + checkInput = e => { + this.setState({ + commentInput: e.target.value, + }); + }; + + inputToComment = () => { + const { newComment, commentInput } = this.state; + this.setState({ + nickname: 'wecode_bootcamp', + newComment: newComment.concat(commentInput), + }); + }; + + enterPress = e => { + if (e.key === 'Enter') { + this.inputToComment(); + } + e.target.value = ''; + }; + + render() { + const { commentValue, commentList } = this.state; + return ( + <div className="commentList"> + {commentList.map(comment => { + return ( + <Comment + key={comment.id} + nickname={comment.userName} + comment={comment.content} + /> + ); + })} + + <div className="newText"> + <input + id="typingText" + value={commentValue} + onChange={this.checkInput} + onKeyPress={this.enterPress} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...." + /> + <button onClick={this.checkInput}>๊ฒŒ์‹œ</button> + </div> + </div> + ); + } +} + +export default CommentList;
JavaScript
- id ๋ผ๋Š” ๊ฐ’์€ ๋ฌด์Šจ ์šฉ๋„๋ฅผ ์œ„ํ•ด ์ž‘์„ฑํ•ด ์ฃผ์‹  ๊ฑธ๊นŒ์š”? id ๋Š” ๊ผญ ํ•„์š”ํ•œ ๋ถ€๋ถ„์ด ์•„๋‹ˆ๋ผ๋ฉด ์‚ฌ์šฉ์„ ์ง€์–‘ํ•ด์ฃผ์„ธ์š”! id ๊ฐ’์€ ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ ์œ ์ผํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. - id ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์˜ˆ๋ฅผ ๋“ค์–ด, google map api ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ง€๋„๋ฅผ ๊ทธ๋ฆด๋•Œ, ์ง€๋„๋ฅผ ๊ทธ๋ฆด html element ๋ฅผ ํŠน์ •ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๊ณค ํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,80 @@ +import React from 'react'; +import Comment from './Comment'; +import './CommentList.scss'; + +class CommentList extends React.Component { + constructor(props) { + super(props); + this.state = { + commentInput: '', + newComment: [], + nickname: '', + commentList: [], + commentValue: '', + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/commentData.json', { + method: 'GET', // GET method๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + }) // ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ธฐ์ž…ํ•ด๋’€์Šต๋‹ˆ๋‹ค. + .then(res => res.json()) + .then(data => { + this.setState({ + commentList: data, + }); + }); + } + + checkInput = e => { + this.setState({ + commentInput: e.target.value, + }); + }; + + inputToComment = () => { + const { newComment, commentInput } = this.state; + this.setState({ + nickname: 'wecode_bootcamp', + newComment: newComment.concat(commentInput), + }); + }; + + enterPress = e => { + if (e.key === 'Enter') { + this.inputToComment(); + } + e.target.value = ''; + }; + + render() { + const { commentValue, commentList } = this.state; + return ( + <div className="commentList"> + {commentList.map(comment => { + return ( + <Comment + key={comment.id} + nickname={comment.userName} + comment={comment.content} + /> + ); + })} + + <div className="newText"> + <input + id="typingText" + value={commentValue} + onChange={this.checkInput} + onKeyPress={this.enterPress} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...." + /> + <button onClick={this.checkInput}>๊ฒŒ์‹œ</button> + </div> + </div> + ); + } +} + +export default CommentList;
JavaScript
- ์—ฌ๊ธฐ๋„ id ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋ฐ ๋ถˆํ•„์š”ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์ง€์›Œ์ฃผ์„ธ์š”~
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
- constructor ์„ ์–ธ์„ ๊ฐ€์žฅ ์œ„์— ์œ„์น˜์‹œ์ผœ์ฃผ์„ธ์š”!
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
- defaultColor ์™€ disabled ๋Š” state ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ์—๋Š” ๋ถ€์ ์ ˆํ•œ ๊ฐ’ ๊ฐ™์Šต๋‹ˆ๋‹ค. idInput ๊ณผ pwInput ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค! - ์–ด๋–ค ๊ธฐ์ค€์œผ๋กœ state ๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•ด์„œ๋Š” ์•„๋ž˜ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”! - https://ko.reactjs.org/docs/thinking-in-react.html#step-3-identify-the-minimal-but-complete-representation-of-ui-state - state ๋กœ ๊ด€๋ฆฌํ•  ํ•„์š”๊ฐ€ ์—†๋Š” ๊ฐ’๋“ค์€ state ๋ฅผ ๋งŒ๋“ค์ง€ ์•Š๋„๋ก ํ•ด์ฃผ์„ธ์š”. ๊ฐ’์„ ์ˆ˜์ •ํ•˜๊ธฐ ์œ„ํ•ด์„ , setState ๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•˜๊ณ , ์ด๋Š” ์ผ์–ด๋‚˜์ง€ ์•Š์•„๋„ ๋˜๋Š” ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง์„ ๋ฐœ์ƒ์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
- ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น ํ™œ์šฉํ•ด ์ฃผ์‹œ๋ฉด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ```suggestion const { name, value } = event.target; this.setState({ [name]: value, }); ```
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
- defaultColor ์™€ disabled ๋ฅผ state ์—์„œ ๊ด€๋ฆฌํ•˜์ง€ ์•Š๋„๋ก ํ•œ๋‹ค๋ฉด, ์ด ๋กœ์ง ๋ถ€๋ถ„์€ ๋” ์ด์ƒ ํ•„์š” ์—†์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
- idInput ๊ณผ pwInput ์„ ์‚ฌ์šฉํ•ด์„œ ๋ฐ”๋กœ ๊ฐ’์„ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”! - inline ์Šคํƒ€์ผ๋ง์„ ์ฃผ์‹œ๋Š” ๊ฒƒ์€ ๊ผญ ํ•„์š”ํ•œ ๊ฒฝ์šฐ๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด ์ง€์–‘ํ•ด์ฃผ์‹œ๊ณ , className ์„ ๋™์ ์œผ๋กœ ๋ถ€์—ฌํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์Šคํƒ€์ผ๋ง ํ•ด์ฃผ์„ธ์š”! - inline ์Šคํƒ€์ผ๋ง์„ ์‚ฌ์šฉํ•˜์‹œ๋Š” ๊ฒฝ์šฐ๋Š”, ์Šฌ๋ผ์ด๋”๋ฅผ ๊ตฌํ˜„๊ณผ ๊ฐ™์ด ์Šคํƒ€์ผ๋ง์ด ๋งค์šฐ ๋งŽ์ด ์ง€์†์ ์œผ๋กœ ๋ณ€ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์— ์‚ฌ์šฉํ•ด ์ฃผ์‹œ๋Š” ๊ฒ๋‹ˆ๋‹ค! ```jsx render () { const { idInput, pwInput } = this.state; isButtonActive = idInput.includes('@') && pwInput.length >= 5 return ( ... <button disabled={!isButtonActive} className={`loginButton ${isButtonActive ? 'active' : ''}`} onClick={this.goToMain} > ... ) } ```
@@ -0,0 +1,46 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); +@import '../../../styles/variable.scss'; + +.Login { + .container { + width: 2000px; + max-width: 100vw; + + .loginContainer { + width: 350px; + height: 400px; + margin: 25vh auto; + border: 2px solid lightgrey; + text-align: center; + + p { + margin: 50px auto; + font-family: 'Lobster'; + font-size: 40px; + } + + .inputId { + @include idpwContainer; + } + + .inputPassword { + @include idpwContainer; + } + + .loginButtonOn { + @include loginButton; + background-color: blue; + } + + .loginButtonOff { + @include loginButton; + background-color: skyblue; + } + + a { + text-decoration: none; + color: blue; + } + } + } +}
Unknown
- common.scss ์— ์ ํ•ฉํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,46 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); +@import '../../../styles/variable.scss'; + +.Login { + .container { + width: 2000px; + max-width: 100vw; + + .loginContainer { + width: 350px; + height: 400px; + margin: 25vh auto; + border: 2px solid lightgrey; + text-align: center; + + p { + margin: 50px auto; + font-family: 'Lobster'; + font-size: 40px; + } + + .inputId { + @include idpwContainer; + } + + .inputPassword { + @include idpwContainer; + } + + .loginButtonOn { + @include loginButton; + background-color: blue; + } + + .loginButtonOff { + @include loginButton; + background-color: skyblue; + } + + a { + text-decoration: none; + color: blue; + } + } + } +}
Unknown
- mixin ์€ variable.scss ์™€ ๊ฐ™์€ ๋ณ„๋„์˜ ํŒŒ์ผ์„ ํ•˜๋‚˜ ๋” ๋งŒ๋“ค์–ด์„œ ๊ทธ๊ณณ์—์„œ ์ผ๊ด„์ ์œผ๋กœ ๊ด€๋ฆฌํ•ด์ฃผ์„ธ์š”!
@@ -0,0 +1,46 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); +@import '../../../styles/variable.scss'; + +.Login { + .container { + width: 2000px; + max-width: 100vw; + + .loginContainer { + width: 350px; + height: 400px; + margin: 25vh auto; + border: 2px solid lightgrey; + text-align: center; + + p { + margin: 50px auto; + font-family: 'Lobster'; + font-size: 40px; + } + + .inputId { + @include idpwContainer; + } + + .inputPassword { + @include idpwContainer; + } + + .loginButtonOn { + @include loginButton; + background-color: blue; + } + + .loginButtonOff { + @include loginButton; + background-color: skyblue; + } + + a { + text-decoration: none; + color: blue; + } + } + } +}
Unknown
- ์Šคํƒ€์ผ๋ง์„ ๋ถ€์—ฌํ•˜๊ธฐ ์œ„ํ•จ์œผ๋กœ๋Š” className ์œผ๋กœ๋„ ์ถฉ๋ถ„ํ•ฉ๋‹ˆ๋‹ค. id ๋ฅผ ์‚ฌ์šฉํ•˜์‹ค ์ด์œ ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.
@@ -1,13 +1,108 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import Nav from '../../../components/Nav/Nav'; +import CommentList from '../Comment/CommentList'; +import './Main.scss'; class MainAh extends React.Component { render() { return ( - <div> - <p>๋ช…์„ฑ</p> + <div className="MainAh"> + <Nav /> + <div className="mainContainer"> + <div className="feedsContainer"> + <article> + <div className="feedsTop"> + <img + className="profileImage" + src="/images/baeyoonah/Main/mark.png" + alt="" + /> + <span className="feedsId">wecode-bootcamp</span> + </div> + <img src="/images/baeyoonah/Main/liberty.jpg" alt="" /> + <div className="feedsIcon"> + <ul> + <li> + <img src="/images/baeyoonah/Main/redheart.png" alt="" /> + </li> + <li> + <img src="/images/baeyoonah/Main/what.png" alt="" /> + </li> + <li> + <img src="/images/baeyoonah/Main/share.png" alt="" /> + </li> + </ul> + <img src="/images/baeyoonah/Main/tag.png" alt="" /> + </div> + <div className="feedsContent"> + <div> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="feedsId">ainworld</span> + <span className="feedsText">๋‹˜ ์™ธ 4๋ช…์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค.</span> + </div> + <CommentList /> + </div> + </article> + </div> + <div className="mainRightContainer"> + <div className="mainRightTop"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">wecode_bootcamp</span> + <p className="mainRightIdInfo">Wecode | ์œ„์ฝ”๋“œ</p> + </div> + + <div className="storyContainer"> + <div className="storyMenu"> + <span className="storyId">์Šคํ† ๋ฆฌ</span> + <span className="storyIdInfo">๋ชจ๋‘๋ณด๊ธฐ</span> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">_yms_s</span> + <p className="siteIdInfo">16๋ถ„ ์ „</p> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">_yms_s</span> + <p className="siteIdInfo">16๋ถ„ ์ „</p> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">_yms_s</span> + <p className="siteIdInfo">16๋ถ„ ์ „</p> + </div> + </div> + + <div className="follow"> + <div className="storyMenu"> + <span className="storyId">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + <span className="storyIdInfo">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">ioaaaaaahye</span> + <p className="siteIdInfo">_legenda๋‹˜ ์™ธ 2๋ช…์ด ...</p> + <button className="followBtn">ํŒ”๋กœ์šฐ</button> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">ioaaaaaahye</span> + <p className="siteIdInfo">_legenda๋‹˜ ์™ธ 2๋ช…์ด ...</p> + <button className="followBtn">ํŒ”๋กœ์šฐ</button> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">ioaaaaaahye</span> + <p className="siteIdInfo">_legenda๋‹˜ ์™ธ 2๋ช…์ด ...</p> + <button className="followBtn">ํŒ”๋กœ์šฐ</button> + </div> + </div> + </div> + </div> </div> ); } } -export default MainAh; +export default withRouter(MainAh);
JavaScript
- ๋ฐ˜๋ณต์ ์ธ ๊ตฌ์กฐ๊ฐ€ ๋ณด์ด๋„ค์š”! ๊ทธ๋ฆฌ๊ณ  ์‚ฌ์‹ค ์ด ๋ถ€๋ถ„์€ ๋ฐฑ์—”๋“œ์—์„œ ์ •๋ณด๋ฅผ ๋ฐ›์•„์™€์„œ ํ™”๋ฉด์— ๊ทธ๋ฆฌ๋Š” ๊ฒƒ์ด๋ฏ€๋กœ, ๋ชฉ์—… ๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌ์„ฑํ•˜์…”์„œ map ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•ด์ฃผ์‹œ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -1,13 +1,108 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import Nav from '../../../components/Nav/Nav'; +import CommentList from '../Comment/CommentList'; +import './Main.scss'; class MainAh extends React.Component { render() { return ( - <div> - <p>๋ช…์„ฑ</p> + <div className="MainAh"> + <Nav /> + <div className="mainContainer"> + <div className="feedsContainer"> + <article> + <div className="feedsTop"> + <img + className="profileImage" + src="/images/baeyoonah/Main/mark.png" + alt="" + /> + <span className="feedsId">wecode-bootcamp</span> + </div> + <img src="/images/baeyoonah/Main/liberty.jpg" alt="" /> + <div className="feedsIcon"> + <ul> + <li> + <img src="/images/baeyoonah/Main/redheart.png" alt="" /> + </li> + <li> + <img src="/images/baeyoonah/Main/what.png" alt="" /> + </li> + <li> + <img src="/images/baeyoonah/Main/share.png" alt="" /> + </li> + </ul> + <img src="/images/baeyoonah/Main/tag.png" alt="" /> + </div> + <div className="feedsContent"> + <div> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="feedsId">ainworld</span> + <span className="feedsText">๋‹˜ ์™ธ 4๋ช…์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค.</span> + </div> + <CommentList /> + </div> + </article> + </div> + <div className="mainRightContainer"> + <div className="mainRightTop"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">wecode_bootcamp</span> + <p className="mainRightIdInfo">Wecode | ์œ„์ฝ”๋“œ</p> + </div> + + <div className="storyContainer"> + <div className="storyMenu"> + <span className="storyId">์Šคํ† ๋ฆฌ</span> + <span className="storyIdInfo">๋ชจ๋‘๋ณด๊ธฐ</span> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">_yms_s</span> + <p className="siteIdInfo">16๋ถ„ ์ „</p> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">_yms_s</span> + <p className="siteIdInfo">16๋ถ„ ์ „</p> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">_yms_s</span> + <p className="siteIdInfo">16๋ถ„ ์ „</p> + </div> + </div> + + <div className="follow"> + <div className="storyMenu"> + <span className="storyId">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + <span className="storyIdInfo">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">ioaaaaaahye</span> + <p className="siteIdInfo">_legenda๋‹˜ ์™ธ 2๋ช…์ด ...</p> + <button className="followBtn">ํŒ”๋กœ์šฐ</button> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">ioaaaaaahye</span> + <p className="siteIdInfo">_legenda๋‹˜ ์™ธ 2๋ช…์ด ...</p> + <button className="followBtn">ํŒ”๋กœ์šฐ</button> + </div> + <div className="storyContent"> + <img src="/images/baeyoonah/Main/mark.png" alt="" /> + <span className="siteId">ioaaaaaahye</span> + <p className="siteIdInfo">_legenda๋‹˜ ์™ธ 2๋ช…์ด ...</p> + <button className="followBtn">ํŒ”๋กœ์šฐ</button> + </div> + </div> + </div> + </div> </div> ); } } -export default MainAh; +export default withRouter(MainAh);
JavaScript
- ์—ฌ๊ธฐ๋„ ์œ„์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,201 @@ +body { + margin: 0; +} +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); + +.MainAh { + .mainContainer { + display: flex; + position: relative; + justify-content: center; + width: 2000px; + max-width: 100vw; + height: 2000px; + background-color: #fafafa; + } + + .feedsContainer { + position: absolute; + left: 15%; + margin-top: 50px; + width: 45%; + border: 2px solid lightgrey; + background-color: white; + + p { + margin: 0; + } + } + + .feedsTop { + margin: 15px 0; + } + + article { + width: 100%; + .profileImage { + vertical-align: middle; + margin-left: 15px; + margin-right: 10px; + width: 30px; + height: 30px; + } + + img { + width: 100%; + } + } + + .feedsIcon { + display: flex; + justify-content: space-between; + margin-top: 5px; + + ul { + display: flex; + margin: 0; + padding-left: 10px; + } + li { + list-style: none; + margin-right: 10px; + } + img { + margin-right: 10px; + width: 30px; + height: 30px; + } + } + + .feedsContent { + padding: 10px; + border-bottom: 2px solid lightgrey; + + img { + margin-right: 5px; + width: 15px; + height: 15px; + } + + .feedsId { + font-weight: bold; + } + .feedsText { + margin-left: 10px; + font-weight: normal; + } + } + + .newText { + margin: 15px 0px 15px 10px; + + input { + width: 90%; + border: none; + color: black; + } + button { + border: none; + background-color: white; + color: skyblue; + } + } + + .mainRightContainer { + display: flex; + flex-direction: column; + position: fixed; + left: 63%; + margin-top: 50px; + width: 20%; + + img { + width: 40px; + height: 40px; + } + + .mainRightIdInfo { + position: absolute; + top: 20px; + left: 5px; + margin: 0; + margin-left: 50px; + color: grey; + } + } + .mainRightTop { + margin-bottom: 10px; + + img { + vertical-align: middle; + margin-right: 10px; + width: 45px; + height: 45px; + } + } + + .storyContainer { + border: 2px solid lightgrey; + margin-top: 10px; + background-color: white; + } + // story, follow ๊ณตํ†ต ์‚ฌ์šฉ + .storyMenu { + display: flex; + justify-content: space-between; + margin: 15px; + } + .storyContent { + margin: 15px; + position: relative; + + img { + vertical-align: middle; + margin-right: 15px; + width: 35px; + height: 35px; + } + } + // ํŠน์ • ์ปจํ…Œ์ด๋„ˆ ์•ˆ์— ๋“ค์–ด๊ฐ€์žˆ์ง€ ์•Š๊ณ  ๊ณตํ†ต์œผ๋กœ ์“ฐ๋Š”์ค‘ + .siteId { + position: absolute; + top: 2px; + font-weight: bold; + } + + .siteIdInfo { + position: absolute; + top: 20px; + left: 5px; + margin: 0; + margin-left: 45px; + color: grey; + } + + .storyId { + color: grey; + margin: 0; + } + + .storyIdinfo { + font-weight: bold; + } + + .follow { + margin-top: 15px; + border: 2px solid lightgrey; + background-color: white; + + .followBtn { + position: absolute; + top: 10px; + right: 0; + float: right; + padding: 0; + border: none; + background-color: white; + color: blue; + font-size: 15px; + } + } +}
Unknown
- reset.scss ์— ์ ํ•ฉํ•ด ๋ณด์ด๋„ค์š”!
@@ -0,0 +1,80 @@ +import React from 'react'; +import Comment from './Comment'; +import './CommentList.scss'; + +class CommentList extends React.Component { + constructor(props) { + super(props); + this.state = { + commentInput: '', + newComment: [], + nickname: '', + commentList: [], + commentValue: '', + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/commentData.json', { + method: 'GET', // GET method๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + }) // ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ธฐ์ž…ํ•ด๋’€์Šต๋‹ˆ๋‹ค. + .then(res => res.json()) + .then(data => { + this.setState({ + commentList: data, + }); + }); + } + + checkInput = e => { + this.setState({ + commentInput: e.target.value, + }); + }; + + inputToComment = () => { + const { newComment, commentInput } = this.state; + this.setState({ + nickname: 'wecode_bootcamp', + newComment: newComment.concat(commentInput), + }); + }; + + enterPress = e => { + if (e.key === 'Enter') { + this.inputToComment(); + } + e.target.value = ''; + }; + + render() { + const { commentValue, commentList } = this.state; + return ( + <div className="commentList"> + {commentList.map(comment => { + return ( + <Comment + key={comment.id} + nickname={comment.userName} + comment={comment.content} + /> + ); + })} + + <div className="newText"> + <input + id="typingText" + value={commentValue} + onChange={this.checkInput} + onKeyPress={this.enterPress} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...." + /> + <button onClick={this.checkInput}>๊ฒŒ์‹œ</button> + </div> + </div> + ); + } +} + +export default CommentList;
JavaScript
์ ์šฉ์™„๋ฃŒ~! ๋‹ค์Šฌ๋‹˜ ์ตœ๊ณ !
@@ -0,0 +1,23 @@ +import React from 'react'; +import './Comment.scss'; + +class NewComment extends React.Component { + render() { + // const newArray = this.props.newComment.map((commentarray, index) => ( + // <li key={index}> + // <span className="newCommentid">{this.props.nickname}</span> + // <span className="newComments">{commentarray}</span> + // </li> + // )); + return ( + <div className="comment"> + <div className="newComment"> + <span className="newCommentid">{this.props.nickname}</span> + <span className="newComments">{this.props.comment}</span> + </div> + </div> + ); + } +} + +export default NewComment;
JavaScript
์ง€์› ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,15 @@ +.comment { + .newComment { + margin-bottom: 5px; + } + + .newCommentid { + font-weight: bold; + margin-bottom: 0; + } + + .newComments { + font-weight: normal; + margin-left: 5px; + } +}
Unknown
์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,80 @@ +import React from 'react'; +import Comment from './Comment'; +import './CommentList.scss'; + +class CommentList extends React.Component { + constructor(props) { + super(props); + this.state = { + commentInput: '', + newComment: [], + nickname: '', + commentList: [], + commentValue: '', + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/commentData.json', { + method: 'GET', // GET method๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + }) // ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ธฐ์ž…ํ•ด๋’€์Šต๋‹ˆ๋‹ค. + .then(res => res.json()) + .then(data => { + this.setState({ + commentList: data, + }); + }); + } + + checkInput = e => { + this.setState({ + commentInput: e.target.value, + }); + }; + + inputToComment = () => { + const { newComment, commentInput } = this.state; + this.setState({ + nickname: 'wecode_bootcamp', + newComment: newComment.concat(commentInput), + }); + }; + + enterPress = e => { + if (e.key === 'Enter') { + this.inputToComment(); + } + e.target.value = ''; + }; + + render() { + const { commentValue, commentList } = this.state; + return ( + <div className="commentList"> + {commentList.map(comment => { + return ( + <Comment + key={comment.id} + nickname={comment.userName} + comment={comment.content} + /> + ); + })} + + <div className="newText"> + <input + id="typingText" + value={commentValue} + onChange={this.checkInput} + onKeyPress={this.enterPress} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...." + /> + <button onClick={this.checkInput}>๊ฒŒ์‹œ</button> + </div> + </div> + ); + } +} + +export default CommentList;
JavaScript
์ ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น์ด ์ต์ˆ™ํ•˜์ง€์•Š์•„ ์จ์•ผํ•  ๊ณณ์„ ์ž˜ ๊ตฌ๋ถ„ํ•˜์ง€ ๋ชปํ•˜๋Š”๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.. ใ… 
@@ -0,0 +1,23 @@ +import React from 'react'; +import './Comment.scss'; + +class NewComment extends React.Component { + render() { + // const newArray = this.props.newComment.map((commentarray, index) => ( + // <li key={index}> + // <span className="newCommentid">{this.props.nickname}</span> + // <span className="newComments">{commentarray}</span> + // </li> + // )); + return ( + <div className="comment"> + <div className="newComment"> + <span className="newCommentid">{this.props.nickname}</span> + <span className="newComments">{this.props.comment}</span> + </div> + </div> + ); + } +} + +export default NewComment;
JavaScript
์•„ ์ด๋Ÿฐ ์‹ค์ˆ˜๋ฅผ ... ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,80 @@ +import React from 'react'; +import Comment from './Comment'; +import './CommentList.scss'; + +class CommentList extends React.Component { + constructor(props) { + super(props); + this.state = { + commentInput: '', + newComment: [], + nickname: '', + commentList: [], + commentValue: '', + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/commentData.json', { + method: 'GET', // GET method๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + }) // ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ธฐ์ž…ํ•ด๋’€์Šต๋‹ˆ๋‹ค. + .then(res => res.json()) + .then(data => { + this.setState({ + commentList: data, + }); + }); + } + + checkInput = e => { + this.setState({ + commentInput: e.target.value, + }); + }; + + inputToComment = () => { + const { newComment, commentInput } = this.state; + this.setState({ + nickname: 'wecode_bootcamp', + newComment: newComment.concat(commentInput), + }); + }; + + enterPress = e => { + if (e.key === 'Enter') { + this.inputToComment(); + } + e.target.value = ''; + }; + + render() { + const { commentValue, commentList } = this.state; + return ( + <div className="commentList"> + {commentList.map(comment => { + return ( + <Comment + key={comment.id} + nickname={comment.userName} + comment={comment.content} + /> + ); + })} + + <div className="newText"> + <input + id="typingText" + value={commentValue} + onChange={this.checkInput} + onKeyPress={this.enterPress} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...." + /> + <button onClick={this.checkInput}>๊ฒŒ์‹œ</button> + </div> + </div> + ); + } +} + +export default CommentList;
JavaScript
์œ„์—์„œ ๋ฐ›์•„์˜จ 'wecode-bootcamp' ๋ผ๋Š” id ๊ฐ’์„ ๋ฐ›์•„์˜ค๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ, ํ™•์‹คํžˆ id ๋ผ๋Š”๊ฒƒ์€ ์ ์ ˆ์น˜ ์•Š์•„ nickname ์œผ๋กœ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,80 @@ +import React from 'react'; +import Comment from './Comment'; +import './CommentList.scss'; + +class CommentList extends React.Component { + constructor(props) { + super(props); + this.state = { + commentInput: '', + newComment: [], + nickname: '', + commentList: [], + commentValue: '', + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/commentData.json', { + method: 'GET', // GET method๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + }) // ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ๋ช…์‹œ์ ์œผ๋กœ ๊ธฐ์ž…ํ•ด๋’€์Šต๋‹ˆ๋‹ค. + .then(res => res.json()) + .then(data => { + this.setState({ + commentList: data, + }); + }); + } + + checkInput = e => { + this.setState({ + commentInput: e.target.value, + }); + }; + + inputToComment = () => { + const { newComment, commentInput } = this.state; + this.setState({ + nickname: 'wecode_bootcamp', + newComment: newComment.concat(commentInput), + }); + }; + + enterPress = e => { + if (e.key === 'Enter') { + this.inputToComment(); + } + e.target.value = ''; + }; + + render() { + const { commentValue, commentList } = this.state; + return ( + <div className="commentList"> + {commentList.map(comment => { + return ( + <Comment + key={comment.id} + nickname={comment.userName} + comment={comment.content} + /> + ); + })} + + <div className="newText"> + <input + id="typingText" + value={commentValue} + onChange={this.checkInput} + onKeyPress={this.enterPress} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ...." + /> + <button onClick={this.checkInput}>๊ฒŒ์‹œ</button> + </div> + </div> + ); + } +} + +export default CommentList;
JavaScript
์ง€์› ์Šต๋‹ˆ๋‹ค!
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
defaultColor๋Š” ์•„์˜ˆ ์ง€์šฐ๊ณ  ์‚ผํ•ญ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์„ ๋ฐ‘์— ์ฃผ์…”์„œ ๊ทธ๊ฑฐ๋กœ ์ƒ‰์ƒ ๋ณ€ํ™˜๊นŒ์ง€ ์ ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ƒํƒœ๊ฐ€ ๋ณ€ํ•œ๋‹ค๊ณ  ์ƒ๊ฐ๋˜๋Š”๊ฒƒ์€ ์ž๊พธ state๋ฅผ ์ด์šฉํ•˜๊ฒŒ ๋˜๋Š”๊ฑฐ ๊ฐ™์•„ ๋” ๊ณต๋ถ€ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
ํ•˜๋‹จ์— ์ฃผ์‹  ํ•ด๊ฒฐ๋ฒ•์œผ๋กœ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -1,13 +1,92 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; class LoginAh extends React.Component { + constructor(props) { + super(props); + this.state = { + idInput: '', + pwInput: '', + }; + } + + loginTest = () => { + fetch('users/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email: this.state.idInput, + password: this.state.pwInput, + }), + }) + .then(response => response.json()) + .then(response => { + if (response.token) { + localStorage.setItem('token', response.token); + this.props.history.push('/MainAh'); + } else { + alert('์•„์ด๋””/๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!'); + } + }); + }; + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/MainAh'); + }; + render() { + const { idInput, pwInput } = this.state; + const isButtonActive = idInput.includes('@') && pwInput.length >= 5; return ( - <div> - <p>๋‹ค์Šฌ</p> + <div className="Login"> + <div className="container"> + <div className="loginContainer"> + <p>westagram</p> + <div className="idContainer"> + <input + onChange={this.handleInput} + name="idInput" + type="text" + className="inputId" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + </div> + <div className="passwordContainer"> + <input + onChange={this.handleInput} + name="pwInput" + type="password" + className="inputPassword" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + </div> + <button + disabled={!isButtonActive} + className={`loginButton ${ + isButtonActive ? 'loginButtonOn' : 'loginButtonOff' + }`} + // onClick={this.goToMain} + onClick={this.loginTest} + > + ๋กœ๊ทธ์ธ + </button> + <div> + <a href="google.com">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </div> + </div> </div> ); } } -export default LoginAh; +export default withRouter(LoginAh);
JavaScript
์ •๋ง ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋ฌด์กฐ๊ฑด constructor ๋‹จ์—์„œ ๋ณ€ํ™”์‹œํ‚ค๋Š” ์ค„ ์•Œ๊ณ  ๊ทธ๊ณณ์—์„œ๋งŒ ํ•ด๊ฒฐํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ render์—์„œ ๋ณ€๊ฒฝํ•˜๋ฉด ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. inline ์Šคํƒ€์ผ๋ง ์ง€์–‘ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!!!
@@ -0,0 +1,15 @@ +{ + "arrowParens": "always", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 80, + "proseWrap": "always", + "quoteProps": "as-needed", + "semi": true, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false, + "endOfLine": "auto" +} \ No newline at end of file
Unknown
EOL์ด ์žˆ๋„ค์š”
@@ -10,7 +10,17 @@ "@babel/core": "^7.23.0", "@babel/preset-env": "^7.22.20", "babel-jest": "^29.7.0", - "jest": "29.6.0" + "eslint": "^8.56.0", + "eslint-config-airbnb": "^19.0.4", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-jsx-a11y": "^6.8.0", + "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.6.0", + "husky": "^9.0.7", + "jest": "29.6.0", + "prettier": "^3.2.4" }, "scripts": { "test": "jest"
Unknown
์˜ค.. husky๊นŒ์ง€
@@ -0,0 +1,28 @@ +import GameMessage from "./GameMessage.js"; +import { VALID_INPUT_LENGTH } from "./gameConstants.js"; + +class Validator { + static isValidInput(input) { + if (!this.isNumber(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_NUMBER); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_CORRECT_LENGTH); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_IS_DUPLICATED); + return true; + } + + static isNumber(input) { + return !Number.isNaN(input); + } + + static isValidLength(input) { + return input.length === VALID_INPUT_LENGTH; + } + + static isDuplicate(input) { + return [...new Set(input)].length === VALID_INPUT_LENGTH; + } +} + +export default Validator;
JavaScript
3์ด๋ผ๋Š” ์ˆซ์ž๋Š” ์–ด๋–ค ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ๊ฐ™์€๋ฐ์š”, ์ด๋Ÿฌํ•œ ์ˆซ์ž๊ฐ€ ์ˆซ์ž ๊ทธ๋Œ€๋กœ ์กด์žฌํ•˜๋Š” ๊ฒƒ์„ ํ”ํžˆ ๋งค์ง๋„˜๋ฒ„๋ผ๊ณ  ๋ถ€๋ฆ…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ด๋Ÿฌํ•œ ์ˆซ์ž๋Š” ๋‹ค์Œ์˜ ์ด์œ ๋กœ ์ƒ์ˆ˜ํ™” ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. 1. ์˜ˆ์‹œ๋กœ ์ˆซ์ž์•ผ๊ตฌ ๊ฒŒ์ž„์˜ ์ˆซ์ž๊ฐฏ์ˆ˜๊ฐ€ 4๋กœ ๋Š˜์–ด๋‚ฌ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ๋ชจ๋“  ํŒŒ์ผ์„ ๋’ค์ ธ์„œ 3์„ 4๋กœ ๊ณ ์ณ์•ผํ•œ๋‹ค. (๋ณ€๊ฒฝ์— ์šฉ์ดํ•˜์ง€ ์•Š๋‹ค.) 2. ์ฒ˜์Œ ์˜จ๋ณด๋”ฉ ํ•˜๋Š” ์‚ฌ๋žŒ์€ ์ด ์ˆซ์ž์˜ ์˜๋ฏธ๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ ํž˜๋“ค๋‹ค. ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์ด ์ค„์–ด๋“ ๋‹ค.
@@ -0,0 +1,28 @@ +import GameMessage from "./GameMessage.js"; +import { VALID_INPUT_LENGTH } from "./gameConstants.js"; + +class Validator { + static isValidInput(input) { + if (!this.isNumber(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_NUMBER); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_CORRECT_LENGTH); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_IS_DUPLICATED); + return true; + } + + static isNumber(input) { + return !Number.isNaN(input); + } + + static isValidLength(input) { + return input.length === VALID_INPUT_LENGTH; + } + + static isDuplicate(input) { + return [...new Set(input)].length === VALID_INPUT_LENGTH; + } +} + +export default Validator;
JavaScript
1. ์ฝ”๋“œ๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ณ ์น˜๋ฉด ๋” ์ค„์–ด๋“ญ๋‹ˆ๋‹ค ใ…Žใ…Ž ```suggestion const newArr = [...new Set(input)] ``` 2. newArr์ด๋ผ๋Š” ์ƒ์ˆ˜๋ช…์ด ์–ด๋–ค ์˜๋ฏธ๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ์ด๋ฆ„์ธ๊ฐ€์š”? ์˜๋ฏธ๊ฐ€ ์—†๊ณ , ๋‹จ๋ฐœ์„ฑ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ์ธก๋ฉด์—์„œ ์ด๋ ‡๊ฒŒ ์ž‘์„ฑํ•ด๋„ ๋  ๊ฒƒ ๊ฐ™์•„์š”. ```js isDuplicate(input) { if ([...new Set(input)].length !== 3) throw new Error(GameMessage.INVALID_INPUT_IS_DUPLICATED) return true; } ```
@@ -0,0 +1,28 @@ +import GameMessage from "./GameMessage.js"; +import { VALID_INPUT_LENGTH } from "./gameConstants.js"; + +class Validator { + static isValidInput(input) { + if (!this.isNumber(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_NUMBER); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_CORRECT_LENGTH); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_IS_DUPLICATED); + return true; + } + + static isNumber(input) { + return !Number.isNaN(input); + } + + static isValidLength(input) { + return input.length === VALID_INPUT_LENGTH; + } + + static isDuplicate(input) { + return [...new Set(input)].length === VALID_INPUT_LENGTH; + } +} + +export default Validator;
JavaScript
1. ๊ฐœ์ธ์ ์ธ ๊ฒฌํ•ด๋กœ๋Š” ๊ฒ€์ฆํ•จ์ˆ˜์—์„œ๋Š” ํ•ด๋‹น input์ด ์œ ํšจํ•œ์ง€/์•ˆํ•œ์ง€(boolean) ํ‰๊ฐ€ํ•œ ๋‹ค์Œ, ์ด ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ ์—๋Ÿฌ๋ฅผ ๋˜์ ธ์ฃผ๋Š” ํŒจํ„ด์„ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋งํ•˜๋ฉด ์—๋Ÿฌ๋ฅผ ๋˜์ ธ์ฃผ๋Š” ๋ถ€๋ถ„์„ ์ด ํ•จ์ˆ˜(is..)๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ถ€๋ถ„์œผ๋กœ ๋„˜๊ธฐ๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•˜๊ณคํ•ฉ๋‹ˆ๋‹ค 2. ์ด๊ฒŒ static method๊ฐ€ ์•„๋‹Œ method์ผ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?
@@ -0,0 +1,28 @@ +import GameMessage from "./GameMessage.js"; +import { VALID_INPUT_LENGTH } from "./gameConstants.js"; + +class Validator { + static isValidInput(input) { + if (!this.isNumber(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_NUMBER); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_CORRECT_LENGTH); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_IS_DUPLICATED); + return true; + } + + static isNumber(input) { + return !Number.isNaN(input); + } + + static isValidLength(input) { + return input.length === VALID_INPUT_LENGTH; + } + + static isDuplicate(input) { + return [...new Set(input)].length === VALID_INPUT_LENGTH; + } +} + +export default Validator;
JavaScript
ํ•„์š”์—†๋Š” ์ฃผ์„์€ ์ง€์šฐ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค !
@@ -0,0 +1,28 @@ +import GameMessage from "./GameMessage.js"; +import { VALID_INPUT_LENGTH } from "./gameConstants.js"; + +class Validator { + static isValidInput(input) { + if (!this.isNumber(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_NUMBER); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_NOT_A_CORRECT_LENGTH); + if (!this.isValidLength(input)) + throw new Error(GameMessage.INVALID_INPUT_IS_DUPLICATED); + return true; + } + + static isNumber(input) { + return !Number.isNaN(input); + } + + static isValidLength(input) { + return input.length === VALID_INPUT_LENGTH; + } + + static isDuplicate(input) { + return [...new Set(input)].length === VALID_INPUT_LENGTH; + } +} + +export default Validator;
JavaScript
boolean์„ ๋ฆฌํ„ดํ•  ๋•Œ๋Š” ๋ฉ”์„œ๋“œ์˜ prefix์— is, has๋ฅผ ๋ถ™์—ฌ์ฃผ๋Š” ๊ฒƒ์ด ๊ด€๋ก€์ž…๋‹ˆ๋‹คใ…Ž_ใ…Ž
@@ -0,0 +1,49 @@ +import { Random } from "@woowacourse/mission-utils"; +import { + VALID_INPUT_LENGTH, + MIN_RANDOM_NUMBER, + MAX_RANDOM_NUMBER, +} from "./gameConstants.js"; + +class Computer { + #solution; + + seeSolution() { + return this.#solution; + } + + makeSolution() { + const computer = []; + while (computer.length < VALID_INPUT_LENGTH) { + const number = Random.pickNumberInRange( + MIN_RANDOM_NUMBER, + MAX_RANDOM_NUMBER + ); + if (!computer.includes(number)) { + computer.push(number); + } + } + this.#solution = computer; + } + + assessUserInput(input) { + let strike = 0; + let ball = 0; + const userInput = input.split("").map(Number); + userInput.forEach((item, index) => { + if ( + this.#solution.indexOf(item) === index && + this.#solution.includes(item) + ) + strike += 1; + else if ( + this.#solution.indexOf(item) !== index && + this.#solution.includes(item) + ) + ball += 1; + }); + return { strike, ball }; + } +} + +export default Computer;
JavaScript
์–ด๋–ค ๊ตฌ๋ฌธ์—๋Š” ์„ธ๋ฏธ์ฝœ๋ก ์ด ์žˆ๊ณ , ์–ด๋–ค ๊ตฌ๋ฌธ์—๋Š” ์„ธ๋ฏธ์ฝœ๋ก ์ด ์žˆ์ง€ ์•Š๋„ค์š”. ๋‘˜ ์ค‘ ํ•˜๋‚˜๋งŒ ํ•˜์‹œ๋Š” ๊ฑธ ์ถ”์ฒœ๋“œ๋ฆฌ๊ณ , ๊ฐ•์ œํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด prettier๋“ฑ์„ ์ด์šฉํ•ด๋ณด์„ธ์š”.
@@ -0,0 +1,49 @@ +import { Random } from "@woowacourse/mission-utils"; +import { + VALID_INPUT_LENGTH, + MIN_RANDOM_NUMBER, + MAX_RANDOM_NUMBER, +} from "./gameConstants.js"; + +class Computer { + #solution; + + seeSolution() { + return this.#solution; + } + + makeSolution() { + const computer = []; + while (computer.length < VALID_INPUT_LENGTH) { + const number = Random.pickNumberInRange( + MIN_RANDOM_NUMBER, + MAX_RANDOM_NUMBER + ); + if (!computer.includes(number)) { + computer.push(number); + } + } + this.#solution = computer; + } + + assessUserInput(input) { + let strike = 0; + let ball = 0; + const userInput = input.split("").map(Number); + userInput.forEach((item, index) => { + if ( + this.#solution.indexOf(item) === index && + this.#solution.includes(item) + ) + strike += 1; + else if ( + this.#solution.indexOf(item) !== index && + this.#solution.includes(item) + ) + ball += 1; + }); + return { strike, ball }; + } +} + +export default Computer;
JavaScript
1. ์ด๋ ‡๊ฒŒ๋„ ๋ฉ๋‹ˆ๋‹ค. ```suggestion const userInput = input.split("").map(Number); ``` 2. ๋ฐฐ์—ด์ด๋ฉด.. s๊ฐ€ ๋ถ™์œผ๋ฉด ์ข‹์ง€ ์•Š์„๊นŒ์š”?
@@ -0,0 +1,49 @@ +import { Random } from "@woowacourse/mission-utils"; +import { + VALID_INPUT_LENGTH, + MIN_RANDOM_NUMBER, + MAX_RANDOM_NUMBER, +} from "./gameConstants.js"; + +class Computer { + #solution; + + seeSolution() { + return this.#solution; + } + + makeSolution() { + const computer = []; + while (computer.length < VALID_INPUT_LENGTH) { + const number = Random.pickNumberInRange( + MIN_RANDOM_NUMBER, + MAX_RANDOM_NUMBER + ); + if (!computer.includes(number)) { + computer.push(number); + } + } + this.#solution = computer; + } + + assessUserInput(input) { + let strike = 0; + let ball = 0; + const userInput = input.split("").map(Number); + userInput.forEach((item, index) => { + if ( + this.#solution.indexOf(item) === index && + this.#solution.includes(item) + ) + strike += 1; + else if ( + this.#solution.indexOf(item) !== index && + this.#solution.includes(item) + ) + ball += 1; + }); + return { strike, ball }; + } +} + +export default Computer;
JavaScript
reduce๋ฅผ ์จ์„œ๋„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š” ```js const strikeAndBall = userInput.reduce((acc, cur) => { if ((this.#solution.indexOf(item) === index) && this.#solution.includes(item)) return { ...acc, strike: acc.strike + 1 } if ((this.#solution.indexOf(item) !== index) && this.#solution.includes(item)) return { ...acc, ball:acc.ball + 1} return acc; }, { strike: 0, ball: 0}) ```
@@ -0,0 +1,15 @@ +{ + "arrowParens": "always", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 80, + "proseWrap": "always", + "quoteProps": "as-needed", + "semi": true, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false, + "endOfLine": "auto" +} \ No newline at end of file
Unknown
์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด prettier๊ฐ€ ์ ์šฉ๋˜์–ด์žˆ์ง€ ์•Š์€๋ฐ, ํ™•์ธํ•œ๋ฒˆ ํ•ด๋ณด์„ธ์šฉ
@@ -0,0 +1,49 @@ +import { Random } from "@woowacourse/mission-utils"; +import { + VALID_INPUT_LENGTH, + MIN_RANDOM_NUMBER, + MAX_RANDOM_NUMBER, +} from "./gameConstants.js"; + +class Computer { + #solution; + + seeSolution() { + return this.#solution; + } + + makeSolution() { + const computer = []; + while (computer.length < VALID_INPUT_LENGTH) { + const number = Random.pickNumberInRange( + MIN_RANDOM_NUMBER, + MAX_RANDOM_NUMBER + ); + if (!computer.includes(number)) { + computer.push(number); + } + } + this.#solution = computer; + } + + assessUserInput(input) { + let strike = 0; + let ball = 0; + const userInput = input.split("").map(Number); + userInput.forEach((item, index) => { + if ( + this.#solution.indexOf(item) === index && + this.#solution.includes(item) + ) + strike += 1; + else if ( + this.#solution.indexOf(item) !== index && + this.#solution.includes(item) + ) + ball += 1; + }); + return { strike, ball }; + } +} + +export default Computer;
JavaScript
์ด๊ฑธ ๋ฆฌํ„ดํ•˜๋Š” ์ด์œ ๊ฐ€ ๋ญ”๊ฐ€์š” ?
@@ -1,5 +1,62 @@ +import { Console } from "@woowacourse/mission-utils"; +import User from "./User.js"; +import Computer from "./Computer.js"; +import Validator from "./Validator.js"; +import GameMessage from "./GameMessage.js"; +import { RETRY_RESPONSE, FULL_STRIKE } from "./gameConstants.js"; + class App { - async play() {} + constructor() { + this.user = new User(); + this.computer = new Computer(); + } + + async play() { + this.computer.makeSolution(); + Console.print(GameMessage.START_MESSAGE); + await this.mainLogic(); + } + + async mainLogic() { + await this.setUserInput(); + this.printStrikeBall(); + if ( + this.computer.assessUserInput(this.user.getNumber()).strike !== + FULL_STRIKE + ) + await this.mainLogic(); + else { + const replayResponse = await Console.readLineAsync( + "๊ฒŒ์ž„์„ ์ƒˆ๋กœ ์‹œ์ž‘ํ•˜๋ ค๋ฉด 1, ์ข…๋ฃŒํ•˜๋ ค๋ฉด 2๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”." + ); + if (parseInt(replayResponse, 10) === RETRY_RESPONSE) { + this.computer.makeSolution(); + this.mainLogic(); + } + } + } + + async setUserInput() { + const input = await Console.readLineAsync("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : "); + if (Validator.isValidInput(input)) { + this.user.setNumber(input); + } + } + + printStrikeBall() { + const { strike, ball } = this.computer.assessUserInput( + this.user.getNumber() + ); + if (strike === 0 && ball === 0) { + Console.print(GameMessage.NOTHING_MESSAGE); + } else if (strike > 0 && ball > 0) { + Console.print(`${strike}๋ณผ ${ball}์ŠคํŠธ๋ผ์ดํฌ`); + } else if (strike === FULL_STRIKE) { + Console.print(GameMessage.SOLVED_MESSAGE); + } else { + Console.print(`${strike}์ŠคํŠธ๋ผ์ดํฌ ${ball}๋ณผ`); + } + } } export default App;
JavaScript
indent๊ฐ€..
@@ -1,5 +1,62 @@ +import { Console } from "@woowacourse/mission-utils"; +import User from "./User.js"; +import Computer from "./Computer.js"; +import Validator from "./Validator.js"; +import GameMessage from "./GameMessage.js"; +import { RETRY_RESPONSE, FULL_STRIKE } from "./gameConstants.js"; + class App { - async play() {} + constructor() { + this.user = new User(); + this.computer = new Computer(); + } + + async play() { + this.computer.makeSolution(); + Console.print(GameMessage.START_MESSAGE); + await this.mainLogic(); + } + + async mainLogic() { + await this.setUserInput(); + this.printStrikeBall(); + if ( + this.computer.assessUserInput(this.user.getNumber()).strike !== + FULL_STRIKE + ) + await this.mainLogic(); + else { + const replayResponse = await Console.readLineAsync( + "๊ฒŒ์ž„์„ ์ƒˆ๋กœ ์‹œ์ž‘ํ•˜๋ ค๋ฉด 1, ์ข…๋ฃŒํ•˜๋ ค๋ฉด 2๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”." + ); + if (parseInt(replayResponse, 10) === RETRY_RESPONSE) { + this.computer.makeSolution(); + this.mainLogic(); + } + } + } + + async setUserInput() { + const input = await Console.readLineAsync("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : "); + if (Validator.isValidInput(input)) { + this.user.setNumber(input); + } + } + + printStrikeBall() { + const { strike, ball } = this.computer.assessUserInput( + this.user.getNumber() + ); + if (strike === 0 && ball === 0) { + Console.print(GameMessage.NOTHING_MESSAGE); + } else if (strike > 0 && ball > 0) { + Console.print(`${strike}๋ณผ ${ball}์ŠคํŠธ๋ผ์ดํฌ`); + } else if (strike === FULL_STRIKE) { + Console.print(GameMessage.SOLVED_MESSAGE); + } else { + Console.print(`${strike}์ŠคํŠธ๋ผ์ดํฌ ${ball}๋ณผ`); + } + } } export default App;
JavaScript
๋งค์ง๋„˜๋ฒ„๊ฐ€ ์‚ด์•„์ด์žˆ๋„ค์šฉ
@@ -1,5 +1,62 @@ +import { Console } from "@woowacourse/mission-utils"; +import User from "./User.js"; +import Computer from "./Computer.js"; +import Validator from "./Validator.js"; +import GameMessage from "./GameMessage.js"; +import { RETRY_RESPONSE, FULL_STRIKE } from "./gameConstants.js"; + class App { - async play() {} + constructor() { + this.user = new User(); + this.computer = new Computer(); + } + + async play() { + this.computer.makeSolution(); + Console.print(GameMessage.START_MESSAGE); + await this.mainLogic(); + } + + async mainLogic() { + await this.setUserInput(); + this.printStrikeBall(); + if ( + this.computer.assessUserInput(this.user.getNumber()).strike !== + FULL_STRIKE + ) + await this.mainLogic(); + else { + const replayResponse = await Console.readLineAsync( + "๊ฒŒ์ž„์„ ์ƒˆ๋กœ ์‹œ์ž‘ํ•˜๋ ค๋ฉด 1, ์ข…๋ฃŒํ•˜๋ ค๋ฉด 2๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”." + ); + if (parseInt(replayResponse, 10) === RETRY_RESPONSE) { + this.computer.makeSolution(); + this.mainLogic(); + } + } + } + + async setUserInput() { + const input = await Console.readLineAsync("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : "); + if (Validator.isValidInput(input)) { + this.user.setNumber(input); + } + } + + printStrikeBall() { + const { strike, ball } = this.computer.assessUserInput( + this.user.getNumber() + ); + if (strike === 0 && ball === 0) { + Console.print(GameMessage.NOTHING_MESSAGE); + } else if (strike > 0 && ball > 0) { + Console.print(`${strike}๋ณผ ${ball}์ŠคํŠธ๋ผ์ดํฌ`); + } else if (strike === FULL_STRIKE) { + Console.print(GameMessage.SOLVED_MESSAGE); + } else { + Console.print(`${strike}์ŠคํŠธ๋ผ์ดํฌ ${ball}๋ณผ`); + } + } } export default App;
JavaScript
์ด๋ ‡๊ฒŒ eslint ๊ทœ์น™์„ ๋ฌด์‹œํ• ๊ฑฐ๋ฉด eslint๋ฅผ ์™œ ์‚ฌ์šฉํ•˜์‹œ๋‚˜์š”?
@@ -1,20 +1,36 @@ package model; +import java.util.ArrayList; import java.util.List; public class Lotto { - private List<String> lottoNumbers; + private List<LottoNo> lottoNumbers; - public Lotto(List<String> lottoNumbers) { + public Lotto(List<LottoNo> lottoNumbers) { this.lottoNumbers = lottoNumbers; } - public int getCorrectNumberCount(List<String> winningNumber) { - return (int) winningNumber.stream().filter((x) -> lottoNumbers.contains(x)).count(); + public Lotto(String[] lottoNumbers) { + this.lottoNumbers = new ArrayList<>(); + for (int i = 0; i < lottoNumbers.length; i++) + this.lottoNumbers.add(new LottoNo(Integer.parseInt(lottoNumbers[i]))); } public String showLotto() { - return lottoNumbers.toString(); + List<String> lotto = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNumbers) + lotto.add(lottoNo.getStringNumber()); + + return lotto.toString(); + } + + public int getCorrectCount(List<String> winningNumbers) { + return (int) lottoNumbers.stream().filter((x) -> winningNumbers.contains(x.getStringNumber())).count(); + } + + public boolean isContain(String stringNumber) { + return (int)lottoNumbers.stream().filter(x -> x.getStringNumber().equals(stringNumber)).count() != 0; } }
Java
๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ Set ์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ๊ณผ List ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์„ ๋น„๊ตํ•ด ๋ณด์•˜์„ ๋•Œ ์–ด๋–ค ์žฅ๋‹จ์ ์ด ์žˆ์„๊นŒ์š”? ์—ฌ๊ธฐ์„œ๋Š” ์–ด๋–ค ์ž๋ฃŒ๊ตฌ์กฐ๊ฐ€ ์–ด์šธ๋ฆด๊นŒ์š”?
@@ -1,20 +1,36 @@ package model; +import java.util.ArrayList; import java.util.List; public class Lotto { - private List<String> lottoNumbers; + private List<LottoNo> lottoNumbers; - public Lotto(List<String> lottoNumbers) { + public Lotto(List<LottoNo> lottoNumbers) { this.lottoNumbers = lottoNumbers; } - public int getCorrectNumberCount(List<String> winningNumber) { - return (int) winningNumber.stream().filter((x) -> lottoNumbers.contains(x)).count(); + public Lotto(String[] lottoNumbers) { + this.lottoNumbers = new ArrayList<>(); + for (int i = 0; i < lottoNumbers.length; i++) + this.lottoNumbers.add(new LottoNo(Integer.parseInt(lottoNumbers[i]))); } public String showLotto() { - return lottoNumbers.toString(); + List<String> lotto = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNumbers) + lotto.add(lottoNo.getStringNumber()); + + return lotto.toString(); + } + + public int getCorrectCount(List<String> winningNumbers) { + return (int) lottoNumbers.stream().filter((x) -> winningNumbers.contains(x.getStringNumber())).count(); + } + + public boolean isContain(String stringNumber) { + return (int)lottoNumbers.stream().filter(x -> x.getStringNumber().equals(stringNumber)).count() != 0; } }
Java
ํ•œ์ค„์ด๋”๋ผ๋„ ๊ด„ํ˜ธ๋ฅผ ๋ถ™์—ฌ์ฃผ๋Š”๊ฑธ ์ปจ๋ฒค์…˜์œผ๋กœ ํ•ฉ์‹œ๋‹ค. ์ด๊ฒƒ์ด ๊ฐ„๊ฒฐํ•˜๋”๋ผ๋„ ์ฝ๋Š” ์‚ฌ๋žŒ ์ž…์žฅ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ๋‹น์—ฐํžˆ ์žˆ์–ด์•ผํ•  ๊ณณ์— ๋ฌด์–ธ๊ฐ€๊ฐ€ ๋น ์ง€๊ฒŒ ๋˜๋ฉด ๊ฐ€๋…์„ฑ์ด ์ €ํ•˜๋ฉ๋‹ˆ๋‹ค. (์ฑ… ์ฝ์„ ๋•Œ์™€ ๋น„์Šท) ๊ทธ๋ฆฌ๊ณ  ์ƒ์„ฑ์ž์—์„œ ๋ญ”๊ฐ€ ๋งŽ์€ ์ผ์„ ํ•ด์ฃผ๋Š”๊ฒŒ ์•„์‰ฝ๋„ค์š”
@@ -1,20 +1,36 @@ package model; +import java.util.ArrayList; import java.util.List; public class Lotto { - private List<String> lottoNumbers; + private List<LottoNo> lottoNumbers; - public Lotto(List<String> lottoNumbers) { + public Lotto(List<LottoNo> lottoNumbers) { this.lottoNumbers = lottoNumbers; } - public int getCorrectNumberCount(List<String> winningNumber) { - return (int) winningNumber.stream().filter((x) -> lottoNumbers.contains(x)).count(); + public Lotto(String[] lottoNumbers) { + this.lottoNumbers = new ArrayList<>(); + for (int i = 0; i < lottoNumbers.length; i++) + this.lottoNumbers.add(new LottoNo(Integer.parseInt(lottoNumbers[i]))); } public String showLotto() { - return lottoNumbers.toString(); + List<String> lotto = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNumbers) + lotto.add(lottoNo.getStringNumber()); + + return lotto.toString(); + } + + public int getCorrectCount(List<String> winningNumbers) { + return (int) lottoNumbers.stream().filter((x) -> winningNumbers.contains(x.getStringNumber())).count(); + } + + public boolean isContain(String stringNumber) { + return (int)lottoNumbers.stream().filter(x -> x.getStringNumber().equals(stringNumber)).count() != 0; } }
Java
boolean์„ int ๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” ์ด์œ ๋Š” ๋ญ”๊ฐ€์š”?
@@ -1,20 +1,36 @@ package model; +import java.util.ArrayList; import java.util.List; public class Lotto { - private List<String> lottoNumbers; + private List<LottoNo> lottoNumbers; - public Lotto(List<String> lottoNumbers) { + public Lotto(List<LottoNo> lottoNumbers) { this.lottoNumbers = lottoNumbers; } - public int getCorrectNumberCount(List<String> winningNumber) { - return (int) winningNumber.stream().filter((x) -> lottoNumbers.contains(x)).count(); + public Lotto(String[] lottoNumbers) { + this.lottoNumbers = new ArrayList<>(); + for (int i = 0; i < lottoNumbers.length; i++) + this.lottoNumbers.add(new LottoNo(Integer.parseInt(lottoNumbers[i]))); } public String showLotto() { - return lottoNumbers.toString(); + List<String> lotto = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNumbers) + lotto.add(lottoNo.getStringNumber()); + + return lotto.toString(); + } + + public int getCorrectCount(List<String> winningNumbers) { + return (int) lottoNumbers.stream().filter((x) -> winningNumbers.contains(x.getStringNumber())).count(); + } + + public boolean isContain(String stringNumber) { + return (int)lottoNumbers.stream().filter(x -> x.getStringNumber().equals(stringNumber)).count() != 0; } }
Java
์ด ๋ถ€๋ถ„ ์ข€ ๋” ๊ฐœ์„ ํ•ด๋ณด์„ธ์š”
@@ -1,20 +1,36 @@ package model; +import java.util.ArrayList; import java.util.List; public class Lotto { - private List<String> lottoNumbers; + private List<LottoNo> lottoNumbers; - public Lotto(List<String> lottoNumbers) { + public Lotto(List<LottoNo> lottoNumbers) { this.lottoNumbers = lottoNumbers; } - public int getCorrectNumberCount(List<String> winningNumber) { - return (int) winningNumber.stream().filter((x) -> lottoNumbers.contains(x)).count(); + public Lotto(String[] lottoNumbers) { + this.lottoNumbers = new ArrayList<>(); + for (int i = 0; i < lottoNumbers.length; i++) + this.lottoNumbers.add(new LottoNo(Integer.parseInt(lottoNumbers[i]))); } public String showLotto() { - return lottoNumbers.toString(); + List<String> lotto = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNumbers) + lotto.add(lottoNo.getStringNumber()); + + return lotto.toString(); + } + + public int getCorrectCount(List<String> winningNumbers) { + return (int) lottoNumbers.stream().filter((x) -> winningNumbers.contains(x.getStringNumber())).count(); + } + + public boolean isContain(String stringNumber) { + return (int)lottoNumbers.stream().filter(x -> x.getStringNumber().equals(stringNumber)).count() != 0; } }
Java
x ๋ฅผ ์ข€ ๋” ์˜๋ฏธ์žˆ๋Š” ๋ณ€์ˆ˜์ด๋ฆ„์œผ๋กœ ์ง€์—ˆ์œผ๋ฉด ์ข‹์•˜์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋ฉ”์†Œ๋“œ ์ฒด์ด๋‹ ๋ฐฉ์‹์—์„œ๋Š” ๊ธธ์ด๊ฐ€ ๊ธธ์–ด์ง€๋ฉด IDE์—์„œ ํ•œ๋ˆˆ์— ํ™•์ธํ•˜๊ธฐ ํž˜๋“œ๋‹ˆ๊นŒ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ์—”ํ„ฐ๋กœ ๋ผ์ธ์ •๋ฆฌ๋ฅผ ์–ด๋А์ •๋„ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•œ ์ปจ๋ฒค์…˜๋„ intellij code style ์—์„œ ์ž๋™์ •๋ ฌ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๊ธด ํ•ฉ๋‹ˆ๋‹ค(์ €๋Š” ์‚ฌ์šฉ์ค‘)
@@ -1,10 +1,8 @@ package model; -import util.ListGenerator; import util.SplitGenerator; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -13,43 +11,44 @@ public class LottoMachine { private static int LOTTO_NUMBER_RANGE = 45; private static int LOTTO_NUMBER_COUNT = 6; private static int LOTTO_PRICE = 1000; - List<Lotto> lottos = new ArrayList<>(); - public List<String> buyLotto(int totalLottoPrice) { - for (int i = 0; i < getLottoCount(totalLottoPrice); i++) - lottos.add(new Lotto(getRandomNumbers(LOTTO_NUMBER_RANGE))); - return showLottoHistory(); + private int tryCount = 0; + + public Lotto getAutoLotto() { + decreaseCount(); + return new Lotto(getRandomNumbers(getNumbersInRange(LOTTO_NUMBER_RANGE))); } - private int getLottoCount(int totalPrice) { - return totalPrice / LOTTO_PRICE; + public void inputMoney(int money) { + tryCount += money / LOTTO_PRICE; } - private List<String> getRandomNumbers(int range) { - List<String> numbersInRange = ListGenerator.getNumbersInRange(range); - Collections.shuffle(numbersInRange); - return numbersInRange.subList(0, LOTTO_NUMBER_COUNT); + public boolean canLotto() { + return tryCount > 0; } - public int[] getStatistic(String winningNumber) { - return createStatistic(toStringList(winningNumber)); + private void decreaseCount() { + if (canLotto() == false) + throw new RuntimeException("๋ˆ ๋„ฃ์–ด!!"); + tryCount--; } - private List<String> toStringList(String winningNumber) { - return Arrays.asList(SplitGenerator.splitWithSign(winningNumber, ", ")); + private List<LottoNo> getNumbersInRange(int range) { + List<LottoNo> numbersInRange = new ArrayList<>(); + + for (int i = 1; i <= range; i++) + numbersInRange.add(new LottoNo(i)); + + return numbersInRange; } - private int[] createStatistic(List<String> winningNumber) { - int[] statistic = new int[LOTTO_NUMBER_COUNT + 1]; - for (Lotto lotto : lottos) - statistic[lotto.getCorrectNumberCount(winningNumber)]++; - return statistic; + private List<LottoNo> getRandomNumbers(List<LottoNo> numbersInRange) { + Collections.shuffle(numbersInRange); + return numbersInRange.subList(0, LOTTO_NUMBER_COUNT); } - private List<String> showLottoHistory() { - List<String> lottoHistory = new ArrayList<>(); - for (Lotto lotto : lottos) - lottoHistory.add(lotto.showLotto()); - return lottoHistory; + public Lotto getDirectLotto(String numbers) { + decreaseCount(); + return new Lotto(SplitGenerator.splitWithSign(numbers, ", ")); } }
Java
getter ์™€ ํ—ท๊ฐˆ๋ฆฌ๋ฏ€๋กœ calculateRandomNumbers ์ฒ˜๋Ÿผ ๋‹ค๋ฅธ ๋‹จ์–ด๋ฅผ ํ™œ์šฉํ•ด๋ณด์‹œ๋Š”๊ฑธ ์ถ”์ฒœ
@@ -1,20 +1,36 @@ package model; +import java.util.ArrayList; import java.util.List; public class Lotto { - private List<String> lottoNumbers; + private List<LottoNo> lottoNumbers; - public Lotto(List<String> lottoNumbers) { + public Lotto(List<LottoNo> lottoNumbers) { this.lottoNumbers = lottoNumbers; } - public int getCorrectNumberCount(List<String> winningNumber) { - return (int) winningNumber.stream().filter((x) -> lottoNumbers.contains(x)).count(); + public Lotto(String[] lottoNumbers) { + this.lottoNumbers = new ArrayList<>(); + for (int i = 0; i < lottoNumbers.length; i++) + this.lottoNumbers.add(new LottoNo(Integer.parseInt(lottoNumbers[i]))); } public String showLotto() { - return lottoNumbers.toString(); + List<String> lotto = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNumbers) + lotto.add(lottoNo.getStringNumber()); + + return lotto.toString(); + } + + public int getCorrectCount(List<String> winningNumbers) { + return (int) lottoNumbers.stream().filter((x) -> winningNumbers.contains(x.getStringNumber())).count(); + } + + public boolean isContain(String stringNumber) { + return (int)lottoNumbers.stream().filter(x -> x.getStringNumber().equals(stringNumber)).count() != 0; } }
Java
int ๊ฐ’์œผ๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋กœ ์ฒ˜์Œ ๊ตฌํ˜„ํ•˜์˜€๋Š”๋ฐ ๋ฆฌํŒฉํ† ๋ง ๊ณผ์ •์—์„œ boolean ํƒ€์ž…์œผ๋กœ ๋ฐ”๊ฟ€๋•Œ ๊นœ๋นกํ•œ ๊ฒƒ๊ฐ™๋„ค์š”.. ์‹ค์ˆ˜ํ•˜์ง€ ์•Š๋„๋ก ์ฃผ์˜ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -1,20 +1,36 @@ package model; +import java.util.ArrayList; import java.util.List; public class Lotto { - private List<String> lottoNumbers; + private List<LottoNo> lottoNumbers; - public Lotto(List<String> lottoNumbers) { + public Lotto(List<LottoNo> lottoNumbers) { this.lottoNumbers = lottoNumbers; } - public int getCorrectNumberCount(List<String> winningNumber) { - return (int) winningNumber.stream().filter((x) -> lottoNumbers.contains(x)).count(); + public Lotto(String[] lottoNumbers) { + this.lottoNumbers = new ArrayList<>(); + for (int i = 0; i < lottoNumbers.length; i++) + this.lottoNumbers.add(new LottoNo(Integer.parseInt(lottoNumbers[i]))); } public String showLotto() { - return lottoNumbers.toString(); + List<String> lotto = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNumbers) + lotto.add(lottoNo.getStringNumber()); + + return lotto.toString(); + } + + public int getCorrectCount(List<String> winningNumbers) { + return (int) lottoNumbers.stream().filter((x) -> winningNumbers.contains(x.getStringNumber())).count(); + } + + public boolean isContain(String stringNumber) { + return (int)lottoNumbers.stream().filter(x -> x.getStringNumber().equals(stringNumber)).count() != 0; } }
Java
set๊ณผ List์˜ ๊ฐ€์žฅ ํฐ ์ฐจ์ด์ ์€ ์ค‘๋ณต์„ ํ—ˆ์šฉํ•˜๋Š”์ง€ ์•ˆํ•˜๋Š”์ง€๋กœ ์•Œ๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ถ€๋ถ„์—์„œ set์„ ํ™œ์šฉํ–ˆ์„๋•Œ ๋กœ๋˜ ๋ฒˆํ˜ธ๊ฐ€ 6๊ฐœ๊ฐ€ ๋ ๋•Œ๊นŒ์ง€ ๋žœ๋ค ์ˆซ์ž๋ฅผ ๋ฐ›๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๊ฒ ๋„ค์š” ์‹œ๋„ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,53 @@ +'use client'; + +import Button from '@/app/components/common/button/Button'; +import Modal from '@/app/components/common/modal/Modal'; +import IconAlert from '@/app/components/icons/IconAlert'; + +interface ConfirmModalInterface { + title: string; + cancelLabel?: string; + confirmLabel?: string; + isModalOpen: boolean; + handleCancel: () => void; + handleConfirm: () => void; +} + +function ConfirmModal({ + title, + cancelLabel, + confirmLabel, + isModalOpen, + handleCancel, + handleConfirm, +}: ConfirmModalInterface) { + return ( + <Modal isOpen={isModalOpen} closeModal={handleCancel}> + <div className="flex flex-col items-center"> + <IconAlert /> + <div className="mt-4 flex w-[239px] flex-col items-center"> + <h2 className="mb-4 text-lg font-light">{title}</h2> + </div> + + <div className="flex justify-end gap-4"> + <Button + onClick={handleCancel} + variant="secondary" + className="w-[8.5rem]" + > + {cancelLabel || '๋‹ซ๊ธฐ'} + </Button> + <Button + onClick={handleConfirm} + variant="danger" + className="w-[8.5rem]" + > + {confirmLabel || 'ํšŒ์› ํƒˆํ‡ด'} + </Button> + </div> + </div> + </Modal> + ); +} + +export default ConfirmModal;
Unknown
๊ณตํ†ต ์ปดํฌ๋„ŒํŠธ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!!!
@@ -10,6 +10,7 @@ import useModal from '@/app/hooks/useModal'; import DetailMemberModal from '@/app/components/team/DetailMemberModal'; import deleteMember from '@/app/lib/group/deleteMemeber'; import { useMutation, useQueryClient } from '@tanstack/react-query'; +import ConfirmModal from '@/app/components/common/modal/ConfirmModal'; interface GroupMember { role: 'ADMIN' | 'MEMBER'; @@ -24,6 +25,11 @@ function MemberCard({ member }: { member: GroupMember }) { const queryClient = useQueryClient(); const { isOpen, toggleDropdown, closeDropdown } = useDropdown(); const { isOpen: isModalOpen, openModal, closeModal } = useModal(); + const { + isOpen: isConfirmModalOpen, + openModal: openConfirmModal, + closeModal: closeConfirmModal, + } = useModal(); const { mutate: expelMember } = useMutation({ mutationFn: deleteMember, @@ -66,7 +72,7 @@ function MemberCard({ member }: { member: GroupMember }) { <DropdownItem onClick={openModal} onClose={closeDropdown}> ๋ฉค๋ฒ„ ์ •๋ณด </DropdownItem> - <DropdownItem onClick={handleExpel} onClose={closeDropdown}> + <DropdownItem onClick={openConfirmModal} onClose={closeDropdown}> ์ถ”๋ฐฉํ•˜๊ธฐ </DropdownItem> </DropdownList> @@ -77,6 +83,14 @@ function MemberCard({ member }: { member: GroupMember }) { isOpen={isModalOpen} closeModal={closeModal} /> + <ConfirmModal + isModalOpen={isConfirmModalOpen} + title={`${member.userName}๋‹˜์„ ์ถ”๋ฐฉํ•˜์‹œ๊ฒ ์–ด์š”?`} + cancelLabel="์ทจ์†Œ" + confirmLabel="์ถ”๋ฐฉ" + handleCancel={closeConfirmModal} + handleConfirm={handleExpel} + /> </> ); }
Unknown
`๋ฅผ ์ถ”๋ฐฉํ•˜์‹œ๊ฒ ์–ด์š”?` ๋ผ๊ณ  ๋ช…์‹œํ•˜๋ฉด ์ด๋ฆ„ ๋งˆ์ง€๋ง‰ ๊ธ€์ž์— ๋ฐ›์นจ์ด ์žˆ๋Š” ์‚ฌ๋žŒ์€ ๋ฌธ๊ตฌ๊ฐ€ ์–ด์ƒ‰ํ•˜๊ฒŒ ๋ณด์ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์˜ˆ): ํ™์ง€์œค๋ฅผ ์ถ”๋ฐฉํ•˜์‹œ๊ฒ ์–ด์š”? ๊ทธ๋ž˜์„œ `${member.userName}๋‹˜์„ ์ถ”๋ฐฉํ•˜์‹œ๊ฒ ์–ด์š”?` ๊ฐ€ ๋” ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -10,6 +10,7 @@ import useModal from '@/app/hooks/useModal'; import DetailMemberModal from '@/app/components/team/DetailMemberModal'; import deleteMember from '@/app/lib/group/deleteMemeber'; import { useMutation, useQueryClient } from '@tanstack/react-query'; +import ConfirmModal from '@/app/components/common/modal/ConfirmModal'; interface GroupMember { role: 'ADMIN' | 'MEMBER'; @@ -24,6 +25,11 @@ function MemberCard({ member }: { member: GroupMember }) { const queryClient = useQueryClient(); const { isOpen, toggleDropdown, closeDropdown } = useDropdown(); const { isOpen: isModalOpen, openModal, closeModal } = useModal(); + const { + isOpen: isConfirmModalOpen, + openModal: openConfirmModal, + closeModal: closeConfirmModal, + } = useModal(); const { mutate: expelMember } = useMutation({ mutationFn: deleteMember, @@ -66,7 +72,7 @@ function MemberCard({ member }: { member: GroupMember }) { <DropdownItem onClick={openModal} onClose={closeDropdown}> ๋ฉค๋ฒ„ ์ •๋ณด </DropdownItem> - <DropdownItem onClick={handleExpel} onClose={closeDropdown}> + <DropdownItem onClick={openConfirmModal} onClose={closeDropdown}> ์ถ”๋ฐฉํ•˜๊ธฐ </DropdownItem> </DropdownList> @@ -77,6 +83,14 @@ function MemberCard({ member }: { member: GroupMember }) { isOpen={isModalOpen} closeModal={closeModal} /> + <ConfirmModal + isModalOpen={isConfirmModalOpen} + title={`${member.userName}๋‹˜์„ ์ถ”๋ฐฉํ•˜์‹œ๊ฒ ์–ด์š”?`} + cancelLabel="์ทจ์†Œ" + confirmLabel="์ถ”๋ฐฉ" + handleCancel={closeConfirmModal} + handleConfirm={handleExpel} + /> </> ); }
Unknown
๋ฌธ๊ตฌ ๋””ํ…Œ์ผ์„ ๋†“์ณค๋„ค์š”. ๋ฐ˜์˜ํ•ด์„œ ์˜ฌ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜Š
@@ -0,0 +1,31 @@ +package com.antique.dto.review; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ReviewRequestDTO { + @Schema(description = "๋ฆฌ๋ทฐ ์ž‘์„ฑ์ž ID") + @NotNull + private Long reviewerId; // ๋ฆฌ๋ทฐ ์ž‘์„ฑ์ž ID + + @Schema(description = "๋ฆฌ๋ทฐ ๋Œ€์ƒ์ž ID") + @NotNull + private Long reviewedUserId; // ๋ฆฌ๋ทฐ ๋Œ€์ƒ์ž ID + + @Schema(description = "์ œํ’ˆ ID") + @NotNull + private Long productId; // ์ œํ’ˆ ID + + @Schema(description = "ํ‰์ ") + @NotNull + private int rating; // ํ‰์  + + @Schema(description = "๋ฆฌ๋ทฐ ๋‚ด์šฉ") + private String content; // ๋ฆฌ๋ทฐ ๋‚ด์šฉ +}
Java
schema ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•ด์„œ ํ‘œํ˜„ํ•˜๋ฉด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์•„..!!
@@ -1,5 +1,12 @@ +import EventController from "./controller/EventController.js"; + class App { - async run() {} + constructor() { + this.eventController = new EventController(); + } + async run() { + await this.eventController.eventStart(); + } } export default App;
JavaScript
App ์ž์ฒด๊ฐ€ Controller๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ  ๊ตฌํ˜„์„ ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,111 @@ +import { MENU, MESSAGE, ARRAY, CALENDAR, BENEFIT_AMOUNT, BADGE, BOUNDARY } from "../commons/constants.js"; +import Order from "./Order.js"; +import { getMenu, getMenuCount } from "../commons/utils.js"; + +class Benefit { + #date; + #menu; + #order; + #benefitResult; + + constructor(date, menu) { + this.#date = date; + this.#menu = menu; + this.#order = new Order(date, menu); + } + + // ํ˜œํƒ ๋‚ด์—ญ + benefitDetail() { + // benefitResult [ DDay | Weekday | Weekend | Special | Giveaway ] + this.#benefitResult = [0, 0, 0, 0, 0]; + + if (this.#isBenefit()) { + if (this.#isDDay()) this.#benefitResult[ARRAY.DDAY] = this.#applyDDay(); + if (this.#isWeekday()) this.#benefitResult[ARRAY.WEEKDAY] = this.#applyWeekday(); + if (this.#isWeekend()) this.#benefitResult[ARRAY.WEEKEND] = this.#applyWeekend(); + if (this.#isSpecial()) this.#benefitResult[ARRAY.SPECIALDAY] = this.#applySpecial(); + if (this.#isGiveaway()) this.#benefitResult[ARRAY.GIVEAWAY] = this.#applyGiveaway(); + } + + return this.#benefitResult; + } + + // ์ด ํ˜œํƒ ๊ธˆ์•ก + totalBenefit() { + let totalBenefit = 0; + this.#benefitResult.forEach((benefit) => { + totalBenefit += benefit; + }); + + return totalBenefit; + } + + // ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก + expectedAmount() { + const totalDiscount = this.totalBenefit() - this.#benefitResult[ARRAY.GIVEAWAY]; + + return this.#order.getAllAmount() - totalDiscount; + } + + // 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€ + eventBadge() { + const totalBenefit = this.totalBenefit(); + + if (!this.#isBenefit()) return MESSAGE.NOTHING; + if (totalBenefit <= BOUNDARY.STAR_PRICE) return BADGE.STAR; + if (totalBenefit <= BOUNDARY.TREE_PRICE) return BADGE.TREE; + + return BADGE.SANTA; + } + + #isBenefit() { + return this.#order.getAllAmount() > BOUNDARY.BENEFIT_PRICE; + } + + #isDDay() { + return this.#date <= BOUNDARY.DDAY_END; + } + + #isWeekday() { + return CALENDAR.WEEKDAY.includes(this.#date); + } + + #isWeekend() { + return CALENDAR.WEEKEND.includes(this.#date); + } + + #isSpecial() { + return CALENDAR.SPECIAL.includes(this.#date); + } + + #isGiveaway() { + return this.#order.getAllAmount() >= BOUNDARY.GIVEAWAY_PRICE; + } + + #applyDDay() { + let discount = BENEFIT_AMOUNT.DDAY_START; + for (let day = 1; day < this.#date; day++) { + discount += BENEFIT_AMOUNT.DDAY_PLUS; + } + return discount; + } + + #applyWeekday() { + const menuCount = getMenuCount(getMenu(MENU.DESSERT), this.#menu); + return menuCount * BENEFIT_AMOUNT.WEEKDAY; + } + + #applyWeekend() { + const menuCount = getMenuCount(getMenu(MENU.MAIN), this.#menu); + return menuCount * BENEFIT_AMOUNT.WEEKEND; + } + + #applySpecial() { + return BENEFIT_AMOUNT.SPECIALDAY; + } + + #applyGiveaway() { + return BENEFIT_AMOUNT.GIVEAWAY; + } +} +export default Benefit;
JavaScript
benefitResult๋ฅผ Obejct๋กœ ๊ตฌํ˜„ํ•˜๋ฉด ์ข€ ๋” ๊ฐ€๋…์„ฑ์ด ์ข‹์ง€ ์•Š์„๊นŒ ์‹ถ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,88 @@ +import Benefit from "../src/model/Benefit.js"; +import { orderIntoArray } from "../src/commons/utils.js"; + +describe("Benefit ํด๋ž˜์Šค ํ…Œ์ŠคํŠธ(ํ˜œํƒ ์žˆ๋Š” ๊ฒฝ์šฐ)", () => { + //given + const date = "3"; + const menu = orderIntoArray("ํ‹ฐ๋ณธ์Šคํ…Œ์ดํฌ-1,๋ฐ”๋น„ํ๋ฆฝ-1,์ดˆ์ฝ”์ผ€์ดํฌ-2,์ œ๋กœ์ฝœ๋ผ-1"); + const benefit = new Benefit(date, menu); + + test("Benefit Detail(ํ˜œํƒ ๋‚ด์—ญ) ํ…Œ์ŠคํŠธ", () => { + // when + const result = benefit.benefitDetail(); + // then + const expected = [1200, 4046, 0, 1000, 25000]; + + expect(result).toEqual(expected); + }); + + test("Total Beneift(์ด ํ˜œํƒ ๊ธˆ์•ก) ํ…Œ์ŠคํŠธ", () => { + // when + const result = benefit.totalBenefit(); + // then + const expected = 31246; + + expect(result).toEqual(expected); + }); + + test("Expected Amount(์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก) ํ…Œ์ŠคํŠธ", () => { + // when + const result = benefit.expectedAmount(); + // then + const expected = 135754; + + expect(result).toEqual(expected); + }); + + test("Event Badge(์ด๋ฒคํŠธ ๋ฐฐ์ง€) ํ…Œ์ŠคํŠธ", () => { + // when + const result = benefit.eventBadge(); + // then + const expected = "์‚ฐํƒ€"; + + expect(result).toEqual(expected); + }); +}); + +describe("Benefit ํด๋ž˜์Šค ํ…Œ์ŠคํŠธ(ํ˜œํƒ ์—†๋Š” ๊ฒฝ์šฐ)", () => { + //given + const date = "26"; + const menu = orderIntoArray("ํƒ€ํŒŒ์Šค-1,์ œ๋กœ์ฝœ๋ผ-1"); + const benefit = new Benefit(date, menu); + + test("Benefit Detail(ํ˜œํƒ ๋‚ด์—ญ) ํ…Œ์ŠคํŠธ", () => { + // when + const result = benefit.benefitDetail(); + // then + const expected = [0, 0, 0, 0, 0]; + + expect(result).toEqual(expected); + }); + + test("Total Beneift(์ด ํ˜œํƒ ๊ธˆ์•ก) ํ…Œ์ŠคํŠธ", () => { + // when + const result = benefit.totalBenefit(); + // then + const expected = 0; + + expect(result).toEqual(expected); + }); + + test("Expected Amount(์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก) ํ…Œ์ŠคํŠธ", () => { + // when + const result = benefit.expectedAmount(); + // then + const expected = 8500; + + expect(result).toEqual(expected); + }); + + test("Event Badge(์ด๋ฒคํŠธ ๋ฐฐ์ง€) ํ…Œ์ŠคํŠธ", () => { + // when + const result = benefit.eventBadge(); + // then + const expected = "์—†์Œ"; + + expect(result).toEqual(expected); + }); +});
JavaScript
ํ…Œ์ŠคํŠธ๊ฐ€ ๋„ˆ๋ฌด ํ•œ์ •๋˜์–ด ์žˆ๋Š”๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค test.each๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ข€ ๋” ๋ฒ”์œ„์„ฑ ์žˆ๊ฒŒ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,63 @@ +import InputView from "../view/InputView.js"; +import OutputView from "../view/OutputView.js"; +import Order from "../model/Order.js"; +import Benefit from "../model/Benefit.js"; +import { print } from "../commons/utils.js"; +import { MENU } from "../commons/constants.js"; + +class EventController { + #date; + #menu; + + async eventStart() { + OutputView.printStart(); + + // ์ฃผ๋ฌธ ์ •๋ณด ์ž…๋ ฅ & ์ฃผ๋ฌธ ์ •๋ณด ์ถœ๋ ฅ + await this.#getOrderInformation(); + OutputView.printOrderInformation(this.#date, this.#menu); + + // ์ฃผ๋ฌธ ํด๋ž˜์Šค ์ƒ์„ฑ & ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก ์ถœ๋ ฅ + const order = new Order(this.#date, this.#menu); + OutputView.printAllAmount(order.getAllAmount()); + + // ํ˜œํƒ ํด๋ž˜์Šค ์ƒ์„ฑ & ํ˜œํƒ๊ณผ ๊ด€๋ จ๋œ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + const benefit = new Benefit(this.#date, this.#menu); + this.#printBenefit(benefit); + } + + async #getOrderInformation() { + await this.#getDate(); + await this.#getMenu(); + } + + async #getDate() { + while (true) { + try { + this.#date = await InputView.inputDate(); + break; + } catch (error) { + print(error); + } + } + } + + async #getMenu() { + while (true) { + try { + this.#menu = await InputView.inputMenu(); + break; + } catch (error) { + print(error); + } + } + } + + #printBenefit(benefit) { + OutputView.printGiveaway(benefit.benefitDetail()); // <์ฆ์ • ๋ฉ”๋‰ด> + OutputView.printBenefitDetail(benefit.benefitDetail()); // <ํ˜œํƒ ๋‚ด์—ญ> + OutputView.printTotalBenefit(benefit.totalBenefit()); // <์ด ํ˜œํ… ๊ธˆ์•ก> + OutputView.printExpectedAmount(benefit.expectedAmount()); // <ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก> + OutputView.printEventBadge(benefit.eventBadge()); // <12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€> + } +} +export default EventController;
JavaScript
๊ฐ๊ฐ์˜ ๋””๋ ‰ํ† ๋ฆฌ์— index.js ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , ๊ณตํ†ต๋˜๊ฒŒ export ์‹œํ‚ค๋ฉด, import ๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค! *view/index.js* ```javascript export {default as InputView.js} from './InputView.js' export {default as OutputView.js} from './OutputView.js' ``` *EventController.js* ```javascript import { InputView, OutputView } '../view/index.js' ```
@@ -0,0 +1,111 @@ +import { MENU, MESSAGE, ARRAY, CALENDAR, BENEFIT_AMOUNT, BADGE, BOUNDARY } from "../commons/constants.js"; +import Order from "./Order.js"; +import { getMenu, getMenuCount } from "../commons/utils.js"; + +class Benefit { + #date; + #menu; + #order; + #benefitResult; + + constructor(date, menu) { + this.#date = date; + this.#menu = menu; + this.#order = new Order(date, menu); + } + + // ํ˜œํƒ ๋‚ด์—ญ + benefitDetail() { + // benefitResult [ DDay | Weekday | Weekend | Special | Giveaway ] + this.#benefitResult = [0, 0, 0, 0, 0]; + + if (this.#isBenefit()) { + if (this.#isDDay()) this.#benefitResult[ARRAY.DDAY] = this.#applyDDay(); + if (this.#isWeekday()) this.#benefitResult[ARRAY.WEEKDAY] = this.#applyWeekday(); + if (this.#isWeekend()) this.#benefitResult[ARRAY.WEEKEND] = this.#applyWeekend(); + if (this.#isSpecial()) this.#benefitResult[ARRAY.SPECIALDAY] = this.#applySpecial(); + if (this.#isGiveaway()) this.#benefitResult[ARRAY.GIVEAWAY] = this.#applyGiveaway(); + } + + return this.#benefitResult; + } + + // ์ด ํ˜œํƒ ๊ธˆ์•ก + totalBenefit() { + let totalBenefit = 0; + this.#benefitResult.forEach((benefit) => { + totalBenefit += benefit; + }); + + return totalBenefit; + } + + // ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก + expectedAmount() { + const totalDiscount = this.totalBenefit() - this.#benefitResult[ARRAY.GIVEAWAY]; + + return this.#order.getAllAmount() - totalDiscount; + } + + // 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€ + eventBadge() { + const totalBenefit = this.totalBenefit(); + + if (!this.#isBenefit()) return MESSAGE.NOTHING; + if (totalBenefit <= BOUNDARY.STAR_PRICE) return BADGE.STAR; + if (totalBenefit <= BOUNDARY.TREE_PRICE) return BADGE.TREE; + + return BADGE.SANTA; + } + + #isBenefit() { + return this.#order.getAllAmount() > BOUNDARY.BENEFIT_PRICE; + } + + #isDDay() { + return this.#date <= BOUNDARY.DDAY_END; + } + + #isWeekday() { + return CALENDAR.WEEKDAY.includes(this.#date); + } + + #isWeekend() { + return CALENDAR.WEEKEND.includes(this.#date); + } + + #isSpecial() { + return CALENDAR.SPECIAL.includes(this.#date); + } + + #isGiveaway() { + return this.#order.getAllAmount() >= BOUNDARY.GIVEAWAY_PRICE; + } + + #applyDDay() { + let discount = BENEFIT_AMOUNT.DDAY_START; + for (let day = 1; day < this.#date; day++) { + discount += BENEFIT_AMOUNT.DDAY_PLUS; + } + return discount; + } + + #applyWeekday() { + const menuCount = getMenuCount(getMenu(MENU.DESSERT), this.#menu); + return menuCount * BENEFIT_AMOUNT.WEEKDAY; + } + + #applyWeekend() { + const menuCount = getMenuCount(getMenu(MENU.MAIN), this.#menu); + return menuCount * BENEFIT_AMOUNT.WEEKEND; + } + + #applySpecial() { + return BENEFIT_AMOUNT.SPECIALDAY; + } + + #applyGiveaway() { + return BENEFIT_AMOUNT.GIVEAWAY; + } +} +export default Benefit;
JavaScript
```javascript this.#benefitResult = Array.from({length:5(ํ˜œํƒ์˜ ๊ธธ์ด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ƒ์ˆ˜๋กœ ์ˆ˜์ •)}, () => 0) ``` ์™€ ๊ฐ™์ด ๋ฐ”๊พธ๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,111 @@ +import { MENU, MESSAGE, ARRAY, CALENDAR, BENEFIT_AMOUNT, BADGE, BOUNDARY } from "../commons/constants.js"; +import Order from "./Order.js"; +import { getMenu, getMenuCount } from "../commons/utils.js"; + +class Benefit { + #date; + #menu; + #order; + #benefitResult; + + constructor(date, menu) { + this.#date = date; + this.#menu = menu; + this.#order = new Order(date, menu); + } + + // ํ˜œํƒ ๋‚ด์—ญ + benefitDetail() { + // benefitResult [ DDay | Weekday | Weekend | Special | Giveaway ] + this.#benefitResult = [0, 0, 0, 0, 0]; + + if (this.#isBenefit()) { + if (this.#isDDay()) this.#benefitResult[ARRAY.DDAY] = this.#applyDDay(); + if (this.#isWeekday()) this.#benefitResult[ARRAY.WEEKDAY] = this.#applyWeekday(); + if (this.#isWeekend()) this.#benefitResult[ARRAY.WEEKEND] = this.#applyWeekend(); + if (this.#isSpecial()) this.#benefitResult[ARRAY.SPECIALDAY] = this.#applySpecial(); + if (this.#isGiveaway()) this.#benefitResult[ARRAY.GIVEAWAY] = this.#applyGiveaway(); + } + + return this.#benefitResult; + } + + // ์ด ํ˜œํƒ ๊ธˆ์•ก + totalBenefit() { + let totalBenefit = 0; + this.#benefitResult.forEach((benefit) => { + totalBenefit += benefit; + }); + + return totalBenefit; + } + + // ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก + expectedAmount() { + const totalDiscount = this.totalBenefit() - this.#benefitResult[ARRAY.GIVEAWAY]; + + return this.#order.getAllAmount() - totalDiscount; + } + + // 12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€ + eventBadge() { + const totalBenefit = this.totalBenefit(); + + if (!this.#isBenefit()) return MESSAGE.NOTHING; + if (totalBenefit <= BOUNDARY.STAR_PRICE) return BADGE.STAR; + if (totalBenefit <= BOUNDARY.TREE_PRICE) return BADGE.TREE; + + return BADGE.SANTA; + } + + #isBenefit() { + return this.#order.getAllAmount() > BOUNDARY.BENEFIT_PRICE; + } + + #isDDay() { + return this.#date <= BOUNDARY.DDAY_END; + } + + #isWeekday() { + return CALENDAR.WEEKDAY.includes(this.#date); + } + + #isWeekend() { + return CALENDAR.WEEKEND.includes(this.#date); + } + + #isSpecial() { + return CALENDAR.SPECIAL.includes(this.#date); + } + + #isGiveaway() { + return this.#order.getAllAmount() >= BOUNDARY.GIVEAWAY_PRICE; + } + + #applyDDay() { + let discount = BENEFIT_AMOUNT.DDAY_START; + for (let day = 1; day < this.#date; day++) { + discount += BENEFIT_AMOUNT.DDAY_PLUS; + } + return discount; + } + + #applyWeekday() { + const menuCount = getMenuCount(getMenu(MENU.DESSERT), this.#menu); + return menuCount * BENEFIT_AMOUNT.WEEKDAY; + } + + #applyWeekend() { + const menuCount = getMenuCount(getMenu(MENU.MAIN), this.#menu); + return menuCount * BENEFIT_AMOUNT.WEEKEND; + } + + #applySpecial() { + return BENEFIT_AMOUNT.SPECIALDAY; + } + + #applyGiveaway() { + return BENEFIT_AMOUNT.GIVEAWAY; + } +} +export default Benefit;
JavaScript
ํด๋ž˜์Šค ๋ถ„๋ฆฌ์— ๋„ˆ๋ฌด ์ง‘์ค‘ํ•˜๋А๋ผ ํ˜œํƒ์„ ํ™•์ธํ•˜๋Š” ํด๋ž˜์Šค์™€ ํ˜œํƒ์„ ์ ์šฉํ•˜๋Š” ํด๋ž˜์Šค๋กœ ๋ถ„๋ฆฌํ•ด์„œ ์ž‘์„ฑํ–ˆ์—ˆ๋Š”๋ฐ, ํ•˜๋‚˜์˜ ํด๋ž˜์Šค์— ๋ฌถ์–ด์„œ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ๋„ ๊ดœ์ฐฎ์•„ ๋ณด์ด๋„ค์š”๐Ÿ˜‚
@@ -0,0 +1,63 @@ +import InputView from "../view/InputView.js"; +import OutputView from "../view/OutputView.js"; +import Order from "../model/Order.js"; +import Benefit from "../model/Benefit.js"; +import { print } from "../commons/utils.js"; +import { MENU } from "../commons/constants.js"; + +class EventController { + #date; + #menu; + + async eventStart() { + OutputView.printStart(); + + // ์ฃผ๋ฌธ ์ •๋ณด ์ž…๋ ฅ & ์ฃผ๋ฌธ ์ •๋ณด ์ถœ๋ ฅ + await this.#getOrderInformation(); + OutputView.printOrderInformation(this.#date, this.#menu); + + // ์ฃผ๋ฌธ ํด๋ž˜์Šค ์ƒ์„ฑ & ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก ์ถœ๋ ฅ + const order = new Order(this.#date, this.#menu); + OutputView.printAllAmount(order.getAllAmount()); + + // ํ˜œํƒ ํด๋ž˜์Šค ์ƒ์„ฑ & ํ˜œํƒ๊ณผ ๊ด€๋ จ๋œ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + const benefit = new Benefit(this.#date, this.#menu); + this.#printBenefit(benefit); + } + + async #getOrderInformation() { + await this.#getDate(); + await this.#getMenu(); + } + + async #getDate() { + while (true) { + try { + this.#date = await InputView.inputDate(); + break; + } catch (error) { + print(error); + } + } + } + + async #getMenu() { + while (true) { + try { + this.#menu = await InputView.inputMenu(); + break; + } catch (error) { + print(error); + } + } + } + + #printBenefit(benefit) { + OutputView.printGiveaway(benefit.benefitDetail()); // <์ฆ์ • ๋ฉ”๋‰ด> + OutputView.printBenefitDetail(benefit.benefitDetail()); // <ํ˜œํƒ ๋‚ด์—ญ> + OutputView.printTotalBenefit(benefit.totalBenefit()); // <์ด ํ˜œํ… ๊ธˆ์•ก> + OutputView.printExpectedAmount(benefit.expectedAmount()); // <ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก> + OutputView.printEventBadge(benefit.eventBadge()); // <12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€> + } +} +export default EventController;
JavaScript
Controller์˜ ํ•„๋“œ๋Š” model์˜ ํ•„๋“œ๋ฅผ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค! ํ•„๋“œ๋ฅผ ์ค„์—ฌ๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,63 @@ +import InputView from "../view/InputView.js"; +import OutputView from "../view/OutputView.js"; +import Order from "../model/Order.js"; +import Benefit from "../model/Benefit.js"; +import { print } from "../commons/utils.js"; +import { MENU } from "../commons/constants.js"; + +class EventController { + #date; + #menu; + + async eventStart() { + OutputView.printStart(); + + // ์ฃผ๋ฌธ ์ •๋ณด ์ž…๋ ฅ & ์ฃผ๋ฌธ ์ •๋ณด ์ถœ๋ ฅ + await this.#getOrderInformation(); + OutputView.printOrderInformation(this.#date, this.#menu); + + // ์ฃผ๋ฌธ ํด๋ž˜์Šค ์ƒ์„ฑ & ์ด ์ฃผ๋ฌธ ๊ธˆ์•ก ์ถœ๋ ฅ + const order = new Order(this.#date, this.#menu); + OutputView.printAllAmount(order.getAllAmount()); + + // ํ˜œํƒ ํด๋ž˜์Šค ์ƒ์„ฑ & ํ˜œํƒ๊ณผ ๊ด€๋ จ๋œ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + const benefit = new Benefit(this.#date, this.#menu); + this.#printBenefit(benefit); + } + + async #getOrderInformation() { + await this.#getDate(); + await this.#getMenu(); + } + + async #getDate() { + while (true) { + try { + this.#date = await InputView.inputDate(); + break; + } catch (error) { + print(error); + } + } + } + + async #getMenu() { + while (true) { + try { + this.#menu = await InputView.inputMenu(); + break; + } catch (error) { + print(error); + } + } + } + + #printBenefit(benefit) { + OutputView.printGiveaway(benefit.benefitDetail()); // <์ฆ์ • ๋ฉ”๋‰ด> + OutputView.printBenefitDetail(benefit.benefitDetail()); // <ํ˜œํƒ ๋‚ด์—ญ> + OutputView.printTotalBenefit(benefit.totalBenefit()); // <์ด ํ˜œํ… ๊ธˆ์•ก> + OutputView.printExpectedAmount(benefit.expectedAmount()); // <ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก> + OutputView.printEventBadge(benefit.eventBadge()); // <12์›” ์ด๋ฒคํŠธ ๋ฐฐ์ง€> + } +} +export default EventController;
JavaScript
ERROR์˜ ์ถœ๋ ฅ๋„ util ์ด ์•„๋‹Œ OutputView ์—์„œ ํ•ด์ฃผ๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?