code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,79 @@
+import React, { useState } from "react";
+import { useNavigate } from 'react-router-dom';
+import "../../../style/reset.scss";
+import "../../../style/common.scss";
+import "../../../style/variables.scss"
+import "./Login.scss";
+
+
+const Login = () => {
+
+ const [userInfo, setUserInfo] = useState({
+ userId:"์์ด๋",
+ userPw:"ํจ์ค์๋",
+ });
+ const navigate = useNavigate();
+ const goToMain = () => {
+ fetch("http://10.58.52.144:3000/users/signup", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ email: userInfo.userId,
+ password: userInfo.userPw,
+ }),
+ })
+ .then((response) => response.json())
+ .then((result) => {
+ if(result.accessToken) {
+ localStorage.setItem("token", result.accessToken);
+ navigate("/jinheekim-main");
+ }
+ if(result.message === "invalid password") {
+ alert ("๋น๋ฐ๋ฒํธ ํ๋ ธ์");
+ };
+ if(result.message === "specified user does not exist") {
+ alert ("์์ด๋ ํ๋ ธ์");
+ }
+ })
+
+ }
+
+ const handleInput = (event) => {
+ const {value, id} = event.target;
+ setUserInfo({...userInfo, [id]:value});
+ };
+
+ const isValue = userInfo.userId.includes('@') && userInfo.userPw.length >= 5;
+
+ return (
+ <div className="login">
+ <div className="box">
+ <h1>Westagram</h1>
+ <div className="inputTxt">
+ <input
+ id="userId"
+ onChange={handleInput}
+ type="text"
+ className="id"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ />
+ <input
+ id="userPw"
+ onChange={handleInput}
+ type="password"
+ className="pw"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ />
+ <button type="button" onClick={goToMain} className={isValue ? "abled-button" : 'disabled-button'} disabled={!isValue}>๋ก๊ทธ์ธ</button>
+ <div className="findPw">
+ <a href="#">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default Login;
\ No newline at end of file | JavaScript | ๐ ์ข์ต๋๋ค! ๊ณ์ํด์ ์ด๋ ๊ฒ ์ธ์
๋ด์ฉ ๋ฐ๋ก๋ฐ๋ก ์ ์ฉํด์ฃผ๋ฉด์ ๋ณธ์ธ์ ์ง์์ผ๋ก ๊ฐ์ ธ๊ฐ์ฃผ์๋ฉด ์ข๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,79 @@
+import React, { useState } from "react";
+import { useNavigate } from 'react-router-dom';
+import "../../../style/reset.scss";
+import "../../../style/common.scss";
+import "../../../style/variables.scss"
+import "./Login.scss";
+
+
+const Login = () => {
+
+ const [userInfo, setUserInfo] = useState({
+ userId:"์์ด๋",
+ userPw:"ํจ์ค์๋",
+ });
+ const navigate = useNavigate();
+ const goToMain = () => {
+ fetch("http://10.58.52.144:3000/users/signup", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ email: userInfo.userId,
+ password: userInfo.userPw,
+ }),
+ })
+ .then((response) => response.json())
+ .then((result) => {
+ if(result.accessToken) {
+ localStorage.setItem("token", result.accessToken);
+ navigate("/jinheekim-main");
+ }
+ if(result.message === "invalid password") {
+ alert ("๋น๋ฐ๋ฒํธ ํ๋ ธ์");
+ };
+ if(result.message === "specified user does not exist") {
+ alert ("์์ด๋ ํ๋ ธ์");
+ }
+ })
+
+ }
+
+ const handleInput = (event) => {
+ const {value, id} = event.target;
+ setUserInfo({...userInfo, [id]:value});
+ };
+
+ const isValue = userInfo.userId.includes('@') && userInfo.userPw.length >= 5;
+
+ return (
+ <div className="login">
+ <div className="box">
+ <h1>Westagram</h1>
+ <div className="inputTxt">
+ <input
+ id="userId"
+ onChange={handleInput}
+ type="text"
+ className="id"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ />
+ <input
+ id="userPw"
+ onChange={handleInput}
+ type="password"
+ className="pw"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ />
+ <button type="button" onClick={goToMain} className={isValue ? "abled-button" : 'disabled-button'} disabled={!isValue}>๋ก๊ทธ์ธ</button>
+ <div className="findPw">
+ <a href="#">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default Login;
\ No newline at end of file | JavaScript | ์ฝ๋์ ์ฃผ์์ด ๋ง์ต๋๋ค!
์ถํ์ ๋ค์ ํ์ตํ ์ฉ๋๋ก ๋จ๊ฒจ๋์ ์ฃผ์์ด๋ผ๋ฉด, ํด๋น๋ด์ฉ์ ๋ฐ๋ก ๋ธ๋ก๊ทธ๋ ๊ฐ์ธ ๋ฉ๋ชจ์ ์์ฑ์ ํด ์ฃผ์๊ณ , ์ฝ๋๋ฅผ github์ ํตํด ์ฌ๋ ค์ฃผ์ค๋๋ ๋ถํ์ํ ์ฝ๋๋ฅผ ์ต๋ํ ์ค์ฌ์ฃผ์ธ์! |
@@ -0,0 +1,79 @@
+import React, { useState } from "react";
+import { useNavigate } from 'react-router-dom';
+import "../../../style/reset.scss";
+import "../../../style/common.scss";
+import "../../../style/variables.scss"
+import "./Login.scss";
+
+
+const Login = () => {
+
+ const [userInfo, setUserInfo] = useState({
+ userId:"์์ด๋",
+ userPw:"ํจ์ค์๋",
+ });
+ const navigate = useNavigate();
+ const goToMain = () => {
+ fetch("http://10.58.52.144:3000/users/signup", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ email: userInfo.userId,
+ password: userInfo.userPw,
+ }),
+ })
+ .then((response) => response.json())
+ .then((result) => {
+ if(result.accessToken) {
+ localStorage.setItem("token", result.accessToken);
+ navigate("/jinheekim-main");
+ }
+ if(result.message === "invalid password") {
+ alert ("๋น๋ฐ๋ฒํธ ํ๋ ธ์");
+ };
+ if(result.message === "specified user does not exist") {
+ alert ("์์ด๋ ํ๋ ธ์");
+ }
+ })
+
+ }
+
+ const handleInput = (event) => {
+ const {value, id} = event.target;
+ setUserInfo({...userInfo, [id]:value});
+ };
+
+ const isValue = userInfo.userId.includes('@') && userInfo.userPw.length >= 5;
+
+ return (
+ <div className="login">
+ <div className="box">
+ <h1>Westagram</h1>
+ <div className="inputTxt">
+ <input
+ id="userId"
+ onChange={handleInput}
+ type="text"
+ className="id"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ />
+ <input
+ id="userPw"
+ onChange={handleInput}
+ type="password"
+ className="pw"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ />
+ <button type="button" onClick={goToMain} className={isValue ? "abled-button" : 'disabled-button'} disabled={!isValue}>๋ก๊ทธ์ธ</button>
+ <div className="findPw">
+ <a href="#">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default Login;
\ No newline at end of file | JavaScript | ```suggestion
<div className="inputTxt">
```
์ ์ฝ๋ ์ฒ๋ผ js์ ๊ธฐ๋ณธ ์ปจ๋ฒค์
์ `camelCase`์
๋๋ค! className์ ์์ฑํ ๋์๋ ์ ๊ฒฝ์จ์ฃผ์
์ผํฉ๋๋ค! |
@@ -0,0 +1,79 @@
+import React, { useState } from "react";
+import { useNavigate } from 'react-router-dom';
+import "../../../style/reset.scss";
+import "../../../style/common.scss";
+import "../../../style/variables.scss"
+import "./Login.scss";
+
+
+const Login = () => {
+
+ const [userInfo, setUserInfo] = useState({
+ userId:"์์ด๋",
+ userPw:"ํจ์ค์๋",
+ });
+ const navigate = useNavigate();
+ const goToMain = () => {
+ fetch("http://10.58.52.144:3000/users/signup", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ email: userInfo.userId,
+ password: userInfo.userPw,
+ }),
+ })
+ .then((response) => response.json())
+ .then((result) => {
+ if(result.accessToken) {
+ localStorage.setItem("token", result.accessToken);
+ navigate("/jinheekim-main");
+ }
+ if(result.message === "invalid password") {
+ alert ("๋น๋ฐ๋ฒํธ ํ๋ ธ์");
+ };
+ if(result.message === "specified user does not exist") {
+ alert ("์์ด๋ ํ๋ ธ์");
+ }
+ })
+
+ }
+
+ const handleInput = (event) => {
+ const {value, id} = event.target;
+ setUserInfo({...userInfo, [id]:value});
+ };
+
+ const isValue = userInfo.userId.includes('@') && userInfo.userPw.length >= 5;
+
+ return (
+ <div className="login">
+ <div className="box">
+ <h1>Westagram</h1>
+ <div className="inputTxt">
+ <input
+ id="userId"
+ onChange={handleInput}
+ type="text"
+ className="id"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ />
+ <input
+ id="userPw"
+ onChange={handleInput}
+ type="password"
+ className="pw"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ />
+ <button type="button" onClick={goToMain} className={isValue ? "abled-button" : 'disabled-button'} disabled={!isValue}>๋ก๊ทธ์ธ</button>
+ <div className="findPw">
+ <a href="#">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default Login;
\ No newline at end of file | JavaScript | ํด๋น scssํ์ผ๋ค์ Index.js์์ import ํด์์ ์ ์ญ์ผ๋ก ์ ์ฉ์ํค๋๊ฒ ์ข์ต๋๋ค. |
@@ -0,0 +1,87 @@
+@import '../../../style/variables.scss';
+@import '../../../style/reset.scss';
+
+
+body {
+ font-size: 14px;
+}
+input {
+ outline: none;
+}
+
+.login {
+ width: 100%;
+ height: 100vh;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ flex-direction: column;
+ .box {
+ width: 400px;
+ padding: 40px 0 20px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ flex-direction: column;
+ border: 1px solid rgb(219, 219, 219);
+
+ h1 {
+ font-size:40px;
+ font-family: 'Lobster';
+ }
+
+ .inputTxt {
+ width: 300px;
+
+ input {
+ display: block;
+ width: 100%;
+ margin: 5px 0;
+ padding: 10px 0 10px 5px;
+ background-color: $grey-color-bg;
+ border-radius: 3px;
+ border: 1px solid $grey-color-border;
+
+ &::placeholder{
+ font-size: 12px;
+ }
+ }
+ }
+ }
+}
+
+@mixin button-style {
+ margin-top: 20px;
+ display: inline-block;
+ width: 100%;
+ text-align: center;
+ text-decoration-line: none;
+ padding: 8px 0;
+ border-radius: 8px;
+ border: 0px;
+ font-weight: bold;
+ color: #fff;
+ cursor: pointer;
+ }
+
+.abled-button {
+ @include button-style;
+ background-color: $point-color-blue;
+}
+
+.disabled-button {
+ @include button-style;
+ background-color: #666;
+}
+
+
+.findPw {
+ text-align: center;
+ margin: 60px 0;
+
+ a {
+ font-size: 9px;
+ color: rgb(0, 55, 107);
+ text-decoration: none;
+ }
+}
\ No newline at end of file | Unknown | ๋ง์ฐฌ๊ฐ์ง ์
๋๋ค! font๊ฐ์ ์์ฑ๋ค๋ common.scss์ ์์ฑํด์ ์ ์ญ์ผ๋ก ๊ด๋ฆฌํ ์ ์๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,87 @@
+@import '../../../style/variables.scss';
+@import '../../../style/reset.scss';
+
+
+body {
+ font-size: 14px;
+}
+input {
+ outline: none;
+}
+
+.login {
+ width: 100%;
+ height: 100vh;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ flex-direction: column;
+ .box {
+ width: 400px;
+ padding: 40px 0 20px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ flex-direction: column;
+ border: 1px solid rgb(219, 219, 219);
+
+ h1 {
+ font-size:40px;
+ font-family: 'Lobster';
+ }
+
+ .inputTxt {
+ width: 300px;
+
+ input {
+ display: block;
+ width: 100%;
+ margin: 5px 0;
+ padding: 10px 0 10px 5px;
+ background-color: $grey-color-bg;
+ border-radius: 3px;
+ border: 1px solid $grey-color-border;
+
+ &::placeholder{
+ font-size: 12px;
+ }
+ }
+ }
+ }
+}
+
+@mixin button-style {
+ margin-top: 20px;
+ display: inline-block;
+ width: 100%;
+ text-align: center;
+ text-decoration-line: none;
+ padding: 8px 0;
+ border-radius: 8px;
+ border: 0px;
+ font-weight: bold;
+ color: #fff;
+ cursor: pointer;
+ }
+
+.abled-button {
+ @include button-style;
+ background-color: $point-color-blue;
+}
+
+.disabled-button {
+ @include button-style;
+ background-color: #666;
+}
+
+
+.findPw {
+ text-align: center;
+ margin: 60px 0;
+
+ a {
+ font-size: 9px;
+ color: rgb(0, 55, 107);
+ text-decoration: none;
+ }
+}
\ No newline at end of file | Unknown | variables.scssํ์ผ์ ์์ผ๋ฉด ๋ ๋ณ์๋ค์ด๋ค์! |
@@ -0,0 +1,163 @@
+import React, { useState, useEffect } from "react";
+import MainFeeds from "./MainFeeds";
+import "./Main.scss";
+import compass from "../assets/icon/compass.png";
+import heart from "../assets/icon/heart.png";
+import instagram from "../assets/icon/instagram.png";
+import search from "../assets/icon/search.png";
+import user from "../assets/icon/user.png";
+import userimg from "../assets/images/test.jpg";
+import feedimg from "../assets/images/test.jpg";
+
+const INFO_LIST = [
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+];
+
+const Main = () => {
+ return (
+ <>
+ <nav className="nav">
+ <div className="navLeft">
+ <img className="navIcon iconInstagram" alt="." src={instagram} />
+ <span className="logo">Westagram</span>
+ </div>
+ <div className="searchBar">
+ <img className="iconSearch" alt="." src={search} />
+ <input
+ className="searchBox"
+ type="text"
+ aria-label="๊ฒ์์ฐฝ"
+ placeholder="๊ฒ์"
+ />
+ </div>
+ <div className="navRight">
+ <img className="navIcon" alt="." src={compass} />
+ <img className="navIcon" alt="." src={heart} />
+ <img className="navIcon" alt="." src={user} />
+ </div>
+ </nav>
+ <div className="main">
+ <MainFeeds />
+ <div className="mainRight">
+ <div className="mainRightTop">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="stories">
+ <div className="storiesTop">
+ <p className="story">์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ </div>
+ <div className="recommend">
+ <div className="storiesTop">
+ <p className="story">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ <div>
+ <ul>
+ {INFO_LIST.map((info) => {
+ return (
+ <li key={info.id}>
+ <a href="{info.link}">{info.text}</a>
+ </li>
+ );
+ })}
+ </ul>
+ <p className="copyright">โ 2023 WESTAGRAM</p>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};
+
+export default Main; | JavaScript | index.js์์ ์ ์ญ์ผ๋ก importํ๋ค๋ฉด ์ด๋ ๊ฒ ํ์ผ๋ง๋ค ๋งค๋ฒ import ํ์ง์์๋ ๋ฉ๋๋ค! |
@@ -0,0 +1,163 @@
+import React, { useState, useEffect } from "react";
+import MainFeeds from "./MainFeeds";
+import "./Main.scss";
+import compass from "../assets/icon/compass.png";
+import heart from "../assets/icon/heart.png";
+import instagram from "../assets/icon/instagram.png";
+import search from "../assets/icon/search.png";
+import user from "../assets/icon/user.png";
+import userimg from "../assets/images/test.jpg";
+import feedimg from "../assets/images/test.jpg";
+
+const INFO_LIST = [
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+];
+
+const Main = () => {
+ return (
+ <>
+ <nav className="nav">
+ <div className="navLeft">
+ <img className="navIcon iconInstagram" alt="." src={instagram} />
+ <span className="logo">Westagram</span>
+ </div>
+ <div className="searchBar">
+ <img className="iconSearch" alt="." src={search} />
+ <input
+ className="searchBox"
+ type="text"
+ aria-label="๊ฒ์์ฐฝ"
+ placeholder="๊ฒ์"
+ />
+ </div>
+ <div className="navRight">
+ <img className="navIcon" alt="." src={compass} />
+ <img className="navIcon" alt="." src={heart} />
+ <img className="navIcon" alt="." src={user} />
+ </div>
+ </nav>
+ <div className="main">
+ <MainFeeds />
+ <div className="mainRight">
+ <div className="mainRightTop">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="stories">
+ <div className="storiesTop">
+ <p className="story">์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ </div>
+ <div className="recommend">
+ <div className="storiesTop">
+ <p className="story">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ <div>
+ <ul>
+ {INFO_LIST.map((info) => {
+ return (
+ <li key={info.id}>
+ <a href="{info.link}">{info.text}</a>
+ </li>
+ );
+ })}
+ </ul>
+ <p className="copyright">โ 2023 WESTAGRAM</p>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};
+
+export default Main; | JavaScript | `comment`๋ผ๋ ๋ณ์๋ช
์ด ์์ฑ๋์ด์๋ comment๋ค์ ๋ชจ์์ธ์ง, ๋ด๊ฐ input์ ์
๋ ฅํ ๊ฐ์ ๊ด๋ฆฌํ๋ ๋ณ์์ธ์ง ์ด๋ฆ๋ง ๋ดค์ ๋ ๋ฐ๋ก ์ถ์ธกํ๊ธฐ ์ด๋ ต์ต๋๋ค.
์๋์ commentArray๋ผ๋ ๋ณ์๋ ๋ง์ฐฌ๊ฐ์ง๋ก ์กฐ๊ธ ๋ ๋ณ์๊ฐ ์ด๋ค state๋ฅผ ๊ฐ์ง๊ณ ์๋์ง ๋ช
ํํ ์ด๋ฆ์ผ๋ก ์์ฑํด์ฃผ์๋ฉด ์ข๊ฒ ์ต๋๋ค |
@@ -0,0 +1,163 @@
+import React, { useState, useEffect } from "react";
+import MainFeeds from "./MainFeeds";
+import "./Main.scss";
+import compass from "../assets/icon/compass.png";
+import heart from "../assets/icon/heart.png";
+import instagram from "../assets/icon/instagram.png";
+import search from "../assets/icon/search.png";
+import user from "../assets/icon/user.png";
+import userimg from "../assets/images/test.jpg";
+import feedimg from "../assets/images/test.jpg";
+
+const INFO_LIST = [
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+];
+
+const Main = () => {
+ return (
+ <>
+ <nav className="nav">
+ <div className="navLeft">
+ <img className="navIcon iconInstagram" alt="." src={instagram} />
+ <span className="logo">Westagram</span>
+ </div>
+ <div className="searchBar">
+ <img className="iconSearch" alt="." src={search} />
+ <input
+ className="searchBox"
+ type="text"
+ aria-label="๊ฒ์์ฐฝ"
+ placeholder="๊ฒ์"
+ />
+ </div>
+ <div className="navRight">
+ <img className="navIcon" alt="." src={compass} />
+ <img className="navIcon" alt="." src={heart} />
+ <img className="navIcon" alt="." src={user} />
+ </div>
+ </nav>
+ <div className="main">
+ <MainFeeds />
+ <div className="mainRight">
+ <div className="mainRightTop">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="stories">
+ <div className="storiesTop">
+ <p className="story">์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ </div>
+ <div className="recommend">
+ <div className="storiesTop">
+ <p className="story">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ <div>
+ <ul>
+ {INFO_LIST.map((info) => {
+ return (
+ <li key={info.id}>
+ <a href="{info.link}">{info.text}</a>
+ </li>
+ );
+ })}
+ </ul>
+ <p className="copyright">โ 2023 WESTAGRAM</p>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};
+
+export default Main; | JavaScript | ```suggestion
setCommentArray(commentList => [ ...commentList,comment]);
```
์ด ๋๊ฐ์ ์ฐจ์ด์ ์ ํ์คํ ์๊ณ ๋์ด๊ฐ์ฃผ์
จ์ผ๋ฉด ์ข๊ฒ ์ต๋๋ค!! |
@@ -0,0 +1,163 @@
+import React, { useState, useEffect } from "react";
+import MainFeeds from "./MainFeeds";
+import "./Main.scss";
+import compass from "../assets/icon/compass.png";
+import heart from "../assets/icon/heart.png";
+import instagram from "../assets/icon/instagram.png";
+import search from "../assets/icon/search.png";
+import user from "../assets/icon/user.png";
+import userimg from "../assets/images/test.jpg";
+import feedimg from "../assets/images/test.jpg";
+
+const INFO_LIST = [
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+];
+
+const Main = () => {
+ return (
+ <>
+ <nav className="nav">
+ <div className="navLeft">
+ <img className="navIcon iconInstagram" alt="." src={instagram} />
+ <span className="logo">Westagram</span>
+ </div>
+ <div className="searchBar">
+ <img className="iconSearch" alt="." src={search} />
+ <input
+ className="searchBox"
+ type="text"
+ aria-label="๊ฒ์์ฐฝ"
+ placeholder="๊ฒ์"
+ />
+ </div>
+ <div className="navRight">
+ <img className="navIcon" alt="." src={compass} />
+ <img className="navIcon" alt="." src={heart} />
+ <img className="navIcon" alt="." src={user} />
+ </div>
+ </nav>
+ <div className="main">
+ <MainFeeds />
+ <div className="mainRight">
+ <div className="mainRightTop">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="stories">
+ <div className="storiesTop">
+ <p className="story">์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ </div>
+ <div className="recommend">
+ <div className="storiesTop">
+ <p className="story">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ <div>
+ <ul>
+ {INFO_LIST.map((info) => {
+ return (
+ <li key={info.id}>
+ <a href="{info.link}">{info.text}</a>
+ </li>
+ );
+ })}
+ </ul>
+ <p className="copyright">โ 2023 WESTAGRAM</p>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};
+
+export default Main; | JavaScript | Input์ ๊ฐ์ด ๋น์ด์์๋ ํจ์๊ฐ ๊ทธ๋ฅ ์๋ฌด๋ฐ ๋์์ ํ์ง ์๋๋ค๋ฉด ๊ธฐ๋ฅ์ ์๋ฌ์ธ์ง, ์๋๋ ๋์์ธ์ง ํ์
ํ๊ธฐ ์ด๋ ต์ต๋๋ค.
`comment` ๊ฐ์ด ๋น์ด์๋ค๋ฉด ํจ์๊ฐ ํธ์ถ๋ ๋ `alert`๋ฅผ ํ์ํด์ฃผ๋ ๋ฑ์ ์ถ๊ฐ์ ์ธ ์กฐ์น๊ฐ ์์ผ๋ฉด ์ข์ต๋๋ค |
@@ -0,0 +1,163 @@
+import React, { useState, useEffect } from "react";
+import MainFeeds from "./MainFeeds";
+import "./Main.scss";
+import compass from "../assets/icon/compass.png";
+import heart from "../assets/icon/heart.png";
+import instagram from "../assets/icon/instagram.png";
+import search from "../assets/icon/search.png";
+import user from "../assets/icon/user.png";
+import userimg from "../assets/images/test.jpg";
+import feedimg from "../assets/images/test.jpg";
+
+const INFO_LIST = [
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+];
+
+const Main = () => {
+ return (
+ <>
+ <nav className="nav">
+ <div className="navLeft">
+ <img className="navIcon iconInstagram" alt="." src={instagram} />
+ <span className="logo">Westagram</span>
+ </div>
+ <div className="searchBar">
+ <img className="iconSearch" alt="." src={search} />
+ <input
+ className="searchBox"
+ type="text"
+ aria-label="๊ฒ์์ฐฝ"
+ placeholder="๊ฒ์"
+ />
+ </div>
+ <div className="navRight">
+ <img className="navIcon" alt="." src={compass} />
+ <img className="navIcon" alt="." src={heart} />
+ <img className="navIcon" alt="." src={user} />
+ </div>
+ </nav>
+ <div className="main">
+ <MainFeeds />
+ <div className="mainRight">
+ <div className="mainRightTop">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="stories">
+ <div className="storiesTop">
+ <p className="story">์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ </div>
+ <div className="recommend">
+ <div className="storiesTop">
+ <p className="story">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ <div>
+ <ul>
+ {INFO_LIST.map((info) => {
+ return (
+ <li key={info.id}>
+ <a href="{info.link}">{info.text}</a>
+ </li>
+ );
+ })}
+ </ul>
+ <p className="copyright">โ 2023 WESTAGRAM</p>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};
+
+export default Main; | JavaScript | map ๋ฉ์๋์ ์ฝ๋ฐฑํจ์์ ๋๋ฒ ์งธ ์ธ์, ์ฆ ์งํฌ๋์ ์ฝ๋์์ user๋ผ๊ณ ํ๋ ๋ณ์๋ ๊ธฐ์ค๋ฐฐ์ด(commnetArray)์ value(๋ฐฐ์ด์ ๊ฐ๊ฐ์ ์์)๋ง๋ค์ index(๋ฐฐ์ด๋ด์ ์์)๋ฅผ ๋ํ๋
๋๋ค. ๋ฆฌ์กํธ์์ ๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉํด์ key ์์ฑ์ ๊ผญ ๋ถ์ฌํ๋ผ๊ณ ํ๋ ์ด์ ๋ ํด๋น์์๋ฅผ ๋ฆฌ์กํธ๊ฐ ๋ช
ํ์ด ์ธ์ํ๊ธฐ ์ํจ์ธ๋ฐ, ๋ฐฐ์ด์ index๋ฅผ key๊ฐ์ผ๋ก ๋ถ์ฌํ๋๊ฒ์ ์กฐ๊ธ ์ง์ํ๋ ๋ฐฉ๋ฒ์
๋๋ค. ์ด๋ค ๊ฐ์ผ๋ก key ์์ฑ์ ๋ถ์ฌํด์ผํ ์ง ์กฐ๊ธ ๋ ๊ณ ๋ฏผํด๋ณด์ธ์! |
@@ -0,0 +1,163 @@
+import React, { useState, useEffect } from "react";
+import MainFeeds from "./MainFeeds";
+import "./Main.scss";
+import compass from "../assets/icon/compass.png";
+import heart from "../assets/icon/heart.png";
+import instagram from "../assets/icon/instagram.png";
+import search from "../assets/icon/search.png";
+import user from "../assets/icon/user.png";
+import userimg from "../assets/images/test.jpg";
+import feedimg from "../assets/images/test.jpg";
+
+const INFO_LIST = [
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+ { id: 1, link: "https://instargram.com", text: "์๊ฐ" },
+];
+
+const Main = () => {
+ return (
+ <>
+ <nav className="nav">
+ <div className="navLeft">
+ <img className="navIcon iconInstagram" alt="." src={instagram} />
+ <span className="logo">Westagram</span>
+ </div>
+ <div className="searchBar">
+ <img className="iconSearch" alt="." src={search} />
+ <input
+ className="searchBox"
+ type="text"
+ aria-label="๊ฒ์์ฐฝ"
+ placeholder="๊ฒ์"
+ />
+ </div>
+ <div className="navRight">
+ <img className="navIcon" alt="." src={compass} />
+ <img className="navIcon" alt="." src={heart} />
+ <img className="navIcon" alt="." src={user} />
+ </div>
+ </nav>
+ <div className="main">
+ <MainFeeds />
+ <div className="mainRight">
+ <div className="mainRightTop">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="stories">
+ <div className="storiesTop">
+ <p className="story">์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ </div>
+ </div>
+ <div className="recommend">
+ <div className="storiesTop">
+ <p className="story">ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ <div className="storyPeople">
+ <div className="photo">
+ <img src={userimg} alt="."></img>
+ </div>
+ <div className="name">
+ <p className="username">jini</p>
+ <p className="username2">์ง๋์ง๋</p>
+ </div>
+ <button>ํ๋ก์ฐ</button>
+ </div>
+ </div>
+ <div>
+ <ul>
+ {INFO_LIST.map((info) => {
+ return (
+ <li key={info.id}>
+ <a href="{info.link}">{info.text}</a>
+ </li>
+ );
+ })}
+ </ul>
+ <p className="copyright">โ 2023 WESTAGRAM</p>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};
+
+export default Main; | JavaScript | ๊ตณ์ด ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ง์๋๋ผ๋ `<textarea></textarea>`ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ฉด multiline input์ ํ์ฉํ ์ ์์ต๋๋ค. |
@@ -0,0 +1,264 @@
+@import '../../../style/reset.scss';
+@import '../../../style/variables.scss';
+
+body {
+ font-size: 14px;
+}
+.logo {
+ font-family: "Lobster";
+ src: url(../assets/Lobster-Regular.ttf);
+}
+input {
+ outline: none;
+}
+
+.navIcon {
+ width: 24px;
+ margin-left: 20px;
+}
+
+.navLeft{
+ .iconInstagram {
+ margin-left: 0;
+ }
+}
+.nav {
+ display: flex;
+ width: 860px;
+ margin: 0 auto;
+ justify-content: space-between;
+ align-items: center;
+ padding: 40px 0;
+
+ .logo {
+ font-size: 24px;
+ margin-left: 20px;
+ border-left: 1px solid black;
+ padding-left: 20px;
+ }
+}
+.navLeft, .searchBar, .navRight{
+ display: flex;
+ align-items: center;
+}
+
+.searchBar {
+ width: 300px;
+ background-color: $grey-color-bg;
+ border: 1px solid $grey-color-border;
+ border-radius: 5px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+
+ .searchBox {
+ width: 50px;
+ padding : 8px 0;
+ border: none;
+ background-color: $grey-color-bg;
+ text-align: center;
+ margin-left: 10px;
+ overflow: auto;
+ outline: none;
+ &:focus {
+ outline: none;
+ }
+ }
+
+ .iconSearch {
+ width: 16px;
+ }
+}
+
+.bold {font-weight: bold;}
+.main {
+ width: 100%;
+ height: 100vh;
+ display: flex;
+ justify-content: center;
+ padding: 80px 40px;
+ background-color: $grey-color-bg;
+ border-top: 2px solid black;
+
+ .username {
+ font-weight: bold;
+ }
+
+ .feeds {
+ border: 1px solid $grey-color-border;
+ background-color: white;
+
+ .feedImg img {
+ width: 468px;
+ }
+ }
+ .feedsTop, .mainRightTop {
+ display: flex;
+ align-items: stretch;
+ padding: 15px;
+ }
+
+ .name {
+ display: flex;
+ margin-left: 15px;
+ justify-content: center;
+ flex-direction: column;
+ }
+ .location, .username2 {
+ font-size: 12px;
+ color: gray;
+ }
+
+ .photo img{
+ width: 50px;
+ border-radius: 100%;
+ }
+
+ .stories{
+ .photo {
+ background: radial-gradient(circle at bottom left, #F58529 20%, #C42D91);
+ border-radius: 100%;
+ height: 57px;
+ width: 57px;
+
+ img {
+ box-sizing: content-box;
+ border: 2px solid #fff;
+ margin: 1px;
+ }
+ }
+ }
+
+ .feedsBottom {
+ padding: 10px;
+
+ .photo img {
+ width: 24px;
+ margin-right: 10px;
+ padding: 1px;
+ border:1px solid rgb(188, 188, 188);
+ }
+
+ .like {
+ margin-top:10px;
+ display: inline-flex;
+ }
+
+ .feedsBottomIcons {
+ display: flex;
+ justify-content: space-between;
+
+ .bottomRight > .navIcon {
+ margin-left:0;
+ }
+
+ .bottomLeft .navIcon:first-child {
+ margin-left: 0;
+ }
+ }
+
+ .comment {
+ margin-top: 10px;
+
+ .writeTime {
+ color: grey;
+ margin-top: 10px;
+ }
+ .commentContainer{
+ position: relative;
+ }
+ .commentButton {
+ position: absolute;
+ right: 0;
+ top: 20px;
+ border: none;
+ background-color: inherit;
+ color: grey;
+ }
+ }
+
+ .description {
+ margin-top: 20px;
+ }
+
+ .commentBox {
+ width: 100%;
+ resize: none;
+ margin-top: 20px;
+ border-style: none;
+ border-bottom: 1px solid grey;
+
+ &:focus {
+ outline: none;
+ }
+ }
+ }
+
+ .mainRight {
+ width: 300px;
+ padding: 0 20px;
+
+ .stories, .recommend {
+ border: 1px solid $grey-color-border;
+ background-color: white;
+ padding: 15px;
+ height: 250px;
+ overflow: hidden;
+ }
+
+ .storiesTop {
+ display: flex;
+ justify-content: space-between;
+ font-size: 12px;
+ }
+
+ .recommend {
+ margin-top: 20px;
+ }
+
+ .story {
+ color: grey;
+ }
+
+ .storyPeople {
+ display: flex;
+ position: relative;
+ margin-top: 15px;
+
+ button {
+ position: absolute;
+ right: 0;
+ margin-top: 15px;
+ border: none;
+ background-color: inherit;
+ color: $point-color-blue;
+ font-weight: bold;
+
+ }
+ }
+ }
+
+ ul {
+ padding: 0;
+
+ li {
+ display: inline-block;
+ list-style-type: none;
+ color: $grey-color-193;
+ margin:5px 5px 0;
+ }
+ li:first-child {
+ margin-left: 0;
+ }
+
+ a {
+ text-decoration: none;
+ color: $grey-color-193;
+ }
+ }
+
+ .copyright {
+ color: $grey-color-193;
+ margin-top: 10px;
+ }
+}
\ No newline at end of file | Unknown | ์์ ๋จ๊ฒจ๋๋ฆฐ ๋ด์ฉ์ ๋ฆฌ๋ทฐ์ ๋์ผํฉ๋๋ค |
@@ -0,0 +1,97 @@
+package com.selab.todo.controller;
+
+import com.selab.todo.common.dto.PageDto;
+import com.selab.todo.common.dto.ResponseDto;
+import com.selab.todo.dto.request.diary.DiaryRegisterRequest;
+import com.selab.todo.dto.request.diary.DiaryUpdateRequest;
+import com.selab.todo.dto.request.feel.FeelingUpdateRequest;
+import com.selab.todo.service.DiaryService;
+import com.selab.todo.service.FeelingService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = {"Diary API"})
+@RestController
+@RequestMapping(value = "/api/v1/diaries", produces = MediaType.APPLICATION_JSON_VALUE)
+@RequiredArgsConstructor
+public class DiaryController {
+ private final DiaryService diaryService;
+ private final FeelingService feelingService;
+
+ @ApiOperation(value = "Diary ๋ฑ๋กํ๊ธฐ")
+ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/register")
+ public ResponseEntity<?> register(@RequestBody DiaryRegisterRequest request) {
+ var response = diaryService.register(request);
+ return ResponseDto.created(response);
+ }
+
+ @ApiOperation(value = "Diary ๋จ๊ฑด ์กฐํํ๊ธฐ")
+ @GetMapping("/{id}")
+ public ResponseEntity<?> get(@PathVariable Long id) {
+ var response = diaryService.get(id);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/search-all")
+ public ResponseEntity<?> getAll(
+ @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
+ ) {
+ var response = diaryService.getAll(pageable);
+ return PageDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์์ ํ๊ธฐ")
+ @PutMapping("/{id}") // @PatchMapping
+ public ResponseEntity<?> update(
+ @PathVariable Long id,
+ @RequestBody DiaryUpdateRequest request
+ ) {
+ var response = diaryService.update(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/{id}")
+ public ResponseEntity<Void> delete(
+ @PathVariable Long id
+ ) {
+ diaryService.delete(id);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Diary ์๋ณ ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/month/{month}")
+ public ResponseEntity<Void> monthDelete(@PathVariable int month) {
+ diaryService.monthDelete(month);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Feeling ์์ ํ๊ธฐ")
+ @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/feeling/{id}")
+ public ResponseEntity<?> updateFeeling(@PathVariable Long id, @RequestBody FeelingUpdateRequest request) {
+ var response = feelingService.updateFeeling(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Feeling ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/feeling-all")
+ public ResponseEntity<?> getAllFeeling(@PageableDefault Pageable pageable) {
+ var response = feelingService.getAllFeeling(pageable);
+ return PageDto.ok(response);
+ }
+} | Java | ์ด๋ฐ ๊ฒฝ์ฐ์๋ month๋ฅผ Request Param์ผ๋ก |
@@ -0,0 +1,97 @@
+package com.selab.todo.controller;
+
+import com.selab.todo.common.dto.PageDto;
+import com.selab.todo.common.dto.ResponseDto;
+import com.selab.todo.dto.request.diary.DiaryRegisterRequest;
+import com.selab.todo.dto.request.diary.DiaryUpdateRequest;
+import com.selab.todo.dto.request.feel.FeelingUpdateRequest;
+import com.selab.todo.service.DiaryService;
+import com.selab.todo.service.FeelingService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = {"Diary API"})
+@RestController
+@RequestMapping(value = "/api/v1/diaries", produces = MediaType.APPLICATION_JSON_VALUE)
+@RequiredArgsConstructor
+public class DiaryController {
+ private final DiaryService diaryService;
+ private final FeelingService feelingService;
+
+ @ApiOperation(value = "Diary ๋ฑ๋กํ๊ธฐ")
+ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/register")
+ public ResponseEntity<?> register(@RequestBody DiaryRegisterRequest request) {
+ var response = diaryService.register(request);
+ return ResponseDto.created(response);
+ }
+
+ @ApiOperation(value = "Diary ๋จ๊ฑด ์กฐํํ๊ธฐ")
+ @GetMapping("/{id}")
+ public ResponseEntity<?> get(@PathVariable Long id) {
+ var response = diaryService.get(id);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/search-all")
+ public ResponseEntity<?> getAll(
+ @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
+ ) {
+ var response = diaryService.getAll(pageable);
+ return PageDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์์ ํ๊ธฐ")
+ @PutMapping("/{id}") // @PatchMapping
+ public ResponseEntity<?> update(
+ @PathVariable Long id,
+ @RequestBody DiaryUpdateRequest request
+ ) {
+ var response = diaryService.update(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/{id}")
+ public ResponseEntity<Void> delete(
+ @PathVariable Long id
+ ) {
+ diaryService.delete(id);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Diary ์๋ณ ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/month/{month}")
+ public ResponseEntity<Void> monthDelete(@PathVariable int month) {
+ diaryService.monthDelete(month);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Feeling ์์ ํ๊ธฐ")
+ @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/feeling/{id}")
+ public ResponseEntity<?> updateFeeling(@PathVariable Long id, @RequestBody FeelingUpdateRequest request) {
+ var response = feelingService.updateFeeling(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Feeling ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/feeling-all")
+ public ResponseEntity<?> getAllFeeling(@PageableDefault Pageable pageable) {
+ var response = feelingService.getAllFeeling(pageable);
+ return PageDto.ok(response);
+ }
+} | Java | ์ ์ฌ๋ฌ ์กฐ๊ฑด์ผ๋ก ๊ฒ์ ๊ธฐ๋ฅ์ ๋ง๋์ ๊ฒ ๊ฐ์๋ฐ, API๋ฅผ ๋๋์ง ๋ง๊ณ , ๊ฒ์ ๋ชจ๋์ ๋ง๋๋๊ฒ ์ด๋จ๊น์? |
@@ -0,0 +1,71 @@
+package com.selab.todo.entity;
+
+import com.selab.todo.common.BaseEntity;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import org.springframework.data.annotation.CreatedDate;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.time.DayOfWeek;
+import java.time.LocalDateTime;
+import java.time.Month;
+import java.time.Year;
+
+@Entity(name = "diary")
+@Getter
+@Table(name = "diary")
+@NoArgsConstructor(access = AccessLevel.PROTECTED)
+public class Diary extends BaseEntity {
+ @Id
+ @Column(name = "id")
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @Column(name = "title")
+ private String title;
+
+ @Column(name = "content")
+ private String content;
+
+ @Column(name = "createdAt")
+ @CreatedDate
+ private LocalDateTime createdAt;
+
+ @Column(name = "year")
+ private Year year;
+
+ @Column(name = "month")
+ private Month month;
+
+ @Column(name = "day")
+ private DayOfWeek day;
+
+ @Column(name = "feel")
+ private String feel;
+
+
+ public Diary(String title, String content, String feel, Year year, Month month, DayOfWeek day) {
+ this.title = title;
+ this.content = content;
+ this.feel = feel;
+ this.year = year;
+ this.month = month;
+ this.day = day;
+ }
+
+ public void update(String title, String content, String feel) {
+ this.title = title;
+ this.content = content;
+ this.feel = feel;
+ }
+
+ public void feelingUpdate(String feel){
+ this.feel = feel;
+ }
+}
\ No newline at end of file | Java | enumrated ์ถ๊ฐํด์ผ ๋ ๊ฒ ๊ฐ์๋ฐ์? |
@@ -0,0 +1,97 @@
+package com.selab.todo.controller;
+
+import com.selab.todo.common.dto.PageDto;
+import com.selab.todo.common.dto.ResponseDto;
+import com.selab.todo.dto.request.diary.DiaryRegisterRequest;
+import com.selab.todo.dto.request.diary.DiaryUpdateRequest;
+import com.selab.todo.dto.request.feel.FeelingUpdateRequest;
+import com.selab.todo.service.DiaryService;
+import com.selab.todo.service.FeelingService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = {"Diary API"})
+@RestController
+@RequestMapping(value = "/api/v1/diaries", produces = MediaType.APPLICATION_JSON_VALUE)
+@RequiredArgsConstructor
+public class DiaryController {
+ private final DiaryService diaryService;
+ private final FeelingService feelingService;
+
+ @ApiOperation(value = "Diary ๋ฑ๋กํ๊ธฐ")
+ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/register")
+ public ResponseEntity<?> register(@RequestBody DiaryRegisterRequest request) {
+ var response = diaryService.register(request);
+ return ResponseDto.created(response);
+ }
+
+ @ApiOperation(value = "Diary ๋จ๊ฑด ์กฐํํ๊ธฐ")
+ @GetMapping("/{id}")
+ public ResponseEntity<?> get(@PathVariable Long id) {
+ var response = diaryService.get(id);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/search-all")
+ public ResponseEntity<?> getAll(
+ @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
+ ) {
+ var response = diaryService.getAll(pageable);
+ return PageDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์์ ํ๊ธฐ")
+ @PutMapping("/{id}") // @PatchMapping
+ public ResponseEntity<?> update(
+ @PathVariable Long id,
+ @RequestBody DiaryUpdateRequest request
+ ) {
+ var response = diaryService.update(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/{id}")
+ public ResponseEntity<Void> delete(
+ @PathVariable Long id
+ ) {
+ diaryService.delete(id);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Diary ์๋ณ ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/month/{month}")
+ public ResponseEntity<Void> monthDelete(@PathVariable int month) {
+ diaryService.monthDelete(month);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Feeling ์์ ํ๊ธฐ")
+ @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/feeling/{id}")
+ public ResponseEntity<?> updateFeeling(@PathVariable Long id, @RequestBody FeelingUpdateRequest request) {
+ var response = feelingService.updateFeeling(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Feeling ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/feeling-all")
+ public ResponseEntity<?> getAllFeeling(@PageableDefault Pageable pageable) {
+ var response = feelingService.getAllFeeling(pageable);
+ return PageDto.ok(response);
+ }
+} | Java | url path์ ๋ํด ๋ค์ ํ๋ฒ ๋ ์ ๊ฒ ๋ถํ๋๋ฆ
๋๋ค!
rest url ๊ท์น ํ์ธํ๊ธฐ |
@@ -0,0 +1,71 @@
+package com.selab.todo.entity;
+
+import com.selab.todo.common.BaseEntity;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import org.springframework.data.annotation.CreatedDate;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.time.DayOfWeek;
+import java.time.LocalDateTime;
+import java.time.Month;
+import java.time.Year;
+
+@Entity(name = "diary")
+@Getter
+@Table(name = "diary")
+@NoArgsConstructor(access = AccessLevel.PROTECTED)
+public class Diary extends BaseEntity {
+ @Id
+ @Column(name = "id")
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @Column(name = "title")
+ private String title;
+
+ @Column(name = "content")
+ private String content;
+
+ @Column(name = "createdAt")
+ @CreatedDate
+ private LocalDateTime createdAt;
+
+ @Column(name = "year")
+ private Year year;
+
+ @Column(name = "month")
+ private Month month;
+
+ @Column(name = "day")
+ private DayOfWeek day;
+
+ @Column(name = "feel")
+ private String feel;
+
+
+ public Diary(String title, String content, String feel, Year year, Month month, DayOfWeek day) {
+ this.title = title;
+ this.content = content;
+ this.feel = feel;
+ this.year = year;
+ this.month = month;
+ this.day = day;
+ }
+
+ public void update(String title, String content, String feel) {
+ this.title = title;
+ this.content = content;
+ this.feel = feel;
+ }
+
+ public void feelingUpdate(String feel){
+ this.feel = feel;
+ }
+}
\ No newline at end of file | Java | LocalDateTime ํน์ ZoneDateTime๊ณผ ๊ฐ์ ์๊ฐ์ ๋ค๋ฃจ๋ ๊ฐ์ฒด ์ฌ์ฉ์ ํ์ง ์์ ์ด์ ๊ฐ ๋ฌด์์ผ๊น์? |
@@ -0,0 +1,23 @@
+package com.selab.todo.entity;
+
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+
+@Entity(name = "feeling")
+@Getter
+@Table(name = "feeling")
+@NoArgsConstructor(access = AccessLevel.PROTECTED)
+@AllArgsConstructor
+public class Feeling {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private Long id;
+
+ @Column(name = "feel")
+ private String feel;
+} | Java | ํด๋น ํด๋์ค์ ์ญํ ์ ๋ฌด์์ผ๊น์?
id, baseentity ์ ๋๋ ์ถ๊ฐํด๋ ๋ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,97 @@
+package com.selab.todo.controller;
+
+import com.selab.todo.common.dto.PageDto;
+import com.selab.todo.common.dto.ResponseDto;
+import com.selab.todo.dto.request.diary.DiaryRegisterRequest;
+import com.selab.todo.dto.request.diary.DiaryUpdateRequest;
+import com.selab.todo.dto.request.feel.FeelingUpdateRequest;
+import com.selab.todo.service.DiaryService;
+import com.selab.todo.service.FeelingService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = {"Diary API"})
+@RestController
+@RequestMapping(value = "/api/v1/diaries", produces = MediaType.APPLICATION_JSON_VALUE)
+@RequiredArgsConstructor
+public class DiaryController {
+ private final DiaryService diaryService;
+ private final FeelingService feelingService;
+
+ @ApiOperation(value = "Diary ๋ฑ๋กํ๊ธฐ")
+ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/register")
+ public ResponseEntity<?> register(@RequestBody DiaryRegisterRequest request) {
+ var response = diaryService.register(request);
+ return ResponseDto.created(response);
+ }
+
+ @ApiOperation(value = "Diary ๋จ๊ฑด ์กฐํํ๊ธฐ")
+ @GetMapping("/{id}")
+ public ResponseEntity<?> get(@PathVariable Long id) {
+ var response = diaryService.get(id);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/search-all")
+ public ResponseEntity<?> getAll(
+ @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
+ ) {
+ var response = diaryService.getAll(pageable);
+ return PageDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์์ ํ๊ธฐ")
+ @PutMapping("/{id}") // @PatchMapping
+ public ResponseEntity<?> update(
+ @PathVariable Long id,
+ @RequestBody DiaryUpdateRequest request
+ ) {
+ var response = diaryService.update(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/{id}")
+ public ResponseEntity<Void> delete(
+ @PathVariable Long id
+ ) {
+ diaryService.delete(id);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Diary ์๋ณ ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/month/{month}")
+ public ResponseEntity<Void> monthDelete(@PathVariable int month) {
+ diaryService.monthDelete(month);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Feeling ์์ ํ๊ธฐ")
+ @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/feeling/{id}")
+ public ResponseEntity<?> updateFeeling(@PathVariable Long id, @RequestBody FeelingUpdateRequest request) {
+ var response = feelingService.updateFeeling(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Feeling ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/feeling-all")
+ public ResponseEntity<?> getAllFeeling(@PageableDefault Pageable pageable) {
+ var response = feelingService.getAllFeeling(pageable);
+ return PageDto.ok(response);
+ }
+} | Java | ์ ์ฉํด๋ณด์์ต๋๋ค |
@@ -0,0 +1,97 @@
+package com.selab.todo.controller;
+
+import com.selab.todo.common.dto.PageDto;
+import com.selab.todo.common.dto.ResponseDto;
+import com.selab.todo.dto.request.diary.DiaryRegisterRequest;
+import com.selab.todo.dto.request.diary.DiaryUpdateRequest;
+import com.selab.todo.dto.request.feel.FeelingUpdateRequest;
+import com.selab.todo.service.DiaryService;
+import com.selab.todo.service.FeelingService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = {"Diary API"})
+@RestController
+@RequestMapping(value = "/api/v1/diaries", produces = MediaType.APPLICATION_JSON_VALUE)
+@RequiredArgsConstructor
+public class DiaryController {
+ private final DiaryService diaryService;
+ private final FeelingService feelingService;
+
+ @ApiOperation(value = "Diary ๋ฑ๋กํ๊ธฐ")
+ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/register")
+ public ResponseEntity<?> register(@RequestBody DiaryRegisterRequest request) {
+ var response = diaryService.register(request);
+ return ResponseDto.created(response);
+ }
+
+ @ApiOperation(value = "Diary ๋จ๊ฑด ์กฐํํ๊ธฐ")
+ @GetMapping("/{id}")
+ public ResponseEntity<?> get(@PathVariable Long id) {
+ var response = diaryService.get(id);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/search-all")
+ public ResponseEntity<?> getAll(
+ @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
+ ) {
+ var response = diaryService.getAll(pageable);
+ return PageDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์์ ํ๊ธฐ")
+ @PutMapping("/{id}") // @PatchMapping
+ public ResponseEntity<?> update(
+ @PathVariable Long id,
+ @RequestBody DiaryUpdateRequest request
+ ) {
+ var response = diaryService.update(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/{id}")
+ public ResponseEntity<Void> delete(
+ @PathVariable Long id
+ ) {
+ diaryService.delete(id);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Diary ์๋ณ ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/month/{month}")
+ public ResponseEntity<Void> monthDelete(@PathVariable int month) {
+ diaryService.monthDelete(month);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Feeling ์์ ํ๊ธฐ")
+ @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/feeling/{id}")
+ public ResponseEntity<?> updateFeeling(@PathVariable Long id, @RequestBody FeelingUpdateRequest request) {
+ var response = feelingService.updateFeeling(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Feeling ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/feeling-all")
+ public ResponseEntity<?> getAllFeeling(@PageableDefault Pageable pageable) {
+ var response = feelingService.getAllFeeling(pageable);
+ return PageDto.ok(response);
+ }
+} | Java | default๋ ์ ํ์ํด์?? |
@@ -0,0 +1,97 @@
+package com.selab.todo.controller;
+
+import com.selab.todo.common.dto.PageDto;
+import com.selab.todo.common.dto.ResponseDto;
+import com.selab.todo.dto.request.diary.DiaryRegisterRequest;
+import com.selab.todo.dto.request.diary.DiaryUpdateRequest;
+import com.selab.todo.dto.request.feel.FeelingUpdateRequest;
+import com.selab.todo.service.DiaryService;
+import com.selab.todo.service.FeelingService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = {"Diary API"})
+@RestController
+@RequestMapping(value = "/api/v1/diaries", produces = MediaType.APPLICATION_JSON_VALUE)
+@RequiredArgsConstructor
+public class DiaryController {
+ private final DiaryService diaryService;
+ private final FeelingService feelingService;
+
+ @ApiOperation(value = "Diary ๋ฑ๋กํ๊ธฐ")
+ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/register")
+ public ResponseEntity<?> register(@RequestBody DiaryRegisterRequest request) {
+ var response = diaryService.register(request);
+ return ResponseDto.created(response);
+ }
+
+ @ApiOperation(value = "Diary ๋จ๊ฑด ์กฐํํ๊ธฐ")
+ @GetMapping("/{id}")
+ public ResponseEntity<?> get(@PathVariable Long id) {
+ var response = diaryService.get(id);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/search-all")
+ public ResponseEntity<?> getAll(
+ @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
+ ) {
+ var response = diaryService.getAll(pageable);
+ return PageDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์์ ํ๊ธฐ")
+ @PutMapping("/{id}") // @PatchMapping
+ public ResponseEntity<?> update(
+ @PathVariable Long id,
+ @RequestBody DiaryUpdateRequest request
+ ) {
+ var response = diaryService.update(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Diary ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/{id}")
+ public ResponseEntity<Void> delete(
+ @PathVariable Long id
+ ) {
+ diaryService.delete(id);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Diary ์๋ณ ์ญ์ ํ๊ธฐ")
+ @DeleteMapping("/month/{month}")
+ public ResponseEntity<Void> monthDelete(@PathVariable int month) {
+ diaryService.monthDelete(month);
+ return ResponseDto.noContent();
+ }
+
+ @ApiOperation(value = "Feeling ์์ ํ๊ธฐ")
+ @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/feeling/{id}")
+ public ResponseEntity<?> updateFeeling(@PathVariable Long id, @RequestBody FeelingUpdateRequest request) {
+ var response = feelingService.updateFeeling(id, request);
+ return ResponseDto.ok(response);
+ }
+
+ @ApiOperation(value = "Feeling ์ ์ฒด ์กฐํํ๊ธฐ")
+ @GetMapping("/feeling-all")
+ public ResponseEntity<?> getAllFeeling(@PageableDefault Pageable pageable) {
+ var response = feelingService.getAllFeeling(pageable);
+ return PageDto.ok(response);
+ }
+} | Java | REST API
- POST : /api/v1/diaries
- GET : /api/v1/diaries
- GET : /api/v1/diaries/{id}
- PUT : /api/v1/diaries/{id}
- DELETE : /api/v1/diaries/{id}
์ด ํํ ์๋๊ฐ์?
๊ทธ๋ฆฌ๊ณ url path์ ์ ๋๋ฌธ์๊ฐ ๋ค์ด๊ฐ๋๊ฑธ๊น์ฉ? |
@@ -0,0 +1,42 @@
+package racingcar.domain;
+
+import racingcar.exception.CarNameLengthException;
+
+public class Car {
+
+ private static final int CAR_NAME_LENGTH = 5;
+ private static final int MOVABLE_MIN_NUMBER = 4;
+ private final String name;
+ private int position = 0;
+
+ public Car(String name) {
+ validate(name);
+ this.name = name;
+ }
+
+ private void validate(String name) {
+ validateLength(name);
+ }
+
+ private void validateLength(String name) {
+ if (name.length() > CAR_NAME_LENGTH) {
+ throw new CarNameLengthException();
+ }
+ }
+
+ public void move(CarMoveNumberGenerator carMoveNumberGenerator) {
+ final int number = carMoveNumberGenerator.generate();
+
+ if (number >= MOVABLE_MIN_NUMBER) {
+ position++;
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+} | Java | ์ปจ๋ฒค์
์ ๋ฐ๋ผ์ ์์์ ์ธ์คํด์ค ๋ณ์๋ฅผ ์ ์ค๋ก ๊ตฌ๋ถํด์ฃผ์๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!! |
@@ -0,0 +1,71 @@
+package racingcar.domain;
+
+import racingcar.exception.CarsDuplicatedNameException;
+import racingcar.exception.CarsMaxScoreBlankException;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class Cars {
+
+ private static final String DELIMITER = ",";
+ private static final String DUPLICATED_DELIMITER_REGEX = ",+";
+ private final List<Car> cars;
+
+ private Cars(List<Car> cars) {
+ this.cars = Collections.unmodifiableList(cars);
+ }
+
+ public static Cars createCarNameByWord(String input) {
+ List<Car> cars = new ArrayList<>();
+ String[] words = divideWord(input);
+ validate(words);
+
+ for (String carName : words) {
+ cars.add(new Car(carName));
+ }
+ return new Cars(cars);
+ }
+
+ private static void validate(String[] words) {
+ validateDuplicatedWord(words);
+ }
+
+ private static void validateDuplicatedWord(String[] words) {
+ Set<String> uniqueWord = new HashSet<>();
+ for (String word : words) {
+ if (!uniqueWord.add(word)) {
+ throw new CarsDuplicatedNameException();
+ }
+ }
+ }
+
+ private static String[] divideWord(String word) {
+ return word.replaceAll(DUPLICATED_DELIMITER_REGEX, DELIMITER).split(DELIMITER);
+ }
+
+ public void move(CarMoveNumberGenerator carMoveNumberGenerator) {
+ for (Car car : cars) {
+ car.move(carMoveNumberGenerator);
+ }
+ }
+
+ public Winner findWinner() {
+ int maxScore = findMaxScore();
+ return new Winner(cars.stream()
+ .filter(car -> (car.getPosition() == maxScore))
+ .map(Car::getName)
+ .collect(Collectors.toList()));
+ }
+
+ private int findMaxScore() {
+ return cars.stream()
+ .max(Comparator.comparingInt(Car::getPosition))
+ .map(Car::getPosition)
+ .orElseThrow(CarsMaxScoreBlankException::new);
+ }
+
+ public List<Car> getCars() {
+ return cars;
+ }
+} | Java | ๋ถ๋ณ ๊ฐ์ฒด๋ฅผ ๋ง๋ค ๋ ์์ฑ์ ๋จ๊ณ์์๋ ๋ฐฉ์ด์ ๋ณต์ฌ๋ฅผ ๊ณ ๋ คํด์ฃผ์๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์์!!
- [๋ฐฉ์ด์ ๋ณต์ฌ์ Unmodifiable Collections](https://tecoble.techcourse.co.kr/post/2021-04-26-defensive-copy-vs-unmodifiable/) |
@@ -0,0 +1,16 @@
+package racingcar.domain;
+
+import java.util.List;
+
+public class Winner {
+
+ private final List<String> winner;
+
+ public Winner(List<String> winner) {
+ this.winner = winner;
+ }
+
+ public List<String> getWinner() {
+ return winner;
+ }
+} | Java | ๋ฆฌ์คํธ์ ๋ค์ด๋ฐ์ ๋ณต์ํ์ด ๋ ์ ์ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค!
`Winner` ํด๋์ค ์์ฒด๋ ์น๋ฆฌ์๋ค์ ์ด๋ฆ์ ๋ด๊ณ ์๋ ์ผ๊ธ ์ปฌ๋ ์
์ด๊ธฐ ๋๋ฌธ์ `Winners` ๋ผ๋ ๋ค์ด๋ฐ์ ๋ ์ถ์ฒ๋๋ฆฝ๋๋ค! |
@@ -0,0 +1,54 @@
+package racingcar.view;
+
+import racingcar.domain.Car;
+import racingcar.domain.Cars;
+import racingcar.domain.Winner;
+
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class OutputView {
+
+ private static final String MESSAGE_INPUT_CAR_NAME = "๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)";
+ private static final String MESSAGE_INPUT_TRY = "์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?";
+ private static final String MESSAGE_RESULT = "์คํ ๊ฒฐ๊ณผ";
+ private static final String MOVE_MARK = "-";
+ private static final String JOIN_NAME_AND_POSITION = " : ";
+ private static final String WINNER_DELIMITER = ",";
+ private static final String MESSAGE_WINNER_PREFIX = "์ต์ข
์ฐ์น์ : ";
+ private static final String MESSAGE_WINNER_SUFFIX = "";
+
+ public void printInputCarName() {
+ System.out.println(MESSAGE_INPUT_CAR_NAME);
+ }
+
+ public void printExceptionMessage(IllegalArgumentException exceptionMessage) {
+ System.out.println(exceptionMessage.getMessage());
+ }
+
+ public void printInputTry() {
+ System.out.println(MESSAGE_INPUT_TRY);
+ }
+
+ public void printBlank() {
+ System.out.println();
+ }
+
+ public void printResult(Cars cars) {
+ System.out.println(MESSAGE_RESULT);
+ for(Car car : cars.getCars()){
+ System.out.println(car.getName() + JOIN_NAME_AND_POSITION + convertMoveMark(car.getPosition()));
+ }
+ printBlank();
+ }
+
+ private String convertMoveMark(int position) {
+ return Stream.generate(() -> MOVE_MARK).limit(position).collect(Collectors.joining());
+ }
+
+ public void printWinner(Winner winner) {
+ String message = winner.getWinner().stream()
+ .collect(Collectors.joining(WINNER_DELIMITER, MESSAGE_WINNER_PREFIX, MESSAGE_WINNER_SUFFIX));
+ System.out.println(message);
+ }
+} | Java | String์์ ์ ๊ณตํ๋ `repeat()` ๋ฉ์๋๋ฅผ ํ์ฉํด๋ณด์๋ ๊ฒ๋ ์ถ์ฒ๋๋ฆฝ๋๋ค! |
@@ -0,0 +1,71 @@
+package racingcar.domain;
+
+import racingcar.exception.CarsDuplicatedNameException;
+import racingcar.exception.CarsMaxScoreBlankException;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class Cars {
+
+ private static final String DELIMITER = ",";
+ private static final String DUPLICATED_DELIMITER_REGEX = ",+";
+ private final List<Car> cars;
+
+ private Cars(List<Car> cars) {
+ this.cars = Collections.unmodifiableList(cars);
+ }
+
+ public static Cars createCarNameByWord(String input) {
+ List<Car> cars = new ArrayList<>();
+ String[] words = divideWord(input);
+ validate(words);
+
+ for (String carName : words) {
+ cars.add(new Car(carName));
+ }
+ return new Cars(cars);
+ }
+
+ private static void validate(String[] words) {
+ validateDuplicatedWord(words);
+ }
+
+ private static void validateDuplicatedWord(String[] words) {
+ Set<String> uniqueWord = new HashSet<>();
+ for (String word : words) {
+ if (!uniqueWord.add(word)) {
+ throw new CarsDuplicatedNameException();
+ }
+ }
+ }
+
+ private static String[] divideWord(String word) {
+ return word.replaceAll(DUPLICATED_DELIMITER_REGEX, DELIMITER).split(DELIMITER);
+ }
+
+ public void move(CarMoveNumberGenerator carMoveNumberGenerator) {
+ for (Car car : cars) {
+ car.move(carMoveNumberGenerator);
+ }
+ }
+
+ public Winner findWinner() {
+ int maxScore = findMaxScore();
+ return new Winner(cars.stream()
+ .filter(car -> (car.getPosition() == maxScore))
+ .map(Car::getName)
+ .collect(Collectors.toList()));
+ }
+
+ private int findMaxScore() {
+ return cars.stream()
+ .max(Comparator.comparingInt(Car::getPosition))
+ .map(Car::getPosition)
+ .orElseThrow(CarsMaxScoreBlankException::new);
+ }
+
+ public List<Car> getCars() {
+ return cars;
+ }
+} | Java | `CarMoveNumberGenerator` ๋ฅผ `Car` ๊ฐ์ฒด๊น์ง ๋๊ฒจ์ฃผ์ง ์์๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค!
๊ทธ๋ฌ๋ฉด `car.move()` ๋ฉ์๋๋ฅผ ํ
์คํธํ๊ธฐ๋ ํจ์ฌ ๊ฐํธํด์ง ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,22 @@
+package racingcar.domain;
+
+public class RacingCarGame {
+
+ private final Cars cars;
+
+ public RacingCarGame(Cars cars) {
+ this.cars = cars;
+ }
+
+ public void move() {
+ cars.move(new CarRandomMoveNumberGenerator());
+ }
+
+ public Winner findWinner() {
+ return cars.findWinner();
+ }
+
+ public Cars getCars() {
+ return cars;
+ }
+} | Java | `RacingCarGame` ํด๋์ค์ ๋ฉ์๋๋ค์ด ๋๋ถ๋ถ `Cars` ํด๋์ค์ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ์ฉ๋๋ก๋ง ์ฌ์ฉ๋๋ ๊ฒ ๊ฐ์์!
`RacingCarGame` ํด๋์ค๊ฐ ์ ๋ง ํ์ํ์ง, ์๋๋ฉด ์ด๋ค ์์ผ๋ก `RacingCarGame` ๋ง์ ์๋ก์ด ์ฑ
์์ ๋ถ์ฌํ ์ ์์ ์ง
์๊ฐํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์!! |
@@ -0,0 +1,47 @@
+package racingcar.domain;
+
+import racingcar.exception.TryCommandNumberException;
+import racingcar.exception.TryCommandRangeException;
+
+public class TryCommand {
+
+ private static final int MIN_TRY = 1;
+ private static final int MAX_TRY = 100000;
+ private int tryCount;
+
+ private TryCommand(int tryCount) {
+ this.tryCount = tryCount;
+ }
+
+ public static TryCommand createTryCommandByString(String input) {
+ int number = convertInt(input);
+ validate(number);
+ return new TryCommand(number);
+ }
+
+ private static void validate(int number) {
+ validateRange(number);
+ }
+
+ private static void validateRange(int number) {
+ if(number < MIN_TRY || number > MAX_TRY) {
+ throw new TryCommandRangeException(MIN_TRY, MAX_TRY);
+ }
+ }
+
+ private static int convertInt(String input) {
+ try{
+ return Integer.parseInt(input);
+ }catch (NumberFormatException exception) {
+ throw new TryCommandNumberException();
+ }
+ }
+
+ public boolean tryMove() {
+ if(tryCount > 0) {
+ tryCount--;
+ return true;
+ }
+ return false;
+ }
+} | Java | ๊ฐ ๊ฐ์ฒด์ ๋ด๋ถ ์ํ๋ฅผ `final` ๋ก ์ ์ธํ๋ ๋ฐฉ๋ฒ๋ ์๋๋ผ๊ตฌ์! ์ฐธ๊ณ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
- [Value Object, Reference Obejct](http://aeternum.egloos.com/v/1111257) |
@@ -0,0 +1,71 @@
+package racingcar.domain;
+
+import racingcar.exception.CarsDuplicatedNameException;
+import racingcar.exception.CarsMaxScoreBlankException;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class Cars {
+
+ private static final String DELIMITER = ",";
+ private static final String DUPLICATED_DELIMITER_REGEX = ",+";
+ private final List<Car> cars;
+
+ private Cars(List<Car> cars) {
+ this.cars = Collections.unmodifiableList(cars);
+ }
+
+ public static Cars createCarNameByWord(String input) {
+ List<Car> cars = new ArrayList<>();
+ String[] words = divideWord(input);
+ validate(words);
+
+ for (String carName : words) {
+ cars.add(new Car(carName));
+ }
+ return new Cars(cars);
+ }
+
+ private static void validate(String[] words) {
+ validateDuplicatedWord(words);
+ }
+
+ private static void validateDuplicatedWord(String[] words) {
+ Set<String> uniqueWord = new HashSet<>();
+ for (String word : words) {
+ if (!uniqueWord.add(word)) {
+ throw new CarsDuplicatedNameException();
+ }
+ }
+ }
+
+ private static String[] divideWord(String word) {
+ return word.replaceAll(DUPLICATED_DELIMITER_REGEX, DELIMITER).split(DELIMITER);
+ }
+
+ public void move(CarMoveNumberGenerator carMoveNumberGenerator) {
+ for (Car car : cars) {
+ car.move(carMoveNumberGenerator);
+ }
+ }
+
+ public Winner findWinner() {
+ int maxScore = findMaxScore();
+ return new Winner(cars.stream()
+ .filter(car -> (car.getPosition() == maxScore))
+ .map(Car::getName)
+ .collect(Collectors.toList()));
+ }
+
+ private int findMaxScore() {
+ return cars.stream()
+ .max(Comparator.comparingInt(Car::getPosition))
+ .map(Car::getPosition)
+ .orElseThrow(CarsMaxScoreBlankException::new);
+ }
+
+ public List<Car> getCars() {
+ return cars;
+ }
+} | Java | ์คํธ๋ฆผ์ผ๋ก ๋ก์ง์ ๋ฐ๊พธ์๋ฉด ๋น ๋ฆฌ์คํธ๋ฅผ ์ ์ธํ์ง ์๊ณ ๋ ๊น๋ํ๊ฒ ๊ตฌํํ ์ ์์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,10 @@
+package racingcar.exception;
+
+public class CarNameLengthException extends IllegalArgumentException{
+
+ private static final String EXCEPTION_MESSAGE_CAR_NAME_LENGTH = "[ERROR] ์๋์ฐจ์ด๋ฆ์ 5๊ธ์ ์ดํ์
๋๋ค";
+
+ public CarNameLengthException() {
+ super(EXCEPTION_MESSAGE_CAR_NAME_LENGTH);
+ }
+} | Java | ํน๋ณํ ์ปค์คํ
์์ธ๋ฅผ ์ฌ์ฉํ์ ์ด์ ๊ฐ ์์๊น์?? ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,42 @@
+package racingcar.domain;
+
+import racingcar.exception.CarNameLengthException;
+
+public class Car {
+
+ private static final int CAR_NAME_LENGTH = 5;
+ private static final int MOVABLE_MIN_NUMBER = 4;
+ private final String name;
+ private int position = 0;
+
+ public Car(String name) {
+ validate(name);
+ this.name = name;
+ }
+
+ private void validate(String name) {
+ validateLength(name);
+ }
+
+ private void validateLength(String name) {
+ if (name.length() > CAR_NAME_LENGTH) {
+ throw new CarNameLengthException();
+ }
+ }
+
+ public void move(CarMoveNumberGenerator carMoveNumberGenerator) {
+ final int number = carMoveNumberGenerator.generate();
+
+ if (number >= MOVABLE_MIN_NUMBER) {
+ position++;
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+} | Java | ๊ฐ์ฌํฉ๋๋ค! ๋์น๊ณ ์๋ ๋ถ๋ถ์ด๋ค์.. |
@@ -0,0 +1,71 @@
+package racingcar.domain;
+
+import racingcar.exception.CarsDuplicatedNameException;
+import racingcar.exception.CarsMaxScoreBlankException;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class Cars {
+
+ private static final String DELIMITER = ",";
+ private static final String DUPLICATED_DELIMITER_REGEX = ",+";
+ private final List<Car> cars;
+
+ private Cars(List<Car> cars) {
+ this.cars = Collections.unmodifiableList(cars);
+ }
+
+ public static Cars createCarNameByWord(String input) {
+ List<Car> cars = new ArrayList<>();
+ String[] words = divideWord(input);
+ validate(words);
+
+ for (String carName : words) {
+ cars.add(new Car(carName));
+ }
+ return new Cars(cars);
+ }
+
+ private static void validate(String[] words) {
+ validateDuplicatedWord(words);
+ }
+
+ private static void validateDuplicatedWord(String[] words) {
+ Set<String> uniqueWord = new HashSet<>();
+ for (String word : words) {
+ if (!uniqueWord.add(word)) {
+ throw new CarsDuplicatedNameException();
+ }
+ }
+ }
+
+ private static String[] divideWord(String word) {
+ return word.replaceAll(DUPLICATED_DELIMITER_REGEX, DELIMITER).split(DELIMITER);
+ }
+
+ public void move(CarMoveNumberGenerator carMoveNumberGenerator) {
+ for (Car car : cars) {
+ car.move(carMoveNumberGenerator);
+ }
+ }
+
+ public Winner findWinner() {
+ int maxScore = findMaxScore();
+ return new Winner(cars.stream()
+ .filter(car -> (car.getPosition() == maxScore))
+ .map(Car::getName)
+ .collect(Collectors.toList()));
+ }
+
+ private int findMaxScore() {
+ return cars.stream()
+ .max(Comparator.comparingInt(Car::getPosition))
+ .map(Car::getPosition)
+ .orElseThrow(CarsMaxScoreBlankException::new);
+ }
+
+ public List<Car> getCars() {
+ return cars;
+ }
+} | Java | ์ค... ์ข์๊ธ ๊ฐ์ฌํฉ๋๋ค. ๋ฐฉ์ด์ ๋ณต์ฌ๋ ์ฒ์ ์ ํด๋ณด๋ ๊ฐ๋
์ด๋ค์! |
@@ -0,0 +1,54 @@
+package racingcar.view;
+
+import racingcar.domain.Car;
+import racingcar.domain.Cars;
+import racingcar.domain.Winner;
+
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class OutputView {
+
+ private static final String MESSAGE_INPUT_CAR_NAME = "๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)";
+ private static final String MESSAGE_INPUT_TRY = "์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?";
+ private static final String MESSAGE_RESULT = "์คํ ๊ฒฐ๊ณผ";
+ private static final String MOVE_MARK = "-";
+ private static final String JOIN_NAME_AND_POSITION = " : ";
+ private static final String WINNER_DELIMITER = ",";
+ private static final String MESSAGE_WINNER_PREFIX = "์ต์ข
์ฐ์น์ : ";
+ private static final String MESSAGE_WINNER_SUFFIX = "";
+
+ public void printInputCarName() {
+ System.out.println(MESSAGE_INPUT_CAR_NAME);
+ }
+
+ public void printExceptionMessage(IllegalArgumentException exceptionMessage) {
+ System.out.println(exceptionMessage.getMessage());
+ }
+
+ public void printInputTry() {
+ System.out.println(MESSAGE_INPUT_TRY);
+ }
+
+ public void printBlank() {
+ System.out.println();
+ }
+
+ public void printResult(Cars cars) {
+ System.out.println(MESSAGE_RESULT);
+ for(Car car : cars.getCars()){
+ System.out.println(car.getName() + JOIN_NAME_AND_POSITION + convertMoveMark(car.getPosition()));
+ }
+ printBlank();
+ }
+
+ private String convertMoveMark(int position) {
+ return Stream.generate(() -> MOVE_MARK).limit(position).collect(Collectors.joining());
+ }
+
+ public void printWinner(Winner winner) {
+ String message = winner.getWinner().stream()
+ .collect(Collectors.joining(WINNER_DELIMITER, MESSAGE_WINNER_PREFIX, MESSAGE_WINNER_SUFFIX));
+ System.out.println(message);
+ }
+} | Java | ์ด๋ฐ,, ์คํธ๋ฆผ์ ๋๋ฌด ๋จ๋ฐํ๋ค์.. `repeat()` ๋ผ๋ ์ข์ ํจ์๊ฐ ์๋๋ฐ ๋ง์ด์ฃ ใ
|
@@ -0,0 +1,22 @@
+package racingcar.domain;
+
+public class RacingCarGame {
+
+ private final Cars cars;
+
+ public RacingCarGame(Cars cars) {
+ this.cars = cars;
+ }
+
+ public void move() {
+ cars.move(new CarRandomMoveNumberGenerator());
+ }
+
+ public Winner findWinner() {
+ return cars.findWinner();
+ }
+
+ public Cars getCars() {
+ return cars;
+ }
+} | Java | ์๋ `RacingCarGame` ์์ ์๋ํ์๋ฅผ ๊ฐ์ง๊ณ ์์ด์ `Cars` ๋ฅผ ์๋ํ์๋งํผ ์์ง์ด๋ ๋ก์ง์ด์์๋๋ฐ controller ์ชฝ์ผ๋ก ํด๋น ๋ก์ง์ ์ฎ๊ธฐ๋๋ฐ๋์ ์ธ๋ชจ์๋ ํด๋์ค๊ฐ ๋์๋ค์.. ์ข์ ์ง์ ๊ฐ์ฌํฉ๋๋ค..! |
@@ -0,0 +1,47 @@
+package racingcar.domain;
+
+import racingcar.exception.TryCommandNumberException;
+import racingcar.exception.TryCommandRangeException;
+
+public class TryCommand {
+
+ private static final int MIN_TRY = 1;
+ private static final int MAX_TRY = 100000;
+ private int tryCount;
+
+ private TryCommand(int tryCount) {
+ this.tryCount = tryCount;
+ }
+
+ public static TryCommand createTryCommandByString(String input) {
+ int number = convertInt(input);
+ validate(number);
+ return new TryCommand(number);
+ }
+
+ private static void validate(int number) {
+ validateRange(number);
+ }
+
+ private static void validateRange(int number) {
+ if(number < MIN_TRY || number > MAX_TRY) {
+ throw new TryCommandRangeException(MIN_TRY, MAX_TRY);
+ }
+ }
+
+ private static int convertInt(String input) {
+ try{
+ return Integer.parseInt(input);
+ }catch (NumberFormatException exception) {
+ throw new TryCommandNumberException();
+ }
+ }
+
+ public boolean tryMove() {
+ if(tryCount > 0) {
+ tryCount--;
+ return true;
+ }
+ return false;
+ }
+} | Java | ๋ถ๋ณ์ผ๋ก ํด๋ ๊ฐ์ ๋ณ๊ฒฝํ๋ ๋ฐฉ๋ฒ์ด ์์๊ตฐ์..
DDD ์์ ๋์ค๋ ๊ฐ๋
์ด๋ผ MVC ์๋ ์ด๋ป๊ฒ ์ ์ฉํ ์ง๋ ๊ณ ๋ฏผ์ ํด๋ด์ผ๊ฒ ๋ค์..
์ข์๊ธ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,10 @@
+package racingcar.exception;
+
+public class CarNameLengthException extends IllegalArgumentException{
+
+ private static final String EXCEPTION_MESSAGE_CAR_NAME_LENGTH = "[ERROR] ์๋์ฐจ์ด๋ฆ์ 5๊ธ์ ์ดํ์
๋๋ค";
+
+ public CarNameLengthException() {
+ super(EXCEPTION_MESSAGE_CAR_NAME_LENGTH);
+ }
+} | Java | [์ปค์คํ
์์ธ](https://tecoble.techcourse.co.kr/post/2020-08-17-custom-exception/)
์ปค์คํ
์์ธ๋ค์ ์ฅ๋จ์ ์ด ์์ต๋๋ค! ๊ทธ๋์ ์ ๋ต์ ์์ง๋ง ์ ๊ฐ ์ฌ์ฉํ ์ด์ ๋
์ฒซ์งธ๋กํด๋์ค ์ด๋ฆ์ผ๋ก ์ด๋ค ์์ธ์ธ์ง ๋ฐ๋ก ์ ์ ์๊ณ
๋์งธ๋ก ๋ณดํต ๋๋ฉ์ธ ์ฝ๋๋ฅผ ๋ณผ๋ ์ค์ํ๊ฒ์ ๊ทธ ๋๋ฉ์ธ ์ญํ ๊ณผ ๊ด๋ จ๋ ๋ก์ง์ด์ง, ์์ธ์ฒ๋ฆฌ๋ฅผ ์ด๋ป๊ฒ ํ๋์ง๊ฐ ์ค์ํ๊ฒ ์๋๊ธฐ๋๋ฌธ์ ์์ธ๋ฅผ ๋ฐ๋ก๋นผ๋ด์ด ์ข ๋ ๋ณด๊ธฐ ํธํ๊ฒ ๋ง๋ค๊ธฐ ์ํจ์
๋๋ค!
์
์งธ๋ก ๋๋ถ๋ถ Spring MVC ํ๋ก์ ํธ์์๋ ์ปค์คํ
์์ธ๋ฅผ ์ฌ์ฉํ๊ธฐ์ ์ฐ์ต์ฐจ์์์ ์ปค์คํ
์์ธ๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. |
@@ -0,0 +1,32 @@
+package baseball.util
+
+// Message
+const val PRINT_NOTHING_MESSAGE = "๋ซ์ฑ"
+const val PRINT_STRIKE_MESSAGE = "%d์คํธ๋ผ์ดํฌ"
+const val PRINT_BALL_MESSAGE = "%d๋ณผ"
+const val PRINT_STRIKE_BALL_MESSAGE = "%d๋ณผ %d์คํธ๋ผ์ดํฌ"
+const val START_GAME_MASSAGE = "์ซ์ ์ผ๊ตฌ ๊ฒ์์ ์์ํฉ๋๋ค."
+const val QUIT_GAME_MASSAGE = "3๊ฐ์ ์ซ์๋ฅผ ๋ชจ๋ ๋งํ์
จ์ต๋๋ค! ๊ฒ์ ์ข
๋ฃ"
+const val SELECT_COMMAND_MESSAGE = "๊ฒ์์ ์๋ก ์์ํ๋ ค๋ฉด 1, ์ข
๋ฃํ๋ ค๋ฉด 2๋ฅผ ์
๋ ฅํ์ธ์."
+const val USER_INPUT_NUMBER_MESSAGE = "์ซ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์: "
+// Error
+const val ERROR_INVALID_INPUT_MESSAGE = "์๋ชป๋ ๊ฐ์ ์
๋ ฅํ์ต๋๋ค"
+const val ERROR_INVALID_COMMAND_MESSAGE = "1๊ณผ 2๋ง ์
๋ ฅํด์ฃผ์ธ์."
+
+// Command
+const val RETRY_COMMAND = "1"
+const val QUIT_COMMAND = "2"
+
+// Code
+const val END_CODE = 2
+const val PLAYING_CODE = 1
+
+// Size, Number
+const val MAX_SIZE = 3
+const val MAX_NUMBER = 9
+const val MIN_NUMBER = 1
+
+// String
+const val EMPTY_STRING = ""
+
+ | Kotlin | util ํด๋๋ฅผ ์ฌ์ฉํด EMPTY_STRING๊ณผ ๊ฐ์ด ์ฌ์ํ ๊ฐ๋ค๊น์ง ์์ํ๋ฅผ ํ์ ๋๋ถ์ ๊ฐ๋
์ฑ์ด ์ข๋ค์. ๋ฐฐ์๊ฐ๋๋ค! |
@@ -0,0 +1,59 @@
+package baseball.game
+
+import baseball.game.service.Game
+import baseball.model.AnswerBoard
+import baseball.model.Computer
+import baseball.util.*
+import baseball.view.User
+import baseball.view.validator.InputValidator
+
+class Baseball(
+ private val user: User,
+ private val computer: Computer,
+ private val answerBoard: AnswerBoard,
+) : Game {
+ private var gameState = PLAYING_CODE
+ private var answer = computer.createAnswer()
+
+ override fun play() {
+ println(START_GAME_MASSAGE)
+ process()
+ }
+
+ // ๊ฒ์ ์งํ
+ override fun process() {
+ do {
+ val userNumber = user.createNumber()
+
+ answerBoard.createResult(answer, userNumber)
+ println(answerBoard.printResult())
+
+ finish()
+ } while (isPlaying())
+ }
+
+ private fun isPlaying(): Boolean = gameState != END_CODE
+
+ override fun quit() {
+ gameState = END_CODE
+ }
+
+ override fun retry() {
+ answer = computer.createAnswer()
+ answerBoard.clearState()
+ }
+
+ private fun printFinishMessage() = println(QUIT_GAME_MASSAGE + "\n" + SELECT_COMMAND_MESSAGE)
+
+ private fun finish() {
+ if (answerBoard.isThreeStrike()) {
+ printFinishMessage()
+ when (InputValidator.validateUserCommand(readLine()!!)) {
+ RETRY_COMMAND -> retry()
+ QUIT_COMMAND -> quit()
+ }
+ }
+ }
+
+}
+ | Kotlin | MVC ๋ชจ๋ธ์ ์ฌ์ฉํ์ ๊ฒ ๊ฐ์ต๋๋ค.
Baseball Class๋ Controller์ ์ญํ ์ ํ๋ ๊ฒ ๊ฐ์๋ฐ, Controller์์ ์ง์ ์
๋ ฅ์ ๋ฐ๋ ๊ฒ๋ณด๋ค๋
์ฌ์ฉ์์ ์ง์ ์ ์ผ๋ก ๋ง๋ฟ๋ View์์ ์
๋ ฅ์ ๋ฐ์์ Controller์์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,12 @@
+package baseball.view
+
+import baseball.util.USER_INPUT_NUMBER_MESSAGE
+import baseball.view.validator.InputValidator
+
+class User {
+ fun createNumber(): String {
+ print(USER_INPUT_NUMBER_MESSAGE)
+ val userNumber = readLine()!!
+ return InputValidator.validateUserNumber(userNumber)
+ }
+}
\ No newline at end of file | Kotlin | ์ฌ์ฉ์๋ก๋ถํฐ ์
๋ ฅ์ ๋ฐ์์ ๊ฒ์ฌ๋ ๊ฐ์ ๋๋ ค๋ณด๋ด์ฃผ๋ ํจ์์ธ ๊ฒ ๊ฐ์ต๋๋ค.
create๋ผ๋ ํจ์๋ช
์ ๋ณด์์ ๋ ์ ๋ "์ฌ์ฉ์๊ฐ ๋ฒํธ๋ฅผ ๋ง๋๋? ์ฌ์ฉ์๊ฐ ๊ธฐ๊ณ์ ์ญํ ์ ํ๋ ๊ฒ์ธ๊ฐ?"๋ผ๋ ์๊ฐ์ด ๋ค์์ต๋๋ค.
input๊ณผ ์ด์ธ๋ฆฌ๋ ํจ์๋ช
์ด๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ํ, ์ ๋ ์ด ๋ถ๋ถ์ ์กฐ๊ธ ๊ณ ๋ฏผ๋๋ ๋ถ๋ถ์ด์ง๋ง,
MVC ํจํด์ View์์ ๋ค๋ฅธ ํด๋์ค๋ฅผ ๊ฐ์ ธ์ ๋ถ๊ธฐ๊ฐ ๋ฐ์ํ ์ ์๋ ๋ก์ง์ ์ฌ์ฉํ๋ ๊ฒ์ ํจํด์ ๊ท์น์ ๋ง์ง ์๋๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,17 @@
+package baseball.view.validator
+
+import baseball.util.*
+
+object InputValidator {
+
+ fun validateUserNumber(userNumber: String): String {
+ require(userNumber.length == MAX_SIZE) { ERROR_INVALID_INPUT_MESSAGE }
+ return userNumber
+ }
+
+ fun validateUserCommand(command: String): String {
+ require(command == RETRY_COMMAND || command == QUIT_COMMAND) { ERROR_INVALID_COMMAND_MESSAGE }
+ return command
+ }
+}
+ | Kotlin | ๋ฏผ์ฌ๋๊ป์ ์ ์๊ฒ require์ ๋ํด ์๋ ค์ฃผ์
จ์ฃ ..! ์ ์ฐ๊ณ ์์ต๋๋ค! ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,59 @@
+package baseball.model
+
+import baseball.util.*
+
+
+class AnswerBoard {
+ // ์ํ๋ฅผ ๋ชจ๋ ์์์ผ๋ก ์ด๊ธฐํ
+ private val stateList = MutableList(MAX_SIZE) { BaseballState.OUT }
+
+
+ private fun createCount(): Triple<Int, Int, Int> {
+ var strikeCount = 0
+ var ballCount = 0
+ var outCount = 0
+
+ stateList.forEach { state ->
+ when (state) {
+ BaseballState.STRIKE -> strikeCount++
+ BaseballState.BALL -> ballCount++
+ BaseballState.OUT -> outCount++
+ }
+ }
+ return Triple(strikeCount, ballCount, outCount)
+ }
+
+ fun createResult(answer: String, userNumber: String) {
+ answer.forEachIndexed { answerIndex, answerNumber ->
+ if (answerNumber == userNumber[answerIndex]) {
+ stateList[answerIndex] = BaseballState.STRIKE
+ }
+ if (answerNumber != userNumber[answerIndex] && answer.contains(userNumber[answerIndex])) {
+ stateList[answerIndex] = BaseballState.BALL
+ }
+ if (answerNumber != userNumber[answerIndex] && !answer.contains(userNumber[answerIndex])) {
+ stateList[answerIndex] = BaseballState.OUT
+ }
+ }
+ }
+
+ fun printResult(): String {
+ val (strikeCount, ballCount, outCount) = createCount()
+ var message = EMPTY_STRING
+
+ // ์์์ผ ๋ ์ถ๋ ฅ
+ if (outCount == stateList.size) message = PRINT_NOTHING_MESSAGE
+ // ์คํธ๋ผ์ดํฌ์ผ๋ ์ถ๋ ฅ
+ if (ballCount == 0 && strikeCount != 0) message = PRINT_STRIKE_MESSAGE.format(strikeCount)
+ // ๋ณผ์ผ๋ ์ถ๋ ฅ
+ if (ballCount != 0 && strikeCount == 0) message = PRINT_BALL_MESSAGE.format(ballCount)
+ // ์คํธ๋ผ์ดํฌ ๋ณผ์ผ ๋
+ if (ballCount != 0 && strikeCount != 0) message = PRINT_STRIKE_BALL_MESSAGE.format(ballCount, strikeCount)
+
+ return message
+ }
+
+ fun isThreeStrike(): Boolean = stateList.all { state -> state == BaseballState.STRIKE }
+
+ fun clearState() = stateList.replaceAll { BaseballState.OUT }
+} | Kotlin | createCount๋ผ๋ ํจ์๋ช
์ "๊ฐ์๋ฅผ **_๋ง๋ ๋ค_**"๋ผ๋ ์๋ฏธ์ธ ๊ฒ ๊ฐ์ต๋๋ค.
ํ์ง๋ง ํจ์์ ์ญํ ์ "์คํธ๋ผ์ดํฌ, ๋ณผ, ์์์ ๊ฐ์๋ฅผ **_์ผ๋ค_**"์ธ ๊ฒ ๊ฐ์ต๋๋ค.
ํจ์๋ช
๊ณผ ์ธ๊ฐ์ง์ ๊ธฐ๋ฅ์ ๋๋๋ ๊ฒ์ ์ด๋จ๊น์?
countStrike, countBall, countOut๊ณผ ๊ฐ์ด์! |
@@ -0,0 +1,59 @@
+package baseball.model
+
+import baseball.util.*
+
+
+class AnswerBoard {
+ // ์ํ๋ฅผ ๋ชจ๋ ์์์ผ๋ก ์ด๊ธฐํ
+ private val stateList = MutableList(MAX_SIZE) { BaseballState.OUT }
+
+
+ private fun createCount(): Triple<Int, Int, Int> {
+ var strikeCount = 0
+ var ballCount = 0
+ var outCount = 0
+
+ stateList.forEach { state ->
+ when (state) {
+ BaseballState.STRIKE -> strikeCount++
+ BaseballState.BALL -> ballCount++
+ BaseballState.OUT -> outCount++
+ }
+ }
+ return Triple(strikeCount, ballCount, outCount)
+ }
+
+ fun createResult(answer: String, userNumber: String) {
+ answer.forEachIndexed { answerIndex, answerNumber ->
+ if (answerNumber == userNumber[answerIndex]) {
+ stateList[answerIndex] = BaseballState.STRIKE
+ }
+ if (answerNumber != userNumber[answerIndex] && answer.contains(userNumber[answerIndex])) {
+ stateList[answerIndex] = BaseballState.BALL
+ }
+ if (answerNumber != userNumber[answerIndex] && !answer.contains(userNumber[answerIndex])) {
+ stateList[answerIndex] = BaseballState.OUT
+ }
+ }
+ }
+
+ fun printResult(): String {
+ val (strikeCount, ballCount, outCount) = createCount()
+ var message = EMPTY_STRING
+
+ // ์์์ผ ๋ ์ถ๋ ฅ
+ if (outCount == stateList.size) message = PRINT_NOTHING_MESSAGE
+ // ์คํธ๋ผ์ดํฌ์ผ๋ ์ถ๋ ฅ
+ if (ballCount == 0 && strikeCount != 0) message = PRINT_STRIKE_MESSAGE.format(strikeCount)
+ // ๋ณผ์ผ๋ ์ถ๋ ฅ
+ if (ballCount != 0 && strikeCount == 0) message = PRINT_BALL_MESSAGE.format(ballCount)
+ // ์คํธ๋ผ์ดํฌ ๋ณผ์ผ ๋
+ if (ballCount != 0 && strikeCount != 0) message = PRINT_STRIKE_BALL_MESSAGE.format(ballCount, strikeCount)
+
+ return message
+ }
+
+ fun isThreeStrike(): Boolean = stateList.all { state -> state == BaseballState.STRIKE }
+
+ fun clearState() = stateList.replaceAll { BaseballState.OUT }
+} | Kotlin | ๋ณ์๋ช
์ด ๋์ฌ + ๋ช
์ฌ๋ก ํ๋ค๋ฉด ํจ์๋ช
๊ณผ ๋ถ์ผ์น ํ์ง ์์๊น์ ?!?
์ด๋ฆ ์ง๊ธฐ์์ ์ค์ํ ๋ช
์ฌ๋ ์์ ์ฐ๋ ๊ฒ์ด ์ข๋ซ๊ณ ํฉ๋๋ค !! ex) countStrike -> strikeCount |
@@ -0,0 +1,12 @@
+package baseball.view
+
+import baseball.util.USER_INPUT_NUMBER_MESSAGE
+import baseball.view.validator.InputValidator
+
+class User {
+ fun createNumber(): String {
+ print(USER_INPUT_NUMBER_MESSAGE)
+ val userNumber = readLine()!!
+ return InputValidator.validateUserNumber(userNumber)
+ }
+}
\ No newline at end of file | Kotlin | ์ด ๋ถ๋ถ๋ ์ง๊ธ๊น์ง๋ ๊ณ ๋ฏผ์ด์๋๋ฐ ์์ธ์ฒ๋ฆฌ๋ฅผ ๋ฐ๋ก ํด์ฃผ๋ ๊ฒ์ด ์ข๋ค๊ณ ํฉ๋๋ค !! |
@@ -1,37 +1,20 @@
import java.util.List;
+import java.util.Set;
-import domain.LottoGame;
-import domain.LottoResults;
-import domain.WinningAnalyzer;
-import domain.WinningStatistics;
+import domain.ManualRequest;
import view.LottoInputView;
-import view.LottoOutputView;
public class LottoController {
- private LottoGame lottoGame;
- private WinningAnalyzer winningAnalyzer;
- public void playLottoGames(int money) {
- lottoGame = new LottoGame();
- lottoGame.generateLottoResultsFromMoney(money);
- }
-
- public void getLottoResults() {
- List<List<Integer>> results = lottoGame.getLottoResults().lottoNumbersToInt();
- int gameCount = lottoGame.getCount();
- LottoOutputView.printLottoResults(gameCount, results);
- }
-
- public void getWinningStatistics() {
- LottoResults lottoResults = lottoGame.getLottoResults();
- winningAnalyzer = new WinningAnalyzer(lottoResults, LottoInputView.getWinningNumbers(), LottoInputView.getBonusNumber());
- WinningStatistics winningStatistics = winningAnalyzer.calculateWinningStatistics();
- LottoOutputView.printBeforeWinnings();
- LottoOutputView.printWinnings(winningStatistics);
- }
-
- public void getReturnOnInvestment() {
- int money = lottoGame.getMoney();
- LottoOutputView.printReturnOnInvestment(winningAnalyzer.getReturnOnInvestment(money));
+ public static void main(String[] args) {
+ int money = LottoInputView.getMoney();
+ int manualCount = LottoInputView.getManualCount();
+ List<Set<Integer>> manualNumbers = LottoInputView.getManualLottos(manualCount);
+ LottoService lottoService = new LottoService();
+ ManualRequest manualRequest = new ManualRequest(manualCount, manualNumbers);
+ lottoService.playLottoGames(manualRequest, money);
+ lottoService.lottoResults();
+ lottoService.winningStatistics();
+ lottoService.returnOnInvestment();
}
} | Java | ์ผ๊ธ ์ปฌ๋ ์
์ ์จ๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -1,13 +0,0 @@
-import view.LottoInputView;
-
-public class LottoMain {
-
- public static void main(String[] args) {
- int money = LottoInputView.getMoney();
- LottoController lottoController = new LottoController();
- lottoController.playLottoGames(money);
- lottoController.getLottoResults();
- lottoController.getWinningStatistics();
- lottoController.getReturnOnInvestment();
- }
-} | Java | - ๊ฐ ๋์
, ๋ฉ์๋ ํธ์ถ๊ณผ ๊ฐ์ด ๊ฐ๋
์ ์ ์ฌ์ฑ์ด ๋ค๋ฅธ ์ฝ๋๋ค๊ฐ์๋ ๊ฐํ์ผ๋ก ๊ฐ๋
์ฑ์ ๋ํ์ค ์ ์์ต๋๋ค.
- ์ปจํธ๋กค๋ฌ์๊ฒ ์ธ๋ถ ๊ธฐ๋ฅ๋ค์ ํธ์ถํ๊ณ ์์ต๋๋ค. ์ด๊ฑด ๋น์ฆ๋์ค๋ก์ง ์ค์ผ์คํธ๋ ์ด์
์ผ๋ก ๋ณด์ฌ์. ๊ทธ๋ฅ ์ ์ ํ Request ๊ฐ์ฒด๋ฅผ ์ ๋ฌํ๊ณ ์ต์ข
๊ฒฐ๊ณผ๋ง ๋ฐํ๋ฐ์์ ์ถ๋ ฅ๊ณ์ธต์๊ฒ ์ ๋ฌํ๋ฉด ๋ ๊ฒ ๊ฐ์์.
- ํ์ฌ ๊ตฌ์กฐ๋ฅผ ๋ณด๋ฉด LottoMain์ด ์ปจํธ๋กค๋ฌ์ ์ญํ ์ ํ๊ณ ์๊ณ , LottoController๊ฐ Service Layer์ ์ญํ ์ ํ๊ณ ์์ต๋๋ค. ๊ทธ๋ผ ์ฐจ๋ผ๋ฆฌ Controller์์ View Layer๋ฅผ ๋ถ๋ฆฌํด LottoMain์ผ๋ก ์ฎ๊ธฐ์๊ณ LottoController์ ์ด๋ฆ์ LottoService๋ก ๋ฐ๊พธ๋๊ฑด ์ด๋จ๊น์ |
@@ -0,0 +1,15 @@
+package domain;
+
+public class GameCount {
+ private final int manualCount;
+ private final int automaticCount;
+
+ public GameCount(int totalCount, int manualCount) {
+ this.manualCount = manualCount;
+ this.automaticCount = totalCount - manualCount;
+ }
+
+ public int getAutomaticCount() {
+ return automaticCount;
+ }
+} | Java | ๋ด๋ถ์ ์ผ๋ก ๊ฐ์ด ๋ณ๊ฒฝ๋์ง ์๋๋ค๋ฉด final ํค์๋๋ฅผ ํตํด ๋ถ๋ณ์ฑ ํ๋ณด๋ฅผ ํ ์ ์์ ๊ฒ ๊ฐ๋ค์. |
@@ -1,23 +1,47 @@
package domain;
+import java.util.List;
+import java.util.Set;
+
public class LottoGame {
private LottoResults lottoResults;
-
private Money money;
+ private WinningAnalyzer winningAnalyzer;
public LottoGame() {
this.lottoResults = new LottoResults();
}
- public void generateLottoResultsFromMoney(int money) {
- this.money = new Money(money);
- for (int i = 0; i < getCount(); i++) {
- lottoResults.add(LottoNumGenerator.generateResult());
+ public void generateLottoResultsFromMoney(ManualRequest manualRequest, int money) {
+ int manualCount = manualRequest.getManualCount();
+ List<Set<Integer>> manualNumbers = manualRequest.getManualNumbers();
+ this.money = new Money(money, manualCount);
+ if (manualCount != manualNumbers.size()) {
+ throw new IllegalArgumentException("์๋ ๊ตฌ๋งค๊ฐ ์๋ชป๋์์ต๋๋ค.");
+ }
+ // ์๋ ๊ตฌ๋งค
+ generateManualResults(manualCount, manualNumbers);
+ generateAutomaticResults();
+ }
+
+ private void generateAutomaticResults() {
+ for (int i = 0; i < getAutomaticCount(); i++) {
+ lottoResults.add(LottoNumGenerator.generateAutomaticResults());
+ }
+ }
+
+ private void generateManualResults(int manualCount, List<Set<Integer>> manualNumbers) {
+ for (int i = 0; i < manualCount; i++) {
+ lottoResults.add(LottoNumGenerator.generateManualResults(manualNumbers.get(i)));
}
}
public int getCount() {
- return money.getCount();
+ return money.getTotalCount();
+ }
+
+ public int getAutomaticCount() {
+ return money.getAutomaticCount();
}
public int getMoney() {
@@ -27,5 +51,19 @@ public int getMoney() {
public LottoResults getLottoResults() {
return lottoResults;
}
+
+ public List<List<Integer>> getLottoResultsToInt() {
+ return lottoResults.lottoResultsToInt();
+ }
+
+ public WinningStatistics calculateWinningStatistics(Set<Integer> winningNumbers, int bonusNumber) {
+ winningAnalyzer = new WinningAnalyzer(lottoResults, winningNumbers, bonusNumber);
+ return winningAnalyzer.calculateWinningStatistics();
+ }
+
+ public float getReturnOnInvestment() {
+ return winningAnalyzer.getReturnOnInvestment(money.getMoney());
+ }
+
}
| Java | ์ด๋ฐ ์ฐธ์กฐํ์
๋ ์ผ๊ธ ์ปฌ๋ ์
์ ์ด์ฉํด์ ๋ด๋ถ ์ธ๋ฑ์ค ์ ์ด๋ฅผ ์ฑ
์ ๋ถ๋ฆฌํ ์ ์์ ๊ฒ ๊ฐ์์. |
@@ -1,23 +1,47 @@
package domain;
+import java.util.List;
+import java.util.Set;
+
public class LottoGame {
private LottoResults lottoResults;
-
private Money money;
+ private WinningAnalyzer winningAnalyzer;
public LottoGame() {
this.lottoResults = new LottoResults();
}
- public void generateLottoResultsFromMoney(int money) {
- this.money = new Money(money);
- for (int i = 0; i < getCount(); i++) {
- lottoResults.add(LottoNumGenerator.generateResult());
+ public void generateLottoResultsFromMoney(ManualRequest manualRequest, int money) {
+ int manualCount = manualRequest.getManualCount();
+ List<Set<Integer>> manualNumbers = manualRequest.getManualNumbers();
+ this.money = new Money(money, manualCount);
+ if (manualCount != manualNumbers.size()) {
+ throw new IllegalArgumentException("์๋ ๊ตฌ๋งค๊ฐ ์๋ชป๋์์ต๋๋ค.");
+ }
+ // ์๋ ๊ตฌ๋งค
+ generateManualResults(manualCount, manualNumbers);
+ generateAutomaticResults();
+ }
+
+ private void generateAutomaticResults() {
+ for (int i = 0; i < getAutomaticCount(); i++) {
+ lottoResults.add(LottoNumGenerator.generateAutomaticResults());
+ }
+ }
+
+ private void generateManualResults(int manualCount, List<Set<Integer>> manualNumbers) {
+ for (int i = 0; i < manualCount; i++) {
+ lottoResults.add(LottoNumGenerator.generateManualResults(manualNumbers.get(i)));
}
}
public int getCount() {
- return money.getCount();
+ return money.getTotalCount();
+ }
+
+ public int getAutomaticCount() {
+ return money.getAutomaticCount();
}
public int getMoney() {
@@ -27,5 +51,19 @@ public int getMoney() {
public LottoResults getLottoResults() {
return lottoResults;
}
+
+ public List<List<Integer>> getLottoResultsToInt() {
+ return lottoResults.lottoResultsToInt();
+ }
+
+ public WinningStatistics calculateWinningStatistics(Set<Integer> winningNumbers, int bonusNumber) {
+ winningAnalyzer = new WinningAnalyzer(lottoResults, winningNumbers, bonusNumber);
+ return winningAnalyzer.calculateWinningStatistics();
+ }
+
+ public float getReturnOnInvestment() {
+ return winningAnalyzer.getReturnOnInvestment(money.getMoney());
+ }
+
}
| Java | Money๊ฐ์ฒด์ธ๋ฐ count์ ๋ณด๊น์ง ๋ด์๋ฒ๋ฆฌ๋ฉด ์ผ๊ธ ๊ฐ์ฒด๋ก์จ์ ํจ์ฉ์ด ๋จ์ด์ง๊ณ ๊ฐ์ฒด ์๊ทธ๋์ฒ๊ฐ ๋ถ๋ถ๋ช
ํด์ง ๊ฒ ๊ฐ๋ค์ ๐ค |
@@ -1,23 +1,47 @@
package domain;
+import java.util.List;
+import java.util.Set;
+
public class LottoGame {
private LottoResults lottoResults;
-
private Money money;
+ private WinningAnalyzer winningAnalyzer;
public LottoGame() {
this.lottoResults = new LottoResults();
}
- public void generateLottoResultsFromMoney(int money) {
- this.money = new Money(money);
- for (int i = 0; i < getCount(); i++) {
- lottoResults.add(LottoNumGenerator.generateResult());
+ public void generateLottoResultsFromMoney(ManualRequest manualRequest, int money) {
+ int manualCount = manualRequest.getManualCount();
+ List<Set<Integer>> manualNumbers = manualRequest.getManualNumbers();
+ this.money = new Money(money, manualCount);
+ if (manualCount != manualNumbers.size()) {
+ throw new IllegalArgumentException("์๋ ๊ตฌ๋งค๊ฐ ์๋ชป๋์์ต๋๋ค.");
+ }
+ // ์๋ ๊ตฌ๋งค
+ generateManualResults(manualCount, manualNumbers);
+ generateAutomaticResults();
+ }
+
+ private void generateAutomaticResults() {
+ for (int i = 0; i < getAutomaticCount(); i++) {
+ lottoResults.add(LottoNumGenerator.generateAutomaticResults());
+ }
+ }
+
+ private void generateManualResults(int manualCount, List<Set<Integer>> manualNumbers) {
+ for (int i = 0; i < manualCount; i++) {
+ lottoResults.add(LottoNumGenerator.generateManualResults(manualNumbers.get(i)));
}
}
public int getCount() {
- return money.getCount();
+ return money.getTotalCount();
+ }
+
+ public int getAutomaticCount() {
+ return money.getAutomaticCount();
}
public int getMoney() {
@@ -27,5 +51,19 @@ public int getMoney() {
public LottoResults getLottoResults() {
return lottoResults;
}
+
+ public List<List<Integer>> getLottoResultsToInt() {
+ return lottoResults.lottoResultsToInt();
+ }
+
+ public WinningStatistics calculateWinningStatistics(Set<Integer> winningNumbers, int bonusNumber) {
+ winningAnalyzer = new WinningAnalyzer(lottoResults, winningNumbers, bonusNumber);
+ return winningAnalyzer.calculateWinningStatistics();
+ }
+
+ public float getReturnOnInvestment() {
+ return winningAnalyzer.getReturnOnInvestment(money.getMoney());
+ }
+
}
| Java | ์๋,์๋ ๋ก๋๋ฉด ๊ทธ๋ฅ LottoNumber, Lotto, Lottos ์ ๋๋ก ๋ค์ด๋ฐ์ ์ง์ด๋ ๋ ๊ฒ ๊ฐ๋ค์ Result๋ผ๊ณ ํ๋ ๋ญ๊ฐ ๋น๊ต๊น์ง ๋ค ๋๋ ์ต์ข
๊ฒฐ๊ณผ๋ฅผ ์๋ฏธํ๋ ๊ฑธ๋ก ๋ณด์
๋๋ค. |
@@ -1,23 +1,47 @@
package domain;
+import java.util.List;
+import java.util.Set;
+
public class LottoGame {
private LottoResults lottoResults;
-
private Money money;
+ private WinningAnalyzer winningAnalyzer;
public LottoGame() {
this.lottoResults = new LottoResults();
}
- public void generateLottoResultsFromMoney(int money) {
- this.money = new Money(money);
- for (int i = 0; i < getCount(); i++) {
- lottoResults.add(LottoNumGenerator.generateResult());
+ public void generateLottoResultsFromMoney(ManualRequest manualRequest, int money) {
+ int manualCount = manualRequest.getManualCount();
+ List<Set<Integer>> manualNumbers = manualRequest.getManualNumbers();
+ this.money = new Money(money, manualCount);
+ if (manualCount != manualNumbers.size()) {
+ throw new IllegalArgumentException("์๋ ๊ตฌ๋งค๊ฐ ์๋ชป๋์์ต๋๋ค.");
+ }
+ // ์๋ ๊ตฌ๋งค
+ generateManualResults(manualCount, manualNumbers);
+ generateAutomaticResults();
+ }
+
+ private void generateAutomaticResults() {
+ for (int i = 0; i < getAutomaticCount(); i++) {
+ lottoResults.add(LottoNumGenerator.generateAutomaticResults());
+ }
+ }
+
+ private void generateManualResults(int manualCount, List<Set<Integer>> manualNumbers) {
+ for (int i = 0; i < manualCount; i++) {
+ lottoResults.add(LottoNumGenerator.generateManualResults(manualNumbers.get(i)));
}
}
public int getCount() {
- return money.getCount();
+ return money.getTotalCount();
+ }
+
+ public int getAutomaticCount() {
+ return money.getAutomaticCount();
}
public int getMoney() {
@@ -27,5 +51,19 @@ public int getMoney() {
public LottoResults getLottoResults() {
return lottoResults;
}
+
+ public List<List<Integer>> getLottoResultsToInt() {
+ return lottoResults.lottoResultsToInt();
+ }
+
+ public WinningStatistics calculateWinningStatistics(Set<Integer> winningNumbers, int bonusNumber) {
+ winningAnalyzer = new WinningAnalyzer(lottoResults, winningNumbers, bonusNumber);
+ return winningAnalyzer.calculateWinningStatistics();
+ }
+
+ public float getReturnOnInvestment() {
+ return winningAnalyzer.getReturnOnInvestment(money.getMoney());
+ }
+
}
| Java | ์๋์์ฑ๊ณผ ์๋์์ฑ์ ๋ฉ์๋๋ก ๊ตฌ๋ถํ๊ณ ์๋๋ฐ LottoGenerator -> LottoAutoGenerator, LottoManualGenerator ๋ฑ์ผ๋ก ์ ๋ตํจํด์ ์ฌ์ฉํ ์๋ ์์ ๊ฒ ๊ฐ๋ค์ |
@@ -1,23 +1,47 @@
package domain;
+import java.util.List;
+import java.util.Set;
+
public class LottoGame {
private LottoResults lottoResults;
-
private Money money;
+ private WinningAnalyzer winningAnalyzer;
public LottoGame() {
this.lottoResults = new LottoResults();
}
- public void generateLottoResultsFromMoney(int money) {
- this.money = new Money(money);
- for (int i = 0; i < getCount(); i++) {
- lottoResults.add(LottoNumGenerator.generateResult());
+ public void generateLottoResultsFromMoney(ManualRequest manualRequest, int money) {
+ int manualCount = manualRequest.getManualCount();
+ List<Set<Integer>> manualNumbers = manualRequest.getManualNumbers();
+ this.money = new Money(money, manualCount);
+ if (manualCount != manualNumbers.size()) {
+ throw new IllegalArgumentException("์๋ ๊ตฌ๋งค๊ฐ ์๋ชป๋์์ต๋๋ค.");
+ }
+ // ์๋ ๊ตฌ๋งค
+ generateManualResults(manualCount, manualNumbers);
+ generateAutomaticResults();
+ }
+
+ private void generateAutomaticResults() {
+ for (int i = 0; i < getAutomaticCount(); i++) {
+ lottoResults.add(LottoNumGenerator.generateAutomaticResults());
+ }
+ }
+
+ private void generateManualResults(int manualCount, List<Set<Integer>> manualNumbers) {
+ for (int i = 0; i < manualCount; i++) {
+ lottoResults.add(LottoNumGenerator.generateManualResults(manualNumbers.get(i)));
}
}
public int getCount() {
- return money.getCount();
+ return money.getTotalCount();
+ }
+
+ public int getAutomaticCount() {
+ return money.getAutomaticCount();
}
public int getMoney() {
@@ -27,5 +51,19 @@ public int getMoney() {
public LottoResults getLottoResults() {
return lottoResults;
}
+
+ public List<List<Integer>> getLottoResultsToInt() {
+ return lottoResults.lottoResultsToInt();
+ }
+
+ public WinningStatistics calculateWinningStatistics(Set<Integer> winningNumbers, int bonusNumber) {
+ winningAnalyzer = new WinningAnalyzer(lottoResults, winningNumbers, bonusNumber);
+ return winningAnalyzer.calculateWinningStatistics();
+ }
+
+ public float getReturnOnInvestment() {
+ return winningAnalyzer.getReturnOnInvestment(money.getMoney());
+ }
+
}
| Java | ์ด ๋ฉ์๋๋ ProfitCalculator -> DefaultProfiltCalculator๋ฑ์ผ๋ก ๋ถ๋ฆฌํด์ ์ด์จ ๊ณ์ฐ๋ ์ถ์ํํ๋ฉด ์ ์ง๋ณด์์ฑ์ด ๋์์ง ๊ฒ ๊ฐ์์ |
@@ -1,7 +1,9 @@
package domain;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.Set;
public class LottoResult {
private List<LottoNumber> lottoResult;
@@ -14,10 +16,11 @@ public LottoResult(List<LottoNumber> lottoNumbers) {
this.lottoResult = lottoNumbers;
}
- public static LottoResult fromIntegers(List<Integer> lottoIntegers) {
+ public static LottoResult fromIntegers(Set<Integer> lottoIntegers) {
LottoResult lottoResult = new LottoResult();
- for (int i = 0; i < lottoIntegers.size(); i++) {
- lottoResult.lottoResult.add(LottoNumber.from(lottoIntegers.get(i)));
+ Iterator<Integer> iterator = lottoIntegers.iterator();
+ while (iterator.hasNext()) {
+ lottoResult.lottoResult.add(LottoNumber.from(iterator.next()));
}
return lottoResult;
}
@@ -38,4 +41,14 @@ public List<Integer> getLottoResult() {
}
return lottoNumbers;
}
+
+ public int calculateCount(WinningNumbers winningNumbers) {
+ int count = 0;
+ return lottoResult.stream().mapToInt(num -> num.addCountIfContain(count, winningNumbers)).sum();
+ }
+
+ public boolean isBonusMatch(BonusNumber bonusNumber) {
+ return lottoResult.stream()
+ .anyMatch(lottoNumber -> bonusNumber.isBonusMatch(lottoNumber));
+ }
} | Java | ๋๋ค์์์ count๋ผ๋ ์ธ๋ถ ๊ฐ์ ์ํฅ์ ์ฃผ๊ณ ์์ด์. ๐ค
๋๋ค์์ ์ธ๋ถ๊ฐ์ ๋ํ ์ํฅ์ ์ฃผ์ง ์์์ผ ํ๊ธฐ์ ์์ ํจ์๋ก ์ค๊ณ๋์ผํฉ๋๋ค. ๋ก์ง๋ด์์ ์ง์ count๊ฐ์ ์ง์ญ๋ณ์๋ฅผ ๋ณ๊ฒฝํ๋ ค๊ณ ํ๋ฉด effective final variable์ ์์ ํ๋ คํ๋ค๊ณ ์ปดํ์ผ ์๋ฌ๊ฐ ๋ฐ์ํ ๊ฒ์ธ๋ฐ, ๋ฉ์๋๋ฅผ ๋ค์ ํธ์ถํด์ ๊ทธ ๋ฌธ์ ๋ฅผ ํผํ์ง๋ง, ๊ทธ๋ ๋ค๊ณ ๋ฌธ์ ๊ฐ ๋์ง ์๋๊ฑด ์๋๋๋ค.
filter์ count๋ฑ์ ์ด์ฉํด์๊ตฌํํ ์๋ ์์ ๊ฒ ๊ฐ๋ค์ |
@@ -1,68 +1,75 @@
package domain;
+import static domain.WinningStatistics.THRESHOLD;
+
import java.util.HashMap;
import java.util.Map;
+import java.util.function.Function;
public enum WinningPrizes {
- MISS(0, 0) {
-
- },
- FIFTH_PRIZE(5, 5_000),
- FOURTH_PRIZE(4, 50_000),
- THIRD_PRIZE(3, 1_500_000),
- SECOND_PRIZE(2, 3_000_000),
- FIRST_PRIZE(1, 2_000_000_000);
-
- public static final int OFFSET = 3;
+ ZERO(0, false, 0, 0, count -> THRESHOLD),
+ ONE(1, false,0, 0, count -> THRESHOLD),
+ TWO(2, false, 5, 5_000, count -> THRESHOLD),
+ THREE(3, false, 5, 5_000, count -> count),
+ FOUR(4, false, 4, 50_000, count -> count),
+ FIVE(5, false, 3, 1_500_000, count -> count),
+ FIVE_BONUS(5, true, 2, 3_000_000, count -> count),
+ SIX(6, false, 1, 2_000_000_000, count -> count);
- private static final Map<Integer, WinningPrizes> WINNING_PRIZES_MAP = new HashMap<>();
+ private static final int HASH_GENERATION_NUMBER = 31;
+ private static final Map<Integer, WinningPrizes> WINNING_PRIZE_MATCHERS_MAP = new HashMap<>();
- static {
- for (WinningPrizes value : values()) {
- WINNING_PRIZES_MAP.put(value.rank, value);
- }
- }
+ private int numberOfCount;
+ private boolean isBonusMatch;
private int rank;
- private final int prizeMoney;
+ private int prizeMoney;
+ private Function<Integer, Integer> countSupplier;
- WinningPrizes(int rank, int prizeMoney) {
+
+ WinningPrizes(int numberOfCount, boolean isBonusMatch, int rank, int prizeMoney, Function<Integer, Integer> countSupplier) {
+ this.numberOfCount = numberOfCount;
+ this.isBonusMatch = isBonusMatch;
this.rank = rank;
this.prizeMoney = prizeMoney;
+ this.countSupplier = countSupplier;
}
- public int calculatePrizeMoney(int count) {
- return prizeMoney * count;
+ static {
+ for (WinningPrizes value : WinningPrizes.values()) {
+ WINNING_PRIZE_MATCHERS_MAP.put(getHashCode(value.numberOfCount, value.isBonusMatch), value);
+ }
}
- public int getPrizeMoney() {
- return prizeMoney;
+ public static int getHashCode(int numberOfCount, boolean isBonusMatch) {
+ int bonusNum = 0;
+ if (isBonusMatch) {
+ bonusNum = 1;
+ }
+ return numberOfCount * HASH_GENERATION_NUMBER + bonusNum;
}
- public int getRank() {
- return rank;
+ public static WinningPrizes valueOf(int numberOfCount, boolean isBonusMatch) {
+ isBonusMatch = checkBonus(numberOfCount, isBonusMatch);
+ return WINNING_PRIZE_MATCHERS_MAP.get(getHashCode(numberOfCount, isBonusMatch));
}
- public static WinningPrizes valueOf(int countOfMatch, boolean matchBonus) {
- if (countOfMatch < OFFSET) {
- return WinningPrizes.MISS;
- }
-
- if (WinningPrizes.SECOND_PRIZE.rank == countOfMatch) {
- return decideSecondOrThirdPrizes(matchBonus);
+ private static boolean checkBonus(int numberOfCount, boolean isBonusMatch) {
+ if (FIVE_BONUS.getNumberOfCount() != numberOfCount && isBonusMatch) {
+ isBonusMatch = false;
}
+ return isBonusMatch;
+ }
- return WINNING_PRIZES_MAP.get(countOfMatch);
+ public int calculatePrizeMoney(int count) {
+ return prizeMoney * count;
}
- public static WinningPrizes valueOf(int rank) {
- return WINNING_PRIZES_MAP.get(rank);
+ public int getPrizeMoney() {
+ return prizeMoney;
}
- private static WinningPrizes decideSecondOrThirdPrizes(boolean matchBonus) {
- if (matchBonus) {
- return WinningPrizes.SECOND_PRIZE;
- }
- return WinningPrizes.THIRD_PRIZE;
+ public int getNumberOfCount() {
+ return countSupplier.apply(numberOfCount);
}
} | Java | IntFunction์ ํ์ฉํด๋ ์ข์ ๊ฒ ๊ฐ์์. |
@@ -2,25 +2,62 @@
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.junit.jupiter.api.Test;
public class LottoGameTest {
@Test
- public void ๋ก๋_๊ตฌ์
๊ธ์ก์_์
๋ ฅํ๋ฉด_๊ตฌ์
๊ธ์ก์_ํด๋นํ๋_๋ก๋๋ฅผ_๋ฐํํ๋ค() {
+ public void ๋ก๋_๊ตฌ์
๊ธ์ก๊ณผ_๋ฒํธ๋ฅผ_์๋์ผ๋ก_์
๋ ฅํ๋ฉด_๊ตฌ์
๊ธ์ก์_ํด๋นํ๋_๋ก๋๋ฅผ_๋ฐํํ๋ค() {
//given
int money = 14000;
+ Set<Integer> manualLottoNumber = new HashSet<>();
+ manualLottoNumber.add(2);
+ manualLottoNumber.add(4);
+ manualLottoNumber.add(6);
+ manualLottoNumber.add(7);
+ manualLottoNumber.add(10);
+ manualLottoNumber.add(12);
+
+ int manualCount = 1;
LottoGame lottoGenerator = new LottoGame();
+ List<Set<Integer>> manualNumbers = new ArrayList<>();
+ manualNumbers.add(manualLottoNumber);
+ ManualRequest manualRequest = new ManualRequest(manualCount, manualNumbers);
+
//when
- lottoGenerator.generateLottoResultsFromMoney(money);
+ lottoGenerator.generateLottoResultsFromMoney(manualRequest, money);
LottoResults lottoResults = lottoGenerator.getLottoResults();
- List<List<Integer>> lottoResultList = lottoResults.lottoNumbersToInt();
+ List<List<Integer>> lottoResultList = lottoResults.lottoResultsToInt();
//then
assertThat(lottoResultList).hasSize(14);
for (List<Integer> lottoNum : lottoResultList) {
assertThat(lottoNum).hasSize(6);
}
}
+
+// @Test
+// public void ๋ก๋_๋ฒํธ๋ฅผ_์๋์ผ๋ก_์
๋ ฅํ _๋_์ค๋ณต๋_๋ฒํธ๋ฅผ_์
๋ ฅํ๋ฉด_์์ธ๋ฅผ_๋์ง๋ค() {
+// //given
+// int money = 1000;
+// List<Integer> manualLottoNumber = Arrays.asList(2, 2, 6, 7, 10, 12);
+// int manualCount = 1;
+// LottoGame lottoGenerator = new LottoGame();
+// List<List<Integer>> manualNumbers = new ArrayList<>();
+// manualNumbers.add(manualLottoNumber);
+// ManualRequest manualRequest = new ManualRequest(manualCount, manualNumbers);
+//
+// //when
+//
+//
+// //then
+//
+// }
+
+
+
} | Java | ์ฌ์ฉํ์ง ์๋ ์ฃผ์(์ฝ๋)์ ์ ๊ฑฐํด์ฃผ์ธ์! |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ์๋ก ์ฑ๊ฒฉ์ด ๋ค๋ฅธ ๋ณ์ ์ ์ธ ๊ฐ์๋ ์ค๋ฐ๊ฟ์ ํ ๋ฒ ๋ฃ์ด์ฃผ๋ ๊ฒ ๋ ๋ณด๊ธฐ ์ข์ง ์์๊น์??๐ค |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ์กฐ๊ฑด๋ฌธ์ ์ซ์์ ๋งค๊ฐ๋ณ์๊ฐ ์ผ์นํ๋ค์!
์ด๋ฐ ์์ผ๋ก ์ฝ๋๋ฅผ ์ค์ผ ์ ์์ง ์์๊น์??๐
```suggestion
answer = randomNumber(numberOfDigit[0]);
``` |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | JS์์ ์ ๊ณตํ๋ ํจ์๋ฅผ ์ ํ์ฉํ์
จ๋ค์! ๐ |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ๋งค์ง ๋๋ฒ ๋ถ๋ฆฌ์ ๋ค์ด๋ฐ ์ปจ๋ฒค์
์ ์ค์ํ์
จ๋ค์! ๐ |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ํ๋์ ํจ์๋ ํ ๊ฐ์ง ์ฑ
์๋ง ๊ฐ๋๋ก ํ๋ ๊ฒ ์ข์์!
randomNumber ํจ์์์๋ ์ค๋ณต๋์ง ์๋ ๋์๋ฅผ ๋ฐํํ๋ ๊ฒ์ด ๋ชฉํ์ธ๋ฐ, randomNumber ๋ณ์์ ๋๋ค๊ฐ์ ๋ฃ๋ ํ์๋ ๊ทธ ์ฑ
์๊ณผ๋ ๋ถ๋ฆฌํ ์ ์์ ๊ฒ ๊ฐ์์.
`let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);` ๋ฅผ ๋ค๋ฅธ ํจ์๋ก ๋ถ๋ฆฌํด๋ณด๋ ๊ฑด ์ด๋จ๊น์?? ๐
[์ฐธ๊ณ ์๋ฃ](https://inpa.tistory.com/entry/OOP-%F0%9F%92%A0-%EC%95%84%EC%A3%BC-%EC%89%BD%EA%B2%8C-%EC%9D%B4%ED%95%B4%ED%95%98%EB%8A%94-SRP-%EB%8B%A8%EC%9D%BC-%EC%B1%85%EC%9E%84-%EC%9B%90%EC%B9%99) |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | while๋ฌธ ํธ์ถ ์ด์ ์ randomNumber์ ์ ์๋ฏธํ ๊ฐ์ ๋ฃ๊ธฐ ์ํด์ ๋๋ค๊ฐ์ ์์ฑํ์ฌ ๋ฏธ๋ฆฌ ๋ฃ์ด์ฃผ๊ณ while์ ํธ์ถํ ๊ฒ ๊ฐ๋ค์. ํ์ง๋ง ์ด๋ ๊ฒ ๋๋ฉด randomNumber์ ์ด๊ธฐํ์์ ๋ํด์ ์ฝ๋ ์ค๋ณต์ด ์ผ์ด๋๊ฒ ๋ฉ๋๋ค!
do .. while ๋ฌธ์ ์ฌ์ฉํด์ ์ฝ๋ ์ค๋ณต์ ์์จ ์ ์์ง ์์๊น์?? ๐ |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | newRow๋ HTML ์์์ธ ๊ฒ ๊ฐ์๋ฐ $๋ฅผ ๋ถ์ฌ์ฃผ๋๊ฒ ๋ง์ง ์์๊น์?? ๐ค
์ ๋ ์ด๋ถ๋ถ์ ํ์คํ์ง ์์ผ๋ ์ง์ ๊ณ ๋ฏผํด๋ณด์๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ์์!
[์ฐธ๊ณ ์๋ฃ](https://choseongho93.tistory.com/213) |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ์ด ๋ถ๋ถ๋ค๋ HTML ์์์ธ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ์ฝ๋์ ๊ฐ๊ฒฐํจ์ ์ํด ์ข์ ๋ฐฉ๋ฒ์ด ๋ ์๋ ์์ง๋ง, ํ ํ์์๋ ํ๋์ ๋ณ๊ฒฝ๋ง์ด ์ผ์ด๋์ผ ํ๋ค๋ ๋ง์ ๋ค์ ์ ์ด ์๋ ๊ฒ ๊ฐ์์!
 |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ๊ฒฝ๊ณ ๋ฌธ์ ๋ด์ฉ์ด ๊ฒน์น๋๋ฐ, ๊ฒฝ๊ณ ๋ฌธ์ ํจ์๋ก ๋ถ๋ฆฌํ๊ฑฐ๋ ๊ฒฝ๊ณ ๋ฌธ ๋ด์ฉ์ ๋ฌธ์์ด ๋ฆฌํฐ๋ด๋ก ์ ์ํ๋ ๊ฑด ์ด๋จ๊น์? ๐ |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ๋ณ๊ฒฝํ innerText ๋ด์ฉ์ ๋ณ์๋ฅผ ๊ฐ๋ ๋ฌธ์์ด ๋ฆฌํฐ๋ด๋ก ํํํ ์ ์์ง ์์๊น์?? ๐
[์ฐธ๊ณ ์๋ฃ](https://www.delftstack.com/ko/howto/javascript/javascript-variable-in-string/) |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ```
score[0] -> ball
score[1] -> strike
```
์ธ ๊ฒ ๊ฐ์๋ฐ, ์ด๋ ๊ฒ ๋งค์ง ๋๋ฒ๋ฅผ ํตํด ์์ฑํ๊ฒ ๋๋ฉด ๋ค๋ฅธ ์ฌ๋๋ค์ด ์ฝ๋๋ฅผ ๋ณด์์ ๋ ์ธ๋ฑ์ค ๋ณ ์ญํ ์ ๋ํด ํด์ํ๊ธฐ ํ๋ค ๊ฒ ๊ฐ์์! ์ธ๋ฑ์ค์ธ 0๊ณผ 1์ ๊ฐ๊ฐ ์์๋ก ๋ถ๋ฆฌํด๋ณด๋ ๊ฑด ์ด๋จ๊น์? ๐ |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | 
๊นํ๋ธ์์ `No newline at end of file`๋ผ๋ ์๋ฌ๊ฐ ๋ํ๋๋ค์! ์ด๋ฐ ์๋ฌ๋ ์ ๋ํ๋๋ ๊ฑธ๊น์??
[์ฐธ๊ณ ์๋ฃ](https://velog.io/@jesop/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%EC%BD%94%EB%93%9C-%EB%A7%88%EC%A7%80%EB%A7%89%EC%97%90-%EB%B9%88-%EC%A4%84-%EC%82%BD%EC%9E%85%ED%95%98%EB%8A%94-%EC%9D%B4%EC%9C%A0) |
@@ -0,0 +1,29 @@
+.container{
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ min-height: 100vh;
+}
+
+.btn-group, .input-content, .table-content{
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ margin: 10px;
+}
+
+table{
+ width: 500px;
+ border: 1px solid black;
+}
+
+th, td{
+ border: 1px solid black;
+ text-align: center;
+}
+
+div input{
+ margin-left: 5px;
+ margin-right: 5px;
+}
\ No newline at end of file | Unknown | ์ค ์ด๋ฐ ๋ฐฉ๋ฒ๋ ์๊ตฐ์...!! ๐ฎ |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ๋ต ๊ฐ์ฌํฉ๋๋ค!
๋ฆ๊ฒ ๋ฆฌ๋ทฐ๋ฌ์์ ์ ๋ง ์ฃ์กํฉ๋๋ค... |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ์ํ ์๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ์ฐธ๊ณ ์๋ฃ ์ ์ฝ์ด๋ดค์ต๋๋ค! SRP์ ๋ํด ์ข ๋ ๊ณต๋ถ๊ฐ ํ์ํ ๊ฒ ๊ฐ๋ค์. ์ฐธ๊ณ ์๋ฃ๋ฅผ ์ฝ์ผ๋ฉด์ ์ข ํท๊ฐ๋ ธ๋ ๋ถ๋ถ์ด ์๋๋ฐ "์์ง๋๋ฅผ ๋๊ฒ, ๊ฒฐํฉ๋๋ ๋ฎ๊ฒ" ๋ผ๋ ๋ฌธ์ฅ์์ ์์ง๋์ ๊ฒฐํฉ๋์ ์ฐจ์ด์ ๋ํด ์กฐ๊ธ ํท๊ฐ๋ฆฝ๋๋ค. ์์ง๋๋ ํจ์ ์์ ๊ตฌ์ฑ์์๋ค์ ์ฐ๊ด๋ ์ ๋, ๊ฒฐํฉ๋๋ ์๋ก ๋ค๋ฅธ ํจ์๊ฐ์ ์ฐ๊ด๋ ์ ๋๋ก ํด์ํ๋๋ฐ ์ด๊ฒ ๋ง๋ ํด์์ธ์ง ์๊ณ ์ถ์ต๋๋ค. |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | function getRandomNumber()๋ก ์๋ก์ด ํจ์๋ฅผ ๋ง๋ค์ด์ ์ค๋ณต์ ํผํ๋๋ก ์์ ํ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ์ฃผ๋ก ๋ง์ ์ฌ๋๋ค์ด ์ฌ์ฉํ๋ ํจ์๋ฅผ ์ฌ์ฉํด์ผ ํ๋์ง ์๋๋ฉด ์ ๊ฐ ํ์๋ก ํ๋ ํจ์๋ฅผ ์จ์ผ ํ๋๊ฐ ๊ถ๊ธํฉ๋๋ค!
์๋ฅผ ๋ค์ด existingNumber๋ ๋ฐฐ์ด์ด๊ธฐ ๋๋ฌธ์ includesํจ์๋ฅผ ์ฌ์ฉํด์ randomNumber๊ฐ ํฌํจ๋์ด ์๋์ง ์ฐพ์๋๋ฐ, ๋ง์ฝ ์ด ํจ์๋ฅผ ๋ค๋ฅธ ์ฌ๋๋ค์ด ์์ฃผ ์ฌ์ฉํ์ง ์๋๋ค๋ฉด ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ฐพ์์ ํ๋ก๊ทธ๋๋ฐ ํด์ผ ํ๋์ง ๋ฌป๊ณ ์ถ์ต๋๋ค. |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | do .. while ๋ฌธ์ ์ฌ์ฉํด์ ์ค๋ณต ์์ ๋ณด๊ฒ ์ต๋๋ค!! do .. while ๋ฌธ์ ์๊ฐ ๋ชปํ๋ค์.. |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | $๋ฅผ ๋ถ์ด๋ ๊ฒ์ด ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,96 @@
+const MAX_RANDOM_NUMBER = 9;
+const MIN_RANDOM_NUMBER = 1;
+const $inputNumber = document.querySelector('.input-number');
+const $gameTable = document.querySelector(".game-table");
+
+let answer;
+
+function inputDigit(numberOfDigit){
+ $gameTable.innerHTML = "<tr><td>์์</td><td>์ซ์</td><td>๊ฒฐ๊ณผ</td></tr>";
+ if(numberOfDigit === "3์๋ฆฌ"){
+ answer = randomNumber(3);
+ } else if(numberOfDigit === "4์๋ฆฌ"){
+ answer = randomNumber(4);
+ } else if(numberOfDigit === "5์๋ฆฌ"){
+ answer = randomNumber(5);
+ }
+}
+
+function randomNumber(numberOfDigit){
+ let result = 0;
+ let existingNumbers = [];
+ for (step = 0; step < numberOfDigit; step++) {
+ let randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ while (existingNumbers.includes(randomNumber)){
+ randomNumber = Math.floor(Math.random() * (MAX_RANDOM_NUMBER - MIN_RANDOM_NUMBER) + MIN_RANDOM_NUMBER);
+ }
+ existingNumbers.push(randomNumber);
+ }
+
+ let weight = 1;
+ for(j = 0; j < numberOfDigit; j++){
+ result += existingNumbers[j] * weight;
+ weight *= 10;
+ }
+
+ console.log(result);
+ return result;
+}
+
+let index = 1;
+function addValue(){
+ const newRow = $gameTable.insertRow();
+ const pitchResult = checkBallAndStrike(answer);
+ const convertedAnswer = answer.toString();
+
+ let isValid = 0;
+ if($inputNumber.value.length === convertedAnswer.length){
+ for(let i = 0; i < $inputNumber.value.length; i++){
+ for(let j = 0; j < $inputNumber.value.length; j++){
+ if(i !== j){
+ if($inputNumber.value[i] === $inputNumber.value[j]){
+ isValid = 1;
+ }
+ }
+ }
+ }
+ if(isValid === 0){
+ const turn = newRow.insertCell(0);
+ const number = newRow.insertCell(1);
+ const result = newRow.insertCell(2);
+ turn.innerText = `${index++}`;
+ number.innerText = `${$inputNumber.value}`
+ if(pitchResult[1] === convertedAnswer.length){
+ result.innerText = `O.K.`;
+ } else{
+ result.innerText = `B: ${pitchResult[0]}, S: ${pitchResult[1]}`;
+ }
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+ } else{
+ alert("์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ์
๋๋ค.");
+ }
+
+}
+
+function checkBallAndStrike(answer){
+ const convertedAnswer = answer.toString();
+ const convertedInputNumber = $inputNumber.value.toString();
+ let k = 0;
+ let score = [0, 0];
+ while(k < convertedAnswer.length){
+ if(convertedAnswer[k] === convertedInputNumber[k]){
+ score[1] += 1;
+ } else{
+ for(let item of convertedAnswer){
+ if(item === convertedInputNumber[k]){
+ score[0] += 1;
+ }
+ }
+ }
+ k += 1;
+ }
+ return score;
+}
\ No newline at end of file | JavaScript | ๊ทธ๋ฌ๋ฉด index๊ฐ์ turn์ ๋ฃ๋ ๊ฒ, index๊ฐ 1์ฉ ์ฆ๊ฐ ํ๋ ๊ฒ ๋ ๊ฐ๋ฅผ ๋๋๋๋ก ์์ ํ๊ฒ ์ต๋๋ค! |
@@ -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 ์ด๋
ธํ
์ด์
์ ์ฌ์ฉํด์ ํํํ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์..!! |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ๋ณ์ ์ ์ธํ ๋๋ `scope` ๊ด๋ฆฌ๋ฅผ ์ํด์ ํญ์ `const`, `let` ๋ฑ์ ํค์๋๋ฅผ ์ฌ์ฉํด์ฃผ๋๊ฒ ์ข์ต๋๋ค! |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์ฌ๊ธฐ๋ ์์ ๋ง์ฐฌ๊ฐ์ง๋ก ๋ณ์ ์ ์ธ ์์ ์ ์ ํ ํค์๋๊ฐ ํ์ํ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ๋ฐ๋ณต๋ฌธ ์์ `validType` ์ ์ฌํ ๋นํ ํ์๋ ์์ด ๋ณด์
๋๋ค. ๊ทธ๋ฌ๋ฉด `const` ๊ฐ ๋ ์ ์ ํ์ง ์์๊น์? |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์ ์ฒด์ ์ผ๋ก String.prototype.match ๋ฅผ ๋ง์ด ์ฌ์ฉํ์
จ๋๋ฐ, Regex ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํด ๋ณด๋ ๊ฒ์ ์ด๋ฏ๊น์? |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | `req.body` ์ ๋ค์ ํค๊ฐ๋ค ์ค ํ๋๊ฐ ์์ ๋๋ฝ๋ ๊ฒฝ์ฐ, ๋ฐํ์์์ ์๋ฌ๊ฐ ๋ฐ์ํ ๊ฒ ๊ฐ์ต๋๋ค. ๊ตฌ์กฐํ ํ ๋น ์์ ์ ์ฒด์ ์ผ๋ก ์ฃผ์ํ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์ฌ๊ธฐ ๋ฐ๋ณต๋ฌธ ๋ด์ `info` ๋ ์ฌํ ๋นํ ์ผ์ ์์ด๋ณด์ด๋ `const` ๊ฐ ๋ ์ ์ ํด ๋ณด์
๋๋ค. |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์๋ฌ๋ฅผ ๋์ง๋ ๋ถ๋ถ์ ๋ชจ๋ํํ๊ฒ ๋๋ฉด ๋ ๋์ ์ฌ์ฉ์ฑ์ ๊ฐ๊ฒ ๋ ๊ฒ ๊ฐ์ต๋๋ค
๊ทธ๋ฆฌ๊ณ ์ง์ ์๋ฌ๋ฅผ ๋ฐํํ๋ ๊ฒ๋ณด๋ค ์๋ฌ๋ฅผ `throw` ํ๊ณ , `catch` ๊ตฌ๋ฌธ์์ ๋ค์ ๋ฏธ๋ค์จ์ด๋ก ๊ฑด๋ด๋ฉด์ ์ต์ข
์ ์ผ๋ก ์๋ฌ๋ฅผ ํจ๋ค๋งํ๋ ํจ์์์ ํ๋ฒ์ ์๋ฌ๋ฅผ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ๋ ์ข์ ๋ณด์
๋๋ค. |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์ ์ฒด์ ์ผ๋ก ํ๋์ ์ปจํธ๋กค๋ฌ ์์ ์ฌ๋ฌ ๊ฐ์ ์ ์ฐจ๋ค์ด ๋์ด๋์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
ํจ์ ๋จ์๋ก ๋ ์ชผ๊ฒ๊ฒ๋๋ฉด, ๋์ค์ unit test ์์๋ ๋ ํธ๋ฆฌํ ๊ฒ ๊ฐ์ต๋๋ค.
๊ฒ์ฆํ๊ณ ์๋ ์ฌ๋ฌ ๋ก์ง๋ค๋, ์ ์ ํ Service ์์ ๋ฃ์ด๋ ํ์๋ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
์๋ฅผ ๋ค์ด, ๋น๋ฐ๋ฒํธ๋ฅผ hash ํ๋ ๋ถ๋ถ๋ req, res ๋ง ๋ค๋ฃจ๊ฒ ๋๋ ์ปจํธ๋กค๋ฌ์์ ๋ค๋ฃจ๋ ๊ฒ์ด ์กฐ๊ธ ์ด์ํด ๋ณด์ด๊ธฐ๋ ํฉ๋๋ค.
์ ๋ฐ์ ์ผ๋ก ์ด ๊ฐ ํจ์๊ฐ ํ๋์ ๋ช
ํํ ์ผ๋ง ํ๋๋ก ๊ตฌ์ฑํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์๋ต ๊ฐ๋ ํด๋ผ์ด์ธํธ์์ ํ์ฝ์ ๋ฐ๋ผ ์ ํด์ง ํผ์ ํญ์ ๋ฐํํ ์ ์๋๋ก ๋ชจ๋ํํด์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ์ง/๋ณด์์ ๋ ์ฉ์ดํ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,13 @@
+const express = require('express');
+const router = express.Router();
+const middleware = require('../middlewares');
+const { userController } = require('../controllers');
+// Route ๋ ์ค์ง Controller ์๋ง ์์กด ํฉ๋๋ค.
+
+router.post(
+ '/signup',
+ [middleware.validateSignUpUserData, middleware.hashPassword],
+ userController.signUp,
+);
+
+module.exports = router; | JavaScript | ์ด ๋ถ๋ถ ์ ์์ ์ผ๋ก ์๋ํ๋์? ํค๊ฐ์ด ๋ค๋ฅธ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,48 @@
+const bcrypt = require('bcrypt');
+const { userDao } = require('../dao');
+
+const validateEmail = (email) => {
+ const validEmailRegExp = /\w@\w+\.\w/i;
+ return validEmailRegExp.test(email);
+};
+
+const validatePw = (pw) => {
+ const pwValidation = {
+ regexUppercase: /[A-Z]/g,
+ regexLowercase: /[a-z]/g,
+ regexSpecialCharacter: /[!|@|#|$|%|^|&|*]/g,
+ regexDigit: /[0-9]/g,
+ };
+ const MIN_PW_LENGTH = 8;
+ const pwLength = pw.length;
+
+ if (pwLength < MIN_PW_LENGTH) return false;
+
+ for (const validType in pwValidation) {
+ if (!pwValidation[validType].test(pw)) {
+ return false;
+ }
+ }
+
+ return true;
+};
+
+const hashPassword = async (password) => {
+ return await bcrypt.hash(password, 10);
+};
+
+const findUser = async (fields) => {
+ return await userDao.findUser(fields);
+};
+
+const createUser = async (userData) => {
+ return await userDao.createUser(userData);
+};
+
+module.exports = {
+ validateEmail,
+ validatePw,
+ hashPassword,
+ findUser,
+ createUser,
+}; | JavaScript | ์ด๋ฐ ํจ์๋ ์์ ๋ชจ๋ํํด์ ๋ค๋ฅธ ๊ณณ์์๋ ๋ฒ์ฉ์ ์ผ๋ก ์ฌ์ฉํด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์ด ๋ถ๋ถ ์๋ ์ ํ๋์? ํค ๊ฐ์ด ์ ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์์ ํ์ต๋๋ค! validation ๋ก์ง์ ์์ ์ ์ฝ๋ ๊ธ์ด์ค๋ค๊ฐ ๋์น๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ํ๋ก ํธ๋จ์์ ๋ฐ์ `req.body`์ ์ ํค๊ฐ๋ค์ด ๋๋ฝ๋ ๊ฒฝ์ฐ ๊ทธ ๊ฐ์ด undefined๋ก ๋๋ ๊ฒ ๊ฐ์๋ฐ,
์ ๊ฐ ๋์น๊ณ ์๋ ๋ถ๋ถ์ด ์์๊น์? |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | `RegExp.prototype.test()`๋ก ์์ ํ์ต๋๋ค! |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์์์ผ์ ๋ง์ํด์ฃผ์ ๋๋ก `return res` ํํ๊ฐ ์๋๋ผ ์๋ฌ ํธ๋ค๋ง์ ๋ชจ๋ํ ํด๋ณด๊ฒ ์ต๋๋ค :) |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ๊ฐ์ฌํฉ๋๋ค!!!!!! |
@@ -0,0 +1,40 @@
+// Controller๋ ์ค์ง Service ๋ ์ด์ด์๋ง ์์กดํฉ๋๋ค.
+const { userService } = require('../services');
+const { errorGenerator } = require('../erros');
+
+const signUp = async (req, res, next) => {
+ try {
+ const {
+ email,
+ hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ } = req.body;
+
+ /*
+ middleware์์ email, hashedPassword, phoneNumber์
+ ์กด์ฌ์ ๋ํ ์๋ฌ ์ฒ๋ฆฌ ํ๋๋ฐ,
+ ์ฌ๊ธฐ์๋ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ ๊น์?
+ */
+
+ const createdUser = await userService.createUser({
+ email,
+ password: hashedPassword,
+ phoneNumber,
+ profileImageUrl,
+ introduction,
+ });
+
+ res.status(201).json({
+ message: 'user created',
+ userId: createdUser.id,
+ });
+ } catch (err) {
+ next(err);
+ }
+};
+
+module.exports = {
+ signUp,
+}; | JavaScript | ์๋ฌ ํธ๋ค๋ง๋ฟ๋ง ์๋๋ผ ์๋ต๋ ๋ชจ๋ํ ํด๋ณด๊ฒ ์ต๋๋ค :) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.