code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -0,0 +1,20 @@ +import { VISIT_DATE_MESSAGE } from '../messages/errorMessages'; +import { EVENT } from '../constants/event'; +import CustomError from '../errors/CustomError'; + +export const validateVisitDate = (visitDate) => { + validateType(visitDate); + validateRange(visitDate); +}; + +const validateType = (visitDate) => { + if (typeof visitDate !== 'number' || Number.isNaN(visitDate)) { + throw new CustomError(VISIT_DATE_MESSAGE.invalidNumber); + } +}; + +const validateRange = (visitDate) => { + if (visitDate < EVENT.startDate || visitDate > EVENT.endDate) { + throw new CustomError(VISIT_DATE_MESSAGE.invalidRange); + } +};
JavaScript
์•— ์ด๊ฑด ์ƒ๊ฐ ๋ชปํ•œ ์˜ˆ์™ธ๋„ค์š”... ํ•„ํ„ฐ๋ง ์•ˆ๋ฉ๋‹ˆ๋‹ค.. ์ถ”ํ›„ ๋ฆฌํŒฉํ† ๋งํ• ๋•Œ ์ˆ˜์ •ํ•ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!
@@ -0,0 +1,56 @@ +import Planner from '../domain/Planner'; +import InputView from '../view/InputView'; +import OutputView from '../view/OutputView'; + +class ChristmasController { + #planner; + + constructor() { + this.#planner = new Planner(); + } + + async play() { + await this.#setPlan(); + this.#showBeforeDiscount(); + this.#showAfterDiscount(); + } + + async #setPlan() { + await this.#retryInput(async () => { + const visitDate = await InputView.readVisitDate(); + this.#planner.setVisitDate(visitDate); + }); + + await this.#retryInput(async () => { + const order = await InputView.readOrder(); + this.#planner.setOrder(order); + }); + } + + #showBeforeDiscount() { + OutputView.printPreviewTitle(this.#planner.getVisitDate()); + OutputView.printOrder(this.#planner.getOrder()); + OutputView.printPriceBeforeDiscount(this.#planner.getPrice()); + } + + #showAfterDiscount() { + const [discount, discountTotal] = this.#planner.caculateDiscount(); + + OutputView.printGift(discount?.gift); + OutputView.printDiscountInfo(discount); + OutputView.printTotalDiscount(discountTotal); + OutputView.printPriceAfterDiscount(this.#planner.getPrice()); + OutputView.printBadge(this.#planner.getBadge(discountTotal)); + } + + async #retryInput(func) { + try { + return await func(); + } catch (error) { + OutputView.printError(error.message); + return this.#retryInput(func); + } + } +} + +export default ChristmasController;
JavaScript
๋ง์”€ํ•˜์‹ ๊ฒƒ์ฒ˜๋Ÿผ ํด๋”๋‚˜ ํŒŒ์ผ ์ด๋ฆ„์œผ๋กœ ์•Œ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์–ด๋А์ •๋„๋กœ ๋ช…ํ™•ํ•˜๊ฒŒ ์ด๋ฆ„์„ ์ง€์–ด์•ผ ํ• ์ง€ ํ•ญ์ƒ ๊ณ ๋ฏผ์ž…๋‹ˆ๋‹ค...๐Ÿฅฒ
@@ -0,0 +1,62 @@ +import { Console } from '@woowacourse/mission-utils'; +import { OUTPUT_MESSAGE, TITLE_MESSAGE, DISCOUNT_MESSAGE } from '../utils/messages/printMessages'; + +const OutputView = { + printPreviewTitle(date) { + Console.print(OUTPUT_MESSAGE.preview(date)); + }, + + printOrder(order) { + Console.print(TITLE_MESSAGE.order); + + Array.from(order.entries()).forEach(([menu, menuCount]) => { + Console.print(OUTPUT_MESSAGE.menu(menu.getName(), menuCount)); + }); + }, + + printPriceBeforeDiscount(price) { + Console.print(TITLE_MESSAGE.priceBeforeDiscount); + Console.print(OUTPUT_MESSAGE.price(price)); + }, + + printGift(gift) { + Console.print(TITLE_MESSAGE.gift); + gift ? Console.print(OUTPUT_MESSAGE.gift()) : Console.print(OUTPUT_MESSAGE.nothing); + }, + + printDiscountInfo(discounts) { + Console.print(TITLE_MESSAGE.discount); + + if (Object.values(discounts).every((value) => value === 0)) { + Console.print(OUTPUT_MESSAGE.nothing); + return; + } + + Object.entries(discounts).forEach(([discountName, discountPrice]) => { + if (discountPrice !== 0) { + Console.print(DISCOUNT_MESSAGE[discountName](discountPrice)); + } + }); + }, + + printTotalDiscount(price) { + Console.print(TITLE_MESSAGE.totalDiscount); + Console.print(price ? OUTPUT_MESSAGE.discountPrice(price) : OUTPUT_MESSAGE.price(price)); + }, + + printPriceAfterDiscount(price) { + Console.print(TITLE_MESSAGE.priceAfterDiscount); + Console.print(OUTPUT_MESSAGE.price(price)); + }, + + printBadge(badge) { + Console.print(TITLE_MESSAGE.badge); + badge ? Console.print(badge) : Console.print(OUTPUT_MESSAGE.nothing); + }, + + printError(errorMessage) { + Console.print(errorMessage); + }, +}; + +export default OutputView;
JavaScript
`Object.entries`๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์—ˆ๊ตฐ์š”...!! ์ด ๋ฐฉ๋ฒ•์€ ๋ฏธ์ฒ˜ ์ƒ๊ฐํ•˜์ง€ ๋ชปํ–ˆ๋Š”๋ฐ ๋ฐฐ์šฐ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค !!!
@@ -0,0 +1,34 @@ +import { MENU_MESSAGE, MENU_COUNT_MESSAGE } from '../messages/errorMessages'; +import { MENU } from '../constants/menu'; +import { VALIDATION } from '../constants/event'; +import CustomError from '../errors/CustomError'; + +export const validateMenuName = (name) => { + validateExist(name); +}; + +export const validateMenuCount = (menuCount) => { + validateType(menuCount); + validateRange(menuCount); +}; + +const validateExist = (name) => { + for (const menuItems of Object.values(MENU)) { + if (menuItems.hasOwnProperty(name)) { + return; + } + } + throw new CustomError(MENU_MESSAGE.isNotExistMenu); +}; + +const validateType = (menuCount) => { + if (typeof menuCount !== 'number' || Number.isNaN(menuCount)) { + throw new CustomError(MENU_COUNT_MESSAGE.invalidNumber); + } +}; + +const validateRange = (menuCount) => { + if (menuCount < VALIDATION.minMenuCount) { + throw new CustomError(MENU_COUNT_MESSAGE.minMenuCount); + } +};
JavaScript
javascript airbnb์— ๋”ฐ๋ฅด๋ฉด ์ถ”์ฒœํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋‹ˆ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค ! `forEach`๋‚˜ `map`์„ ์‚ฌ์šฉํ•˜์‹œ๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?? ์ฐธ๊ณ  : [Javascript airbnb 11.1](https://github.com/tipjs/javascript-style-guide#11.1)
@@ -0,0 +1,4 @@ +export const priceFormatter = new Intl.NumberFormat('ko-KR', { + minimumFractionDigits: 0, + maximumFractionDigits: 0, +});
JavaScript
toLocaleString() ํ•จ์ˆ˜ ๋ง๊ณ  ์ด๋ ‡๊ฒŒ ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”??
@@ -1,3 +1,5 @@ +import {ReviewLikeButtonProps} from "@review-canvas/theme"; + export type Shadow = 'NONE' | 'SMALL' | 'MEDIUM' | 'LARGE'; export type FocusAreaLayout = 'BEST_REVIEW_TOP' | 'BEST_REVIEW_BOTTOM' | 'BEST_REVIEW_LEFT' | 'BEST_REVIEW_RIGHT'; export type ReviewAreaLayout = 'REVIEW_TOP' | 'REVIEW_BOTTOM' | 'REVIEW_LEFT' | 'REVIEW_RIGHT'; @@ -6,6 +8,7 @@ export type AlignmentPosition = 'LEFT' | 'CENTER' | 'RIGHT'; export type DetailViewType = 'SPREAD' | 'MODAL'; export type PagingType = 'PAGE_NUMBER' | 'SEE_MORE_SCROLL'; export type FilterType = 'LIST' | 'DROPDOWN'; +export type ReviewLikeButtonType = 'NONE' | 'THUMB_UP_WITH_TEXT' | 'THUMB_UP'; export interface Margin { left: string; @@ -43,11 +46,11 @@ export interface Round { } export interface ReviewLike { - buttonType: string; - iconColor: string; - textColor: string; buttonBorderColor: string; buttonRound: Round; + buttonType: ReviewLikeButtonType; + iconColor: string; + textColor: string; } export interface ReviewLayout {
TypeScript
์ „์ฒด์ ์œผ๋กœ Prettier๊ฐ€ ์ ์šฉ์ด ์•ˆ ๋˜์–ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ Prettier ์ „์ฒด์ ์œผ๋กœ ์ ์šฉํ•ด ์ฃผ์„ธ์š”!
@@ -9,50 +9,55 @@ import { generateShadowCSS, } from '@review-canvas/theme'; +// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg'; import { Star } from '@/components/review/star.tsx'; import { useReviewItemStyle } from '@/contexts/style/review-item.ts'; import useMessageToShop from '@/hooks/use-message-to-shop.ts'; -import type { ReplyItem } from '@/services/api-types/review'; +import type { ReviewItemProps } from '@/services/api-types/review'; +import { useReviewService } from '@/services/review.tsx'; import { useConnectedShop } from '@/state/shop.ts'; import { MESSAGE_TYPES } from '@/utils/message'; import Reply from './reply'; - -interface ReviewItemProps { - id: number; - rate: number; - content: string; - reviewerID: string; - reviewer: string; - replies: ReplyItem[]; -} +import { useEffect, useState } from 'react'; export default function ReviewItem(props: ReviewItemProps) { const style = useReviewItemStyle(); const { userID } = useConnectedShop(); + const reviewService = useReviewService(); const message = useMessageToShop(); + const [count, setCount] = useState(0); + + useEffect(() => { + async function fetchData() { + return reviewService.userReviewLike(props.id); + } + void fetchData().then((response) => { + setCount(response.data.count); + }); + }, [props.id, reviewService]); const edit = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'edit_review', url: `/reviews/${props.id}/edit`, }); }; - const deleteReview = () => { message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, { type: 'delete', url: `/reviews/${props.id}/delete`, }); }; - const showReviewDetail = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'detail', url: `/reviews/${props.id}`, }); }; + const createLike = () => {}; + return ( <li css={[ @@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) { generateFontCSS(style.font), generateShadowCSS(style.shadow, style.shadowColor), css` + border-color: ${style.borderColor}; background-color: ${style.backgroundColor}; display: flex; flex-direction: column; @@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) { ์ž‘์„ฑ์ž <span>{props.reviewer}</span> </div> <p className="text-left">{props.content}</p> + {/*{style.reviewLike.buttonType !== 'NONE' ? (*/} + {/* <button*/} + {/* onClick={(evt) => {*/} + {/* evt.stopPropagation();*/} + {/* if (userID === props.reviewerID) {*/} + {/* return;*/} + {/* }*/} + {/* }}*/} + {/* css={[*/} + {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/} + {/* css`*/} + {/* border-width: 1px;*/} + {/* padding: 2px 6px;*/} + {/* margin-top: 15px;*/} + {/* margin-bottom: 10px;*/} + {/* border-color: ${style.reviewLike.buttonBorderColor};*/} + {/* color: ${style.reviewLike.textColor};*/} + {/* transition:*/} + {/* background-color 0.5s ease,*/} + {/* color 0.5s ease;*/} + {/* display: flex;*/} + + {/* &:hover {*/} + {/* background-color: ${style.reviewLike.textColor};*/} + {/* color: white;*/} + {/* }*/} + {/* `,*/} + {/* ]}*/} + {/* >*/} + {/* <ThumbUpIcon />*/} + {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋„์›€๋ผ์š”!</div> : null}*/} + {/* <div className="ml-1">0</div>*/} + {/* </button>*/} + {/*) : null}*/} + <button + css={[ + generateBorderRadiusCSS(style.reviewLike.buttonRound), + css` + border-width: 1px; + padding: 2px 6px; + margin-top: 15px; + margin-bottom: 10px; + border-color: ${style.reviewLike.buttonBorderColor}; + color: ${style.reviewLike.textColor}; + transition: + background-color 0.5s ease, + color 0.5s ease; + display: flex; + + &:hover { + background-color: ${style.reviewLike.textColor}; + color: white; + } + `, + ]} + onClick={createLike} + type="button" + > + {/*<ThumbUpIcon />*/} + <div className="ml-1">๋„์›€๋ผ์š”!</div> + <div className="ml-1">{count}</div> + </button> {userID === props.reviewerID ? ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional <div
Unknown
svg๋Š” component๋กœ ๋ถ„๋ฆฌํ•ด์„œ Importํ•ด์„œ ์“ฐ๋Š” ๊ฒŒ ์–ด๋–จ๊ฐ€์š”?? ๋‹ค๋ฅธ ๊ณณ์—์„œ๋„ ์“ธ ์ˆ˜ ์žˆ๊ณ , ์ปดํฌ๋„ŒํŠธ ์ฝ”๋“œ ๋‚ด์—์„œ ๊ฐ€๋…์„ฑ์ด ์ข‹์ง€ ์•Š์€ ๊ฒƒ ๊ฐ™์•„์„œ์š”!
@@ -9,50 +9,55 @@ import { generateShadowCSS, } from '@review-canvas/theme'; +// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg'; import { Star } from '@/components/review/star.tsx'; import { useReviewItemStyle } from '@/contexts/style/review-item.ts'; import useMessageToShop from '@/hooks/use-message-to-shop.ts'; -import type { ReplyItem } from '@/services/api-types/review'; +import type { ReviewItemProps } from '@/services/api-types/review'; +import { useReviewService } from '@/services/review.tsx'; import { useConnectedShop } from '@/state/shop.ts'; import { MESSAGE_TYPES } from '@/utils/message'; import Reply from './reply'; - -interface ReviewItemProps { - id: number; - rate: number; - content: string; - reviewerID: string; - reviewer: string; - replies: ReplyItem[]; -} +import { useEffect, useState } from 'react'; export default function ReviewItem(props: ReviewItemProps) { const style = useReviewItemStyle(); const { userID } = useConnectedShop(); + const reviewService = useReviewService(); const message = useMessageToShop(); + const [count, setCount] = useState(0); + + useEffect(() => { + async function fetchData() { + return reviewService.userReviewLike(props.id); + } + void fetchData().then((response) => { + setCount(response.data.count); + }); + }, [props.id, reviewService]); const edit = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'edit_review', url: `/reviews/${props.id}/edit`, }); }; - const deleteReview = () => { message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, { type: 'delete', url: `/reviews/${props.id}/delete`, }); }; - const showReviewDetail = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'detail', url: `/reviews/${props.id}`, }); }; + const createLike = () => {}; + return ( <li css={[ @@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) { generateFontCSS(style.font), generateShadowCSS(style.shadow, style.shadowColor), css` + border-color: ${style.borderColor}; background-color: ${style.backgroundColor}; display: flex; flex-direction: column; @@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) { ์ž‘์„ฑ์ž <span>{props.reviewer}</span> </div> <p className="text-left">{props.content}</p> + {/*{style.reviewLike.buttonType !== 'NONE' ? (*/} + {/* <button*/} + {/* onClick={(evt) => {*/} + {/* evt.stopPropagation();*/} + {/* if (userID === props.reviewerID) {*/} + {/* return;*/} + {/* }*/} + {/* }}*/} + {/* css={[*/} + {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/} + {/* css`*/} + {/* border-width: 1px;*/} + {/* padding: 2px 6px;*/} + {/* margin-top: 15px;*/} + {/* margin-bottom: 10px;*/} + {/* border-color: ${style.reviewLike.buttonBorderColor};*/} + {/* color: ${style.reviewLike.textColor};*/} + {/* transition:*/} + {/* background-color 0.5s ease,*/} + {/* color 0.5s ease;*/} + {/* display: flex;*/} + + {/* &:hover {*/} + {/* background-color: ${style.reviewLike.textColor};*/} + {/* color: white;*/} + {/* }*/} + {/* `,*/} + {/* ]}*/} + {/* >*/} + {/* <ThumbUpIcon />*/} + {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋„์›€๋ผ์š”!</div> : null}*/} + {/* <div className="ml-1">0</div>*/} + {/* </button>*/} + {/*) : null}*/} + <button + css={[ + generateBorderRadiusCSS(style.reviewLike.buttonRound), + css` + border-width: 1px; + padding: 2px 6px; + margin-top: 15px; + margin-bottom: 10px; + border-color: ${style.reviewLike.buttonBorderColor}; + color: ${style.reviewLike.textColor}; + transition: + background-color 0.5s ease, + color 0.5s ease; + display: flex; + + &:hover { + background-color: ${style.reviewLike.textColor}; + color: white; + } + `, + ]} + onClick={createLike} + type="button" + > + {/*<ThumbUpIcon />*/} + <div className="ml-1">๋„์›€๋ผ์š”!</div> + <div className="ml-1">{count}</div> + </button> {userID === props.reviewerID ? ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional <div
Unknown
๋ถˆํ•„์š”ํ•œ console์€ ์ œ์™ธํ•ด์ฃผ์„ธ์š”! ์ž์‹ ์˜ ๋ฆฌ๋ทฐ์—๋Š” ๋„์›€๋ผ์š” ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ์˜คํžˆ๋ ค alert์œผ๋กœ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒŒ ๋‚ซ์ง€ ์•Š์„๊นŒ ์‹ถ๋„ค์š”
@@ -9,50 +9,55 @@ import { generateShadowCSS, } from '@review-canvas/theme'; +// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg'; import { Star } from '@/components/review/star.tsx'; import { useReviewItemStyle } from '@/contexts/style/review-item.ts'; import useMessageToShop from '@/hooks/use-message-to-shop.ts'; -import type { ReplyItem } from '@/services/api-types/review'; +import type { ReviewItemProps } from '@/services/api-types/review'; +import { useReviewService } from '@/services/review.tsx'; import { useConnectedShop } from '@/state/shop.ts'; import { MESSAGE_TYPES } from '@/utils/message'; import Reply from './reply'; - -interface ReviewItemProps { - id: number; - rate: number; - content: string; - reviewerID: string; - reviewer: string; - replies: ReplyItem[]; -} +import { useEffect, useState } from 'react'; export default function ReviewItem(props: ReviewItemProps) { const style = useReviewItemStyle(); const { userID } = useConnectedShop(); + const reviewService = useReviewService(); const message = useMessageToShop(); + const [count, setCount] = useState(0); + + useEffect(() => { + async function fetchData() { + return reviewService.userReviewLike(props.id); + } + void fetchData().then((response) => { + setCount(response.data.count); + }); + }, [props.id, reviewService]); const edit = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'edit_review', url: `/reviews/${props.id}/edit`, }); }; - const deleteReview = () => { message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, { type: 'delete', url: `/reviews/${props.id}/delete`, }); }; - const showReviewDetail = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'detail', url: `/reviews/${props.id}`, }); }; + const createLike = () => {}; + return ( <li css={[ @@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) { generateFontCSS(style.font), generateShadowCSS(style.shadow, style.shadowColor), css` + border-color: ${style.borderColor}; background-color: ${style.backgroundColor}; display: flex; flex-direction: column; @@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) { ์ž‘์„ฑ์ž <span>{props.reviewer}</span> </div> <p className="text-left">{props.content}</p> + {/*{style.reviewLike.buttonType !== 'NONE' ? (*/} + {/* <button*/} + {/* onClick={(evt) => {*/} + {/* evt.stopPropagation();*/} + {/* if (userID === props.reviewerID) {*/} + {/* return;*/} + {/* }*/} + {/* }}*/} + {/* css={[*/} + {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/} + {/* css`*/} + {/* border-width: 1px;*/} + {/* padding: 2px 6px;*/} + {/* margin-top: 15px;*/} + {/* margin-bottom: 10px;*/} + {/* border-color: ${style.reviewLike.buttonBorderColor};*/} + {/* color: ${style.reviewLike.textColor};*/} + {/* transition:*/} + {/* background-color 0.5s ease,*/} + {/* color 0.5s ease;*/} + {/* display: flex;*/} + + {/* &:hover {*/} + {/* background-color: ${style.reviewLike.textColor};*/} + {/* color: white;*/} + {/* }*/} + {/* `,*/} + {/* ]}*/} + {/* >*/} + {/* <ThumbUpIcon />*/} + {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋„์›€๋ผ์š”!</div> : null}*/} + {/* <div className="ml-1">0</div>*/} + {/* </button>*/} + {/*) : null}*/} + <button + css={[ + generateBorderRadiusCSS(style.reviewLike.buttonRound), + css` + border-width: 1px; + padding: 2px 6px; + margin-top: 15px; + margin-bottom: 10px; + border-color: ${style.reviewLike.buttonBorderColor}; + color: ${style.reviewLike.textColor}; + transition: + background-color 0.5s ease, + color 0.5s ease; + display: flex; + + &:hover { + background-color: ${style.reviewLike.textColor}; + color: white; + } + `, + ]} + onClick={createLike} + type="button" + > + {/*<ThumbUpIcon />*/} + <div className="ml-1">๋„์›€๋ผ์š”!</div> + <div className="ml-1">{count}</div> + </button> {userID === props.reviewerID ? ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional <div
Unknown
ts ignore๋Š” ํ˜น์‹œ ์™œ ์„ค์ •ํ•ด ๋†“์œผ์‹  ๊ฑธ๊นŒ์š”??
@@ -9,50 +9,55 @@ import { generateShadowCSS, } from '@review-canvas/theme'; +// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg'; import { Star } from '@/components/review/star.tsx'; import { useReviewItemStyle } from '@/contexts/style/review-item.ts'; import useMessageToShop from '@/hooks/use-message-to-shop.ts'; -import type { ReplyItem } from '@/services/api-types/review'; +import type { ReviewItemProps } from '@/services/api-types/review'; +import { useReviewService } from '@/services/review.tsx'; import { useConnectedShop } from '@/state/shop.ts'; import { MESSAGE_TYPES } from '@/utils/message'; import Reply from './reply'; - -interface ReviewItemProps { - id: number; - rate: number; - content: string; - reviewerID: string; - reviewer: string; - replies: ReplyItem[]; -} +import { useEffect, useState } from 'react'; export default function ReviewItem(props: ReviewItemProps) { const style = useReviewItemStyle(); const { userID } = useConnectedShop(); + const reviewService = useReviewService(); const message = useMessageToShop(); + const [count, setCount] = useState(0); + + useEffect(() => { + async function fetchData() { + return reviewService.userReviewLike(props.id); + } + void fetchData().then((response) => { + setCount(response.data.count); + }); + }, [props.id, reviewService]); const edit = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'edit_review', url: `/reviews/${props.id}/edit`, }); }; - const deleteReview = () => { message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, { type: 'delete', url: `/reviews/${props.id}/delete`, }); }; - const showReviewDetail = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'detail', url: `/reviews/${props.id}`, }); }; + const createLike = () => {}; + return ( <li css={[ @@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) { generateFontCSS(style.font), generateShadowCSS(style.shadow, style.shadowColor), css` + border-color: ${style.borderColor}; background-color: ${style.backgroundColor}; display: flex; flex-direction: column; @@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) { ์ž‘์„ฑ์ž <span>{props.reviewer}</span> </div> <p className="text-left">{props.content}</p> + {/*{style.reviewLike.buttonType !== 'NONE' ? (*/} + {/* <button*/} + {/* onClick={(evt) => {*/} + {/* evt.stopPropagation();*/} + {/* if (userID === props.reviewerID) {*/} + {/* return;*/} + {/* }*/} + {/* }}*/} + {/* css={[*/} + {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/} + {/* css`*/} + {/* border-width: 1px;*/} + {/* padding: 2px 6px;*/} + {/* margin-top: 15px;*/} + {/* margin-bottom: 10px;*/} + {/* border-color: ${style.reviewLike.buttonBorderColor};*/} + {/* color: ${style.reviewLike.textColor};*/} + {/* transition:*/} + {/* background-color 0.5s ease,*/} + {/* color 0.5s ease;*/} + {/* display: flex;*/} + + {/* &:hover {*/} + {/* background-color: ${style.reviewLike.textColor};*/} + {/* color: white;*/} + {/* }*/} + {/* `,*/} + {/* ]}*/} + {/* >*/} + {/* <ThumbUpIcon />*/} + {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋„์›€๋ผ์š”!</div> : null}*/} + {/* <div className="ml-1">0</div>*/} + {/* </button>*/} + {/*) : null}*/} + <button + css={[ + generateBorderRadiusCSS(style.reviewLike.buttonRound), + css` + border-width: 1px; + padding: 2px 6px; + margin-top: 15px; + margin-bottom: 10px; + border-color: ${style.reviewLike.buttonBorderColor}; + color: ${style.reviewLike.textColor}; + transition: + background-color 0.5s ease, + color 0.5s ease; + display: flex; + + &:hover { + background-color: ${style.reviewLike.textColor}; + color: white; + } + `, + ]} + onClick={createLike} + type="button" + > + {/*<ThumbUpIcon />*/} + <div className="ml-1">๋„์›€๋ผ์š”!</div> + <div className="ml-1">{count}</div> + </button> {userID === props.reviewerID ? ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional <div
Unknown
P3: interface ๊ฐ™์€ ๊ฒฝ์šฐ ๋‹ค๋ฅธ ๊ณณ์—์„œ๋„ ์—ฌ๋Ÿฌ ๊ณณ์—์„œ ์“ฐ์ผ ์ˆ˜ ์žˆ๋Š”๋ฐ, type ๋””๋ ‰ํ† ๋ฆฌ ๋“ฑ์— ๊ณตํ†ต์ ์ธ model์„ ์ •์˜ํ•ด๋†“๊ณ  extends ๋“ฑ์œผ๋กœ ๊ฐ€์ ธ์™€์„œ ์“ฐ๋Š” ๋ฐฉ์‹๋„ ๊ณ ๋ คํ•ด ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ReviewItem์€ ์ƒ๋‹นํžˆ ๋งŽ์€ ๊ณณ์—์„œ ์“ฐ์ด๋Š” ์š”์†Œ๋กœ ์ƒ๊ฐ๋˜์„œ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„ ๋‚จ๊น๋‹ˆ๋‹ค!
@@ -1,3 +1,5 @@ +import {ReviewLikeButtonProps} from "@review-canvas/theme"; + export type Shadow = 'NONE' | 'SMALL' | 'MEDIUM' | 'LARGE'; export type FocusAreaLayout = 'BEST_REVIEW_TOP' | 'BEST_REVIEW_BOTTOM' | 'BEST_REVIEW_LEFT' | 'BEST_REVIEW_RIGHT'; export type ReviewAreaLayout = 'REVIEW_TOP' | 'REVIEW_BOTTOM' | 'REVIEW_LEFT' | 'REVIEW_RIGHT'; @@ -6,6 +8,7 @@ export type AlignmentPosition = 'LEFT' | 'CENTER' | 'RIGHT'; export type DetailViewType = 'SPREAD' | 'MODAL'; export type PagingType = 'PAGE_NUMBER' | 'SEE_MORE_SCROLL'; export type FilterType = 'LIST' | 'DROPDOWN'; +export type ReviewLikeButtonType = 'NONE' | 'THUMB_UP_WITH_TEXT' | 'THUMB_UP'; export interface Margin { left: string; @@ -43,11 +46,11 @@ export interface Round { } export interface ReviewLike { - buttonType: string; - iconColor: string; - textColor: string; buttonBorderColor: string; buttonRound: Round; + buttonType: ReviewLikeButtonType; + iconColor: string; + textColor: string; } export interface ReviewLayout {
TypeScript
Plugin ์„ค์น˜๋ฅผ ํ•˜๋ฉด ์™„๋ฃŒ์ธ ์ค„ ์•Œ์•˜๋Š”๋ฐ ์„ค์ •์—์„œ Manually๋กœ ๋ฐ”๊พธ์–ด์ค˜์•ผ ํ–ˆ๊ตฐ์š”... ํ˜„์žฌ Prettier๋ฅผ ํ™œ์„ฑํ™” ์ƒํƒœ๋กœ ๋ณ€๊ฒฝํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ „์ฒด ํŒŒ์ผ์— ์ ์šฉํ•˜์—ฌ ๋‹ค์‹œ ์ปค๋ฐ‹ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -9,50 +9,55 @@ import { generateShadowCSS, } from '@review-canvas/theme'; +// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg'; import { Star } from '@/components/review/star.tsx'; import { useReviewItemStyle } from '@/contexts/style/review-item.ts'; import useMessageToShop from '@/hooks/use-message-to-shop.ts'; -import type { ReplyItem } from '@/services/api-types/review'; +import type { ReviewItemProps } from '@/services/api-types/review'; +import { useReviewService } from '@/services/review.tsx'; import { useConnectedShop } from '@/state/shop.ts'; import { MESSAGE_TYPES } from '@/utils/message'; import Reply from './reply'; - -interface ReviewItemProps { - id: number; - rate: number; - content: string; - reviewerID: string; - reviewer: string; - replies: ReplyItem[]; -} +import { useEffect, useState } from 'react'; export default function ReviewItem(props: ReviewItemProps) { const style = useReviewItemStyle(); const { userID } = useConnectedShop(); + const reviewService = useReviewService(); const message = useMessageToShop(); + const [count, setCount] = useState(0); + + useEffect(() => { + async function fetchData() { + return reviewService.userReviewLike(props.id); + } + void fetchData().then((response) => { + setCount(response.data.count); + }); + }, [props.id, reviewService]); const edit = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'edit_review', url: `/reviews/${props.id}/edit`, }); }; - const deleteReview = () => { message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, { type: 'delete', url: `/reviews/${props.id}/delete`, }); }; - const showReviewDetail = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'detail', url: `/reviews/${props.id}`, }); }; + const createLike = () => {}; + return ( <li css={[ @@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) { generateFontCSS(style.font), generateShadowCSS(style.shadow, style.shadowColor), css` + border-color: ${style.borderColor}; background-color: ${style.backgroundColor}; display: flex; flex-direction: column; @@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) { ์ž‘์„ฑ์ž <span>{props.reviewer}</span> </div> <p className="text-left">{props.content}</p> + {/*{style.reviewLike.buttonType !== 'NONE' ? (*/} + {/* <button*/} + {/* onClick={(evt) => {*/} + {/* evt.stopPropagation();*/} + {/* if (userID === props.reviewerID) {*/} + {/* return;*/} + {/* }*/} + {/* }}*/} + {/* css={[*/} + {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/} + {/* css`*/} + {/* border-width: 1px;*/} + {/* padding: 2px 6px;*/} + {/* margin-top: 15px;*/} + {/* margin-bottom: 10px;*/} + {/* border-color: ${style.reviewLike.buttonBorderColor};*/} + {/* color: ${style.reviewLike.textColor};*/} + {/* transition:*/} + {/* background-color 0.5s ease,*/} + {/* color 0.5s ease;*/} + {/* display: flex;*/} + + {/* &:hover {*/} + {/* background-color: ${style.reviewLike.textColor};*/} + {/* color: white;*/} + {/* }*/} + {/* `,*/} + {/* ]}*/} + {/* >*/} + {/* <ThumbUpIcon />*/} + {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋„์›€๋ผ์š”!</div> : null}*/} + {/* <div className="ml-1">0</div>*/} + {/* </button>*/} + {/*) : null}*/} + <button + css={[ + generateBorderRadiusCSS(style.reviewLike.buttonRound), + css` + border-width: 1px; + padding: 2px 6px; + margin-top: 15px; + margin-bottom: 10px; + border-color: ${style.reviewLike.buttonBorderColor}; + color: ${style.reviewLike.textColor}; + transition: + background-color 0.5s ease, + color 0.5s ease; + display: flex; + + &:hover { + background-color: ${style.reviewLike.textColor}; + color: white; + } + `, + ]} + onClick={createLike} + type="button" + > + {/*<ThumbUpIcon />*/} + <div className="ml-1">๋„์›€๋ผ์š”!</div> + <div className="ml-1">{count}</div> + </button> {userID === props.reviewerID ? ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional <div
Unknown
ํ™•์ธํ•˜์˜€์Šต๋‹ˆ๋‹ค, Alert๋กœ ๋ณ€๊ฒฝํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค, ๋„์›€๋ผ์š”!์˜ ๊ฒฝ์šฐ์—๋Š” ๋ฒ„ํŠผ์ด ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์ž„์‹œ๋กœ ๋„ฃ์–ด๋‘๊ณ  ๋‚˜์ค‘์— ๋„์›€๋ผ์š” API๊ฐ€ ๋ฐฑ์—”๋“œ์—์„œ ๊ตฌํ˜„๋˜๋ฉด ๋กœ์ง์œผ๋กœ ๋Œ€์ฒดํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -9,50 +9,55 @@ import { generateShadowCSS, } from '@review-canvas/theme'; +// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg'; import { Star } from '@/components/review/star.tsx'; import { useReviewItemStyle } from '@/contexts/style/review-item.ts'; import useMessageToShop from '@/hooks/use-message-to-shop.ts'; -import type { ReplyItem } from '@/services/api-types/review'; +import type { ReviewItemProps } from '@/services/api-types/review'; +import { useReviewService } from '@/services/review.tsx'; import { useConnectedShop } from '@/state/shop.ts'; import { MESSAGE_TYPES } from '@/utils/message'; import Reply from './reply'; - -interface ReviewItemProps { - id: number; - rate: number; - content: string; - reviewerID: string; - reviewer: string; - replies: ReplyItem[]; -} +import { useEffect, useState } from 'react'; export default function ReviewItem(props: ReviewItemProps) { const style = useReviewItemStyle(); const { userID } = useConnectedShop(); + const reviewService = useReviewService(); const message = useMessageToShop(); + const [count, setCount] = useState(0); + + useEffect(() => { + async function fetchData() { + return reviewService.userReviewLike(props.id); + } + void fetchData().then((response) => { + setCount(response.data.count); + }); + }, [props.id, reviewService]); const edit = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'edit_review', url: `/reviews/${props.id}/edit`, }); }; - const deleteReview = () => { message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, { type: 'delete', url: `/reviews/${props.id}/delete`, }); }; - const showReviewDetail = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'detail', url: `/reviews/${props.id}`, }); }; + const createLike = () => {}; + return ( <li css={[ @@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) { generateFontCSS(style.font), generateShadowCSS(style.shadow, style.shadowColor), css` + border-color: ${style.borderColor}; background-color: ${style.backgroundColor}; display: flex; flex-direction: column; @@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) { ์ž‘์„ฑ์ž <span>{props.reviewer}</span> </div> <p className="text-left">{props.content}</p> + {/*{style.reviewLike.buttonType !== 'NONE' ? (*/} + {/* <button*/} + {/* onClick={(evt) => {*/} + {/* evt.stopPropagation();*/} + {/* if (userID === props.reviewerID) {*/} + {/* return;*/} + {/* }*/} + {/* }}*/} + {/* css={[*/} + {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/} + {/* css`*/} + {/* border-width: 1px;*/} + {/* padding: 2px 6px;*/} + {/* margin-top: 15px;*/} + {/* margin-bottom: 10px;*/} + {/* border-color: ${style.reviewLike.buttonBorderColor};*/} + {/* color: ${style.reviewLike.textColor};*/} + {/* transition:*/} + {/* background-color 0.5s ease,*/} + {/* color 0.5s ease;*/} + {/* display: flex;*/} + + {/* &:hover {*/} + {/* background-color: ${style.reviewLike.textColor};*/} + {/* color: white;*/} + {/* }*/} + {/* `,*/} + {/* ]}*/} + {/* >*/} + {/* <ThumbUpIcon />*/} + {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋„์›€๋ผ์š”!</div> : null}*/} + {/* <div className="ml-1">0</div>*/} + {/* </button>*/} + {/*) : null}*/} + <button + css={[ + generateBorderRadiusCSS(style.reviewLike.buttonRound), + css` + border-width: 1px; + padding: 2px 6px; + margin-top: 15px; + margin-bottom: 10px; + border-color: ${style.reviewLike.buttonBorderColor}; + color: ${style.reviewLike.textColor}; + transition: + background-color 0.5s ease, + color 0.5s ease; + display: flex; + + &:hover { + background-color: ${style.reviewLike.textColor}; + color: white; + } + `, + ]} + onClick={createLike} + type="button" + > + {/*<ThumbUpIcon />*/} + <div className="ml-1">๋„์›€๋ผ์š”!</div> + <div className="ml-1">{count}</div> + </button> {userID === props.reviewerID ? ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional <div
Unknown
ํ™•์ธํ•˜์˜€์Šต๋‹ˆ๋‹ค, Import๋กœ ๋Œ€์ฒดํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -9,50 +9,55 @@ import { generateShadowCSS, } from '@review-canvas/theme'; +// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg'; import { Star } from '@/components/review/star.tsx'; import { useReviewItemStyle } from '@/contexts/style/review-item.ts'; import useMessageToShop from '@/hooks/use-message-to-shop.ts'; -import type { ReplyItem } from '@/services/api-types/review'; +import type { ReviewItemProps } from '@/services/api-types/review'; +import { useReviewService } from '@/services/review.tsx'; import { useConnectedShop } from '@/state/shop.ts'; import { MESSAGE_TYPES } from '@/utils/message'; import Reply from './reply'; - -interface ReviewItemProps { - id: number; - rate: number; - content: string; - reviewerID: string; - reviewer: string; - replies: ReplyItem[]; -} +import { useEffect, useState } from 'react'; export default function ReviewItem(props: ReviewItemProps) { const style = useReviewItemStyle(); const { userID } = useConnectedShop(); + const reviewService = useReviewService(); const message = useMessageToShop(); + const [count, setCount] = useState(0); + + useEffect(() => { + async function fetchData() { + return reviewService.userReviewLike(props.id); + } + void fetchData().then((response) => { + setCount(response.data.count); + }); + }, [props.id, reviewService]); const edit = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'edit_review', url: `/reviews/${props.id}/edit`, }); }; - const deleteReview = () => { message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, { type: 'delete', url: `/reviews/${props.id}/delete`, }); }; - const showReviewDetail = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'detail', url: `/reviews/${props.id}`, }); }; + const createLike = () => {}; + return ( <li css={[ @@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) { generateFontCSS(style.font), generateShadowCSS(style.shadow, style.shadowColor), css` + border-color: ${style.borderColor}; background-color: ${style.backgroundColor}; display: flex; flex-direction: column; @@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) { ์ž‘์„ฑ์ž <span>{props.reviewer}</span> </div> <p className="text-left">{props.content}</p> + {/*{style.reviewLike.buttonType !== 'NONE' ? (*/} + {/* <button*/} + {/* onClick={(evt) => {*/} + {/* evt.stopPropagation();*/} + {/* if (userID === props.reviewerID) {*/} + {/* return;*/} + {/* }*/} + {/* }}*/} + {/* css={[*/} + {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/} + {/* css`*/} + {/* border-width: 1px;*/} + {/* padding: 2px 6px;*/} + {/* margin-top: 15px;*/} + {/* margin-bottom: 10px;*/} + {/* border-color: ${style.reviewLike.buttonBorderColor};*/} + {/* color: ${style.reviewLike.textColor};*/} + {/* transition:*/} + {/* background-color 0.5s ease,*/} + {/* color 0.5s ease;*/} + {/* display: flex;*/} + + {/* &:hover {*/} + {/* background-color: ${style.reviewLike.textColor};*/} + {/* color: white;*/} + {/* }*/} + {/* `,*/} + {/* ]}*/} + {/* >*/} + {/* <ThumbUpIcon />*/} + {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋„์›€๋ผ์š”!</div> : null}*/} + {/* <div className="ml-1">0</div>*/} + {/* </button>*/} + {/*) : null}*/} + <button + css={[ + generateBorderRadiusCSS(style.reviewLike.buttonRound), + css` + border-width: 1px; + padding: 2px 6px; + margin-top: 15px; + margin-bottom: 10px; + border-color: ${style.reviewLike.buttonBorderColor}; + color: ${style.reviewLike.textColor}; + transition: + background-color 0.5s ease, + color 0.5s ease; + display: flex; + + &:hover { + background-color: ${style.reviewLike.textColor}; + color: white; + } + `, + ]} + onClick={createLike} + type="button" + > + {/*<ThumbUpIcon />*/} + <div className="ml-1">๋„์›€๋ผ์š”!</div> + <div className="ml-1">{count}</div> + </button> {userID === props.reviewerID ? ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional <div
Unknown
ํ…Œ์ŠคํŠธ๋ฅผ ํ•  ๋•Œ ReviewLikeButton์ด 'None'์œผ๋กœ ๊ณ ์ •์ด๋ผ ํ•˜๋“œ์ฝ”๋”ฉ์œผ๋กœ ReviewLikeButton์„ ๋ฐ”๊พธ๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ๊ณผ์ •์—์„œ ์กฐ๊ฑด๋ฌธ ๊ฒฝ๊ณ ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ์„ค์ •ํ•ด๋‘์—ˆ๋Š”๋ฐ ํ•˜๋“œ์ฝ”๋”ฉ๋งŒ ์ง€์šฐ๊ณ  ์ด๊ทธ๋…ธ์–ด๋ฅผ ๋ชป ์ง€์› ๋„ค์š”... ์ง€์›Œ์„œ ๋ฐ˜์˜ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -9,50 +9,55 @@ import { generateShadowCSS, } from '@review-canvas/theme'; +// import ThumbUpIcon from '@/assets/icon/icon-thumb-up.svg'; import { Star } from '@/components/review/star.tsx'; import { useReviewItemStyle } from '@/contexts/style/review-item.ts'; import useMessageToShop from '@/hooks/use-message-to-shop.ts'; -import type { ReplyItem } from '@/services/api-types/review'; +import type { ReviewItemProps } from '@/services/api-types/review'; +import { useReviewService } from '@/services/review.tsx'; import { useConnectedShop } from '@/state/shop.ts'; import { MESSAGE_TYPES } from '@/utils/message'; import Reply from './reply'; - -interface ReviewItemProps { - id: number; - rate: number; - content: string; - reviewerID: string; - reviewer: string; - replies: ReplyItem[]; -} +import { useEffect, useState } from 'react'; export default function ReviewItem(props: ReviewItemProps) { const style = useReviewItemStyle(); const { userID } = useConnectedShop(); + const reviewService = useReviewService(); const message = useMessageToShop(); + const [count, setCount] = useState(0); + + useEffect(() => { + async function fetchData() { + return reviewService.userReviewLike(props.id); + } + void fetchData().then((response) => { + setCount(response.data.count); + }); + }, [props.id, reviewService]); const edit = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'edit_review', url: `/reviews/${props.id}/edit`, }); }; - const deleteReview = () => { message(MESSAGE_TYPES.OPEN_SELECTING_MODAL, { type: 'delete', url: `/reviews/${props.id}/delete`, }); }; - const showReviewDetail = () => { message(MESSAGE_TYPES.OPEN_MODAL, { type: 'detail', url: `/reviews/${props.id}`, }); }; + const createLike = () => {}; + return ( <li css={[ @@ -63,6 +68,7 @@ export default function ReviewItem(props: ReviewItemProps) { generateFontCSS(style.font), generateShadowCSS(style.shadow, style.shadowColor), css` + border-color: ${style.borderColor}; background-color: ${style.backgroundColor}; display: flex; flex-direction: column; @@ -88,6 +94,68 @@ export default function ReviewItem(props: ReviewItemProps) { ์ž‘์„ฑ์ž <span>{props.reviewer}</span> </div> <p className="text-left">{props.content}</p> + {/*{style.reviewLike.buttonType !== 'NONE' ? (*/} + {/* <button*/} + {/* onClick={(evt) => {*/} + {/* evt.stopPropagation();*/} + {/* if (userID === props.reviewerID) {*/} + {/* return;*/} + {/* }*/} + {/* }}*/} + {/* css={[*/} + {/* generateBorderRadiusCSS(style.reviewLike.buttonRound),*/} + {/* css`*/} + {/* border-width: 1px;*/} + {/* padding: 2px 6px;*/} + {/* margin-top: 15px;*/} + {/* margin-bottom: 10px;*/} + {/* border-color: ${style.reviewLike.buttonBorderColor};*/} + {/* color: ${style.reviewLike.textColor};*/} + {/* transition:*/} + {/* background-color 0.5s ease,*/} + {/* color 0.5s ease;*/} + {/* display: flex;*/} + + {/* &:hover {*/} + {/* background-color: ${style.reviewLike.textColor};*/} + {/* color: white;*/} + {/* }*/} + {/* `,*/} + {/* ]}*/} + {/* >*/} + {/* <ThumbUpIcon />*/} + {/* {style.reviewLike.buttonType === 'THUMB_UP_WITH_TEXT' ? <div className="ml-1">๋„์›€๋ผ์š”!</div> : null}*/} + {/* <div className="ml-1">0</div>*/} + {/* </button>*/} + {/*) : null}*/} + <button + css={[ + generateBorderRadiusCSS(style.reviewLike.buttonRound), + css` + border-width: 1px; + padding: 2px 6px; + margin-top: 15px; + margin-bottom: 10px; + border-color: ${style.reviewLike.buttonBorderColor}; + color: ${style.reviewLike.textColor}; + transition: + background-color 0.5s ease, + color 0.5s ease; + display: flex; + + &:hover { + background-color: ${style.reviewLike.textColor}; + color: white; + } + `, + ]} + onClick={createLike} + type="button" + > + {/*<ThumbUpIcon />*/} + <div className="ml-1">๋„์›€๋ผ์š”!</div> + <div className="ml-1">{count}</div> + </button> {userID === props.reviewerID ? ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- This is intentional <div
Unknown
service/api-types/review.tsx์— ๊ณตํ†ต ๋ชจ๋ธ๋กœ ์„ ์–ธํ•˜์—ฌ export ๋ฐ import ํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -6,11 +6,24 @@ * smtp session ๊ด€๋ฆฌ ์‹œ ์ถฉ๋Œ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ์ ์ ˆํ•œ ๋งค์ปค๋‹ˆ์ฆ˜์„ ์ ์šฉํ•˜์—ฌ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ +//extern smtp_session_pool *sessions[MAX_POOL_NUM]; + void delSmtpSession(char *session_id) { /* TODO ๊ณผ์ œ 1-1 * smtp ์„ธ์…˜์„ ์ข…๋ฃŒ * ๊ทธ๋™์•ˆ ์‚ฌ์šฉ๋˜์—ˆ๋˜ session์„ session_id๋ฅผ ์ด์šฉํ•˜์—ฌ session ๋ณด๊ด€์†Œ์—์„œ ์ œ๊ฑฐํ•˜๋Š” ๋กœ์ง์„ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ + smtp_session_t *session = NULL; + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + if (sessions[pool_num].occupied == 1) { + if (!strcmp(session_id, sessions[pool_num].sess_id)) { + sessions[pool_num].occupied = 0; + sessions[pool_num].used = 0; + return; + } + } + } return; } @@ -19,6 +32,16 @@ smtp_session_t *addSmtpSession(smtp_session_t *session) { * smtp ์„ธ์…˜์„ ์ถ”๊ฐ€ * ์ „๋‹ฌ๋ฐ›์€ smtp session์ •๋ณด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํ˜„์žฌ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋Š” smtp session ๋ณด๊ด€์†Œ์— ์ถ”๊ฐ€ํ•˜๋Š” ๋กœ์ง์„ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + if (sessions[pool_num].occupied == 0) { + sessions[pool_num].occupied = 1; + strcpy(sessions[pool_num].sess_id, session->session_id); + sessions[pool_num].session = (smtp_session_t *)session; + return session; + } + } + return NULL; } @@ -29,3 +52,41 @@ smtp_session_t *getSmtpSession(char *session_id) { */ return NULL; } + +void initSessionPool() +{ + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + sessions[pool_num].occupied = 0; + sessions[pool_num].used = 0; + } +} + +int getSmtpSessionIdxForPool() { + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + if (sessions[pool_num].occupied == 1) { + if (sessions[pool_num].used == 0) { + sessions[pool_num].used = 1; + return pool_num; + } + } + } + return -1; +} + +void unusedSmtpSession(int pool_num) { + if (sessions[pool_num].used == 1) { + sessions[pool_num].used = 0; + } + return; +} +/* +void unusedSmtpSession(char) { + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + if (!strcmp(session_id, sessions[pool_num].sess_id)) { + sessions[pool_num].used = 0; + } + } +} */
C
๊ธฐ๋Šฅ์ƒ ๋ฌธ์ œ๋Š” ์—†์–ด๋ณด์ž…๋‹ˆ๋‹ค. ๋‹ค๋งŒ ๋ฐฐ์—ด index 0๋ถ€ํ„ฐ ์ˆœํ™˜ํ•˜์—ฌ ๋Œ€์ƒ Session์„ ์ฐพ๋Š” ๊ฑด ํšจ์œจ์ ์ด์ง€ ์•Š๋Š” ๋กœ์ง ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ตœ์ดˆ ํ• ๋‹น ๋•Œ์™€ ๋‹ฌ๋ฆฌ, Session์— Index๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹ ๋“ฑ index๋ฅผ ์ €์žฅ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„์ด ์žˆ์„ ๊ฑด๋ฐ ๊ทธ๋Ÿฌ์ง€ ์•Š๊ณ  for loop + strcmp์œผ๋กœ ๊ฐ™์€ SessionID๊ฐ€ ๋‚˜์˜ฌ๋•Œ๊นŒ์ง€ ์ฐพ๋Š” ๋กœ์ง์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์‹œ๊ฐ„ ์—ฌ๊ฑด์ด ์•ˆ๋˜์–ด ๊ทธ๋žฌ์„์ˆ˜๋„ ์žˆ์„๊ฒƒ ๊ฐ™์€๋ฐ, ๊ฐœ๋ฐœ์ž๊ฐ€ ์ด๋Ÿฐ ๋ถ€๋ถ„์€ ๊ฐœ์„  ๋˜์–ด์•ผ ํ•จ์„ ์ธ์ง€ ํ•˜๊ณ  ์žˆ์—ˆ์œผ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.
@@ -18,8 +18,25 @@ typedef struct smtp_session { char smtp_mail_from[ MAX_MAIL_FROM ]; } smtp_session_t; +/* added by se00248 */ +#define MAX_POOL_NUM 10000 + +typedef struct smtp_session_pool { + int occupied; + int used; + char sess_id[ L_SESSION_ID ]; + smtp_session_t *session; +} smtp_session_pool; + +extern void initSessionPool(); +extern int getSmtpSessionIdxForPool(); +extern void unusedSmtpSession(int pool_num); +//extern smtp_session_t *getSmtpSessionForPool(); +//extern void unusedSmtpSession(char *session_id); +extern smtp_session_pool sessions[MAX_POOL_NUM]; +/* end added by se00248 */ + extern void delSmtpSession(char * session_id); extern smtp_session_t * addSmtpSession(smtp_session_t * session); - #endif //CAREER_TEST3_SMTPSESSION_H
Unknown
์‹œํ—˜์ฝ”๋“œ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด point arrayํ˜•ํƒœ๋กœ ๊ฐ€์ด๋“œ ์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค. extern smtp_session_pool *sessions[MAX_POOL_NUM]; ํ•˜์ง€๋งŒ ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  smtp_session_pool ์„ ๋งŒ๋“ค์–ด smtp_session_t *session;์„ ๊ฐ์‹ธ๋‘์—ˆ๊ณ , occupied / used ์œผ๋กœ ๊ตฌ๋ถ„ ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•œ ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
@@ -7,13 +7,25 @@ * smtpHandleInboundConnection๋กœ์ง์„ ํ†ตํ•ด Connection์„ ๋งบ๋Š”๊ฑธ ๊ถŒ์œ  ๋“œ๋ฆฝ๋‹ˆ๋‹ค.(ํ•ด๋‹น ๋กœ์ง์„ ์‚ฌ์šฉ์•ˆํ•˜์…”๋„ ๋ฌด๋ฐฉํ•ฉ๋‹ˆ๋‹ค.) * */ + +int count = 0; + void smtpWaitAsync(int server_fd) { /* TODO ๊ณผ์ œ 2-1 * smtpSvrRecvAsync.c ํŒŒ์ผ์€ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ์–ด ํ•˜๋Š” ๋กœ์ง์ด ์ž‘์„ฑ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. * N๊ฐœ์˜ H_SERVER_WORK_TH ์Šค๋ ˆ๋“œ์™€ ํ•˜๋‚˜์˜ smtpWaitAsync ์Šค๋ ˆ๋“œ๊ฐ€ ๋™์‹œ์— ๋™์ž‘ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. * smtpWaitAsync Function์—์„œ Connection์„ ๋งบ๊ณ (smtpHandleInboundConnection๋กœ์ง ์‚ฌ์šฉ ๊ถŒ์œ ) * ๋น„๋™๊ธฐ ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ๊ฐœ๋ฐœํ•œํ›„ session์ •๋ณด๋ฅผ WorkThread๋กœ ์ „๋‹ฌํ•˜๋Š” ๋กœ์ง์„ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ + while (1) { + smtp_session_t *session = NULL; + if ((session = smtpHandleInboundConnection(server_fd)) == NULL) { + msleep(25); + continue; + } + //msleep(25); + } + return; } void *H_SERVER_WORK_TH(void *args) { @@ -26,12 +38,21 @@ void *H_SERVER_WORK_TH(void *args) { /* TODO ๊ณผ์ œ 2-2 * session์ •๋ณด๋ฅผ ํ•ด๋‹น ์œ„์น˜์— ๋ฐ›์•„ ์˜ฌ์ˆ˜์žˆ๊ฒŒ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ + int idx = -1; + if ((idx = getSmtpSessionIdxForPool()) == -1) { + msleep(25); + continue; + } + + session = sessions[idx].session; if (session == NULL) { msleep(25); continue; } + if (++count % 100 == 0) msleep(25); + if ((nLine = smtpReadLine(session->sock_fd, buf, sizeof(buf))) <= 0) { LOG (LOG_INF, "%s : %sSMTP Connection closed%s : fd = %d, session_id=%s\n", __func__, C_YLLW, C_NRML, session->sock_fd, @@ -46,6 +67,8 @@ void *H_SERVER_WORK_TH(void *args) { } continue; } + + unusedSmtpSession(idx); } return NULL; @@ -68,4 +91,4 @@ int smtpStartWorkThreads(int n_work_threads) { } return 0; -} \ No newline at end of file +}
C
100๋‹จ์œ„๋กœ sleep์„ ์ฃผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋งˆ๋„ ์„ฑ๋Šฅ ํ…Œ์ŠคํŠธ๊ฐ„์— ์ด์Šˆ๊ฐ€ ๋‚˜์™€์„œ sleep์„ ์ฃผ์—ˆ๋˜๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ์€ ๋˜๋Š”๋ฐ, ์ •ํ™•ํ•œ ์˜๋„๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ works Thread์—์„œ ์ ์ ˆํ•œ lock ์—†์ด ์ „์—ญ๋ณ€์ˆ˜ ํ•˜๋‚˜๋ฅผ ํ†ตํ•ด ์ œ์–ด๋ฅผ ํ•˜๋Š”์ ์ด ์ด์ƒํ•ด ๋ณด์ด๋„ค์š”
@@ -6,11 +6,24 @@ * smtp session ๊ด€๋ฆฌ ์‹œ ์ถฉ๋Œ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ์ ์ ˆํ•œ ๋งค์ปค๋‹ˆ์ฆ˜์„ ์ ์šฉํ•˜์—ฌ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ +//extern smtp_session_pool *sessions[MAX_POOL_NUM]; + void delSmtpSession(char *session_id) { /* TODO ๊ณผ์ œ 1-1 * smtp ์„ธ์…˜์„ ์ข…๋ฃŒ * ๊ทธ๋™์•ˆ ์‚ฌ์šฉ๋˜์—ˆ๋˜ session์„ session_id๋ฅผ ์ด์šฉํ•˜์—ฌ session ๋ณด๊ด€์†Œ์—์„œ ์ œ๊ฑฐํ•˜๋Š” ๋กœ์ง์„ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ + smtp_session_t *session = NULL; + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + if (sessions[pool_num].occupied == 1) { + if (!strcmp(session_id, sessions[pool_num].sess_id)) { + sessions[pool_num].occupied = 0; + sessions[pool_num].used = 0; + return; + } + } + } return; } @@ -19,6 +32,16 @@ smtp_session_t *addSmtpSession(smtp_session_t *session) { * smtp ์„ธ์…˜์„ ์ถ”๊ฐ€ * ์ „๋‹ฌ๋ฐ›์€ smtp session์ •๋ณด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํ˜„์žฌ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋Š” smtp session ๋ณด๊ด€์†Œ์— ์ถ”๊ฐ€ํ•˜๋Š” ๋กœ์ง์„ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + if (sessions[pool_num].occupied == 0) { + sessions[pool_num].occupied = 1; + strcpy(sessions[pool_num].sess_id, session->session_id); + sessions[pool_num].session = (smtp_session_t *)session; + return session; + } + } + return NULL; } @@ -29,3 +52,41 @@ smtp_session_t *getSmtpSession(char *session_id) { */ return NULL; } + +void initSessionPool() +{ + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + sessions[pool_num].occupied = 0; + sessions[pool_num].used = 0; + } +} + +int getSmtpSessionIdxForPool() { + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + if (sessions[pool_num].occupied == 1) { + if (sessions[pool_num].used == 0) { + sessions[pool_num].used = 1; + return pool_num; + } + } + } + return -1; +} + +void unusedSmtpSession(int pool_num) { + if (sessions[pool_num].used == 1) { + sessions[pool_num].used = 0; + } + return; +} +/* +void unusedSmtpSession(char) { + int pool_num = 0; + for (pool_num = 0; pool_num < MAX_POOL_NUM; pool_num++) { + if (!strcmp(session_id, sessions[pool_num].sess_id)) { + sessions[pool_num].used = 0; + } + } +} */
C
smtpSession.c์— ์žˆ๋Š” ํ•จ์ˆ˜๋“ค ๊ณตํ†ต์œผ๋กœ, ์ „์—ญ ๋ณ€์ˆ˜ ์ ‘๊ทผ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋•Œ ์ ์ ˆํ•œ lock์„ ์‚ฌ์šฉํ•˜์—ฌ์•ผ ํ•˜์˜€๋Š”๋ฐ ๊ทธ๋Ÿฐ ๋ถ€๋ถ„์ด ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
@@ -7,13 +7,25 @@ * smtpHandleInboundConnection๋กœ์ง์„ ํ†ตํ•ด Connection์„ ๋งบ๋Š”๊ฑธ ๊ถŒ์œ  ๋“œ๋ฆฝ๋‹ˆ๋‹ค.(ํ•ด๋‹น ๋กœ์ง์„ ์‚ฌ์šฉ์•ˆํ•˜์…”๋„ ๋ฌด๋ฐฉํ•ฉ๋‹ˆ๋‹ค.) * */ + +int count = 0; + void smtpWaitAsync(int server_fd) { /* TODO ๊ณผ์ œ 2-1 * smtpSvrRecvAsync.c ํŒŒ์ผ์€ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ์–ด ํ•˜๋Š” ๋กœ์ง์ด ์ž‘์„ฑ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. * N๊ฐœ์˜ H_SERVER_WORK_TH ์Šค๋ ˆ๋“œ์™€ ํ•˜๋‚˜์˜ smtpWaitAsync ์Šค๋ ˆ๋“œ๊ฐ€ ๋™์‹œ์— ๋™์ž‘ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. * smtpWaitAsync Function์—์„œ Connection์„ ๋งบ๊ณ (smtpHandleInboundConnection๋กœ์ง ์‚ฌ์šฉ ๊ถŒ์œ ) * ๋น„๋™๊ธฐ ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ๊ฐœ๋ฐœํ•œํ›„ session์ •๋ณด๋ฅผ WorkThread๋กœ ์ „๋‹ฌํ•˜๋Š” ๋กœ์ง์„ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ + while (1) { + smtp_session_t *session = NULL; + if ((session = smtpHandleInboundConnection(server_fd)) == NULL) { + msleep(25); + continue; + } + //msleep(25); + } + return; } void *H_SERVER_WORK_TH(void *args) { @@ -26,12 +38,21 @@ void *H_SERVER_WORK_TH(void *args) { /* TODO ๊ณผ์ œ 2-2 * session์ •๋ณด๋ฅผ ํ•ด๋‹น ์œ„์น˜์— ๋ฐ›์•„ ์˜ฌ์ˆ˜์žˆ๊ฒŒ ๊ฐœ๋ฐœํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. */ + int idx = -1; + if ((idx = getSmtpSessionIdxForPool()) == -1) { + msleep(25); + continue; + } + + session = sessions[idx].session; if (session == NULL) { msleep(25); continue; } + if (++count % 100 == 0) msleep(25); + if ((nLine = smtpReadLine(session->sock_fd, buf, sizeof(buf))) <= 0) { LOG (LOG_INF, "%s : %sSMTP Connection closed%s : fd = %d, session_id=%s\n", __func__, C_YLLW, C_NRML, session->sock_fd, @@ -46,6 +67,8 @@ void *H_SERVER_WORK_TH(void *args) { } continue; } + + unusedSmtpSession(idx); } return NULL; @@ -68,4 +91,4 @@ int smtpStartWorkThreads(int n_work_threads) { } return 0; -} \ No newline at end of file +}
C
์ € ์ž๋ฆฌ์— sleep์ด ๋“ค์–ด๊ฐ„ ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค! ๋™๊ธฐํ™” ์ฒ˜๋ฆฌ๊ฐ€ ์ž˜ ๋˜์—ˆ๋‹ค๋ฉด ํ•„์š” ์—†์„ ์ฝ”๋“œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,61 @@ +package bridge.controller; + +import bridge.domain.BridgeGame; +import bridge.domain.BridgeMaker; +import bridge.domain.Direction; +import bridge.domain.GameCommand; +import bridge.dto.GameResultDto; +import bridge.dto.RoundResultDto; +import bridge.dto.RoundResultsDto; +import bridge.view.InputView; +import bridge.view.OutputView; +import bridge.util.Repeater; + +import java.util.ArrayList; +import java.util.List; + +public class BridgeGameController { + private final BridgeMaker bridgeMaker; + private final InputView inputView; + private final OutputView outputView; + + public BridgeGameController(BridgeMaker bridgeMaker, InputView inputView, OutputView outputView) { + this.bridgeMaker = bridgeMaker; + this.inputView = inputView; + this.outputView = outputView; + } + + public void run() { + outputView.printGreeting(); + BridgeGame bridgeGame = Repeater.repeatUntilNoException(this::createBridge); + + List<RoundResultDto> roundResults = new ArrayList<>(); + GameCommand gameCommand = GameCommand.RETRY; + + int tryCount = 1; + while (!bridgeGame.isGameEnd() && gameCommand.equals(GameCommand.RETRY)) { + + RoundResultDto roundResultDto = executeRound(bridgeGame); + roundResults.add(roundResultDto); + outputView.printMap(new RoundResultsDto(roundResults)); + if (!roundResultDto.isMoveSuccess()) { + gameCommand = Repeater.repeatUntilNoException(inputView::readGameCommand); + tryCount++; + roundResults.clear(); + bridgeGame.retry(); + } + } + outputView.printResult(new GameResultDto(new RoundResultsDto(roundResults), tryCount, bridgeGame.isGameEnd())); + } + + private BridgeGame createBridge() { + Integer length = Repeater.repeatUntilNoException(inputView::readBridgeSize); + return BridgeGame.from(bridgeMaker.makeBridge(length)); + } + + private RoundResultDto executeRound(BridgeGame bridgeGame) { + Direction direction = Repeater.repeatUntilNoException(inputView::readMoving); + return new RoundResultDto(direction, bridgeGame.move(direction)); + } + +}
Java
์ปจํŠธ๋กค๋Ÿฌ์—์„œ run()์„ ํ†ตํ•ด ๋‹ค๋ฆฌ ๊ฒŒ์ž„์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์žˆ๋„ค์š”! ๋‹ค๋งŒ ํ•ด๋‹น ๋ฉ”์„œ๋“œ๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์€ ์ผ์„ ํ•˜๊ณ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ๊ธฐ๋Šฅ์˜ ๋ถ„๋ฆฌ๊ฐ€ ์ด๋ฃจ์–ด์ง€๋ฉด ๋ฉ”์„œ๋“œ๊ฐ€ ํ•œ๊ฐ€์ง€์ผ๋งŒ ํ•  ์ˆ˜ ์žˆ์„๊ฒƒ ๊ฐ™์•„์š”๐Ÿ˜
@@ -0,0 +1,64 @@ +package bridge.domain; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ ๊ฒŒ์ž„์„ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค + */ +public class BridgeGame { + private static final int MIN_LENGTH = 3; + private static final int MAX_LENGTH = 20; + private static final String INVALID_LENGTH_BRIDGE_MESSAGE = "[ERROR] ๋‹ค๋ฆฌ ๊ธธ์ด๋Š” 3๋ถ€ํ„ฐ 20 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."; + + private final List<Direction> escapeRoute; + private int userPosition = 0; + + private BridgeGame(List<Direction> escapeRoute) { + validate(escapeRoute); + this.escapeRoute = escapeRoute; + } + + public static BridgeGame from(List<String> directions) { + List<Direction> escapeRoute = directions.stream() + .map(Direction::from) + .collect(Collectors.toList()); + return new BridgeGame(escapeRoute); + } + /** + * ์‚ฌ์šฉ์ž๊ฐ€ ์นธ์„ ์ด๋™ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ + * <p> + * ์ด๋™์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…(return type), ์ธ์ž(parameter)๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. + */ + public boolean move(Direction direction) { + if (escapeRoute.get(userPosition).equals(direction)) { + userPosition++; + return true; + } + return false; + } + + public boolean isGameEnd () { + return userPosition == escapeRoute.size(); + } + + /** + * ์‚ฌ์šฉ์ž๊ฐ€ ๊ฒŒ์ž„์„ ๋‹ค์‹œ ์‹œ๋„ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ + * <p> + * ์žฌ์‹œ์ž‘์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…(return type), ์ธ์ž(parameter)๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. + */ + public void retry() { + userPosition = 0; + } + + private void validate(List<Direction> escapeRoute) { + validateLength(escapeRoute); + } + + private void validateLength(List<Direction> escapeRoute) { + if (escapeRoute.size() < MIN_LENGTH || escapeRoute.size() > MAX_LENGTH) { + throw new IllegalArgumentException(INVALID_LENGTH_BRIDGE_MESSAGE); + } + } + +}
Java
์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ ํ™œ์šฉ ๐Ÿ‘ ํ˜น์‹œ ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ๋งŒ๋“œ๋Š” ๊ธฐ์ค€์ด ์žˆ์„๊นŒ์š”? ์ €๋ถ€ํ„ฐ ์ด์•ผ๊ธฐ๋ฅผ ๋“œ๋ฆฌ๋ฉด ์ƒ์„ฑ์ž์™€ ํ•„๋“œ ํƒ€์ž…์ด ์ผ์น˜ํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด ์ƒ์„ฑํ•˜๊ณ , ๋‹ค๋ฅธ ํƒ€์ž…์„ ํ†ตํ•ด ์ƒ์„ฑํ• ๋•Œ๋Š” ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,22 @@ +package bridge.domain; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class BridgeMaker { + + private final BridgeNumberGenerator bridgeNumberGenerator; + + public BridgeMaker(BridgeNumberGenerator bridgeNumberGenerator) { + this.bridgeNumberGenerator = bridgeNumberGenerator; + } + + public List<String> makeBridge(int size) { + return IntStream.range(0, size) + .map(i -> bridgeNumberGenerator.generate()) + .mapToObj(Direction::from) + .map(Direction::getInputCode) + .collect(Collectors.toList()); + } +}
Java
์ŠคํŠธ๋ฆผ ํ™œ์šฉ ๐Ÿ‘
@@ -1,4 +1,4 @@ -package bridge; +package bridge.domain; @FunctionalInterface public interface BridgeNumberGenerator {
Java
BridgeNumberGenerator๋Š” ๋‹ค๋ฆฌ๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ์ˆซ์ž๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํด๋ž˜์Šค๋กœ ๋ณด์ž…๋‹ˆ๋‹ค! ์ €๋Š” ํ•ด๋‹น ๋ถ€๋ถ„์ด ์„œ๋น„์Šค์— ๊ฐ€๊น๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ๋„๋ฉ”์ธ์œผ๋กœ ์ƒ๊ฐํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์œผ์‹ค๊นŒ์š”?๐Ÿ˜€
@@ -0,0 +1,17 @@ +package bridge.util; + +import java.util.function.Supplier; + +public class Repeater { + + public static <T> T repeatUntilNoException(Supplier<T> inputSupplier) { + while (true) { + try { + return inputSupplier.get(); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + +}
Java
์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ ๋ฐ˜๋ณตํ•ด์„œ ๋‹ค์‹œ ์ž…๋ ฅ ๋ฐ›๊ธฐ ์œ„ํ•ด์„œ ๋งŒ๋“œ์‹  ํด๋ž˜์Šค๋กœ ๋ณด์ž…๋‹ˆ๋‹ค!๐Ÿ˜Ž ์ €๋Š” ์ž…๋ ฅ๋ฐ›์„๋•Œ ํ•ด๋‹น ๋ถ€๋ถ„์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ๋กœ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์ง€ ์•Š๊ณ  InputView ๋‚ด๋ถ€์— ์ •์˜ํ–ˆ๋Š”๋ฐ ์ด๋ ‡๊ฒŒ ๋ถ„๋ฆฌํ•˜์˜€์„๋•Œ์˜ ์žฅ์ ์—” ๋ฌด์—‡์ด ์žˆ๋‚˜์š”?
@@ -0,0 +1,60 @@ +package bridge.view; + +import bridge.domain.Direction; +import bridge.dto.GameResultDto; +import bridge.dto.RoundResultDto; +import bridge.dto.RoundResultsDto; + +import java.util.List; + +public class OutputMessageResolver { + + private static final String ROUND_MESSAGE_PREFIX = "["; + private static final String ROUND_MESSAGE_POSTFIX = "]"; + private static final String SEPARATOR = "|"; + private static final String MOVE_SUCCESS_MARK = " O "; + private static final String MOVE_FAIL_MARK = " X "; + private static final String MOVE_NONE_MARK = " "; + private static final String GAME_RESULT_MESSAGE_PREFIX = "์ตœ์ข… ๊ฒŒ์ž„ ๊ฒฐ๊ณผ"; + + public String resolveRoundResultMessage(RoundResultsDto roundResultsDto) { + + List<RoundResultDto> roundResultDtos = roundResultsDto.getRoundResultDtos(); + String upDirectionFootPrint = ROUND_MESSAGE_PREFIX; + String downDirectionFootPrint = ROUND_MESSAGE_PREFIX; + for (RoundResultDto roundResultDto : roundResultDtos) { + if (roundResultDto.getMoveDirection() == Direction.UP) { + upDirectionFootPrint += mapToMoveMark(roundResultDto.isMoveSuccess()) + SEPARATOR; + downDirectionFootPrint += MOVE_NONE_MARK + SEPARATOR; + } + if (roundResultDto.getMoveDirection() == Direction.DOWN) { + upDirectionFootPrint += MOVE_NONE_MARK + SEPARATOR; + downDirectionFootPrint += mapToMoveMark(roundResultDto.isMoveSuccess()) + SEPARATOR; + } + } + + upDirectionFootPrint = upDirectionFootPrint.substring(0, upDirectionFootPrint.length() - 1); + downDirectionFootPrint = downDirectionFootPrint.substring(0, downDirectionFootPrint.length() - 1); + return upDirectionFootPrint + ROUND_MESSAGE_POSTFIX + "\n" + downDirectionFootPrint + ROUND_MESSAGE_POSTFIX; + } + + public String resolveGameResultMessage(GameResultDto gameResultDto) { + StringBuilder stbd = new StringBuilder(); + stbd.append(GAME_RESULT_MESSAGE_PREFIX + "\n"); + stbd.append(resolveRoundResultMessage(gameResultDto.getRoundResultsDto()) + "\n"); + if (gameResultDto.isGameSuccess()) { + stbd.append("๊ฒŒ์ž„ ์„ฑ๊ณต ์—ฌ๋ถ€: ์„ฑ๊ณต\n"); + } + if (!gameResultDto.isGameSuccess()) { + stbd.append("๊ฒŒ์ž„ ์„ฑ๊ณต ์—ฌ๋ถ€: ์‹คํŒจ\n"); + } + stbd.append(String.format("์ด ์‹œ๋„ํ•œ ํšŸ์ˆ˜: %d", gameResultDto.getRetryCount())); + return stbd.toString(); + } + private String mapToMoveMark(boolean moveSuccess) { + if (!moveSuccess) { + return MOVE_FAIL_MARK; + } + return MOVE_SUCCESS_MARK; + } +}
Java
๋‹ค๋ฆฌ ์ถœ๋ ฅ์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค! ํ•ด๋‹น ๋ฉ”์„œ๋“œ ํ˜ผ์ž 19์ค„์„ ์‚ฌ์šฉ์ค‘์ธ๊ฒƒ์„ ๋ณด๋ฉด ๋ถ„๋ฆฌ์˜ ์—ฌ์ง€๊ฐ€ ์žˆ์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~๐Ÿ˜
@@ -0,0 +1,37 @@ +package bridge.view; + +import bridge.dto.GameResultDto; +import bridge.dto.RoundResultsDto; + +/** + * ์‚ฌ์šฉ์ž์—๊ฒŒ ๊ฒŒ์ž„ ์ง„ํ–‰ ์ƒํ™ฉ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. + */ +public class OutputView { + private static final String GREETING_MESSAGE = "๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ ๊ฒŒ์ž„์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค."; + private final OutputMessageResolver outputMessageResolver; + + public OutputView(OutputMessageResolver outputMessageResolver) { + this.outputMessageResolver = outputMessageResolver; + } + + public void printGreeting() { + System.out.println(GREETING_MESSAGE); + } + /** + * ํ˜„์žฌ๊นŒ์ง€ ์ด๋™ํ•œ ๋‹ค๋ฆฌ์˜ ์ƒํƒœ๋ฅผ ์ •ํ•ด์ง„ ํ˜•์‹์— ๋งž์ถฐ ์ถœ๋ ฅํ•œ๋‹ค. + * <p> + * ์ถœ๋ ฅ์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ์˜ ์ธ์ž(parameter)๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. + */ + public void printMap(RoundResultsDto roundResultsDto) { + System.out.println(outputMessageResolver.resolveRoundResultMessage(roundResultsDto)); + } + + /** + * ๊ฒŒ์ž„์˜ ์ตœ์ข… ๊ฒฐ๊ณผ๋ฅผ ์ •ํ•ด์ง„ ํ˜•์‹์— ๋งž์ถฐ ์ถœ๋ ฅํ•œ๋‹ค. + * <p> + * ์ถœ๋ ฅ์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ์˜ ์ธ์ž(parameter)๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. + */ + public void printResult(GameResultDto gameResultDto) { + System.out.println(outputMessageResolver.resolveGameResultMessage(gameResultDto)); + } +}
Java
Dto ๋ฅผ ํ†ตํ•ด view์—์„œ๋Š” ๋„๋ฉ”์ธ์„ ์ง์ ‘์ ์œผ๋กœ ์˜์กดํ•˜์ง€ ์•Š๊ณ  ์žˆ๋„ค์š”! ๐Ÿ‘
@@ -0,0 +1,52 @@ +# ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ ๊ฒŒ์ž„ + +์œ„์•„๋ž˜ ๋‘˜ ์ค‘ ํ•˜๋‚˜์˜ ์นธ๋งŒ ๊ฑด๋„ ์ˆ˜ ์žˆ๋Š” ๋‹ค๋ฆฌ๋ฅผ ๋๊นŒ์ง€ ๊ฑด๋„ˆ๊ฐ€๋Š” ๊ฒŒ์ž„์ด๋‹ค. + +- ์œ„์•„๋ž˜ ๋‘ ์นธ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋‹ค๋ฆฌ๋ฅผ ๊ฑด๋„ˆ์•ผ ํ•œ๋‹ค. + - ๋‹ค๋ฆฌ๋Š” ์™ผ์ชฝ์—์„œ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ฑด๋„ˆ์•ผ ํ•œ๋‹ค. + - ์œ„์•„๋ž˜ ๋‘˜ ์ค‘ ํ•˜๋‚˜์˜ ์นธ๋งŒ ๊ฑด๋„ ์ˆ˜ ์žˆ๋‹ค. +- ๋‹ค๋ฆฌ์˜ ๊ธธ์ด๋ฅผ ์ˆซ์ž๋กœ ์ž…๋ ฅ๋ฐ›๊ณ  ์ƒ์„ฑํ•œ๋‹ค. + - ๋‹ค๋ฆฌ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์œ„ ์นธ๊ณผ ์•„๋ž˜ ์นธ ์ค‘ ๊ฑด๋„ ์ˆ˜ ์žˆ๋Š” ์นธ์€ 0๊ณผ 1 ์ค‘ ๋ฌด์ž‘์œ„ ๊ฐ’์„ ์ด์šฉํ•ด์„œ ์ •ํ•œ๋‹ค. + - ์œ„ ์นธ์„ ๊ฑด๋„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ U, ์•„๋ž˜ ์นธ์„ ๊ฑด๋„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ D๊ฐ’์œผ๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค. + - ๋ฌด์ž‘์œ„ ๊ฐ’์ด 0์ธ ๊ฒฝ์šฐ ์•„๋ž˜ ์นธ, 1์ธ ๊ฒฝ์šฐ ์œ„ ์นธ์ด ๊ฑด๋„ ์ˆ˜ ์žˆ๋Š” ์นธ์ด ๋œ๋‹ค. +- ๋‹ค๋ฆฌ๊ฐ€ ์ƒ์„ฑ๋˜๋ฉด ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ด๋™ํ•  ์นธ์„ ์„ ํƒํ•œ๋‹ค. + - ์ด๋™ํ•  ๋•Œ ์œ„ ์นธ์€ ๋Œ€๋ฌธ์ž U, ์•„๋ž˜ ์นธ์€ ๋Œ€๋ฌธ์ž D๋ฅผ ์ž…๋ ฅํ•œ๋‹ค. + - ์ด๋™ํ•œ ์นธ์„ ๊ฑด๋„ ์ˆ˜ ์žˆ๋‹ค๋ฉด O๋กœ ํ‘œ์‹œํ•œ๋‹ค. ๊ฑด๋„ ์ˆ˜ ์—†๋‹ค๋ฉด X๋กœ ํ‘œ์‹œํ•œ๋‹ค. +- ๋‹ค๋ฆฌ๋ฅผ ๋๊นŒ์ง€ ๊ฑด๋„ˆ๋ฉด ๊ฒŒ์ž„์ด ์ข…๋ฃŒ๋œ๋‹ค. +- ๋‹ค๋ฆฌ๋ฅผ ๊ฑด๋„ˆ๋‹ค ์‹คํŒจํ•˜๋ฉด ๊ฒŒ์ž„์„ ์žฌ์‹œ์ž‘ํ•˜๊ฑฐ๋‚˜ ์ข…๋ฃŒํ•  ์ˆ˜ ์žˆ๋‹ค. + - ์žฌ์‹œ์ž‘ํ•ด๋„ ์ฒ˜์Œ์— ๋งŒ๋“  ๋‹ค๋ฆฌ๋กœ ์žฌ์‚ฌ์šฉํ•œ๋‹ค. + - ๊ฒŒ์ž„ ๊ฒฐ๊ณผ์˜ ์ด ์‹œ๋„ํ•œ ํšŸ์ˆ˜๋Š” ์ฒซ ์‹œ๋„๋ฅผ ํฌํ•จํ•ด ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•  ๋•Œ๊นŒ์ง€ ์‹œ๋„ํ•œ ํšŸ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. +- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ `IllegalArgumentException`๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ณ , "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ ํ›„ ๊ทธ ๋ถ€๋ถ„๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋‹ค์‹œ ๋ฐ›๋Š”๋‹ค. + - `Exception`์ด ์•„๋‹Œ `IllegalArgumentException`, `IllegalStateException` ๋“ฑ๊ณผ ๊ฐ™์€ ๋ช…ํ™•ํ•œ ์œ ํ˜•์„ ์ฒ˜๋ฆฌํ•œ๋‹ค. + +# ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก +## ์ž…๋ ฅ +- [ ] ๋‹ค๋ฆฌ์˜ ๊ธธ์ด๋ฅผ ์ž…๋ ฅ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. +- [ ] ์œ„ ์•„๋ž˜ ์ค‘ ์œ ์ €๊ฐ€ ์ด๋™ํ•˜๊ณ ์ž ํ•˜๋Š” ๋ฐฉํ–ฅ์„ ์ž…๋ ฅ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. +- [ ] ๊ฒŒ์ž„ ์ข…๋ฃŒ ์‹œ ๊ฒŒ์ž„ ์žฌ์‹œ๋„ ์—ฌ๋ถ€๋ฅผ ์ž…๋ ฅ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. + +## ์ถœ๋ ฅ +- [ ] ๋งค ๋ผ์šด๋“œ ๋งˆ๋‹ค ์ด๋™ํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๋‹ค. +- [ ] ์ตœ์ข… ๊ฒŒ์ž„ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค. + +## ์ž…๋ ฅ ๊ฒ€์ฆ +- [ ] ๋‹ค๋ฆฌ ๊ธธ์ด ์ž…๋ ฅ ๊ฒ€์ฆ + - [ ] ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฐ’์œผ๋กœ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ + - [ ] 3์ด์ƒ 20 ์ดํ•˜์˜ ๊ฐ’์ด ์•„๋‹Œ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- [ ] ์œ„ ์•„๋ž˜์ค‘ ์œ ์ €๊ฐ€ ์ด๋™ํ•  ์นธ ์ž…๋ ฅ ๊ฒ€์ฆ + - [ ] U์™€ D์ค‘ ํ•˜๋‚˜์˜ ๋ฌธ์ž๋ฅผ ์„ ํƒ ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- [ ] ๊ฒŒ์ž„ ์žฌ์‹œ์ž‘/์ข…๋ฃŒ ์—ฌ๋ถ€ ์ž…๋ ฅ ๊ฒ€์ฆ + - [ ] R๊ณผ Q์ค‘ ํ•˜๋‚˜์˜ ๋ฌธ์ž๋ฅผ ์„ ํƒ ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ + +## ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง +- [ ] ๋‹ค๋ฆฌ + - [ ] ํŠน์ • ๊ธธ์ด์˜ ๋‹ค๋ฆฌ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. + - [ ] ๋‹ค๋ฆฌ๋Š” ```U,D,U,U,D```์™€ ๊ฐ™์ด ๊ฑด๋„ ์ˆ˜ ์žˆ๋Š” ๊ธธ์ด ์ƒ์„ฑ ์‹œ ์ •ํ•ด์ง„๋‹ค. + - [ ] ๋‹ค๋ฆฌ์˜ ๊ธธ์€ ์ƒ์„ฑ ์‹œ 0๊ณผ 1์˜ ๋ฌด์ž‘์œ„ ๊ฐ’์„ ํ†ตํ•ด์„œ ์ •ํ•ด์ง„๋‹ค. (0:D , 1:U) +- [ ] ๊ฒŒ์ž„ + - [ ] ์ด๋™ ๋ฐฉํ–ฅ์„ ์ •ํ–ˆ์„ ๋•Œ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค. + - [ ] ๊ฒŒ์ž„์— ์‹คํŒจํ•˜๋Š” ๊ฒฝ์šฐ ๊ฒŒ์ž„์„ ์žฌ์‹œ์ž‘ํ•˜๊ฑฐ๋‚˜ ์ข…๋ฃŒํ•  ์ˆ˜ ์žˆ๋‹ค. + - [ ] ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ์— ์‹คํŒจํ•˜์—ฌ ์žฌ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ์šฐ ๋„์ „์ค‘์ธ ๋‹ค๋ฆฌ๋กœ ๋„์ „ํ•œ๋‹ค. + - [ ] ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ์— ์„ฑ๊ณตํ•  ๊ฒฝ์šฐ ๊ฒŒ์ž„์€ ์ข…๋ฃŒ๋œ๋‹ค. + +
Unknown
๊ผผ๊ผผํ•œ readme ์ž‘์„ฑ ์ข‹์Šต๋‹ˆ๋‹ค! ๐Ÿ‘ ๋‹ค๋งŒ ์ฒดํฌ๋ฆฌ์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค๋ฉด ์™„์„ฑ๋œ ๊ธฐ๋Šฅ์€` - [x]` ๋กœ ์ฒดํฌ๋ฅผ ํ•˜๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!๐Ÿ˜Ž
@@ -0,0 +1,64 @@ +package bridge.domain; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ ๊ฒŒ์ž„์„ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค + */ +public class BridgeGame { + private static final int MIN_LENGTH = 3; + private static final int MAX_LENGTH = 20; + private static final String INVALID_LENGTH_BRIDGE_MESSAGE = "[ERROR] ๋‹ค๋ฆฌ ๊ธธ์ด๋Š” 3๋ถ€ํ„ฐ 20 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."; + + private final List<Direction> escapeRoute; + private int userPosition = 0; + + private BridgeGame(List<Direction> escapeRoute) { + validate(escapeRoute); + this.escapeRoute = escapeRoute; + } + + public static BridgeGame from(List<String> directions) { + List<Direction> escapeRoute = directions.stream() + .map(Direction::from) + .collect(Collectors.toList()); + return new BridgeGame(escapeRoute); + } + /** + * ์‚ฌ์šฉ์ž๊ฐ€ ์นธ์„ ์ด๋™ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ + * <p> + * ์ด๋™์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…(return type), ์ธ์ž(parameter)๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. + */ + public boolean move(Direction direction) { + if (escapeRoute.get(userPosition).equals(direction)) { + userPosition++; + return true; + } + return false; + } + + public boolean isGameEnd () { + return userPosition == escapeRoute.size(); + } + + /** + * ์‚ฌ์šฉ์ž๊ฐ€ ๊ฒŒ์ž„์„ ๋‹ค์‹œ ์‹œ๋„ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ + * <p> + * ์žฌ์‹œ์ž‘์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…(return type), ์ธ์ž(parameter)๋Š” ์ž์œ ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. + */ + public void retry() { + userPosition = 0; + } + + private void validate(List<Direction> escapeRoute) { + validateLength(escapeRoute); + } + + private void validateLength(List<Direction> escapeRoute) { + if (escapeRoute.size() < MIN_LENGTH || escapeRoute.size() > MAX_LENGTH) { + throw new IllegalArgumentException(INVALID_LENGTH_BRIDGE_MESSAGE); + } + } + +}
Java
๋‚˜๋„ ๋˜‘๊ฐ™์ด ํ•˜๊ณ  ์žˆ์Œ๐Ÿ˜ƒ ๋งคํ•‘์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋“ฑ ์ƒ์„ฑ๋กœ์ง์— ๋ฌด์–ธ๊ฐ€ ์ถ”๊ฐ€๋  ๋งŒํ•œ ๊ฒƒ์ด ์žˆ๋‹ค๋ฉด ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค ๐Ÿ™‚
@@ -1,4 +1,4 @@ -package bridge; +package bridge.domain; @FunctionalInterface public interface BridgeNumberGenerator {
Java
๋„ˆ ๋ง๋Œ€๋กœ ์„œ๋น„์Šค๋Š” ํ–‰์œ„์— ์ง‘์ค‘ํ•˜๋Š” ๋ ˆ์ด์–ด๋ผ๊ณ  ๋‚˜๋„ ์ƒ๊ฐํ•จ ๊ทธ๋Ÿฐ๋ฐ ํ–‰์œ„์™€ ์†์„ฑ์„ ๋ฌถ์€, ์šฐ๋ฆฌ๊ฐ€ ์„œ๋น„์Šคํ•˜๋Š” ๋ถ„์•ผ๋ฅผ ๋„๋ฉ”์ธ์œผ๋กœ ์ •์˜ํ•œ๋‹ค๋ฉด ๋„๋ฉ”์ธ์œผ๋กœ์˜ ๋ถ„๋ฆฌ๋„ ๋ฌธ์ œ์—†๋‹ค๊ณ  ๊ฐœ์ธ์ ์œผ๋กœ ์ƒ๊ฐํ•จ ๐Ÿค” ์ฆ‰ ๋„๋ฉ”์ธ์ด ์ข€ ๋” ํฌ๊ด„์ ์ธ ๊ฐœ๋…์ด๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค ๋„๋ฉ”์ธ ๋ ˆ์ด์–ด์™€ ์„œ๋น„์Šค๋ ˆ์ด์–ด์˜ ๊ตฌ๋ถ„์€ ๊ฐœ๋ฐœ ํŒจํ„ด (ex: DDD)๊ณผ ๊ฐ™์€ ๊ฒƒ๋“ค์— ์˜ํ–ฅ์„ ๋ฐ›๋Š” ๋ถ€๋ถ„์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์žˆ๋‹ค ๐Ÿ˜„
@@ -0,0 +1,17 @@ +package bridge.util; + +import java.util.function.Supplier; + +public class Repeater { + + public static <T> T repeatUntilNoException(Supplier<T> inputSupplier) { + while (true) { + try { + return inputSupplier.get(); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + +}
Java
์œ ํ‹ธ๋ฆฌํ‹ฐ ํด๋ž˜์Šค๋กœ ์ ์šฉํ–ˆ๊ธฐ์— ๋ฒ”์šฉ์„ฑ์žˆ๊ฒŒ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค ์‹ค์ œ๋กœ ํ•ด๋‹น ํด๋ž˜์Šค๋Š” ์ž…๋ ฅ์—์„œ๋งŒ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์ง€ ์•Š๊ณ  ์ƒ์„ฑ์— ์‹คํŒจํ•˜๋Š” ๊ฒฝ์šฐ์—๋„ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์–ด ๐Ÿ™‚
@@ -0,0 +1,79 @@ +package christmas.controller; + +import christmas.domain.badge.Badge; +import christmas.domain.discount.DiscountDetails; +import christmas.domain.discount.TotalDiscountEvent; +import christmas.domain.gift.Gift; +import christmas.domain.plan.EventDate; +import christmas.domain.plan.Menu; +import christmas.domain.plan.Order; +import christmas.domain.plan.Plan; +import christmas.dto.PlanResultDto; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; +import java.util.function.Supplier; + +public class ChristmasPlanerController { + + private final TotalDiscountEvent discountEvent = TotalDiscountEvent.createDecemberEvent(); + private final InputView inputView = new InputView(); + private final OutputView outputView = new OutputView(); + + public void run() { + startApplication(); + Plan plan = inputPlan(); + PlanResultDto planResult = applyEvents(plan); + printEventResult(planResult); + } + + private void startApplication() { + outputView.printApplicationTitle(); + } + + private Plan inputPlan() { + EventDate date = readRepeatedlyUntilNoException(this::readDate); + Order order = readRepeatedlyUntilNoException(this::readOrder); + return Plan.of(date, order); + } + + private <T> T readRepeatedlyUntilNoException(Supplier<T> supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception); + return readRepeatedlyUntilNoException(supplier); + } + } + + private EventDate readDate() { + int date = inputView.readDate(); + return EventDate.from(date); + } + + private Order readOrder() { + Map<Menu, Integer> order = inputView.readOrder(); + return Order.from(order); + } + + private PlanResultDto applyEvents(Plan plan) { + DiscountDetails discountDetails = discountEvent.makeDiscountDetails(plan); + Gift gift = Gift.from(plan.calculateTotalPrice()); + int totalBenefitPrice = calculateTotalBenefitPrice(discountDetails, gift); + Badge badge = Badge.from(totalBenefitPrice); + + return PlanResultDto.builder() + .plan(plan).discountDetails(discountDetails) + .gift(gift).badge(badge).build(); + } + + private int calculateTotalBenefitPrice(DiscountDetails discountDetails, Gift gift) { + int totalDiscountPrice = discountDetails.calculateTotalDiscountPrice(); + int giftBenefitPrice = gift.calculateBenefitPrice(); + return totalDiscountPrice + giftBenefitPrice; + } + + private void printEventResult(PlanResultDto planResult) { + outputView.printPlanResult(planResult); + } +}
Java
Plan์œผ๋กœ ๊ฐ์ฒดํ™” ์‹œํ‚ค์‹ ๊ฒŒ ์ธ์ƒ ๊นŠ๋„ค์š”!
@@ -0,0 +1,33 @@ +package christmas.domain.badge; + +import java.util.List; + +public enum Badge { + + SANTA(20_000), + TREE(10_000), + STAR(5_000), + NOTHING(0); + + private static final List<Badge> ORDER_BY_BENEFIT = List.of(SANTA, TREE, STAR, NOTHING); + + private final int minBenefitAmount; + + Badge(int minBenefitAmount) { + this.minBenefitAmount = minBenefitAmount; + } + + public static Badge from(int benefitAmount) { + return ORDER_BY_BENEFIT.stream() + .filter(badge -> badge.isReach(benefitAmount)) + .findFirst().orElseThrow(Badge::createIllegalBenefitAmountException); + } + + private static IllegalArgumentException createIllegalBenefitAmountException() { + return new IllegalArgumentException("benefit amount must not be negative"); + } + + private boolean isReach(int benefitAmount) { + return benefitAmount >= this.minBenefitAmount; + } +}
Java
Enum์€ vlaues()๋ฅผ ํ†ตํ•ด ์„ ์–ธ ์ˆœ์„œ๋Œ€๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์œผ๋‹ˆ ๋”ฐ๋กœ ์ •์˜ํ•˜์‹œ๋Š”๋Œ€์‹  ์‚ฌ์šฉํ•˜์…”๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,76 @@ +package christmas.domain.plan; + +import christmas.exception.DateInputException; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.Objects; +import java.util.Set; +import java.util.function.IntUnaryOperator; + +public class EventDate { + + private static final int YEAR = 2023; + private static final int MONTH = 12; + private static final int MIN_DATE = 1; + private static final int MAX_DATE = 31; + + private static final Set<DayOfWeek> WEEKEND = Set.of(DayOfWeek.FRIDAY, DayOfWeek.SATURDAY); + + private final LocalDate date; + + private EventDate(int date) { + validate(date); + this.date = LocalDate.of(YEAR, MONTH, date); + } + + private static void validate(int date) { + if (isOutOfRange(date)) { + throw new DateInputException("Date is Out of Range : " + date); + } + } + + private static boolean isOutOfRange(int date) { + return date < MIN_DATE || date > MAX_DATE; + } + + public static EventDate from(int date) { + return new EventDate(date); + } + + public boolean isWeekend() { + DayOfWeek dayOfWeek = date.getDayOfWeek(); + return WEEKEND.contains(dayOfWeek); + } + + public boolean isWeekDay() { + return !isWeekend(); + } + + public int calculateByDate(IntUnaryOperator function) { + return function.applyAsInt(getDate()); + } + + public int getDate() { + return date.getDayOfMonth(); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + EventDate comparedDate = (EventDate) object; + return Objects.equals(date, comparedDate.date); + } + + @Override + public int hashCode() { + if (date == null) { + return 0; + } + return date.hashCode(); + } +}
Java
dayOfWeek์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•˜์ง€ ์•Š๊ณ  ํ‰์ผ/์ฃผ๋ง ์—ฌ๋ถ€๋งŒ ์•Œ ์ˆ˜ ์žˆ๋„๋ก ํ•˜์…จ๋„ค์š”! 3์ฃผ์ฐจ ํ”ผ๋“œ๋ฐฑ์„ ์ž˜ ๋ฐ˜์˜ํ•˜์…จ๋„ค์š” ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค๐Ÿ‘
@@ -0,0 +1,27 @@ +package christmas.domain.discount.policy; + +import christmas.domain.plan.EventSchedule; +import christmas.domain.plan.Plan; +import java.util.function.IntUnaryOperator; + +public class ChristmasDDayDiscount extends DiscountPolicy { + + private static final int START_DATE = 1; + private static final int END_DATE = 25; + private static final EventSchedule EVENT_SCHEDULE = EventSchedule.of(START_DATE, END_DATE); + + private static final int DEFAULT_DISCOUNT_AMOUNT = 1_000; + private static final int INCREASING_DISCOUNT_AMOUNT = 100; + private static final IntUnaryOperator DISCOUNT_FUNCTION_BY_DATE + = date -> DEFAULT_DISCOUNT_AMOUNT + (date - 1) * INCREASING_DISCOUNT_AMOUNT; + + @Override + boolean isSatisfyPrecondition(Plan plan) { + return plan.isContainedBy(EVENT_SCHEDULE); + } + + @Override + int calculateDiscountAmount(Plan plan) { + return plan.calculateByDate(DISCOUNT_FUNCTION_BY_DATE); + } +}
Java
๋‹ค๋ฅธ ๊ตฌํ˜„์ฒด๋“ค๊ณผ ๋‹ฌ๋ฆฌ ์ด๋ถ€๋ถ„๋งŒ ํ•จ์ˆ˜ํ˜•์œผ๋กœ ์ž‘์„ฑํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์œผ์‹ค๊นŒ์š”?
@@ -0,0 +1,47 @@ +package christmas.domain.gift; + +import christmas.domain.plan.Menu; +import java.util.Map; +import java.util.Objects; + +public enum Gift { + EVENT_GIFT(Map.of(Menu.CHAMPAGNE, 1)), + NOTHING(Map.of()); + + private static final int MIN_GIFT_PRICE = 120_000; + + private final Map<Menu, Integer> menuToCount; + + Gift(Map<Menu, Integer> menuToCount) { + this.menuToCount = Objects.requireNonNull(menuToCount); + } + + public static Gift from(int totalPrice) { + if (isOverThanStandardPrice(totalPrice)) { + return EVENT_GIFT; + } + return NOTHING; + } + + private static boolean isOverThanStandardPrice(int totalPrice) { + return totalPrice >= MIN_GIFT_PRICE; + } + + public int calculateBenefitPrice() { + return menuToCount.keySet().stream() + .mapToInt(menu -> calculatePartOfPrice(menu, menuToCount.get(menu))) + .sum(); + } + + public int calculatePartOfPrice(Menu menu, int count) { + return menu.getPrice() * count; + } + + public boolean isEmpty() { + return menuToCount.isEmpty(); + } + + public Map<Menu, Integer> getMenuToCount() { + return Map.copyOf(menuToCount); + } +}
Java
์ด ๋ถ€๋ถ„์€ ์ฆ์ •ํ’ˆ์ด ์—ฌ๋Ÿฌ๊ฐœ๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค๋Š” ํ™•์žฅ์„ฑ์„ ๊ณ ๋ คํ•˜์‹ ๊ฑด๊ฐ€์š”?๐Ÿ‘
@@ -0,0 +1,21 @@ +package christmas.view; + +import christmas.domain.badge.Badge; +import java.util.Map; + +class BadgeView { + + private static final Map<Badge, String> BADGE_TO_MESSAGE = Map.of( + Badge.SANTA, "์‚ฐํƒ€", Badge.TREE, "ํŠธ๋ฆฌ", + Badge.STAR, "๋ณ„", Badge.NOTHING, "์—†์Œ"); + + private BadgeView() { + } + + public static String findView(Badge badge) { + if (!BADGE_TO_MESSAGE.containsKey(badge)) { + throw new IllegalArgumentException("Badge not enrolled at view; input : " + badge); + } + return BADGE_TO_MESSAGE.get(badge); + } +}
Java
๋ฆฌ๋ทฐ์ด๋‹˜์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ๊ถ๊ธˆํ•œ๊ฒŒ ์ƒ๊ฒจ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋Š”์ง€ ์—ฌ์ญค๋ด…๋‹ˆ๋‹ค! 3์ฃผ์ฐจ ํ”ผ๋“œ๋ฐฑ ์ค‘ "view๋ฅผ ์œ„ํ•œ ๋กœ์ง์€ ๋ถ„๋ฆฌํ•œ๋‹ค"๊ฐ€ ๋ชจ๋ธ์—์„œ๋Š” ๋ทฐ์™€ ๊ด€๋ จ๋œ ๊ฒƒ๋“ค ์•„๋ฌด๊ฒƒ๋„ ๊ฐ€์งˆ ์ˆ˜ ์—†๋Š” ๊ฑธ ์˜๋ฏธํ•˜๋ฉด ์ด ์ฒ˜๋Ÿผ ๋ทฐ์—์„œ ๋„๋ฉ”์ธ์— ๋Œ€ํ•ด ๋งŽ์€ ๊ฑธ ์•Œ์•„์•ผํ•˜๋Š” ์ ๋„ ์ƒ๊ธธ ์ˆ˜๋„ ์žˆ์ง€ ์•Š์„๊นŒ์š”?
@@ -0,0 +1,79 @@ +package christmas.controller; + +import christmas.domain.badge.Badge; +import christmas.domain.discount.DiscountDetails; +import christmas.domain.discount.TotalDiscountEvent; +import christmas.domain.gift.Gift; +import christmas.domain.plan.EventDate; +import christmas.domain.plan.Menu; +import christmas.domain.plan.Order; +import christmas.domain.plan.Plan; +import christmas.dto.PlanResultDto; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; +import java.util.function.Supplier; + +public class ChristmasPlanerController { + + private final TotalDiscountEvent discountEvent = TotalDiscountEvent.createDecemberEvent(); + private final InputView inputView = new InputView(); + private final OutputView outputView = new OutputView(); + + public void run() { + startApplication(); + Plan plan = inputPlan(); + PlanResultDto planResult = applyEvents(plan); + printEventResult(planResult); + } + + private void startApplication() { + outputView.printApplicationTitle(); + } + + private Plan inputPlan() { + EventDate date = readRepeatedlyUntilNoException(this::readDate); + Order order = readRepeatedlyUntilNoException(this::readOrder); + return Plan.of(date, order); + } + + private <T> T readRepeatedlyUntilNoException(Supplier<T> supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception); + return readRepeatedlyUntilNoException(supplier); + } + } + + private EventDate readDate() { + int date = inputView.readDate(); + return EventDate.from(date); + } + + private Order readOrder() { + Map<Menu, Integer> order = inputView.readOrder(); + return Order.from(order); + } + + private PlanResultDto applyEvents(Plan plan) { + DiscountDetails discountDetails = discountEvent.makeDiscountDetails(plan); + Gift gift = Gift.from(plan.calculateTotalPrice()); + int totalBenefitPrice = calculateTotalBenefitPrice(discountDetails, gift); + Badge badge = Badge.from(totalBenefitPrice); + + return PlanResultDto.builder() + .plan(plan).discountDetails(discountDetails) + .gift(gift).badge(badge).build(); + } + + private int calculateTotalBenefitPrice(DiscountDetails discountDetails, Gift gift) { + int totalDiscountPrice = discountDetails.calculateTotalDiscountPrice(); + int giftBenefitPrice = gift.calculateBenefitPrice(); + return totalDiscountPrice + giftBenefitPrice; + } + + private void printEventResult(PlanResultDto planResult) { + outputView.printPlanResult(planResult); + } +}
Java
์ €๋„ ์ด๋Ÿฐ ๋А๋‚Œ์ธ๋ฐ์š”. ์ €๋Š” ๋ทฐ๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ์š”์ฒญํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ๋“ค์„ ์ปจํŠธ๋กคํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ˜‚
@@ -0,0 +1,79 @@ +package christmas.controller; + +import christmas.domain.badge.Badge; +import christmas.domain.discount.DiscountDetails; +import christmas.domain.discount.TotalDiscountEvent; +import christmas.domain.gift.Gift; +import christmas.domain.plan.EventDate; +import christmas.domain.plan.Menu; +import christmas.domain.plan.Order; +import christmas.domain.plan.Plan; +import christmas.dto.PlanResultDto; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; +import java.util.function.Supplier; + +public class ChristmasPlanerController { + + private final TotalDiscountEvent discountEvent = TotalDiscountEvent.createDecemberEvent(); + private final InputView inputView = new InputView(); + private final OutputView outputView = new OutputView(); + + public void run() { + startApplication(); + Plan plan = inputPlan(); + PlanResultDto planResult = applyEvents(plan); + printEventResult(planResult); + } + + private void startApplication() { + outputView.printApplicationTitle(); + } + + private Plan inputPlan() { + EventDate date = readRepeatedlyUntilNoException(this::readDate); + Order order = readRepeatedlyUntilNoException(this::readOrder); + return Plan.of(date, order); + } + + private <T> T readRepeatedlyUntilNoException(Supplier<T> supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception); + return readRepeatedlyUntilNoException(supplier); + } + } + + private EventDate readDate() { + int date = inputView.readDate(); + return EventDate.from(date); + } + + private Order readOrder() { + Map<Menu, Integer> order = inputView.readOrder(); + return Order.from(order); + } + + private PlanResultDto applyEvents(Plan plan) { + DiscountDetails discountDetails = discountEvent.makeDiscountDetails(plan); + Gift gift = Gift.from(plan.calculateTotalPrice()); + int totalBenefitPrice = calculateTotalBenefitPrice(discountDetails, gift); + Badge badge = Badge.from(totalBenefitPrice); + + return PlanResultDto.builder() + .plan(plan).discountDetails(discountDetails) + .gift(gift).badge(badge).build(); + } + + private int calculateTotalBenefitPrice(DiscountDetails discountDetails, Gift gift) { + int totalDiscountPrice = discountDetails.calculateTotalDiscountPrice(); + int giftBenefitPrice = gift.calculateBenefitPrice(); + return totalDiscountPrice + giftBenefitPrice; + } + + private void printEventResult(PlanResultDto planResult) { + outputView.printPlanResult(planResult); + } +}
Java
์˜ค DTO์— ๋นŒ๋” ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜์…จ๋„ค์š” ์Šคํ”„๋ง ์–ด๋…ธํ…Œ์ด์…˜์—์„œ ์‚ฌ์šฉํ•˜๋˜ ๊ฑด๋ฐ ํ›Œ๋ฅญํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,27 @@ +package christmas.domain.discount.policy; + +import christmas.domain.plan.EventSchedule; +import christmas.domain.plan.Plan; +import java.util.function.IntUnaryOperator; + +public class ChristmasDDayDiscount extends DiscountPolicy { + + private static final int START_DATE = 1; + private static final int END_DATE = 25; + private static final EventSchedule EVENT_SCHEDULE = EventSchedule.of(START_DATE, END_DATE); + + private static final int DEFAULT_DISCOUNT_AMOUNT = 1_000; + private static final int INCREASING_DISCOUNT_AMOUNT = 100; + private static final IntUnaryOperator DISCOUNT_FUNCTION_BY_DATE + = date -> DEFAULT_DISCOUNT_AMOUNT + (date - 1) * INCREASING_DISCOUNT_AMOUNT; + + @Override + boolean isSatisfyPrecondition(Plan plan) { + return plan.isContainedBy(EVENT_SCHEDULE); + } + + @Override + int calculateDiscountAmount(Plan plan) { + return plan.calculateByDate(DISCOUNT_FUNCTION_BY_DATE); + } +}
Java
์ด๋ฒˆ ๊ณผ์ œ์—์„œ ๋žŒ๋‹ค๋ฅผ ๋งŽ์ด ์—ฐ์Šตํ•ด๋ณด๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ {() -> } ์™ธ์—๋„ ์ด๋ ‡๊ฒŒ ์“ธ ์ˆ˜ ์žˆ๊ฒ ๊ตฐ์š”! ์ข‹์€ ์ •๋ณด ์–ป์–ด๊ฐ‘๋‹ˆ๋‹ค!
@@ -0,0 +1,29 @@ +package christmas.view; + +import christmas.exception.DateInputException; +import christmas.exception.OnlyDrinkMenuException; +import christmas.exception.OrderInputException; +import christmas.exception.TotalMenuCountException; +import java.util.Map; + +class ErrorMessageView { + + private static final String ERROR_MESSAGE_PREFIX = "[ERROR] "; + private static final Map<Class<? extends IllegalArgumentException>, String> EXCEPTION_TO_ERROR_MESSAGE + = Map.of(DateInputException.class, "์œ ํšจํ•˜์ง€ ์•Š์€ ๋‚ ์งœ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.", + OrderInputException.class, "์œ ํšจํ•˜์ง€ ์•Š์€ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.", + OnlyDrinkMenuException.class, "์ฃผ๋ฌธ์€ ์Œ๋ฃŒ๋กœ๋งŒ ๊ตฌ์„ฑ๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค", + TotalMenuCountException.class, "์ด ๋ฉ”๋‰ด ๊ฐœ์ˆ˜๋Š” 20๊ฐœ๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค"); + private static final String DEFAULT_ERROR_MESSAGE = "์˜ˆ์ƒ์น˜ ๋ชปํ•œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ฌธ์˜ํ•˜์„ธ์š”."; + + private ErrorMessageView() { + } + + public static String constructMessage(IllegalArgumentException exception) { + return ERROR_MESSAGE_PREFIX.concat(findErrorMessage(exception)); + } + + private static String findErrorMessage(IllegalArgumentException exception) { + return EXCEPTION_TO_ERROR_MESSAGE.getOrDefault(exception.getClass(), DEFAULT_ERROR_MESSAGE); + } +}
Java
๊ฐ ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋ฅผ ๋งต์œผ๋กœ ๋‹ด๋Š” ๋ฐฉ๋ฒ• ์ •๋ง ๊ธฐ๋˜ฅ์ฐจ๋„ค์š”...
@@ -0,0 +1,79 @@ +package christmas.controller; + +import christmas.domain.badge.Badge; +import christmas.domain.discount.DiscountDetails; +import christmas.domain.discount.TotalDiscountEvent; +import christmas.domain.gift.Gift; +import christmas.domain.plan.EventDate; +import christmas.domain.plan.Menu; +import christmas.domain.plan.Order; +import christmas.domain.plan.Plan; +import christmas.dto.PlanResultDto; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; +import java.util.function.Supplier; + +public class ChristmasPlanerController { + + private final TotalDiscountEvent discountEvent = TotalDiscountEvent.createDecemberEvent(); + private final InputView inputView = new InputView(); + private final OutputView outputView = new OutputView(); + + public void run() { + startApplication(); + Plan plan = inputPlan(); + PlanResultDto planResult = applyEvents(plan); + printEventResult(planResult); + } + + private void startApplication() { + outputView.printApplicationTitle(); + } + + private Plan inputPlan() { + EventDate date = readRepeatedlyUntilNoException(this::readDate); + Order order = readRepeatedlyUntilNoException(this::readOrder); + return Plan.of(date, order); + } + + private <T> T readRepeatedlyUntilNoException(Supplier<T> supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception); + return readRepeatedlyUntilNoException(supplier); + } + } + + private EventDate readDate() { + int date = inputView.readDate(); + return EventDate.from(date); + } + + private Order readOrder() { + Map<Menu, Integer> order = inputView.readOrder(); + return Order.from(order); + } + + private PlanResultDto applyEvents(Plan plan) { + DiscountDetails discountDetails = discountEvent.makeDiscountDetails(plan); + Gift gift = Gift.from(plan.calculateTotalPrice()); + int totalBenefitPrice = calculateTotalBenefitPrice(discountDetails, gift); + Badge badge = Badge.from(totalBenefitPrice); + + return PlanResultDto.builder() + .plan(plan).discountDetails(discountDetails) + .gift(gift).badge(badge).build(); + } + + private int calculateTotalBenefitPrice(DiscountDetails discountDetails, Gift gift) { + int totalDiscountPrice = discountDetails.calculateTotalDiscountPrice(); + int giftBenefitPrice = gift.calculateBenefitPrice(); + return totalDiscountPrice + giftBenefitPrice; + } + + private void printEventResult(PlanResultDto planResult) { + outputView.printPlanResult(planResult); + } +}
Java
Plan ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ๋•Œ EventDate์™€ Order ๊ฐ์ฒด๋ฅผ ํ•œ ๋ฒˆ์— ๋„ฃ์–ด์„œ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด ๊น”๋”ํ•˜๊ธฐ๋Š” ํ•˜์ง€๋งŒ EventDate์™€ Order๋ฅผ ์ƒ์„ฑ์‹œ ๊ฒ€์ฆํ•˜๋Š”๋ฐ ๋ฐฉ๋ฌธ ๋‚ ์งœ์™€ ์ฃผ๋ฌธ ๋„๋ฉ”์ธ์ด ์ปจํŠธ๋กค๋Ÿฌ์— ๋…ธ์ถœ๋˜๋Š”๊ฒƒ์ด ์•„๋‹Œ๊ฐ€ ์ƒ๊ฐ์ด ๋“œ๋Š”๋ฐ์š”, ์ด ๋ถ€๋ถ„์€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”?
@@ -0,0 +1,79 @@ +package christmas.controller; + +import christmas.domain.badge.Badge; +import christmas.domain.discount.DiscountDetails; +import christmas.domain.discount.TotalDiscountEvent; +import christmas.domain.gift.Gift; +import christmas.domain.plan.EventDate; +import christmas.domain.plan.Menu; +import christmas.domain.plan.Order; +import christmas.domain.plan.Plan; +import christmas.dto.PlanResultDto; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; +import java.util.function.Supplier; + +public class ChristmasPlanerController { + + private final TotalDiscountEvent discountEvent = TotalDiscountEvent.createDecemberEvent(); + private final InputView inputView = new InputView(); + private final OutputView outputView = new OutputView(); + + public void run() { + startApplication(); + Plan plan = inputPlan(); + PlanResultDto planResult = applyEvents(plan); + printEventResult(planResult); + } + + private void startApplication() { + outputView.printApplicationTitle(); + } + + private Plan inputPlan() { + EventDate date = readRepeatedlyUntilNoException(this::readDate); + Order order = readRepeatedlyUntilNoException(this::readOrder); + return Plan.of(date, order); + } + + private <T> T readRepeatedlyUntilNoException(Supplier<T> supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception); + return readRepeatedlyUntilNoException(supplier); + } + } + + private EventDate readDate() { + int date = inputView.readDate(); + return EventDate.from(date); + } + + private Order readOrder() { + Map<Menu, Integer> order = inputView.readOrder(); + return Order.from(order); + } + + private PlanResultDto applyEvents(Plan plan) { + DiscountDetails discountDetails = discountEvent.makeDiscountDetails(plan); + Gift gift = Gift.from(plan.calculateTotalPrice()); + int totalBenefitPrice = calculateTotalBenefitPrice(discountDetails, gift); + Badge badge = Badge.from(totalBenefitPrice); + + return PlanResultDto.builder() + .plan(plan).discountDetails(discountDetails) + .gift(gift).badge(badge).build(); + } + + private int calculateTotalBenefitPrice(DiscountDetails discountDetails, Gift gift) { + int totalDiscountPrice = discountDetails.calculateTotalDiscountPrice(); + int giftBenefitPrice = gift.calculateBenefitPrice(); + return totalDiscountPrice + giftBenefitPrice; + } + + private void printEventResult(PlanResultDto planResult) { + outputView.printPlanResult(planResult); + } +}
Java
๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ปจํŠธ๋กค๋Ÿฌ์—์„œ ๋ฐฉ๋ฌธ๋‚ ์งœ์™€ ์ฃผ๋ฌธ์„ ๊ฐ€์ง€๊ณ ์žˆ๋Š” Plan ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด ํ• ์ธ์„ ์ ์šฉํ•˜์‹œ๋Š”๋ฐ, ํ• ์ธ ์ ์šฉ์ด๋ผ๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด ๋…ธ์ถœ๋˜์–ด์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹Œ๊ฐ€ ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค. ์„œ๋น„์Šค ๋ ˆ์ด์–ด์—์„œ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์€ ์ด์œ ๊ฐ€ ์žˆ์œผ์‹ ์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,33 @@ +package christmas.domain.badge; + +import java.util.List; + +public enum Badge { + + SANTA(20_000), + TREE(10_000), + STAR(5_000), + NOTHING(0); + + private static final List<Badge> ORDER_BY_BENEFIT = List.of(SANTA, TREE, STAR, NOTHING); + + private final int minBenefitAmount; + + Badge(int minBenefitAmount) { + this.minBenefitAmount = minBenefitAmount; + } + + public static Badge from(int benefitAmount) { + return ORDER_BY_BENEFIT.stream() + .filter(badge -> badge.isReach(benefitAmount)) + .findFirst().orElseThrow(Badge::createIllegalBenefitAmountException); + } + + private static IllegalArgumentException createIllegalBenefitAmountException() { + return new IllegalArgumentException("benefit amount must not be negative"); + } + + private boolean isReach(int benefitAmount) { + return benefitAmount >= this.minBenefitAmount; + } +}
Java
values() ๋“ฑ์œผ๋กœ ๊ฐ€์ ธ์˜ค๋ฉด ์ˆœ์„œ๊ฐ€ ์ œ๊ฐ€ ์ž‘์„ฑํ•œ ์ˆœ์„œ์— ์˜ํ–ฅ์„ ๋ฐ›๋Š”๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ์ผ๋ถ€๋Ÿฌ `ORDER_BY_BENEFIT`์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ๋‹ค๋ฅธ ์ฝ”๋“œ๋“ค์„ ๋ณด๋‹ˆ `Arrays.stream(values()).sort(this::price)` ํ˜•์‹์œผ๋กœ ๋งŽ์ด ์‚ฌ์šฉ ํ•ด์•ผ ๊ฒ ๋”๋ผ๊ตฌ์š”.
@@ -0,0 +1,27 @@ +package christmas.domain.discount.policy; + +import christmas.domain.plan.EventSchedule; +import christmas.domain.plan.Plan; +import java.util.function.IntUnaryOperator; + +public class ChristmasDDayDiscount extends DiscountPolicy { + + private static final int START_DATE = 1; + private static final int END_DATE = 25; + private static final EventSchedule EVENT_SCHEDULE = EventSchedule.of(START_DATE, END_DATE); + + private static final int DEFAULT_DISCOUNT_AMOUNT = 1_000; + private static final int INCREASING_DISCOUNT_AMOUNT = 100; + private static final IntUnaryOperator DISCOUNT_FUNCTION_BY_DATE + = date -> DEFAULT_DISCOUNT_AMOUNT + (date - 1) * INCREASING_DISCOUNT_AMOUNT; + + @Override + boolean isSatisfyPrecondition(Plan plan) { + return plan.isContainedBy(EVENT_SCHEDULE); + } + + @Override + int calculateDiscountAmount(Plan plan) { + return plan.calculateByDate(DISCOUNT_FUNCTION_BY_DATE); + } +}
Java
๋„๋ฉ”์ธ๋ผ๋ฆฌ ์ •๋ณด๋ฅผ ์ฃผ๊ณ  ๋ฐ›๋Š”๋ฐ getter๋ฅผ ์•ˆ์“ฐ๋Š” ๊ฒƒ์ด ๊ฐœ์ธ์ ์ธ ์ด๋ฒˆ ๊ณผ์ œ ๋ชฉํ‘œ์˜€์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ date ๋ผ๋Š” int ๊ฐ’์„ ๋ฐ›์•„์˜ค๊ธฐ ๋ณด๋‹ค, date๋ฅผ ํ†ตํ•ด ๊ณ„์‚ฐํ•˜๋Š” ์‹์„ ๋„˜๊ฒจ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ƒ๊ฐํ•ด๋ณด๋ฉด ์ด์ •๋„๋Š” getter๋กœ ์จ๋„ ๋˜์ง€ ์•Š๋‚˜ ์‹ถ์ง€๋งŒ, ๊ทธ๋ƒฅ ์ตœ๋Œ€ํ•œ ๊ฐ์ฒด๋‹ต๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ํ˜•์‹์œผ๋กœ ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,47 @@ +package christmas.domain.gift; + +import christmas.domain.plan.Menu; +import java.util.Map; +import java.util.Objects; + +public enum Gift { + EVENT_GIFT(Map.of(Menu.CHAMPAGNE, 1)), + NOTHING(Map.of()); + + private static final int MIN_GIFT_PRICE = 120_000; + + private final Map<Menu, Integer> menuToCount; + + Gift(Map<Menu, Integer> menuToCount) { + this.menuToCount = Objects.requireNonNull(menuToCount); + } + + public static Gift from(int totalPrice) { + if (isOverThanStandardPrice(totalPrice)) { + return EVENT_GIFT; + } + return NOTHING; + } + + private static boolean isOverThanStandardPrice(int totalPrice) { + return totalPrice >= MIN_GIFT_PRICE; + } + + public int calculateBenefitPrice() { + return menuToCount.keySet().stream() + .mapToInt(menu -> calculatePartOfPrice(menu, menuToCount.get(menu))) + .sum(); + } + + public int calculatePartOfPrice(Menu menu, int count) { + return menu.getPrice() * count; + } + + public boolean isEmpty() { + return menuToCount.isEmpty(); + } + + public Map<Menu, Integer> getMenuToCount() { + return Map.copyOf(menuToCount); + } +}
Java
๋„ต! ํ™•์žฅ์„ฑ์„ ๊ณ ๋ คํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,21 @@ +package christmas.view; + +import christmas.domain.badge.Badge; +import java.util.Map; + +class BadgeView { + + private static final Map<Badge, String> BADGE_TO_MESSAGE = Map.of( + Badge.SANTA, "์‚ฐํƒ€", Badge.TREE, "ํŠธ๋ฆฌ", + Badge.STAR, "๋ณ„", Badge.NOTHING, "์—†์Œ"); + + private BadgeView() { + } + + public static String findView(Badge badge) { + if (!BADGE_TO_MESSAGE.containsKey(badge)) { + throw new IllegalArgumentException("Badge not enrolled at view; input : " + badge); + } + return BADGE_TO_MESSAGE.get(badge); + } +}
Java
๋งž์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๋˜๋ฉด View๊ฐ€ ๊ต‰์žฅํžˆ ์ปค์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ํ‰์†Œ์— ์ €๋„ enum์—์„œ ๊ด€๋ฆฌํ–ˆ๋Š”๋ฐ ์ด๋ฒˆ์ฃผ ๊ณผ์ œ์—๋Š” ์š”๊ตฌ์‚ฌํ•ญ์„ ๊ทนํ•œ์œผ๋กœ ์ฑ™๊ธฐ๊ณ  ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค. ์งˆ๋ฌธํ•˜์‹  ๋ถ€๋ถ„์ด ๊ต‰์žฅํžˆ ๋‚ ์นด๋กœ์šฐ์‹œ๋„ค์š”. "๋”ฐ์ง€์ง€ ์•Š๊ณ  ์š”๊ตฌ ์‚ฌํ•ญ์„ ์ตœ๋Œ€ํ•œ ์ง€์ผœ๋ณด์ž"๋Š” ๋ถ€๋ถ„์€ ์ „๋ถ€ ์–ธ๊ธ‰ํ•˜์‹  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋‚ ์นด๋กœ์šด ๋ฆฌ๋ทฐ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค.
@@ -0,0 +1,48 @@ +package christmas.domain.plan; + +public enum Menu { + + MUSHROOM_SOUP(6_000, Category.APPETIZER), + TAPAS(5_500, Category.APPETIZER), + CAESAR_SALAD(8_000, Category.APPETIZER), + + T_BONE_STEAK(55_000, Category.MAIN), + BARBECUE_RIBS(54_000, Category.MAIN), + SEAFOOD_PASTA(35_000, Category.MAIN), + CHRISTMAS_PASTA(25_000, Category.MAIN), + + CHOCOLATE_CAKE(15_000, Category.DESSERT), + ICE_CREAM(5_000, Category.DESSERT), + + ZERO_COKE(3_000, Category.DRINK), + RED_WINE(60_000, Category.DRINK), + CHAMPAGNE(25_000, Category.DRINK); + + private final int price; + private final Category category; + + Menu(int price, Category category) { + this.price = price; + this.category = category; + } + + public boolean isMain() { + return this.category == Category.MAIN; + } + + public boolean isDessert() { + return this.category == Category.DESSERT; + } + + public boolean isDrink() { + return this.category == Category.DRINK; + } + + public int getPrice() { + return price; + } + + private enum Category { + APPETIZER, MAIN, DESSERT, DRINK + } +}
Java
๊ฐ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„๋กœ๋„ enum์„ ์ •์˜ํ•ด์„œ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์„๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค!
@@ -0,0 +1,27 @@ +package christmas.view; + +import christmas.dto.DiscountEventDto; +import java.util.Map; + +class BenefitDetailView { + + private static final Map<DiscountEventDto, String> DISCOUNT_EVENT_TO_MESSAGE = Map.of( + DiscountEventDto.CHRISTMAS_D_DAY, "ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ", DiscountEventDto.WEEKDAY, "ํ‰์ผ ํ• ์ธ", + DiscountEventDto.WEEKEND, "์ฃผ๋ง ํ• ์ธ", DiscountEventDto.SPECIAL, "ํŠน๋ณ„ ํ• ์ธ" + ); + private static final String GIFT_EVENT_MESSAGE = "์ฆ์ • ์ด๋ฒคํŠธ"; + + private BenefitDetailView() { + } + + public static String findView(DiscountEventDto discountEvent) { + if (!DISCOUNT_EVENT_TO_MESSAGE.containsKey(discountEvent)) { + throw new IllegalArgumentException("DiscountEventDto not enrolled at view; input : " + discountEvent); + } + return DISCOUNT_EVENT_TO_MESSAGE.get(discountEvent); + } + + public static String findGiftEventView() { + return GIFT_EVENT_MESSAGE; + } +}
Java
์„ธ์„ธํ•˜๊ฒŒ ๋‚˜๋ˆ„๋‹ค๋ณด๋‹ˆ ํ• ์ธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋ทฐ๊ฐ€ ๊ฐ–๊ฒŒ๋œ ๊ฒƒ ๊ฐ™๋„ค์š”. ์œ„์— ๋‹ค์Šฌ๋‹˜์ด ๋ง์”€ํ•˜์‹  ๊ฒƒ ์ฒ˜๋Ÿผ ๋ทฐ๊ฐ€ ๋„๋ฉ”์ธ์— ๊ด€๋ จํ•œ ์ •๋ณด๋ฅผ ๊ฐ–๊ฒŒ๋˜๊ณ  ๋ณ€๊ฒฝ ํฌ์ธํŠธ ๋˜ํ•œ ๋Š˜์ง€ ์•Š์„๊นŒ ํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,103 @@ +package christmas.domain.plan; + +import christmas.exception.OnlyDrinkMenuException; +import christmas.exception.OrderInputException; +import christmas.exception.TotalMenuCountException; +import java.util.Map; +import java.util.Map.Entry; +import java.util.function.Predicate; + +public class Order { + + private static final int TOTAL_COUNT_OF_MENU = 20; + + private final Map<Menu, Integer> menuToCount; + + private Order(Map<Menu, Integer> menuToCount) { + validate(menuToCount); + this.menuToCount = Map.copyOf(menuToCount); + } + + private static void validate(Map<Menu, Integer> menuToCount) { + validateCountPerMenu(menuToCount); + validateTotalCount(menuToCount); + validateNotOnlyDrink(menuToCount); + } + + private static void validateCountPerMenu(Map<Menu, Integer> menuToCount) { + if (isExistCountUnderOne(menuToCount)) { + throw new OrderInputException("quantity isn't less than 1"); + } + } + + private static boolean isExistCountUnderOne(Map<Menu, Integer> menuToCount) { + return menuToCount.values().stream() + .anyMatch(count -> count < 1); + } + + private static void validateTotalCount(Map<Menu, Integer> menuToCount) { + if (isOverTotalCount(menuToCount)) { + throw new TotalMenuCountException(TOTAL_COUNT_OF_MENU); + } + } + + private static boolean isOverTotalCount(Map<Menu, Integer> menuToCount) { + return countTotalMenu(menuToCount) > TOTAL_COUNT_OF_MENU; + } + + private static int countTotalMenu(Map<Menu, Integer> menuToCount) { + return menuToCount.values().stream() + .mapToInt(Integer::intValue) + .sum(); + } + + private static void validateNotOnlyDrink(Map<Menu, Integer> menuToCount) { + if (isOnlyDrinkMenu(menuToCount)) { + throw new OnlyDrinkMenuException(); + } + } + + private static boolean isOnlyDrinkMenu(Map<Menu, Integer> menuToCount) { + return menuToCount.keySet().stream() + .allMatch(Menu::isDrink); + } + + public static Order from(Map<Menu, Integer> menuToCount) { + return new Order(menuToCount); + } + + public int countMainMenu() { + return countMenu(Menu::isMain); + } + + public int countDessertMenu() { + return countMenu(Menu::isDessert); + } + + private int countMenu(Predicate<Menu> condition) { + return menuToCount.keySet().stream() + .filter(condition) + .mapToInt(menuToCount::get) + .sum(); + } + + public int calculateTotalPrice() { + return menuToCount.entrySet().stream() + .mapToInt(this::calculateSubPrice) + .sum(); + } + + private int calculateSubPrice(Entry<Menu, Integer> menuCountPair) { + int menuPrice = menuCountPair.getKey().getPrice(); + int count = menuCountPair.getValue(); + return menuPrice * count; + } + + public boolean isTotalPriceEqualOrMoreThan(int comparedPrice) { + return calculateTotalPrice() >= comparedPrice; + } + + public Map<Menu, Integer> getMenuToCount() { + return Map.copyOf(menuToCount); + } +}
Java
์ €๋„ ์ด๋ ‡๊ฒŒ ํ–ˆ๋‹ค๊ฐ€ ํƒ์ƒ‰์ด ์žฅ์ ์ธ Map ๊ฐ€์ง€๊ณ  ์ž๊พธ ์ˆœํšŒํ•˜๋Š”๋ฐ์— ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ ๊ฐ™์•„์„œ `public record menuToCount(Menu menu, int quantity){}` ์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด์„œ ์ˆœํšŒ์— ์ ์ ˆํ•˜๊ฒŒ `List<menuToCount>` ์ด๋ ‡๊ฒŒ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ ๊ทธ๋ƒฅ Map ์‚ฌ์šฉํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”??
@@ -0,0 +1,21 @@ +package christmas.domain.discount.policy; + +import christmas.domain.plan.EventSchedule; +import christmas.domain.plan.Plan; +import java.util.Set; + +public class SpecialDiscount extends DiscountPolicy { + + private static final EventSchedule EVENT_SCHEDULE = EventSchedule.from(Set.of(3, 10, 17, 24, 25, 31)); + private static final int DISCOUNT_AMOUNT = 1_000; + + @Override + boolean isSatisfyPrecondition(Plan plan) { + return plan.isContainedBy(EVENT_SCHEDULE); + } + + @Override + int calculateDiscountAmount(Plan plan) { + return DISCOUNT_AMOUNT; + } +}
Java
ํŠน๋ณ„ ์ด๋ฒคํŠธ ๋‚ ์งœ๋Š” ์ผ์š”์ผ + ํฌ๋ฆฌ์Šค๋งˆ์Šค๋‚  ์ธ๋ฐ, ์ด ๋ถ€๋ถ„์„ ๋ช…ํ™•ํ•˜๊ฒŒ ๋“œ๋ ค๋ƒˆ์œผ๋ฉด ๋” ์ข‹์ง€ ์•Š์•˜์„๊นŒ ์‹ถ์–ด์š”!
@@ -0,0 +1,47 @@ +package christmas.domain.gift; + +import christmas.domain.plan.Menu; +import java.util.Map; +import java.util.Objects; + +public enum Gift { + EVENT_GIFT(Map.of(Menu.CHAMPAGNE, 1)), + NOTHING(Map.of()); + + private static final int MIN_GIFT_PRICE = 120_000; + + private final Map<Menu, Integer> menuToCount; + + Gift(Map<Menu, Integer> menuToCount) { + this.menuToCount = Objects.requireNonNull(menuToCount); + } + + public static Gift from(int totalPrice) { + if (isOverThanStandardPrice(totalPrice)) { + return EVENT_GIFT; + } + return NOTHING; + } + + private static boolean isOverThanStandardPrice(int totalPrice) { + return totalPrice >= MIN_GIFT_PRICE; + } + + public int calculateBenefitPrice() { + return menuToCount.keySet().stream() + .mapToInt(menu -> calculatePartOfPrice(menu, menuToCount.get(menu))) + .sum(); + } + + public int calculatePartOfPrice(Menu menu, int count) { + return menu.getPrice() * count; + } + + public boolean isEmpty() { + return menuToCount.isEmpty(); + } + + public Map<Menu, Integer> getMenuToCount() { + return Map.copyOf(menuToCount); + } +}
Java
์ด๋ ‡๊ฒŒ ์ฆ์ • ์ด๋ฒคํŠธ๋งŒ ๋”ฐ๋กœ ๋‹ค๋ฃจ์…จ๊ตฐ์š” ์ข‹์€ ๋ฐฉ๋ฒ• ์•Œ์•„๊ฐ‘๋‹ˆ๋‹ค!
@@ -0,0 +1,76 @@ +package christmas.domain.plan; + +import christmas.exception.DateInputException; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.Objects; +import java.util.Set; +import java.util.function.IntUnaryOperator; + +public class EventDate { + + private static final int YEAR = 2023; + private static final int MONTH = 12; + private static final int MIN_DATE = 1; + private static final int MAX_DATE = 31; + + private static final Set<DayOfWeek> WEEKEND = Set.of(DayOfWeek.FRIDAY, DayOfWeek.SATURDAY); + + private final LocalDate date; + + private EventDate(int date) { + validate(date); + this.date = LocalDate.of(YEAR, MONTH, date); + } + + private static void validate(int date) { + if (isOutOfRange(date)) { + throw new DateInputException("Date is Out of Range : " + date); + } + } + + private static boolean isOutOfRange(int date) { + return date < MIN_DATE || date > MAX_DATE; + } + + public static EventDate from(int date) { + return new EventDate(date); + } + + public boolean isWeekend() { + DayOfWeek dayOfWeek = date.getDayOfWeek(); + return WEEKEND.contains(dayOfWeek); + } + + public boolean isWeekDay() { + return !isWeekend(); + } + + public int calculateByDate(IntUnaryOperator function) { + return function.applyAsInt(getDate()); + } + + public int getDate() { + return date.getDayOfMonth(); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + EventDate comparedDate = (EventDate) object; + return Objects.equals(date, comparedDate.date); + } + + @Override + public int hashCode() { + if (date == null) { + return 0; + } + return date.hashCode(); + } +}
Java
์ €๋Š” LocalDate๋ฅผ ๊ทธ๋ƒฅ ์‚ฌ์šฉํ–ˆ์—ˆ๋Š”๋ฐ, ์ด๋ ‡๊ฒŒ ๋”ฐ๋กœ ํด๋ž˜์Šค๋กœ ํŒŒ์„œ ๋‹ค๋ฃจ๋Š”๊ฒŒ ํ›จ์”ฌ ๊น”๋”ํ•œ๊ฒƒ ๊ฐ™๋„ค์š”
@@ -0,0 +1,79 @@ +package christmas.controller; + +import christmas.domain.badge.Badge; +import christmas.domain.discount.DiscountDetails; +import christmas.domain.discount.TotalDiscountEvent; +import christmas.domain.gift.Gift; +import christmas.domain.plan.EventDate; +import christmas.domain.plan.Menu; +import christmas.domain.plan.Order; +import christmas.domain.plan.Plan; +import christmas.dto.PlanResultDto; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; +import java.util.function.Supplier; + +public class ChristmasPlanerController { + + private final TotalDiscountEvent discountEvent = TotalDiscountEvent.createDecemberEvent(); + private final InputView inputView = new InputView(); + private final OutputView outputView = new OutputView(); + + public void run() { + startApplication(); + Plan plan = inputPlan(); + PlanResultDto planResult = applyEvents(plan); + printEventResult(planResult); + } + + private void startApplication() { + outputView.printApplicationTitle(); + } + + private Plan inputPlan() { + EventDate date = readRepeatedlyUntilNoException(this::readDate); + Order order = readRepeatedlyUntilNoException(this::readOrder); + return Plan.of(date, order); + } + + private <T> T readRepeatedlyUntilNoException(Supplier<T> supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception); + return readRepeatedlyUntilNoException(supplier); + } + } + + private EventDate readDate() { + int date = inputView.readDate(); + return EventDate.from(date); + } + + private Order readOrder() { + Map<Menu, Integer> order = inputView.readOrder(); + return Order.from(order); + } + + private PlanResultDto applyEvents(Plan plan) { + DiscountDetails discountDetails = discountEvent.makeDiscountDetails(plan); + Gift gift = Gift.from(plan.calculateTotalPrice()); + int totalBenefitPrice = calculateTotalBenefitPrice(discountDetails, gift); + Badge badge = Badge.from(totalBenefitPrice); + + return PlanResultDto.builder() + .plan(plan).discountDetails(discountDetails) + .gift(gift).badge(badge).build(); + } + + private int calculateTotalBenefitPrice(DiscountDetails discountDetails, Gift gift) { + int totalDiscountPrice = discountDetails.calculateTotalDiscountPrice(); + int giftBenefitPrice = gift.calculateBenefitPrice(); + return totalDiscountPrice + giftBenefitPrice; + } + + private void printEventResult(PlanResultDto planResult) { + outputView.printPlanResult(planResult); + } +}
Java
"์–ด์ฉ” ์ˆ˜ ์—†๋Š” ๋ถ€๋ถ„์ด๋‹ค"๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ๊ทธ๋ƒฅ ์ง€๊ธˆ ์ฆ‰๊ฐ์ ์œผ๋กœ ๋“  ์ œ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค. (๋ถ„๋ช…ํžˆ ์ฑ…์ด๋‚˜ ๊ธ€์—์„œ ๋ดค์„ํ…๋ฐ...) - ๊ฐ์ฒด๋Š” ์ƒ์„ฑ์ž์—์„œ ์ธ์ž๋ฅผ ํ†ตํ•ด ์ฃผ์ž… ๋ฐ›๋Š” ๊ฒƒ์ด ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์งœ๋Š”๋ฐ ์šฉ์ดํ•˜๋‹ค (๋‚ด๋ถ€์—์„œ ์ƒ์„ฑํ•˜์ง€ ๋ง๊ณ ) - ๊ฐ์ฒด๋Š” ์„œ๋กœ์— ๋Œ€ํ•ด ๋ชจ๋ฅด๋ฉด ๋ชจ๋ฅผ์ˆ˜๋ก (์˜์กด์„ฑ์ด ๋‚ฎ์„์ˆ˜๋ก) ์ข‹๋‹ค. ์‚ฌ์‹ค 1๋ฒˆ์„ ์ง€ํ‚ฌ๋ ค๋ฉด ์ง€๊ธˆ์ฒ˜๋Ÿผ ์™ธ๋ถ€์—์„œ ์ƒ์„ฑํ•ด์„œ ๋„ฃ์–ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  Controller์™€ ๋„๋ฉ”์ธ ๊ฐ„์˜ ์ข…์†์„ฑ์„ ์ค„์ด๋ ค๋ฉด (2๋ฒˆ์„ ์ง€ํ‚ค๋ ค๋ฉด) EventDate์™€ Order๋ฅผ Plan๋‚ด๋ถ€์—์„œ ์ƒ์„ฑํ•ด์•ผ ํ•˜์ฃ . ๊ทธ๋ƒฅ ์ง€ํ‚ฌ ๊ฒŒ ๋งŽ๋‹ค๋ณด๋ฉด ๋ชจ๋‘ ์ง€ํ‚ฌ ์ˆ˜๋Š” ์—†์ฃ . ์š”๊ตฌ์‚ฌํ•ญ ์ž์ฒด๊ฐ€ EventDate์˜ ํ˜•์‹์ด ๋‹ค๋ฅผ ๋•Œ, ๋ฐ”๋กœ ๋‹ค์‹œ ์ž…๋ ฅํ•ด์•ผ ํ•˜๋‹ˆ๊นŒ 1๋ฒˆ ๊ทœ์น™์„ ๋”ฐ๋ž๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฆฌ๋ทฐ์–ด๋‹˜์ด ์ƒ๊ฐํ•˜์‹  ๊ฒƒ์— ์ œ๋Œ€๋กœ ๋‹ต๋ณ€์„ ๋ชป๋“œ๋ฆฐ ๊ฑฐ ๊ฐ™์€๋ฐ ์•„๋ž˜์„œ ์ด์–ด์„œ ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,79 @@ +package christmas.controller; + +import christmas.domain.badge.Badge; +import christmas.domain.discount.DiscountDetails; +import christmas.domain.discount.TotalDiscountEvent; +import christmas.domain.gift.Gift; +import christmas.domain.plan.EventDate; +import christmas.domain.plan.Menu; +import christmas.domain.plan.Order; +import christmas.domain.plan.Plan; +import christmas.dto.PlanResultDto; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; +import java.util.function.Supplier; + +public class ChristmasPlanerController { + + private final TotalDiscountEvent discountEvent = TotalDiscountEvent.createDecemberEvent(); + private final InputView inputView = new InputView(); + private final OutputView outputView = new OutputView(); + + public void run() { + startApplication(); + Plan plan = inputPlan(); + PlanResultDto planResult = applyEvents(plan); + printEventResult(planResult); + } + + private void startApplication() { + outputView.printApplicationTitle(); + } + + private Plan inputPlan() { + EventDate date = readRepeatedlyUntilNoException(this::readDate); + Order order = readRepeatedlyUntilNoException(this::readOrder); + return Plan.of(date, order); + } + + private <T> T readRepeatedlyUntilNoException(Supplier<T> supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception); + return readRepeatedlyUntilNoException(supplier); + } + } + + private EventDate readDate() { + int date = inputView.readDate(); + return EventDate.from(date); + } + + private Order readOrder() { + Map<Menu, Integer> order = inputView.readOrder(); + return Order.from(order); + } + + private PlanResultDto applyEvents(Plan plan) { + DiscountDetails discountDetails = discountEvent.makeDiscountDetails(plan); + Gift gift = Gift.from(plan.calculateTotalPrice()); + int totalBenefitPrice = calculateTotalBenefitPrice(discountDetails, gift); + Badge badge = Badge.from(totalBenefitPrice); + + return PlanResultDto.builder() + .plan(plan).discountDetails(discountDetails) + .gift(gift).badge(badge).build(); + } + + private int calculateTotalBenefitPrice(DiscountDetails discountDetails, Gift gift) { + int totalDiscountPrice = discountDetails.calculateTotalDiscountPrice(); + int giftBenefitPrice = gift.calculateBenefitPrice(); + return totalDiscountPrice + giftBenefitPrice; + } + + private void printEventResult(PlanResultDto planResult) { + outputView.printPlanResult(planResult); + } +}
Java
์•„๋งˆ๋„ ์‹ค์งˆ์ ์œผ๋กœ๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์ž‘์€ ํฌ๊ธฐ์ด๋‹ค ๋ณด๋‹ˆ Service Layer๋กœ๊นŒ์ง€ ๋ถ„๋ฆฌํ•  ํ•„์š”์„ฑ์„ ๋ชป๋А๋‚€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ฉ”์„œ๋“œ๋ฅผ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ ๋งŒ์œผ๋กœ๋„ ์ถฉ๋ถ„ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์—ฌ๊ธฐ์—์„œ ํ”„๋กœ๊ทธ๋žจ์ด ์ ์  ์ปค์ง„๋‹ค๋ฉด Service Layer๊ฐ€ ํ•„์š”ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,48 @@ +package christmas.domain.plan; + +public enum Menu { + + MUSHROOM_SOUP(6_000, Category.APPETIZER), + TAPAS(5_500, Category.APPETIZER), + CAESAR_SALAD(8_000, Category.APPETIZER), + + T_BONE_STEAK(55_000, Category.MAIN), + BARBECUE_RIBS(54_000, Category.MAIN), + SEAFOOD_PASTA(35_000, Category.MAIN), + CHRISTMAS_PASTA(25_000, Category.MAIN), + + CHOCOLATE_CAKE(15_000, Category.DESSERT), + ICE_CREAM(5_000, Category.DESSERT), + + ZERO_COKE(3_000, Category.DRINK), + RED_WINE(60_000, Category.DRINK), + CHAMPAGNE(25_000, Category.DRINK); + + private final int price; + private final Category category; + + Menu(int price, Category category) { + this.price = price; + this.category = category; + } + + public boolean isMain() { + return this.category == Category.MAIN; + } + + public boolean isDessert() { + return this.category == Category.DESSERT; + } + + public boolean isDrink() { + return this.category == Category.DRINK; + } + + public int getPrice() { + return price; + } + + private enum Category { + APPETIZER, MAIN, DESSERT, DRINK + } +}
Java
์ €๋Š” Menu Enum์—๊ฒŒ์„œ public method๋ฅผ ์ œ๊ณตํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋ฐฉ์‹์ด ํšจ์œจ์ ์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฐ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„๋กœ๋„ enum์„ ๊ด€๋ฆฌํ•˜๋Š” ์ฝ”๋“œ๋Š” ์–ด๋–ค ๋А๋‚Œ์ผ๊นŒ์š”? ๊ทธ๋ฆฌ๊ณ  ๊ทธ ๋ฐฉ์‹์ด ์ด ๋ฐฉ์‹๋ณด๋‹ค ๋” ์ข‹์€ ์ ์€ ๋ฌด์—‡์ด ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,27 @@ +package christmas.view; + +import christmas.dto.DiscountEventDto; +import java.util.Map; + +class BenefitDetailView { + + private static final Map<DiscountEventDto, String> DISCOUNT_EVENT_TO_MESSAGE = Map.of( + DiscountEventDto.CHRISTMAS_D_DAY, "ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ", DiscountEventDto.WEEKDAY, "ํ‰์ผ ํ• ์ธ", + DiscountEventDto.WEEKEND, "์ฃผ๋ง ํ• ์ธ", DiscountEventDto.SPECIAL, "ํŠน๋ณ„ ํ• ์ธ" + ); + private static final String GIFT_EVENT_MESSAGE = "์ฆ์ • ์ด๋ฒคํŠธ"; + + private BenefitDetailView() { + } + + public static String findView(DiscountEventDto discountEvent) { + if (!DISCOUNT_EVENT_TO_MESSAGE.containsKey(discountEvent)) { + throw new IllegalArgumentException("DiscountEventDto not enrolled at view; input : " + discountEvent); + } + return DISCOUNT_EVENT_TO_MESSAGE.get(discountEvent); + } + + public static String findGiftEventView() { + return GIFT_EVENT_MESSAGE; + } +}
Java
๋ณ€๊ฒฝ ํฌ์ธํŠธ๊ฐ€ ๋Š˜์–ด๋‚œ๋‹ค๋Š” ์ , ํฅ๋ฏธ๋กญ๋„ค์š”. ํ™•์‹คํžˆ ์ •์ฑ…์ด ํ•˜๋‚˜ ๋” ์ถ”๊ฐ€๋œ๋‹ค๋ฉด, enum์—๋„ ์ถ”๊ฐ€ํ•˜๊ณ  BenefitDetailView์—๋„ ์ถ”๊ฐ€๋˜์–ด์•ผ ํ•˜๋‹ˆ ์ข€ ๊ทธ๋ ‡๋„ค์š”. ์ด๊ฑธ ๊ตฌํ˜„ํ•  ๋•Œ ์ œ ์ƒ๊ฐ์€ ์ด๋žฌ์Šต๋‹ˆ๋‹ค. > ๋งŒ์•ฝ์— "ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ"์ด๋ผ๋Š” ์ถœ๋ ฅ ํ…์ŠคํŠธ๋ฅผ "ํฌ๋ฆฌ์Šค๋งˆ์Šค D-day ํ• ์ธ"์œผ๋กœ ์ˆ˜์ •ํ•œ๋‹ค๊ณ  ํ•˜๋ฉด, ํ•ด๋‹น ์ฝ”๋“œ๋Š” ์–ด๋””์— ์žˆ์–ด์•ผ ํ• ๊นŒ? ์ด ์งˆ๋ฌธ์—์„œ ์ถœ๋ฐœํ–ˆ์Šต๋‹ˆ๋‹ค. ์ €๋Š” '์ถœ๋ ฅ ํ˜•์‹์„ ์ˆ˜์ •'ํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— view package์— ์žˆ์–ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ์ถœ๋ ฅ ํ˜•์‹์ด ๋„๋ฉ”์ธ์— ๋”ฐ๋ผ ์—ฌ๊ธฐ ์ €๊ธฐ์— ํผ์ ธ์žˆ๋Š” ๊ฒƒ๋„ ์ˆ˜์ •ํ•˜๋Š”๋ฐ ๋ณ„๋กœ๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ด ๋ถ€๋ถ„์€ ์•ž์œผ๋กœ ์–ด๋–ป๊ฒŒ ๋ณ€๊ฒฝ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋Š”์ง€์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ๊ตฌํ˜„ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,33 @@ +import letters from "../mockData"; + +const sleep = n => new Promise(resolve => setTimeout(resolve, n)); + +export const getLetters = async () => { + await sleep(500); + return letters; +}; + +export const getLetterById = async id => { + await sleep(100); + return letters.find(letter => letter.id === id); +}; + +export const updateLetter = async (id, payload) => { + await sleep(100); + const { title, artist, imageUrl } = payload; + const songStory = payload.songStory; + + const foundLetter = letters.find(letter => letter.id === id); + + const updatedLetter = { + ...foundLetter, + song: { title, artist, imageUrl }, + songStory + }; + + const index = letters.indexOf(foundLetter); + letters.splice(index, 1); + letters.push(updatedLetter); + + return updatedLetter; +};
JavaScript
๋ฐฐ์—ด์—์„œ ์›ํ•˜๋Š” ์กฐ๊ฑด๊นŒ์ง€๋งŒ ์ฐพ๋Š” find method๋ฅผ ์‚ฌ์šฉํ•œ ๊ฑด ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค !
@@ -0,0 +1,24 @@ +import React from "react"; +import styled from "styled-components"; + +const Footer = () => { + return ( + <FooterBlock> + <p className="copyright">&copy; Museop Kim</p> + </FooterBlock> + ); +}; + +const FooterBlock = styled.div` + display: flex; + justify-content: center; + align-items: center; + width: 100%; + height: 8rem; + margin-top: 6rem; + background-color: #f5f5f7; + font-weight: 500; + box-shadow: 0px -10px 35px 5px #f1f1f1; +`; + +export default Footer;
Unknown
style components๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋‹ˆ๊นŒ `box-shadow: 0px -10px 35px 5px #f1f1f1;` ๋ถ€๋ถ„์˜ ์ƒ‰์ƒ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” styled-components ThemeProvider๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”. ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ „๋‹ฌ๋ฐ›์€ ์ƒ‰์ƒ์„ ๋™์ผํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋ฉด ๋‹คํฌ๋ชจ๋“œ์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ• ๋•Œ๋„ ์†์‰ฝ๊ฒŒ ์Šคํƒ€์ผ ๋ณ€๋™์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๋„ˆ๋ฌด ๋งŽ์ด ์ง„ํ–‰๋œ ํ”„๋กœ์ ํŠธ๋Š” ์Šคํƒ€์ผ ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•˜๊ธฐ ์‰ฝ์ง€ ์•Š์œผ๋‹ˆ๊นŒ ์ข€ ์ž‘์€ ๋‹จ์œ„์ผ ๋•Œ ์‹œ๋„ํ•ด ๋ณด๋Š”๊ฒƒ๋„ ์ข‹์„๊ฑฐ ๊ฐ™์•„์š” ๐Ÿ˜‰
@@ -0,0 +1,47 @@ +import React from "react"; +import styled from "styled-components"; +import { Link } from "react-router-dom"; + +const Navigation = () => { + return ( + <NavigationBlock> + <Link to="/">์‹ ์ฒญ๊ณก</Link> + <Link to="/ranking">์‹ ์ฒญ๊ณก ์ˆœ์œ„</Link> + <Link to="/contents">์‹ ์ฒญ๊ณก ์œ ํŠœ๋ธŒ ์˜์ƒ</Link> + <Link to="/musicsheets">๋ฆฌ์–ผํ”ผ์•„๋…ธ ์•…๋ณด์ง‘</Link> + </NavigationBlock> + ); +}; + +const NavigationBlock = styled.div` + height: 100%; + display: flex; + align-items: center; + + & > * { + /* padding: 25px 5px 10px 5px; */ + box-sizing: border-box; + display: flex; + align-items: center; + margin: 0px 30px; + padding-top: 10px; + font-size: 1.2rem; + font-weight: 600; + text-decoration: none; + align-self: center; + color: inherit; + opacity: 0.5; + height: 100%; + /* border-bottom: 1px solid rgba(0, 0, 0, 0); */ + border-bottom: 3px solid rgba(250, 162, 193, 0); + transition: 0.3s; + + :hover { + opacity: 1; + /* color: #faa2c1; */ + border-bottom: 3px solid rgba(250, 162, 193, 1); + } + } +`; + +export default Navigation;
Unknown
ํฐํŠธ์™€ ๊ฐ™์ด ๋ฐ˜์‘ํ˜•์— ์˜ํ–ฅ์„ ๋ฐ›์•„์•ผ ํ•˜๋Š” ๊ธฐ์ค€๊ณผ ๊ทธ๋ ‡์ง€ ์•Š์€ ์š”์†Œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ px๊ณผ rem์„ ์‚ฌ์šฉํ•˜์‹œ๋Š” ๊ฑด๊ฐ€์š” ? ๊ทธ๋Ÿฐ ์˜๋„๋ผ๋ฉด ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค.
@@ -0,0 +1,147 @@ +import React from "react"; +import styled from "styled-components"; + +const MAX_LENGTH = 100; + +const Letter = ({ + id, + user, + song, + songStory, + createdDateTime, + onReadLetter +}) => { + const { username, avatarUrl } = user; + const { title, artist, imageUrl } = song; + + return ( + <> + <LetterBlock onClick={() => onReadLetter(id)}> + <SongBlock> + <img src={imageUrl} alt="ALBUM IMAGE" className="album-image" /> + <div className="song-about"> + <span className="song-about__title">{title}</span> + <span className="song-about__artist">{artist}</span> + </div> + </SongBlock> + <SongStory> + {songStory.length > MAX_LENGTH + ? `${songStory.slice(0, MAX_LENGTH)} ...` + : songStory} + </SongStory> + <UserBlock> + <div className="created-time">{createdDateTime}</div> + <div className="user-about"> + <img src={avatarUrl} className="user-about__avatar" /> + <span className="user-about__name">{username}</span> + </div> + </UserBlock> + </LetterBlock> + </> + ); +}; + +const LetterBlock = styled.li` + width: 25rem; + height: 23rem; + margin: 1.2rem; + margin-bottom: 5rem; + box-sizing: border-box; + display: flex; + flex-direction: column; + padding: 0.7rem; + border: #ffdeeb; + border-radius: 0.5rem; + cursor: pointer; + transition: 0.3s; + box-shadow: 0 13px 27px -5px rgba(50, 50, 93, 0.2), + 0 8px 16px -8px rgba(0, 0, 0, 0.2), 0 -6px 16px -6px rgba(0, 0, 0, 0.025); + + &:hover { + box-shadow: 0px 25px 30px 3px rgba(0, 0, 0, 0.3); + } + + .album-image { + width: 10rem; + height: 10rem; + } +`; + +const SongBlock = styled.div` + display: flex; + justify-content: space-between; + + .album-image { + position: relative; + top: -2.5rem; + box-shadow: 3px 2px 5px 1px rgba(0, 0, 0, 0.3); + border-radius: 5px; + } + + .song-about { + display: flex; + flex-direction: column; + justify-content: center; + margin-right: auto; + margin-left: 2rem; + + .song-about__title { + overflow-x: hidden; + font-size: 1.4rem; + font-weight: 500; + color: #2c2c2c; + opacity: 0.9; + } + + .song-about__artist { + margin-top: 0.5rem; + font-size: 1.2rem; + opacity: 0.8; + } + } +`; + +const SongStory = styled.p` + width: 100%; + max-height: 8rem; + line-break: anywhere; + margin-top: -0.3rem; + font-size: 1.2rem; + line-height: 1.9rem; + opacity: 0.9; + padding: 0rem 0.5rem; +`; + +const UserBlock = styled.div` + display: flex; + justify-content: space-between; + align-items: center; + margin: auto 5px 3px 5px; + + .created-time { + font-size: 1.1rem; + margin-top: 0.8rem; + opacity: 0.7; + } + + .user-about { + display: flex; + align-items: center; + } + + .user-about__avatar { + max-width: 2.5rem; + max-height: 2.5rem; + border-radius: 50%; + box-shadow: 3px 2px 10px 1px rgba(0, 0, 0, 0.3); + } + + .user-about__name { + font-size: 1.1rem; + margin-top: 0.5rem; + margin-left: 0.5rem; + opacity: 0.8; + } +`; + +export default Letter;
Unknown
className ์ปจ๋ฒค์…˜ ์ค‘ "-"์™€ "_"๋Š” ์–ด๋–ค ๊ธฐ์ค€์ด ์žˆ์„๊นŒ์š” ? ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค ใ…Ž
@@ -0,0 +1,29 @@ +import React from "react"; +import styled from "styled-components"; +import LetterContainer from "../../containers/Letter/LetterContainer"; + +const LetterList = ({ letters }) => { + return ( + <LetterListBlock> + {letters.map(letter => ( + <LetterContainer + key={letter.id} + id={letter.id} + user={letter.user} + song={letter.song} + songStory={letter.songStory} + createdDateTime={letter.createdDateTime} + /> + ))} + </LetterListBlock> + ); +}; + +const LetterListBlock = styled.ul` + width: 100%; + display: flex; + flex-wrap: wrap; + margin-top: 4.5rem; +`; + +export default LetterList;
Unknown
๋ณดํ†ต Container๋Š” ์ข€ ๋” ํฐ ๋‹จ์œ„์—์„œ์˜ ์˜๋ฏธ์—์„œ ์‚ฌ์šฉ๋˜๊ณค ํ•˜๋Š”๊ฑฐ ๊ฐ™์•„์š”. ์—ฌ๋Ÿฌ ์ž์‹ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ง€๊ณ  ๋งŽ์€ ์ด๋ฒคํŠธ ๋กœ์ง์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์„ผํ„ฐ์˜ ๋А๋‚Œ์œผ๋กœ ๋„ค์ด๋ฐ์„ ํ•˜๊ณค ํ•˜๋Š”๋ฐ LetterList๋ฉด LetterItem๊ณผ ๊ฐ™์ด ๋‹จ์ผํ•˜๊ฒŒ ํ‘œํ˜„ํ•ด ์ฃผ๋Š”๊ฒƒ๋„ ์ข‹์„๊ฑฐ ๊ฐ™์•„์š” !
@@ -0,0 +1,30 @@ +import React, { useEffect, useState } from "react"; +import ModalTemplate from "../Template/Modal/ModalTemplate"; +import LetterDetailsSong from "./LetterDetailsSong"; +import LetterDetailsSongStory from "./LetterDetailsSongStory"; +import LetterModalTemplate from "../Template/LetterModal/LetterModalTemplate"; +import LetterDetailsUser from "./LetterDetailsUser"; +import LetterModalDiv from "../LetterModal/LetterModalContents/LetterModalDiv"; +import LetterModalHiddenButtonContainer from "../../containers/LetterModal/LetterModalHiddenButtonContainer"; +import LetterModalButtonContainer from "../../containers/LetterModal/LetterModalButtonContainer"; +import { useSelector } from "react-redux"; + +const LetterDetails = ({ letter }) => { + const { song, songStory, createdDateTime, user } = letter; + + return ( + <ModalTemplate> + <LetterModalTemplate> + <LetterModalHiddenButtonContainer /> + <LetterModalDiv> + <LetterDetailsSong song={song} /> + <LetterDetailsSongStory songStory={songStory} /> + <LetterDetailsUser user={user} createdDateTime={createdDateTime} /> + <LetterModalButtonContainer /> + </LetterModalDiv> + </LetterModalTemplate> + </ModalTemplate> + ); +}; + +export default LetterDetails;
Unknown
`const { song, songStory, createdDateTime, user } = letter;` ๋„ˆ๋ฌด ๋งŽ์€ ์–‘์˜ ๊ฐ์ฒด Props๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด ์ด ๋ถ€๋ถ„ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ๊ฐ๊ฐ ์ด๋ฆ„์„ ๊ฐ€์ง„ Props๋กœ ์ „๋‹ฌํ•ด ์ฃผ๋Š”๊ฒƒ๋„ ์ข‹์„๊ฑฐ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค! ๊ทธ๋Ÿฌ๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ ์ปดํฌ๋„ŒํŠธ์— ์ง์ ‘ ๋“ค์–ด์™€ ๋ณด์ง€ ์•Š์•„๋„ ์ „๋‹ฌ๋˜๋Š” Props ๋งŒ์œผ๋กœ ์—ญํ• ์„ ์œ ์ถ”ํ•ด ๋ณผ ์ˆ˜ ์žˆ์„๊ฑฐ ๊ฐ™์•„์š”.
@@ -0,0 +1,45 @@ +import React, { useEffect } from "react"; +import { MdMoreHoriz } from "react-icons/md"; +import styled, { css } from "styled-components"; +import LetterDetailsHiddenMenuButton from "./LetterDetailsHiddenMenuButton"; + +const LetterDetailsHiddenMenu = ({ + isMouseEnter, + isMenuOpen, + onToggle, + changeToEdit +}) => { + return ( + <ButtonBlock isMouseEnter={isMouseEnter} onClick={onToggle}> + <HiddenMenu /> + {isMenuOpen && ( + <LetterDetailsHiddenMenuButton changeToEdit={changeToEdit} /> + )} + </ButtonBlock> + ); +}; + +const ButtonBlock = styled.div` + ${props => + props.isMouseEnter + ? css` + visibility: visible; + opacity: 1; + ` + : css` + visibility: hidden; + opacity: 0; + `} + transition: 0.7s; +`; + +const HiddenMenu = styled(MdMoreHoriz)` + position: absolute; + bottom: 93%; + right: 3%; + cursor: pointer; + font-size: 2.1rem; + color: gray; +`; + +export default LetterDetailsHiddenMenu;
Unknown
visibility: hidden; , display : none ์˜ ์ฐจ์ด๋ฅผ ์•„์‹œ๋‚˜์š” ? ใ…Žใ…Ž ๋ชจ๋ฅด๊ณ  ๊ณ„์‹ ๋‹ค๋ฉด ํ•œ๋ฒˆ ์•Œ์•„๋ณด๋Š”๊ฒƒ๋„ ์ข‹์Šต๋‹ˆ๋‹ค ! ๋Œ€๋‹จํ•œ๊ฑด ์•„๋‹ˆ๊ณ  ๊ทธ๋ƒฅ DOM ํŠธ๋ฆฌ์™€ ๊ด€๋ จ๋œ ๋‚ด์šฉ์ด์—์š”.
@@ -0,0 +1,28 @@ +import React from "react"; +import LetterModalSong from "../LetterModal/LetterModalSong/LetterModalSong"; +import SongAbout from "../LetterModal/LetterModalSong/SongAbout"; +import SongArticle from "../LetterModal/LetterModalSong/SongArticle"; +import SongArticleItem from "../LetterModal/LetterModalSong/SongArticleItem"; +import SongArticleName from "../LetterModal/LetterModalSong/SongArticleName"; +import SongImage from "../LetterModal/LetterModalSong/SongImage"; + +const LetterDetailsSong = ({ song }) => { + const { title, artist, imageUrl } = song; + return ( + <LetterModalSong> + <SongImage imageUrl={imageUrl} /> + <SongAbout> + <SongArticle> + <SongArticleName articleName={"TITLE"} /> + <SongArticleItem articleName={"TITLE"} item={title} /> + </SongArticle> + <SongArticle> + <SongArticleName articleName={"ARTIST"} /> + <SongArticleItem articleName={"ARTIST"} item={artist} /> + </SongArticle> + </SongAbout> + </LetterModalSong> + ); +}; + +export default LetterDetailsSong;
Unknown
์ด ๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ๋ฐ˜๋ณต๋˜๋Š” ์ปดํฌ๋„ŒํŠธ๋กœ ๋ณด์ด๋Š”๋ฐ ์ด๊ฑธ ํ•˜๋‚˜๋กœ ๋ฌถ์–ด์„œ ๊ด€๋ฆฌํ•ด ๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š” ? <SongArticle> <SongArticleName articleName={"TITLE"} /> <SongArticleItem articleName={"TITLE"} item={title} /> </SongArticle>
@@ -0,0 +1,48 @@ +import React from "react"; +import styled from "styled-components"; +import { BiSearch } from "react-icons/bi"; +import useModal from "../../hooks/useModal"; +import SongSearchModal from "./SongSearchModal/SongSearchModal"; + +const LetterEditorSearchButton = () => { + const [isOpened, onOpenModal, onCloseModal] = useModal(); + + return ( + <> + <StyledButton onClick={onOpenModal}> + <SearchIcon /> + ์‹ ์ฒญ๊ณก ๊ฒ€์ƒ‰ + </StyledButton> + <SongSearchModal isOpened={isOpened} onCloseModal={onCloseModal} /> + </> + ); +}; + +const StyledButton = styled.div` + display: flex; + justify-content: center; + align-items: center; + position: absolute; + width: 11rem; + top: 14%; + right: 15%; + + padding: 0.35rem 0rem; + border-style: none; + border-radius: 0.5rem; + font-size: 1.2rem; + background-color: #f06595; + box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 0.15); + color: #fff; + font-weight: 500; + z-index: 1; + cursor: pointer; +`; + +const SearchIcon = styled(BiSearch)` + font-size: 1.35rem; + margin-right: 0.35rem; + opacity: 0.9; +`; + +export default LetterEditorSearchButton;
Unknown
modal๊ณผ ๊ด€๋ จ๋œ ๋™์ž‘์„ custom hook์œผ๋กœ ์‚ฌ์šฉํ•œ ๋ถ€๋ถ„ ์ข‹์•„ ๋ณด์ž…๋‹ˆ๋‹ค !
@@ -0,0 +1,108 @@ +import React from "react"; +import styled from "styled-components"; +import { BiSearch } from "react-icons/bi"; +import { useDispatch } from "react-redux"; +import { searchSong } from "../../../modules/song"; + +const SearchForm = ({ onCloseModal }) => { + const dispatch = useDispatch(); + + const onSearchSong = event => { + event.preventDefault(); + dispatch(searchSong()); + }; + + return ( + <Form> + <SearchInputWrap> + <SearchLabel>์•„ํ‹ฐ์ŠคํŠธ</SearchLabel> + <SearchInput type="text" name="artist" /> + </SearchInputWrap> + <SearchInputWrap> + <SearchLabel>์ œ๋ชฉ</SearchLabel> + <SearchInput type="text" name="title" /> + </SearchInputWrap> + <SearchButton type="submit" onClick={onSearchSong}> + <SearchIcon /> + </SearchButton> + </Form> + ); +}; + +const Form = styled.form` + box-sizing: border-box; + width: 95%; + display: flex; + justify-content: center; + margin: 0rem auto 3.5rem auto; +`; + +const SearchLabel = styled.span` + display: flex; + align-items: center; + position: absolute; + top: 0rem; + left: 0rem; + height: 2.37rem; + font-size: 1rem; + background-color: #727272; + padding: 0rem 0.7rem; + border-radius: 0.3rem 0rem 0rem 0.3rem; + color: white; + font-weight: 600; + box-shadow: 1px 0px 3px 1px rgba(0, 0, 0, 0.1); +`; + +const SearchInput = styled.input` + border: none; + outline: none; + color: #868e96; + width: 100%; + margin: 0rem 0.5rem 0rem 5.5rem; + font-size: 1.2rem; + background-color: #fbfbfd; +`; + +const SearchInputWrap = styled.div` + display: flex; + align-items: center; + position: relative; + border: 1px solid #e9ecef; + border-radius: 1rem 0rem 0rem 1rem; + padding: 0.1rem 0rem; + background: #fbfbfd; + height: 2.1rem; + flex: 11; + + &:nth-child(2) { + & > ${SearchLabel} { + border-radius: 0.2rem; + margin-left: -0.25rem; + } + + & > ${SearchInput} { + margin-left: 3.8rem; + } + } +`; + +const SearchButton = styled.button` + display: flex; + position: relative; + justify-content: center; + align-items: center; + border: none; + outline: none; + cursor: pointer; + background-color: #e1999c; + border-radius: 0rem 0.5rem 0.5rem 0rem; + flex: 1; + box-shadow: 1px 0px 3px 1px rgba(0, 0, 0, 0.1); +`; + +const SearchIcon = styled(BiSearch)` + color: #fff; + font-size: 1.4rem; +`; + +export default SearchForm;
Unknown
Form์ด ์ ์  ๋” ๋ณต์žกํ•œ ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๋ฉด ๊ด€๋ฆฌ๊ฐ€ ์‰ฝ์ง€ ์•Š์€๋ฐ ๊ทธ๋Ÿด๋• https://react-hook-form.com/ ์œ„์™€ ๊ฐ™์€ ๋„๊ตฌ๋ฅผ ๋„์ž…ํ•ด ๋ณผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค ใ…Ž
@@ -0,0 +1,24 @@ +import React from "react"; +import styled from "styled-components"; + +const Footer = () => { + return ( + <FooterBlock> + <p className="copyright">&copy; Museop Kim</p> + </FooterBlock> + ); +}; + +const FooterBlock = styled.div` + display: flex; + justify-content: center; + align-items: center; + width: 100%; + height: 8rem; + margin-top: 6rem; + background-color: #f5f5f7; + font-weight: 500; + box-shadow: 0px -10px 35px 5px #f1f1f1; +`; + +export default Footer;
Unknown
์ปดํฌ๋„ŒํŠธ๋ฅผ ์žฌ์‚ฌ์šฉ ํ•˜๋“ฏ์ด ์Šคํƒ€์ผ๋„ ์—ฌ๋Ÿฌ ๊ณณ์— ์žฌ์‚ฌ์šฉ ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ๋„ค์š”. `ThemeProvider`์— ๋Œ€ํ•ด ์ž˜ ๋ชฐ๋ž๋Š”๋ฐ ์ด๋ฒˆ ๊ธฐํšŒ์— ํ•œ๋ฒˆ ํ•™์Šต ํ•ด๋ณด๊ณ  ํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ ์šฉ๊นŒ์ง€ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ์กฐ์–ธ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ‘
@@ -0,0 +1,47 @@ +import React from "react"; +import styled from "styled-components"; +import { Link } from "react-router-dom"; + +const Navigation = () => { + return ( + <NavigationBlock> + <Link to="/">์‹ ์ฒญ๊ณก</Link> + <Link to="/ranking">์‹ ์ฒญ๊ณก ์ˆœ์œ„</Link> + <Link to="/contents">์‹ ์ฒญ๊ณก ์œ ํŠœ๋ธŒ ์˜์ƒ</Link> + <Link to="/musicsheets">๋ฆฌ์–ผํ”ผ์•„๋…ธ ์•…๋ณด์ง‘</Link> + </NavigationBlock> + ); +}; + +const NavigationBlock = styled.div` + height: 100%; + display: flex; + align-items: center; + + & > * { + /* padding: 25px 5px 10px 5px; */ + box-sizing: border-box; + display: flex; + align-items: center; + margin: 0px 30px; + padding-top: 10px; + font-size: 1.2rem; + font-weight: 600; + text-decoration: none; + align-self: center; + color: inherit; + opacity: 0.5; + height: 100%; + /* border-bottom: 1px solid rgba(0, 0, 0, 0); */ + border-bottom: 3px solid rgba(250, 162, 193, 0); + transition: 0.3s; + + :hover { + opacity: 1; + /* color: #faa2c1; */ + border-bottom: 3px solid rgba(250, 162, 193, 1); + } + } +`; + +export default Navigation;
Unknown
์ฒ˜์Œ์—๋Š” ๋ง์”€ ํ•˜์‹  ๊ฒƒ์ฒ˜๋Ÿผ px๊ณผ rem์„ ๊ตฌ๋ถ„ํ•ด์„œ ์‚ฌ์šฉ ํ•˜๋‹ค๊ฐ€ ์ƒ๋Œ€ ๊ฐ’์ธ rem์œผ๋กœ ๋‹จ์œ„๋ฅผ ํ†ต์ผํ•˜๊ณ  ์ ์šฉ ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ˜น์‹œ ์ด๋ ‡๊ฒŒ ํ•  ๊ฒฝ์šฐ ์ฃผ์˜ํ•ด์•ผ ๋  ๊ณ ๋ ค์‚ฌํ•ญ ๊ฐ™์€๊ฒŒ ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,147 @@ +import React from "react"; +import styled from "styled-components"; + +const MAX_LENGTH = 100; + +const Letter = ({ + id, + user, + song, + songStory, + createdDateTime, + onReadLetter +}) => { + const { username, avatarUrl } = user; + const { title, artist, imageUrl } = song; + + return ( + <> + <LetterBlock onClick={() => onReadLetter(id)}> + <SongBlock> + <img src={imageUrl} alt="ALBUM IMAGE" className="album-image" /> + <div className="song-about"> + <span className="song-about__title">{title}</span> + <span className="song-about__artist">{artist}</span> + </div> + </SongBlock> + <SongStory> + {songStory.length > MAX_LENGTH + ? `${songStory.slice(0, MAX_LENGTH)} ...` + : songStory} + </SongStory> + <UserBlock> + <div className="created-time">{createdDateTime}</div> + <div className="user-about"> + <img src={avatarUrl} className="user-about__avatar" /> + <span className="user-about__name">{username}</span> + </div> + </UserBlock> + </LetterBlock> + </> + ); +}; + +const LetterBlock = styled.li` + width: 25rem; + height: 23rem; + margin: 1.2rem; + margin-bottom: 5rem; + box-sizing: border-box; + display: flex; + flex-direction: column; + padding: 0.7rem; + border: #ffdeeb; + border-radius: 0.5rem; + cursor: pointer; + transition: 0.3s; + box-shadow: 0 13px 27px -5px rgba(50, 50, 93, 0.2), + 0 8px 16px -8px rgba(0, 0, 0, 0.2), 0 -6px 16px -6px rgba(0, 0, 0, 0.025); + + &:hover { + box-shadow: 0px 25px 30px 3px rgba(0, 0, 0, 0.3); + } + + .album-image { + width: 10rem; + height: 10rem; + } +`; + +const SongBlock = styled.div` + display: flex; + justify-content: space-between; + + .album-image { + position: relative; + top: -2.5rem; + box-shadow: 3px 2px 5px 1px rgba(0, 0, 0, 0.3); + border-radius: 5px; + } + + .song-about { + display: flex; + flex-direction: column; + justify-content: center; + margin-right: auto; + margin-left: 2rem; + + .song-about__title { + overflow-x: hidden; + font-size: 1.4rem; + font-weight: 500; + color: #2c2c2c; + opacity: 0.9; + } + + .song-about__artist { + margin-top: 0.5rem; + font-size: 1.2rem; + opacity: 0.8; + } + } +`; + +const SongStory = styled.p` + width: 100%; + max-height: 8rem; + line-break: anywhere; + margin-top: -0.3rem; + font-size: 1.2rem; + line-height: 1.9rem; + opacity: 0.9; + padding: 0rem 0.5rem; +`; + +const UserBlock = styled.div` + display: flex; + justify-content: space-between; + align-items: center; + margin: auto 5px 3px 5px; + + .created-time { + font-size: 1.1rem; + margin-top: 0.8rem; + opacity: 0.7; + } + + .user-about { + display: flex; + align-items: center; + } + + .user-about__avatar { + max-width: 2.5rem; + max-height: 2.5rem; + border-radius: 50%; + box-shadow: 3px 2px 10px 1px rgba(0, 0, 0, 0.3); + } + + .user-about__name { + font-size: 1.1rem; + margin-top: 0.5rem; + margin-left: 0.5rem; + opacity: 0.8; + } +`; + +export default Letter;
Unknown
์ปดํฌ๋„ŒํŠธ ์ด์™ธ์— className์„ ์ง์ ‘ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ๋Œ€๋ถ€๋ถ„ CSS ๋„ค์ด๋ฐ ์ปจ๋ฒค์…˜์œผ๋กœ ์•Œ๋ ค์ง„ `BEM` ์„ ์ ์šฉ ํ–ˆ์Šต๋‹ˆ๋‹คใ…Žใ…Ž `-`๋Š” ๋‘ ๋‹จ์–ด๋ฅผ ์—ฐ๊ฒฐํ•ด์•ผ ํ•  ๋•Œ, `__`๋Š” ํŠน์ • ๋ธ”๋Ÿญ์„ ๊ตฌ์„ฑํ•˜๋Š” ํ•˜์œ„ ์š”์†Œ๋ฅผ ๊ตฌ๋ถ„ํ•  ๋•Œ ์‚ฌ์šฉ ํ–ˆ๋˜ ๋“ฏ ํ•˜๋„ค์š”. [CSS BEM](https://css-tricks.com/bem-101/) ์„ ์ฐธ๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค :)
@@ -0,0 +1,29 @@ +import React from "react"; +import styled from "styled-components"; +import LetterContainer from "../../containers/Letter/LetterContainer"; + +const LetterList = ({ letters }) => { + return ( + <LetterListBlock> + {letters.map(letter => ( + <LetterContainer + key={letter.id} + id={letter.id} + user={letter.user} + song={letter.song} + songStory={letter.songStory} + createdDateTime={letter.createdDateTime} + /> + ))} + </LetterListBlock> + ); +}; + +const LetterListBlock = styled.ul` + width: 100%; + display: flex; + flex-wrap: wrap; + margin-top: 4.5rem; +`; + +export default LetterList;
Unknown
Container๋ฅผ ์–ธ์ œ ์‚ฌ์šฉํ•ด์•ผ ํ•  ์ง€ ๋ช…ํ™•ํ•œ ๊ธฐ์ค€์ด ์—†์—ˆ๋Š”๋ฐ, ๋ฆฌ๋ทฐ ํ•ด์ฃผ์‹  ๋‚ด์šฉ์„ ๋ณด๊ณ  ๊ณ ๋ฏผ ๋˜๋˜ ๊ฒƒ๋“ค์ด ๋งŽ์ด ๋œ์–ด์ง€๋Š” ๋А๋‚Œ์ด์—์š”. ๋‹ค์Œ ์ˆ˜์ • ๋•Œ ๋ฐ˜์˜ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ™‚
@@ -0,0 +1,30 @@ +import React, { useEffect, useState } from "react"; +import ModalTemplate from "../Template/Modal/ModalTemplate"; +import LetterDetailsSong from "./LetterDetailsSong"; +import LetterDetailsSongStory from "./LetterDetailsSongStory"; +import LetterModalTemplate from "../Template/LetterModal/LetterModalTemplate"; +import LetterDetailsUser from "./LetterDetailsUser"; +import LetterModalDiv from "../LetterModal/LetterModalContents/LetterModalDiv"; +import LetterModalHiddenButtonContainer from "../../containers/LetterModal/LetterModalHiddenButtonContainer"; +import LetterModalButtonContainer from "../../containers/LetterModal/LetterModalButtonContainer"; +import { useSelector } from "react-redux"; + +const LetterDetails = ({ letter }) => { + const { song, songStory, createdDateTime, user } = letter; + + return ( + <ModalTemplate> + <LetterModalTemplate> + <LetterModalHiddenButtonContainer /> + <LetterModalDiv> + <LetterDetailsSong song={song} /> + <LetterDetailsSongStory songStory={songStory} /> + <LetterDetailsUser user={user} createdDateTime={createdDateTime} /> + <LetterModalButtonContainer /> + </LetterModalDiv> + </LetterModalTemplate> + </ModalTemplate> + ); +}; + +export default LetterDetails;
Unknown
๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ๊ฐ์ฒด ์ž์ฒด๋ฅผ ๋„˜๊ธฐ๋Š” ๊ฒƒ์ด ์—ฌ๋Ÿฌ ์ธก๋ฉด์—์„œ ๋” ์ข‹์„๊ฑฐ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด์—ˆ๋Š”๋ฐ, ์•„๋‹Œ ๊ฒฝ์šฐ๋„ ์žˆ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“œ๋„ค์š”! ์ˆ˜์ •ํ•  ๋•Œ ๋ฐ˜์˜ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ‘
@@ -0,0 +1,45 @@ +import React, { useEffect } from "react"; +import { MdMoreHoriz } from "react-icons/md"; +import styled, { css } from "styled-components"; +import LetterDetailsHiddenMenuButton from "./LetterDetailsHiddenMenuButton"; + +const LetterDetailsHiddenMenu = ({ + isMouseEnter, + isMenuOpen, + onToggle, + changeToEdit +}) => { + return ( + <ButtonBlock isMouseEnter={isMouseEnter} onClick={onToggle}> + <HiddenMenu /> + {isMenuOpen && ( + <LetterDetailsHiddenMenuButton changeToEdit={changeToEdit} /> + )} + </ButtonBlock> + ); +}; + +const ButtonBlock = styled.div` + ${props => + props.isMouseEnter + ? css` + visibility: visible; + opacity: 1; + ` + : css` + visibility: hidden; + opacity: 0; + `} + transition: 0.7s; +`; + +const HiddenMenu = styled(MdMoreHoriz)` + position: absolute; + bottom: 93%; + right: 3%; + cursor: pointer; + font-size: 2.1rem; + color: gray; +`; + +export default LetterDetailsHiddenMenu;
Unknown
`display: none`์€ DOM์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๋Š” ๋ฐ˜๋ฉด `visibility: hidden` ์€ DOM์— ์˜ํ–ฅ์„ ์ฃผ๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ  ์žˆ์—ˆ์–ด์š”ใ…Žใ…Ž `transition` ์€ `display: none`์—์„œ ์ž‘๋™ํ•˜์ง€ ์•Š์•„์„œ `visibility` ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋๋Š”๋ฐ, ํ˜น์‹œ ์ปจ๋ฒค์…˜์ด ๋”ฐ๋กœ ์žˆ๋‹ค๊ฑฐ๋‚˜ ๋” ํšจ์œจ์ ์ธ ๋ฐฉ๋ฒ•์ด ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,28 @@ +import React from "react"; +import LetterModalSong from "../LetterModal/LetterModalSong/LetterModalSong"; +import SongAbout from "../LetterModal/LetterModalSong/SongAbout"; +import SongArticle from "../LetterModal/LetterModalSong/SongArticle"; +import SongArticleItem from "../LetterModal/LetterModalSong/SongArticleItem"; +import SongArticleName from "../LetterModal/LetterModalSong/SongArticleName"; +import SongImage from "../LetterModal/LetterModalSong/SongImage"; + +const LetterDetailsSong = ({ song }) => { + const { title, artist, imageUrl } = song; + return ( + <LetterModalSong> + <SongImage imageUrl={imageUrl} /> + <SongAbout> + <SongArticle> + <SongArticleName articleName={"TITLE"} /> + <SongArticleItem articleName={"TITLE"} item={title} /> + </SongArticle> + <SongArticle> + <SongArticleName articleName={"ARTIST"} /> + <SongArticleItem articleName={"ARTIST"} item={artist} /> + </SongArticle> + </SongAbout> + </LetterModalSong> + ); +}; + +export default LetterDetailsSong;
Unknown
์ปดํฌ๋„ŒํŠธ๋ฅผ ์™„์ „ํžˆ ๋‹ค ๋ถ„๋ฆฌ ํ•œ ๋’ค์— ํ•œ๋ฒˆ ๋” ์ •๋ฆฌ๋ฅผ ํ–ˆ์–ด์•ผ ํ•˜๋Š”๋ฐ ์ด๋Ÿฐ ์ค‘๋ณต์€ ๋ฌถ์–ด์„œ ์ค„์ด๋Š”๊ฒŒ ์ข‹์„๊ฑฐ ๊ฐ™์•„์š”. ๋ฐ˜์˜ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์•Œ๋ ค์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,108 @@ +import React from "react"; +import styled from "styled-components"; +import { BiSearch } from "react-icons/bi"; +import { useDispatch } from "react-redux"; +import { searchSong } from "../../../modules/song"; + +const SearchForm = ({ onCloseModal }) => { + const dispatch = useDispatch(); + + const onSearchSong = event => { + event.preventDefault(); + dispatch(searchSong()); + }; + + return ( + <Form> + <SearchInputWrap> + <SearchLabel>์•„ํ‹ฐ์ŠคํŠธ</SearchLabel> + <SearchInput type="text" name="artist" /> + </SearchInputWrap> + <SearchInputWrap> + <SearchLabel>์ œ๋ชฉ</SearchLabel> + <SearchInput type="text" name="title" /> + </SearchInputWrap> + <SearchButton type="submit" onClick={onSearchSong}> + <SearchIcon /> + </SearchButton> + </Form> + ); +}; + +const Form = styled.form` + box-sizing: border-box; + width: 95%; + display: flex; + justify-content: center; + margin: 0rem auto 3.5rem auto; +`; + +const SearchLabel = styled.span` + display: flex; + align-items: center; + position: absolute; + top: 0rem; + left: 0rem; + height: 2.37rem; + font-size: 1rem; + background-color: #727272; + padding: 0rem 0.7rem; + border-radius: 0.3rem 0rem 0rem 0.3rem; + color: white; + font-weight: 600; + box-shadow: 1px 0px 3px 1px rgba(0, 0, 0, 0.1); +`; + +const SearchInput = styled.input` + border: none; + outline: none; + color: #868e96; + width: 100%; + margin: 0rem 0.5rem 0rem 5.5rem; + font-size: 1.2rem; + background-color: #fbfbfd; +`; + +const SearchInputWrap = styled.div` + display: flex; + align-items: center; + position: relative; + border: 1px solid #e9ecef; + border-radius: 1rem 0rem 0rem 1rem; + padding: 0.1rem 0rem; + background: #fbfbfd; + height: 2.1rem; + flex: 11; + + &:nth-child(2) { + & > ${SearchLabel} { + border-radius: 0.2rem; + margin-left: -0.25rem; + } + + & > ${SearchInput} { + margin-left: 3.8rem; + } + } +`; + +const SearchButton = styled.button` + display: flex; + position: relative; + justify-content: center; + align-items: center; + border: none; + outline: none; + cursor: pointer; + background-color: #e1999c; + border-radius: 0rem 0.5rem 0.5rem 0rem; + flex: 1; + box-shadow: 1px 0px 3px 1px rgba(0, 0, 0, 0.1); +`; + +const SearchIcon = styled(BiSearch)` + color: #fff; + font-size: 1.4rem; +`; + +export default SearchForm;
Unknown
์ง€๊ธˆ ์ •๋„์˜ ํผ ์‚ฌ์šฉ์—์„œ๋Š” ์ง์ ‘ ๊ตฌํ˜„๋„ ๋ฌด๋ฆฌ๊ฐ€ ์—†์—ˆ์ง€๋งŒ, ํผ์ด ๋ณต์žกํ•ด์ง€๋ฉด ํ™•์‹คํžˆ ๊ด€๋ฆฌํ•˜๊ธฐ๋„ ์‰ฝ์ง€ ์•Š์„ ๋“ฏ ํ•˜๋”๋ผ๊ตฌ์š”. ๊ธฐ์–ต ํ•ด๋‘์—ˆ๋‹ค๊ฐ€ ํ•„์š”ํ•  ๋•Œ ์ ์šฉ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค :) ์•Œ๋ ค์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,75 @@ +package bridge.controller; + +import bridge.BridgeRandomNumberGenerator; +import bridge.constants.GameValue; +import bridge.domain.Bridge; +import bridge.domain.BridgeGame; +import bridge.domain.BridgeMaker; +import bridge.view.handler.InputHandler; +import bridge.view.OutputView; + +public class BridgeController { + private final InputHandler inputHandler; + private final OutputView outputView; + private final BridgeGame bridgeGame; + private boolean status = true; + + public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) { + this.inputHandler = inputHandler; + this.outputView = outputView; + this.bridgeGame = bridgeGame; + } + + public void start() { + outputView.printStartMessage(); + Bridge bridge = createBridge(); + run(bridge); + } + + private Bridge createBridge() { + outputView.printBridgeSizeInputMessage(); + BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator()); + return inputHandler.createValidatedBridge(bridgeMaker); + } + + private void run(Bridge bridge) { + while (status) { + move(bridge); + if (isFinished()) { + finishGame(); + } + if (!isFinished()) { + askRetry(); + } + } + } + + private void move(Bridge bridge) { + for (String square : bridge.getBridge()) { + outputView.printMoveInputMessage(); + String moveCommand = inputHandler.readMoving(); + bridgeGame.move(square, moveCommand); + outputView.printMap(bridgeGame.getMoveResult()); + } + } + + private boolean isFinished() { + return bridgeGame.isSuccessful(); + } + + private void finishGame() { + outputView.printResult(bridgeGame); + status = false; + } + + private void askRetry() { + outputView.printRetryMessage(); + String retryCommand = inputHandler.readGameCommand(); + if (retryCommand.equals(GameValue.RETRY_COMMAND)) { + bridgeGame.retry(); + } + if (retryCommand.equals(GameValue.QUIT_COMMAND)) { + outputView.printResult(bridgeGame); + } + } +}
Java
๋‹ค๋ฆฌ๋ฅผ ๋Œ๋ฉด์„œ ์ด๋™์„ ๋ฐ›๊ณ  ์žˆ๋Š” ํ˜•ํƒœ๋ผ์„œ, ์ด๋™์ด ์‹คํŒจํ•ด๋„ ๋ฐ”๋กœ ์žฌ์‹œ๋„ ์—ฌ๋ถ€๋ฅผ ๋ฌป์ง€ ์•Š๊ณ , ๊ทธ๋ƒฅ ์ง„ํ–‰์ด ๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค..!
@@ -0,0 +1,75 @@ +package bridge.controller; + +import bridge.BridgeRandomNumberGenerator; +import bridge.constants.GameValue; +import bridge.domain.Bridge; +import bridge.domain.BridgeGame; +import bridge.domain.BridgeMaker; +import bridge.view.handler.InputHandler; +import bridge.view.OutputView; + +public class BridgeController { + private final InputHandler inputHandler; + private final OutputView outputView; + private final BridgeGame bridgeGame; + private boolean status = true; + + public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) { + this.inputHandler = inputHandler; + this.outputView = outputView; + this.bridgeGame = bridgeGame; + } + + public void start() { + outputView.printStartMessage(); + Bridge bridge = createBridge(); + run(bridge); + } + + private Bridge createBridge() { + outputView.printBridgeSizeInputMessage(); + BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator()); + return inputHandler.createValidatedBridge(bridgeMaker); + } + + private void run(Bridge bridge) { + while (status) { + move(bridge); + if (isFinished()) { + finishGame(); + } + if (!isFinished()) { + askRetry(); + } + } + } + + private void move(Bridge bridge) { + for (String square : bridge.getBridge()) { + outputView.printMoveInputMessage(); + String moveCommand = inputHandler.readMoving(); + bridgeGame.move(square, moveCommand); + outputView.printMap(bridgeGame.getMoveResult()); + } + } + + private boolean isFinished() { + return bridgeGame.isSuccessful(); + } + + private void finishGame() { + outputView.printResult(bridgeGame); + status = false; + } + + private void askRetry() { + outputView.printRetryMessage(); + String retryCommand = inputHandler.readGameCommand(); + if (retryCommand.equals(GameValue.RETRY_COMMAND)) { + bridgeGame.retry(); + } + if (retryCommand.equals(GameValue.QUIT_COMMAND)) { + outputView.printResult(bridgeGame); + } + } +}
Java
์‹คํŒจํ•˜๊ณ  ์žฌ์‹œ๋„๋Š” ์ข…๋ฃŒ๋ฅผ ์ž…๋ ฅํ–ˆ์„ ๋•Œ, ๊ฒŒ์ž„์ด ์ข…๋ฃŒ๋˜์ง€ ์•Š๊ณ  ๊ณ„์† ๋‹ค์Œ ์ด๋™ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค..! ์‹คํŒจํ•˜๊ณ  ์—ฌ๊ธฐ๋กœ ๋“ค์–ด์™€์„œ status๋ฅผ false๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ๋ถ€๋ถ„์ด ์—†์–ด์„œ์ธ ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,75 @@ +package bridge.controller; + +import bridge.BridgeRandomNumberGenerator; +import bridge.constants.GameValue; +import bridge.domain.Bridge; +import bridge.domain.BridgeGame; +import bridge.domain.BridgeMaker; +import bridge.view.handler.InputHandler; +import bridge.view.OutputView; + +public class BridgeController { + private final InputHandler inputHandler; + private final OutputView outputView; + private final BridgeGame bridgeGame; + private boolean status = true; + + public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) { + this.inputHandler = inputHandler; + this.outputView = outputView; + this.bridgeGame = bridgeGame; + } + + public void start() { + outputView.printStartMessage(); + Bridge bridge = createBridge(); + run(bridge); + } + + private Bridge createBridge() { + outputView.printBridgeSizeInputMessage(); + BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator()); + return inputHandler.createValidatedBridge(bridgeMaker); + } + + private void run(Bridge bridge) { + while (status) { + move(bridge); + if (isFinished()) { + finishGame(); + } + if (!isFinished()) { + askRetry(); + } + } + } + + private void move(Bridge bridge) { + for (String square : bridge.getBridge()) { + outputView.printMoveInputMessage(); + String moveCommand = inputHandler.readMoving(); + bridgeGame.move(square, moveCommand); + outputView.printMap(bridgeGame.getMoveResult()); + } + } + + private boolean isFinished() { + return bridgeGame.isSuccessful(); + } + + private void finishGame() { + outputView.printResult(bridgeGame); + status = false; + } + + private void askRetry() { + outputView.printRetryMessage(); + String retryCommand = inputHandler.readGameCommand(); + if (retryCommand.equals(GameValue.RETRY_COMMAND)) { + bridgeGame.retry(); + } + if (retryCommand.equals(GameValue.QUIT_COMMAND)) { + outputView.printResult(bridgeGame); + } + } +}
Java
์ด๋™ํ–ˆ์„ ๋•Œ X๊ฐ€ ๋‚˜์˜ค๋ฉด ์žฌ์‹œ์ž‘์ด ๋‚˜์™€์•ผํ•˜๋Š”๋ฐ ์ด๊ฑฐ ์ œ๊ฐ€ ๋ฌธ์ œ๋ฅผ ์ž˜ ๋ชป์ดํ•ดํ–ˆ๋„ค์š” ใ…‹ใ…‹..
@@ -0,0 +1,75 @@ +package bridge.controller; + +import bridge.BridgeRandomNumberGenerator; +import bridge.constants.GameValue; +import bridge.domain.Bridge; +import bridge.domain.BridgeGame; +import bridge.domain.BridgeMaker; +import bridge.view.handler.InputHandler; +import bridge.view.OutputView; + +public class BridgeController { + private final InputHandler inputHandler; + private final OutputView outputView; + private final BridgeGame bridgeGame; + private boolean status = true; + + public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) { + this.inputHandler = inputHandler; + this.outputView = outputView; + this.bridgeGame = bridgeGame; + } + + public void start() { + outputView.printStartMessage(); + Bridge bridge = createBridge(); + run(bridge); + } + + private Bridge createBridge() { + outputView.printBridgeSizeInputMessage(); + BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator()); + return inputHandler.createValidatedBridge(bridgeMaker); + } + + private void run(Bridge bridge) { + while (status) { + move(bridge); + if (isFinished()) { + finishGame(); + } + if (!isFinished()) { + askRetry(); + } + } + } + + private void move(Bridge bridge) { + for (String square : bridge.getBridge()) { + outputView.printMoveInputMessage(); + String moveCommand = inputHandler.readMoving(); + bridgeGame.move(square, moveCommand); + outputView.printMap(bridgeGame.getMoveResult()); + } + } + + private boolean isFinished() { + return bridgeGame.isSuccessful(); + } + + private void finishGame() { + outputView.printResult(bridgeGame); + status = false; + } + + private void askRetry() { + outputView.printRetryMessage(); + String retryCommand = inputHandler.readGameCommand(); + if (retryCommand.equals(GameValue.RETRY_COMMAND)) { + bridgeGame.retry(); + } + if (retryCommand.equals(GameValue.QUIT_COMMAND)) { + outputView.printResult(bridgeGame); + } + } +}
Java
๊ทธ๋Ÿฌ๋„ค์š” ๋ถ„๋ฆฌํ•˜๊ธฐ์ „์—๋Š” ์ •์ƒ๋™์ž‘ํ•ด์„œ ๋ฆฌํŒฉํ† ๋ง๋‹จ๊ณ„์—์„œ ์‹ค์ˆ˜ํ–ˆ๋‚˜๋ด…๋‹ˆ๋‹ค.. ๋งˆ์ง€๋ง‰์— ๋‹ค์‹œ ํ•œ๋ฒˆ ๊ผผ๊ผผํžˆ ์ฒดํฌํ•ด์•ผ๊ฒ ๋„ค์š” ๐Ÿ˜จ
@@ -0,0 +1,14 @@ +package bridge.constants; + +public class GameValue { + + private GameValue() { + } + + public static final String MOVE_UP_COMMAND = "U"; + public static final String MOVE_DOWN_COMMAND = "D"; + public static final String RETRY_COMMAND = "R"; + public static final String QUIT_COMMAND = "Q"; + public static final String MOVE = "O"; + public static final String STOP = "X"; +}
Java
๊ด€๋ จ ์žˆ๋Š” ์ƒ์ˆ˜๋ผ๋ฆฌ Enum ์œผ๋กœ ๋ฌถ์–ด๋ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค :)
@@ -0,0 +1,17 @@ +package bridge.constants; + +import java.util.regex.Pattern; + +public enum RegexPattern { + ONLY_NUMBER(Pattern.compile("\\d+")); + + private final Pattern pattern; + + RegexPattern(Pattern pattern) { + this.pattern = pattern; + } + + public boolean matches(String value) { + return pattern.matcher(value).matches(); + } +}
Java
Pattern ์ž์ฒด๋ฅผ Enum ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ƒ๊ฐํ•ด๋ณด์ง€ ๋ชปํ–ˆ๋Š”๋ฐ, ์ด๊ฑฐ ๊ฝค๋‚˜ ์žฌํ™œ์šฉ์„ฑ์ด ๋†’๊ฒ ๊ตฐ์š” ๐Ÿ‘
@@ -0,0 +1,75 @@ +package bridge.controller; + +import bridge.BridgeRandomNumberGenerator; +import bridge.constants.GameValue; +import bridge.domain.Bridge; +import bridge.domain.BridgeGame; +import bridge.domain.BridgeMaker; +import bridge.view.handler.InputHandler; +import bridge.view.OutputView; + +public class BridgeController { + private final InputHandler inputHandler; + private final OutputView outputView; + private final BridgeGame bridgeGame; + private boolean status = true; + + public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) { + this.inputHandler = inputHandler; + this.outputView = outputView; + this.bridgeGame = bridgeGame; + } + + public void start() { + outputView.printStartMessage(); + Bridge bridge = createBridge(); + run(bridge); + } + + private Bridge createBridge() { + outputView.printBridgeSizeInputMessage(); + BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator()); + return inputHandler.createValidatedBridge(bridgeMaker); + } + + private void run(Bridge bridge) { + while (status) { + move(bridge); + if (isFinished()) { + finishGame(); + } + if (!isFinished()) { + askRetry(); + } + } + } + + private void move(Bridge bridge) { + for (String square : bridge.getBridge()) { + outputView.printMoveInputMessage(); + String moveCommand = inputHandler.readMoving(); + bridgeGame.move(square, moveCommand); + outputView.printMap(bridgeGame.getMoveResult()); + } + } + + private boolean isFinished() { + return bridgeGame.isSuccessful(); + } + + private void finishGame() { + outputView.printResult(bridgeGame); + status = false; + } + + private void askRetry() { + outputView.printRetryMessage(); + String retryCommand = inputHandler.readGameCommand(); + if (retryCommand.equals(GameValue.RETRY_COMMAND)) { + bridgeGame.retry(); + } + if (retryCommand.equals(GameValue.QUIT_COMMAND)) { + outputView.printResult(bridgeGame); + } + } +}
Java
์ด ๋ถ€๋ถ„์€ ์ธ๋ดํŠธ๋ฅผ 1๋กœ ๋ฆฌํŒฉํ† ๋งํ•˜๋Š” ๊ณ ํ†ต์Šค๋Ÿฌ์šด(?) ๊ฒฝํ—˜์„ ํ•ด๋ณด์…”๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์ €๋„ ์ ˆ๋Œ€ ๋ชป ์ค„์ผ ๊ฒƒ ๊ฐ™๋˜ ์ธ๋ดํŠธ๋ฅผ ์ค„์ด๋ ค๊ณ  ์ด๋ฆฌ์ €๋ฆฌ ๋น„ํ‹€๋‹ค๋ณด๋‹ˆ(?) ๋‹ค์–‘ํ•œ ์ธ์‚ฌ์ดํŠธ๋“ค์ด ๋– ์˜ค๋ฅด๋”๋ผ๊ณ ์š”..!
@@ -0,0 +1,82 @@ +package bridge.domain; + +import bridge.constants.GameValue; + +/** + * ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ ๊ฒŒ์ž„์„ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค + */ +public class BridgeGame { + + private int retryCount; + private MoveResult moveResult; + + public BridgeGame(MoveResult moveResult, int retryCount) { + this.moveResult = moveResult; + this.retryCount = retryCount; + } + + /** + * ์‚ฌ์šฉ์ž๊ฐ€ ์นธ์„ ์ด๋™ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ + */ + public void move(String square, String moveCommand) { + if (moveCommand.equals(GameValue.MOVE_UP_COMMAND)) { + moveUp(square, moveCommand); + } + if (moveCommand.equals(GameValue.MOVE_DOWN_COMMAND)) { + moveLower(square, moveCommand); + } + } + + private boolean isMoveUp(String square, String moveCommand) { + return square.equals(moveCommand); + } + + private void moveUp(String square, String moveCommand) { + if (isMoveUp(square, moveCommand)) { + moveResult.moveUp(GameValue.MOVE); + } + if (!isMoveUp(square, moveCommand)) { + moveResult.moveUp(GameValue.STOP); + } + } + + private boolean isMoveLower(String square, String moveCommand) { + return square.equals(moveCommand); + } + + private void moveLower(String square, String moveCommand) { + if (isMoveLower(square, moveCommand)) { + moveResult.moveLowwer(GameValue.MOVE); + } + if (!isMoveLower(square, moveCommand)) { + moveResult.moveLowwer(GameValue.STOP); + } + } + + public boolean isSuccessful() { + return moveResult.isSuccessful(); + } + + public String getGameResult() { + if (isSuccessful()) { + return "์„ฑ๊ณต"; + } + return "์‹คํŒจ"; + } + + /** + * ์‚ฌ์šฉ์ž๊ฐ€ ๊ฒŒ์ž„์„ ๋‹ค์‹œ ์‹œ๋„ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ + */ + public void retry() { + retryCount++; + moveResult = new MoveResult(); + } + + public int getRetryCount() { + return retryCount; + } + + public MoveResult getMoveResult() { + return moveResult; + } +}
Java
์—ฌ๊ธฐ early return ์ด ๋น ์ง„ ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,37 @@ +package bridge.domain; + +import java.util.ArrayList; +import java.util.List; + +public class MoveResult { + private final List<String> upperBridge; + private final List<String> lowerBridge; + + public MoveResult() { + this.upperBridge = new ArrayList<>(); + this.lowerBridge = new ArrayList<>(); + } + + public void moveUp(String moveResult) { + upperBridge.add(moveResult); + lowerBridge.add(" "); + } + + public void moveLowwer(String moveResult) { + upperBridge.add(" "); + lowerBridge.add(moveResult); + } + + public boolean isSuccessful() { + if (upperBridge.contains("X") || lowerBridge.contains("X")) { + return false; + } + return true; + } + + @Override + public String toString() { + return "[ " + String.join(" | ", upperBridge) + " ]\n" + + "[ " + String.join(" | ", lowerBridge) + " ]"; + } +}
Java
> ํ•ต์‹ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์™€ UI๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋กœ์ง์„ ๋ถ„๋ฆฌํ•ด ๊ตฌํ˜„ํ•œ๋‹ค. ์ด ๋ถ€๋ถ„์€ ์š”๊ตฌ์‚ฌํ•ญ์ด ์ง€์ผœ์ง€์ง€ ์•Š์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํ”„๋ฆฌ์ฝ”์Šค ๊ธฐ๊ฐ„ ๋™์•ˆ ๊ฐ€์žฅ ๋งŽ์ด ์š”๊ตฌ๋œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ฒ•์ด๋ผ, ์ด ๋ถ€๋ถ„์€ ๊ผญ ๋ฆฌํŒฉํ† ๋ง ํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,56 @@ +package bridge.view; + +import bridge.domain.BridgeGame; +import bridge.domain.MoveResult; + +/** + * ์‚ฌ์šฉ์ž์—๊ฒŒ ๊ฒŒ์ž„ ์ง„ํ–‰ ์ƒํ™ฉ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. + */ +public class OutputView { + + public void printStartMessage() { + println("๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ ๊ฒŒ์ž„์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค."); + } + + public void printBridgeSizeInputMessage() { + printNewLine(); + println("๋‹ค๋ฆฌ์˜ ๊ธธ์ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + + public void printMoveInputMessage() { + printNewLine(); + println("์ด๋™ํ•  ์นธ์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”. (์œ„: U, ์•„๋ž˜: D)"); + } + + /** + * ํ˜„์žฌ๊นŒ์ง€ ์ด๋™ํ•œ ๋‹ค๋ฆฌ์˜ ์ƒํƒœ๋ฅผ ์ •ํ•ด์ง„ ํ˜•์‹์— ๋งž์ถฐ ์ถœ๋ ฅํ•œ๋‹ค. + */ + public void printMap(MoveResult moveResult) { + println(moveResult.toString()); + } + + /** + * ๊ฒŒ์ž„์˜ ์ตœ์ข… ๊ฒฐ๊ณผ๋ฅผ ์ •ํ•ด์ง„ ํ˜•์‹์— ๋งž์ถฐ ์ถœ๋ ฅํ•œ๋‹ค. + */ + public void printResult(BridgeGame bridgeGame) { + printNewLine(); + println("์ตœ์ข… ๊ฒŒ์ž„ ๊ฒฐ๊ณผ"); + printMap(bridgeGame.getMoveResult()); + printNewLine(); + System.out.printf("๊ฒŒ์ž„ ์„ฑ๊ณต ์—ฌ๋ถ€: %s\n", bridgeGame.getGameResult()); + System.out.printf("์ด ์‹œ๋„ํ•œ ํšŸ์ˆ˜: %d\n", bridgeGame.getRetryCount()); + } + + public void printRetryMessage() { + printNewLine(); + println("๊ฒŒ์ž„์„ ๋‹ค์‹œ ์‹œ๋„ํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”. (์žฌ์‹œ๋„: R, ์ข…๋ฃŒ: Q)"); + } + + private void println(String output) { + System.out.println(output); + } + + private void printNewLine() { + System.out.println(); + } +}
Java
ํ™•์‹คํžˆ ์ถœ๋ ฅ์šฉ ๋ฉ”์‹œ์ง€๊ฐ€ ์žฌํ™œ์šฉ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์—†๋‹ค๋ณด๋‹ˆ, ์ด๋ ‡๊ฒŒ ํ•˜๋“œ ์ฝ”๋”ฉํ•ด๋„ ๊ฝค๋‚˜ ์ง๊ด€์ ์ด์ž–์•„? ๋ผ๋Š” ๋А๋‚Œ์„ ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค ๐Ÿ‘
@@ -0,0 +1,42 @@ +package bridge.view.handler; + +import bridge.domain.Bridge; +import bridge.domain.BridgeMaker; +import bridge.view.ErrorView; +import bridge.view.InputView; +import java.util.function.Supplier; + +public class InputHandler { + private final InputView inputView; + private final ErrorView errorView; + + public InputHandler(InputView inputView, ErrorView errorView) { + this.inputView = inputView; + this.errorView = errorView; + } + + public Bridge createValidatedBridge(BridgeMaker bridgeMaker) { + return receiveValidatedInput(() -> { + int bridgeSize = inputView.readBridgeSize(); + return Bridge.from(bridgeMaker.makeBridge(bridgeSize)); + }); + } + + public String readMoving() { + return receiveValidatedInput(inputView::readMoving); + } + + public String readGameCommand() { + return receiveValidatedInput(inputView::readGameCommand); + } + + private <T> T receiveValidatedInput(Supplier<T> inputView) { + while (true) { + try { + return inputView.get(); + } catch (IllegalArgumentException exception) { + errorView.printErrorMessage(exception.getMessage()); + } + } + } +}
Java
(๊ถ๊ธˆํ•ด์š”!) ๊ทธ๋™์•ˆ ํ˜„์ค€๋‹˜๊ณผ ๋ฆฌ๋ทฐํ•ด์˜ค๋ฉด์„œ ์ด๋Ÿฐ ์žฌ์‹œ๋„ ๋กœ์ง์„ while ๋กœ ์ฒ˜๋ฆฌํ• ๊นŒ, ์žฌ๊ท€๋กœ ์ฒ˜๋ฆฌํ• ๊นŒ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ ์ €๋Š” ์žฌ๊ท€๋ฅผ ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์žฌ๊ท€๋ฅผ ์„ ํƒํ•ด๋„ ํ˜ธ์ถœ ๋ށ์Šค๊ฐ€ ๊นŠ์–ด์ง€๋Š”๊ฒŒ ์•„๋‹ˆ๊ณ  ๋ށ์Šค๊ฐ€ 1๋กœ ๊ณ„์† ์œ ์ง€๋˜๋Š” ๊ฒƒ ๊ฐ™๋”๋ผ๊ณ ์š”. (์–ด์ฐจํ”ผ catch๋ฅผ ํ•˜๊ณ  ์—๋Ÿฌ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ์„ ํ•˜๋ฏ€๋กœ) ํ˜„์ค€๋‹˜์€ ์žฌ๊ท€ ๋Œ€์‹  while์„ ์„ ํƒํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค :)
@@ -0,0 +1,82 @@ +package bridge.domain; + +import bridge.constants.GameValue; + +/** + * ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ ๊ฒŒ์ž„์„ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค + */ +public class BridgeGame { + + private int retryCount; + private MoveResult moveResult; + + public BridgeGame(MoveResult moveResult, int retryCount) { + this.moveResult = moveResult; + this.retryCount = retryCount; + } + + /** + * ์‚ฌ์šฉ์ž๊ฐ€ ์นธ์„ ์ด๋™ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ + */ + public void move(String square, String moveCommand) { + if (moveCommand.equals(GameValue.MOVE_UP_COMMAND)) { + moveUp(square, moveCommand); + } + if (moveCommand.equals(GameValue.MOVE_DOWN_COMMAND)) { + moveLower(square, moveCommand); + } + } + + private boolean isMoveUp(String square, String moveCommand) { + return square.equals(moveCommand); + } + + private void moveUp(String square, String moveCommand) { + if (isMoveUp(square, moveCommand)) { + moveResult.moveUp(GameValue.MOVE); + } + if (!isMoveUp(square, moveCommand)) { + moveResult.moveUp(GameValue.STOP); + } + } + + private boolean isMoveLower(String square, String moveCommand) { + return square.equals(moveCommand); + } + + private void moveLower(String square, String moveCommand) { + if (isMoveLower(square, moveCommand)) { + moveResult.moveLowwer(GameValue.MOVE); + } + if (!isMoveLower(square, moveCommand)) { + moveResult.moveLowwer(GameValue.STOP); + } + } + + public boolean isSuccessful() { + return moveResult.isSuccessful(); + } + + public String getGameResult() { + if (isSuccessful()) { + return "์„ฑ๊ณต"; + } + return "์‹คํŒจ"; + } + + /** + * ์‚ฌ์šฉ์ž๊ฐ€ ๊ฒŒ์ž„์„ ๋‹ค์‹œ ์‹œ๋„ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ + */ + public void retry() { + retryCount++; + moveResult = new MoveResult(); + } + + public int getRetryCount() { + return retryCount; + } + + public MoveResult getMoveResult() { + return moveResult; + } +}
Java
else๋ฌธ์ด ์•„๋‹ˆ๋ผ์„œ ์•„๋ฌด๋ž˜๋„ return์„ ์ถ”๊ฐ€ํ•ด ๋‹ค์Œ ์กฐ๊ฑด์„ ํ™•์ธํ•˜์ง€ ์•Š๋„๋ก ํ•˜๋Š”๊ฒŒ ์ข‹๊ฒ ๋„ค์š” !
@@ -0,0 +1,37 @@ +package bridge.domain; + +import java.util.ArrayList; +import java.util.List; + +public class MoveResult { + private final List<String> upperBridge; + private final List<String> lowerBridge; + + public MoveResult() { + this.upperBridge = new ArrayList<>(); + this.lowerBridge = new ArrayList<>(); + } + + public void moveUp(String moveResult) { + upperBridge.add(moveResult); + lowerBridge.add(" "); + } + + public void moveLowwer(String moveResult) { + upperBridge.add(" "); + lowerBridge.add(moveResult); + } + + public boolean isSuccessful() { + if (upperBridge.contains("X") || lowerBridge.contains("X")) { + return false; + } + return true; + } + + @Override + public String toString() { + return "[ " + String.join(" | ", upperBridge) + " ]\n" + + "[ " + String.join(" | ", lowerBridge) + " ]"; + } +}
Java
ํ—› ๊ทธ ๋ถ€๋ถ„์„ ๋†“์ณ๋ฒ„๋ ธ๋„ค์š” .. ์ด๋ฒˆ 5๊ธฐ ์ตœ์ข…๊นŒ์ง€ ์น˜๋ฉด์„œ ๋А๋‚€๊ฑด๋ฐ 5์‹œ๊ฐ„์ด๋ผ๋Š” ์‹œ๊ฐ„์— ์–ฝ๋งค์ด์ง€ ์•Š๊ณ  ์ดˆ๋ฐ˜์— ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ์„ ๊ผผ๊ผผํžˆ ๊ฒ€ํ† ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๋ผˆ์ €๋ฆฌ๊ฒŒ ๋А๊ผˆ์Šต๋‹ˆ๋‹ค..
@@ -0,0 +1,42 @@ +package bridge.view.handler; + +import bridge.domain.Bridge; +import bridge.domain.BridgeMaker; +import bridge.view.ErrorView; +import bridge.view.InputView; +import java.util.function.Supplier; + +public class InputHandler { + private final InputView inputView; + private final ErrorView errorView; + + public InputHandler(InputView inputView, ErrorView errorView) { + this.inputView = inputView; + this.errorView = errorView; + } + + public Bridge createValidatedBridge(BridgeMaker bridgeMaker) { + return receiveValidatedInput(() -> { + int bridgeSize = inputView.readBridgeSize(); + return Bridge.from(bridgeMaker.makeBridge(bridgeSize)); + }); + } + + public String readMoving() { + return receiveValidatedInput(inputView::readMoving); + } + + public String readGameCommand() { + return receiveValidatedInput(inputView::readGameCommand); + } + + private <T> T receiveValidatedInput(Supplier<T> inputView) { + while (true) { + try { + return inputView.get(); + } catch (IllegalArgumentException exception) { + errorView.printErrorMessage(exception.getMessage()); + } + } + } +}
Java
์žฌ๊ท€ ํ˜ธ์ถœ๋กœ ๊ตฌํ˜„ํ–ˆ์„ ๋•Œ ์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์ง„๋‹ค๋Š” ์žฅ์ ์„ ๊ฐ€์ง€๊ณ  ์žˆ์ง€๋งŒ ํƒ์ƒ‰ ๊นŠ์ด๊ฐ€ ๊นŠ์–ด ์งˆ ๋•Œ ์œ„ํ—˜ํ•  ๊ฒƒ์ด๋ผ ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ์„ ํ˜ธ๋‹˜ ๋ง์”€๋Œ€๋กœ 1๋กœ ์œ ์ง€๋œ๋‹ค๋ฉด ์ด ์ ์€ ์•„๋ฌด๋ž˜๋„ ์ œ์™ธํ•ด์•ผํ• ๊ฒƒ ๊ฐ™๋„ค์š” ํ•˜์ง€๋งŒ while๋ฌธ์„ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ๋ฐ˜๋ณต ํšŸ์ˆ˜๋ฅผ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ๋„ ์žˆ๊ธฐ์— while๋ฌธ์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด์„œ ์‹ค์ œ ๋กœ๊ทธ์ธ ์ •์ฑ…์ฒ˜๋Ÿผ ์ž˜๋ชป๋œ ๊ฐ’์„ 3ํšŒ ๋˜๋Š” 5ํšŒ ์ž…๋ ฅ ํ–ˆ์„ ๊ฒฝ์šฐ ์ž…๋ ฅ์„ ์ข…๋ฃŒ ์‹œํ‚จ๋‹ค๋˜๊ฐ€ ๋“ฑ์˜ ์ƒํ™ฉ๋„ ์ƒ๊ฐํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,42 @@ +package bridge.view.handler; + +import bridge.domain.Bridge; +import bridge.domain.BridgeMaker; +import bridge.view.ErrorView; +import bridge.view.InputView; +import java.util.function.Supplier; + +public class InputHandler { + private final InputView inputView; + private final ErrorView errorView; + + public InputHandler(InputView inputView, ErrorView errorView) { + this.inputView = inputView; + this.errorView = errorView; + } + + public Bridge createValidatedBridge(BridgeMaker bridgeMaker) { + return receiveValidatedInput(() -> { + int bridgeSize = inputView.readBridgeSize(); + return Bridge.from(bridgeMaker.makeBridge(bridgeSize)); + }); + } + + public String readMoving() { + return receiveValidatedInput(inputView::readMoving); + } + + public String readGameCommand() { + return receiveValidatedInput(inputView::readGameCommand); + } + + private <T> T receiveValidatedInput(Supplier<T> inputView) { + while (true) { + try { + return inputView.get(); + } catch (IllegalArgumentException exception) { + errorView.printErrorMessage(exception.getMessage()); + } + } + } +}
Java
ํ™•์‹คํžˆ **3ํšŒ ๊นŒ์ง€๋งŒ ์žฌ์‹œ๋„๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค** ๋ผ๋Š” ๋กœ์ง์ด ์žˆ์„ ๊ฒฝ์šฐ์—๋Š” while ๋ฌธ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š”๊ฒŒ ์œ ์—ฐํ•˜๊ฒŒ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”! ์ธ์‚ฌ์ดํŠธ ๋ฐ›๊ณ  ๊ฐ‘๋‹ˆ๋‹ค :D
@@ -0,0 +1,40 @@ +package org.sopt.androidseminar1 + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Toast +import org.sopt.androidseminar1.databinding.SignInBinding + +class SignInActivity: AppCompatActivity() { + private lateinit var binding: SignInBinding // ๊ณ ์ •์ ์ธ Class ๊ฐ’์€ ์•„๋‹ˆ๋‹ค. + // activity_main -> ActivityMain + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = SignInBinding.inflate(layoutInflater) // layoutInflater : xml์„ ๋ถˆ๋Ÿฌ์ฃผ๋Š” ์ •๋„ + setContentView(binding.root) // setContentView : xml์„ ๊ทธ๋ ค์ฃผ๋Š” ํ•จ์ˆ˜ + + + // intent ๋ณ€๊ฒฝ + val goSignup: Intent = Intent(this, SignUpActivity::class.java) + val goHomeActivity: Intent = Intent(this, HomeActivity::class.java ) + + // ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ + binding.btnLogin.setOnClickListener { + if (binding.etId.text.toString().isEmpty() || binding.etPw.text.toString().isEmpty()){ + Toast.makeText(this, "๋กœ๊ทธ์ธ ์‹คํŒจ", Toast.LENGTH_SHORT).show() + } + else { + startActivity(goHomeActivity) + } + } + + // ํšŒ์›๊ฐ€์ž… + binding.btnSignup.setOnClickListener{ + startActivity(goSignup) + } + + setContentView(binding.root) + } +} \ No newline at end of file
Kotlin
์ฝ”ํ‹€๋ฆฐ์—์„œ๋Š” ํƒ€์ž… ์ถ”๋ก  ๊ธฐ๋Šฅ์„ ์ง€์›ํ•ด์ฃผ๊ธฐ๋•Œ๋ฌธ์— ```suggestion val goSignup = Intent(this, SignUpActivity::class.java) val goHomeActivity = Intent(this, HomeActivity::class.java ) ``` ์ด๋ ‡๊ฒŒ๋งŒ ์ž‘์„ฑํ•˜์…”๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹น~:)
@@ -0,0 +1,40 @@ +package org.sopt.androidseminar1 + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Toast +import org.sopt.androidseminar1.databinding.SignInBinding + +class SignInActivity: AppCompatActivity() { + private lateinit var binding: SignInBinding // ๊ณ ์ •์ ์ธ Class ๊ฐ’์€ ์•„๋‹ˆ๋‹ค. + // activity_main -> ActivityMain + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = SignInBinding.inflate(layoutInflater) // layoutInflater : xml์„ ๋ถˆ๋Ÿฌ์ฃผ๋Š” ์ •๋„ + setContentView(binding.root) // setContentView : xml์„ ๊ทธ๋ ค์ฃผ๋Š” ํ•จ์ˆ˜ + + + // intent ๋ณ€๊ฒฝ + val goSignup: Intent = Intent(this, SignUpActivity::class.java) + val goHomeActivity: Intent = Intent(this, HomeActivity::class.java ) + + // ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ + binding.btnLogin.setOnClickListener { + if (binding.etId.text.toString().isEmpty() || binding.etPw.text.toString().isEmpty()){ + Toast.makeText(this, "๋กœ๊ทธ์ธ ์‹คํŒจ", Toast.LENGTH_SHORT).show() + } + else { + startActivity(goHomeActivity) + } + } + + // ํšŒ์›๊ฐ€์ž… + binding.btnSignup.setOnClickListener{ + startActivity(goSignup) + } + + setContentView(binding.root) + } +} \ No newline at end of file
Kotlin
์—ฌ๊ธฐ์„œ toString()์˜ ๊ฒฝ์šฐ ๋นผ์ฃผ์…”๋„ ๊ดœ์ฐฎ์Šต๋‹ˆ๋‹ค~!!
@@ -0,0 +1,40 @@ +package org.sopt.androidseminar1 + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Toast +import org.sopt.androidseminar1.databinding.SignInBinding + +class SignInActivity: AppCompatActivity() { + private lateinit var binding: SignInBinding // ๊ณ ์ •์ ์ธ Class ๊ฐ’์€ ์•„๋‹ˆ๋‹ค. + // activity_main -> ActivityMain + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = SignInBinding.inflate(layoutInflater) // layoutInflater : xml์„ ๋ถˆ๋Ÿฌ์ฃผ๋Š” ์ •๋„ + setContentView(binding.root) // setContentView : xml์„ ๊ทธ๋ ค์ฃผ๋Š” ํ•จ์ˆ˜ + + + // intent ๋ณ€๊ฒฝ + val goSignup: Intent = Intent(this, SignUpActivity::class.java) + val goHomeActivity: Intent = Intent(this, HomeActivity::class.java ) + + // ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ + binding.btnLogin.setOnClickListener { + if (binding.etId.text.toString().isEmpty() || binding.etPw.text.toString().isEmpty()){ + Toast.makeText(this, "๋กœ๊ทธ์ธ ์‹คํŒจ", Toast.LENGTH_SHORT).show() + } + else { + startActivity(goHomeActivity) + } + } + + // ํšŒ์›๊ฐ€์ž… + binding.btnSignup.setOnClickListener{ + startActivity(goSignup) + } + + setContentView(binding.root) + } +} \ No newline at end of file
Kotlin
ํ˜„์žฌ setContentView ํ•จ์ˆ˜๊ฐ€ ๋‘๋ฒˆ ํ˜ธ์ถœ๋˜๊ณ  ์žˆ๋Š”๋ฐ ํ•˜๋‚˜๋Š” ์ง€์›Œ์ฃผ์…”๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์•„์š”~!!
@@ -0,0 +1,40 @@ +package org.sopt.androidseminar1 + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Toast +import org.sopt.androidseminar1.databinding.SignInBinding + +class SignInActivity: AppCompatActivity() { + private lateinit var binding: SignInBinding // ๊ณ ์ •์ ์ธ Class ๊ฐ’์€ ์•„๋‹ˆ๋‹ค. + // activity_main -> ActivityMain + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = SignInBinding.inflate(layoutInflater) // layoutInflater : xml์„ ๋ถˆ๋Ÿฌ์ฃผ๋Š” ์ •๋„ + setContentView(binding.root) // setContentView : xml์„ ๊ทธ๋ ค์ฃผ๋Š” ํ•จ์ˆ˜ + + + // intent ๋ณ€๊ฒฝ + val goSignup: Intent = Intent(this, SignUpActivity::class.java) + val goHomeActivity: Intent = Intent(this, HomeActivity::class.java ) + + // ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ + binding.btnLogin.setOnClickListener { + if (binding.etId.text.toString().isEmpty() || binding.etPw.text.toString().isEmpty()){ + Toast.makeText(this, "๋กœ๊ทธ์ธ ์‹คํŒจ", Toast.LENGTH_SHORT).show() + } + else { + startActivity(goHomeActivity) + } + } + + // ํšŒ์›๊ฐ€์ž… + binding.btnSignup.setOnClickListener{ + startActivity(goSignup) + } + + setContentView(binding.root) + } +} \ No newline at end of file
Kotlin
๋ชจ๋“  ๋กœ์ง์„ ๋‹ค onCreate์— ๋„ฃ๊ธฐ๋ณด๋‹ค๋Š” ๊ฐ€๋…์„ฑ, ์žฌ์‚ฌ์šฉ์„ฑ ์ธก๋ฉด์„ ๊ณ ๋ คํ•ด์„œ ํ•จ์ˆ˜ํ™”๋ฅผ ํ•ด์ฃผ์‹œ๋Š” ๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~!!
@@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + + <corners android:radius="5dip"/> + + <stroke android:width="2dp" + android:color="#F658A6"/> + <solid android:color="#F658A6"/> + <corners + android:topLeftRadius="12dp" + android:topRightRadius="12dp" + android:bottomLeftRadius="12dp" + android:bottomRightRadius="12dp"/> +</shape> \ No newline at end of file
Unknown
dip๋Š” dp์™€ ๊ฐ™์€ ๊ฐœ๋…์ž…๋‹ˆ๋‹ค! ์ˆ˜์น˜๋ฅผ dp๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~!!!
@@ -0,0 +1,126 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".HomeActivity"> + + <TextView + android:id="@+id/textView10" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="70dp" + android:text="@string/sopthub" + android:textColor="#F658A6" + android:textSize="40sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + + <TextView + android:id="@+id/textView11" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="20dp" + android:layout_marginTop="40dp" + android:text="@string/kimdaeho" + android:textColor="@color/black" + android:textSize="15sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.059" + app:layout_constraintStart_toEndOf="@+id/textView15" + app:layout_constraintTop_toBottomOf="@+id/imageView2" /> + + <TextView + android:id="@+id/textView12" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/old" + android:textColor="@color/black" + android:textSize="15sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.193" + app:layout_constraintStart_toEndOf="@+id/textView16" + app:layout_constraintTop_toTopOf="@+id/textView16" /> + + <TextView + android:id="@+id/textView14" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="60dp" + android:text="@string/introduce" + android:textColor="@color/black" + android:textSize="15sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.453" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView13" /> + + <TextView + android:id="@+id/textView13" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/entj" + android:textColor="@color/black" + android:textSize="15sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.154" + app:layout_constraintStart_toEndOf="@+id/textView17" + app:layout_constraintTop_toTopOf="@+id/textView17" /> + + <ImageView + android:id="@+id/imageView2" + android:layout_width="119dp" + android:layout_height="147dp" + android:layout_marginTop="30dp" + app:layout_constraintEnd_toEndOf="@+id/textView10" + app:layout_constraintHorizontal_bias="0.491" + app:layout_constraintStart_toStartOf="@+id/textView10" + app:layout_constraintTop_toBottomOf="@+id/textView10" + app:srcCompat="@drawable/kimdaeho" /> + + <TextView + android:id="@+id/textView15" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="150dp" + android:text="@string/name" + android:textColor="@color/black" + android:textSize="15sp" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@+id/textView11" /> + + <TextView + android:id="@+id/textView16" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="40dp" + android:text="@string/age" + android:textColor="@color/black" + android:textSize="15sp" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="@+id/textView15" + app:layout_constraintTop_toBottomOf="@+id/textView15" /> + + <TextView + android:id="@+id/textView17" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="40dp" + android:text="@string/mbti" + android:textColor="@color/black" + android:textSize="15sp" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="@+id/textView16" + app:layout_constraintTop_toBottomOf="@+id/textView16" /> + + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
Unknown
View ์ปดํฌ๋„ŒํŠธ์˜ id ๊ฐ’์˜ ๋„ค์ด๋ฐ์€ ์ข€ ๋” ๊ธฐ๋Šฅ์— ๋งž๊ฒŒ~~ ๊ตฌ์ฒด์ ์œผ๋กœ ๋„ค์ด๋ฐ ํ•˜๋Š” ๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~!!
@@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".SignInActivity"> + + <!-- + text size -> sp + hardcoded text -> @values ํด๋”๋กœ text ์˜ฎ๊ธฐ๊ธฐ + @values ์—๋‹ค๊ฐ€ color ์˜ฎ๊ธฐ๊ธฐ + amulator ์— action bar ์ œ๊ฑฐ + ์Šคํ…Œ์ด๋”์Šค๋ฐ” ์ƒ‰๊น” ๋ณ€๊ฒฝํ•ด์•ผํ•จ -> @themas--> + <TextView + android:id="@+id/textView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="70dp" + android:text="@string/sopthub" + android:textColor="@color/pink" + android:textSize="40sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <TextView + android:id="@+id/textView2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="40dp" + android:layout_marginTop="40dp" + android:text="@string/id" + android:textColor="@color/black" + android:textSize="20sp" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView4" /> + + <EditText + android:id="@+id/et_id" + android:layout_width="0dp" + android:layout_height="50dp" + android:layout_marginTop="8dp" + android:layout_marginEnd="40dp" + android:background="@drawable/round_blank_edge" + android:ems="10" + android:inputType="textPersonName" + android:paddingStart="15dp" + android:hint="@string/input_id" + android:textColor="@color/gray" + android:textSize="15sp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="@+id/textView2" + app:layout_constraintTop_toBottomOf="@+id/textView2" /> + + <TextView + android:id="@+id/textView3" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="20dp" + android:text="@string/password" + android:textColor="@color/black" + android:textSize="20sp" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="@+id/et_id" + app:layout_constraintTop_toBottomOf="@+id/et_id" /> + + <EditText + android:id="@+id/et_pw" + android:layout_width="0dp" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:layout_marginEnd="40dp" + android:background="@drawable/round_blank_edge" + android:ems="10" + android:inputType="textPassword" + android:minHeight="48dp" + android:paddingStart="15dp" + android:hint="@string/input_password" + android:textColor="@color/gray" + android:textSize="15sp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="@+id/textView3" + app:layout_constraintTop_toBottomOf="@+id/textView3" /> + + <Button + android:id="@+id/btn_login" + android:layout_width="0dp" + android:layout_height="50dp" + android:layout_marginBottom="120dp" + android:background="@drawable/round_full_edge" + android:text="@string/login" + android:textColor="@color/white" + android:textSize="15sp" + android:textStyle="bold" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="@+id/et_pw" + app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintStart_toStartOf="@+id/et_pw" + app:layout_constraintTop_toBottomOf="@+id/et_pw" /> + + + <Button + android:id="@+id/btn_signup" + android:layout_width="0dp" + android:layout_height="50dp" + android:background="@color/white" + android:text="@string/signup" + android:textColor="@color/gray" + android:textSize="15sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="@+id/btn_login" + app:layout_constraintStart_toStartOf="@+id/btn_login" + app:layout_constraintTop_toBottomOf="@+id/btn_login" + app:layout_constraintVertical_bias="0.0" /> + + <TextView + android:id="@+id/textView4" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:text="@string/login" + android:textColor="@color/black" + android:textSize="25sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="@+id/textView" + app:layout_constraintHorizontal_bias="0.486" + app:layout_constraintStart_toStartOf="@+id/textView" + app:layout_constraintTop_toBottomOf="@+id/textView" /> + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file
Unknown
๊ณ ์ • dp๋ฅผ ๋†’์ด๋‚˜ ๋„ˆ๋น„๊ฐ’์œผ๋กœ ์ค„ ๊ฒฝ์šฐ ํœด๋Œ€ํฐ ๊ธฐ์ข…์— ๋”ฐ๋ผ ๋‚ด์šฉ์ด ์ž˜๋ฆด์ˆ˜๋„์žˆ๊ณ , ๋ชจ์–‘์ด ์ด์ƒํ•˜๊ฒŒ ๋‚˜์˜ฌ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค~ ํ˜น์‹œ ๊ณ ์ • dp๋ฅผ ๋†’์ด ๊ฐ’์œผ๋กœ ์ฃผ์‹  ํŠน๋ณ„ํ•œ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”~๐Ÿ‘€๐Ÿ‘€
@@ -0,0 +1,150 @@ +// +// MyDetailReviewViewController.swift +// Pyonsnal-Color +// +// Created by ์กฐ์†Œ์ • on 5/19/24. +// + +import ModernRIBs +import UIKit + +protocol MyDetailReviewPresentableListener: AnyObject { + func didTapBackButton() +} + +final class MyDetailReviewViewController: UIViewController, + MyDetailReviewPresentable, + MyDetailReviewViewControllable { + // MARK: Interfaces + private typealias DataSource = UICollectionViewDiffableDataSource<Section, Item> + private typealias Snapshot = NSDiffableDataSourceSnapshot<Section, Item> + + private enum Section { + case main + } + + private enum Item: Hashable { + case productDetail(product: ProductDetailEntity) + case review(review: ReviewEntity) + case landing + } + + weak var listener: MyDetailReviewPresentableListener? + + // MARK: Private Properties + private let viewHolder: ViewHolder = .init() + private var dataSource: DataSource? + private var productDetail: ProductDetailEntity? + private var review: ReviewEntity? + + // MARK: View Life Cycles + override func viewDidLoad() { + super.viewDidLoad() + viewHolder.place(in: view) + viewHolder.configureConstraints(for: view) + self.configureUI() + self.bindActions() + self.configureCollectionView() + self.configureDataSource() + self.applySnapshot(with: productDetail, review: review) + } + + func update(with productDetail: ProductDetailEntity, review: ReviewEntity) { + self.productDetail = productDetail + self.review = review + } + + // MARK: Private Methods + private func configureUI() { + self.view.backgroundColor = .white + } + + private func bindActions() { + self.viewHolder.backNavigationView.delegate = self + } + + private func configureCollectionView() { + self.registerCollectionViewCells() + self.viewHolder.collectionView.delegate = self + } + + private func registerCollectionViewCells() { + self.viewHolder.collectionView.register(ProductDetailReviewCell.self) + self.viewHolder.collectionView.register( + UICollectionViewCell.self, + forCellWithReuseIdentifier: MyReviewContentView.identifier + ) + self.viewHolder.collectionView.register(ActionButtonCell.self) + } + + private func configureDataSource() { + dataSource = DataSource(collectionView: self.viewHolder.collectionView) { collectionView, indexPath, itemIdentifier in + switch itemIdentifier { + case .productDetail(let product): + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MyReviewContentView.identifier, for: indexPath) + cell.contentConfiguration = MyReviewContentConfiguration( + mode: .tastes, + storeImageIcon: product.storeType, + imageUrl: product.imageURL, + title: "ํ”„๋ง๊ธ€์Šค) ๋งค์ฝคํ•œ๋ง›(๋Œ€) ํ”„๋ง๊ธ€์Šค) ๋งค์ฝคํ•œ๋ง›(๋Œ€)ํ”„๋ง๊ธ€์Šค) ๋งค์ฝคํ•œ๋ง›(๋Œ€)ํ”„๋ง๊ธ€์Šค) ๋งค์ฝคํ•œ๋ง›", + tastesTag: ["์นดํŽ˜์ธ ๋Ÿฌ๋ฒ„", "ํ—ฌ์ฐฝ", "์บ๋ฆญํ„ฐ์ปฌ๋ ‰ํ„ฐ", "์บ๋ฆญํ„ฐ์ปฌ๋ ‰ํ„ฐ"] + ) + return cell + case .review(let review): + let cell: ProductDetailReviewCell = collectionView.dequeueReusableCell(for: indexPath) + cell.payload = .init(hasEvaluateView: false, review: review) + return cell + case .landing: + let cell: ActionButtonCell = collectionView.dequeueReusableCell(for: indexPath) + cell.actionButton.setText(with: ActionButtonCell.Constants.Text.showProduct) + return cell + } + } + } + + private func applySnapshot(with productDetail: ProductDetailEntity?, review: ReviewEntity?) { + guard let productDetail, let review else { return } + var snapshot = Snapshot() + snapshot.appendSections([.main]) + snapshot.appendItems([.productDetail(product: productDetail)]) + snapshot.appendItems([.review(review: review)]) + snapshot.appendItems([.landing]) + dataSource?.apply(snapshot, animatingDifferences: false) + } +} + +// MARK: - UICollectionViewDelegateFlowLayout +extension MyDetailReviewViewController: UICollectionViewDelegateFlowLayout { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + guard let item = dataSource?.itemIdentifier(for: indexPath) else { return CGSize.zero } + let screenWidth = collectionView.bounds.width + switch item { + case .productDetail: + return .init(width: screenWidth, height: 136) + case .review(let review): + let estimateHeight: CGFloat = 1000 + let cell = ProductDetailReviewCell() + cell.frame = .init( + origin: .zero, + size: .init(width: screenWidth, height: estimateHeight) + ) + cell.payload = .init(hasEvaluateView: false, review: review) + cell.layoutIfNeeded() + let estimateSize = cell.systemLayoutSizeFitting( + .init(width: screenWidth, height: UIView.layoutFittingCompressedSize.height), + withHorizontalFittingPriority: .required, + verticalFittingPriority: .defaultLow + ) + return estimateSize + case .landing: + return .init(width: screenWidth, height: 40) + } + } +} + +// MARK: - BackNavigationViewDelegate +extension MyDetailReviewViewController: BackNavigationViewDelegate { + func didTapBackButton() { + listener?.didTapBackButton() + } +}
Swift
[C] ์•„๋ž˜์˜ `applySnapshot(with: , review:)` ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์™ธ๋ถ€์—์„œ ์ „๋‹ฌ๋ฐ›๋„๋ก ํ•˜๊ณ  ๋ทฐ์ปจ ๋‚ด๋ถ€์—์„œ๋Š” `productDetail, review` ๊ฐ™์€ ์ •๋ณด๋ฅผ ๋ชจ๋ฅด๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์–ด๋–จ๊นŒ์š”? (๋ทฐ์ปจ์ด ๋ฉ์ฒญํ•˜๋„๋ก..!)
@@ -0,0 +1,96 @@ +// +// MyReviewViewController.swift +// Pyonsnal-Color +// +// Created by ์กฐ์†Œ์ • on 5/19/24. +// + +import ModernRIBs +import UIKit + +protocol MyReviewPresentableListener: AnyObject { + func didTapMyReviewBackButton() + func didTapMyDetailReview(with productDetail: ProductDetailEntity, reviewId: String) +} + +final class MyReviewViewController: UIViewController, + MyReviewPresentable, + MyReviewViewControllable { + + weak var listener: MyReviewPresentableListener? + var viewHolder: MyReviewViewController.ViewHolder = .init() + + override func viewDidLoad() { + super.viewDidLoad() + viewHolder.place(in: view) + viewHolder.configureConstraints(for: view) + self.configureUI() + self.bindActions() + self.configureTableView() + } + + func update(reviews: [ReviewEntity]) { + self.updateNavigationTitle(reviewCount: reviews.count) + } + + // MARK: - Private Mehods + private func configureUI() { + self.view.backgroundColor = .white + } + + private func bindActions() { + self.viewHolder.backNavigationView.delegate = self + } + + private func updateNavigationTitle(reviewCount: Int) { + let updatedTitle = Text.navigationTitleView + "(\(reviewCount))" + self.viewHolder.backNavigationView.setText(with: updatedTitle) + } + + private func configureTableView() { + self.viewHolder.tableView.register( + UITableViewCell.self, + forCellReuseIdentifier: MyReviewContentView.identifier + ) + self.viewHolder.tableView.delegate = self + self.viewHolder.tableView.dataSource = self + } +} + +// MARK: - UITableViewDelegate +extension MyReviewViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + listener?.didTapMyDetailReview(with: ProductDetailEntity(id: "", storeType: .cu, imageURL: URL(string: "www.naver.com")!, name: "", price: "", eventType: nil, productType: .event, updatedTime: "", description: nil, isNew: nil, viewCount: 0, category: nil, isFavorite: nil, originPrice: nil, giftImageURL: nil, giftTitle: nil, giftPrice: nil, isEventExpired: nil, reviews: [], avgScore: nil), reviewId: "1") // TODO: interactor๋กœ๋ถ€ํ„ฐ ๋ฐ›์•„์˜จ ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝ + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return UITableView.automaticDimension + } +} + +// MARK: - UITableViewDataSource +extension MyReviewViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 10 // TODO: interactor๋กœ๋ถ€ํ„ฐ ๋ฐ›์•„์˜จ ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝ + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: MyReviewContentView.identifier, for: indexPath) + cell.selectionStyle = .none // TODO: interactor๋กœ๋ถ€ํ„ฐ ๋ฐ›์•„์˜จ ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝ + cell.contentConfiguration = MyReviewContentConfiguration( + mode: .date, + storeImageIcon: .sevenEleven, + imageUrl: URL(string: "www.naver.com")!, + title: "ํ…Œ์ŠคํŠธ", + date: "2024.05.19" + ) + return cell + } +} + +// MARK: - BackNavigationViewDelegate +extension MyReviewViewController: BackNavigationViewDelegate { + func didTapBackButton() { + listener?.didTapMyReviewBackButton() + } +}
Swift
`automaticDimension` ์ง€์ •ํ•ด์ค€ ์ด์œ ๊ฐ€ ์…€๋งˆ๋‹ค ๋‹ค๋ฅธ ๋†’์ด๊ฐ’ ์ฃผ๊ธฐ ์œ„ํ•ด์„œ ์ธ๊ฐ€์š”?
@@ -0,0 +1,41 @@ +// +// MyReviewContentConfiguration.swift +// Pyonsnal-Color +// +// Created by ์กฐ์†Œ์ • on 5/19/24. +// + +import UIKit + +struct MyReviewContentConfiguration: UIContentConfiguration { + var storeImageIcon: ConvenienceStore + var imageUrl: URL + var title: String + var date: String? + var mode: ProductInfoStackView.Mode + var tastesTag: [String]? + + init( + mode: ProductInfoStackView.Mode, + storeImageIcon: ConvenienceStore, + imageUrl: URL, + title: String, + date: String? = nil, + tastesTag: [String]? = nil + ) { + self.mode = mode + self.storeImageIcon = storeImageIcon + self.imageUrl = imageUrl + self.title = title + self.date = date + self.tastesTag = tastesTag + } + + func makeContentView() -> any UIView & UIContentView { + return MyReviewContentView(configuration: self, mode: mode) + } + + func updated(for state: any UIConfigurationState) -> MyReviewContentConfiguration { + return self + } +}
Swift
`UIContentConfiguration` ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• ๋•๋ถ„์— ๋ฐฐ์› ์Šต๋‹ˆ๋‹ค ๐Ÿ‘