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">© 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">© 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` ํ์ฉํ๋ ๋ฐฉ๋ฒ ๋๋ถ์ ๋ฐฐ์ ์ต๋๋ค ๐ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.