code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -19,41 +19,56 @@ export default class Repo { }) { this.id = id; this.name = name; - this.full_name = full_name; + this.fullName = full_name; this.owner = owner; - this.html_url = html_url; + this.htmlUrl = html_url; this.description = description; - this.stargazers_count = stargazers_count; - this.watchers_count = watchers_count; - this.forks_count = forks_count; + this.stargazersCount = stargazers_count; + this.watchersCount = watchers_count; + this.forksCount = forks_count; this.forks = forks; - this.created_at = created_at; - this.updated_at = updated_at; - this.clone_url = clone_url; + this.createdAt = created_at; + this.updatedAt = updated_at; + this.cloneUrl = clone_url; this.language = language; this.watchers = watchers; this.visibility = visibility; } render() { return ` - <div class="col-12 col-sm-6 mb-4" id="repo-${this.id}"> + <div class="col-12 col-sm-6 mb-4 px-2" id="repo-${this.id}"> <div class="card border-secondary h-100" > - <div class="card-body"> - <div class="d-flex align-items-center flex-wrap"> - <h5 class="mb-2 mr-2"> - ${this.name} - </h5> - <span class="mb-2 badge bg-light"> + <div class="card-body d-flex flex-column justify-content-between"> + <div class="d-flex align-items-center flex-wrap" > + <a class="text-info d-flex align-items-center flex-wrap mb-2 mr-2" href="${ + this.htmlUrl + }" target="_blank"> + <h5> + ${this.name} + </h5> + </a> + <span class="mb-2 badge bg-light mr-2"> ${this.visibility} </span> + <span class="mb-2 d-flex align-items-center"> + <img alt="๋ ˆํฌ์ง€ํ† ๋ฆฌ ์Šคํƒ€ ์•„์ด์ฝ˜" src="${ + this.stargazersCount > 0 ? "star_filled.svg" : "star.svg" + }" height="16"/> + ${this.stargazersCount} + </span> </div> <p class="card-text">${this.description ?? ""}</p> <div> - <span class="text-secondary"> + <span class="text-secondary mr-2"> ${this.language ?? ""} </span> + <span class="text-secondary mr-2"> + <img src="fork.svg" alt="ํฌํฌ ์•„์ด์ฝ˜" height="18"/> + ${this.forks} + </span> <span class="text-secondary"> - ${this.forks > 0 ? this.forks : ""} + <img src="watch.svg" alt="์›Œ์น˜ ์•„์ด์ฝ˜" height="18"/> + ${this.watchersCount} </span> </div> </div>
JavaScript
๊ทธ ๋ถ€๋ถ„์€ ์‹ ๊ฒฝ์“ฐ์ง€ ๋ชปํ–ˆ๋„ค์š”! ํ•œ๊ตญ ์„œ๋น„์Šค์—์„œ๋Š” alt๋„ ํ•œ๊ธ€๋กœ ์ ์–ด์ฃผ๋Š”๊ฒŒ ๋” ๋‚˜์„๊นŒ์š”?
@@ -1,83 +1,112 @@ import GithubApiController from "@controllers/githubController"; import User from "@models/User"; +import { + NO_SEARCH_RESULT_TEMPLATE, + SEARCH_LOADING_TEMPLATE, + getReposTemplate, + NO_REPOS_TEMPLATE, +} from "@templates/search"; +import { SPINNER_TEMPLATE } from "@templates/spinner"; +import { NUMBER_OF_REPOS } from "@constants/search"; const searchResultContainer = document.body.querySelector(".search-result"); export default class SearchController { - constructor(inputEl, submitEl) { + constructor(inputEl, submitEl, historyController) { this.inputEl = inputEl; this.submitEl = submitEl; this.fetcher = new GithubApiController(); + this.historyController = historyController; this.init(); } init() { this.inputEl.addEventListener("keypress", (event) => { - if (event.code === 'Enter') { + if (event.code === "Enter") { this.search(this.inputEl.value); } }); this.submitEl.addEventListener("click", () => { this.search(this.inputEl.value); }); + + this.historyController.historyContainer.addEventListener( + "click", + (event) => { + if ( + event.target.classList.contains("list-group-item") && + !event.target.classList.contains("button__delete") + ) { + const [searchValue] = event.target.textContent.trim().split("\n"); + this.search(searchValue); + } + } + ); } async search(searchValue) { const renderUser = (user) => { const userResult = searchResultContainer.querySelector("#user-result"); userResult.id = user.id; - userResult.innerHTML = user.render(); + user.render(userResult); }; - - const renderRepos = (repos) => { + const renderNoUserInfo = () => { + const userResult = searchResultContainer.querySelector("#user-result"); + userResult.innerHTML = NO_SEARCH_RESULT_TEMPLATE; + }; + const createRepoResultContainerEl = () => { const repoResult = document.createElement("div"); - repoResult.id = "#repos-result"; + repoResult.id = "repo-result"; repoResult.className = "bs-component"; + return repoResult; + }; + const renderRepos = (repos, numberOfRepos) => { + const repoResult = createRepoResultContainerEl(); + repoResult.innerHTML = getReposTemplate(repos, numberOfRepos); - repoResult.innerHTML = ` - <div class="container"> - <div class="row"> - ${repos - .slice(0, 5) - .map((repo) => repo.render()) - .join("\n")} - </div> - </div> - `; searchResultContainer.appendChild(repoResult); }; + const renderNoRepos = () => { + const repoResult = createRepoResultContainerEl(); + repoResult.innerHTML = NO_REPOS_TEMPLATE; + + searchResultContainer.appendChild(repoResult); + }; + const createLoadingElement = () => { + const element = document.createElement("div"); + element.className = "card-body d-flex align-items-center"; + element.innerHTML = SPINNER_TEMPLATE; + return element; + }; const trimmedValue = searchValue.trim(); if (!trimmedValue) { alert("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”"); return; } - - searchResultContainer.innerHTML = ` - <div class="card my-3"> - <h4 class="card-header">๊ฒ€์ƒ‰๊ฒฐ๊ณผ</h4> - <div id="user-result" class="card-body d-flex align-items-center"> - <p class="text-center container-fluid"> - ๊ฒ€์ƒ‰์ค‘ - </p> - </div> - </div> - `; + this.historyController.addHistory(trimmedValue); + searchResultContainer.innerHTML = SEARCH_LOADING_TEMPLATE; const userInfo = await this.fetcher.getUser(trimmedValue); if (!userInfo) { - const userResult = searchResultContainer.querySelector("#user-result"); - userResult.innerHTML = ` - <p class="text-center container-fluid"> - ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. - </p> - `; + renderNoUserInfo(); return; } const user = new User(userInfo); renderUser(user); - user.setRepos(await this.fetcher.getRepos(user)); - renderRepos(user.repos); + const loadingEl = createLoadingElement(); + + searchResultContainer.appendChild(loadingEl); + const repos = await this.fetcher.getRepos(user); + searchResultContainer.removeChild(loadingEl); + + if (repos.length === 0) { + renderNoRepos(); + return; + } + + user.setRepos(repos); + renderRepos(user.repos, NUMBER_OF_REPOS); } }
JavaScript
๊ธฐ์กด vs ์ƒˆ๋กœ ์ƒ์„ฑ์€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ๋‹ˆ๊นŒ create๊ฐ€ ๋” ๋ช…ํ™•ํ•˜๊ฒ ๋„ค์š” :)
@@ -0,0 +1,65 @@ +import History from "@models/History"; +import { + getHistoryItemTemplate, + NO_HISTORY_TEMPLATE, +} from "@templates/history"; + +export default class HistoryController { + constructor(historyContainer) { + this.historyContainer = historyContainer; + this.numberOfHistory = 0; + this._init(); + } + _init() { + this._initEvent(); + this._initHistory(); + } + _initEvent() { + this.historyContainer.addEventListener("click", (event) => { + if (event.target.classList.contains("button__delete")) { + const toDeleteEl = event.target.parentElement; + this.deleteHistory(toDeleteEl); + } + }); + } + _initHistory() { + const history = History.getAll(); + this.numberOfHistory = history.length; + + if (this.numberOfHistory === 0) { + this.historyContainer.innerHTML = NO_HISTORY_TEMPLATE; + return; + } + + const historyTemplates = history + .map(({ value, id }) => getHistoryItemTemplate(value, id)) + .join(""); + this.historyContainer.innerHTML = historyTemplates; + } + addHistory(searchValue) { + const historyId = History.add(searchValue); + if (!historyId) { + return; + } + + const listItemEl = getHistoryItemTemplate(searchValue, historyId); + + this.numberOfHistory++; + if (this.numberOfHistory === 1) { + this.historyContainer.innerHTML = listItemEl; + return; + } + + this.historyContainer.insertAdjacentHTML("beforeend", listItemEl); + } + deleteHistory(historyEl) { + const id = historyEl.id; + this.historyContainer.removeChild(historyEl); + History.delete(id); + this.numberOfHistory--; + + if (this.numberOfHistory === 0) { + this.historyContainer.innerHTML = NO_HISTORY_TEMPLATE; + } + } +}
JavaScript
๊ฐ„๊ฒฐํ•œ ๋ฒ„์ „๋„ ๊ดœ์ฐฎ๊ตฐ์š” ใ…Žใ…Ž
@@ -1,11 +1,13 @@ import Repo from "@models/Repo"; +import { getDateDiff } from "@utils/dateUtils"; export default class User { constructor({ id, avatar_url, created_at, email, + bio, followers, following, login, @@ -22,57 +24,114 @@ export default class User { this.id = id; this.avartar = avatar_url; this.name = name; + this.bio = bio; this.followers = followers; this.following = following; this.loginId = login; this.email = email; - this.public_repos = public_repos; - this.public_gists = public_gists; - this.created_at = created_at; - this.html_url = html_url; + this.publicRepos = public_repos; + this.publicGists = public_gists; + this.createdAt = created_at; + this.htmlUrl = html_url; this.organizations_url = organizations_url; - this.starred_url = starred_url; + this.starredUrl = starred_url; this.subscriptions_url = subscriptions_url; - this.repos_url = repos_url; - this.updated_at = updated_at; + this.reposUrl = repos_url; + this.updatedAt = updated_at; this.repos = []; } - render() { + _getCreatedDateInfo() { + const today = new Date(); + const createdDate = new Date(this.createdAt); + const monthDiff = getDateDiff(today, createdDate, "month"); + + if (monthDiff === 0) { + const dayDiff = getDateDiff(today, createdDate, "day"); + return `${dayDiff}์ผ ์ „`; + } + + const year = Math.floor(monthDiff / 12); + const month = monthDiff % 12; + if (year === 0) { + return `${month}๊ฐœ์›” ์ „`; + } + if (month === 0) { + return `${year}๋…„ ์ „`; + } + + return `${year}๋…„ ${month}๊ฐœ์›” ์ „`; + } + setEvent() { + const activityChart = document.body.querySelector("#activity-chart"); + activityChart.onerror = (event) => { + event.target.style.setProperty("display", "none"); + event.target.parentElement.insertAdjacentHTML( + "beforeend", + '<div class="activity-error ml-4">No Activity Chart</div>' + ); + }; + } + template() { return ` - <div> - <img - src="${this.avartar}" - alt="${this.name} ํ”„๋กœํ•„์‚ฌ์ง„" - width="90" - class="mr-3 rounded-circle" - /> + <div class="w-100 flex-lg-row flex-column d-flex align-items-center justify-content-center"> + <div class="d-flex align-items-center justify-content-center"> + <img + src="${this.avartar}" + alt="${this.name} ํ”„๋กœํ•„์‚ฌ์ง„" + width="200" + class="mr-xl-3 mb-3 mb-xl-0 rounded-circle" + /> + </div> + <div class="w-100 d-flex flex-column align-items-lg-start align-items-center"> + <div class="px-4 text-lg-left text-center"> + <a class="text-primary" href="${this.htmlUrl}" target="_blank"> + <h5 class="card-title">${this.loginId} </h5> + </a> + <div class="d-flex align-items-end"> + <h6 class="card-subtitle m-0">${this.name ?? ""}</h6> + <span class="card-text text-muted ml-2 font-size-xs">${this._getCreatedDateInfo()}</span> </div> - <div> - <h5 class="card-title">${this.name} </h5> - <h6 class="card-subtitle text-muted">${this.loginId}</h6> - <div class="card-body p-0 mt-2"> - <a - href="https://github.com/dmstmdrbs?tab=followers" - target="_blank" - class="card-link badge bg-success text-white" - >Followers ${this.followers}๋ช…</a - > - <a - href="https://github.com/dmstmdrbs?tab=following" - target="_blank" - class="card-link badge bg-success text-white ml-2" - >Following ${this.following}๋ช…</a - > - <a - href="https://github.com/dmstmdrbs?tab=repositories" - target="_blank" - class="card-link badge bg-info text-white ml-2" - >Repos ${this.public_repos}๊ฐœ</a - > - <span class="badge bg-secondary text-white ml-2">Gists ${this.public_gists}๊ฐœ</span> - </div> - </div> - `; + <p class="m-0 mt-2">${this.bio ?? ""}</p> + </div> + <div class="card-body py-1 ml-1 mb-2"> + <a + href="https://github.com/${this.loginId}?tab=followers" + target="_blank" + class="card-link badge bg-success text-white" + >Followers ${this.followers}๋ช…</a + > + <a + href="https://github.com/${this.loginId}?tab=following" + target="_blank" + class="card-link badge bg-success text-white ml-2" + >Following ${this.following}๋ช…</a + > + <a + href="https://github.com/${this.loginId}?tab=repositories" + target="_blank" + class="card-link badge bg-info text-white ml-2" + >Repos ${this.publicRepos}๊ฐœ + </a> + <span class="badge bg-secondary text-white ml-2"> + Gists ${this.publicGists}๊ฐœ + </span> + </div> + <div class="w-100"> + <img + id="activity-chart" + class="w-100" + style="max-width: 663px;" + src="https://ghchart.rshah.org/${this.loginId}" + alt="๊นƒํ—ˆ๋ธŒ ํ™œ๋™ ์ฐจํŠธ" + /> + </div> + </div> + </div> + `; + } + render(container) { + container.innerHTML = this.template(); + this.setEvent(); } setRepos(repos) { this.repos = repos
JavaScript
๊ฐ์ฒด ํ”„๋กœํผํ‹ฐ๋ฅผ ๋ณต์‚ฌํ•ด์˜ค๋Š” ๊ณผ์ •์—์„œ ๋‹ค๋ฅธ ๋ถ€๋ถ„์€ ์‹ ๊ฒฝ์„ ์“ฐ์ง€ ๋ชปํ–ˆ๋„ค์š”...! ํ†ต์ผ ์‹œ์ผœ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -19,41 +19,56 @@ export default class Repo { }) { this.id = id; this.name = name; - this.full_name = full_name; + this.fullName = full_name; this.owner = owner; - this.html_url = html_url; + this.htmlUrl = html_url; this.description = description; - this.stargazers_count = stargazers_count; - this.watchers_count = watchers_count; - this.forks_count = forks_count; + this.stargazersCount = stargazers_count; + this.watchersCount = watchers_count; + this.forksCount = forks_count; this.forks = forks; - this.created_at = created_at; - this.updated_at = updated_at; - this.clone_url = clone_url; + this.createdAt = created_at; + this.updatedAt = updated_at; + this.cloneUrl = clone_url; this.language = language; this.watchers = watchers; this.visibility = visibility; } render() { return ` - <div class="col-12 col-sm-6 mb-4" id="repo-${this.id}"> + <div class="col-12 col-sm-6 mb-4 px-2" id="repo-${this.id}"> <div class="card border-secondary h-100" > - <div class="card-body"> - <div class="d-flex align-items-center flex-wrap"> - <h5 class="mb-2 mr-2"> - ${this.name} - </h5> - <span class="mb-2 badge bg-light"> + <div class="card-body d-flex flex-column justify-content-between"> + <div class="d-flex align-items-center flex-wrap" > + <a class="text-info d-flex align-items-center flex-wrap mb-2 mr-2" href="${ + this.htmlUrl + }" target="_blank"> + <h5> + ${this.name} + </h5> + </a> + <span class="mb-2 badge bg-light mr-2"> ${this.visibility} </span> + <span class="mb-2 d-flex align-items-center"> + <img alt="๋ ˆํฌ์ง€ํ† ๋ฆฌ ์Šคํƒ€ ์•„์ด์ฝ˜" src="${ + this.stargazersCount > 0 ? "star_filled.svg" : "star.svg" + }" height="16"/> + ${this.stargazersCount} + </span> </div> <p class="card-text">${this.description ?? ""}</p> <div> - <span class="text-secondary"> + <span class="text-secondary mr-2"> ${this.language ?? ""} </span> + <span class="text-secondary mr-2"> + <img src="fork.svg" alt="ํฌํฌ ์•„์ด์ฝ˜" height="18"/> + ${this.forks} + </span> <span class="text-secondary"> - ${this.forks > 0 ? this.forks : ""} + <img src="watch.svg" alt="์›Œ์น˜ ์•„์ด์ฝ˜" height="18"/> + ${this.watchersCount} </span> </div> </div>
JavaScript
๋„ต~ ์ œ๊ฐ€ ์ง€๊ธˆ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์˜ ๊ฒฝ์šฐ ๋‹ค ํ•œ๊ธ€๋กœ alt ์ ์–ด์ฃผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค!
@@ -19,41 +19,56 @@ export default class Repo { }) { this.id = id; this.name = name; - this.full_name = full_name; + this.fullName = full_name; this.owner = owner; - this.html_url = html_url; + this.htmlUrl = html_url; this.description = description; - this.stargazers_count = stargazers_count; - this.watchers_count = watchers_count; - this.forks_count = forks_count; + this.stargazersCount = stargazers_count; + this.watchersCount = watchers_count; + this.forksCount = forks_count; this.forks = forks; - this.created_at = created_at; - this.updated_at = updated_at; - this.clone_url = clone_url; + this.createdAt = created_at; + this.updatedAt = updated_at; + this.cloneUrl = clone_url; this.language = language; this.watchers = watchers; this.visibility = visibility; } render() { return ` - <div class="col-12 col-sm-6 mb-4" id="repo-${this.id}"> + <div class="col-12 col-sm-6 mb-4 px-2" id="repo-${this.id}"> <div class="card border-secondary h-100" > - <div class="card-body"> - <div class="d-flex align-items-center flex-wrap"> - <h5 class="mb-2 mr-2"> - ${this.name} - </h5> - <span class="mb-2 badge bg-light"> + <div class="card-body d-flex flex-column justify-content-between"> + <div class="d-flex align-items-center flex-wrap" > + <a class="text-info d-flex align-items-center flex-wrap mb-2 mr-2" href="${ + this.htmlUrl + }" target="_blank"> + <h5> + ${this.name} + </h5> + </a> + <span class="mb-2 badge bg-light mr-2"> ${this.visibility} </span> + <span class="mb-2 d-flex align-items-center"> + <img alt="๋ ˆํฌ์ง€ํ† ๋ฆฌ ์Šคํƒ€ ์•„์ด์ฝ˜" src="${ + this.stargazersCount > 0 ? "star_filled.svg" : "star.svg" + }" height="16"/> + ${this.stargazersCount} + </span> </div> <p class="card-text">${this.description ?? ""}</p> <div> - <span class="text-secondary"> + <span class="text-secondary mr-2"> ${this.language ?? ""} </span> + <span class="text-secondary mr-2"> + <img src="fork.svg" alt="ํฌํฌ ์•„์ด์ฝ˜" height="18"/> + ${this.forks} + </span> <span class="text-secondary"> - ${this.forks > 0 ? this.forks : ""} + <img src="watch.svg" alt="์›Œ์น˜ ์•„์ด์ฝ˜" height="18"/> + ${this.watchersCount} </span> </div> </div>
JavaScript
์•„ํ•˜! ์ฐธ๊ณ ํ•ด์„œ ์ง„ํ–‰ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค~
@@ -1,70 +1,10 @@ -# Getting Started with Create React App +# React Westagram 3ํŒ€ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +instagram์„ ๋ชจํ‹ฐ๋ธŒ๋กœ ํ•œ ํด๋ก  ํŒ€ ํ”„๋กœ์ ํŠธ -## Available Scripts +# ํŒ€์› -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in your browser. - -The page will reload when you make changes.\ -You may also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can't go back!** - -If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. - -You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `npm run build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) +- ์ •๋‹ค์ธ +- ๋‹ค๋‚˜ +- ์ด์ง€ํ˜œ +- ํ•œ์ง€์„ 
Unknown
๐Ÿ‘ README.md ํŒŒ์ผ ์ˆ˜์ •ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ^^
@@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import "./Login.scss"; + +const Login = () => { + const navigate = useNavigate(); + const [showErrorMessage, setShowErrorMessage] = useState(false); + + const [userInfo, setUserInfo] = useState({ + userId: "", + userPw: "", + }); + + const isActive = userInfo.userPw.length >= 5 && userInfo.userId.includes("@"); + + useEffect(() => {}, [userInfo, showErrorMessage]); + + const handleInput = (event) => { + const { value, id } = event.target; + setUserInfo({ ...userInfo, [id]: value }); + }; + + const goToMain = () => { + if (isActive) { + navigate("/jisun-main"); + } else { + setShowErrorMessage(true); + } + }; + + return ( + <div className="login"> + <div className="box"> + <h1>Westagram</h1> + <input + type="text" + id="userId" + onChange={handleInput} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input type="password" id="userPw" onChange={handleInput} placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" /> + <button + className="btnLogin" + onClick={goToMain} + style={{ backgroundColor: isActive ? "#2d94ef" : "#67b5fa" }} + > + ๋กœ๊ทธ์ธ + </button> + <span>๋˜๋Š”</span> + <button className="btnFacebook">Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</button> + {showErrorMessage && <p className="err">์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•˜์„ธ์š”.</p>} + <button className="findPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + <div className="box"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? <a href="/signup">๊ฐ€์ž…ํ•˜๊ธฐ</a> + </div> + </div> + ); +}; + +export default Login;
Unknown
๋” ์ด์ƒ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ถˆํ•„์š”ํ•œ ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ฃผ์„์€ ๊ผญ ์‚ญ์ œํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import "./Login.scss"; + +const Login = () => { + const navigate = useNavigate(); + const [showErrorMessage, setShowErrorMessage] = useState(false); + + const [userInfo, setUserInfo] = useState({ + userId: "", + userPw: "", + }); + + const isActive = userInfo.userPw.length >= 5 && userInfo.userId.includes("@"); + + useEffect(() => {}, [userInfo, showErrorMessage]); + + const handleInput = (event) => { + const { value, id } = event.target; + setUserInfo({ ...userInfo, [id]: value }); + }; + + const goToMain = () => { + if (isActive) { + navigate("/jisun-main"); + } else { + setShowErrorMessage(true); + } + }; + + return ( + <div className="login"> + <div className="box"> + <h1>Westagram</h1> + <input + type="text" + id="userId" + onChange={handleInput} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input type="password" id="userPw" onChange={handleInput} placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" /> + <button + className="btnLogin" + onClick={goToMain} + style={{ backgroundColor: isActive ? "#2d94ef" : "#67b5fa" }} + > + ๋กœ๊ทธ์ธ + </button> + <span>๋˜๋Š”</span> + <button className="btnFacebook">Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</button> + {showErrorMessage && <p className="err">์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•˜์„ธ์š”.</p>} + <button className="findPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + <div className="box"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? <a href="/signup">๊ฐ€์ž…ํ•˜๊ธฐ</a> + </div> + </div> + ); +}; + +export default Login;
Unknown
์ฝ˜์†”๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค ํ…Œ์ŠคํŠธ๊ฐ€ ๋๋‚œ ์ฝ”๋“œ๋Š” ํ•ญ์ƒ ์ง€์›Œ์ฃผ์„ธ์š”! ์•„๋ž˜์— ๋‚จ์•„์žˆ๋Š” ๋ชจ๋“  ์ฝ˜์†”์€ ์‚ญ์ œ ํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import "./Login.scss"; + +const Login = () => { + const navigate = useNavigate(); + const [showErrorMessage, setShowErrorMessage] = useState(false); + + const [userInfo, setUserInfo] = useState({ + userId: "", + userPw: "", + }); + + const isActive = userInfo.userPw.length >= 5 && userInfo.userId.includes("@"); + + useEffect(() => {}, [userInfo, showErrorMessage]); + + const handleInput = (event) => { + const { value, id } = event.target; + setUserInfo({ ...userInfo, [id]: value }); + }; + + const goToMain = () => { + if (isActive) { + navigate("/jisun-main"); + } else { + setShowErrorMessage(true); + } + }; + + return ( + <div className="login"> + <div className="box"> + <h1>Westagram</h1> + <input + type="text" + id="userId" + onChange={handleInput} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input type="password" id="userPw" onChange={handleInput} placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" /> + <button + className="btnLogin" + onClick={goToMain} + style={{ backgroundColor: isActive ? "#2d94ef" : "#67b5fa" }} + > + ๋กœ๊ทธ์ธ + </button> + <span>๋˜๋Š”</span> + <button className="btnFacebook">Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</button> + {showErrorMessage && <p className="err">์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•˜์„ธ์š”.</p>} + <button className="findPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + <div className="box"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? <a href="/signup">๊ฐ€์ž…ํ•˜๊ธฐ</a> + </div> + </div> + ); +}; + +export default Login;
Unknown
๐Ÿ‘ useEffect ๊นŒ์ง€ ํ™œ์šฉํ•ด๋ณด์…จ๊ตฐ์š”! condition ๋ณ€์ˆ˜๊ฐ€ userInfo๋ผ๋Š” state๋ฅผ ์ด๋ฏธ ์ฐธ์กฐํ•œ ๊ฐ’์ด๊ธฐ๋•Œ๋ฌธ์— isActive๋ผ๋Š” ๊ฐ’์„ ๋”ฐ๋กœ state๋กœ ๊ด€๋ฆฌํ•˜์ง€์•Š์•„๋„ condition ๋ณ€์ˆ˜๊ฐ€ ์ฐธ์กฐํ•˜๊ณ ์žˆ๋Š” ๊ฐ’์ด ์ด๋ฏธ state๋ผ์„œ state๋ณ€ํ™”์— ๋”ฐ๋ผ ์ฆ‰๊ฐ์ ์œผ๋กœ ๋‹ค๋ฅธ ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. isActive๋ฅผ state๊ฐ€ ์•„๋‹Œ ์ผ๋ฐ˜๋ณ€์ˆ˜๋กœ ๊ด€๋ฆฌํ•ด๋ณด์‹œ๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import "./Login.scss"; + +const Login = () => { + const navigate = useNavigate(); + const [showErrorMessage, setShowErrorMessage] = useState(false); + + const [userInfo, setUserInfo] = useState({ + userId: "", + userPw: "", + }); + + const isActive = userInfo.userPw.length >= 5 && userInfo.userId.includes("@"); + + useEffect(() => {}, [userInfo, showErrorMessage]); + + const handleInput = (event) => { + const { value, id } = event.target; + setUserInfo({ ...userInfo, [id]: value }); + }; + + const goToMain = () => { + if (isActive) { + navigate("/jisun-main"); + } else { + setShowErrorMessage(true); + } + }; + + return ( + <div className="login"> + <div className="box"> + <h1>Westagram</h1> + <input + type="text" + id="userId" + onChange={handleInput} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input type="password" id="userPw" onChange={handleInput} placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" /> + <button + className="btnLogin" + onClick={goToMain} + style={{ backgroundColor: isActive ? "#2d94ef" : "#67b5fa" }} + > + ๋กœ๊ทธ์ธ + </button> + <span>๋˜๋Š”</span> + <button className="btnFacebook">Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</button> + {showErrorMessage && <p className="err">์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•˜์„ธ์š”.</p>} + <button className="findPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + <div className="box"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? <a href="/signup">๊ฐ€์ž…ํ•˜๊ธฐ</a> + </div> + </div> + ); +}; + +export default Login;
Unknown
๐Ÿ‘ ์กฐ๊ฑด๋ถ€๋žœ๋”๋ง ํ™œ์šฉํ•ด๋ณด์…จ๊ตฐ์š”!! ์˜คํžˆ๋ ค showErrorMessage๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ useEffectํ•จ์ˆ˜ ๋‚ด์—์„œ ์„ ์–ธํ•œ condition๊ฐ’์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ๊ด€๋ฆฌํ•ด๋ณผ ์ˆ˜ ์žˆ๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,144 @@ +.login { + width: 100%; + height: 100vh; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + + .box { + padding: 25px 40px; + display: flex; + flex-direction: column; + align-items: center; + width: 100%; + max-width: 350px; + box-sizing: border-box; + border: 1px solid #dbdbdb; + + &:first-of-type { + margin-bottom: 12px; + } + + h1 { + margin: 15px 0 40px; + font-family: "Lobster", cursive; + font-weight: 100; + font-size: 42px; + } + + input { + padding: 8px 8px; + width: 100%; + background: #fafafa; + color: #737373; + font-size: 12px; + box-sizing: border-box; + border: 1px solid #dbdbdb; + border-radius: 4px; + + &:first-of-type { + margin-bottom: 7px; + } + + &:last-of-type { + margin-bottom: 14px; + } + } + + span { + margin: 20px 0 30px; + padding: 0 20px; + position: relative; + font-size: 12px; + color: #737373; + + &:before { + content: ""; + position: absolute; + top: 50%; + right: -110px; + width: 110px; + height: 1px; + background: #dbdbdb; + } + + &:after { + content: ""; + position: absolute; + top: 50%; + left: -110px; + width: 110px; + height: 1px; + background: #dbdbdb; + } + } + + .btnLogin { + padding: 10px 0; + width: 100%; + background: #67b5fa; + color: #fff; + font-size: 14px; + font-weight: 500; + border: none; + border-radius: 8px; + + // &:hover { + // background: #2d94ef; + // } + } + + .btnLoginChange { + background: #2d94ef; + } + + .btnFacebook { + padding-left: 24px; + position: relative; + height: 16px; + background: none; + color: #375085; + border: none; + font-size: 14px; + font-weight: 600; + + &:before { + content: ""; + position: absolute; + left: 0; + width: 16px; + height: 16px; + background: url("../../../assets/jisun/Login/icon_facebook.png") no-repeat; + } + } + + .err { + margin: 35px 0 10px; + color: #ed4956; + font-size: 14px; + } + + .findPassword { + margin-top: 25px; + color: #375085; + font-size: 12px; + font-weight: 600; + background: none; + border: none; + } + } + + .box:last-of-type { + flex-direction: row; + justify-content: center; + color: #000; + font-size: 13px; + font-weight: 500; + + &:last-of-type > a { + margin-left: 4px; + color: #0095f6; + } + } +}
Unknown
์›นํฐํŠธ ๊ฐ™์€๊ฒฝ์šฐ๋Š” index.htmlํŒŒ์ผ์—์„œ ์ถ”๊ฐ€ํ•  ์ˆ˜๋„ ์žˆ๊ณ  common.scss์—์„œ ๊ด€๋ฆฌํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,160 @@ +import React from "react"; +import "./Main.scss"; +import { Link, useNavigate } from "react-router-dom"; + +const Main = () => { + const navigate = useNavigate(); + + const goToMain = () => { + navigate("/jisun-main"); + }; + + return ( + <div className="main"> + <nav> + <Link to="/jisun-main" className="goHome"> + <span className="logo"></span> + <p>Westagram</p> + </Link> + <div className="inputWrap"> + <input type="search" placeholder="๊ฒ€์ƒ‰" /> + </div> + <div className="icons"> + <button className="iconCompass"></button> + <button className="iconLike on"></button> + <button className="iconMypage"></button> + </div> + </nav> + <div className="contentsWrap"> + <div className="feeds"> + <article> + <div className="accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> + </a> + <a className="accountName">hanccino</a> + <a className="moreMenu"> + <img alt="๋”๋ณด๊ธฐ ์•„์ด์ฝ˜" src="../../../../images/jisun/icon_more.png" /> + </a> + </div> + <div className="image"> + <img alt="์›ฐ์‹œ์ฝ”๊ธฐ ํ•œ๊ฐ•" src="../../../../images/jisun/img_feed.png" /> + </div> + <div className="text"> + <div className="buttons"> + <span className="like on"></span> + <span className="dm"></span> + <span className="share"></span> + <span className="bookMark"></span> + </div> + <div className="likedStatus"> + <a className="accountPicture"> + <img + alt="์œ„์ฝ”๋“œ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wecode.png" + /> + </a> + <a className="accountName">wecode_life</a>๋‹˜ <a>์™ธ 10๋ช…</a>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </div> + <div className="mention"> + <a className="accountName mr5">hanccino</a> + ์šฐ๋ฆฌ์ง‘ ๊ฐ•์•„์ง€ ์ธ„๋ฅด๋ฅผ ์ข‹์•„ํ•ด... + <span className="viewMore">๋” ๋ณด๊ธฐ</span> + </div> + <div className="currentComments"> + <a className="accountName mr5">wecode_bootcamp</a>์กธ๊ท€ํƒฑ! + </div> + <div className="addComments"> + <textarea aria-label="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..."></textarea> + </div> + </div> + </article> + </div> + <div className="mainRight"> + <div className="myAccount accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="../../../../images/jisun/img_profile.png" /> + </a> + <span> + <a className="accountName">hanccino</a> + Jisun lives with a corgi + </span> + </div> + <div className="recommandList"> + <div> + <strong>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</strong> + <span className="viewAll">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="์œ„์›Œํฌ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wework.jpeg" + /> + </a> + <span> + <a className="accountName">wework</a> + wecode_bootcamp๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋„ทํ”Œ๋ฆญ์Šค ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_netflix.jpeg" + /> + </a> + <span> + <a className="accountName">netflixkr</a> + wecode_premium๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๊ฐฑ๋”์ฝ”๊ธฐ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_corgi.jpeg" + /> + </a> + <span> + <a className="accountName">gang_the_corgi</a> + ํšŒ์›๋‹˜์„ ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋ฐค๋น„ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_bambi.jpeg" + /> + </a> + <span> + <a className="accountName">bambi__jeju</a> + gdragon๋‹˜ ์™ธ 4๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="ํ”ผ์‹๋Œ€ํ•™ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_psickuniv.jpeg" + /> + </a> + <span> + <a className="accountName">psickuniv</a> + dev_gag๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + </div> + </div> + </div> + </div> + ); +}; + +export default Main;
Unknown
reset.scss ํŒŒ์ผ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ „์—ญ์—์„œ ์ ์šฉ๋˜์–ด์•ผ ํ•˜๋Š” ํŒŒ์ผ์ž„์œผ๋กœ index.js์—์„œ importํ•ด ์˜ค๋Š”๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,160 @@ +import React from "react"; +import "./Main.scss"; +import { Link, useNavigate } from "react-router-dom"; + +const Main = () => { + const navigate = useNavigate(); + + const goToMain = () => { + navigate("/jisun-main"); + }; + + return ( + <div className="main"> + <nav> + <Link to="/jisun-main" className="goHome"> + <span className="logo"></span> + <p>Westagram</p> + </Link> + <div className="inputWrap"> + <input type="search" placeholder="๊ฒ€์ƒ‰" /> + </div> + <div className="icons"> + <button className="iconCompass"></button> + <button className="iconLike on"></button> + <button className="iconMypage"></button> + </div> + </nav> + <div className="contentsWrap"> + <div className="feeds"> + <article> + <div className="accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> + </a> + <a className="accountName">hanccino</a> + <a className="moreMenu"> + <img alt="๋”๋ณด๊ธฐ ์•„์ด์ฝ˜" src="../../../../images/jisun/icon_more.png" /> + </a> + </div> + <div className="image"> + <img alt="์›ฐ์‹œ์ฝ”๊ธฐ ํ•œ๊ฐ•" src="../../../../images/jisun/img_feed.png" /> + </div> + <div className="text"> + <div className="buttons"> + <span className="like on"></span> + <span className="dm"></span> + <span className="share"></span> + <span className="bookMark"></span> + </div> + <div className="likedStatus"> + <a className="accountPicture"> + <img + alt="์œ„์ฝ”๋“œ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wecode.png" + /> + </a> + <a className="accountName">wecode_life</a>๋‹˜ <a>์™ธ 10๋ช…</a>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </div> + <div className="mention"> + <a className="accountName mr5">hanccino</a> + ์šฐ๋ฆฌ์ง‘ ๊ฐ•์•„์ง€ ์ธ„๋ฅด๋ฅผ ์ข‹์•„ํ•ด... + <span className="viewMore">๋” ๋ณด๊ธฐ</span> + </div> + <div className="currentComments"> + <a className="accountName mr5">wecode_bootcamp</a>์กธ๊ท€ํƒฑ! + </div> + <div className="addComments"> + <textarea aria-label="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..."></textarea> + </div> + </div> + </article> + </div> + <div className="mainRight"> + <div className="myAccount accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="../../../../images/jisun/img_profile.png" /> + </a> + <span> + <a className="accountName">hanccino</a> + Jisun lives with a corgi + </span> + </div> + <div className="recommandList"> + <div> + <strong>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</strong> + <span className="viewAll">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="์œ„์›Œํฌ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wework.jpeg" + /> + </a> + <span> + <a className="accountName">wework</a> + wecode_bootcamp๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋„ทํ”Œ๋ฆญ์Šค ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_netflix.jpeg" + /> + </a> + <span> + <a className="accountName">netflixkr</a> + wecode_premium๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๊ฐฑ๋”์ฝ”๊ธฐ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_corgi.jpeg" + /> + </a> + <span> + <a className="accountName">gang_the_corgi</a> + ํšŒ์›๋‹˜์„ ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋ฐค๋น„ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_bambi.jpeg" + /> + </a> + <span> + <a className="accountName">bambi__jeju</a> + gdragon๋‹˜ ์™ธ 4๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="ํ”ผ์‹๋Œ€ํ•™ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_psickuniv.jpeg" + /> + </a> + <span> + <a className="accountName">psickuniv</a> + dev_gag๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + </div> + </div> + </div> + </div> + ); +}; + +export default Main;
Unknown
์•„์ด์ฝ˜๋“ค์„ ๋ˆŒ๋ €์„๋•Œ ํŠน์ •ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ด์•ผํ•˜๋Š”๊ฒƒ์ด ์•„๋‹ˆ๋ผ๋ฉด a ํƒœ๊ทธ๋‚˜ Link ํƒœ๊ทธ๊ฐ€ ์•„๋‹Œ ์—ฌํƒ€ ๋‹ค๋ฅธํƒœ๊ทธ๋ฅผ ํ™œ์šฉํ•ด์„œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,160 @@ +import React from "react"; +import "./Main.scss"; +import { Link, useNavigate } from "react-router-dom"; + +const Main = () => { + const navigate = useNavigate(); + + const goToMain = () => { + navigate("/jisun-main"); + }; + + return ( + <div className="main"> + <nav> + <Link to="/jisun-main" className="goHome"> + <span className="logo"></span> + <p>Westagram</p> + </Link> + <div className="inputWrap"> + <input type="search" placeholder="๊ฒ€์ƒ‰" /> + </div> + <div className="icons"> + <button className="iconCompass"></button> + <button className="iconLike on"></button> + <button className="iconMypage"></button> + </div> + </nav> + <div className="contentsWrap"> + <div className="feeds"> + <article> + <div className="accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> + </a> + <a className="accountName">hanccino</a> + <a className="moreMenu"> + <img alt="๋”๋ณด๊ธฐ ์•„์ด์ฝ˜" src="../../../../images/jisun/icon_more.png" /> + </a> + </div> + <div className="image"> + <img alt="์›ฐ์‹œ์ฝ”๊ธฐ ํ•œ๊ฐ•" src="../../../../images/jisun/img_feed.png" /> + </div> + <div className="text"> + <div className="buttons"> + <span className="like on"></span> + <span className="dm"></span> + <span className="share"></span> + <span className="bookMark"></span> + </div> + <div className="likedStatus"> + <a className="accountPicture"> + <img + alt="์œ„์ฝ”๋“œ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wecode.png" + /> + </a> + <a className="accountName">wecode_life</a>๋‹˜ <a>์™ธ 10๋ช…</a>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </div> + <div className="mention"> + <a className="accountName mr5">hanccino</a> + ์šฐ๋ฆฌ์ง‘ ๊ฐ•์•„์ง€ ์ธ„๋ฅด๋ฅผ ์ข‹์•„ํ•ด... + <span className="viewMore">๋” ๋ณด๊ธฐ</span> + </div> + <div className="currentComments"> + <a className="accountName mr5">wecode_bootcamp</a>์กธ๊ท€ํƒฑ! + </div> + <div className="addComments"> + <textarea aria-label="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..."></textarea> + </div> + </div> + </article> + </div> + <div className="mainRight"> + <div className="myAccount accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="../../../../images/jisun/img_profile.png" /> + </a> + <span> + <a className="accountName">hanccino</a> + Jisun lives with a corgi + </span> + </div> + <div className="recommandList"> + <div> + <strong>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</strong> + <span className="viewAll">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="์œ„์›Œํฌ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wework.jpeg" + /> + </a> + <span> + <a className="accountName">wework</a> + wecode_bootcamp๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋„ทํ”Œ๋ฆญ์Šค ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_netflix.jpeg" + /> + </a> + <span> + <a className="accountName">netflixkr</a> + wecode_premium๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๊ฐฑ๋”์ฝ”๊ธฐ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_corgi.jpeg" + /> + </a> + <span> + <a className="accountName">gang_the_corgi</a> + ํšŒ์›๋‹˜์„ ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋ฐค๋น„ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_bambi.jpeg" + /> + </a> + <span> + <a className="accountName">bambi__jeju</a> + gdragon๋‹˜ ์™ธ 4๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="ํ”ผ์‹๋Œ€ํ•™ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_psickuniv.jpeg" + /> + </a> + <span> + <a className="accountName">psickuniv</a> + dev_gag๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + </div> + </div> + </div> + </div> + ); +}; + +export default Main;
Unknown
ํ•ด๋‹น ์ƒ๋Œ€๊ฒฝ๋กœ๊ฐ€ publicํด๋”๋ฅผ ์ฐธ๊ณ ํ•˜๋Š”๊ฑฐ๋ผ๋ฉด ```suggestion <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> ``` ์ด๋ ‡๊ฒŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,160 @@ +import React from "react"; +import "./Main.scss"; +import { Link, useNavigate } from "react-router-dom"; + +const Main = () => { + const navigate = useNavigate(); + + const goToMain = () => { + navigate("/jisun-main"); + }; + + return ( + <div className="main"> + <nav> + <Link to="/jisun-main" className="goHome"> + <span className="logo"></span> + <p>Westagram</p> + </Link> + <div className="inputWrap"> + <input type="search" placeholder="๊ฒ€์ƒ‰" /> + </div> + <div className="icons"> + <button className="iconCompass"></button> + <button className="iconLike on"></button> + <button className="iconMypage"></button> + </div> + </nav> + <div className="contentsWrap"> + <div className="feeds"> + <article> + <div className="accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> + </a> + <a className="accountName">hanccino</a> + <a className="moreMenu"> + <img alt="๋”๋ณด๊ธฐ ์•„์ด์ฝ˜" src="../../../../images/jisun/icon_more.png" /> + </a> + </div> + <div className="image"> + <img alt="์›ฐ์‹œ์ฝ”๊ธฐ ํ•œ๊ฐ•" src="../../../../images/jisun/img_feed.png" /> + </div> + <div className="text"> + <div className="buttons"> + <span className="like on"></span> + <span className="dm"></span> + <span className="share"></span> + <span className="bookMark"></span> + </div> + <div className="likedStatus"> + <a className="accountPicture"> + <img + alt="์œ„์ฝ”๋“œ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wecode.png" + /> + </a> + <a className="accountName">wecode_life</a>๋‹˜ <a>์™ธ 10๋ช…</a>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </div> + <div className="mention"> + <a className="accountName mr5">hanccino</a> + ์šฐ๋ฆฌ์ง‘ ๊ฐ•์•„์ง€ ์ธ„๋ฅด๋ฅผ ์ข‹์•„ํ•ด... + <span className="viewMore">๋” ๋ณด๊ธฐ</span> + </div> + <div className="currentComments"> + <a className="accountName mr5">wecode_bootcamp</a>์กธ๊ท€ํƒฑ! + </div> + <div className="addComments"> + <textarea aria-label="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..."></textarea> + </div> + </div> + </article> + </div> + <div className="mainRight"> + <div className="myAccount accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="../../../../images/jisun/img_profile.png" /> + </a> + <span> + <a className="accountName">hanccino</a> + Jisun lives with a corgi + </span> + </div> + <div className="recommandList"> + <div> + <strong>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</strong> + <span className="viewAll">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="์œ„์›Œํฌ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wework.jpeg" + /> + </a> + <span> + <a className="accountName">wework</a> + wecode_bootcamp๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋„ทํ”Œ๋ฆญ์Šค ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_netflix.jpeg" + /> + </a> + <span> + <a className="accountName">netflixkr</a> + wecode_premium๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๊ฐฑ๋”์ฝ”๊ธฐ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_corgi.jpeg" + /> + </a> + <span> + <a className="accountName">gang_the_corgi</a> + ํšŒ์›๋‹˜์„ ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋ฐค๋น„ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_bambi.jpeg" + /> + </a> + <span> + <a className="accountName">bambi__jeju</a> + gdragon๋‹˜ ์™ธ 4๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="ํ”ผ์‹๋Œ€ํ•™ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_psickuniv.jpeg" + /> + </a> + <span> + <a className="accountName">psickuniv</a> + dev_gag๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + </div> + </div> + </div> + </div> + ); +}; + +export default Main;
Unknown
className์ด ๋„ˆ๋ฌด ๋ชจํ˜ธํ•ฉ๋‹ˆ๋‹ค!! ์–ด๋–ค ์•„์ด์ฝ˜์ธ์ง€ ์•Œ๋ ค์ฃผ์„ธ์š”
@@ -78,6 +78,7 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re List<ReviewPhoto> reviewPhotoList = new ArrayList<>(); List<String> photoUrls = new ArrayList<>(); + if(reviewPhotos == null) return reviewPhotoList; reviewPhotos.forEach(multipartFile -> { try { photoUrls.add(s3Util.upload(multipartFile)); @@ -87,7 +88,6 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re }); photoUrls.forEach(photoUrl -> reviewPhotoList.add(reviewPhotoPort.save(new ReviewPhoto(reviewId, photoUrl)))); - return reviewPhotoList; }
Java
์ด ๋ถ€๋ถ„์€ ์–ด๋–ค ์˜๋ฏธ์ธ๊ฐ€์š”?
@@ -78,6 +78,7 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re List<ReviewPhoto> reviewPhotoList = new ArrayList<>(); List<String> photoUrls = new ArrayList<>(); + if(reviewPhotos == null) return reviewPhotoList; reviewPhotos.forEach(multipartFile -> { try { photoUrls.add(s3Util.upload(multipartFile)); @@ -87,7 +88,6 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re }); photoUrls.forEach(photoUrl -> reviewPhotoList.add(reviewPhotoPort.save(new ReviewPhoto(reviewId, photoUrl)))); - return reviewPhotoList; }
Java
์ด ๋ถ€๋ถ„์€ ์–ด๋–ค ์˜๋ฏธ์ธ๊ฐ€์š”?
@@ -0,0 +1,34 @@ +package com.luckytree.shop.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Type; + +@Component +public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { + + /** + * Converter for support http request with header Content-Type: multipart/form-data + */ + public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) { + super(objectMapper, MediaType.APPLICATION_OCTET_STREAM); + } + + @Override + public boolean canWrite(Class<?> clazz, MediaType mediaType) { + return false; + } + + @Override + public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) { + return false; + } + + @Override + protected boolean canWrite(MediaType mediaType) { + return false; + } +}
Java
์ด ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ณณ์ด ์–ด๋”˜๊ฐ€์š”?
@@ -32,12 +32,11 @@ public class ReviewController { private final ReviewUseCase reviewUseCase; @Operation(summary = "๋ฆฌ๋ทฐ ๋“ฑ๋ก") - @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity<CreateReviewResponse> createReview( - @RequestBody @Valid CreateReviewRequest createReviewRequest, - @RequestPart("reviewPhotos") @Valid List<MultipartFile> reviewPhotos) { + @RequestPart("createReviewRequest") @Valid CreateReviewRequest createReviewRequest, + @RequestPart(value = "reviewPhotos", required = false) @Valid List<MultipartFile> reviewPhotos) { Review review = reviewUseCase.create(createReviewRequest.toDomain(Long.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()))); - List<ReviewPhoto> reviewPhotoList = reviewUseCase.createReviewPhoto(review.getId(), reviewPhotos); return ResponseEntity.ok(new CreateReviewResponse(review, reviewPhotoList));
Java
๋ฆฌํ€˜์ŠคํŠธ๋ฐ”๋””๊ฐ€ ์‚ฌ๋ผ์กŒ๋Š”๋ฐ, ์ด ๊ฒฝ์šฐ์—๋„ ํด๋ผ์ด์–ธํŠธ์—์„œ JSON ํ˜•์‹์˜ Body ํƒœ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ค๋Š” ๋ฐ์— ๋ฌธ์ œ๊ฐ€ ์—†๋‚˜์š”?
@@ -78,6 +78,7 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re List<ReviewPhoto> reviewPhotoList = new ArrayList<>(); List<String> photoUrls = new ArrayList<>(); + if(reviewPhotos == null) return reviewPhotoList; reviewPhotos.forEach(multipartFile -> { try { photoUrls.add(s3Util.upload(multipartFile)); @@ -87,7 +88,6 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re }); photoUrls.forEach(photoUrl -> reviewPhotoList.add(reviewPhotoPort.save(new ReviewPhoto(reviewId, photoUrl)))); - return reviewPhotoList; }
Java
๋ฆฌ๋ทฐ ์ƒ์„ฑ ์‹œ ํฌํ† ๋ฅผ ์„ ํƒํ•˜์ง€ ์•Š์•„๋„ ์ด ์„œ๋น„์Šค๊ฐ€ ์‹คํ–‰๋˜์–ด์„œ ์„ ํƒ๋˜์ง€ ์•Š์•˜์„ ๋•Œ ๋ฐ”๋กœ ๋น ์ ธ๋‚˜๊ฐ€๊ฒŒ ํ•œ๊ฒ๋‹ˆ๋‹ค
@@ -0,0 +1,34 @@ +package com.luckytree.shop.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Type; + +@Component +public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { + + /** + * Converter for support http request with header Content-Type: multipart/form-data + */ + public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) { + super(objectMapper, MediaType.APPLICATION_OCTET_STREAM); + } + + @Override + public boolean canWrite(Class<?> clazz, MediaType mediaType) { + return false; + } + + @Override + public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) { + return false; + } + + @Override + protected boolean canWrite(MediaType mediaType) { + return false; + } +}
Java
swagger์—์„œ ๋ฆฌ๋ทฐ ์ƒ์„ฑ API์— multipartfile์„ ์‚ฌ์šฉํ•ด์„œ ๊ทธ๊ฑฐ ์‚ฌ์šฉํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ๋Š” ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค
@@ -32,12 +32,11 @@ public class ReviewController { private final ReviewUseCase reviewUseCase; @Operation(summary = "๋ฆฌ๋ทฐ ๋“ฑ๋ก") - @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity<CreateReviewResponse> createReview( - @RequestBody @Valid CreateReviewRequest createReviewRequest, - @RequestPart("reviewPhotos") @Valid List<MultipartFile> reviewPhotos) { + @RequestPart("createReviewRequest") @Valid CreateReviewRequest createReviewRequest, + @RequestPart(value = "reviewPhotos", required = false) @Valid List<MultipartFile> reviewPhotos) { Review review = reviewUseCase.create(createReviewRequest.toDomain(Long.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()))); - List<ReviewPhoto> reviewPhotoList = reviewUseCase.createReviewPhoto(review.getId(), reviewPhotos); return ResponseEntity.ok(new CreateReviewResponse(review, reviewPhotoList));
Java
swagger๋ž‘ postman์—์„œ ํ™•์ธํ–ˆ๊ณ  ์˜คํžˆ๋ ค ๋ฆฌํ€˜์ŠคํŠธ๋ฐ”๋””๋ฅผ ์ผ์„ ๋•Œ ์•ˆ๋ผ์„œ ๋ฐ”๊ฟจ์Šต๋‹ˆ๋‹ค. ์ด์œ ๋Š” ์ฐพ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,43 @@ +// +// PopcornOrangeButton.swift +// Popcorn-iOS +// +// Created by ์ œ๋ฏผ์šฐ on 1/12/25. +// + +import UIKit + +final class PopcornOrangeButton: UIButton { + init(text: String, isEnabled: Bool) { + super.init(frame: .zero) + configureInitialSetting(isEnabled: isEnabled) + configureButtonUI(text: text) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +// MARK: - Configure Initial Setting +extension PopcornOrangeButton { + private func configureInitialSetting(isEnabled: Bool) { + self.isEnabled = isEnabled + self.cornerRadius(radius: 10) + } + + private func configureButtonUI(text: String) { + var config = UIButton.Configuration.filled() + config.baseBackgroundColor = isEnabled == true + ? UIColor(resource: .popcornOrange) + : UIColor(resource: .popcornGray2) + config.attributedTitle = AttributedString( + text, + attributes: AttributeContainer([ + .font: UIFont(name: RobotoFontName.robotoSemiBold, size: 15)!, + .foregroundColor: UIColor(.white) + ]) + ) + configuration = config + } +}
Swift
์ €๋„ ์กฐ๋งŒ๊ฐ„ ์ด๊ฑธ๋กœ ๋ฆฌํŒฉํ† ๋งํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!!
@@ -0,0 +1,425 @@ +// +// WriteReviewViewController.swift +// Popcorn-iOS +// +// Created by ์ œ๋ฏผ์šฐ on 1/12/25. +// + +import PhotosUI +import UIKit + +final class WriteReviewViewController: UIViewController { + private let viewModel = WriteReviewViewModel() + + private let popupMainImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(resource: .imagePlaceHolder) + imageView.contentMode = .scaleAspectFill + imageView.clipsToBounds = true + return imageView + }() + + private let popupTitleLabel: UILabel = { + let label = UILabel() + label.popcornSemiBold(text: "ํŒ์—… ์ œ๋ชฉ", size: 15) + label.numberOfLines = 0 + return label + }() + + private let popupPeriodLabel: UILabel = { + let label = UILabel() + label.popcornMedium(text: "00.00.00~00.00.00", size: 10) + return label + }() + + private let userSatisfactionTitleLabel: UILabel = { + let label = UILabel() + label.popcornSemiBold(text: "ํŒ์—…์Šคํ† ์–ด ๋งŒ์กฑ๋„", size: 15) + return label + }() + + private let userStatisfactionRatingView = StarRatingView(starSpacing: 11.63, isUserInteractionEnabled: true) + + private let writeReviewTitleLabel: UILabel = { + let label = UILabel() + label.popcornSemiBold(text: "๋ฆฌ๋ทฐ ์ž‘์„ฑ", size: 15) + return label + }() + + private let reviewConstraintTitleLabel: UILabel = { + let label = UILabel() + label.popcornMedium(text: "0์ž / ์ตœ์†Œ 10์ž", size: 13) + label.textColor = UIColor(resource: .popcornDarkBlueGray) + return label + }() + + private lazy var reviewTextView: UITextView = { + let textView = UITextView() + textView.text = viewModel.reviewTextViewPlaceHolderText + textView.textColor = UIColor(resource: .popcornDarkBlueGray) + textView.font = UIFont(name: RobotoFontName.robotoMedium, size: 15) + textView.textContainerInset = UIEdgeInsets(top: 15, left: 10, bottom: 15, right: 10) + textView.autocapitalizationType = .none + textView.autocorrectionType = .no // ์ž๋™ ์ˆ˜์ • ๋น„ํ™œ์„ฑํ™” + textView.spellCheckingType = .no // ๋งž์ถค๋ฒ• ๊ฒ€์‚ฌ ๋น„ํ™œ์„ฑํ™” + textView.smartQuotesType = .no // ์Šค๋งˆํŠธ ๋”ฐ์˜ดํ‘œ ๋น„ํ™œ์„ฑํ™” + textView.smartDashesType = .no // ์Šค๋งˆํŠธ ๋Œ€์‹œ ๋น„ํ™œ์„ฑํ™” + textView.smartInsertDeleteType = .no // ์Šค๋งˆํŠธ ์‚ฝ์ž…/์‚ญ์ œ ๋น„ํ™œ์„ฑํ™” + + textView.backgroundColor = UIColor(resource: .popcornGray4) + textView.layer.borderWidth = 1 + textView.layer.borderColor = UIColor(resource: .popcornGray2).cgColor + textView.cornerRadius(radius: 10) + return textView + }() + + private let uploadImageTitleLabel: UILabel = { + let label = UILabel() + label.popcornSemiBold(text: "์‚ฌ์ง„ ๋“ฑ๋ก", size: 15) + return label + }() + + private let uploadImageConstraintTitleLabel: UILabel = { + let label = UILabel() + label.popcornMedium(text: "0์žฅ / ์ตœ๋Œ€ 10์žฅ", size: 13) + label.textColor = UIColor(resource: .popcornDarkBlueGray) + return label + }() + + private let uploadImageCollectionView: UICollectionView = { + let layout = UICollectionViewFlowLayout() + layout.scrollDirection = .horizontal + layout.minimumInteritemSpacing = 10 + + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) + collectionView.showsHorizontalScrollIndicator = false + return collectionView + }() + + private let reviewCompleteButton = PopcornOrangeButton(text: "๋ฆฌ๋ทฐ ๋“ฑ๋กํ•˜๊ธฐ", isEnabled: false) + + // MARK: - Stack View + private lazy var popupTitlePeriodStackView: UIStackView = { + let stackView = UIStackView(arrangedSubviews: [popupTitleLabel, popupPeriodLabel]) + stackView.axis = .vertical + stackView.spacing = 5 + stackView.alignment = .leading + stackView.distribution = .fillProportionally + return stackView + }() + + init(image: UIImage, title: String, period: String) { + super.init(nibName: nil, bundle: nil) + popupMainImageView.image = image + popupTitleLabel.text = title + popupPeriodLabel.text = period + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + super.viewDidLoad() + configureInitialSetting() + configureSubviews() + configureLayout() + configureAction() + bind(to: viewModel) + } + + func bind(to viewModel: WriteReviewViewModel) { + viewModel.reviewTextPublisher = { [weak self] textCount in + guard let self else { return } + DispatchQueue.main.async { + self.reviewConstraintTitleLabel.text = "\(textCount)์ž / ์ตœ์†Œ 10์ž" + } + } + + viewModel.reviewImagesPublisher = { [weak self] imageCount in + guard let self else { return } + DispatchQueue.main.async { + self.uploadImageConstraintTitleLabel.text = "\(imageCount)์žฅ / ์ตœ๋Œ€ 10์žฅ" + self.uploadImageCollectionView.reloadData() + } + } + + viewModel.isSubmitEnabledPublisher = { [weak self] isSubmitEnable in + guard let self else { return } + + DispatchQueue.main.async { + self.reviewCompleteButton.isEnabled = isSubmitEnable + self.reviewCompleteButton.configuration?.baseBackgroundColor = isSubmitEnable + ? UIColor(resource: .popcornOrange) + : UIColor(resource: .popcornGray2) + } + } + } +} + +// MARK: - Initial Setting +extension WriteReviewViewController { + private func configureInitialSetting() { + view.backgroundColor = .white + + configureGestureRecognizer() + configureCollectionView() + reviewTextView.delegate = self + userStatisfactionRatingView.delegate = self + } + + private func configureCollectionView() { + uploadImageCollectionView.dataSource = self + uploadImageCollectionView.delegate = self + + uploadImageCollectionView.register( + UploadImageCollectionViewCell.self, + forCellWithReuseIdentifier: UploadImageCollectionViewCell.reuseIdentifier + ) + } + + private func configureGestureRecognizer() { + let panGesture = UIPanGestureRecognizer( + target: userStatisfactionRatingView, + action: #selector(userStatisfactionRatingView.handlePanGesture(_:)) + ) + let tapGesture = UITapGestureRecognizer( + target: userStatisfactionRatingView, + action: #selector(userStatisfactionRatingView.handleTapGesture(_:)) + ) + [panGesture, tapGesture].forEach { userStatisfactionRatingView.addGestureRecognizer($0) } + } +} + +// MARK: - Configure Action +extension WriteReviewViewController { + private func configureAction() { + reviewCompleteButton.addAction(UIAction { [weak self] _ in + guard let self else { return } + self.didTapReviewCompleteButton() + }, for: .touchUpInside) + } + + private func didTapReviewCompleteButton() { + viewModel.postReviewData() + self.navigationController?.popViewController(animated: true) + } +} + +// MARK: - Implement StarRatingView Delegate +extension WriteReviewViewController: StarRatingViewDelegate { + func didChangeRating(to rating: Float) { + viewModel.updateRating(rating) + } +} + +// MARK: - Implement UITextView Delegate +extension WriteReviewViewController: UITextViewDelegate { + func textViewDidChange(_ textView: UITextView) { + viewModel.updateReviewText(textView.text) + } + + func textViewDidBeginEditing(_ textView: UITextView) { + if textView.text == viewModel.reviewTextViewPlaceHolderText { + textView.text = nil + textView.textColor = UIColor.black + } + } + + func textViewDidEndEditing(_ textView: UITextView) { + if textView.text.isEmpty { + textView.text = viewModel.reviewTextViewPlaceHolderText + textView.textColor = UIColor(resource: .popcornDarkBlueGray) + } + } + + override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { + view.endEditing(true) + } +} + +// MARK: - Configure PHPicker +extension WriteReviewViewController: PHPickerViewControllerDelegate { + private func configurePHPicker(selectionLimit: Int) { + var config = PHPickerConfiguration() + config.selectionLimit = selectionLimit + config.filter = .images + + let phPickerViewController = PHPickerViewController(configuration: config) + phPickerViewController.delegate = self + self.present(phPickerViewController, animated: true) + } + + func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { + picker.dismiss(animated: true) + + results.forEach { [weak self] result in + guard let self else { return } + guard viewModel.provideReviewImagesCount() <= 10 else { return } + + let itemProvider = result.itemProvider + if itemProvider.canLoadObject(ofClass: UIImage.self) { + itemProvider.loadObject(ofClass: UIImage.self) { image, error in + if error != nil { + return + } + + if let image = image as? UIImage { + self.viewModel.addImage(image) + } + } + } + } + } + + private func presentResetAlert(for index: Int) { + let alert = UIAlertController(title: "์ด๋ฏธ์ง€ ์ดˆ๊ธฐํ™”", message: "ํ•ด๋‹น ์ด๋ฏธ์ง€๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?", preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "์ทจ์†Œ", style: .cancel, handler: nil)) + alert.addAction(UIAlertAction(title: "์ดˆ๊ธฐํ™”", style: .destructive) { [weak self] _ in + guard let self else { return } + self.viewModel.resetImage(at: index) + }) + present(alert, animated: true) + } +} + +// MARK: - Implement UICollectionView DataSource +extension WriteReviewViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return 10 + } + + func collectionView( + _ collectionView: UICollectionView, + cellForItemAt indexPath: IndexPath + ) -> UICollectionViewCell { + guard let cell = collectionView.dequeueReusableCell( + withReuseIdentifier: UploadImageCollectionViewCell.reuseIdentifier, + for: indexPath + ) as? UploadImageCollectionViewCell else { + return UICollectionViewCell() + } + + let reviewImage = viewModel.provideReviewImages(at: indexPath.item) + cell.configureContents(image: reviewImage) + + return cell + } +} + +// MARK: - Implement UICollectionView DelegateFlowLayout +extension WriteReviewViewController: UICollectionViewDelegateFlowLayout { + func collectionView( + _ collectionView: UICollectionView, + layout collectionViewLayout: UICollectionViewLayout, + sizeForItemAt indexPath: IndexPath + ) -> CGSize { + let height = view.bounds.height * 70 / 852 + let width = height + + return CGSize(width: width, height: height) + } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let image = viewModel.provideReviewImages(at: indexPath.item) + + if image != UIImage(resource: .uploadImagePlaceholder) { + presentResetAlert(for: indexPath.item) + } else { + let selectionLimit = 10 - viewModel.provideReviewImagesCount() + configurePHPicker(selectionLimit: selectionLimit) + } + } +} + +// MARK: - Configure UI +extension WriteReviewViewController { + private func configureSubviews() { + [ + popupMainImageView, + popupTitlePeriodStackView, + userSatisfactionTitleLabel, + userStatisfactionRatingView, + writeReviewTitleLabel, + reviewConstraintTitleLabel, + reviewTextView, + uploadImageTitleLabel, + uploadImageConstraintTitleLabel, + uploadImageCollectionView, + reviewCompleteButton + ].forEach { + view.addSubview($0) + $0.translatesAutoresizingMaskIntoConstraints = false + } + } + + private func configureLayout() { + let safeArea = view.safeAreaLayoutGuide + let reviewCompleteButtonTopConstraint = reviewCompleteButton.topAnchor.constraint( + greaterThanOrEqualTo: uploadImageCollectionView.bottomAnchor, + constant: 64 + ) + let screenHeight = view.bounds.height + let verticalSpacing = screenHeight >= 800 ? CGFloat(45) : CGFloat(30) + + reviewCompleteButtonTopConstraint.priority = .defaultLow + NSLayoutConstraint.activate([ + popupMainImageView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 30), + popupMainImageView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor, constant: 26), + popupMainImageView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 50/393), + popupMainImageView.heightAnchor.constraint(equalTo: popupMainImageView.widthAnchor), + + popupTitlePeriodStackView.leadingAnchor.constraint( + equalTo: popupMainImageView.trailingAnchor, + constant: 10 + ), + popupTitlePeriodStackView.centerYAnchor.constraint(equalTo: popupMainImageView.centerYAnchor), + + userSatisfactionTitleLabel.topAnchor.constraint( + equalTo: popupMainImageView.bottomAnchor, + constant: verticalSpacing + ), + userSatisfactionTitleLabel.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + + userStatisfactionRatingView.topAnchor.constraint( + equalTo: userSatisfactionTitleLabel.bottomAnchor, + constant: 20 + ), + userStatisfactionRatingView.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor), + + writeReviewTitleLabel.topAnchor.constraint( + equalTo: userStatisfactionRatingView.bottomAnchor, + constant: verticalSpacing + ), + writeReviewTitleLabel.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + writeReviewTitleLabel.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor), + + reviewConstraintTitleLabel.centerYAnchor.constraint(equalTo: writeReviewTitleLabel.centerYAnchor), + reviewConstraintTitleLabel.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -27), + + reviewTextView.topAnchor.constraint(equalTo: writeReviewTitleLabel.bottomAnchor, constant: 20), + reviewTextView.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + reviewTextView.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor), + reviewTextView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 104/852), + + uploadImageTitleLabel.topAnchor.constraint(equalTo: reviewTextView.bottomAnchor, constant: verticalSpacing), + uploadImageTitleLabel.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + uploadImageConstraintTitleLabel.trailingAnchor.constraint( + equalTo: reviewConstraintTitleLabel.trailingAnchor + ), + + uploadImageConstraintTitleLabel.centerYAnchor.constraint(equalTo: uploadImageTitleLabel.centerYAnchor), + + uploadImageCollectionView.topAnchor.constraint(equalTo: uploadImageTitleLabel.bottomAnchor, constant: 20), + uploadImageCollectionView.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + uploadImageCollectionView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -27), + uploadImageCollectionView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 70/852), + + reviewCompleteButtonTopConstraint, + reviewCompleteButton.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + reviewCompleteButton.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -51), + reviewCompleteButton.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor), + reviewCompleteButton.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 55/852) + ]) + } +}
Swift
๋””์ž์ธ์ด ์ถ”๊ฐ€๋˜์–ด์•ผํ•˜์ง€๋งŒ.. ์–ผ๋Ÿฟ์œผ๋กœ ํ‘œ์‹œ๋˜๋Š”๊ฑฐ๋ณด๋‹ค x๋ฒ„ํŠผ์ด ์žˆ๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”? ์‚ฌ์šฉ์ž ์ž…์žฅ์—์„œ ์ด๋ฏธ์ง€๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜๊ณ ์‹ถ์„ ๋•Œ ์‚ฌ์ง„์„ ํ„ฐ์น˜ํ•˜๋ฉด ์ด๋ฏธ์ง€ ์ดˆ๊ธฐํ™”๋ฅผ ํ•œ๋‹ค๋Š”๊ฑธ ๋– ์˜ฌ๋ฆฌ๊ธฐ๊ฐ€ ์–ด๋ ค์šธ๊ฑฐ ๊ฐ™์•„์„œ์š”!
@@ -0,0 +1,43 @@ +// +// PopcornOrangeButton.swift +// Popcorn-iOS +// +// Created by ์ œ๋ฏผ์šฐ on 1/12/25. +// + +import UIKit + +final class PopcornOrangeButton: UIButton { + init(text: String, isEnabled: Bool) { + super.init(frame: .zero) + configureInitialSetting(isEnabled: isEnabled) + configureButtonUI(text: text) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +// MARK: - Configure Initial Setting +extension PopcornOrangeButton { + private func configureInitialSetting(isEnabled: Bool) { + self.isEnabled = isEnabled + self.cornerRadius(radius: 10) + } + + private func configureButtonUI(text: String) { + var config = UIButton.Configuration.filled() + config.baseBackgroundColor = isEnabled == true + ? UIColor(resource: .popcornOrange) + : UIColor(resource: .popcornGray2) + config.attributedTitle = AttributedString( + text, + attributes: AttributeContainer([ + .font: UIFont(name: RobotoFontName.robotoSemiBold, size: 15)!, + .foregroundColor: UIColor(.white) + ]) + ) + configuration = config + } +}
Swift
๋„ต! ๋‚˜์ค‘์— ํ™”๋ฉด ์—ฐ๊ฒฐ ์‹œ ๋‚ด๋น„๊ฒŒ์ด์…˜ ๋ฐ” ๊ตฌํ˜„ํ•˜๋ ค๊ณ  ํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,425 @@ +// +// WriteReviewViewController.swift +// Popcorn-iOS +// +// Created by ์ œ๋ฏผ์šฐ on 1/12/25. +// + +import PhotosUI +import UIKit + +final class WriteReviewViewController: UIViewController { + private let viewModel = WriteReviewViewModel() + + private let popupMainImageView: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(resource: .imagePlaceHolder) + imageView.contentMode = .scaleAspectFill + imageView.clipsToBounds = true + return imageView + }() + + private let popupTitleLabel: UILabel = { + let label = UILabel() + label.popcornSemiBold(text: "ํŒ์—… ์ œ๋ชฉ", size: 15) + label.numberOfLines = 0 + return label + }() + + private let popupPeriodLabel: UILabel = { + let label = UILabel() + label.popcornMedium(text: "00.00.00~00.00.00", size: 10) + return label + }() + + private let userSatisfactionTitleLabel: UILabel = { + let label = UILabel() + label.popcornSemiBold(text: "ํŒ์—…์Šคํ† ์–ด ๋งŒ์กฑ๋„", size: 15) + return label + }() + + private let userStatisfactionRatingView = StarRatingView(starSpacing: 11.63, isUserInteractionEnabled: true) + + private let writeReviewTitleLabel: UILabel = { + let label = UILabel() + label.popcornSemiBold(text: "๋ฆฌ๋ทฐ ์ž‘์„ฑ", size: 15) + return label + }() + + private let reviewConstraintTitleLabel: UILabel = { + let label = UILabel() + label.popcornMedium(text: "0์ž / ์ตœ์†Œ 10์ž", size: 13) + label.textColor = UIColor(resource: .popcornDarkBlueGray) + return label + }() + + private lazy var reviewTextView: UITextView = { + let textView = UITextView() + textView.text = viewModel.reviewTextViewPlaceHolderText + textView.textColor = UIColor(resource: .popcornDarkBlueGray) + textView.font = UIFont(name: RobotoFontName.robotoMedium, size: 15) + textView.textContainerInset = UIEdgeInsets(top: 15, left: 10, bottom: 15, right: 10) + textView.autocapitalizationType = .none + textView.autocorrectionType = .no // ์ž๋™ ์ˆ˜์ • ๋น„ํ™œ์„ฑํ™” + textView.spellCheckingType = .no // ๋งž์ถค๋ฒ• ๊ฒ€์‚ฌ ๋น„ํ™œ์„ฑํ™” + textView.smartQuotesType = .no // ์Šค๋งˆํŠธ ๋”ฐ์˜ดํ‘œ ๋น„ํ™œ์„ฑํ™” + textView.smartDashesType = .no // ์Šค๋งˆํŠธ ๋Œ€์‹œ ๋น„ํ™œ์„ฑํ™” + textView.smartInsertDeleteType = .no // ์Šค๋งˆํŠธ ์‚ฝ์ž…/์‚ญ์ œ ๋น„ํ™œ์„ฑํ™” + + textView.backgroundColor = UIColor(resource: .popcornGray4) + textView.layer.borderWidth = 1 + textView.layer.borderColor = UIColor(resource: .popcornGray2).cgColor + textView.cornerRadius(radius: 10) + return textView + }() + + private let uploadImageTitleLabel: UILabel = { + let label = UILabel() + label.popcornSemiBold(text: "์‚ฌ์ง„ ๋“ฑ๋ก", size: 15) + return label + }() + + private let uploadImageConstraintTitleLabel: UILabel = { + let label = UILabel() + label.popcornMedium(text: "0์žฅ / ์ตœ๋Œ€ 10์žฅ", size: 13) + label.textColor = UIColor(resource: .popcornDarkBlueGray) + return label + }() + + private let uploadImageCollectionView: UICollectionView = { + let layout = UICollectionViewFlowLayout() + layout.scrollDirection = .horizontal + layout.minimumInteritemSpacing = 10 + + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) + collectionView.showsHorizontalScrollIndicator = false + return collectionView + }() + + private let reviewCompleteButton = PopcornOrangeButton(text: "๋ฆฌ๋ทฐ ๋“ฑ๋กํ•˜๊ธฐ", isEnabled: false) + + // MARK: - Stack View + private lazy var popupTitlePeriodStackView: UIStackView = { + let stackView = UIStackView(arrangedSubviews: [popupTitleLabel, popupPeriodLabel]) + stackView.axis = .vertical + stackView.spacing = 5 + stackView.alignment = .leading + stackView.distribution = .fillProportionally + return stackView + }() + + init(image: UIImage, title: String, period: String) { + super.init(nibName: nil, bundle: nil) + popupMainImageView.image = image + popupTitleLabel.text = title + popupPeriodLabel.text = period + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + super.viewDidLoad() + configureInitialSetting() + configureSubviews() + configureLayout() + configureAction() + bind(to: viewModel) + } + + func bind(to viewModel: WriteReviewViewModel) { + viewModel.reviewTextPublisher = { [weak self] textCount in + guard let self else { return } + DispatchQueue.main.async { + self.reviewConstraintTitleLabel.text = "\(textCount)์ž / ์ตœ์†Œ 10์ž" + } + } + + viewModel.reviewImagesPublisher = { [weak self] imageCount in + guard let self else { return } + DispatchQueue.main.async { + self.uploadImageConstraintTitleLabel.text = "\(imageCount)์žฅ / ์ตœ๋Œ€ 10์žฅ" + self.uploadImageCollectionView.reloadData() + } + } + + viewModel.isSubmitEnabledPublisher = { [weak self] isSubmitEnable in + guard let self else { return } + + DispatchQueue.main.async { + self.reviewCompleteButton.isEnabled = isSubmitEnable + self.reviewCompleteButton.configuration?.baseBackgroundColor = isSubmitEnable + ? UIColor(resource: .popcornOrange) + : UIColor(resource: .popcornGray2) + } + } + } +} + +// MARK: - Initial Setting +extension WriteReviewViewController { + private func configureInitialSetting() { + view.backgroundColor = .white + + configureGestureRecognizer() + configureCollectionView() + reviewTextView.delegate = self + userStatisfactionRatingView.delegate = self + } + + private func configureCollectionView() { + uploadImageCollectionView.dataSource = self + uploadImageCollectionView.delegate = self + + uploadImageCollectionView.register( + UploadImageCollectionViewCell.self, + forCellWithReuseIdentifier: UploadImageCollectionViewCell.reuseIdentifier + ) + } + + private func configureGestureRecognizer() { + let panGesture = UIPanGestureRecognizer( + target: userStatisfactionRatingView, + action: #selector(userStatisfactionRatingView.handlePanGesture(_:)) + ) + let tapGesture = UITapGestureRecognizer( + target: userStatisfactionRatingView, + action: #selector(userStatisfactionRatingView.handleTapGesture(_:)) + ) + [panGesture, tapGesture].forEach { userStatisfactionRatingView.addGestureRecognizer($0) } + } +} + +// MARK: - Configure Action +extension WriteReviewViewController { + private func configureAction() { + reviewCompleteButton.addAction(UIAction { [weak self] _ in + guard let self else { return } + self.didTapReviewCompleteButton() + }, for: .touchUpInside) + } + + private func didTapReviewCompleteButton() { + viewModel.postReviewData() + self.navigationController?.popViewController(animated: true) + } +} + +// MARK: - Implement StarRatingView Delegate +extension WriteReviewViewController: StarRatingViewDelegate { + func didChangeRating(to rating: Float) { + viewModel.updateRating(rating) + } +} + +// MARK: - Implement UITextView Delegate +extension WriteReviewViewController: UITextViewDelegate { + func textViewDidChange(_ textView: UITextView) { + viewModel.updateReviewText(textView.text) + } + + func textViewDidBeginEditing(_ textView: UITextView) { + if textView.text == viewModel.reviewTextViewPlaceHolderText { + textView.text = nil + textView.textColor = UIColor.black + } + } + + func textViewDidEndEditing(_ textView: UITextView) { + if textView.text.isEmpty { + textView.text = viewModel.reviewTextViewPlaceHolderText + textView.textColor = UIColor(resource: .popcornDarkBlueGray) + } + } + + override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { + view.endEditing(true) + } +} + +// MARK: - Configure PHPicker +extension WriteReviewViewController: PHPickerViewControllerDelegate { + private func configurePHPicker(selectionLimit: Int) { + var config = PHPickerConfiguration() + config.selectionLimit = selectionLimit + config.filter = .images + + let phPickerViewController = PHPickerViewController(configuration: config) + phPickerViewController.delegate = self + self.present(phPickerViewController, animated: true) + } + + func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { + picker.dismiss(animated: true) + + results.forEach { [weak self] result in + guard let self else { return } + guard viewModel.provideReviewImagesCount() <= 10 else { return } + + let itemProvider = result.itemProvider + if itemProvider.canLoadObject(ofClass: UIImage.self) { + itemProvider.loadObject(ofClass: UIImage.self) { image, error in + if error != nil { + return + } + + if let image = image as? UIImage { + self.viewModel.addImage(image) + } + } + } + } + } + + private func presentResetAlert(for index: Int) { + let alert = UIAlertController(title: "์ด๋ฏธ์ง€ ์ดˆ๊ธฐํ™”", message: "ํ•ด๋‹น ์ด๋ฏธ์ง€๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?", preferredStyle: .alert) + alert.addAction(UIAlertAction(title: "์ทจ์†Œ", style: .cancel, handler: nil)) + alert.addAction(UIAlertAction(title: "์ดˆ๊ธฐํ™”", style: .destructive) { [weak self] _ in + guard let self else { return } + self.viewModel.resetImage(at: index) + }) + present(alert, animated: true) + } +} + +// MARK: - Implement UICollectionView DataSource +extension WriteReviewViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return 10 + } + + func collectionView( + _ collectionView: UICollectionView, + cellForItemAt indexPath: IndexPath + ) -> UICollectionViewCell { + guard let cell = collectionView.dequeueReusableCell( + withReuseIdentifier: UploadImageCollectionViewCell.reuseIdentifier, + for: indexPath + ) as? UploadImageCollectionViewCell else { + return UICollectionViewCell() + } + + let reviewImage = viewModel.provideReviewImages(at: indexPath.item) + cell.configureContents(image: reviewImage) + + return cell + } +} + +// MARK: - Implement UICollectionView DelegateFlowLayout +extension WriteReviewViewController: UICollectionViewDelegateFlowLayout { + func collectionView( + _ collectionView: UICollectionView, + layout collectionViewLayout: UICollectionViewLayout, + sizeForItemAt indexPath: IndexPath + ) -> CGSize { + let height = view.bounds.height * 70 / 852 + let width = height + + return CGSize(width: width, height: height) + } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let image = viewModel.provideReviewImages(at: indexPath.item) + + if image != UIImage(resource: .uploadImagePlaceholder) { + presentResetAlert(for: indexPath.item) + } else { + let selectionLimit = 10 - viewModel.provideReviewImagesCount() + configurePHPicker(selectionLimit: selectionLimit) + } + } +} + +// MARK: - Configure UI +extension WriteReviewViewController { + private func configureSubviews() { + [ + popupMainImageView, + popupTitlePeriodStackView, + userSatisfactionTitleLabel, + userStatisfactionRatingView, + writeReviewTitleLabel, + reviewConstraintTitleLabel, + reviewTextView, + uploadImageTitleLabel, + uploadImageConstraintTitleLabel, + uploadImageCollectionView, + reviewCompleteButton + ].forEach { + view.addSubview($0) + $0.translatesAutoresizingMaskIntoConstraints = false + } + } + + private func configureLayout() { + let safeArea = view.safeAreaLayoutGuide + let reviewCompleteButtonTopConstraint = reviewCompleteButton.topAnchor.constraint( + greaterThanOrEqualTo: uploadImageCollectionView.bottomAnchor, + constant: 64 + ) + let screenHeight = view.bounds.height + let verticalSpacing = screenHeight >= 800 ? CGFloat(45) : CGFloat(30) + + reviewCompleteButtonTopConstraint.priority = .defaultLow + NSLayoutConstraint.activate([ + popupMainImageView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 30), + popupMainImageView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor, constant: 26), + popupMainImageView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 50/393), + popupMainImageView.heightAnchor.constraint(equalTo: popupMainImageView.widthAnchor), + + popupTitlePeriodStackView.leadingAnchor.constraint( + equalTo: popupMainImageView.trailingAnchor, + constant: 10 + ), + popupTitlePeriodStackView.centerYAnchor.constraint(equalTo: popupMainImageView.centerYAnchor), + + userSatisfactionTitleLabel.topAnchor.constraint( + equalTo: popupMainImageView.bottomAnchor, + constant: verticalSpacing + ), + userSatisfactionTitleLabel.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + + userStatisfactionRatingView.topAnchor.constraint( + equalTo: userSatisfactionTitleLabel.bottomAnchor, + constant: 20 + ), + userStatisfactionRatingView.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor), + + writeReviewTitleLabel.topAnchor.constraint( + equalTo: userStatisfactionRatingView.bottomAnchor, + constant: verticalSpacing + ), + writeReviewTitleLabel.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + writeReviewTitleLabel.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor), + + reviewConstraintTitleLabel.centerYAnchor.constraint(equalTo: writeReviewTitleLabel.centerYAnchor), + reviewConstraintTitleLabel.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -27), + + reviewTextView.topAnchor.constraint(equalTo: writeReviewTitleLabel.bottomAnchor, constant: 20), + reviewTextView.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + reviewTextView.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor), + reviewTextView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 104/852), + + uploadImageTitleLabel.topAnchor.constraint(equalTo: reviewTextView.bottomAnchor, constant: verticalSpacing), + uploadImageTitleLabel.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + uploadImageConstraintTitleLabel.trailingAnchor.constraint( + equalTo: reviewConstraintTitleLabel.trailingAnchor + ), + + uploadImageConstraintTitleLabel.centerYAnchor.constraint(equalTo: uploadImageTitleLabel.centerYAnchor), + + uploadImageCollectionView.topAnchor.constraint(equalTo: uploadImageTitleLabel.bottomAnchor, constant: 20), + uploadImageCollectionView.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + uploadImageCollectionView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -27), + uploadImageCollectionView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 70/852), + + reviewCompleteButtonTopConstraint, + reviewCompleteButton.leadingAnchor.constraint(equalTo: popupMainImageView.leadingAnchor), + reviewCompleteButton.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -51), + reviewCompleteButton.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor), + reviewCompleteButton.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 55/852) + ]) + } +}
Swift
์‹ค์ˆ˜๋กœ ์ธํ•ด ์‚ฌ์ง„์ด ์‚ญ์ œ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์–ผ๋Ÿฟ์œผ๋กœ ํ‘œ์‹œํ•˜์—ฌ ํ™•์ธ์„ ๋‹ค์‹œ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์˜๋„ํ•˜์˜€์Šต๋‹ˆ๋‹ค! ๋””์ž์ด๋„ˆ๋‹˜๊ณผ ๋‹ค์‹œ ํ•œ ๋ฒˆ ์ƒ์˜ํ•ด๋ด์•ผ๊ฒ ๋„ค์š”!!
@@ -0,0 +1,15 @@ +import { useQuery } from '@tanstack/react-query'; + +import getTempleReviews from './axios'; +import { ReviewsResponse } from './type'; + +const useGetTempleReviews = (templestayId: string, page: number) => { + const { data, isLoading, isError } = useQuery<ReviewsResponse>({ + queryKey: ['reviews', templestayId, page], + queryFn: () => getTempleReviews(templestayId, page), + }); + + return { data, isLoading, isError }; +}; + +export default useGetTempleReviews;
TypeScript
ํ˜„์žฌ ์ฟผ๋ฆฌํ‚ค๊ฐ€ reviews์™€ page๋กœ๋งŒ ์ •ํ•ด์ ธ ์žˆ์–ด์„œ ๋ชจ๋“  ํ…œํ”Œ์Šคํ…Œ์ด ๋ฆฌ๋ทฐ๊ฐ€ ๊ฐ™์€ ์ฟผ๋ฆฌํ‚ค๋ฅผ ๊ณต์œ ํ•˜๊ณ  ์žˆ์–ด์„œ queryKey: ['reviews', templestayId, page],๋กœ templestayId๋ฅผ ์ฟผ๋ฆฌํ‚ค์— ์ถ”๊ฐ€ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ ํ…œํ”Œ์Šคํ…Œ์ด ๋ฆฌ๋ทฐ๋ฅผ ๊ตฌ๋ณ„ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,15 @@ +import { useQuery } from '@tanstack/react-query'; + +import getTempleReviews from './axios'; +import { ReviewsResponse } from './type'; + +const useGetTempleReviews = (templestayId: string, page: number) => { + const { data, isLoading, isError } = useQuery<ReviewsResponse>({ + queryKey: ['reviews', templestayId, page], + queryFn: () => getTempleReviews(templestayId, page), + }); + + return { data, isLoading, isError }; +}; + +export default useGetTempleReviews;
TypeScript
๋„ต ๋ฐ˜์˜ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,36 @@ +package me.misik.api.infra + +import me.misik.api.core.Chatbot +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import org.springframework.web.reactive.function.client.WebClient +import org.springframework.web.reactive.function.client.support.WebClientAdapter +import org.springframework.web.service.invoker.HttpServiceProxyFactory + +@Configuration +class ClovaChatbotConfiguration( + @Value("\${me.misik.chatbot.clova.url:https://clovastudio.stream.ntruss.com/}") private val chatbotUrl: String, + @Value("\${me.misik.chatbot.clova.authorization}") private val authorization: String, +) { + + @Bean + fun clovaChatbot(): Chatbot { + val webClient = WebClient.builder() + .baseUrl(chatbotUrl) + .defaultHeaders { headers -> + headers.add(HttpHeaders.AUTHORIZATION, "Bearer $authorization") + headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + headers.add(HttpHeaders.ACCEPT, MediaType.TEXT_EVENT_STREAM_VALUE) + } + .build() + + val httpServiceProxyFactory = HttpServiceProxyFactory + .builderFor(WebClientAdapter.create(webClient)) + .build() + + return httpServiceProxyFactory.createClient(Chatbot::class.java) + } +}
Kotlin
hoxy ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋“ฑ๋กํ•˜๋Š”๊ฑฐ๋ฉด @Value ์‚ฌ์šฉํ•ด๋„ ๋ ๊นŒ์š”? ํ˜น์€ @Qualifier๋Š” ์‚ฌ์šฉํ•  ๋นˆ ๊ฐ์ฒด ์„ ํƒ ์‹œ ์“ฐ๋Š”๊ฑธ๋กœ ์•Œ๊ณ ์žˆ๋Š”๋ฐ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋“ฑ๋กํ•  ๋•Œ๋„ ์“ธ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋Š”์ง€์šฉ? ๐Ÿ˜
@@ -0,0 +1,17 @@ +package me.misik.api.api + +import me.misik.api.app.ReCreateReviewFacade +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +class ReviewController( + private val reCreateReviewFacade: ReCreateReviewFacade, +) { + + @PostMapping("reviews/{id}/re-create") + fun reCreateReview( + @PathVariable("id") id: Long, + ) = reCreateReviewFacade.reCreateReviewInBackground(id) +}
Kotlin
์žฌ์ƒ์„ฑ๋œ ๋ฆฌ๋ทฐ๋„ ์บ์‹ฑ์— ํ™œ์šฉํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์€๋ฐ ์ œ๊ฐ€ #5 ํ•  ๋•Œ ์ถ”๊ฐ€ํ•ด๋ด๋„ ๋ ๊นŒ์š”? 1) ์žฌ์‚ฌ์šฉ์„ ์œ„ํ•ด DB์— ์ €์žฅ 2) ์ด๋ฏธ ๊ฐ™์€ ์œ ์ €์—๊ฒŒ ์ œ๊ณต๋œ ๋ฆฌ๋ทฐ๋Š” ๋˜ ์ œ๊ณต X ์œ„๋ฅผ ์œ„ํ•ด์„œ device id ํ—ค๋”๋ฅผ ๋ฐ›์•„์˜ค๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹น!
@@ -0,0 +1,24 @@ +# ๋ฆฌ๋ทฐ ์ƒ์„ฑ + +๋ฆฌ๋ทฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +## Request + +### HTTP METHOD : `GET` + +### url : `https://api.misik.me/reviews/{id}` +### Http Headers +- device-id: ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’ + `๋ฏธ๋ž˜์—๋„ ๋ณ€ํ•˜์ง€ ์•Š์•„์•ผํ•จ ์•ฑ์„ ์‚ญ์ œํ–ˆ๋‹ค ๋‹ค์‹œ ๊น”์•„๋„ ์•ˆ๋ณ€ํ•˜๋Š” ๊ฐ’์œผ๋กœ ์ค„ ์ˆ˜ ์žˆ๋Š”์ง€` + +### Response + +#### `Response Status 200 OK` + +```json +{ + "isSuccess": true, // ๋ฆฌ๋ทฐ๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์•˜์œผ๋ฉด false, ์ „์ฒด๊ฐ€ ์„ฑ๊ณต๋˜๋ฉด true + "id": "123456789", + "review": "์นด์•ผํ† ์Šค๋Š” ์ˆจ๊ฒจ์ ธ ์žˆ๋Š” ์นด์•ผ์žผ๊ณผ ๋ฒ„ํ„ฐ๊ฐ€ ํ™•์‹คํžˆ ๊ฐ€๋“ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ๊ฐ€๊ฒŒ์˜ ๋ถ„์œ„๊ธฐ๋Š” ์•„๋Š‘ํ•˜๊ณ  ํŽธ์•ˆํ•˜๊ณ  ๋ฐ”๊นฅ์ชฝ์— ์žˆ๊ณ  ์‚ฌ๋ž‘ํ•˜๋Š” ์‹œ๊ฐ„์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์ž…๋‹ˆ๋‹ค. ๋ฌด์—‡๋ณด๋‹ค ๊ฐ€๊ฒฉ์— ๋น„ํ•ด ์Œ์‹์˜ ํ’ˆ์งˆ์ด ์ •๋ง ํ›Œ๋ฅญํ•ด์„œ, ๋งˆ์Œ์— ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค." +} +```
Unknown
์ด ๋ถ€๋ถ„ ๋‹ค์Œ ์—”์ง€๋‹ˆ์–ด ํšŒ์˜ ๋•Œ ํด๋ผ์ด์–ธํŠธ ๋ถ„๋“ค๊ณผ ์ด์•ผ๊ธฐ ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ๐Ÿ˜ ์•ž์œผ๋กœ๋„ ๋น„์Šทํ•œ ์กฐํšŒ ๋กœ์ง์„ ์œ„ํ•ด ํ•ฉ์˜ํ•ด๋‘๋ฉด ์ข‹์„๋“ฏ์š”! ์ง€๊ธˆ์ฒ˜๋Ÿผ ์กฐํšŒํ•  ๋•Œ ๊ฐ’์ด ์—†์œผ๋ฉด 200์„ ์ฃผ๊ณ  ํ•„๋“œ๋กœ ๊ตฌ๋ถ„ํ•˜๊ฒŒ ํ•  ๊ฒƒ์ธ์ง€, ์•„๋‹ˆ๋ฉด 400์„ ๋‚ด๋ ค์ค„์ง€์— ๋Œ€ํ•ด์„œ์šฉ!
@@ -0,0 +1,17 @@ +package me.misik.api.api + +import me.misik.api.app.ReCreateReviewFacade +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +class ReviewController( + private val reCreateReviewFacade: ReCreateReviewFacade, +) { + + @PostMapping("reviews/{id}/re-create") + fun reCreateReview( + @PathVariable("id") id: Long, + ) = reCreateReviewFacade.reCreateReviewInBackground(id) +}
Kotlin
hoxy ์—ฌ๊ธฐ ๋ฉ”์„œ๋“œ๋ช…์ด reCreateReview๊ฐ€ ์•„๋‹Œ createReview์ธ๋ฐ ์˜๋„ํ•˜์‹ ๊ฑธ๊นŒ์š”? ๐Ÿฅณ
@@ -0,0 +1,24 @@ +# ๋ฆฌ๋ทฐ ์ƒ์„ฑ + +๋ฆฌ๋ทฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +## Request + +### HTTP METHOD : `GET` + +### url : `https://api.misik.me/reviews/{id}` +### Http Headers +- device-id: ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’ + `๋ฏธ๋ž˜์—๋„ ๋ณ€ํ•˜์ง€ ์•Š์•„์•ผํ•จ ์•ฑ์„ ์‚ญ์ œํ–ˆ๋‹ค ๋‹ค์‹œ ๊น”์•„๋„ ์•ˆ๋ณ€ํ•˜๋Š” ๊ฐ’์œผ๋กœ ์ค„ ์ˆ˜ ์žˆ๋Š”์ง€` + +### Response + +#### `Response Status 200 OK` + +```json +{ + "isSuccess": true, // ๋ฆฌ๋ทฐ๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์•˜์œผ๋ฉด false, ์ „์ฒด๊ฐ€ ์„ฑ๊ณต๋˜๋ฉด true + "id": "123456789", + "review": "์นด์•ผํ† ์Šค๋Š” ์ˆจ๊ฒจ์ ธ ์žˆ๋Š” ์นด์•ผ์žผ๊ณผ ๋ฒ„ํ„ฐ๊ฐ€ ํ™•์‹คํžˆ ๊ฐ€๋“ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ๊ฐ€๊ฒŒ์˜ ๋ถ„์œ„๊ธฐ๋Š” ์•„๋Š‘ํ•˜๊ณ  ํŽธ์•ˆํ•˜๊ณ  ๋ฐ”๊นฅ์ชฝ์— ์žˆ๊ณ  ์‚ฌ๋ž‘ํ•˜๋Š” ์‹œ๊ฐ„์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์ž…๋‹ˆ๋‹ค. ๋ฌด์—‡๋ณด๋‹ค ๊ฐ€๊ฒฉ์— ๋น„ํ•ด ์Œ์‹์˜ ํ’ˆ์งˆ์ด ์ •๋ง ํ›Œ๋ฅญํ•ด์„œ, ๋งˆ์Œ์— ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค." +} +```
Unknown
๐Ÿ‘ ๋„˜ ์ข‹์•„์š”! streaming ๋ฐฉ์‹ ์ง€์›ํ• ๊ฑฐ๋ผ์„œ ์ƒ์„ฑ์‹œ ๋ฆฌ๋ทฐ id๋งŒ ๋ฐ˜ํ™˜ํ•˜๊ณ , id๋กœ ์—ฌ๋Ÿฌ ๋ฒˆ ์กฐํšŒํ•ด์˜ค๊ฒŒ ํ•˜๊ธฐ!! ์ข‹์Šต๋‹ˆ๋‹น!!
@@ -0,0 +1,65 @@ +package me.misik.api.core + +import kotlinx.coroutines.flow.Flow +import me.misik.api.domain.Review +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.service.annotation.PostExchange + +fun interface Chatbot { + + @PostExchange("/testapp/v1/chat-completions/HCX-003") + fun createReviewWithModelName(@RequestBody request: Request): Flow<Response> + + data class Request( + val messages: List<Message>, + val includeAiFilters: Boolean = true, + ) { + data class Message( + val role: String, + val content: String, + ) { + + companion object { + + fun createSystem(content: String) = Message( + role = "system", + content = content, + ) + + fun createUser(content: String) = Message( + role = "user", + content = content, + ) + } + } + + companion object { + private val cachedSystemMessage = Message.createSystem( + """ + ๋„ˆ๋Š” ์ง€๊ธˆ๋ถ€ํ„ฐ ์Œ์‹์— ๋Œ€ํ•œ ๋ฆฌ๋ทฐ๋ฅผ ํ•˜๋Š” ๊ณ ๋…ํ•œ ๋ฏธ์‹๊ฐ€์•ผ. + ๋‹ต๋ณ€์—๋Š” ๋ฆฌ๋ทฐ์— ๋Œ€ํ•œ ๋‚ด์šฉ๋งŒ ํฌํ•จํ•ด. + ๋˜ํ•œ, ์‘๋‹ต ๋ฉ”์‹œ์ง€๋Š” ๊ณต๋ฐฑ์„ ํฌํ•จํ•ด์„œ 300์ž๊ฐ€ ๋„˜์œผ๋ฉด ์ ˆ๋Œ€๋กœ ์•ˆ๋ผ. + """ + ) + + fun from(review: Review): Request { + return Request( + messages = listOf( + cachedSystemMessage, + Message.createUser(review.requestPrompt.text) + ) + ) + } + } + } + + data class Response( + val stopReason: String?, + val message: Message?, + ) { + data class Message( + val role: String, + val content: String, + ) + } +}
Kotlin
HTTP Interface ๐Ÿ‘ ๊ฐ€๋…์„ฑ ์งฑ์ด๋„ค์šฉ
@@ -0,0 +1,24 @@ +# ๋ฆฌ๋ทฐ ์ƒ์„ฑ + +๋ฆฌ๋ทฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +## Request + +### HTTP METHOD : `GET` + +### url : `https://api.misik.me/reviews/{id}` +### Http Headers +- device-id: ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’ + `๋ฏธ๋ž˜์—๋„ ๋ณ€ํ•˜์ง€ ์•Š์•„์•ผํ•จ ์•ฑ์„ ์‚ญ์ œํ–ˆ๋‹ค ๋‹ค์‹œ ๊น”์•„๋„ ์•ˆ๋ณ€ํ•˜๋Š” ๊ฐ’์œผ๋กœ ์ค„ ์ˆ˜ ์žˆ๋Š”์ง€` + +### Response + +#### `Response Status 200 OK` + +```json +{ + "isSuccess": true, // ๋ฆฌ๋ทฐ๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์•˜์œผ๋ฉด false, ์ „์ฒด๊ฐ€ ์„ฑ๊ณต๋˜๋ฉด true + "id": "123456789", + "review": "์นด์•ผํ† ์Šค๋Š” ์ˆจ๊ฒจ์ ธ ์žˆ๋Š” ์นด์•ผ์žผ๊ณผ ๋ฒ„ํ„ฐ๊ฐ€ ํ™•์‹คํžˆ ๊ฐ€๋“ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ๊ฐ€๊ฒŒ์˜ ๋ถ„์œ„๊ธฐ๋Š” ์•„๋Š‘ํ•˜๊ณ  ํŽธ์•ˆํ•˜๊ณ  ๋ฐ”๊นฅ์ชฝ์— ์žˆ๊ณ  ์‚ฌ๋ž‘ํ•˜๋Š” ์‹œ๊ฐ„์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์ž…๋‹ˆ๋‹ค. ๋ฌด์—‡๋ณด๋‹ค ๊ฐ€๊ฒฉ์— ๋น„ํ•ด ์Œ์‹์˜ ํ’ˆ์งˆ์ด ์ •๋ง ํ›Œ๋ฅญํ•ด์„œ, ๋งˆ์Œ์— ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค." +} +```
Unknown
์•„ ์ด๊ฒŒ 60์ดˆ ๋Œ€๊ธฐ๋•Œ๋ฌธ์— ์ถ”๊ฐ€๋œ๊ฑฐ๊ตฐ์š”! 1. ๋ฆฌ๋ทฐ ์ƒ์„ฑ ์ค‘, ์•„์ง ๋œ ์ƒ์„ฑ๋จ 2. ์•„์˜ˆ ์—†๋Š” ๋ฆฌ๋ทฐid๋ฅผ ์กฐํšŒํ•˜๋ ค๊ณ  ํ•จ 3. ๋ฆฌ๋ทฐ ์ƒ์„ฑ๋จ, ์กฐํšŒ ๊ฐ€๋Šฅ ์ด๋ ‡๊ฒŒ 3๊ฐ€์ง€ ๊ฒฝ์šฐ๊ฐ€ ์žˆ์–ด๋ณด์—ฌ์š”!
@@ -0,0 +1,36 @@ +package me.misik.api.infra + +import me.misik.api.core.Chatbot +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import org.springframework.web.reactive.function.client.WebClient +import org.springframework.web.reactive.function.client.support.WebClientAdapter +import org.springframework.web.service.invoker.HttpServiceProxyFactory + +@Configuration +class ClovaChatbotConfiguration( + @Value("\${me.misik.chatbot.clova.url:https://clovastudio.stream.ntruss.com/}") private val chatbotUrl: String, + @Value("\${me.misik.chatbot.clova.authorization}") private val authorization: String, +) { + + @Bean + fun clovaChatbot(): Chatbot { + val webClient = WebClient.builder() + .baseUrl(chatbotUrl) + .defaultHeaders { headers -> + headers.add(HttpHeaders.AUTHORIZATION, "Bearer $authorization") + headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + headers.add(HttpHeaders.ACCEPT, MediaType.TEXT_EVENT_STREAM_VALUE) + } + .build() + + val httpServiceProxyFactory = HttpServiceProxyFactory + .builderFor(WebClientAdapter.create(webClient)) + .build() + + return httpServiceProxyFactory.createClient(Chatbot::class.java) + } +}
Kotlin
์˜ค ์˜คํƒ€์ž…๋‹ˆ๋‹ค! ใ…‹ใ…‹ใ…‹ใ…‹ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค [b838a91](https://github.com/Nexters/misik-api/pull/7/commits/b838a916d60cf5b000f306c15caf7652e9ee0082)
@@ -0,0 +1,17 @@ +package me.misik.api.api + +import me.misik.api.app.ReCreateReviewFacade +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +class ReviewController( + private val reCreateReviewFacade: ReCreateReviewFacade, +) { + + @PostMapping("reviews/{id}/re-create") + fun reCreateReview( + @PathVariable("id") id: Long, + ) = reCreateReviewFacade.reCreateReviewInBackground(id) +}
Kotlin
๋„ต ๋‹น์—ฐํ•˜์ฃต ์ˆ˜์ •ํ•ด์ฃผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค! ์ถ”๊ฐ€๋กœ, ๊ตฌํ˜„ํ•˜๋ฉด์„œ ์ถœ์‹œ์ „์— ํ•ด์•ผํ• ๊ฑฐ ๊ฐ™์€ ์บ์‹ฑ์„ ๋ฐœ๊ฒฌํ–ˆ๋Š”๋ฐ์š”. ํ˜„์žฌ๋Š” ๋ฆฌ๋ทฐ๋ฅผ ์ƒ์„ฑํ• ๋•Œ, streaming๋ฐฉ์‹์œผ๋กœ DB์— ํ•˜๋‚˜์”ฉ ์ ์žฌ๋ฅผ ํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ฆ‰, ์ฟผ๋ฆฌ๊ฐ€ streaming์˜ ์‘๋‹ต๊ฐฏ์ˆ˜ ๋งŒํผ ๋‚˜๊ฐ€๊ณ , ์œ„ ์‚ฌ์ง„์—์„œ๋Š” ์ด 77๋ฒˆ ์ฟผ๋ฆฌ๊ฐ€ ์ˆ˜ํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๋กœ์ง์„ ์งœ๋Š”๊ฑด DB์— ๋ถ€๋‹ด์ด ๋˜๊ณ , ์„ฑ๋Šฅ๋„ ๋‚˜์˜ค๊ธฐ ํž˜๋“œ๋‹ˆ ์“ฐ๊ธฐ ์บ์‹ฑ์„ ํ•ด์•ผํ• ๊ฑฐ ๊ฐ™์•„์š”. ๋‘๊ฐ€์ง€ ํ”Œ๋กœ์šฐ์— ๋ ˆ๋””์Šค ํ˜น์€ ์ธ๋ฉ”๋ชจ๋ฆฌ๋กœ ์บ์‹ฑ์„ ์ถ”๊ฐ€ํ•ด์•ผํ• ๊ฑฐ ๊ฐ™์€๋ฐ์š”. 1. ์‹ค์‹œ๊ฐ„ ํด๋ง ๋ฆฌ๋ทฐ ์กฐํšŒ (1์ฐจ MVP์—์„œ๋Š” ์—†์Œ) -> redis์—์„œ ์ƒ์„ฑ์ค‘์ธ ๋ฆฌ๋ทฐ๋ฅผ ๋จผ์ € ์กฐํšŒํ•˜๊ณ  ์—†๋‹ค๋ฉด DB๋ฅผ ์กฐํšŒํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์ˆ˜์ • 2. ๋ฆฌ๋ทฐ ์ƒ์„ฑ ๋ฐ ์žฌ์ƒ์„ฑ -> DB์— ๋ฆฌ๋ทฐ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์ „์— redis์— ์ „๋ถ€๋‹ค ์ €์žฅํ•ด๋‘๊ณ , ๋ฆฌ๋ทฐ ์ƒ์„ฑ์ด ๋‹ค ๋˜๋ฉด DB์— flush (77๋ฒˆ ์ฟผ๋ฆฌ๋ฅผ 1๋ฒˆ์œผ๋กœ ์ˆ˜์ •)
@@ -0,0 +1,24 @@ +# ๋ฆฌ๋ทฐ ์ƒ์„ฑ + +๋ฆฌ๋ทฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +## Request + +### HTTP METHOD : `GET` + +### url : `https://api.misik.me/reviews/{id}` +### Http Headers +- device-id: ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’ + `๋ฏธ๋ž˜์—๋„ ๋ณ€ํ•˜์ง€ ์•Š์•„์•ผํ•จ ์•ฑ์„ ์‚ญ์ œํ–ˆ๋‹ค ๋‹ค์‹œ ๊น”์•„๋„ ์•ˆ๋ณ€ํ•˜๋Š” ๊ฐ’์œผ๋กœ ์ค„ ์ˆ˜ ์žˆ๋Š”์ง€` + +### Response + +#### `Response Status 200 OK` + +```json +{ + "isSuccess": true, // ๋ฆฌ๋ทฐ๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์•˜์œผ๋ฉด false, ์ „์ฒด๊ฐ€ ์„ฑ๊ณต๋˜๋ฉด true + "id": "123456789", + "review": "์นด์•ผํ† ์Šค๋Š” ์ˆจ๊ฒจ์ ธ ์žˆ๋Š” ์นด์•ผ์žผ๊ณผ ๋ฒ„ํ„ฐ๊ฐ€ ํ™•์‹คํžˆ ๊ฐ€๋“ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ๊ฐ€๊ฒŒ์˜ ๋ถ„์œ„๊ธฐ๋Š” ์•„๋Š‘ํ•˜๊ณ  ํŽธ์•ˆํ•˜๊ณ  ๋ฐ”๊นฅ์ชฝ์— ์žˆ๊ณ  ์‚ฌ๋ž‘ํ•˜๋Š” ์‹œ๊ฐ„์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์ž…๋‹ˆ๋‹ค. ๋ฌด์—‡๋ณด๋‹ค ๊ฐ€๊ฒฉ์— ๋น„ํ•ด ์Œ์‹์˜ ํ’ˆ์งˆ์ด ์ •๋ง ํ›Œ๋ฅญํ•ด์„œ, ๋งˆ์Œ์— ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค." +} +```
Unknown
๋„ต๋„ต ์„œ๋ฒ„์‚ฌ์ด๋“œ ํด๋ง (60์ดˆ ๋Œ€๊ธฐ) ๋•Œ๋ฌธ์— ์ถ”๊ฐ€๋œ ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค! ๋ฆฌ๋ทฐ๊ฐ€ ์ƒ์„ฑ์ค‘์ด๋ฉด false, ๋ฆฌ๋ทฐ๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ์œผ๋ฉด true๋ฅผ ์‘๋‹ตํ•ด์ฃผ๋ ค๊ณ  ํ•ด์š”. > ์•„์˜ˆ ์—†๋Š” ๋ฆฌ๋ทฐid๋ฅผ ์กฐํšŒํ•˜๋ ค๊ณ  ํ•จ ์—๋Ÿฌ ์‘๋‹ต์ด๋ž‘์€ ๋‹ค๋ฅธ๋‚ด์šฉ๊ฐ™์•„์„œ, ์—๋Ÿฌ ์‘๋‹ตํ…œํ”Œ๋ฆฟ์€ ๋”ฐ๋กœ ์ •์˜ํ•ด๋ณด๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ํ˜„์žฌ๋Š” ์—†๋Š” ๋ฆฌ๋ทฐ๋ฅผ ์กฐํšŒํ•˜๋ ค๊ณ  ํ•˜๋ฉด 400 BadRequest๋กœ ์‘๋‹ตํ•˜๊ณ  ์žˆ์”๋‹ˆ๋‹ค.
@@ -0,0 +1,17 @@ +package me.misik.api.api + +import me.misik.api.app.ReCreateReviewFacade +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +class ReviewController( + private val reCreateReviewFacade: ReCreateReviewFacade, +) { + + @PostMapping("reviews/{id}/re-create") + fun reCreateReview( + @PathVariable("id") id: Long, + ) = reCreateReviewFacade.reCreateReviewInBackground(id) +}
Kotlin
์˜คํƒ€์ž…๋‹ˆ๋‹ค! ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค ๐Ÿฅณ
@@ -0,0 +1,17 @@ +package me.misik.api.api + +import me.misik.api.app.ReCreateReviewFacade +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +class ReviewController( + private val reCreateReviewFacade: ReCreateReviewFacade, +) { + + @PostMapping("reviews/{id}/re-create") + fun reCreateReview( + @PathVariable("id") id: Long, + ) = reCreateReviewFacade.reCreateReviewInBackground(id) +}
Kotlin
์กฐํšŒ, ์ƒ์„ฑ(๋ฐ ์žฌ์ƒ์„ฑ) ๋‘ ์ผ€์ด์Šค ๋‹ค ์บ์‹ฑ ๊ฐ€์‹œ์ฃ ! ๐Ÿ‘
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
final ๋กœ ์„ ์–ธํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค~
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
check ๋ฉ”์„œ๋“œ๋“ค์ด public ์ธ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”~?
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
java 8 ์˜ stream map ์„ ์จ๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
์ ‘๊ทผ์ œ์–ด์ž๋ฅผ package-private ์œผ๋กœ ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
Set<LottoNo> ๋กœ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”~
@@ -0,0 +1,46 @@ +import java.util.Objects; + +public class LottoNo implements Comparable<LottoNo> { + private final static int INVALID_NUM = 0; + public final static LottoNo INVALID_LOTTO_NO = new LottoNo(INVALID_NUM); + + private int lottoNumber; + + public LottoNo(int lottoNumber) { + try { + this.lottoNumber = validateLottoNo(lottoNumber); + } catch (IllegalArgumentException e) { + this.lottoNumber = INVALID_NUM; + } + } + + public int getLottoNumber() { + return lottoNumber; + } + + private int validateLottoNo(int lottoNumber) { + if (lottoNumber < 1 || lottoNumber > 45) { + throw new IllegalArgumentException(); + } + + return lottoNumber; + } + + @Override + public int hashCode() { + return Objects.hashCode(lottoNumber); + } + + @Override + public boolean equals(Object obj) { + if (lottoNumber == ((LottoNo)obj).lottoNumber) + return true; + + return false; + } + + @Override + public int compareTo(LottoNo o) { + return lottoNumber - o.lottoNumber; + } +}
Java
LottoNo ๋Š” ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š” lottoNumber ํ•˜๋‚˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผํ•˜๋ฏ€๋กœ final ํ‚ค์›Œ๋“œ๋ฅผ ๋„ฃ์–ด๋„ ๋  ๊ฒƒ ๊ฐ™๋„ค์š” ใ…Žใ…Ž
@@ -0,0 +1,46 @@ +import java.util.Objects; + +public class LottoNo implements Comparable<LottoNo> { + private final static int INVALID_NUM = 0; + public final static LottoNo INVALID_LOTTO_NO = new LottoNo(INVALID_NUM); + + private int lottoNumber; + + public LottoNo(int lottoNumber) { + try { + this.lottoNumber = validateLottoNo(lottoNumber); + } catch (IllegalArgumentException e) { + this.lottoNumber = INVALID_NUM; + } + } + + public int getLottoNumber() { + return lottoNumber; + } + + private int validateLottoNo(int lottoNumber) { + if (lottoNumber < 1 || lottoNumber > 45) { + throw new IllegalArgumentException(); + } + + return lottoNumber; + } + + @Override + public int hashCode() { + return Objects.hashCode(lottoNumber); + } + + @Override + public boolean equals(Object obj) { + if (lottoNumber == ((LottoNo)obj).lottoNumber) + return true; + + return false; + } + + @Override + public int compareTo(LottoNo o) { + return lottoNumber - o.lottoNumber; + } +}
Java
์Œ.. RuntimeException ์„ ๋ฐœ์ƒ์‹œํ‚ค๊ณ  catch ๋ฅผ ๊ตณ์ด ํ•˜๋Š” ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”? checkedException ๊ณผ uncheckedException ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~
@@ -0,0 +1,46 @@ +import java.util.Objects; + +public class LottoNo implements Comparable<LottoNo> { + private final static int INVALID_NUM = 0; + public final static LottoNo INVALID_LOTTO_NO = new LottoNo(INVALID_NUM); + + private int lottoNumber; + + public LottoNo(int lottoNumber) { + try { + this.lottoNumber = validateLottoNo(lottoNumber); + } catch (IllegalArgumentException e) { + this.lottoNumber = INVALID_NUM; + } + } + + public int getLottoNumber() { + return lottoNumber; + } + + private int validateLottoNo(int lottoNumber) { + if (lottoNumber < 1 || lottoNumber > 45) { + throw new IllegalArgumentException(); + } + + return lottoNumber; + } + + @Override + public int hashCode() { + return Objects.hashCode(lottoNumber); + } + + @Override + public boolean equals(Object obj) { + if (lottoNumber == ((LottoNo)obj).lottoNumber) + return true; + + return false; + } + + @Override + public int compareTo(LottoNo o) { + return lottoNumber - o.lottoNumber; + } +}
Java
๊ตณ์ด ๋ฉ”์„œ๋“œ๋กœ ๋นผ์ง€ ์•Š์•„๋„ ๋  ๊ฒƒ ๊ฐ™์•„์š”
@@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.List; + +public class LottoRankResult { + private List<Rank> ranks; + + public LottoRankResult(WinningLotto winningLotto, LottoTicket lottoTicket) { + this.ranks = new ArrayList<>(); + + for (Lotto lotto : lottoTicket.getAllLottoGames()) { + ranks.add( + Rank.valueOf( + winningLotto.getCountOfSameNumber(lotto), + winningLotto.isWinningBonus(lotto) + ) + ); + } + } + + public int getCount(Rank rank) { + return (int) ranks.stream().filter(t -> t.equals(rank)).count(); + } + + public Money getTotalWinningMoney() { + Money earnings = Money.ZERO; + + for (Rank rank : ranks) { + earnings = earnings.add(rank.getWinningMoney()); + } + + return earnings; + } + + public double getEarningsRate(Money invest) { + Money earnings = getTotalWinningMoney(); + + return (double)(earnings.intValue()) / invest.intValue() * 100.0; + } + +} \ No newline at end of file
Java
๋ญ”๊ฐ€ ์ด๋ฆ„์ด ๊ฒฐ๊ณผ๋ฅผ ๋‹ด๋Š” ๋ฐ์ดํ„ฐ ๊ทธ๋ฆ‡ ๊ฐ™์€ ๋А๋‚Œ์ด๋ผ LottoCalculator LottoResultCalculator LottoRankCalculator ๊ฐ™์€ ๋„ค์ด๋ฐ์œผ๋กœ ๋ณ€๊ฒฝํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ๊ทธ์— ๋งž์ถฐ์„œ ๋ฉ”์„œ๋“œ ๋„ค์ด๋ฐ๋„ ๋ณ€๊ฒฝํ•˜๋ฉด ๋‹จ์ˆœํžˆ set ๋œ ๋ฐ์ดํ„ฐ๋ฅผ get ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ƒํƒœ์™€ ํ–‰์œ„๋ฅผ ๊ฐ–๋Š” ๊ฐ์ฒด์ง€ํ–ฅ์ ์ธ ๋„ค์ด๋ฐ์ด ๋  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค
@@ -0,0 +1,22 @@ +import java.util.ArrayList; +import java.util.List; + +public class Lottos { + private List<Lotto> lottos; + + public Lottos() { + this.lottos = new ArrayList<>(); + } + + public List<Lotto> getLottos() { + return lottos; + } + + public void addLotto(Lotto lotto) { + lottos.add(lotto); + } + + public int getSize() { + return lottos.size(); + } +}
Java
Lottos ๊ฐ€ ๊ฐ€์ง€๋Š” ํ–‰์œ„๊ฐ€ ํ•˜๋‚˜๋„ ์—†๋Š”๋ฐ์š”, ๋‹ค๋ฅธ ๊ฐ์ฒด์—์„œ ์œ„์ž„ํ• ๋งŒํ•œ๊ฒŒ ์—†์„๊นŒ์š”? get์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์€ Lottos ์˜ tell dont ask ์›์น™์ด ์•ˆ์ง€์ผœ์ง€๊ณ  ์žˆ๋‹ค๋Š” ๋œป์ด๊ณ , ์—ฌ๊ธฐ๋กœ ์œ„์ž„ํ• ๋งŒํ•œ ์ฑ…์ž„์ด ์‚ฐ์žฌํ•ด ์žˆ๋‹ค๋Š” ๋œป์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,29 @@ +import java.util.List; + +public class WinningLotto { + private Lotto winningLotto; + private LottoNo bonusNo; + + public WinningLotto(List<LottoNo> winningLottoNumbers, LottoNo lottoNo) { + if (winningLottoNumbers == null) { + throw new IllegalArgumentException("'lotto' must not be null"); + } + if (lottoNo == null) { + throw new IllegalArgumentException("'lottoNo' must not be null"); + } + + this.winningLotto = new Lotto(winningLottoNumbers); + this.bonusNo = lottoNo; + } + + public int getCountOfSameNumber(Lotto purchasedLotto) { + return (int) winningLotto.getLottoNums() + .stream() + .filter(purchasedLotto.getLottoNums()::contains) + .count(); + } + + public boolean isWinningBonus(Lotto purchasedLotto) { + return purchasedLotto.getLottoNums().contains(bonusNo); + } +}
Java
Lotto๋ฅผ ์ƒ์† ๋ฐ›์„ ์ˆ˜๋„ ์žˆ์—ˆ๋Š”๋ฐ ์ด๋ ‡๊ฒŒ ํ•ฉ์„ฑ์„ ์‚ฌ์šฉํ•˜์…จ๋„ค์š”. ๐Ÿ‘ ํ˜น์‹œ๋ผ๋„ ์šฐ์—ฐํžˆ ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ•˜์‹ ๊ฑฐ๋ผ๋ฉด, ์ƒ์†๊ณผ ํ•ฉ์„ฑ์„ ๊ตฌ๊ธ€๋ง ํ•ด๋ณด์‹œ๋ฉด ๊ด€๋ จ ์ž๋ฃŒ๋ฅผ ์ฐพ์œผ์‹ค ์ˆ˜ ์žˆ์„๊ฒ๋‹ˆ๋‹ค ~
@@ -0,0 +1,43 @@ +import java.util.Scanner; + +public class LottoApplication { + private static boolean APP_SUCCESS = false; + + public static void main(String[] args) { + runUntilAppSuccess(); + } + + public static void runUntilAppSuccess() { + while (!APP_SUCCESS) { + run(); + } + } + + public static void run() { + final Scanner scanner = new Scanner(System.in); + int countOfManualLotto; + + try { + LottoService lottoService = new LottoService( + InputView.scanMoney(scanner), + countOfManualLotto = InputView.scanCountOfManualLotto(scanner), + InputView.scanNumbersOfManualLotto(scanner, countOfManualLotto), + new LottoSeller() + ); + + lottoService.purchaseLottoTicket(); + lottoService.printPurchaseResult(); + + lottoService.setWinningLotto( + InputView.scanWinningLotto(scanner), + InputView.scanBonusNo(scanner) + ); + + lottoService.printWinningResult(); + + APP_SUCCESS = true; + } catch (OutOfConditionException | IllegalArgumentException e) { + e.printStackTrace(); + } + } +}
Java
LottoGame ์ด๋ผ๋Š” ๋„ค์ด๋ฐ์€ ์–ด๋–จ๊นŒ์š”
@@ -0,0 +1,43 @@ +import java.util.Scanner; + +public class LottoApplication { + private static boolean APP_SUCCESS = false; + + public static void main(String[] args) { + runUntilAppSuccess(); + } + + public static void runUntilAppSuccess() { + while (!APP_SUCCESS) { + run(); + } + } + + public static void run() { + final Scanner scanner = new Scanner(System.in); + int countOfManualLotto; + + try { + LottoService lottoService = new LottoService( + InputView.scanMoney(scanner), + countOfManualLotto = InputView.scanCountOfManualLotto(scanner), + InputView.scanNumbersOfManualLotto(scanner, countOfManualLotto), + new LottoSeller() + ); + + lottoService.purchaseLottoTicket(); + lottoService.printPurchaseResult(); + + lottoService.setWinningLotto( + InputView.scanWinningLotto(scanner), + InputView.scanBonusNo(scanner) + ); + + lottoService.printWinningResult(); + + APP_SUCCESS = true; + } catch (OutOfConditionException | IllegalArgumentException e) { + e.printStackTrace(); + } + } +}
Java
lottoService ์— set ํ•˜๊ณ  get ํ•˜๊ณ  ์ ˆ์ฐจ์ง€ํ–ฅ์ ์ธ ๋ฐฉ์‹์œผ๋กœ ์ฝ”๋“œ๊ฐ€ ์งœ์—ฌ์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ๋กœ์ง์ด lottoService ๋ฅผ ํ†ตํ•˜๋ฉด์„œ ๊ฒฐ๊ตญ ์ด ํด๋ž˜์Šค๋Š” ์ ์  ๋น„๋Œ€ํ•ด์งˆํ…๋ฐ์š” ์ข‹์€ ๊ฐœ์„  ๋ฐฉ๋ฒ•์ด ์—†์„๊นŒ์š”~?
@@ -0,0 +1,48 @@ +import java.util.Arrays; + +public enum Rank { + FIRST(6, 2000000000), + SECOND(5, 30000000), + THIRD(5, 1500000), + FOURTH(4, 50000), + FIFTH(3, 5000), + MISS(0, 0); + + private int countOfMatch; + private Money winningMoney; + + Rank(int countOfMatch, int winningMoney) { + this.countOfMatch = countOfMatch; + this.winningMoney = Money.valueOf(winningMoney); + } + + public static Rank valueOf(int countOfGame, boolean matchBonus) { + if (countOfGame == SECOND.getCountOfMatch()) { + return getSecondOrThird(matchBonus); + } + + return Arrays.stream(values()) + .filter(r -> countOfGame == r.countOfMatch) + .findFirst() + .orElse(MISS); + } + + public static Rank[] valuesNotMiss() { + return new Rank[]{FIRST, SECOND, THIRD, FOURTH, FIFTH}; + } + + private static Rank getSecondOrThird(boolean matchBonus) { + if (matchBonus) + return SECOND; + return THIRD; + } + + public int getCountOfMatch() { + return countOfMatch; + } + + public Money getWinningMoney() { + return winningMoney; + } + +}
Java
์ค‘๊ด„ํ˜ธ๊ฐ€ ๋น ์กŒ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,21 @@ +public class RankResult { + private Rank rank; + private int countOfRank; + + RankResult(Rank rank) { + this.rank = rank; + this.countOfRank = 0; + } + + public Rank getRank() { + return rank; + } + + public int getCountOfRank() { + return countOfRank; + } + + public void countUp(int count) { + countOfRank += count; + } +}
Java
๋ฐ์ดํ„ฐ๋“ค์„ ํด๋ž˜์Šค๋กœ ๋ฌถ๋Š” ๊ฒƒ์ด ๊ฐ์ฒด์ง€ํ–ฅ์€ ์•„๋‹™๋‹ˆ๋‹ค~ RankResult ๋„ ๊ฒฐ๊ตญ ๋ฐ์ดํ„ฐ์™€ get ๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ์œ ์˜๋ฏธํ•œ ํ–‰์œ„๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค ใ… ใ…  ๋ถˆํ•„์š”ํ•œ ๊ฐ์ฒด๊ฐ€ ์•„๋‹Œ์ง€, ์œ ์˜๋ฏธํ•œ ํ–‰์œ„๋ฅผ ๊ฐ€์ง„ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค๋ ค๋ฉด ์–ด๋–ค ํ–‰์œ„๋ฅผ ๋ถ€์—ฌํ•ด์•ผํ•˜๋Š”์ง€ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~
@@ -0,0 +1,50 @@ +import java.util.List; + +public class LottoSeller { + private LottoPurchaseService lottoPurchaseService; + private Money change; + + public LottoSeller() { + change = Money.ZERO; + lottoPurchaseService = new LottoPurchaseService(); + } + + public LottoTicket sellTicketTo(LottoUser lottoUser) throws OutOfConditionException { + Money investMoney = LottoPurchaseService + .validatePurchase( + lottoUser.getInvestMoney(), + lottoUser.getCountOfManualLotto() + ); + + this.change = LottoPurchaseService + .calculateChange(investMoney); + + return lottoPurchaseService + .createLottoTicket( + investMoney, + getCountOfAutoGame(investMoney, lottoUser.getCountOfManualLotto()), + changeToLottos(lottoUser.getNumbersOfManualLottos()) + ); + } + + public int getCountOfAutoGame(Money investMoney, int countOfManualLotto) { + return investMoney.divideBy(LottoPurchaseService.LOTTO_PRICE).intValue() + - countOfManualLotto; + } + + private Lottos changeToLottos(List<List<LottoNo>> numbers0fManualLottos) { + Lottos manualLottos = new Lottos(); + + for (List<LottoNo> lottoNums : numbers0fManualLottos) { + manualLottos.addLotto( + lottoPurchaseService.createManualLotto(lottoNums) + ); + } + + return manualLottos; + } + + public Money getChange() { + return change; + } +}
Java
Service ๋ผ๋Š” ๋„ค์ด๋ฐ์„ ์“ฐ์‹œ๋Š”๊ฑธ๋กœ ๋ด์„œ ์›น ์ชฝ ์ž๋ฃŒ๋ฅผ ๋ณด์‹  ๊ฒƒ ๊ฐ™์€๋ฐ, controller, service, repository ์ด๋Ÿฐ layered architecture ๋Š” ์ง€๊ธˆ ์ €ํฌ๊ฐ€ ํ•˜๊ณ  ์žˆ๋Š” ๊ฐ์ฒด์ง€ํ–ฅ๊ณผ ๊ฑฐ๋ฆฌ๊ฐ€ ์ข€ ์žˆ์Šต๋‹ˆ๋‹ค ~ service ๋ผ๋Š” ๋„ค์ด๋ฐ์„ ์‚ฌ์šฉํ•˜๊ธฐ๋ณด๋‹ค๋Š” ์ข€ ๋” ๊ตฌ์ฒด์ ์ด๊ณ  ๋ˆ„๊ตฌ๋‚˜ ๊ธ€ ์ฝ๋“ฏ์ด ๋ณผ ์ˆ˜ ์žˆ๋Š” ๋„ค์ด๋ฐ์„ ํ•˜์‹œ๋ฉด ํ•ด๋‹น ๊ฐ์ฒด์— ๋ถ€์—ฌํ•˜๋Š” ์ฑ…์ž„๊ณผ ํ–‰์œ„๋“ค๋„ ๋‹ฌ๋ผ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค ~ ๋„ค์ด๋ฐ์€ ๋‹จ์ˆœํžˆ ์‹œ๊ฐ์ ์ธ ํšจ๊ณผ ๊ทธ ์ด์ƒ์˜ ๊ฐ€์น˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,50 @@ +import java.util.List; + +public class LottoSeller { + private LottoPurchaseService lottoPurchaseService; + private Money change; + + public LottoSeller() { + change = Money.ZERO; + lottoPurchaseService = new LottoPurchaseService(); + } + + public LottoTicket sellTicketTo(LottoUser lottoUser) throws OutOfConditionException { + Money investMoney = LottoPurchaseService + .validatePurchase( + lottoUser.getInvestMoney(), + lottoUser.getCountOfManualLotto() + ); + + this.change = LottoPurchaseService + .calculateChange(investMoney); + + return lottoPurchaseService + .createLottoTicket( + investMoney, + getCountOfAutoGame(investMoney, lottoUser.getCountOfManualLotto()), + changeToLottos(lottoUser.getNumbersOfManualLottos()) + ); + } + + public int getCountOfAutoGame(Money investMoney, int countOfManualLotto) { + return investMoney.divideBy(LottoPurchaseService.LOTTO_PRICE).intValue() + - countOfManualLotto; + } + + private Lottos changeToLottos(List<List<LottoNo>> numbers0fManualLottos) { + Lottos manualLottos = new Lottos(); + + for (List<LottoNo> lottoNums : numbers0fManualLottos) { + manualLottos.addLotto( + lottoPurchaseService.createManualLotto(lottoNums) + ); + } + + return manualLottos; + } + + public Money getChange() { + return change; + } +}
Java
์  ํ•˜๋‚˜ ์ฐ์„ ๋•Œ๋Š” ์ค„๋ฐ”๊ฟˆ์„ ์•ˆํ•˜์‹œ๋Š”๊ฒŒ ์ผ๋ฐ˜์ ์ž…๋‹ˆ๋‹ค. ๋ฉ”์†Œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ๋„ 3๊ฐœ ์ด์ƒ๋ถ€ํ„ฐ ์—”ํ„ฐ๋ฅผ ์น˜์‹œ๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,42 @@ +import java.util.List; + +public class LottoService { + LottoUser lottoUser; + LottoSeller lottoSeller; + LottoTicket purchasedLottoTicket = null; + WinningLotto winningLotto = null; + PurchaseResultView purchaseResultView = null; + WinningResultView winningResultView = null; + + public LottoService(Money investMoney, int countOfManualLotto, List<List<LottoNo>> numbersOfManualLotto, + LottoSeller lottoSeller) { + this.lottoUser = new LottoUser(investMoney, countOfManualLotto, numbersOfManualLotto); + this.lottoSeller = lottoSeller; + } + + public LottoTicket purchaseLottoTicket() throws OutOfConditionException { + purchasedLottoTicket = lottoSeller.sellTicketTo(lottoUser); + lottoUser.setLottoTicket(purchasedLottoTicket); + + return purchasedLottoTicket; + } + + public void printPurchaseResult() { + purchaseResultView = new PurchaseResultView(); + + purchaseResultView.notifyIfChangeLeft(lottoSeller); + purchaseResultView.printPurchasedTicket(lottoUser); + } + + public void setWinningLotto(List<LottoNo> winningLottoNumbers, LottoNo bonusNo) { + winningLotto = new WinningLotto(winningLottoNumbers, bonusNo); + } + + public void printWinningResult() { + winningResultView = new WinningResultView(); + + winningResultView.printWinningResult(winningLotto, purchasedLottoTicket); + winningResultView.printEarningsRate(winningLotto, purchasedLottoTicket); + } + +}
Java
set์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฐ์ฒด์ง€ํ–ฅ ์ƒํ™œ์ฒด์กฐ ๊ทœ์น™์„ ์ ์šฉํ•ด๋ณด์‹œ๋ฉด ์ฝ”๋“œ์˜ ์„ค๊ณ„๊ฐ€ ๋‹ฌ๋ผ์งˆ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,43 @@ +import java.util.ArrayList; +import java.util.List; + +public class LottoTicket { + private Money ticketPrice; + private Lottos autoLottos; + private Lottos manualLottos; + + public LottoTicket(Money ticketPrice, Lottos autoLottos, Lottos manualLottos) { + this.ticketPrice = ticketPrice; + this.autoLottos = autoLottos; + this.manualLottos = manualLottos; + } + + public List<Lotto> getAllLottoGames() { + List<Lotto> lottos = new ArrayList<>(); + + lottos.addAll(getManualLottos()); + lottos.addAll(getAutoLottos()); + + return lottos; + } + + public List<Lotto> getAutoLottos() { + return autoLottos.getLottos(); + } + + public List<Lotto> getManualLottos() { + return manualLottos.getLottos(); + } + + public int getCountOfAutoLotto() { + return autoLottos.getSize(); + } + + public int getCountOfManualLotto() { + return manualLottos.getSize(); + } + + public Money getTicketPrice() { + return ticketPrice; + } +}
Java
์—ฌ๊ธฐ๋„ ํ–‰์œ„๊ฐ€ ์—†๊ณ  ๋ฐ์ดํ„ฐ + getter ๋ฟ์ด๋„ค์š”. ๊ทธ๋Ÿฐ๋ฐ ์ด๋ ‡๊ฒŒ ํด๋ž˜์Šค๋ฅผ ๋‚˜๋ˆ ๋ณด๋ ค๊ณ  ์ตœ๋Œ€ํ•œ ์‹œ๋„ํ•˜์‹  ์  ๐Ÿ‘
@@ -0,0 +1,35 @@ +import java.util.List; + +public class LottoUser { + private Money investMoney; + private int countOfManualLotto; + private List<List<LottoNo>> numbersOfManualLottos; + + private LottoTicket lottoTicket; + + public LottoUser(Money investMoney, int countOfManualLotto, List<List<LottoNo>> numbersOfManualLottos) { + this.investMoney = investMoney; + this.countOfManualLotto = countOfManualLotto; + this.numbersOfManualLottos = numbersOfManualLottos; + } + + public void setLottoTicket(LottoTicket lottoTicket) { + this.lottoTicket = lottoTicket; + } + + public LottoTicket getLottoTicket() { + return lottoTicket; + } + + public int getCountOfManualLotto() { + return countOfManualLotto; + } + + public List<List<LottoNo>> getNumbersOfManualLottos() { + return numbersOfManualLottos; + } + + public Money getInvestMoney() { + return investMoney; + } +}
Java
์—ฌ๊ธฐ๋„ setter getter ๋ฟ ์ด๋„ค์š” ใ… 
@@ -0,0 +1,65 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public final class LottoPurchaseService { + public final static Money LOTTO_PRICE = Money.valueOf(1000); + + public static Money validatePurchase(Money inputMoney, int countOfManualLotto) throws OutOfConditionException { + if (inputMoney.intValue() < LOTTO_PRICE.intValue()) { + throw new OutOfConditionException(LOTTO_PRICE + "์› ์ด์ƒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค."); + } + + if (countOfManualLotto * LOTTO_PRICE.intValue() > inputMoney.intValue()) { + throw new IllegalArgumentException("๊ธˆ์•ก์ด ์ž‘์•„ ์›ํ•˜๋Š” ๋งŒํผ ์ˆ˜๋™ ๋กœ๋˜๋ฅผ ์‚ด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + + return inputMoney; + } + + public static Money calculateChange(Money inputMoney) { + return Money.valueOf(inputMoney.intValue() % LOTTO_PRICE.intValue()); + } + + public Lotto createManualLotto(List<LottoNo> lottoNums) { + Collections.sort(lottoNums); + return new Lotto(lottoNums); + } + + public Lotto createAutoLotto() { + List<LottoNo> auto = new ArrayList<>(shuffleAllLottoNo().subList(0, 6)); + Collections.sort(auto); + + return new Lotto(auto); + } + + public Lottos createAutoLottos(int countOfAutoLotto) { + Lottos autoLottos = new Lottos(); + + for (int i = 0; i < countOfAutoLotto; i++) { + autoLottos.addLotto( + createAutoLotto() + ); + } + + return autoLottos; + } + + public LottoTicket createLottoTicket(Money ticketPrice, int countOfAutoLotto, Lottos manualLottos) { + return new LottoTicket( + ticketPrice, + createAutoLottos(countOfAutoLotto), + manualLottos); + } + + private List<LottoNo> shuffleAllLottoNo() { + List<LottoNo> lottoNums = new ArrayList<>(); + + for (int i = 1; i <= 45; i++) { + lottoNums.add(new LottoNo(i)); + } + Collections.shuffle(lottoNums); + + return lottoNums; + } +}
Java
๋ฐ์ดํ„ฐ์™€ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋”ฐ๋กœ ์žˆ๋Š” ๊ฒƒ == ์ ˆ์ฐจ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ˜„ ์ƒํ™ฉ : ๋ฐ์ดํ„ฐ = LottoSeller, Ticket, User ๋“ฑ (๋ฐ์ดํ„ฐ + getter) ํ”„๋กœ์„ธ์Šค = Service (๋ฐ์ดํ„ฐ get ํ•ด์„œ ๋กœ์ง ์ฒ˜๋ฆฌ) ๋‹ต : MVC์™€ layered architecture๋ฅผ ์žŠ๊ณ  view ์™€ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ๋งŒ ๊ธฐ์–ตํ•˜๊ณ  ์งœ๋ณด๊ธฐ
@@ -0,0 +1,65 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; +import java.util.stream.Collectors; + +public final class InputView { + + public static Money scanMoney(Scanner scanner) { + System.out.println("\n๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + return Money.valueOf(Integer.parseInt(scanner.nextLine())); + } + + public static int scanCountOfManualLotto(Scanner scanner) { + System.out.println("\n์ˆ˜๋™์œผ๋กœ ๊ตฌ๋งคํ•  ๋กœ๋˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + return Integer.parseInt(scanner.nextLine()); + } + + public static List<List<LottoNo>> scanNumbersOfManualLotto(Scanner scanner, int countOfManualGame) { + System.out.println("\n์ˆ˜๋™์œผ๋กœ ๊ตฌ๋งคํ•  ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + List<List<LottoNo>> manualLotto = new ArrayList<>(); + String input = scanner.nextLine(); + int count = countOfManualGame; + + while (!input.isEmpty() && count != 0) { + count--; + addScannedNumbers(manualLotto, input); + input = scanner.nextLine(); + } + + return manualLotto; + } + + private static void addScannedNumbers(List<List<LottoNo>> manualLotto, String input) { + manualLotto.add( + Arrays.asList(input.replaceAll(" ", "").split(",")) + .stream() + .map(Integer::parseInt) + .map(LottoNo::new) + .collect(Collectors.toList()) + ); + } + + public static List<LottoNo> scanWinningLotto(Scanner scanner) { + System.out.println("\n์ง€๋‚œ ์ฃผ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + return Arrays.asList(scanner.nextLine() + .replaceAll(" ", "") + .split(",")) + .stream() + .map(Integer::parseInt) + .map(LottoNo::new) + .collect(Collectors.toList()); + } + + public static LottoNo scanBonusNo(Scanner scanner) { + System.out.println("๋ณด๋„ˆ์Šค ๋ณผ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + return new LottoNo(Integer.parseInt(scanner.nextLine())); + } + +}
Java
view ์—์„œ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ scan ํ•ด์˜ค๋Š” ์ฑ…์ž„๋งŒ ์žˆ์Šต๋‹ˆ๋‹ค. ์ง€๊ธˆ์€ ๋ณ€ํ™˜ ๋กœ์ง๊นŒ์ง€ ์—ฌ๊ธฐ์„œ ์ฒ˜๋ฆฌํ•˜๊ณ  ์žˆ๋„ค์š”~!
@@ -0,0 +1,29 @@ +public final class PurchaseResultView { + public void notifyIfChangeLeft(LottoSeller seller) { + if (!seller.getChange().equals(Money.ZERO)) { + System.out.println("์ž”๋ˆ " + seller.getChange() + "์›์ด ๋‚จ์•˜์Šต๋‹ˆ๋‹ค."); + System.out.println(); + } + } + + public void printPurchasedTicket(LottoUser lottoUser) { + LottoTicket lottoTicket = lottoUser.getLottoTicket(); + + System.out.println( + "์ˆ˜๋™์œผ๋กœ " + lottoTicket.getCountOfManualLotto() + + "์žฅ, ์ž๋™์œผ๋กœ " + lottoTicket.getCountOfAutoLotto() + + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค." + ); + + for (Lotto manualGame : lottoTicket.getManualLottos()) { + System.out.println(manualGame.getNums()); + } + + for (Lotto autoGame : lottoTicket.getAutoLottos()) { + System.out.println(autoGame.getNums()); + } + + System.out.println(); + } + +}
Java
finall class ๋กœ ํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค~
@@ -1,23 +1,20 @@ <template> - <button - @click=" - () => { - if (!props.disabled) props.onClick(); - } - " - :class="getNextButtonStyle()" - > - <slot></slot> + <button @click="handleNextButtonClick" :class="getNextButtonStyle()"> + <slot /> </button> </template> <script setup lang="ts"> const props = defineProps<{ - isPrimary?: boolean; + isPrimary?: boolean | undefined; onClick: () => void; - disabled?: boolean; + disabled?: boolean | undefined; }>(); +const handleNextButtonClick = () => { + if (!props.disabled) props.onClick(); +}; + const getNextButtonStyle = () => ({ 'h-fit w-[340px] rounded-2xl border-0 p-6 text-large font-bold mb-6': true, 'bg-primary-light dark:bg-primary-dark': props.isPrimary,
Unknown
๋‹จ์ˆœ ๊ถ๊ธˆ์ฆ์œผ๋กœ ์งˆ๋ฌธ๋“œ๋ฆฝ๋‹ˆ๋‹ค. undefined๋ฅผ ํƒ€์ž…์œผ๋กœ ์ง€์ •ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”? NextButton.vue์˜ ๋ถ€๋ชจ ์ปดํฌ๋„ŒํŠธ์—์„œ isPrimary ๊ฐ’์„ ๋ถ€์—ฌํ•˜์ง€ ์•Š์„ ๋•Œ๊ฐ€ ์žˆ์–ด undefined๋ฅผ ํฌํ•จํ•œ ๊ฒƒ์œผ๋กœ ๋ณด์ด๋Š”๋ฐ, ์ด ๊ฒฝ์šฐ๋Š” ? ๋งŒ์œผ๋กœ๋„ ์ถฉ๋ถ„ํžˆ ํ‘œํ˜„์ด ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํŠนํžˆ boolean์ด๊ธฐ๋•Œ๋ฌธ์— undefined์ผ ๋•Œ falsyํ•˜๊ฒŒ ์ธ์‹์ด ๋  ๊ฒƒ ๊ฐ™์€๋ฐ ์ถ”๊ฐ€ํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค~
@@ -3,8 +3,8 @@ <p class="text-medium font-semi_bold">{{ title }}</p> <div class="flex gap-x-3"> <button - v-for="size in sizes" - :key="size.id" + v-for="(size, index) in sizes" + :key="getButtonKey(size, index)" class="flex flex-col items-center justify-between gap-y-[10px]" @click="handleSizeClick(size)" > @@ -23,9 +23,10 @@ </template> <script setup lang="ts"> -import { Size } from '@interface/goods'; +import { Size } from '@interface/sizes'; import { useUserSelectStore } from '@store/storeUserSelect'; import { PLACE_HOLD_IMAGE_URL } from '@constants'; +import { storeToRefs } from 'pinia'; defineProps<{ title: string; @@ -38,11 +39,12 @@ const getImageWidth = (size: Size) => { return 74; }; -const { userSelect, setUserSelectSizeId, setUserSelectSizeValue } = - useUserSelectStore(); +const store = useUserSelectStore(); +const { userSelect } = storeToRefs(store); +const { setUserSelectSizeId, setUserSelectSizeValue } = store; const handleSizeClick = (size: Size) => { - if (userSelect.sizeId === size.id) { + if (userSelect.value.sizeId === size.id) { setUserSelectSizeId(0); setUserSelectSizeValue(0); return; @@ -51,11 +53,13 @@ const handleSizeClick = (size: Size) => { setUserSelectSizeValue(size.value); }; +const getButtonKey = (size: Size, index: number) => `size-${size.id}-${index}`; + const getUserSelectStyle = (size: Size) => ({ 'flex h-[74px] w-[74px] items-center justify-center rounded-2xl border-[3px] bg-gray_01-light dark:bg-gray_01-dark': true, - 'border-secondary-light': userSelect.sizeId === size.id, + 'border-secondary-light': userSelect.value.sizeId === size.id, 'border-gray_01-light dark:border-gray_01-dark': - userSelect.sizeId !== size.id, + userSelect.value.sizeId !== size.id, }); </script>
Unknown
storeToRefs ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ฐ˜์‘์„ฑ์„ ์‚ด๋ฆฌ์…จ๋„ค์š” ๐Ÿ‘
@@ -3,16 +3,12 @@ <section class="mx-auto flex h-full flex-col items-center justify-between bg-gray_00-light text-gray_05-light dark:bg-gray_00-dark dark:text-gray_05-dark sm:w-screen md:w-96" > - <ProgressNavBar prevPage="/size" pageName="ingredient" /> - <div v-if="isLoading">๋กœ๋”ฉ์ค‘์ž…๋‹ˆ๋‹ค.</div> + <ProgressNavBar prevPage="size" pageName="ingredient" /> + <Loading v-if="isLoading" /> <IngredientBoard :ingredients="data?.ingredients ?? []" v-else /> <div v-if="!isAbleToRecommend">์žฌ๋ฃŒ๋ฅผ ์กฐ๊ธˆ ๋” ๊ณจ๋ผ๋ณผ๊นŒ์š”?</div> <NextButton - :onClick=" - () => { - mutation.mutate(userItem); - } - " + :onClick="postUserItem" isPrimary :disabled="!isAbleToRecommend || !userSelect.sizeValue" > @@ -29,6 +25,7 @@ import { storeToRefs } from 'pinia'; import ProgressNavBar from '@containers/ProgressNavBar.vue'; import IngredientBoard from '@containers/IngredientBoard.vue'; import NextButton from '@components/NextButton.vue'; +import Loading from '@src/components/Loading.vue'; import { useUserSelectStore } from '@store/storeUserSelect'; import { useGetIngredients } from '@apis/ingredients'; import { usePostRecipe } from '@apis/recipes'; @@ -38,6 +35,9 @@ const { userSelect, userItem } = storeToRefs(store); const { data, isLoading } = useGetIngredients(); const mutation = usePostRecipe(); +const postUserItem = () => { + mutation.mutate(userItem.value); +}; const allFlavorIdList = computed( () =>
Unknown
์„œ๋ฒ„ ์ƒํƒœ๊ด€๋ฆฌ์™€ ํด๋ผ์ด์–ธํŠธ ์ƒํƒœ๊ด€๋ฆฌ๋ฅผ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ด€๋ฆฌํ•˜์…จ๊ตฐ์š” ๐Ÿ‘
@@ -1,23 +1,20 @@ <template> - <button - @click=" - () => { - if (!props.disabled) props.onClick(); - } - " - :class="getNextButtonStyle()" - > - <slot></slot> + <button @click="handleNextButtonClick" :class="getNextButtonStyle()"> + <slot /> </button> </template> <script setup lang="ts"> const props = defineProps<{ - isPrimary?: boolean; + isPrimary?: boolean | undefined; onClick: () => void; - disabled?: boolean; + disabled?: boolean | undefined; }>(); +const handleNextButtonClick = () => { + if (!props.disabled) props.onClick(); +}; + const getNextButtonStyle = () => ({ 'h-fit w-[340px] rounded-2xl border-0 p-6 text-large font-bold mb-6': true, 'bg-primary-light dark:bg-primary-dark': props.isPrimary,
Unknown
์‚ฌ์‹ค ์ €๋„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์•˜๋‹ค๊ฐ€, ์ข€๋” ๊ฐ€์‹œ์ ์œผ๋กœ ํ‘œํ˜„ํ•˜๋ ค๊ณ  ์ž‘์„ฑ์„ ํ–ˆ์–ด์š”! ์Œ, ๋ฉ”์ด๋ธŒ๋‹˜ ๋ง์”€๋“ฃ๊ณ  ๋‹ค์‹œ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ ๊ฐ€์‹œ์„ฑ๋งŒ์œผ๋กœ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฑด ์ข€ ์˜๋ฏธ๊ฐ€ ์—†๋Š” ๊ฒƒ ๊ฐ™๊ธดํ•˜๋„ค์š”!!
@@ -3,20 +3,18 @@ class="text-gray_05-light dark:text-gray_05-dark w-6 h-6" @click="goBack" > - <slot></slot> + <slot /> </button> </template> <script setup lang="ts"> -import { useRouter } from 'vue-router'; +import { pushPage } from '@router/route.helper'; const props = defineProps<{ prevPage: string; }>(); -const router = useRouter(); - function goBack() { - router.push(props.prevPage); + pushPage(props.prevPage); } </script>
Unknown
ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋กœ ํ•ด์ฃผ์„ธ์š”~
@@ -0,0 +1,91 @@ +package christmas.Controller; + +import christmas.Domain.EventBenefitSettler; +import christmas.Domain.EventPlanner; +import christmas.Event.EventBadge; +import christmas.View.InputView; +import christmas.View.OutputView; +import java.util.Map; + +public class EventController { + public EventPlanner eventPlanner; + public EventBenefitSettler eventBenefitSettler; + + public void eventStart() { + OutputView.printWelcomeMessage(); + takeVisitDate(); + + takeOrder(); + + int preDiscountTotalOrderPrice = handlePreDiscountTotalOrderPrice(); + + handleBenefit(preDiscountTotalOrderPrice); + } + + public void takeVisitDate() { + try { + String visitDate = InputView.readVisitDate(); + eventBenefitSettler = new EventBenefitSettler(visitDate); + } catch (NumberFormatException e) { + OutputView.printException(e); + takeVisitDate(); + } catch (IllegalArgumentException e) { + OutputView.printException(e); + takeVisitDate(); + } + } + + public void takeOrder() { + try { + String orderMenu = InputView.readMenuOrder(); + eventPlanner = new EventPlanner(orderMenu); + OutputView.printOrderMenu(orderMenu); + } catch (NumberFormatException e) { + OutputView.printException(e); + takeOrder(); + } catch (IllegalArgumentException e) { + OutputView.printException(e); + takeOrder(); + } + } + + public void handleBenefit(int preDiscountTotalOrderPrice) { + Map<String, Integer> categoryCount = eventPlanner.calculateCategoryCount(); + + Map<String, Integer> receivedBenefits = handleReceivedBenefits(categoryCount, preDiscountTotalOrderPrice); + int benefitsTotalAmount = handlebenefitsTotalAmount(receivedBenefits); + handleDiscountedTotalAmount(receivedBenefits, preDiscountTotalOrderPrice); + handleEventBadge(benefitsTotalAmount); + } + + public Map<String, Integer> handleReceivedBenefits(Map<String, Integer> categoryCount, int preDiscountTotalOrderPrice){ + Map<String, Integer> receivedBenefits = eventBenefitSettler.calculateReceivedBenefits(categoryCount, + preDiscountTotalOrderPrice); + OutputView.printReceivedBenefits(receivedBenefits); + return receivedBenefits; + } + + public int handlebenefitsTotalAmount(Map<String, Integer> receivedBenefits){ + int benefitsTotalAmount = eventBenefitSettler.caculateBenefitsTotalAmount(receivedBenefits); + OutputView.printBenefitsTotalAmount(benefitsTotalAmount); + return benefitsTotalAmount; + } + + public void handleDiscountedTotalAmount(Map<String, Integer> receivedBenefits, int preDiscountTotalOrderPrice){ + int discountedTotalAmount = eventBenefitSettler.calculateDiscountedTotalAmount(receivedBenefits, + preDiscountTotalOrderPrice); + OutputView.printDiscountedTotalAmount(discountedTotalAmount); + } + + public void handleEventBadge(int benefitsTotalAmount){ + String eventBadgeType = EventBadge.findMyEventBadgeType(benefitsTotalAmount); + OutputView.printEventBadgeType(eventBadgeType); + } + + public int handlePreDiscountTotalOrderPrice() { + int preDiscountTotalOrderPrice = eventPlanner.calculatePreDiscountTotalOrderPrice(); + OutputView.printPreDicountTotalOrderPrice(preDiscountTotalOrderPrice); + OutputView.printGiftMenu(preDiscountTotalOrderPrice); + return preDiscountTotalOrderPrice; + } +}
Java
```suggestion public void takeVisitDate() { try { String visitDate = InputView.readVisitDate(); eventBenefitSettler = new EventBenefitSettler(visitDate); } catch (IllegalArgumentException e) { OutputView.printException(e); takeVisitDate(); } } ``` ์ €๋„ ๋ฐฉ๊ธˆ ์ฐพ์•„์„œ ์•Œ๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ `NumberFormatException` ์˜ ๋ถ€๋ชจ ์˜ˆ์™ธ๊ฐ€ `IllegalArgumentException` ์ด๋”๋ผ๊ณ ์š”! ๊ทธ๋ž˜์„œ ๊ตณ์ด ๋‘˜์˜ ์˜ˆ์™ธ๋ฅผ ๋‚˜๋ˆ„์ง€ ์•Š๊ณ  `IllegalArgumentException` ๋งŒ ์žก์•„์ค˜๋„ ๊ฐ™์ด ์žกํž ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ใ…Žใ…Ž
@@ -0,0 +1,92 @@ +package christmas.Util; + +import static christmas.Event.EventOption.EVENT_END_DATE; +import static christmas.Event.EventOption.EVENT_START_DATE; +import static christmas.Event.EventOption.MAX_ORDER_QUANTITY; +import static christmas.Message.OutputMessage.NOT_A_VALID_DATE; + +import christmas.Domain.MenuBoard; +import christmas.Message.OutputMessage; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class OrderMenuValidator { + public static void validateDate(String input) { + int number = Integer.parseInt(input); + if (number < EVENT_START_DATE || number > EVENT_END_DATE) { + throw new IllegalArgumentException(NOT_A_VALID_DATE); + } + } + + public static void checkValidOrderForm(String input) { + String pattern = "^[๊ฐ€-ํžฃ]+-[0-9]+(,\\s*[๊ฐ€-ํžฃ]+-[0-9]+)*$"; // ๋ฉ”๋‰ด ์ž…๋ ฅ ํ˜•์‹ + if (!input.matches(pattern)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + + public static void checkDuplicateMenu(String input) { + // ์ •๊ทœํ‘œํ˜„์‹ ํŒจํ„ด + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + + Set<String> menuSet = new HashSet<>(); + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + String menuName = matcher.group(1); + if (!menuSet.add(menuName)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + } + + public static void checkMaxOrderQuantity(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuQuantity = 0; + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + menuQuantity += Integer.parseInt(matcher.group(2)); + } + if (menuQuantity > MAX_ORDER_QUANTITY) { + throw new IllegalArgumentException(OutputMessage.INVALID_MAX_ORDER_QAUNTITY_ERROR); + } + } + + public static void checkMenuContainsOnlyDrink(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuNum = 0; + int drinkNum = 0; + + while (matcher.find()) { + if (isDrinkMenu(matcher.group(1))) { + drinkNum++; + } + menuNum++; + } + if (drinkNum == menuNum) { + throw new IllegalArgumentException(OutputMessage.MENU_CONTAIN_ONLY_DRINK_ERROR); + } + } + + public static boolean isDrinkMenu(String orderMenu) { + for (MenuBoard menu : MenuBoard.values()) { + if (orderMenu.equals(menu.getMenuName()) && menu.getMenuCategory().equals("์Œ๋ฃŒ")) { + return true; + } + } + return false; + } + +}
Java
์ •๊ทœํ‘œํ˜„์‹์„ ์ •๋ง ์ž˜ ํ™œ์šฉํ•˜์‹œ๋Š”๊ตฐ์š”!๐Ÿ‘๐Ÿ‘ ๊ทธ๋Ÿฐ๋ฐ `(?:,|$)` ๋Š” ์–ด๋–ค ์—ญํ• ์„ ํ•˜๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,92 @@ +package christmas.Util; + +import static christmas.Event.EventOption.EVENT_END_DATE; +import static christmas.Event.EventOption.EVENT_START_DATE; +import static christmas.Event.EventOption.MAX_ORDER_QUANTITY; +import static christmas.Message.OutputMessage.NOT_A_VALID_DATE; + +import christmas.Domain.MenuBoard; +import christmas.Message.OutputMessage; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class OrderMenuValidator { + public static void validateDate(String input) { + int number = Integer.parseInt(input); + if (number < EVENT_START_DATE || number > EVENT_END_DATE) { + throw new IllegalArgumentException(NOT_A_VALID_DATE); + } + } + + public static void checkValidOrderForm(String input) { + String pattern = "^[๊ฐ€-ํžฃ]+-[0-9]+(,\\s*[๊ฐ€-ํžฃ]+-[0-9]+)*$"; // ๋ฉ”๋‰ด ์ž…๋ ฅ ํ˜•์‹ + if (!input.matches(pattern)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + + public static void checkDuplicateMenu(String input) { + // ์ •๊ทœํ‘œํ˜„์‹ ํŒจํ„ด + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + + Set<String> menuSet = new HashSet<>(); + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + String menuName = matcher.group(1); + if (!menuSet.add(menuName)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + } + + public static void checkMaxOrderQuantity(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuQuantity = 0; + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + menuQuantity += Integer.parseInt(matcher.group(2)); + } + if (menuQuantity > MAX_ORDER_QUANTITY) { + throw new IllegalArgumentException(OutputMessage.INVALID_MAX_ORDER_QAUNTITY_ERROR); + } + } + + public static void checkMenuContainsOnlyDrink(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuNum = 0; + int drinkNum = 0; + + while (matcher.find()) { + if (isDrinkMenu(matcher.group(1))) { + drinkNum++; + } + menuNum++; + } + if (drinkNum == menuNum) { + throw new IllegalArgumentException(OutputMessage.MENU_CONTAIN_ONLY_DRINK_ERROR); + } + } + + public static boolean isDrinkMenu(String orderMenu) { + for (MenuBoard menu : MenuBoard.values()) { + if (orderMenu.equals(menu.getMenuName()) && menu.getMenuCategory().equals("์Œ๋ฃŒ")) { + return true; + } + } + return false; + } + +}
Java
`isDrinkMenu` ๋Š” `MenuBoard` ์—๊ฒŒ ๋„˜๊ฒจ์ฃผ๋ฉด ์–ด๋–จ๊นŒ์š”?? ์Œ๋ฃŒ๋ฅผ ํ™•์ธํ•˜๋Š” ์ฑ…์ž„์€ `MenuBoard` ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๊ฒŒ ๋” ์–ด์šธ๋ฆด ๊ฒƒ ๊ฐ™์•„์š”! ๐Ÿ˜
@@ -0,0 +1,92 @@ +package christmas.Util; + +import static christmas.Event.EventOption.EVENT_END_DATE; +import static christmas.Event.EventOption.EVENT_START_DATE; +import static christmas.Event.EventOption.MAX_ORDER_QUANTITY; +import static christmas.Message.OutputMessage.NOT_A_VALID_DATE; + +import christmas.Domain.MenuBoard; +import christmas.Message.OutputMessage; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class OrderMenuValidator { + public static void validateDate(String input) { + int number = Integer.parseInt(input); + if (number < EVENT_START_DATE || number > EVENT_END_DATE) { + throw new IllegalArgumentException(NOT_A_VALID_DATE); + } + } + + public static void checkValidOrderForm(String input) { + String pattern = "^[๊ฐ€-ํžฃ]+-[0-9]+(,\\s*[๊ฐ€-ํžฃ]+-[0-9]+)*$"; // ๋ฉ”๋‰ด ์ž…๋ ฅ ํ˜•์‹ + if (!input.matches(pattern)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + + public static void checkDuplicateMenu(String input) { + // ์ •๊ทœํ‘œํ˜„์‹ ํŒจํ„ด + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + + Set<String> menuSet = new HashSet<>(); + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + String menuName = matcher.group(1); + if (!menuSet.add(menuName)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + } + + public static void checkMaxOrderQuantity(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuQuantity = 0; + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + menuQuantity += Integer.parseInt(matcher.group(2)); + } + if (menuQuantity > MAX_ORDER_QUANTITY) { + throw new IllegalArgumentException(OutputMessage.INVALID_MAX_ORDER_QAUNTITY_ERROR); + } + } + + public static void checkMenuContainsOnlyDrink(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuNum = 0; + int drinkNum = 0; + + while (matcher.find()) { + if (isDrinkMenu(matcher.group(1))) { + drinkNum++; + } + menuNum++; + } + if (drinkNum == menuNum) { + throw new IllegalArgumentException(OutputMessage.MENU_CONTAIN_ONLY_DRINK_ERROR); + } + } + + public static boolean isDrinkMenu(String orderMenu) { + for (MenuBoard menu : MenuBoard.values()) { + if (orderMenu.equals(menu.getMenuName()) && menu.getMenuCategory().equals("์Œ๋ฃŒ")) { + return true; + } + } + return false; + } + +}
Java
ํ•ด๋‹น ์ •๊ทœํ‘œํ˜„์‹์ด ๋ฐ˜๋ณต๋˜๋Š” ๊ฒƒ ๊ฐ™์•„์š”! ๊ทธ๋ ‡๋‹ค๋ฉด Pattern ๊ฐ์ฒด๋ฅผ ์บ์‹ฑํ•ด์ฃผ๋ฉด ์–ด๋–จ๊นŒ์š”?? ๋””์Šค์ฝ”๋“œ ํ•จ๊ป˜ ๋‚˜๋ˆ„๊ธฐ์— ํ˜„์ง€๋‹˜์ด[ ๊ณต์œ ํ•˜์‹  ๊ธ€](https://velog.io/@dlguswl936/%EA%B3%B5%EB%B6%80%ED%95%9C-%EA%B2%83-String.matches%EB%8A%94-%EC%99%9C-%EC%84%B1%EB%8A%A5%EC%97%90-%EC%95%88-%EC%A2%8B%EC%9D%84%EA%B9%8C#%EA%B2%B0%EB%A1%A0-pattern-%EA%B0%9D%EC%B2%B4%EB%A5%BC-%EC%BA%90%EC%8B%B1%ED%95%B4%EB%91%90%EA%B8%B0)์ด ๋„์›€์ด ๋˜์‹ค ๊ฒƒ ๊ฐ™์•„์„œ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,30 @@ +package christmas.Util; + +public class CommaFormatter { + public static String formatWithComma(int number) { + String numberStr = Integer.toString(number); + int length = numberStr.length(); + + if (length <= 3) { + return numberStr; + } + String result = insertComma(numberStr, length); + + return result; + } + + private static String insertComma(String number, int length) { + int count = 0; + StringBuilder result = new StringBuilder(); + for (int i = length - 1; i >= 0; i--) { + result.insert(0, number.charAt(i)); + count++; + + if (count == 3 && i != 0) { + result.insert(0, ','); + count = 0; + } + } + return result.toString(); + } +}
Java
์ฝค๋งˆ๋ฅผ ์œ„ํ•ด ์ „์šฉ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์ฃผ์…จ๊ตฐ์š”! ์ง์ ‘ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ๋„ ์ข‹๋„ค์š”! ๊ทธ๋Ÿฐ๋ฐ ๋ˆ ๋‹จ์œ„๋ฅผ ์œ„ํ•œ ์ฝค๋งˆ๋ฅผ ๋„ฃ์–ด์ฃผ๋Š” ๊ธฐ๋Šฅ์„ ์ž๋ฐ”์—์„œ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ต๋‹ˆ๋‹ค! ใ…Žใ…Ž DecimalFormat ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”! ์ œ๊ฐ€ [์ฐธ๊ณ ํ–ˆ๋˜ ๊ธ€](https://jamesdreaming.tistory.com/203)์„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,67 @@ +package christmas.Domain; + +import christmas.Util.OrderMenuValidator; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class EventPlanner { + private final List<Menu> orderMenu; + + public EventPlanner(String menu) { + validateOrderMenuForm(menu); + List<Menu> orderMenu = createOrderMenuRepository(menu); + this.orderMenu = orderMenu; + } + + public int calculatePreDiscountTotalOrderPrice() { + int totalOrderPrice = 0; + for (Menu menu : orderMenu) { + totalOrderPrice += menu.getMenuTotalPrice(); + } + return totalOrderPrice; + } + + public Map<String, Integer> calculateCategoryCount() { + Map<String, Integer> categoryCount = new HashMap<>(); + int count = 0; + for (Menu menu : orderMenu) { + String menuCategory = menu.getMenuCategory(); + if (categoryCount.containsKey(menuCategory)) { + count = categoryCount.get(menuCategory) + menu.getMenuQuantity(); + categoryCount.put(menuCategory, count); + } + if (!categoryCount.containsKey(menuCategory)) { + categoryCount.put(menuCategory, menu.getMenuQuantity()); + } + } + return categoryCount; + } + + private List<Menu> createOrderMenuRepository(String orderMenu) { + List<Menu> menuList = new ArrayList<>(); + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(orderMenu); + + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + String menuName = matcher.group(1); + String menuQuantity = matcher.group(2); + menuList.add(new Menu(menuName, menuQuantity)); + } + return menuList; + } + + private void validateOrderMenuForm(String orderedMenu) { + OrderMenuValidator.checkValidOrderForm(orderedMenu); + OrderMenuValidator.checkDuplicateMenu(orderedMenu); + OrderMenuValidator.checkMaxOrderQuantity(orderedMenu); + OrderMenuValidator.checkMenuContainsOnlyDrink(orderedMenu); + } +}
Java
```suggestion public Map<String, Integer> calculateCategoryCount() { Map<String, Integer> categoryCount = new HashMap<>(); int count = 0; for (Menu menu : orderMenu) { String menuCategory = menu.getMenuCategory(); categoryCount.put(menuCategory, categoryCount.getOrDefault(menuCategory, 0) + 1) } return categoryCount; } ``` `getOrDefault` ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ฐ”๊ฟ”์ค„ ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค! ใ…Žใ…Ž ๊ฐ’์ด ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ณ  ์—†์œผ๋ฉด default ๋กœ ์ง€์ •ํ•ด์ค€ ๊ฐ’(์—ฌ๊ธฐ์„  0)์„ ๊ฐ€์ ธ์˜ค๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค!
@@ -0,0 +1,102 @@ +package christmas.Domain; + +import christmas.Event.EventBenefit; +import christmas.Event.EventOption; +import christmas.Event.SpecialDiscountDay; +import christmas.Util.OrderMenuValidator; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; + +public class EventBenefitSettler { + private final int visitDate; + + public EventBenefitSettler(String visitDate) { + OrderMenuValidator.validateDate(visitDate); + this.visitDate = Integer.parseInt(visitDate); + } + + public Map<String, Integer> calculateReceivedBenefits(Map<String, Integer> categoryCount, + int preDiscountTotalOrderPrice) { + Map<String, Integer> receivedBenefits = new HashMap<>(); + if (preDiscountTotalOrderPrice >= EventOption.MINIMUM_ORDER_PRICE_TO_GET_DISCOUNT) { + caculateChristmasDDayDiscount(receivedBenefits); + caculateWeekdayDiscount(receivedBenefits, categoryCount); + caculateWeekendDiscount(receivedBenefits, categoryCount); + caculateSpecialDiscount(receivedBenefits); + checkGiftMenu(receivedBenefits, preDiscountTotalOrderPrice); + } + return receivedBenefits; + } + + public int caculateBenefitsTotalAmount(Map<String, Integer> receivedBenefits) { + int benefitsTotalAmount = 0; + for (Map.Entry<String, Integer> benefit : receivedBenefits.entrySet()) { + benefitsTotalAmount += benefit.getValue(); + } + return benefitsTotalAmount; + } + + public int calculateDiscountedTotalAmount(Map<String, Integer> receivedBenefits, int preDiscountTotalOrderPrice) { + int discountedTotalAmount = preDiscountTotalOrderPrice; + for (Map.Entry<String, Integer> benefit : receivedBenefits.entrySet()) { + if (benefit.getKey() != EventBenefit.GIFT_MENU.getEventType()) { + discountedTotalAmount -= benefit.getValue(); + } + } + return discountedTotalAmount; + } + + private void caculateSpecialDiscount(Map<String, Integer> receivedBenefits) { + if (SpecialDiscountDay.isSpecialDay(this.visitDate)) { + receivedBenefits.put(EventBenefit.SPECIAL_DISCOUNT.getEventType(), + EventBenefit.SPECIAL_DISCOUNT.getBenefitAmount()); + } + } + + private void checkGiftMenu(Map<String, Integer> receivedBenefits, int preDiscountTotalOrderPrice) { + if (preDiscountTotalOrderPrice >= EventOption.MINIMUM_ORDER_PRICE_TO_GET_GIFT_MENU) { + receivedBenefits.put(EventBenefit.GIFT_MENU.getEventType(), EventBenefit.GIFT_MENU.getBenefitAmount()); + } + } + + private void caculateChristmasDDayDiscount(Map<String, Integer> receivedBenefits) { + int discount = 0; + if (this.visitDate <= EventOption.CHRISTMAS_D_DAY_EVENT_END_DATE) { + discount = EventOption.CHRISTMAS_D_DAY_START_DISCOUNT_AMOUNT; + discount += EventBenefit.CHRISTMAS_D_DAY_DISCOUNT.getBenefitTotalAmount(this.visitDate - 1); + receivedBenefits.put(EventBenefit.CHRISTMAS_D_DAY_DISCOUNT.getEventType(), discount); + } + } + + private void caculateWeekdayDiscount(Map<String, Integer> receivedBenefits, Map<String, Integer> categoryCount) { + int discount = 0; + if (!isWeekend()) { + try { + int countDessert = categoryCount.get(EventBenefit.WEEKDAY_DISCOUNT.getEventTarget()); // ์žˆ๋Š”์ง€๋ฅผ ์ฒดํฌ + discount += EventBenefit.WEEKDAY_DISCOUNT.getBenefitTotalAmount(countDessert); + receivedBenefits.put(EventBenefit.WEEKDAY_DISCOUNT.getEventType(), discount); + } catch (NullPointerException e) { + } + } + } + + private void caculateWeekendDiscount(Map<String, Integer> receivedBenefits, Map<String, Integer> categoryCount) { + int discount = 0; + if (isWeekend()) { + try { + int countMain = categoryCount.get(EventBenefit.WEEKEND_DISCOUNT.getEventTarget()); // ์žˆ๋Š”์ง€๋ฅผ ์ฒดํฌ + discount += EventBenefit.WEEKEND_DISCOUNT.getBenefitTotalAmount(countMain); + receivedBenefits.put(EventBenefit.WEEKDAY_DISCOUNT.getEventType(), discount); + } catch (NullPointerException e) { + } + } + } + + private boolean isWeekend() { + LocalDate date = LocalDate.of(EventOption.EVENT_YEAR, EventOption.EVENT_MONTH, this.visitDate); + DayOfWeek dayOfWeek = date.getDayOfWeek(); + return dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY; + } +}
Java
`LocalDate` ๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์š”์ผ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ตฐ์š”! ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค! ๐Ÿ˜
@@ -47,4 +47,13 @@ final class SettingViewModel { seconds: 0, identifier: "SelectedTimeNotification") } + + // URL ์—ด๊ธฐ ๋ฉ”์„œ๋“œ + func openURL(_ urlString: String) { + guard let url = URL(string: urlString), UIApplication.shared.canOpenURL(url) else { + print("์œ ํšจํ•˜์ง€ ์•Š์€ URL์ž…๋‹ˆ๋‹ค: \(urlString)") + return + } + UIApplication.shared.open(url, options: [:], completionHandler: nil) + } }
Swift
url ์ด๋™์ด ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ•˜๋Š” ๊ฑฐ๊ตฐ์š”
@@ -0,0 +1,209 @@ +import styled from '@emotion/styled'; +import { colors } from '@sopt-makers/colors'; +import { fonts } from '@sopt-makers/fonts'; +import { IconCheck, IconChevronDown } from '@sopt-makers/icons'; +import { Button } from '@sopt-makers/ui'; +import { ReactNode, useEffect, useState } from 'react'; + +import Portal from '@/components/common/Portal'; +import { zIndex } from '@/styles/zIndex'; + +interface Option { + label: string; + value: number | undefined; + description?: string; +} + +interface BottomSheetSelectProps { + options: Option[]; + defaultOption?: Option; + value: string | null | undefined; + placeholder: string; + onChange: (value: string) => void; + icon?: ReactNode; + className?: string; +} + +const BottomSheetMDS = ({ + options, + defaultOption, + value, + placeholder, + onChange, + icon, + className, +}: BottomSheetSelectProps) => { + const [open, setOpen] = useState(false); + const [selectedValue, setSelectedValue] = useState(value); + const [temporaryValue, setTemporaryValue] = useState(value); + + const handleOpen = () => setOpen(true); + const handleClose = () => setOpen(false); + + const handleOptionSelect = (value: string) => { + setTemporaryValue(value); + }; + + const handleConfirm = () => { + setSelectedValue(temporaryValue); + onChange(temporaryValue as string); + + handleClose(); + }; + + useEffect(() => { + if (open) { + document.body.style.overflow = 'hidden'; + } else { + document.body.style.overflow = ''; + } + + return () => { + document.body.style.overflow = ''; + }; + }, [open]); + + const getSelectedLabel = (value: string) => { + return options.find((option) => Number(option.value) === Number(value))?.label; + }; + + return ( + <Container> + <InputField onClick={handleOpen} className={className}> + {selectedValue ? ( + <p>{getSelectedLabel(selectedValue)}</p> + ) : ( + <p style={{ color: '#808087', whiteSpace: 'pre-wrap' }}>{placeholder}</p> + )} + + {icon || ( + <IconChevronDown + style={{ + width: 20, + minWidth: 20, + height: 20, + minHeight: 20, + transform: open ? 'rotate(-180deg)' : '', + transition: 'all 0.5s', + }} + /> + )} + </InputField> + + {open && ( + <Portal portalId='bottomsheet'> + <Overlay /> + <BottomSheet> + <OptionList> + {defaultOption && ( + <OptionItem onClick={() => handleOptionSelect(String(defaultOption.value))}> + {defaultOption.label} + {temporaryValue === defaultOption.value && <CheckedIcon />} + </OptionItem> + )} + {options.map((option) => ( + <OptionItem key={option.value} onClick={() => handleOptionSelect(String(option.value))}> + <StItemDiv> + {option.label} + <OptionSubItem>{option.description}</OptionSubItem> + </StItemDiv> + {temporaryValue === option.value && <CheckedIcon />} + </OptionItem> + ))} + </OptionList> + <Button size='lg' style={{ width: '100%' }} onClick={handleConfirm}> + ํ™•์ธ + </Button> + </BottomSheet> + </Portal> + )} + </Container> + ); +}; +export default BottomSheetMDS; + +const Container = styled.div` + position: relative; + width: 100%; +`; + +const InputField = styled.div` + display: flex; + gap: 12px; + align-items: center; + justify-content: space-between; + border-radius: 10px; + background-color: ${colors.gray800}; + cursor: pointer; + padding: 11px 16px; + ${fonts.BODY_16_M}; + + max-width: calc(100vw - 40px); + + p { + width: 100%; + overflow: hidden; /* ๋„˜์น˜๋Š” ํ…์ŠคํŠธ ์ˆจ๊น€ */ + text-overflow: ellipsis; + white-space: nowrap; /* ํ…์ŠคํŠธ ์ค„ ๋ฐ”๊ฟˆ ๋ฐฉ์ง€ */ + } +`; + +const Overlay = styled.div` + position: fixed; + top: 0; + left: 0; + z-index: ${zIndex.ํ—ค๋”}; + background-color: rgb(15 15 18 / 80%); + width: 100%; + height: 100%; +`; + +const BottomSheet = styled.section` + position: fixed; + bottom: 0; + left: 20px; + z-index: ${zIndex.ํ—ค๋”}; + margin-bottom: 12px; + border-radius: 16px; + background-color: ${colors.gray800}; + padding: 16px; + width: calc(100% - 40px); +`; + +const OptionList = styled.ul` + margin: 0 0 16px; + padding: 0; + max-height: 300px; + overflow-y: auto; + list-style: none; +`; + +const OptionItem = styled.li` + display: flex; + align-items: center; + justify-content: space-between; + border-radius: 8px; + cursor: pointer; + padding: 10px; + height: 66px; + ${fonts.BODY_14_M} + + &:hover { + background-color: ${colors.gray700}; + } +`; +const OptionSubItem = styled.div` + margin-top: 2px; + ${fonts.BODY_13_R} + + color:${colors.gray200} +`; + +const CheckedIcon = styled(IconCheck)` + width: 24px; + height: 24px; + color: ${colors.success}; +`; +const StItemDiv = styled.div` + width: 100%; +`;
Unknown
๊ทธ `BottomSheetSelect`์ปดํฌ๋„ŒํŠธ๋ฅผ ์ด์ „์— ๋„์˜์ด๊ฐ€ ๊ตฌํ˜„ํ•ด์คฌ์—ˆ๋Š”๋ฐ ์š”๊ฒŒ ๋™์ผํ•œ ๋ชฉ์ ์„ ๊ฐ€์ง„ ์ปดํฌ๋„ŒํŠธ์ธ๊ฑธ๋กœ ๋ณด์—ฌ์„œ์š”..!!! ํ˜น์‹œ ๋”ฐ๋กœ ๊ตฌํ˜„ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?? ํ˜น์‹œ ์กด์žฌํ•˜๋Š”์ง€ ๋ชฐ๋ž๋˜๊ฑธ๊นŒ ์ฃผ๋ฅต.. ๋งŒ์•ฝ์— ๊ทธ๋Ÿฐ๊ฒƒ์ด๋ผ๋ฉด ์–ด์ฐจํ”ผ mds๋กœ ๋Œ€์ฒด๋˜์–ด์•ผํ•  ๋ถ€๋ถ„์ด๋‹ˆ, ์ž˜ ์ž‘๋™ํ•œ๋‹ค๋ฉด ์ˆ˜์ •ํ•  ํ•„์š”๋Š” ์—†์„๊ฑฐ๊ฐ™์Šต๋‹ˆ๋‹ค!!!!
@@ -0,0 +1,328 @@ +import styled from '@emotion/styled'; +import { colors } from '@sopt-makers/colors'; +import { fonts } from '@sopt-makers/fonts'; +import { Button, Callout, SelectV2, Tag, TextArea, useDialog, useToast } from '@sopt-makers/ui'; +import { useMutation } from '@tanstack/react-query'; +import { useRouter } from 'next/router'; +import { playgroundLink } from 'playground-common/export'; +import { useState } from 'react'; + +import { useGetCoffeechatHistory } from '@/api/endpoint/coffeechat/getCoffeechatHistory'; +import { postCoffeechatReview } from '@/api/endpoint/coffeechat/postCoffeechatReview'; +import AuthRequired from '@/components/auth/AuthRequired'; +import BottomSheetMDS from '@/components/coffeechat/CoffeeChatReveiw/BottomSheetMDS'; +import useCustomConfirm from '@/components/common/Modal/useCustomConfirm'; +import Responsive from '@/components/common/Responsive'; +import useEventLogger from '@/components/eventLogger/hooks/useEventLogger'; +import { MB_BIG_MEDIA_QUERY, MOBILE_MEDIA_QUERY } from '@/styles/mediaQuery'; +import { setLayout } from '@/utils/layout'; + +const CoffeeChatReviewUpload = () => { + const [nickname, setNickname] = useState(''); + const [content, setContent] = useState(''); + const [isChecked, setIsChecked] = useState(false); + + const { open } = useDialog(); + const { confirm } = useCustomConfirm(); + const [coffeechat, setCoffeechat] = useState<number>(0); + + const { open: toastOpen } = useToast(); + const { data, isLoading } = useGetCoffeechatHistory(); + const router = useRouter(); + const { logSubmitEvent } = useEventLogger(); + const { mutate } = useMutation({ + mutationFn: () => postCoffeechatReview.request(coffeechat, nickname, content), + onSuccess: () => { + toastOpen({ + icon: 'success', + content: 'ํ›„๊ธฐ๊ฐ€ ๋“ฑ๋ก๋์–ด์š”! ๊ฒฝํ—˜์„ ๋‚˜๋ˆ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ด์š”.', + style: { + content: { + whiteSpace: 'pre-wrap', + }, + }, + }); + logSubmitEvent('coffeechatReview'); + router.push(playgroundLink.coffeechat()); + }, + onError: () => { + toastOpen({ + icon: 'error', + content: '๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์–ด์š”.', + style: { + content: { + whiteSpace: 'pre-wrap', + }, + }, + }); + }, + }); + const selectOptions = data?.coffeeChatHistories.map((item) => ({ + label: item.coffeeChatBio || '', + value: item.id ?? undefined, + description: item.name + ' | ' + item.career || '', + })); + + const handleEnroll = async () => { + if (nickname.length <= 0 || content.length <= 0) { + setIsChecked(true); + } else if (coffeechat === 0) { + open({ + title: `์ปคํ”ผ์ฑ—์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”.`, + description: <StDescription>์ปคํ”ผ์ฑ— ๋ฆฌ๋ทฐ๋Š” ์ปคํ”ผ์ฑ— ์ž‘์„ฑ ํ›„์—๋งŒ ์ž‘์„ฑ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.</StDescription>, + type: 'single', + typeOptions: { + approveButtonText: 'ํ™•์ธ', + }, + }); + } else { + open({ + title: 'ํ›„๊ธฐ๋ฅผ ๋“ฑ๋กํ•˜๊ธฐ ์ „, ํ™•์ธํ•ด์ฃผ์„ธ์š”!', + description: ( + <StDescription> + ํ•œ ๋ฒˆ ๋“ฑ๋กํ•œ ํ›„๊ธฐ๋Š” ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์–ด์š”. ์ˆ˜์ • ๋ฐ ์‚ญ์ œ๋ฅผ ์›ํ•˜์‹ ๋‹ค๋ฉด ๋ฉ”์ด์ปค์Šค ์นด์นด์˜ค ์ฑ„๋„๋กœ ๋ฌธ์˜ํ•ด ์ฃผ์„ธ์š”. + </StDescription> + ), + type: 'default', + typeOptions: { + cancelButtonText: '๋‹ซ๊ธฐ', + approveButtonText: '๋“ฑ๋กํ•˜๊ธฐ', + buttonFunction: async () => { + await mutate(); + }, + }, + }); + } + }; + return ( + <AuthRequired> + <StMainSection> + <StReviewSection> + <StTitle>์ปคํ”ผ์ฑ— ํ›„๊ธฐ ์ž‘์„ฑํ•˜๊ธฐ</StTitle> + <Callout type='information'> + ์ปคํ”ผ์†์—์„œ ์œ ์ตํ•œ ์‹œ๊ฐ„ ๋ณด๋‚ด์…จ๋‚˜์š”? ์ปคํ”ผ์†์—์„œ ๋” ๋งŽ์€ ์ปคํ”ผ์ฑ—์ด ์˜ค๊ฐˆ ์ˆ˜ ์žˆ๋„๋ก ์†Œ์ค‘ํ•œ ํ›„๊ธฐ๋ฅผ ๋ถ€ํƒ๋“œ๋ ค์š”! + </Callout> + <StInfo> + ํ›„๊ธฐ๋ฅผ ์ž‘์„ฑํ•  ์ปคํ”ผ์ฑ— <span style={{ color: 'rgb(247 114 52 / 100%)' }}>*</span> + </StInfo> + <StSubInfo>์ปคํ”ผ์ฑ—์„ ์ง„ํ–‰ํ•œ ํšŒ์›์ธ์ง€ ํ™•์ธ์ด ํ•„์š”ํ•ด์š”. ์–ด๋–ค ์ปคํ”ผ์ฑ—์„ ์ง„ํ–‰ํ–ˆ๋Š”์ง€๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์•„์š”</StSubInfo> + <Responsive only='desktop'> + <SelectV2.Root + type='textDesc' + className='coffechat-select' + visibleOptions={3} + onChange={(e) => setCoffeechat(Number(e))} + > + <SelectV2.Trigger> + <SelectV2.TriggerContent placeholder={'์ง„ํ–‰ํ•œ ์ปคํ”ผ์ฑ—์˜ ์ œ๋ชฉ์ด ๋ฌด์—‡์ธ๊ฐ€์š”?'} /> + </SelectV2.Trigger> + <StSelectV2Menu className='coffeechat-ul'> + {selectOptions?.map((option) => ( + <StSelectV2MenuItem key={option.value} option={option} /> + ))} + </StSelectV2Menu> + </SelectV2.Root> + </Responsive> + <Responsive only='mobile'> + <div style={{ marginTop: '8px' }}> + <BottomSheetMDS + placeholder='์ง„ํ–‰ํ•œ ์ปคํ”ผ์ฑ—์˜ ์ œ๋ชฉ์€ ๋ฌด์—‡์ธ๊ฐ€์š”?' + options={selectOptions || []} + value={undefined} + onChange={(value) => { + setCoffeechat(Number(value)); + }} + /> + </div> + </Responsive> + {coffeechat > 0 && ( + <> + {' '} + <StInfo>์„ ํƒํ•œ ์ปคํ”ผ์ฑ—์˜ ์ฃผ์ œ</StInfo> + <StLabelWrapper> + {data?.coffeeChatHistories + .find((item) => item.id === coffeechat) // id๊ฐ€ coffeechat์ธ ๊ฐ์ฒด ์ฐพ๊ธฐ + ?.coffeeChatTopicType?.map((tag, index) => ( + <Tag key={index} type='solid' size='md' variant='default'> + {tag} + </Tag> + ))} + </StLabelWrapper> + </> + )} + + <StInfo> + ๋‚˜์˜ ๋‹‰๋„ค์ž„ <span style={{ color: 'rgb(247 114 52 / 100%)' }}>*</span> + </StInfo> + <StSubInfo>ํ›„๊ธฐ๋Š” ์ปคํ”ผ์† ํ™ˆ์— ์ต๋ช…์œผ๋กœ ๋“ฑ๋ก๋ผ์š”! ์›ํ•˜๋Š” ๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”</StSubInfo> + <div style={{ position: 'relative' }}> + <StTextArea + errorMessage='๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”' + isError={isChecked && nickname.length <= 0} + maxLength={10} + placeholder='ex. ์นดํŽ˜์ธ ์ค‘๋…์ž' + onChange={(e) => setNickname(e.target.value)} + value={nickname} + /> + <TextCountWrapper>{nickname.length < 10 ? nickname.length : 10}/10</TextCountWrapper> + <StInfo> + ์ƒ์„ธ ํ›„๊ธฐ <span style={{ color: 'rgb(247 114 52 / 100%)' }}>*</span> + </StInfo> + </div> + <div style={{ position: 'relative', height: 'auto' }}> + <StTextArea + errorMessage='์ƒ์„ธ ํ›„๊ธฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”' + placeholder={`ex. +โ€ข ๊ถ๊ธˆํ–ˆ๋˜ ๋‚ด์šฉ์„ A-Z๊นŒ์ง€ ์นœ์ ˆํ•˜๊ฒŒ ์•Œ๋ ค์ฃผ์…”์„œ ์œ ์ตํ–ˆ์–ด์š”. +โ€ข ์ด๋Ÿฐ ๋‚ด์šฉ์„ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์–ด์„œ ๋œป ๊นŠ์—ˆ์–ด์š”.`} + fixedHeight={130} + maxLength={500} + onChange={(e) => setContent(e.target.value)} + isError={isChecked && content.length <= 0} + value={content} + ></StTextArea> + <TextCountWrapper style={{ top: '160px' }}>{content.length}/500</TextCountWrapper> + </div> + <StButtonWrapper> + <StButton onClick={() => handleEnroll()}>ํ›„๊ธฐ ๋“ฑ๋กํ•˜๊ธฐ</StButton> + </StButtonWrapper> + </StReviewSection> + </StMainSection> + </AuthRequired> + ); +}; +setLayout(CoffeeChatReviewUpload, 'headerFooter'); +export default CoffeeChatReviewUpload; +const StMainSection = styled.div` + display: flex; + align-items: center; + justify-content: center; + margin-top: 48px; + margin-bottom: 142px; + width: 100%; + height: 100%; + + .coffechat-select { + margin-top: 8px; + width: 100%; + + button { + width: 100%; + + div { + width: 100%; + } + } + } + + @media ${MOBILE_MEDIA_QUERY} { + margin-top: 0; + } + @media ${MB_BIG_MEDIA_QUERY} { + margin-bottom: 84px; + } +`; +const StReviewSection = styled.div` + padding: 40px; + padding-right: 30px; + padding-left: 30px; + width: 1260px; + + @media ${MB_BIG_MEDIA_QUERY} { + padding: 30px; + padding-right: 20px; + padding-left: 20px; + } +`; +const StTitle = styled.div` + margin-bottom: 20px; + width: 100%; + height: 48px; + ${fonts.HEADING_32_B} + @media ${MB_BIG_MEDIA_QUERY} { + ${fonts.HEADING_24_B} + + margin-bottom:16px; + } +`; +const StInfo = styled.div` + ${fonts.LABEL_16_SB} + + margin-top:40px; + @media ${MB_BIG_MEDIA_QUERY} { + ${fonts.LABEL_14_SB}; + } +`; +const StSubInfo = styled.div` + ${fonts.LABEL_14_SB} + + margin-top:8px; + letter-spacing: -0.32px; + color: ${colors.gray300}; + + @media ${MB_BIG_MEDIA_QUERY} { + ${fonts.LABEL_12_SB}; + } +`; + +const StTextArea = styled(TextArea)` + margin-top: 8px; +`; +const StButtonWrapper = styled.div` + display: flex; + justify-content: flex-end; + margin-top: 70px; + width: 100%; +`; +const TextCountWrapper = styled.div` + position: absolute; + top: 56px; + width: 100%; + text-align: right; + color: ${colors.gray300}; + ${fonts.LABEL_12_SB}; +`; +const StButton = styled(Button)` + @media ${MB_BIG_MEDIA_QUERY} { + width: 100%; + height: 42px; + ${fonts.LABEL_16_SB} + } +`; + +const StLabelWrapper = styled.div` + display: flex; + gap: 8px; + margin-top: 8px; + + div { + border-radius: 100px; + padding: 3px 9px; + } +`; +const StSelectV2Menu = styled(SelectV2.Menu)` + width: calc(100vw - 60px); + max-width: 1200px; + white-space: nowrap; + + li { + width: calc(100vw - 60px); + max-width: 1200px; + + button { + width: calc(100vw - 60px); + max-width: 1200px; + } + } +`; +const StSelectV2MenuItem = styled(SelectV2.MenuItem)` + li { + width: calc(100% - 60px); + } +`; +const StDescription = styled.div` + margin-top: 12px; + @media ${MOBILE_MEDIA_QUERY} { + margin-top: 8px; + } +`;
Unknown
mutation ์‹คํŒจ์‹œ ์—๋Ÿฌ์ฒ˜๋ฆฌ๋„ ๋„ฃ์–ด์ฃผ๋ฉด ์ข‹์„๊ฑฐ๊ฐ™์•„์š”!! onError ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ด์„œ '๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์–ด์š”.' ์™€ ๊ฐ™์€ toast๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์–ด๋„ ์ข‹์„๊ฑฐ๊ฐ™์•„์š”!
@@ -0,0 +1,209 @@ +import styled from '@emotion/styled'; +import { colors } from '@sopt-makers/colors'; +import { fonts } from '@sopt-makers/fonts'; +import { IconCheck, IconChevronDown } from '@sopt-makers/icons'; +import { Button } from '@sopt-makers/ui'; +import { ReactNode, useEffect, useState } from 'react'; + +import Portal from '@/components/common/Portal'; +import { zIndex } from '@/styles/zIndex'; + +interface Option { + label: string; + value: number | undefined; + description?: string; +} + +interface BottomSheetSelectProps { + options: Option[]; + defaultOption?: Option; + value: string | null | undefined; + placeholder: string; + onChange: (value: string) => void; + icon?: ReactNode; + className?: string; +} + +const BottomSheetMDS = ({ + options, + defaultOption, + value, + placeholder, + onChange, + icon, + className, +}: BottomSheetSelectProps) => { + const [open, setOpen] = useState(false); + const [selectedValue, setSelectedValue] = useState(value); + const [temporaryValue, setTemporaryValue] = useState(value); + + const handleOpen = () => setOpen(true); + const handleClose = () => setOpen(false); + + const handleOptionSelect = (value: string) => { + setTemporaryValue(value); + }; + + const handleConfirm = () => { + setSelectedValue(temporaryValue); + onChange(temporaryValue as string); + + handleClose(); + }; + + useEffect(() => { + if (open) { + document.body.style.overflow = 'hidden'; + } else { + document.body.style.overflow = ''; + } + + return () => { + document.body.style.overflow = ''; + }; + }, [open]); + + const getSelectedLabel = (value: string) => { + return options.find((option) => Number(option.value) === Number(value))?.label; + }; + + return ( + <Container> + <InputField onClick={handleOpen} className={className}> + {selectedValue ? ( + <p>{getSelectedLabel(selectedValue)}</p> + ) : ( + <p style={{ color: '#808087', whiteSpace: 'pre-wrap' }}>{placeholder}</p> + )} + + {icon || ( + <IconChevronDown + style={{ + width: 20, + minWidth: 20, + height: 20, + minHeight: 20, + transform: open ? 'rotate(-180deg)' : '', + transition: 'all 0.5s', + }} + /> + )} + </InputField> + + {open && ( + <Portal portalId='bottomsheet'> + <Overlay /> + <BottomSheet> + <OptionList> + {defaultOption && ( + <OptionItem onClick={() => handleOptionSelect(String(defaultOption.value))}> + {defaultOption.label} + {temporaryValue === defaultOption.value && <CheckedIcon />} + </OptionItem> + )} + {options.map((option) => ( + <OptionItem key={option.value} onClick={() => handleOptionSelect(String(option.value))}> + <StItemDiv> + {option.label} + <OptionSubItem>{option.description}</OptionSubItem> + </StItemDiv> + {temporaryValue === option.value && <CheckedIcon />} + </OptionItem> + ))} + </OptionList> + <Button size='lg' style={{ width: '100%' }} onClick={handleConfirm}> + ํ™•์ธ + </Button> + </BottomSheet> + </Portal> + )} + </Container> + ); +}; +export default BottomSheetMDS; + +const Container = styled.div` + position: relative; + width: 100%; +`; + +const InputField = styled.div` + display: flex; + gap: 12px; + align-items: center; + justify-content: space-between; + border-radius: 10px; + background-color: ${colors.gray800}; + cursor: pointer; + padding: 11px 16px; + ${fonts.BODY_16_M}; + + max-width: calc(100vw - 40px); + + p { + width: 100%; + overflow: hidden; /* ๋„˜์น˜๋Š” ํ…์ŠคํŠธ ์ˆจ๊น€ */ + text-overflow: ellipsis; + white-space: nowrap; /* ํ…์ŠคํŠธ ์ค„ ๋ฐ”๊ฟˆ ๋ฐฉ์ง€ */ + } +`; + +const Overlay = styled.div` + position: fixed; + top: 0; + left: 0; + z-index: ${zIndex.ํ—ค๋”}; + background-color: rgb(15 15 18 / 80%); + width: 100%; + height: 100%; +`; + +const BottomSheet = styled.section` + position: fixed; + bottom: 0; + left: 20px; + z-index: ${zIndex.ํ—ค๋”}; + margin-bottom: 12px; + border-radius: 16px; + background-color: ${colors.gray800}; + padding: 16px; + width: calc(100% - 40px); +`; + +const OptionList = styled.ul` + margin: 0 0 16px; + padding: 0; + max-height: 300px; + overflow-y: auto; + list-style: none; +`; + +const OptionItem = styled.li` + display: flex; + align-items: center; + justify-content: space-between; + border-radius: 8px; + cursor: pointer; + padding: 10px; + height: 66px; + ${fonts.BODY_14_M} + + &:hover { + background-color: ${colors.gray700}; + } +`; +const OptionSubItem = styled.div` + margin-top: 2px; + ${fonts.BODY_13_R} + + color:${colors.gray200} +`; + +const CheckedIcon = styled(IconCheck)` + width: 24px; + height: 24px; + color: ${colors.success}; +`; +const StItemDiv = styled.div` + width: 100%; +`;
Unknown
์•— ์ด๊ฑฐ ์ฝ”๋“œ ์ž์ฒด๊ฐ€ ๋„์˜์ด๊ฐ€ ๋งŒ๋“ ๊ฑฐ ๊ธฐ๋ฐ˜์ด ๋งž์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž! ๋‹จ, ์ด๋ฒˆ์— mds ๋””์ž์ธ์ด ์—…๋ฐ์ดํŠธ ๋˜๋ฉด์„œ ๊ธฐ์กด ๋ฐ”ํ…€์‹œํŠธ ๋””์ž์ธ์ด ์•„๋‹ˆ๋ผ.. description ๋ถ€๋ถ„์ด ์ถ”๊ฐ€๋˜์–ด๊ฐ€์ง€๊ณ , ๋„์˜์ด๊ฐ€ ๋งŒ๋“ค์–ด์ค€ ์นœ๊ตฌ๋ž‘ ์กฐ๊ธˆ ๋‹ค๋ฅด๊ฒŒ ์ž‘๋™ํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค..! ๊ธฐ์กด์— ์“ฐ์ด๋˜ ๋ฐ”ํ…€์‹œํŠธ๋ฅผ ์ˆ˜์ •ํ•˜๋ฉด ์‚ฌ์ด๋“œ์ดํŽ™ํŠธ๊ฐ€ ์ข€ ๋งŽ์ด ์ƒ๊ธธ ๊ฒƒ ๊ฐ™์•„์„œ ์ผ๋‹จ์€ ํ˜„์žฌ ์ปค์Šคํ…€์œผ๋กœ ๊ตฌํ˜„ํ•ด๋‘”๊ฑฐ๋ผ, Mds๋กœ ๋Œ€์ฒดํ•˜๋ฉด ๋  ๊ฒƒ๊ฐ™์•„์š”!
@@ -0,0 +1,328 @@ +import styled from '@emotion/styled'; +import { colors } from '@sopt-makers/colors'; +import { fonts } from '@sopt-makers/fonts'; +import { Button, Callout, SelectV2, Tag, TextArea, useDialog, useToast } from '@sopt-makers/ui'; +import { useMutation } from '@tanstack/react-query'; +import { useRouter } from 'next/router'; +import { playgroundLink } from 'playground-common/export'; +import { useState } from 'react'; + +import { useGetCoffeechatHistory } from '@/api/endpoint/coffeechat/getCoffeechatHistory'; +import { postCoffeechatReview } from '@/api/endpoint/coffeechat/postCoffeechatReview'; +import AuthRequired from '@/components/auth/AuthRequired'; +import BottomSheetMDS from '@/components/coffeechat/CoffeeChatReveiw/BottomSheetMDS'; +import useCustomConfirm from '@/components/common/Modal/useCustomConfirm'; +import Responsive from '@/components/common/Responsive'; +import useEventLogger from '@/components/eventLogger/hooks/useEventLogger'; +import { MB_BIG_MEDIA_QUERY, MOBILE_MEDIA_QUERY } from '@/styles/mediaQuery'; +import { setLayout } from '@/utils/layout'; + +const CoffeeChatReviewUpload = () => { + const [nickname, setNickname] = useState(''); + const [content, setContent] = useState(''); + const [isChecked, setIsChecked] = useState(false); + + const { open } = useDialog(); + const { confirm } = useCustomConfirm(); + const [coffeechat, setCoffeechat] = useState<number>(0); + + const { open: toastOpen } = useToast(); + const { data, isLoading } = useGetCoffeechatHistory(); + const router = useRouter(); + const { logSubmitEvent } = useEventLogger(); + const { mutate } = useMutation({ + mutationFn: () => postCoffeechatReview.request(coffeechat, nickname, content), + onSuccess: () => { + toastOpen({ + icon: 'success', + content: 'ํ›„๊ธฐ๊ฐ€ ๋“ฑ๋ก๋์–ด์š”! ๊ฒฝํ—˜์„ ๋‚˜๋ˆ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ด์š”.', + style: { + content: { + whiteSpace: 'pre-wrap', + }, + }, + }); + logSubmitEvent('coffeechatReview'); + router.push(playgroundLink.coffeechat()); + }, + onError: () => { + toastOpen({ + icon: 'error', + content: '๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์–ด์š”.', + style: { + content: { + whiteSpace: 'pre-wrap', + }, + }, + }); + }, + }); + const selectOptions = data?.coffeeChatHistories.map((item) => ({ + label: item.coffeeChatBio || '', + value: item.id ?? undefined, + description: item.name + ' | ' + item.career || '', + })); + + const handleEnroll = async () => { + if (nickname.length <= 0 || content.length <= 0) { + setIsChecked(true); + } else if (coffeechat === 0) { + open({ + title: `์ปคํ”ผ์ฑ—์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”.`, + description: <StDescription>์ปคํ”ผ์ฑ— ๋ฆฌ๋ทฐ๋Š” ์ปคํ”ผ์ฑ— ์ž‘์„ฑ ํ›„์—๋งŒ ์ž‘์„ฑ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.</StDescription>, + type: 'single', + typeOptions: { + approveButtonText: 'ํ™•์ธ', + }, + }); + } else { + open({ + title: 'ํ›„๊ธฐ๋ฅผ ๋“ฑ๋กํ•˜๊ธฐ ์ „, ํ™•์ธํ•ด์ฃผ์„ธ์š”!', + description: ( + <StDescription> + ํ•œ ๋ฒˆ ๋“ฑ๋กํ•œ ํ›„๊ธฐ๋Š” ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์–ด์š”. ์ˆ˜์ • ๋ฐ ์‚ญ์ œ๋ฅผ ์›ํ•˜์‹ ๋‹ค๋ฉด ๋ฉ”์ด์ปค์Šค ์นด์นด์˜ค ์ฑ„๋„๋กœ ๋ฌธ์˜ํ•ด ์ฃผ์„ธ์š”. + </StDescription> + ), + type: 'default', + typeOptions: { + cancelButtonText: '๋‹ซ๊ธฐ', + approveButtonText: '๋“ฑ๋กํ•˜๊ธฐ', + buttonFunction: async () => { + await mutate(); + }, + }, + }); + } + }; + return ( + <AuthRequired> + <StMainSection> + <StReviewSection> + <StTitle>์ปคํ”ผ์ฑ— ํ›„๊ธฐ ์ž‘์„ฑํ•˜๊ธฐ</StTitle> + <Callout type='information'> + ์ปคํ”ผ์†์—์„œ ์œ ์ตํ•œ ์‹œ๊ฐ„ ๋ณด๋‚ด์…จ๋‚˜์š”? ์ปคํ”ผ์†์—์„œ ๋” ๋งŽ์€ ์ปคํ”ผ์ฑ—์ด ์˜ค๊ฐˆ ์ˆ˜ ์žˆ๋„๋ก ์†Œ์ค‘ํ•œ ํ›„๊ธฐ๋ฅผ ๋ถ€ํƒ๋“œ๋ ค์š”! + </Callout> + <StInfo> + ํ›„๊ธฐ๋ฅผ ์ž‘์„ฑํ•  ์ปคํ”ผ์ฑ— <span style={{ color: 'rgb(247 114 52 / 100%)' }}>*</span> + </StInfo> + <StSubInfo>์ปคํ”ผ์ฑ—์„ ์ง„ํ–‰ํ•œ ํšŒ์›์ธ์ง€ ํ™•์ธ์ด ํ•„์š”ํ•ด์š”. ์–ด๋–ค ์ปคํ”ผ์ฑ—์„ ์ง„ํ–‰ํ–ˆ๋Š”์ง€๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์•„์š”</StSubInfo> + <Responsive only='desktop'> + <SelectV2.Root + type='textDesc' + className='coffechat-select' + visibleOptions={3} + onChange={(e) => setCoffeechat(Number(e))} + > + <SelectV2.Trigger> + <SelectV2.TriggerContent placeholder={'์ง„ํ–‰ํ•œ ์ปคํ”ผ์ฑ—์˜ ์ œ๋ชฉ์ด ๋ฌด์—‡์ธ๊ฐ€์š”?'} /> + </SelectV2.Trigger> + <StSelectV2Menu className='coffeechat-ul'> + {selectOptions?.map((option) => ( + <StSelectV2MenuItem key={option.value} option={option} /> + ))} + </StSelectV2Menu> + </SelectV2.Root> + </Responsive> + <Responsive only='mobile'> + <div style={{ marginTop: '8px' }}> + <BottomSheetMDS + placeholder='์ง„ํ–‰ํ•œ ์ปคํ”ผ์ฑ—์˜ ์ œ๋ชฉ์€ ๋ฌด์—‡์ธ๊ฐ€์š”?' + options={selectOptions || []} + value={undefined} + onChange={(value) => { + setCoffeechat(Number(value)); + }} + /> + </div> + </Responsive> + {coffeechat > 0 && ( + <> + {' '} + <StInfo>์„ ํƒํ•œ ์ปคํ”ผ์ฑ—์˜ ์ฃผ์ œ</StInfo> + <StLabelWrapper> + {data?.coffeeChatHistories + .find((item) => item.id === coffeechat) // id๊ฐ€ coffeechat์ธ ๊ฐ์ฒด ์ฐพ๊ธฐ + ?.coffeeChatTopicType?.map((tag, index) => ( + <Tag key={index} type='solid' size='md' variant='default'> + {tag} + </Tag> + ))} + </StLabelWrapper> + </> + )} + + <StInfo> + ๋‚˜์˜ ๋‹‰๋„ค์ž„ <span style={{ color: 'rgb(247 114 52 / 100%)' }}>*</span> + </StInfo> + <StSubInfo>ํ›„๊ธฐ๋Š” ์ปคํ”ผ์† ํ™ˆ์— ์ต๋ช…์œผ๋กœ ๋“ฑ๋ก๋ผ์š”! ์›ํ•˜๋Š” ๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”</StSubInfo> + <div style={{ position: 'relative' }}> + <StTextArea + errorMessage='๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”' + isError={isChecked && nickname.length <= 0} + maxLength={10} + placeholder='ex. ์นดํŽ˜์ธ ์ค‘๋…์ž' + onChange={(e) => setNickname(e.target.value)} + value={nickname} + /> + <TextCountWrapper>{nickname.length < 10 ? nickname.length : 10}/10</TextCountWrapper> + <StInfo> + ์ƒ์„ธ ํ›„๊ธฐ <span style={{ color: 'rgb(247 114 52 / 100%)' }}>*</span> + </StInfo> + </div> + <div style={{ position: 'relative', height: 'auto' }}> + <StTextArea + errorMessage='์ƒ์„ธ ํ›„๊ธฐ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”' + placeholder={`ex. +โ€ข ๊ถ๊ธˆํ–ˆ๋˜ ๋‚ด์šฉ์„ A-Z๊นŒ์ง€ ์นœ์ ˆํ•˜๊ฒŒ ์•Œ๋ ค์ฃผ์…”์„œ ์œ ์ตํ–ˆ์–ด์š”. +โ€ข ์ด๋Ÿฐ ๋‚ด์šฉ์„ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์–ด์„œ ๋œป ๊นŠ์—ˆ์–ด์š”.`} + fixedHeight={130} + maxLength={500} + onChange={(e) => setContent(e.target.value)} + isError={isChecked && content.length <= 0} + value={content} + ></StTextArea> + <TextCountWrapper style={{ top: '160px' }}>{content.length}/500</TextCountWrapper> + </div> + <StButtonWrapper> + <StButton onClick={() => handleEnroll()}>ํ›„๊ธฐ ๋“ฑ๋กํ•˜๊ธฐ</StButton> + </StButtonWrapper> + </StReviewSection> + </StMainSection> + </AuthRequired> + ); +}; +setLayout(CoffeeChatReviewUpload, 'headerFooter'); +export default CoffeeChatReviewUpload; +const StMainSection = styled.div` + display: flex; + align-items: center; + justify-content: center; + margin-top: 48px; + margin-bottom: 142px; + width: 100%; + height: 100%; + + .coffechat-select { + margin-top: 8px; + width: 100%; + + button { + width: 100%; + + div { + width: 100%; + } + } + } + + @media ${MOBILE_MEDIA_QUERY} { + margin-top: 0; + } + @media ${MB_BIG_MEDIA_QUERY} { + margin-bottom: 84px; + } +`; +const StReviewSection = styled.div` + padding: 40px; + padding-right: 30px; + padding-left: 30px; + width: 1260px; + + @media ${MB_BIG_MEDIA_QUERY} { + padding: 30px; + padding-right: 20px; + padding-left: 20px; + } +`; +const StTitle = styled.div` + margin-bottom: 20px; + width: 100%; + height: 48px; + ${fonts.HEADING_32_B} + @media ${MB_BIG_MEDIA_QUERY} { + ${fonts.HEADING_24_B} + + margin-bottom:16px; + } +`; +const StInfo = styled.div` + ${fonts.LABEL_16_SB} + + margin-top:40px; + @media ${MB_BIG_MEDIA_QUERY} { + ${fonts.LABEL_14_SB}; + } +`; +const StSubInfo = styled.div` + ${fonts.LABEL_14_SB} + + margin-top:8px; + letter-spacing: -0.32px; + color: ${colors.gray300}; + + @media ${MB_BIG_MEDIA_QUERY} { + ${fonts.LABEL_12_SB}; + } +`; + +const StTextArea = styled(TextArea)` + margin-top: 8px; +`; +const StButtonWrapper = styled.div` + display: flex; + justify-content: flex-end; + margin-top: 70px; + width: 100%; +`; +const TextCountWrapper = styled.div` + position: absolute; + top: 56px; + width: 100%; + text-align: right; + color: ${colors.gray300}; + ${fonts.LABEL_12_SB}; +`; +const StButton = styled(Button)` + @media ${MB_BIG_MEDIA_QUERY} { + width: 100%; + height: 42px; + ${fonts.LABEL_16_SB} + } +`; + +const StLabelWrapper = styled.div` + display: flex; + gap: 8px; + margin-top: 8px; + + div { + border-radius: 100px; + padding: 3px 9px; + } +`; +const StSelectV2Menu = styled(SelectV2.Menu)` + width: calc(100vw - 60px); + max-width: 1200px; + white-space: nowrap; + + li { + width: calc(100vw - 60px); + max-width: 1200px; + + button { + width: calc(100vw - 60px); + max-width: 1200px; + } + } +`; +const StSelectV2MenuItem = styled(SelectV2.MenuItem)` + li { + width: calc(100% - 60px); + } +`; +const StDescription = styled.div` + margin-top: 12px; + @media ${MOBILE_MEDIA_QUERY} { + margin-top: 8px; + } +`;
Unknown
์•„์•„ ๋„ˆ๋ฌด ์ข‹์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,209 @@ +import styled from '@emotion/styled'; +import { colors } from '@sopt-makers/colors'; +import { fonts } from '@sopt-makers/fonts'; +import { IconCheck, IconChevronDown } from '@sopt-makers/icons'; +import { Button } from '@sopt-makers/ui'; +import { ReactNode, useEffect, useState } from 'react'; + +import Portal from '@/components/common/Portal'; +import { zIndex } from '@/styles/zIndex'; + +interface Option { + label: string; + value: number | undefined; + description?: string; +} + +interface BottomSheetSelectProps { + options: Option[]; + defaultOption?: Option; + value: string | null | undefined; + placeholder: string; + onChange: (value: string) => void; + icon?: ReactNode; + className?: string; +} + +const BottomSheetMDS = ({ + options, + defaultOption, + value, + placeholder, + onChange, + icon, + className, +}: BottomSheetSelectProps) => { + const [open, setOpen] = useState(false); + const [selectedValue, setSelectedValue] = useState(value); + const [temporaryValue, setTemporaryValue] = useState(value); + + const handleOpen = () => setOpen(true); + const handleClose = () => setOpen(false); + + const handleOptionSelect = (value: string) => { + setTemporaryValue(value); + }; + + const handleConfirm = () => { + setSelectedValue(temporaryValue); + onChange(temporaryValue as string); + + handleClose(); + }; + + useEffect(() => { + if (open) { + document.body.style.overflow = 'hidden'; + } else { + document.body.style.overflow = ''; + } + + return () => { + document.body.style.overflow = ''; + }; + }, [open]); + + const getSelectedLabel = (value: string) => { + return options.find((option) => Number(option.value) === Number(value))?.label; + }; + + return ( + <Container> + <InputField onClick={handleOpen} className={className}> + {selectedValue ? ( + <p>{getSelectedLabel(selectedValue)}</p> + ) : ( + <p style={{ color: '#808087', whiteSpace: 'pre-wrap' }}>{placeholder}</p> + )} + + {icon || ( + <IconChevronDown + style={{ + width: 20, + minWidth: 20, + height: 20, + minHeight: 20, + transform: open ? 'rotate(-180deg)' : '', + transition: 'all 0.5s', + }} + /> + )} + </InputField> + + {open && ( + <Portal portalId='bottomsheet'> + <Overlay /> + <BottomSheet> + <OptionList> + {defaultOption && ( + <OptionItem onClick={() => handleOptionSelect(String(defaultOption.value))}> + {defaultOption.label} + {temporaryValue === defaultOption.value && <CheckedIcon />} + </OptionItem> + )} + {options.map((option) => ( + <OptionItem key={option.value} onClick={() => handleOptionSelect(String(option.value))}> + <StItemDiv> + {option.label} + <OptionSubItem>{option.description}</OptionSubItem> + </StItemDiv> + {temporaryValue === option.value && <CheckedIcon />} + </OptionItem> + ))} + </OptionList> + <Button size='lg' style={{ width: '100%' }} onClick={handleConfirm}> + ํ™•์ธ + </Button> + </BottomSheet> + </Portal> + )} + </Container> + ); +}; +export default BottomSheetMDS; + +const Container = styled.div` + position: relative; + width: 100%; +`; + +const InputField = styled.div` + display: flex; + gap: 12px; + align-items: center; + justify-content: space-between; + border-radius: 10px; + background-color: ${colors.gray800}; + cursor: pointer; + padding: 11px 16px; + ${fonts.BODY_16_M}; + + max-width: calc(100vw - 40px); + + p { + width: 100%; + overflow: hidden; /* ๋„˜์น˜๋Š” ํ…์ŠคํŠธ ์ˆจ๊น€ */ + text-overflow: ellipsis; + white-space: nowrap; /* ํ…์ŠคํŠธ ์ค„ ๋ฐ”๊ฟˆ ๋ฐฉ์ง€ */ + } +`; + +const Overlay = styled.div` + position: fixed; + top: 0; + left: 0; + z-index: ${zIndex.ํ—ค๋”}; + background-color: rgb(15 15 18 / 80%); + width: 100%; + height: 100%; +`; + +const BottomSheet = styled.section` + position: fixed; + bottom: 0; + left: 20px; + z-index: ${zIndex.ํ—ค๋”}; + margin-bottom: 12px; + border-radius: 16px; + background-color: ${colors.gray800}; + padding: 16px; + width: calc(100% - 40px); +`; + +const OptionList = styled.ul` + margin: 0 0 16px; + padding: 0; + max-height: 300px; + overflow-y: auto; + list-style: none; +`; + +const OptionItem = styled.li` + display: flex; + align-items: center; + justify-content: space-between; + border-radius: 8px; + cursor: pointer; + padding: 10px; + height: 66px; + ${fonts.BODY_14_M} + + &:hover { + background-color: ${colors.gray700}; + } +`; +const OptionSubItem = styled.div` + margin-top: 2px; + ${fonts.BODY_13_R} + + color:${colors.gray200} +`; + +const CheckedIcon = styled(IconCheck)` + width: 24px; + height: 24px; + color: ${colors.success}; +`; +const StItemDiv = styled.div` + width: 100%; +`;
Unknown
์•„ UI๊ฐ€ ์ข€ ๋‹ฌ๋ž๊ตฐ์š”~!!! ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค ใ…Žใ…Žใ…Ž
@@ -0,0 +1,31 @@ +package com.spoteditor.backend.domain.user.controller; + +import com.spoteditor.backend.common.exceptions.user.UserException; +import com.spoteditor.backend.common.exceptions.user.UserErrorCode; +import com.spoteditor.backend.domain.user.service.UserTokenService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class AuthController { + + private final UserTokenService userTokenService; + + @PostMapping("/auth/refresh") + public ResponseEntity<Void> refreshAccessToken (HttpServletRequest request, HttpServletResponse response) throws Exception { + userTokenService.refreshAccessToken(request, response); + + return new ResponseEntity<>(HttpStatus.OK); + } +}
Java
BaseException์ด RuntimeException์„ ์ƒ์†๋ฐ›๋Š” ์ €ํฌ ํ”„๋กœ์ ํŠธ์˜ ์ตœ์ƒ์œ„ ์˜ˆ์™ธ๊ฐ€ ๋งž๋‹ค๋ฉด ์ง์ ‘ ๋…ธ์ถœ์„ ํ•  ํ•„์š”๊ฐ€ ์—†์–ด๋ณด์ž…๋‹ˆ๋‹ค. ์ตœ์ƒ์œ„ ์–ธ์ฒดํฌ ์˜ˆ์™ธ๋ฅผ ๊ฐœ๋ฐœ ํ›„ ๊ทธ ์–ธ์ฒดํฌ ์˜ˆ์™ธ๋ฅผ ์ƒ์†๋ฐ›๊ณ  ๊ฐ๊ฐ์˜ ์ปค์Šคํ…€ ์˜ค๋ฅ˜ ์ฝ”๋“œ๋ฅผ ๋“ฑ๋กํ•œ๋‹ค๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋Š” ์„ธ๋ฐ€ํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,41 @@ +package com.spoteditor.backend.domain.user.service; + +import com.spoteditor.backend.common.exceptions.user.UserErrorCode; +import com.spoteditor.backend.common.exceptions.user.UserException; +import com.spoteditor.backend.common.util.CookieUtils; +import com.spoteditor.backend.domain.user.common.dto.UserIdDto; +import com.spoteditor.backend.security.jwt.JwtConstants; +import com.spoteditor.backend.security.jwt.JwtUtils; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserTokenService { + + private final JwtUtils jwtUtils; + private final CookieUtils cookieUtils; + + public void refreshAccessToken(HttpServletRequest request, HttpServletResponse response) throws Exception { + String refreshToken = cookieUtils.getRefreshToken(request); + + if(refreshToken == null) { + throw new UserException(UserErrorCode.REFRESH_TOKEN_NOT_IN_COOKIE); + } + + try { + // RefreshToken ๊ฒ€์ฆ + UsernamePasswordAuthenticationToken authentication = jwtUtils.setAuthentication(refreshToken); + UserIdDto userIdDto = (UserIdDto) authentication.getPrincipal(); + + // ๊ฒ€์ฆ ์„ฑ๊ณต -> accessToken ๋ฐœ๊ธ‰ + String accessToken = jwtUtils.createAccessToken(userIdDto.getId()); + cookieUtils.setAccessTokenCookie(response, JwtConstants.ACCESS_TOKEN, accessToken); + } catch (UserException e) { + throw new UserException(UserErrorCode.REFRESH_TOKEN_INVALID); + } + } +}
Java
์ด ๋ถ€๋ถ„๋„ ๋™์ผํ•œ ๋งฅ๋ฝ์ž…๋‹ˆ๋‹ค.
@@ -0,0 +1,43 @@ +package com.spoteditor.backend.security.oauth.handler; + +import com.spoteditor.backend.common.util.CookieUtils; +import com.spoteditor.backend.security.jwt.JwtConstants; +import com.spoteditor.backend.security.jwt.JwtUtils; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.Authentication; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.Map; + +@Component +@RequiredArgsConstructor +public class OauthSuccessHandler implements AuthenticationSuccessHandler { + + private final JwtUtils jwtUtils; + private final CookieUtils cookieUtils; + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { + OAuth2User oauthUser = (OAuth2User) authentication.getPrincipal(); + + Map<String, Object> attributesMap = oauthUser.getAttributes(); + + Long id = (Long) attributesMap.get("id"); + String name = (String) attributesMap.get("name"); + + String accessToken = jwtUtils.createAccessToken(id); + String refreshToken = jwtUtils.createRefreshToken(id); + + cookieUtils.setAccessTokenCookie(response, JwtConstants.ACCESS_TOKEN, accessToken); + cookieUtils.setRefreshTokenCookie(response, JwtConstants.REFRESH_TOKEN, refreshToken); + +// redirect + response.sendRedirect("/success"); + } +}
Java
`/success` ๊ฒฝ๋กœ๊ฐ€ ์ฝœ๋ฐฑ ์ฒ˜๋ฆฌ์ธ๊ฐ€์š”?
@@ -0,0 +1,43 @@ +package com.spoteditor.backend.security.oauth.handler; + +import com.spoteditor.backend.common.util.CookieUtils; +import com.spoteditor.backend.security.jwt.JwtConstants; +import com.spoteditor.backend.security.jwt.JwtUtils; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.Authentication; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.Map; + +@Component +@RequiredArgsConstructor +public class OauthSuccessHandler implements AuthenticationSuccessHandler { + + private final JwtUtils jwtUtils; + private final CookieUtils cookieUtils; + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { + OAuth2User oauthUser = (OAuth2User) authentication.getPrincipal(); + + Map<String, Object> attributesMap = oauthUser.getAttributes(); + + Long id = (Long) attributesMap.get("id"); + String name = (String) attributesMap.get("name"); + + String accessToken = jwtUtils.createAccessToken(id); + String refreshToken = jwtUtils.createRefreshToken(id); + + cookieUtils.setAccessTokenCookie(response, JwtConstants.ACCESS_TOKEN, accessToken); + cookieUtils.setRefreshTokenCookie(response, JwtConstants.REFRESH_TOKEN, refreshToken); + +// redirect + response.sendRedirect("/success"); + } +}
Java
๋„ค ๋งž์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,31 @@ +package com.spoteditor.backend.domain.user.controller; + +import com.spoteditor.backend.common.exceptions.user.UserException; +import com.spoteditor.backend.common.exceptions.user.UserErrorCode; +import com.spoteditor.backend.domain.user.service.UserTokenService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class AuthController { + + private final UserTokenService userTokenService; + + @PostMapping("/auth/refresh") + public ResponseEntity<Void> refreshAccessToken (HttpServletRequest request, HttpServletResponse response) throws Exception { + userTokenService.refreshAccessToken(request, response); + + return new ResponseEntity<>(HttpStatus.OK); + } +}
Java
๋‹ต๋ณ€์ฃผ์‹  ๋‚ด์šฉ์ด BaseException์„ ์ƒ์†๋ฐ›๋Š” ๊ฐ๊ฐ์˜ ์ปค์Šคํ…€ ์˜ค๋ฅ˜ ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•ด์„œ ๋” ์˜๋ฏธ๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ํ•˜๋ผ๋Š” ๋ง์”€์ด์‹ ๊ฐ€์š”?
@@ -0,0 +1,31 @@ +package com.spoteditor.backend.domain.user.controller; + +import com.spoteditor.backend.common.exceptions.user.UserException; +import com.spoteditor.backend.common.exceptions.user.UserErrorCode; +import com.spoteditor.backend.domain.user.service.UserTokenService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class AuthController { + + private final UserTokenService userTokenService; + + @PostMapping("/auth/refresh") + public ResponseEntity<Void> refreshAccessToken (HttpServletRequest request, HttpServletResponse response) throws Exception { + userTokenService.refreshAccessToken(request, response); + + return new ResponseEntity<>(HttpStatus.OK); + } +}
Java
๋„ค, ์ง€๊ธˆ ์ฝ”๋“œ๋ฅผ ๋ณด์‹œ๋ฉด BaseException์„ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๋˜์–ด ์žˆ๋Š”๋ฐ ์ถ”๊ฐ€ ์š”๊ตฌ์‚ฌํ•ญ ์ ‘์ˆ˜์‹œ ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,31 @@ +package com.spoteditor.backend.domain.user.controller; + +import com.spoteditor.backend.common.exceptions.user.UserException; +import com.spoteditor.backend.common.exceptions.user.UserErrorCode; +import com.spoteditor.backend.domain.user.service.UserTokenService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class AuthController { + + private final UserTokenService userTokenService; + + @PostMapping("/auth/refresh") + public ResponseEntity<Void> refreshAccessToken (HttpServletRequest request, HttpServletResponse response) throws Exception { + userTokenService.refreshAccessToken(request, response); + + return new ResponseEntity<>(HttpStatus.OK); + } +}
Java
๊ทธ๋ฆฌ๊ณ  ์ถ”๊ฐ€์ ์œผ๋กœ ๋ง์”€์„ ๋“œ๋ฆฌ๋Š”๊ฑด ์ €ํฌ ๊ฐ„ํŠธ ์ฐจํŠธ์— ์žˆ๋Š” ๊ทœ์•ฝ์„ ๋‹ค์‹œ ํ•œ ๋ฒˆ ์ดํ•ด๋ฅผ ํ•˜์…”์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค POST ์š”์ฒญ์ธ ๊ฒฝ์šฐ์—๋Š” ๋ถ„๋ช… ๋ฐ”๋””๊ฐ€ ์—†์ด HTTP Status Code๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณด๋‚ด์ค˜์•ผํ•˜๋Š”๋ฐ ์˜คํžˆ๋ ค List ์ปฌ๋ ‰์…˜์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,41 @@ +package com.spoteditor.backend.domain.user.service; + +import com.spoteditor.backend.common.exceptions.user.UserErrorCode; +import com.spoteditor.backend.common.exceptions.user.UserException; +import com.spoteditor.backend.common.util.CookieUtils; +import com.spoteditor.backend.domain.user.common.dto.UserIdDto; +import com.spoteditor.backend.security.jwt.JwtConstants; +import com.spoteditor.backend.security.jwt.JwtUtils; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserTokenService { + + private final JwtUtils jwtUtils; + private final CookieUtils cookieUtils; + + public void refreshAccessToken(HttpServletRequest request, HttpServletResponse response) throws Exception { + String refreshToken = cookieUtils.getRefreshToken(request); + + if(refreshToken == null) { + throw new UserException(UserErrorCode.REFRESH_TOKEN_NOT_IN_COOKIE); + } + + try { + // RefreshToken ๊ฒ€์ฆ + UsernamePasswordAuthenticationToken authentication = jwtUtils.setAuthentication(refreshToken); + UserIdDto userIdDto = (UserIdDto) authentication.getPrincipal(); + + // ๊ฒ€์ฆ ์„ฑ๊ณต -> accessToken ๋ฐœ๊ธ‰ + String accessToken = jwtUtils.createAccessToken(userIdDto.getId()); + cookieUtils.setAccessTokenCookie(response, JwtConstants.ACCESS_TOKEN, accessToken); + } catch (UserException e) { + throw new UserException(UserErrorCode.REFRESH_TOKEN_INVALID); + } + } +}
Java
์ด UserIdDto๋ฅผ ์ปจํŠธ๋กค๋Ÿฌ์—์„œ ์–ด๋–ป๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋ฅผ ๋ฌธ์„œํ™”ํ•ด์ฃผ์‹œ๋ฉด ์ฝ์–ด๋ณด๊ณ  ๊ณต๊ฐ„ ์ธก์— ์ ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
์˜ค ๊ตฌ์กฐ๋ถ„ํ•ด ํ• ๋‹น~
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
this.state.id.includes('@') && this.state.id.length >= 5 && this.state.pw.length >= 8 ์ด๊ฑธ true/false Boolean?? ์ด๊ฐ’์„ ์‚ฌ์šฉํ•ด์„œ ์‚ผํ•ญ์—ฐ์‚ฐ์ž๋กœ ํ•ด๋„ ๋˜์ง€ ์•Š์„๊นŒ์š” ์ˆ˜์ •๋‹˜์€ ์ž˜ํ•˜์‹œ๋‹ˆ ์•„๋งˆ๊ฐ€๋Šฅํ•˜์‹ค๋“ฏ!
@@ -0,0 +1,61 @@ +.Login { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + + main { + display: flex; + flex-direction: column; + justify-content: space-around; + width: 350px; + height: 380px; + padding: 40px; + border: 1px solid #ccc; + + header { + h1 { + font-family: 'Lobster', cursive; + text-align: center; + } + } + + .loginInputBox { + form { + display: flex; + flex-direction: column; + justify-content: center; + + input { + margin-bottom: 5px; + padding: 9px 8px 7px; + background-color: rgb(250, 250, 250); + border: 1px solid rgb(38, 38, 38); + border-radius: 3px; + } + + .loginBtn { + margin-top: 10px; + padding: 9px 8px 7px; + border: none; + border-radius: 3px; + color: #fff; + background-color: #0096f6; + &:disabled { + background-color: #c0dffd; + } + } + } + } + + footer { + .findPassword { + display: block; + margin-top: 50px; + text-align: center; + color: #00376b; + font-size: 14px; + } + } + } +}
Unknown
์ด๊ฑด ์™œ ์ฃผ์„์œผ๋กœ ๋˜์žˆ๋‚˜์š”???
@@ -0,0 +1,134 @@ +[ + { + "id": 1, + "userName": "eessoo__", + "src": "../images/soojeongLee/user2.jpg", + "feedText": "๐Ÿ’Ÿ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "soojeonglee", + "content": "Hi there.", + "commnetLike": false + }, + { + "id": 3, + "userName": "jaehyunlee", + "content": "Hey.", + "commnetLike": false + }, + { + "id": 4, + "userName": "gyeongminlee", + "content": "Hi.", + "commnetLike": true + } + ], + "isLike": false + }, + { + "id": 2, + "userName": "zz_ing94", + "src": "../../images/soojeongLee/user3.jpg", + "feedText": "Toy story ๐Ÿ’š", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "jisuoh", + "content": "โœจ", + "commnetLike": true + }, + { + "id": 3, + "userName": "jungjunsung", + "content": "coffee", + "commnetLike": false + }, + { + "id": 4, + "userName": "somihwang", + "content": "ํฌํ‚ค", + "commnetLike": true + } + ], + "isLike": false + }, + { + "id": 3, + "userName": "hwayoonci", + "src": "../../images/soojeongLee/user4.jpg", + "feedText": "์˜ค๋Š˜์˜ ์ผ๊ธฐ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "yunkyunglee", + "content": "๊ท€์—ฌ์šด ์Šคํ‹ฐ์ปค", + "commnetLike": true + }, + { + "id": 3, + "userName": "summer", + "content": "๐Ÿถ", + "commnetLike": false + }, + { + "id": 4, + "userName": "uiyeonlee", + "content": "๐Ÿ‘๐Ÿป", + "commnetLike": true + } + ], + "isLike": true + }, + { + "id": 4, + "userName": "cosz_zy", + "src": "../../images/soojeongLee/user5.jpg", + "feedText": "1์ผ ํ™”๊ฐ€ ๐ŸŽจ ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "soojeonglee", + "content": "Hi there.", + "commnetLike": false + }, + { + "id": 3, + "userName": "jaehyunlee", + "content": "Hey.", + "commnetLike": true + }, + { + "id": 4, + "userName": "gyeongminlee", + "content": "Hi.", + "commnetLike": true + } + ], + "isLike": false + } +]
Unknown
์ œ์ด์Šจ ํŒŒ์ผ๋„ ์žˆ์—ˆ๊ตฐ์š”!
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
์˜ค ์ด๋ ‡๊ฒŒ ๋‹ค์‹œ ๋ณผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•๋„ ๋‚˜์˜์ง€ ์•Š์€ ๋“ฏ ? ๋‚˜์ค‘์— ๊ฐ€์„œ๋Š” ์ง€์›Œ์•ผ ๋  ์ˆ˜๋„ ์žˆ์ง€๋งŒ...?
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
๋ฒ„ํŠผ์œผ๋กœ ํ•œ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”? ๊ถ๊ธˆ
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
autoComplete ์ด๊ฑฐ๋Š” ๋ญ”๊ฐ€์š”? ๊ถ๊ธˆ~
@@ -0,0 +1,128 @@ +@import '../../../../styles/variables.scss'; + +article { + margin-bottom: 20px; + background-color: #fff; + border-radius: 3px; + border: 1px solid $border-color; + + header { + @include flex-center; + justify-content: space-between; + align-content: center; + padding: 10px; + + h1 { + @include flex-center; + + .contentHeader { + @include userProfile; + margin-right: 10px; + background-image: url('http://localhost:3000/images/soojeongLee/userImage.jpg'); + background-size: cover; + } + .userName { + font-size: 16px; + font-weight: 600; + } + } + + .ellipsis { + @include button; + font-size: 22px; + .ellipsisIcon { + font-weight: 400; + } + } + } + + .feedContent { + img { + width: 100%; + } + + .reactionsBox { + @include flex-center; + justify-content: space-between; + padding: 5px 10px; + + .reactionsLeft { + display: flex; + + .leftButton { + @include button; + font-size: 22px; + margin-right: 10px; + + .fa-external-link-alt { + font-size: 20px; + } + } + } + + .reactionsRight { + .rightButton { + @include button; + font-size: 22px; + } + } + } + + h2 { + display: flex; + align-items: center; + padding: 0 10px 10px; + font-size: 16px; + font-weight: normal; + + .feedConUser { + @include userProfile; + margin-right: 5px; + background-image: url('http://localhost:3000/images/soojeongLee/user7.jpg'); + background-size: cover; + } + + .likeCount { + @include button; + margin-left: 4px; + font-size: 16px; + } + } + + .feedText { + margin-bottom: 10px; + padding: 0 10px; + + .postTime { + @include postTime; + margin-top: 5px; + font-size: 14px; + font-weight: bold; + } + } + } + + .feedFooter { + background-color: #fff; + border-top: 1px solid $border-color; + + .inputBox { + display: flex; + padding: 10px; + + .comment { + flex: 9; + border: none; + outline: none; + } + + .commentSubmit { + @include button; + flex: 1; + &:hover { + color: $summit-color; + } + } + } + } +}
Unknown
์ด๋Ÿฐ scss ๊ธฐ๋Šฅ ์ €๋Š” ํ—ท๊ฐˆ๋ ค์„œ ์ž˜ ๋ชปํ•˜๊ฒ ๋˜๋ฐ ์ž˜ํ•˜์‹œ๋„ค์š”..
@@ -0,0 +1,23 @@ +//๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +//์ปดํฌ๋„ŒํŠธ +import { FOOTLIST } from '../FootLists/footData'; + +// css +import './FootLists.scss'; + +export class FootLists extends Component { + render() { + return FOOTLIST.map(footlists => { + return ( + <Link to="" className="listDot" key={footlists.id}> + {footlists.footlist} + </Link> + ); + }); + } +} + +export default FootLists;
JavaScript
๋Œ“๊ธ€ ํ”„๋ž์Šค!
@@ -0,0 +1,46 @@ +export const FOOTLIST = [ + { + id: 1, + footlist: '์†Œ๊ฐœ', + }, + { + id: 2, + footlist: '๋„์›€๋ง', + }, + { + id: 3, + footlist: 'ํ™๋ณด ์„ผํ„ฐ', + }, + { + id: 4, + footlist: 'API', + }, + { + id: 5, + footlist: '์ฑ„์šฉ ์ •๋ณด', + }, + { + id: 6, + footlist: '๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ', + }, + { + id: 7, + footlist: '์•ฝ๊ด€', + }, + { + id: 8, + footlist: '์œ„์น˜', + }, + { + id: 9, + footlist: '์ธ๊ธฐ ๊ณ„์ •', + }, + { + id: 10, + footlist: 'ํ•ด์‹œํƒœ๊ทธ', + }, + { + id: 11, + footlist: '์–ธ์–ด', + }, +];
JavaScript
ํ™”์ดํŒ… ํ‘ธํ„ฐ ๋งŒ๋“ค์–ด์„œ ๊ฐ•์˜ ๋ถ€ํƒ๋“œ๋ ค์š”