code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,10 @@
+import { Member, ReviewCycle } from './entities';
+
+export type ReviewCycleRequest = {
+ name: ReviewCycle['name'];
+ reviewees: Member['entityId'][];
+ title: string;
+ description: string;
+};
+
+export type ReviewCycleResponse = Pick<ReviewCycle, 'entityId'>; | TypeScript | [์ ์]
์ด๊ฒ๊ณผ entities์ ํ์
์ ์ผ๋ถ ๊ณตํต์ผ๋ก ์ฌ์ฉํด๋ณผ ์๋ ์์ผ๋ ค๋์? ๊ฐ์ ๋งฅ๋ฝ์ ๋ด๊ณ ์๋ ํ์
์ธ๋ฐ ๋งฅ๋ฝ์ด ์์ ๋ถ๋ฆฌ๋์ด์ ๋์ค์ ์ ์ง๋ณด์ํ ๋ ์ฃผ์ํด์ผ๊ฒ ๋ค๋ ์๊ฐ์ด ๋๋ค์ |
@@ -0,0 +1,67 @@
+import { Button, Form, Input, Select, Space } from 'antd';
+import { REVIEW_CYCLE_FORM_NAMES, REVIEW_CYCLE_RULES } from './constants';
+import useMembers from '@apis/review/useMembers';
+import { ReviewCycleRequest } from '@apis/review/type';
+import { ReviewCycle } from '@apis/review/entities';
+
+interface Props {
+ onFinish: (values: ReviewCycleRequest) => void;
+ onReset: () => void;
+ initialValues?: {
+ name: ReviewCycle['name'];
+ reviewees: number[];
+ title: ReviewCycle['question']['title'];
+ description: ReviewCycle['question']['description'];
+ };
+ confirmButtonProps?: { text: string };
+ deleteButtonProps?: { text: string; handleClick: () => void };
+}
+
+export default function ReviewCycleForm({
+ onFinish,
+ onReset,
+ initialValues,
+ confirmButtonProps = { text: 'ํ์ธ' },
+ deleteButtonProps,
+}: Props) {
+ const { members, isLoading } = useMembers();
+
+ return (
+ <Form labelAlign="right" onFinish={onFinish} onReset={onReset} initialValues={initialValues}>
+ <Form.Item label="๋ฆฌ๋ทฐ ์ ์ฑ
์ด๋ฆ" name={REVIEW_CYCLE_FORM_NAMES.name} rules={REVIEW_CYCLE_RULES.reviewCycleName}>
+ <Input />
+ </Form.Item>
+
+ <Form.Item label="๋ฆฌ๋ทฐ ๋ฐ๋ ์ฌ๋" name={REVIEW_CYCLE_FORM_NAMES.reviewees} rules={REVIEW_CYCLE_RULES.reviewees}>
+ <Select
+ mode="multiple"
+ loading={isLoading}
+ placeholder="๋ฆฌ๋ทฐ ๋ฐ๋ ์ฌ๋์ ์ ํํด์ฃผ์ธ์."
+ optionFilterProp="label"
+ options={members?.map(m => ({ key: m.entityId, label: m.name, value: m.entityId }))}
+ />
+ </Form.Item>
+
+ <Form.Item label="์ง๋ฌธ" name={REVIEW_CYCLE_FORM_NAMES.question.title} rules={REVIEW_CYCLE_RULES.questionTitle}>
+ <Input />
+ </Form.Item>
+
+ <Form.Item
+ label="์ง๋ฌธ ์ค๋ช
"
+ name={REVIEW_CYCLE_FORM_NAMES.question.description}
+ rules={REVIEW_CYCLE_RULES.questionDescription}
+ >
+ <Input />
+ </Form.Item>
+ <Form.Item style={{ textAlign: 'right' }}>
+ <Space size={10}>
+ <Button htmlType="reset">์ทจ์</Button>
+ {deleteButtonProps && <Button onClick={deleteButtonProps.handleClick}>{deleteButtonProps.text}</Button>}
+ <Button type="primary" htmlType="submit">
+ {confirmButtonProps.text}
+ </Button>
+ </Space>
+ </Form.Item>
+ </Form>
+ );
+} | Unknown | [์ ๊ทน]
ui๋ฅผ ๋ ๋๋งํ๊ธฐ ์ํ buttonProps๊ฐ ๊ฐ์ฒดํํ๋ก ๋ด๋ ค๊ฐ๋ฉด ๋์ค์ ์ ์ง๋ณด์์ฐจ์์์ ์ด๋ ค์์ด ์์ ๊ฒ ๊ฐ์๋ฐ ๋ฐฉ๋ฒ์ด ์์ผ๋ ค๋์??
confirmButtonProps๋ deleteButtonProps๋ Form์ด๋ผ๋ ๋งฅ๋ฝ์์๋ ์์ ๋ค์ด๊ฐ๋ ๋ ๊ฒ ๊ฐ๋ค๊ณ ํ๋จํ ์๋ ์์ผ๋ ์ค์ ๋ ๋ํ๋ ์ชฝ์์๋ prop์ ๊บผ๋ด์ฐ๋ ์ฐจ์์ ๋ถ๊ณผํด์ ์ด๋ป๊ฒ๋ ๋ถ๋ฆฌ๊ฐ ๋๋ฉด ์ข๊ฒ ๋ค๋ ์๊ฐ์ด ๋ค์ด์. |
@@ -0,0 +1,28 @@
+import { faker } from '@faker-js/faker';
+import { personList } from '@mocks/auth/data';
+import { v4 as uuidv4 } from 'uuid';
+
+const personCount = personList.length;
+
+export const reviewCycleList = Array.from({ length: 10 }, (_, i) => ({
+ entityId: uuidv4(),
+ name: faker.lorem.words(),
+ creator: personList[Math.floor(Math.random() * personCount)],
+ reviewees: shuffleArray(personList).slice(0, Math.floor(Math.random() * personCount) + 1),
+ question: {
+ title: faker.lorem.words(),
+ description: faker.lorem.sentence(),
+ },
+ updatedAt: faker.date.past().toISOString(),
+}));
+
+function shuffleArray<T>(array: T[]) {
+ const result = [...array];
+
+ for (let i = result.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1));
+ [result[i], result[j]] = [result[j], result[i]];
+ }
+
+ return result;
+} | TypeScript | `faker` ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ ์ ํ ์ ์ฐ์๋ค์ ๐ |
@@ -0,0 +1,25 @@
+import { DeleteOutlined } from '@ant-design/icons';
+import { useDeleteReviewCycle, useGetReviewCycles } from '@apis/review/useReviewCycles';
+import { message } from 'antd';
+
+function DeleteButton({ entityId }: { entityId: number }) {
+ const { refetchReviewCycle } = useGetReviewCycles();
+ const { deleteReviewCycle } = useDeleteReviewCycle({
+ entityId,
+ onSuccess: refetchReviewCycle,
+ onError: message.error,
+ });
+
+ return (
+ <button
+ onClick={e => {
+ e.stopPropagation();
+ deleteReviewCycle();
+ }}
+ >
+ <DeleteOutlined />
+ </button>
+ );
+}
+
+export default DeleteButton; | Unknown | [์ ๊ทน]
๋ฒํผ์ธ๋ฐ ๋ฒํผ์ด ์๋ ์ปดํฌ๋ํธ๊ฐ ๋ ๊ฒ ๊ฐ์์.
์์ด์ฝ์ ํด๋ฆญ์ด๋ฒคํธ๋ฅผ ๋ค๋ ๊ฒ์ ๋ํด์๋ ์ด๋ป๊ฒ ์๊ฐํ์๋์ฉ? role=button์ด ๋๋๋ก ํด์ผํ๋ ํ๋ ํ๋จ์ด ๋๋ค์ |
@@ -0,0 +1,163 @@
+import { Person, personIDMap, personMap } from './../auth/data';
+import { API_PATH } from '@apis/constants';
+import { personList } from '@mocks/auth/data';
+import { HttpResponse, http } from 'msw';
+import { reviewCycleList } from './data';
+import { ReviewCycleRequest } from '@apis/review/type';
+import { JWTPayload, JWTVerifyResult, jwtVerify } from 'jose';
+import { v4 as uuidv4 } from 'uuid';
+import { validateAccessToken } from '@mocks/utils';
+import { secretKey } from '@mocks/constants';
+
+export const reviewHandlers = [
+ http.get(API_PATH.MEMBERS, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ return HttpResponse.json({
+ members: personList.map(m => ({
+ entityId: m.entityId,
+ name: m.name,
+ })),
+ });
+ }),
+
+ http.get(API_PATH.REVIEW_CYCLES, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const formatted = reviewCycleList.map(r => ({
+ entityId: r.entityId,
+ name: r.name,
+ creator: r.creator.name,
+ reviewees: r.reviewees.map(m => ({ entityId: m.entityId, name: m.name })),
+ question: {
+ title: r.question.title,
+ description: r.question.description,
+ },
+ updatedAt: r.updatedAt,
+ }));
+
+ return HttpResponse.json({
+ reviewCycles: formatted,
+ });
+ }),
+
+ http.post<never, ReviewCycleRequest>(API_PATH.REVIEW_CYCLES, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const accessToken = request.headers.get('Authorization')?.split(' ')[1];
+ const verified = accessToken && (await jwtVerify(accessToken, secretKey));
+ const email = (verified as JWTVerifyResult<JWTPayload>).payload.email;
+
+ const req = await request.json();
+ const reviewees = req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person));
+
+ reviewCycleList.push({
+ entityId: uuidv4(),
+ name: req.name,
+ creator: personMap.get(email as string) ?? ({} as Person),
+ reviewees: reviewees,
+ question: {
+ title: req.title,
+ description: req.description,
+ },
+ updatedAt: new Date().toISOString(),
+ });
+
+ return HttpResponse.json(
+ {
+ reviewCycle: reviewCycleList[reviewCycleList.length - 1],
+ },
+ {
+ status: 201,
+ },
+ );
+ }),
+
+ http.delete<{ entityId: string }>(`${API_PATH.REVIEW_CYCLES}/:entityId`, async ({ request, params }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const index = reviewCycleList.splice(
+ reviewCycleList.findIndex(r => r.entityId === params.entityId),
+ 1,
+ );
+
+ if (index.length === 0) {
+ return HttpResponse.json(
+ {
+ error: { message: '๋ฆฌ๋ทฐ ์ฌ์ดํด์ด ์กด์ฌํ์ง ์์ต๋๋ค' },
+ },
+ {
+ status: 404,
+ },
+ );
+ }
+
+ return HttpResponse.json({
+ status: 200,
+ });
+ }),
+
+ http.put<{ entityId: string }, ReviewCycleRequest>(
+ `${API_PATH.REVIEW_CYCLES}/:entityId`,
+ async ({ request, params }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const index = reviewCycleList.findIndex(r => r.entityId === params.entityId);
+
+ if (index === -1) {
+ return HttpResponse.json(
+ {
+ error: { message: '๋ฆฌ๋ทฐ ์ฌ์ดํด์ด ์กด์ฌํ์ง ์์ต๋๋ค' },
+ },
+ {
+ status: 404,
+ },
+ );
+ }
+
+ const req = await request.json();
+ const prev = reviewCycleList[index];
+
+ reviewCycleList[index] = {
+ entityId: params.entityId,
+ name: req.name,
+ creator: prev.creator,
+ reviewees: req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)),
+ question: {
+ title: req.title,
+ description: req.description,
+ },
+ updatedAt: new Date().toISOString(),
+ };
+
+ return HttpResponse.json(
+ {
+ entityId: params.entityId,
+ },
+ {
+ status: 200,
+ },
+ );
+ },
+ ),
+]; | TypeScript | ์ฌ๊ธฐ๋ ์ค์ฝํ๊ฐ ๋์ผ๋ `r`๋ณด๋ค๋ `reviewCycle`์ผ๋ก ๋ค์ด๋ฐ ํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์์~ |
@@ -0,0 +1,43 @@
+import { Button } from 'antd';
+import { RoundContent } from 'components/common/RoundContent';
+import useReviewCycleCreateModal from './ReviewCycleModals/useReviewCycleCreateModal';
+import ReviewCycleTable from './ReviewCycleTable';
+import useReviewCycleUpdateModal from './ReviewCycleModals/useReviewCycleUpdateModal';
+import useSelectedReviewCycle from './useSelectedReviewCycle';
+
+function ReviewCycles() {
+ const { selectedReviewCycle } = useSelectedReviewCycle();
+
+ const reviewCycleCreateModal = useReviewCycleCreateModal();
+ const reviewCycleUpdateModal = useReviewCycleUpdateModal({
+ entityId: selectedReviewCycle?.entityId,
+ });
+
+ function openReviewCycleCreateModal() {
+ reviewCycleCreateModal.open();
+ }
+
+ function openReviewCycleUpdateModal() {
+ reviewCycleUpdateModal.open();
+ }
+
+ return (
+ <RoundContent>
+ <RoundContent.Header
+ title="๋ฆฌ๋ทฐ ์ ์ฑ
๋ชฉ๋ก"
+ rightArea={
+ <Button type="primary" size="large" onClick={openReviewCycleCreateModal}>
+ ๋ฆฌ๋ทฐ ์ ์ฑ
์์ฑ
+ </Button>
+ }
+ />
+ <RoundContent.Body>
+ <ReviewCycleTable onRowClick={openReviewCycleUpdateModal} />
+ </RoundContent.Body>
+ {reviewCycleCreateModal.render()}
+ {reviewCycleUpdateModal.render()}
+ </RoundContent>
+ );
+}
+
+export default ReviewCycles; | Unknown | [์ ๊ทน]
์ธ์คํด์ค๋ camelcase๊ฐ ๋๋ฉด ์ข๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,163 @@
+import { Person, personIDMap, personMap } from './../auth/data';
+import { API_PATH } from '@apis/constants';
+import { personList } from '@mocks/auth/data';
+import { HttpResponse, http } from 'msw';
+import { reviewCycleList } from './data';
+import { ReviewCycleRequest } from '@apis/review/type';
+import { JWTPayload, JWTVerifyResult, jwtVerify } from 'jose';
+import { v4 as uuidv4 } from 'uuid';
+import { validateAccessToken } from '@mocks/utils';
+import { secretKey } from '@mocks/constants';
+
+export const reviewHandlers = [
+ http.get(API_PATH.MEMBERS, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ return HttpResponse.json({
+ members: personList.map(m => ({
+ entityId: m.entityId,
+ name: m.name,
+ })),
+ });
+ }),
+
+ http.get(API_PATH.REVIEW_CYCLES, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const formatted = reviewCycleList.map(r => ({
+ entityId: r.entityId,
+ name: r.name,
+ creator: r.creator.name,
+ reviewees: r.reviewees.map(m => ({ entityId: m.entityId, name: m.name })),
+ question: {
+ title: r.question.title,
+ description: r.question.description,
+ },
+ updatedAt: r.updatedAt,
+ }));
+
+ return HttpResponse.json({
+ reviewCycles: formatted,
+ });
+ }),
+
+ http.post<never, ReviewCycleRequest>(API_PATH.REVIEW_CYCLES, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const accessToken = request.headers.get('Authorization')?.split(' ')[1];
+ const verified = accessToken && (await jwtVerify(accessToken, secretKey));
+ const email = (verified as JWTVerifyResult<JWTPayload>).payload.email;
+
+ const req = await request.json();
+ const reviewees = req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person));
+
+ reviewCycleList.push({
+ entityId: uuidv4(),
+ name: req.name,
+ creator: personMap.get(email as string) ?? ({} as Person),
+ reviewees: reviewees,
+ question: {
+ title: req.title,
+ description: req.description,
+ },
+ updatedAt: new Date().toISOString(),
+ });
+
+ return HttpResponse.json(
+ {
+ reviewCycle: reviewCycleList[reviewCycleList.length - 1],
+ },
+ {
+ status: 201,
+ },
+ );
+ }),
+
+ http.delete<{ entityId: string }>(`${API_PATH.REVIEW_CYCLES}/:entityId`, async ({ request, params }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const index = reviewCycleList.splice(
+ reviewCycleList.findIndex(r => r.entityId === params.entityId),
+ 1,
+ );
+
+ if (index.length === 0) {
+ return HttpResponse.json(
+ {
+ error: { message: '๋ฆฌ๋ทฐ ์ฌ์ดํด์ด ์กด์ฌํ์ง ์์ต๋๋ค' },
+ },
+ {
+ status: 404,
+ },
+ );
+ }
+
+ return HttpResponse.json({
+ status: 200,
+ });
+ }),
+
+ http.put<{ entityId: string }, ReviewCycleRequest>(
+ `${API_PATH.REVIEW_CYCLES}/:entityId`,
+ async ({ request, params }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const index = reviewCycleList.findIndex(r => r.entityId === params.entityId);
+
+ if (index === -1) {
+ return HttpResponse.json(
+ {
+ error: { message: '๋ฆฌ๋ทฐ ์ฌ์ดํด์ด ์กด์ฌํ์ง ์์ต๋๋ค' },
+ },
+ {
+ status: 404,
+ },
+ );
+ }
+
+ const req = await request.json();
+ const prev = reviewCycleList[index];
+
+ reviewCycleList[index] = {
+ entityId: params.entityId,
+ name: req.name,
+ creator: prev.creator,
+ reviewees: req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)),
+ question: {
+ title: req.title,
+ description: req.description,
+ },
+ updatedAt: new Date().toISOString(),
+ };
+
+ return HttpResponse.json(
+ {
+ entityId: params.entityId,
+ },
+ {
+ status: 200,
+ },
+ );
+ },
+ ),
+]; | TypeScript | `r`์ด ์ค๋ณต ๋ณ์๋ผ ์ฌ๊ธฐ๋ `m`์ด ๋์๊ตฐ์..
`r`์ `reviewCycle`๋ก ๋ฐ๊พธ๋ฉด ์ฌ๊ธฐ๋ `r`์ด์ด๋ ๊ด์ฐฎ์๋ณด์
๋๋ค. ํน์ ์ข ๋ ๋ช
ํํ `reviewee`์ด๋ ์ข๊ฒ ๊ตฌ์!
์ทจํฅ ์ฐจ์ด์ผ ์ ์๊ฒ ์ง๋ง ๊ฐ์ธ์ ์ผ๋ก๋ ํ ์ค ์ ๋์ ์ค์ฝํ์ผ ๋๋ ์ถ์ฝ ๋ณ์ ์ฌ์ฉํด๋ ํฌ๊ฒ ๊ฐ๋
์ฑ์ ํด์น์ง ์์ ๊ด์ฐฎ๋ค๊ณ ์๊ฐํด์~ |
@@ -0,0 +1,163 @@
+import { Person, personIDMap, personMap } from './../auth/data';
+import { API_PATH } from '@apis/constants';
+import { personList } from '@mocks/auth/data';
+import { HttpResponse, http } from 'msw';
+import { reviewCycleList } from './data';
+import { ReviewCycleRequest } from '@apis/review/type';
+import { JWTPayload, JWTVerifyResult, jwtVerify } from 'jose';
+import { v4 as uuidv4 } from 'uuid';
+import { validateAccessToken } from '@mocks/utils';
+import { secretKey } from '@mocks/constants';
+
+export const reviewHandlers = [
+ http.get(API_PATH.MEMBERS, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ return HttpResponse.json({
+ members: personList.map(m => ({
+ entityId: m.entityId,
+ name: m.name,
+ })),
+ });
+ }),
+
+ http.get(API_PATH.REVIEW_CYCLES, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const formatted = reviewCycleList.map(r => ({
+ entityId: r.entityId,
+ name: r.name,
+ creator: r.creator.name,
+ reviewees: r.reviewees.map(m => ({ entityId: m.entityId, name: m.name })),
+ question: {
+ title: r.question.title,
+ description: r.question.description,
+ },
+ updatedAt: r.updatedAt,
+ }));
+
+ return HttpResponse.json({
+ reviewCycles: formatted,
+ });
+ }),
+
+ http.post<never, ReviewCycleRequest>(API_PATH.REVIEW_CYCLES, async ({ request }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const accessToken = request.headers.get('Authorization')?.split(' ')[1];
+ const verified = accessToken && (await jwtVerify(accessToken, secretKey));
+ const email = (verified as JWTVerifyResult<JWTPayload>).payload.email;
+
+ const req = await request.json();
+ const reviewees = req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person));
+
+ reviewCycleList.push({
+ entityId: uuidv4(),
+ name: req.name,
+ creator: personMap.get(email as string) ?? ({} as Person),
+ reviewees: reviewees,
+ question: {
+ title: req.title,
+ description: req.description,
+ },
+ updatedAt: new Date().toISOString(),
+ });
+
+ return HttpResponse.json(
+ {
+ reviewCycle: reviewCycleList[reviewCycleList.length - 1],
+ },
+ {
+ status: 201,
+ },
+ );
+ }),
+
+ http.delete<{ entityId: string }>(`${API_PATH.REVIEW_CYCLES}/:entityId`, async ({ request, params }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const index = reviewCycleList.splice(
+ reviewCycleList.findIndex(r => r.entityId === params.entityId),
+ 1,
+ );
+
+ if (index.length === 0) {
+ return HttpResponse.json(
+ {
+ error: { message: '๋ฆฌ๋ทฐ ์ฌ์ดํด์ด ์กด์ฌํ์ง ์์ต๋๋ค' },
+ },
+ {
+ status: 404,
+ },
+ );
+ }
+
+ return HttpResponse.json({
+ status: 200,
+ });
+ }),
+
+ http.put<{ entityId: string }, ReviewCycleRequest>(
+ `${API_PATH.REVIEW_CYCLES}/:entityId`,
+ async ({ request, params }) => {
+ const res = await validateAccessToken(request);
+
+ if (res) {
+ return res;
+ }
+
+ const index = reviewCycleList.findIndex(r => r.entityId === params.entityId);
+
+ if (index === -1) {
+ return HttpResponse.json(
+ {
+ error: { message: '๋ฆฌ๋ทฐ ์ฌ์ดํด์ด ์กด์ฌํ์ง ์์ต๋๋ค' },
+ },
+ {
+ status: 404,
+ },
+ );
+ }
+
+ const req = await request.json();
+ const prev = reviewCycleList[index];
+
+ reviewCycleList[index] = {
+ entityId: params.entityId,
+ name: req.name,
+ creator: prev.creator,
+ reviewees: req.reviewees.map(id => personIDMap.get(id) ?? ({} as Person)),
+ question: {
+ title: req.title,
+ description: req.description,
+ },
+ updatedAt: new Date().toISOString(),
+ };
+
+ return HttpResponse.json(
+ {
+ entityId: params.entityId,
+ },
+ {
+ status: 200,
+ },
+ );
+ },
+ ),
+]; | TypeScript | [์ ์]
์๋๋ก `push`๋ฅผ ํ๋ฉด ๋งจ ๋ค์ ๋ค์ด๊ฐ๊ฒ ๋ผ์ ์ต์ ์์ผ๋ก ๋ณด์ด์ง ์๊ฒ ๋๋๋ผ๊ตฌ์~
์ ๋ ฌ์ ํ ๋ฒ ํด ์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,10 @@
+import { Member, ReviewCycle } from './entities';
+
+export type ReviewCycleRequest = {
+ name: ReviewCycle['name'];
+ reviewees: Member['entityId'][];
+ title: string;
+ description: string;
+};
+
+export type ReviewCycleResponse = Pick<ReviewCycle, 'entityId'>; | TypeScript | ์ ์๋์ฒ๋ผ ํ์ดํํ๋ฉด ๊ฐ์ ๋งฅ๋ฝ์์ด ์ ๋๋ฌ๋๋ ค๋์?
```ts
export type ReviewCycleRequest = {
name: ReviewCycle['name'];
reviewees: Member['entityId'][];
title: string;
description: string;
};
export type ReviewCycleResponse = Pick<ReviewCycle, 'entityId'>;
``` |
@@ -0,0 +1,90 @@
+import { API_PATH } from '@apis/constants';
+import { useQuery } from '@apis/common/useQuery';
+import { ReviewCycle } from './entities';
+import { ReviewCycleRequest, ReviewCycleResponse } from './type';
+import { useDelete, usePost, usePut } from '@apis/common/useMutation';
+import { get } from 'lodash';
+
+export function useGetReviewCycles() {
+ const {
+ data,
+ isLoading,
+ mutate: refetchReviewCycle,
+ } = useQuery<{ reviewCycles: ReviewCycle[] }>(API_PATH.REVIEW_CYCLES);
+
+ return {
+ reviewCycles: data?.reviewCycles,
+ isLoading,
+ refetchReviewCycle,
+ };
+}
+
+export function useCreateReviewCycle({
+ onSuccess,
+ onError,
+}: {
+ onSuccess: () => void;
+ onError: (message: string) => void;
+}) {
+ const { trigger, isMutating } = usePost<ReviewCycleRequest, ReviewCycleResponse>({
+ endpoint: API_PATH.REVIEW_CYCLES,
+ onSuccess: onSuccess,
+ onError: err => {
+ const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์ฌ์ดํด ์์ฑ์ ์คํจํ์ต๋๋ค.');
+ onError(errorMessage);
+ },
+ });
+
+ return {
+ createReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle),
+ isMutating,
+ };
+}
+
+export function useUpdateReviewCycle({
+ entityId,
+ onSuccess,
+ onError,
+}: {
+ entityId?: number;
+ onSuccess: () => void;
+ onError: (message: string) => void;
+}) {
+ const { trigger, isMutating } = usePut<ReviewCycleRequest, ReviewCycleResponse>({
+ endpoint: entityId ? `${API_PATH.REVIEW_CYCLES}/${entityId}` : null,
+ onSuccess: onSuccess,
+ onError: err => {
+ const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์ฌ์ดํด ์์ ์ ์คํจํ์ต๋๋ค.');
+ onError(errorMessage);
+ },
+ });
+
+ return {
+ updateReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle),
+ isMutating,
+ };
+}
+
+export function useDeleteReviewCycle({
+ entityId,
+ onSuccess,
+ onError,
+}: {
+ entityId: number;
+ onSuccess: () => void;
+ onError: (message: string) => void;
+}) {
+ const { trigger, isMutating } = useDelete({
+ endpoint: `${API_PATH.REVIEW_CYCLES}/${entityId}`,
+ onSuccess,
+ onError: err => {
+ const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์ฌ์ดํด ์ญ์ ์ ์คํจํ์ต๋๋ค.');
+ onError(errorMessage);
+ },
+ });
+
+ return {
+ deleteReviewCycle: trigger,
+ isMutating,
+ };
+} | TypeScript | ์ด ๋ถ๋ถ์ SWR ๊ธฐ๋ฐ์ ์ธํฐํ์ด์ค(trigger)๋ฅผ ๊ฐ์ถ๊ณ ์ธํฐํ์ด์ค๋ฅผ ํต์ผํ๊ธฐ ์ํ ๋ชฉ์ ์ด์์ด์. ์ถํ์ SWR์ tanstack-query ๋ฑ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ๋ณ๊ฒฝํ๋๋ผ๋ ๋์ผํ๊ฒ createReviewCycle ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๋๋ก ํด์ ์ฌ์ฉ์ฒ์์๋ ์ฝ๋๋ฅผ ์์ ํ ํ์๊ฐ ์๋๋ก ํ๊ณ ์ ํ์ต๋๋ค. |
@@ -0,0 +1,17 @@
+import { Rule } from 'antd/lib/form';
+
+export const REVIEW_CYCLE_FORM_NAMES = {
+ name: 'name',
+ reviewees: 'reviewees',
+ question: {
+ title: 'title',
+ description: 'description',
+ },
+} as const;
+
+export const REVIEW_CYCLE_RULES: Record<string, Rule[]> = {
+ reviewCycleName: [{ required: true, message: '๋ฆฌ๋ทฐ ์ ์ฑ
์ด๋ฆ์ ์
๋ ฅํ์ธ์.' }],
+ reviewees: [{ required: true, message: '๋ฆฌ๋ทฐ ๋ฐ๋ ์ฌ๋์ ์ ํํ์ธ์.' }],
+ questionTitle: [{ required: true, message: '์ง๋ฌธ ์ ๋ชฉ์ ์
๋ ฅํ์ธ์.' }],
+ questionDescription: [{ required: true, message: '์ง๋ฌธ ์ค๋ช
์ ์
๋ ฅํ์ธ์.' }],
+}; | TypeScript | ํด๋น form์ ์์๊ฐ ์ด๋ป๊ฒ ๊ตฌ์ฑ๋์ด ์๋์ง ํ๋์ ํ์
ํ๊ธฐ ์ฝ์ง ์์๊น ํ์๋๋ฐ, ํ๋์ ๊ฐ์ฒด๋ก ๋ฌถ๋๊ฒ ๋์์ผ๋ ค๋ ์ถ๊ตฐ์! |
@@ -0,0 +1,25 @@
+import { DeleteOutlined } from '@ant-design/icons';
+import { useDeleteReviewCycle, useGetReviewCycles } from '@apis/review/useReviewCycles';
+import { message } from 'antd';
+
+function DeleteButton({ entityId }: { entityId: number }) {
+ const { refetchReviewCycle } = useGetReviewCycles();
+ const { deleteReviewCycle } = useDeleteReviewCycle({
+ entityId,
+ onSuccess: refetchReviewCycle,
+ onError: message.error,
+ });
+
+ return (
+ <button
+ onClick={e => {
+ e.stopPropagation();
+ deleteReviewCycle();
+ }}
+ >
+ <DeleteOutlined />
+ </button>
+ );
+}
+
+export default DeleteButton; | Unknown | ํ์ฌ ํ
์ด๋ธ onRowClick ์ ๋ฆฌ๋ทฐ ์ฌ์ดํด ์์ ๋ชจ๋ฌ์ด ์ด๋ฆฌ๋๋ก ์ด๋ฒคํธ๋ฅผ ๋ฑ๋กํด๋์๋๋ฐ์, ์ญ์ ๋ฒํผ ์์๋ ์ด๋ฒคํธ ์ ํ๋ฅผ ๋ง๋๋ก ํ์ต๋๋ค. |
@@ -0,0 +1,25 @@
+import { DeleteOutlined } from '@ant-design/icons';
+import { useDeleteReviewCycle, useGetReviewCycles } from '@apis/review/useReviewCycles';
+import { message } from 'antd';
+
+function DeleteButton({ entityId }: { entityId: number }) {
+ const { refetchReviewCycle } = useGetReviewCycles();
+ const { deleteReviewCycle } = useDeleteReviewCycle({
+ entityId,
+ onSuccess: refetchReviewCycle,
+ onError: message.error,
+ });
+
+ return (
+ <button
+ onClick={e => {
+ e.stopPropagation();
+ deleteReviewCycle();
+ }}
+ >
+ <DeleteOutlined />
+ </button>
+ );
+}
+
+export default DeleteButton; | Unknown | ๋ต button์ผ๋ก ๊ฐ์ธ๋๊ฒ ์ข๊ฒ ๊ตฐ์.
> ๋ฐ์ํ์ต๋๋ค! [refactor: ์ญ์ ๋ฒํผ ๊ตฌ์กฐ ๋ณ๊ฒฝ](https://github.com/lemonbase-labs/journee-on-boarding-project/pull/7/commits/2201091e80c11c71bb97c3cf131410067cb04478) |
@@ -0,0 +1,67 @@
+import { Button, Form, Input, Select, Space } from 'antd';
+import { REVIEW_CYCLE_FORM_NAMES, REVIEW_CYCLE_RULES } from './constants';
+import useMembers from '@apis/review/useMembers';
+import { ReviewCycleRequest } from '@apis/review/type';
+import { ReviewCycle } from '@apis/review/entities';
+
+interface Props {
+ onFinish: (values: ReviewCycleRequest) => void;
+ onReset: () => void;
+ initialValues?: {
+ name: ReviewCycle['name'];
+ reviewees: number[];
+ title: ReviewCycle['question']['title'];
+ description: ReviewCycle['question']['description'];
+ };
+ confirmButtonProps?: { text: string };
+ deleteButtonProps?: { text: string; handleClick: () => void };
+}
+
+export default function ReviewCycleForm({
+ onFinish,
+ onReset,
+ initialValues,
+ confirmButtonProps = { text: 'ํ์ธ' },
+ deleteButtonProps,
+}: Props) {
+ const { members, isLoading } = useMembers();
+
+ return (
+ <Form labelAlign="right" onFinish={onFinish} onReset={onReset} initialValues={initialValues}>
+ <Form.Item label="๋ฆฌ๋ทฐ ์ ์ฑ
์ด๋ฆ" name={REVIEW_CYCLE_FORM_NAMES.name} rules={REVIEW_CYCLE_RULES.reviewCycleName}>
+ <Input />
+ </Form.Item>
+
+ <Form.Item label="๋ฆฌ๋ทฐ ๋ฐ๋ ์ฌ๋" name={REVIEW_CYCLE_FORM_NAMES.reviewees} rules={REVIEW_CYCLE_RULES.reviewees}>
+ <Select
+ mode="multiple"
+ loading={isLoading}
+ placeholder="๋ฆฌ๋ทฐ ๋ฐ๋ ์ฌ๋์ ์ ํํด์ฃผ์ธ์."
+ optionFilterProp="label"
+ options={members?.map(m => ({ key: m.entityId, label: m.name, value: m.entityId }))}
+ />
+ </Form.Item>
+
+ <Form.Item label="์ง๋ฌธ" name={REVIEW_CYCLE_FORM_NAMES.question.title} rules={REVIEW_CYCLE_RULES.questionTitle}>
+ <Input />
+ </Form.Item>
+
+ <Form.Item
+ label="์ง๋ฌธ ์ค๋ช
"
+ name={REVIEW_CYCLE_FORM_NAMES.question.description}
+ rules={REVIEW_CYCLE_RULES.questionDescription}
+ >
+ <Input />
+ </Form.Item>
+ <Form.Item style={{ textAlign: 'right' }}>
+ <Space size={10}>
+ <Button htmlType="reset">์ทจ์</Button>
+ {deleteButtonProps && <Button onClick={deleteButtonProps.handleClick}>{deleteButtonProps.text}</Button>}
+ <Button type="primary" htmlType="submit">
+ {confirmButtonProps.text}
+ </Button>
+ </Space>
+ </Form.Item>
+ </Form>
+ );
+} | Unknown | ์ํ.. ์ ๋ ์ง๊ด์ ์ด๋ผ๊ณ ์๊ฐํ๋๋ฐ, ์ ์ง๋ณด์ ์ฐจ์์์ ์ด๋ค ์ด๋ ค์์ธ์ง ํน์ ์ด๋ป๊ฒ ๋ถ๋ฆฌ๋์ด์ผ ํ๋์ง ์ข ๋ ์ค๋ช
ํด์ฃผ์ค ์ ์์๊น์?
์ค์ ๋ก ํ์ฌ ๋ ๋ชฌ๋ฒ ์ด์ค ๋ชจ๋ฌ ํ
์ธ useBasicModal๋ ๋น์ทํ ํจํด์ผ๋ก ์ฌ์ฉํ๊ณ ์๋๋ฐ, ์ ๋ ์ ์ง๋ณด์ ์ฐจ์์์ ์ด๋ ค์์ด ์์ด์ ๊ฐ์ ํด์ผ ํ๋ค๊ณ ์๊ฐํ์ง ์์์ด์์! |
@@ -0,0 +1,43 @@
+import { Button } from 'antd';
+import { RoundContent } from 'components/common/RoundContent';
+import useReviewCycleCreateModal from './ReviewCycleModals/useReviewCycleCreateModal';
+import ReviewCycleTable from './ReviewCycleTable';
+import useReviewCycleUpdateModal from './ReviewCycleModals/useReviewCycleUpdateModal';
+import useSelectedReviewCycle from './useSelectedReviewCycle';
+
+function ReviewCycles() {
+ const { selectedReviewCycle } = useSelectedReviewCycle();
+
+ const reviewCycleCreateModal = useReviewCycleCreateModal();
+ const reviewCycleUpdateModal = useReviewCycleUpdateModal({
+ entityId: selectedReviewCycle?.entityId,
+ });
+
+ function openReviewCycleCreateModal() {
+ reviewCycleCreateModal.open();
+ }
+
+ function openReviewCycleUpdateModal() {
+ reviewCycleUpdateModal.open();
+ }
+
+ return (
+ <RoundContent>
+ <RoundContent.Header
+ title="๋ฆฌ๋ทฐ ์ ์ฑ
๋ชฉ๋ก"
+ rightArea={
+ <Button type="primary" size="large" onClick={openReviewCycleCreateModal}>
+ ๋ฆฌ๋ทฐ ์ ์ฑ
์์ฑ
+ </Button>
+ }
+ />
+ <RoundContent.Body>
+ <ReviewCycleTable onRowClick={openReviewCycleUpdateModal} />
+ </RoundContent.Body>
+ {reviewCycleCreateModal.render()}
+ {reviewCycleUpdateModal.render()}
+ </RoundContent>
+ );
+}
+
+export default ReviewCycles; | Unknown | ๋ค!! ๋ฐ์ํ์ต๋๋ค!
[refactor: ์ธ์คํด์ค camelcase๋ก ์์ ](https://github.com/lemonbase-labs/journee-on-boarding-project/pull/7/commits/3a4fecb79aa6c1a53951900d79c308af0a87d940) |
@@ -0,0 +1,90 @@
+import { API_PATH } from '@apis/constants';
+import { useQuery } from '@apis/common/useQuery';
+import { ReviewCycle } from './entities';
+import { ReviewCycleRequest, ReviewCycleResponse } from './type';
+import { useDelete, usePost, usePut } from '@apis/common/useMutation';
+import { get } from 'lodash';
+
+export function useGetReviewCycles() {
+ const {
+ data,
+ isLoading,
+ mutate: refetchReviewCycle,
+ } = useQuery<{ reviewCycles: ReviewCycle[] }>(API_PATH.REVIEW_CYCLES);
+
+ return {
+ reviewCycles: data?.reviewCycles,
+ isLoading,
+ refetchReviewCycle,
+ };
+}
+
+export function useCreateReviewCycle({
+ onSuccess,
+ onError,
+}: {
+ onSuccess: () => void;
+ onError: (message: string) => void;
+}) {
+ const { trigger, isMutating } = usePost<ReviewCycleRequest, ReviewCycleResponse>({
+ endpoint: API_PATH.REVIEW_CYCLES,
+ onSuccess: onSuccess,
+ onError: err => {
+ const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์ฌ์ดํด ์์ฑ์ ์คํจํ์ต๋๋ค.');
+ onError(errorMessage);
+ },
+ });
+
+ return {
+ createReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle),
+ isMutating,
+ };
+}
+
+export function useUpdateReviewCycle({
+ entityId,
+ onSuccess,
+ onError,
+}: {
+ entityId?: number;
+ onSuccess: () => void;
+ onError: (message: string) => void;
+}) {
+ const { trigger, isMutating } = usePut<ReviewCycleRequest, ReviewCycleResponse>({
+ endpoint: entityId ? `${API_PATH.REVIEW_CYCLES}/${entityId}` : null,
+ onSuccess: onSuccess,
+ onError: err => {
+ const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์ฌ์ดํด ์์ ์ ์คํจํ์ต๋๋ค.');
+ onError(errorMessage);
+ },
+ });
+
+ return {
+ updateReviewCycle: (reviewCycle: ReviewCycleRequest) => trigger(reviewCycle),
+ isMutating,
+ };
+}
+
+export function useDeleteReviewCycle({
+ entityId,
+ onSuccess,
+ onError,
+}: {
+ entityId: number;
+ onSuccess: () => void;
+ onError: (message: string) => void;
+}) {
+ const { trigger, isMutating } = useDelete({
+ endpoint: `${API_PATH.REVIEW_CYCLES}/${entityId}`,
+ onSuccess,
+ onError: err => {
+ const errorMessage = get(err, 'response.data.error.message', '๋ฆฌ๋ทฐ ์ฌ์ดํด ์ญ์ ์ ์คํจํ์ต๋๋ค.');
+ onError(errorMessage);
+ },
+ });
+
+ return {
+ deleteReviewCycle: trigger,
+ isMutating,
+ };
+} | TypeScript | ์คํธ ์ธํฐํ์ด์ค ํต์ผ ๋ชฉ์ ! ์ดํดํ์ต๋๋ค~
๊ณ ๋ ๋ค๋ฉด ๊ฐ์ ํ์ผ [L87](https://github.com/lemonbase-labs/journee-on-boarding-project/pull/7/files#diff-3ab91e36eb619267b0f18915f2e642a8452aece2c4e8220b0bce854dc2e8d68eR87)์ `deleteReviewCycle: trigger`๋ ์ ์ฒ๋ฆฌ๊ฐ ๋๋ฝ๋ ๊ฒ ๊ฐ์ ๊ฐ์ด ๋ฐ์ํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์~ |
@@ -0,0 +1,177 @@
+@import '../../../styles/variable.scss';
+
+@mixin flex {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
+
+@mixin login-input {
+ width: 266px;
+ height: 36px;
+ border: $boxBorder;
+ background-color: #fafafa;
+ color: #a4a4a4;
+ border-radius: 2px;
+ margin-bottom: 6px;
+ font-size: 12px;
+ padding-left: 8px;
+}
+
+.Login {
+ background-color: $backGroundColor;
+
+ .main-box {
+ width: 350px;
+ height: 385px;
+ border: $boxBorder;
+ background-color: $white;
+ margin: 44px auto 10px auto;
+
+ .logo {
+ font-family: 'lobster';
+ font-size: 40px;
+ letter-spacing: -1px;
+ text-align: center;
+ margin: 40px auto;
+ }
+
+ .login-wrap {
+ display: flex;
+ justify-content: center;
+ flex-wrap: wrap;
+ margin-bottom: 8px;
+
+ .nameEmail {
+ @include login-input;
+ &:focus {
+ outline: 1px solid #a8a8a8;
+ }
+ }
+
+ .passWord {
+ @include login-input;
+ &:focus {
+ outline: 1px solid #a8a8a8;
+ }
+ }
+
+ .login-btn {
+ width: 266px;
+ height: 30px;
+ margin: 8px 0;
+ border: none;
+ border-radius: 4px;
+ background-color: $instaBlue;
+ opacity: 1;
+ color: $white;
+ font-size: 13.5px;
+ font-weight: bold;
+ cursor: pointer;
+
+ &:disabled {
+ opacity: 0.5;
+ }
+ }
+ }
+
+ .or-wrap {
+ @include flex;
+
+ .or-line {
+ width: 105px;
+ height: 1px;
+ background-color: #dbdbdb;
+ align-items: center;
+ }
+
+ .or {
+ font-size: 13px;
+ font-weight: bold;
+ color: #a8a8a8;
+ margin: 0 17px;
+ }
+ }
+
+ .facebook-login {
+ @include flex;
+ margin: 20px auto;
+ color: none;
+
+ .facebook-btn {
+ background-color: transparent;
+ border: none;
+ cursor: pointer;
+ }
+
+ .facebook-icon {
+ width: 16px;
+ height: 16px;
+ margin-right: 5px;
+ }
+
+ span {
+ color: $faceBookColor;
+ font-weight: bold;
+ position: relative;
+ bottom: 2px;
+ }
+ }
+
+ .forgot-password {
+ color: $faceBookColor;
+ font-size: 12px;
+ text-align: center;
+
+ .forgot-btn {
+ color: $faceBookColor;
+ background-color: transparent;
+ cursor: pointer;
+
+ &:visited {
+ color: transparent;
+ }
+ }
+ }
+ }
+
+ .join-box {
+ width: 350px;
+ height: 60px;
+ border: 1px solid #dbdbdb;
+ background-color: $white;
+ text-align: center;
+ margin: 0 auto 20px auto;
+ @include flex;
+
+ .let-join {
+ font-size: 14px;
+
+ .signup-btn {
+ font-weight: bold;
+ color: $instaBlue;
+ background-color: transparent;
+ cursor: pointer;
+ }
+ }
+ }
+
+ .app-down {
+ .app-down-text {
+ text-align: center;
+ font-size: 14px;
+ }
+
+ .download-image {
+ display: flex;
+ justify-content: center;
+
+ .appstore-link,
+ .googleplay-link {
+ width: 136px;
+ height: 40px;
+ margin: 20px 4px;
+ }
+ }
+ }
+} | Unknown | - index.js์์ importํ๊ธฐ ๋๋ฌธ์ ์ฌ๊ธฐ์๋ ์ํ์
๋ ๋ฉ๋๋ค. |
@@ -0,0 +1,177 @@
+@import '../../../styles/variable.scss';
+
+@mixin flex {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
+
+@mixin login-input {
+ width: 266px;
+ height: 36px;
+ border: $boxBorder;
+ background-color: #fafafa;
+ color: #a4a4a4;
+ border-radius: 2px;
+ margin-bottom: 6px;
+ font-size: 12px;
+ padding-left: 8px;
+}
+
+.Login {
+ background-color: $backGroundColor;
+
+ .main-box {
+ width: 350px;
+ height: 385px;
+ border: $boxBorder;
+ background-color: $white;
+ margin: 44px auto 10px auto;
+
+ .logo {
+ font-family: 'lobster';
+ font-size: 40px;
+ letter-spacing: -1px;
+ text-align: center;
+ margin: 40px auto;
+ }
+
+ .login-wrap {
+ display: flex;
+ justify-content: center;
+ flex-wrap: wrap;
+ margin-bottom: 8px;
+
+ .nameEmail {
+ @include login-input;
+ &:focus {
+ outline: 1px solid #a8a8a8;
+ }
+ }
+
+ .passWord {
+ @include login-input;
+ &:focus {
+ outline: 1px solid #a8a8a8;
+ }
+ }
+
+ .login-btn {
+ width: 266px;
+ height: 30px;
+ margin: 8px 0;
+ border: none;
+ border-radius: 4px;
+ background-color: $instaBlue;
+ opacity: 1;
+ color: $white;
+ font-size: 13.5px;
+ font-weight: bold;
+ cursor: pointer;
+
+ &:disabled {
+ opacity: 0.5;
+ }
+ }
+ }
+
+ .or-wrap {
+ @include flex;
+
+ .or-line {
+ width: 105px;
+ height: 1px;
+ background-color: #dbdbdb;
+ align-items: center;
+ }
+
+ .or {
+ font-size: 13px;
+ font-weight: bold;
+ color: #a8a8a8;
+ margin: 0 17px;
+ }
+ }
+
+ .facebook-login {
+ @include flex;
+ margin: 20px auto;
+ color: none;
+
+ .facebook-btn {
+ background-color: transparent;
+ border: none;
+ cursor: pointer;
+ }
+
+ .facebook-icon {
+ width: 16px;
+ height: 16px;
+ margin-right: 5px;
+ }
+
+ span {
+ color: $faceBookColor;
+ font-weight: bold;
+ position: relative;
+ bottom: 2px;
+ }
+ }
+
+ .forgot-password {
+ color: $faceBookColor;
+ font-size: 12px;
+ text-align: center;
+
+ .forgot-btn {
+ color: $faceBookColor;
+ background-color: transparent;
+ cursor: pointer;
+
+ &:visited {
+ color: transparent;
+ }
+ }
+ }
+ }
+
+ .join-box {
+ width: 350px;
+ height: 60px;
+ border: 1px solid #dbdbdb;
+ background-color: $white;
+ text-align: center;
+ margin: 0 auto 20px auto;
+ @include flex;
+
+ .let-join {
+ font-size: 14px;
+
+ .signup-btn {
+ font-weight: bold;
+ color: $instaBlue;
+ background-color: transparent;
+ cursor: pointer;
+ }
+ }
+ }
+
+ .app-down {
+ .app-down-text {
+ text-align: center;
+ font-size: 14px;
+ }
+
+ .download-image {
+ display: flex;
+ justify-content: center;
+
+ .appstore-link,
+ .googleplay-link {
+ width: 136px;
+ height: 40px;
+ margin: 20px 4px;
+ }
+ }
+ }
+} | Unknown | - mixin ์ฌ์ฉํด์ฃผ์ ๊ฒ ์ข์ต๋๋ค.
- ๋ค๋ฅธ ๋ถ๋ค๊น์ง ์ฌ์ฉํ์ค ์ ์๋ ๋ถ๋ถ์ด๋ผ๊ณ ์๊ฐ๋์๋ฉด variables.scss๋ก ์ฎ๊ฒจ์ ์งํํด ์ฃผ์ธ์. |
@@ -0,0 +1,177 @@
+@import '../../../styles/variable.scss';
+
+@mixin flex {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
+
+@mixin login-input {
+ width: 266px;
+ height: 36px;
+ border: $boxBorder;
+ background-color: #fafafa;
+ color: #a4a4a4;
+ border-radius: 2px;
+ margin-bottom: 6px;
+ font-size: 12px;
+ padding-left: 8px;
+}
+
+.Login {
+ background-color: $backGroundColor;
+
+ .main-box {
+ width: 350px;
+ height: 385px;
+ border: $boxBorder;
+ background-color: $white;
+ margin: 44px auto 10px auto;
+
+ .logo {
+ font-family: 'lobster';
+ font-size: 40px;
+ letter-spacing: -1px;
+ text-align: center;
+ margin: 40px auto;
+ }
+
+ .login-wrap {
+ display: flex;
+ justify-content: center;
+ flex-wrap: wrap;
+ margin-bottom: 8px;
+
+ .nameEmail {
+ @include login-input;
+ &:focus {
+ outline: 1px solid #a8a8a8;
+ }
+ }
+
+ .passWord {
+ @include login-input;
+ &:focus {
+ outline: 1px solid #a8a8a8;
+ }
+ }
+
+ .login-btn {
+ width: 266px;
+ height: 30px;
+ margin: 8px 0;
+ border: none;
+ border-radius: 4px;
+ background-color: $instaBlue;
+ opacity: 1;
+ color: $white;
+ font-size: 13.5px;
+ font-weight: bold;
+ cursor: pointer;
+
+ &:disabled {
+ opacity: 0.5;
+ }
+ }
+ }
+
+ .or-wrap {
+ @include flex;
+
+ .or-line {
+ width: 105px;
+ height: 1px;
+ background-color: #dbdbdb;
+ align-items: center;
+ }
+
+ .or {
+ font-size: 13px;
+ font-weight: bold;
+ color: #a8a8a8;
+ margin: 0 17px;
+ }
+ }
+
+ .facebook-login {
+ @include flex;
+ margin: 20px auto;
+ color: none;
+
+ .facebook-btn {
+ background-color: transparent;
+ border: none;
+ cursor: pointer;
+ }
+
+ .facebook-icon {
+ width: 16px;
+ height: 16px;
+ margin-right: 5px;
+ }
+
+ span {
+ color: $faceBookColor;
+ font-weight: bold;
+ position: relative;
+ bottom: 2px;
+ }
+ }
+
+ .forgot-password {
+ color: $faceBookColor;
+ font-size: 12px;
+ text-align: center;
+
+ .forgot-btn {
+ color: $faceBookColor;
+ background-color: transparent;
+ cursor: pointer;
+
+ &:visited {
+ color: transparent;
+ }
+ }
+ }
+ }
+
+ .join-box {
+ width: 350px;
+ height: 60px;
+ border: 1px solid #dbdbdb;
+ background-color: $white;
+ text-align: center;
+ margin: 0 auto 20px auto;
+ @include flex;
+
+ .let-join {
+ font-size: 14px;
+
+ .signup-btn {
+ font-weight: bold;
+ color: $instaBlue;
+ background-color: transparent;
+ cursor: pointer;
+ }
+ }
+ }
+
+ .app-down {
+ .app-down-text {
+ text-align: center;
+ font-size: 14px;
+ }
+
+ .download-image {
+ display: flex;
+ justify-content: center;
+
+ .appstore-link,
+ .googleplay-link {
+ width: 136px;
+ height: 40px;
+ margin: 20px 4px;
+ }
+ }
+ }
+} | Unknown | - nesting ํด์ฃผ์ธ์.
- ๋ ํ๊ทธ๋ฅผ ์ด์ฉํ ์์ฑ ์ฃผ์๋ ๊ฒ์ ์งํฅํด ์ฃผ์๊ณ className์ ํ์ฉํด ์ฃผ์ธ์. |
@@ -1,7 +1,138 @@
-import React from 'react';
+import React, { useState } from 'react';
+import { useNavigate, Link } from 'react-router-dom';
-function Login() {
- return <div>Gaeul Login</div>;
-}
+const Login = () => {
+ const [inputValues, setInputValues] = useState({
+ userId: '',
+ password: '',
+ });
+
+ const handleInput = event => {
+ const { name, value } = event.target;
+ setInputValues({ ...inputValues, [name]: value });
+ };
+
+ const isValidLogin = !(
+ inputValues.userId.includes('@') && inputValues.password.length >= 5
+ );
+
+ const navigate = useNavigate();
+
+ function signUp(e) {
+ e.preventDefault();
+ fetch('http://10.58.2.36:3001/auth/signup', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json;charset=utf-8' },
+ body: JSON.stringify({
+ email: inputValues.userId,
+ password: inputValues.password,
+ }),
+ });
+ }
+
+ function login(e) {
+ e.preventDefault();
+ fetch('http://10.58.2.36:3001/auth/signin', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json;charset=utf-8' },
+ body: JSON.stringify({
+ email: inputValues.userId,
+ password: inputValues.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (!!data.accessToken) {
+ alert('ํ์ํฉ๋๋ค!');
+ localStorage.setItem('token', data.accessToken);
+ navigate('/maing');
+ } else if (data.message === 'INVALID_ID') {
+ alert('์์ด๋๋ฅผ ํ์ธํด์ฃผ์ธ์!');
+ } else if (data.message === 'INVALID_PW') {
+ alert('๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด์ฃผ์ธ์!');
+ }
+ });
+ }
+
+ return (
+ <div className="Login">
+ <section className="main-box">
+ <div className="logo">Westagram</div>
+
+ <form className="login-wrap" onSubmit={login}>
+ <input
+ name="userId"
+ type="text"
+ className="nameEmail"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ onChange={handleInput}
+ value={inputValues.userId}
+ />
+ <input
+ name="password"
+ type="password"
+ className="passWord"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ onChange={handleInput}
+ value={inputValues.password}
+ />
+ <button className="login-btn" disabled={isValidLogin}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+
+ <div className="or-wrap">
+ <div className="or-line" />
+ <p className="or">๋๋</p>
+ <div className="or-line" />
+ </div>
+
+ <div className="facebook-login">
+ <button className="facebook-btn">
+ <img
+ className="facebook-icon"
+ src="images/Gaeul/facebook_icon.png"
+ alt="facebook icon"
+ />
+ <span>Facebook์ผ๋ก ๋ก๊ทธ์ธ</span>
+ </button>
+ </div>
+
+ <div className="forgot-password">
+ <button className="forgot-btn">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</button>
+ </div>
+ </section>
+
+ <section className="join-box">
+ <p className="let-join">
+ ๊ณ์ ์ด ์์ผ์ ๊ฐ์?
+ <button className="signup-btn" onClick={signUp}>
+ ๊ฐ์
ํ๊ธฐ
+ </button>
+ </p>
+ </section>
+
+ <div className="app-down">
+ <p className="app-down-text">์ฑ์ ๋ค์ด๋ก๋ํ์ธ์.</p>
+ <div className="download-image">
+ <Link to="https://apps.apple.com/app/instagram/id389801252?vt=lo">
+ <img
+ className="appstore-link"
+ src="images/Gaeul/appstoredownload.png"
+ alt="go to appstore"
+ />
+ </Link>
+ <Link to="https://play.google.com/store/apps/details?id=com.instagram.androidreferrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26ig_mid%3D9B98617F-78AA-471A-A22F-E8F80A1366E9%26utm_content%3Dlo%26utm_medium%3Dbadge">
+ <img
+ className="googleplay-link"
+ src="images/Gaeul/googleplaydownload.png"
+ alt="go to googleplay"
+ />
+ </Link>
+ </div>
+ </div>
+ </div>
+ );
+};
export default Login; | JavaScript | - ๋ถํ์ํ ์ฃผ์์ ์ญ์ ํด ์ฃผ์ธ์. |
@@ -1,7 +1,138 @@
-import React from 'react';
+import React, { useState } from 'react';
+import { useNavigate, Link } from 'react-router-dom';
-function Login() {
- return <div>Gaeul Login</div>;
-}
+const Login = () => {
+ const [inputValues, setInputValues] = useState({
+ userId: '',
+ password: '',
+ });
+
+ const handleInput = event => {
+ const { name, value } = event.target;
+ setInputValues({ ...inputValues, [name]: value });
+ };
+
+ const isValidLogin = !(
+ inputValues.userId.includes('@') && inputValues.password.length >= 5
+ );
+
+ const navigate = useNavigate();
+
+ function signUp(e) {
+ e.preventDefault();
+ fetch('http://10.58.2.36:3001/auth/signup', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json;charset=utf-8' },
+ body: JSON.stringify({
+ email: inputValues.userId,
+ password: inputValues.password,
+ }),
+ });
+ }
+
+ function login(e) {
+ e.preventDefault();
+ fetch('http://10.58.2.36:3001/auth/signin', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json;charset=utf-8' },
+ body: JSON.stringify({
+ email: inputValues.userId,
+ password: inputValues.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (!!data.accessToken) {
+ alert('ํ์ํฉ๋๋ค!');
+ localStorage.setItem('token', data.accessToken);
+ navigate('/maing');
+ } else if (data.message === 'INVALID_ID') {
+ alert('์์ด๋๋ฅผ ํ์ธํด์ฃผ์ธ์!');
+ } else if (data.message === 'INVALID_PW') {
+ alert('๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด์ฃผ์ธ์!');
+ }
+ });
+ }
+
+ return (
+ <div className="Login">
+ <section className="main-box">
+ <div className="logo">Westagram</div>
+
+ <form className="login-wrap" onSubmit={login}>
+ <input
+ name="userId"
+ type="text"
+ className="nameEmail"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ onChange={handleInput}
+ value={inputValues.userId}
+ />
+ <input
+ name="password"
+ type="password"
+ className="passWord"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ onChange={handleInput}
+ value={inputValues.password}
+ />
+ <button className="login-btn" disabled={isValidLogin}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+
+ <div className="or-wrap">
+ <div className="or-line" />
+ <p className="or">๋๋</p>
+ <div className="or-line" />
+ </div>
+
+ <div className="facebook-login">
+ <button className="facebook-btn">
+ <img
+ className="facebook-icon"
+ src="images/Gaeul/facebook_icon.png"
+ alt="facebook icon"
+ />
+ <span>Facebook์ผ๋ก ๋ก๊ทธ์ธ</span>
+ </button>
+ </div>
+
+ <div className="forgot-password">
+ <button className="forgot-btn">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</button>
+ </div>
+ </section>
+
+ <section className="join-box">
+ <p className="let-join">
+ ๊ณ์ ์ด ์์ผ์ ๊ฐ์?
+ <button className="signup-btn" onClick={signUp}>
+ ๊ฐ์
ํ๊ธฐ
+ </button>
+ </p>
+ </section>
+
+ <div className="app-down">
+ <p className="app-down-text">์ฑ์ ๋ค์ด๋ก๋ํ์ธ์.</p>
+ <div className="download-image">
+ <Link to="https://apps.apple.com/app/instagram/id389801252?vt=lo">
+ <img
+ className="appstore-link"
+ src="images/Gaeul/appstoredownload.png"
+ alt="go to appstore"
+ />
+ </Link>
+ <Link to="https://play.google.com/store/apps/details?id=com.instagram.androidreferrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26ig_mid%3D9B98617F-78AA-471A-A22F-E8F80A1366E9%26utm_content%3Dlo%26utm_medium%3Dbadge">
+ <img
+ className="googleplay-link"
+ src="images/Gaeul/googleplaydownload.png"
+ alt="go to googleplay"
+ />
+ </Link>
+ </div>
+ </div>
+ </div>
+ );
+};
export default Login; | JavaScript | - ํ๊ทธ๋ฅผ ์ฌ์ฉํด ์ฃผ์๊ณ className์ ํด๋น ์ปดํฌ๋ํธ๋ก ํด์ฃผ์ธ์. |
@@ -1,7 +1,138 @@
-import React from 'react';
+import React, { useState } from 'react';
+import { useNavigate, Link } from 'react-router-dom';
-function Login() {
- return <div>Gaeul Login</div>;
-}
+const Login = () => {
+ const [inputValues, setInputValues] = useState({
+ userId: '',
+ password: '',
+ });
+
+ const handleInput = event => {
+ const { name, value } = event.target;
+ setInputValues({ ...inputValues, [name]: value });
+ };
+
+ const isValidLogin = !(
+ inputValues.userId.includes('@') && inputValues.password.length >= 5
+ );
+
+ const navigate = useNavigate();
+
+ function signUp(e) {
+ e.preventDefault();
+ fetch('http://10.58.2.36:3001/auth/signup', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json;charset=utf-8' },
+ body: JSON.stringify({
+ email: inputValues.userId,
+ password: inputValues.password,
+ }),
+ });
+ }
+
+ function login(e) {
+ e.preventDefault();
+ fetch('http://10.58.2.36:3001/auth/signin', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json;charset=utf-8' },
+ body: JSON.stringify({
+ email: inputValues.userId,
+ password: inputValues.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (!!data.accessToken) {
+ alert('ํ์ํฉ๋๋ค!');
+ localStorage.setItem('token', data.accessToken);
+ navigate('/maing');
+ } else if (data.message === 'INVALID_ID') {
+ alert('์์ด๋๋ฅผ ํ์ธํด์ฃผ์ธ์!');
+ } else if (data.message === 'INVALID_PW') {
+ alert('๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด์ฃผ์ธ์!');
+ }
+ });
+ }
+
+ return (
+ <div className="Login">
+ <section className="main-box">
+ <div className="logo">Westagram</div>
+
+ <form className="login-wrap" onSubmit={login}>
+ <input
+ name="userId"
+ type="text"
+ className="nameEmail"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ onChange={handleInput}
+ value={inputValues.userId}
+ />
+ <input
+ name="password"
+ type="password"
+ className="passWord"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ onChange={handleInput}
+ value={inputValues.password}
+ />
+ <button className="login-btn" disabled={isValidLogin}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+
+ <div className="or-wrap">
+ <div className="or-line" />
+ <p className="or">๋๋</p>
+ <div className="or-line" />
+ </div>
+
+ <div className="facebook-login">
+ <button className="facebook-btn">
+ <img
+ className="facebook-icon"
+ src="images/Gaeul/facebook_icon.png"
+ alt="facebook icon"
+ />
+ <span>Facebook์ผ๋ก ๋ก๊ทธ์ธ</span>
+ </button>
+ </div>
+
+ <div className="forgot-password">
+ <button className="forgot-btn">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</button>
+ </div>
+ </section>
+
+ <section className="join-box">
+ <p className="let-join">
+ ๊ณ์ ์ด ์์ผ์ ๊ฐ์?
+ <button className="signup-btn" onClick={signUp}>
+ ๊ฐ์
ํ๊ธฐ
+ </button>
+ </p>
+ </section>
+
+ <div className="app-down">
+ <p className="app-down-text">์ฑ์ ๋ค์ด๋ก๋ํ์ธ์.</p>
+ <div className="download-image">
+ <Link to="https://apps.apple.com/app/instagram/id389801252?vt=lo">
+ <img
+ className="appstore-link"
+ src="images/Gaeul/appstoredownload.png"
+ alt="go to appstore"
+ />
+ </Link>
+ <Link to="https://play.google.com/store/apps/details?id=com.instagram.androidreferrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26ig_mid%3D9B98617F-78AA-471A-A22F-E8F80A1366E9%26utm_content%3Dlo%26utm_medium%3Dbadge">
+ <img
+ className="googleplay-link"
+ src="images/Gaeul/googleplaydownload.png"
+ alt="go to googleplay"
+ />
+ </Link>
+ </div>
+ </div>
+ </div>
+ );
+};
export default Login; | JavaScript | - return ์์ชฝ์ render์ ๊ด๋ จ๋ ๋ถ๋ถ์ด๋ผ ๋ก์ง์ ์ต๋ํ ํจ์ ์์ญ์ ์์ฑํด ์ฃผ์ธ์. |
@@ -1,7 +1,138 @@
-import React from 'react';
+import React, { useState } from 'react';
+import { useNavigate, Link } from 'react-router-dom';
-function Login() {
- return <div>Gaeul Login</div>;
-}
+const Login = () => {
+ const [inputValues, setInputValues] = useState({
+ userId: '',
+ password: '',
+ });
+
+ const handleInput = event => {
+ const { name, value } = event.target;
+ setInputValues({ ...inputValues, [name]: value });
+ };
+
+ const isValidLogin = !(
+ inputValues.userId.includes('@') && inputValues.password.length >= 5
+ );
+
+ const navigate = useNavigate();
+
+ function signUp(e) {
+ e.preventDefault();
+ fetch('http://10.58.2.36:3001/auth/signup', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json;charset=utf-8' },
+ body: JSON.stringify({
+ email: inputValues.userId,
+ password: inputValues.password,
+ }),
+ });
+ }
+
+ function login(e) {
+ e.preventDefault();
+ fetch('http://10.58.2.36:3001/auth/signin', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json;charset=utf-8' },
+ body: JSON.stringify({
+ email: inputValues.userId,
+ password: inputValues.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (!!data.accessToken) {
+ alert('ํ์ํฉ๋๋ค!');
+ localStorage.setItem('token', data.accessToken);
+ navigate('/maing');
+ } else if (data.message === 'INVALID_ID') {
+ alert('์์ด๋๋ฅผ ํ์ธํด์ฃผ์ธ์!');
+ } else if (data.message === 'INVALID_PW') {
+ alert('๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด์ฃผ์ธ์!');
+ }
+ });
+ }
+
+ return (
+ <div className="Login">
+ <section className="main-box">
+ <div className="logo">Westagram</div>
+
+ <form className="login-wrap" onSubmit={login}>
+ <input
+ name="userId"
+ type="text"
+ className="nameEmail"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ onChange={handleInput}
+ value={inputValues.userId}
+ />
+ <input
+ name="password"
+ type="password"
+ className="passWord"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ onChange={handleInput}
+ value={inputValues.password}
+ />
+ <button className="login-btn" disabled={isValidLogin}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+
+ <div className="or-wrap">
+ <div className="or-line" />
+ <p className="or">๋๋</p>
+ <div className="or-line" />
+ </div>
+
+ <div className="facebook-login">
+ <button className="facebook-btn">
+ <img
+ className="facebook-icon"
+ src="images/Gaeul/facebook_icon.png"
+ alt="facebook icon"
+ />
+ <span>Facebook์ผ๋ก ๋ก๊ทธ์ธ</span>
+ </button>
+ </div>
+
+ <div className="forgot-password">
+ <button className="forgot-btn">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</button>
+ </div>
+ </section>
+
+ <section className="join-box">
+ <p className="let-join">
+ ๊ณ์ ์ด ์์ผ์ ๊ฐ์?
+ <button className="signup-btn" onClick={signUp}>
+ ๊ฐ์
ํ๊ธฐ
+ </button>
+ </p>
+ </section>
+
+ <div className="app-down">
+ <p className="app-down-text">์ฑ์ ๋ค์ด๋ก๋ํ์ธ์.</p>
+ <div className="download-image">
+ <Link to="https://apps.apple.com/app/instagram/id389801252?vt=lo">
+ <img
+ className="appstore-link"
+ src="images/Gaeul/appstoredownload.png"
+ alt="go to appstore"
+ />
+ </Link>
+ <Link to="https://play.google.com/store/apps/details?id=com.instagram.androidreferrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26ig_mid%3D9B98617F-78AA-471A-A22F-E8F80A1366E9%26utm_content%3Dlo%26utm_medium%3Dbadge">
+ <img
+ className="googleplay-link"
+ src="images/Gaeul/googleplaydownload.png"
+ alt="go to googleplay"
+ />
+ </Link>
+ </div>
+ </div>
+ </div>
+ );
+};
export default Login; | JavaScript | - navigate๋ ์กฐ๊ฑด์ด ์์ ๋ ์ฌ์ฉํ์๋ฉด ๋ฉ๋๋ค.
- ๊ทธ๊ฒ ์๋๋ผ๋ฉด ๋ง์ํ์ ๊ฒ ์ฒ๋ผ Link ์ปดํฌ๋ํธ๋ฅผ ํ์ฉํ์
๋ ๋ฉ๋๋ค. |
@@ -0,0 +1,100 @@
+@import '../../../styles/variable.scss';
+
+p {
+ font-family: 'Roboto';
+ letter-spacing: 0.2px;
+}
+
+.Main {
+ background-color: $backGroundColor;
+
+ .main {
+ display: flex;
+ justify-content: center;
+ padding-bottom: 100px;
+
+ .main-right {
+ width: 250px;
+ height: 500px;
+
+ .id-info-box {
+ display: flex;
+ justify-content: left;
+ align-items: center;
+ padding-left: 5px;
+ margin-bottom: 15px;
+
+ .my-image {
+ width: 45px;
+ height: 45px;
+ border-radius: 50%;
+ background-color: black;
+ margin-right: 10px;
+ }
+
+ .my-info {
+ p {
+ font-size: 14px;
+ }
+
+ #my-id {
+ font-weight: 500;
+ margin-bottom: 3px;
+ }
+
+ #my-id-text {
+ color: #adafb1;
+ }
+ }
+ }
+
+ .site-info {
+ width: 220px;
+ display: flex;
+ flex-wrap: wrap;
+
+ .site-info-list {
+ color: #c3c5c7;
+ font-size: 12px;
+ margin-bottom: 5px;
+
+ a {
+ color: #c3c5c7;
+ }
+
+ &:not(:last-child)::after {
+ content: '\00B7';
+ color: lightgray;
+ margin: 0 3px;
+ }
+ }
+
+ p {
+ color: #c3c5c7;
+ font-size: 12px;
+ margin-top: 15px;
+ line-height: 15px;
+ }
+ }
+ }
+ }
+}
+
+/* media query */
+@media screen and (max-width: 750px) {
+ .header-wrap {
+ max-width: 750px;
+ }
+
+ .main {
+ display: block;
+
+ .feeds {
+ margin: 0 auto;
+ }
+ }
+
+ .main-right {
+ display: none;
+ }
+} | Unknown | - body๋ ๋ค๋ฅธ ํ์ด์ง์๋ ์ํฅ์ ์ค ์ ์๊ฒ ๋ค์
- ํ์ํ ๋ถ๋ถ์ด๋ผ๋ฉด common.scss์์ ์งํ๋๊ฑฐ๋ ํ์๋ค๊ณผ ๋
ผ์ ํ ์งํํ์๋ฉด ๋ฉ๋๋ค. |
@@ -0,0 +1,100 @@
+@import '../../../styles/variable.scss';
+
+p {
+ font-family: 'Roboto';
+ letter-spacing: 0.2px;
+}
+
+.Main {
+ background-color: $backGroundColor;
+
+ .main {
+ display: flex;
+ justify-content: center;
+ padding-bottom: 100px;
+
+ .main-right {
+ width: 250px;
+ height: 500px;
+
+ .id-info-box {
+ display: flex;
+ justify-content: left;
+ align-items: center;
+ padding-left: 5px;
+ margin-bottom: 15px;
+
+ .my-image {
+ width: 45px;
+ height: 45px;
+ border-radius: 50%;
+ background-color: black;
+ margin-right: 10px;
+ }
+
+ .my-info {
+ p {
+ font-size: 14px;
+ }
+
+ #my-id {
+ font-weight: 500;
+ margin-bottom: 3px;
+ }
+
+ #my-id-text {
+ color: #adafb1;
+ }
+ }
+ }
+
+ .site-info {
+ width: 220px;
+ display: flex;
+ flex-wrap: wrap;
+
+ .site-info-list {
+ color: #c3c5c7;
+ font-size: 12px;
+ margin-bottom: 5px;
+
+ a {
+ color: #c3c5c7;
+ }
+
+ &:not(:last-child)::after {
+ content: '\00B7';
+ color: lightgray;
+ margin: 0 3px;
+ }
+ }
+
+ p {
+ color: #c3c5c7;
+ font-size: 12px;
+ margin-top: 15px;
+ line-height: 15px;
+ }
+ }
+ }
+ }
+}
+
+/* media query */
+@media screen and (max-width: 750px) {
+ .header-wrap {
+ max-width: 750px;
+ }
+
+ .main {
+ display: block;
+
+ .feeds {
+ margin: 0 auto;
+ }
+ }
+
+ .main-right {
+ display: none;
+ }
+} | Unknown | - ์ปดํฌ๋ํธ๋ฅผ ๋ถ๋ฆฌํ์
จ๋ค๋ฉด ํด๋น css๋ ๋ถ๋ฆฌํ์
์ ์งํํ์๋ ๊ฒ ๊ฐ๋
์ฑ์๋ ์ข๊ฒ ๋ค์. |
@@ -0,0 +1,82 @@
+import React, { useState } from 'react';
+import CommentList from './CommentList';
+
+const Feeds = ({ feedData }) => {
+ const [input, setInput] = useState('');
+ const [inputList, setInputList] = useState([]);
+
+ const post = event => {
+ event.preventDefault();
+ setInputList(inputList.concat(input));
+ setInput('');
+ };
+
+ const handleInput = event => {
+ setInput(event.target.value);
+ };
+
+ return (
+ <div className="feeds" key={feedData.userId}>
+ <div className="user-bar">
+ <div className="user">
+ <div className="user-image" />
+ <em className="user-id">{feedData.userId}</em>
+ </div>
+ <button id="feed-dot">
+ <i className="fa-solid fa-ellipsis" />
+ </button>
+ </div>
+
+ <img className="article-img" src={feedData.url} alt="ํผ๋์ด๋ฏธ์ง" />
+
+ <div className="article-icons">
+ <div className="article-three-icons">
+ <button>
+ <i className="fa-regular fa-heart" />
+ </button>
+ <button>
+ <i className="fa-regular fa-comment" />
+ </button>
+ <button>
+ <i className="fa-solid fa-arrow-up-from-bracket" />
+ </button>
+ </div>
+
+ <button className="bookmark">
+ <i className="fa-regular fa-bookmark" />
+ </button>
+ </div>
+
+ <div className="like-user">
+ <div className="like-user-img" />
+ <p>
+ <b>{feedData.likeUser}</b>๋ ์ธ <b>{feedData.like}๋ช
</b>์ด ์ข์ํฉ๋๋ค
+ </p>
+ </div>
+
+ <ul className="comments-ul">
+ {inputList.map((input, idx) => {
+ return <CommentList key={idx} item={input} />;
+ })}
+ </ul>
+
+ <form className="lets-comment" onSubmit={post}>
+ <input
+ className="comment-input"
+ type="text"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={handleInput}
+ value={input}
+ />
+ <button
+ className={input ? 'submitCommentActive' : 'submitCommentInactive'}
+ disabled={!input}
+ >
+ ๊ฒ์
+ </button>
+ </form>
+ </div>
+ );
+};
+
+export default Feeds; | JavaScript | - className์ ์ปดํฌ๋ํธ๋ช
๊ณผ ๊ฐ๊ฒ ํด์ฃผ์ธ์. |
@@ -0,0 +1,82 @@
+import React, { useState } from 'react';
+import CommentList from './CommentList';
+
+const Feeds = ({ feedData }) => {
+ const [input, setInput] = useState('');
+ const [inputList, setInputList] = useState([]);
+
+ const post = event => {
+ event.preventDefault();
+ setInputList(inputList.concat(input));
+ setInput('');
+ };
+
+ const handleInput = event => {
+ setInput(event.target.value);
+ };
+
+ return (
+ <div className="feeds" key={feedData.userId}>
+ <div className="user-bar">
+ <div className="user">
+ <div className="user-image" />
+ <em className="user-id">{feedData.userId}</em>
+ </div>
+ <button id="feed-dot">
+ <i className="fa-solid fa-ellipsis" />
+ </button>
+ </div>
+
+ <img className="article-img" src={feedData.url} alt="ํผ๋์ด๋ฏธ์ง" />
+
+ <div className="article-icons">
+ <div className="article-three-icons">
+ <button>
+ <i className="fa-regular fa-heart" />
+ </button>
+ <button>
+ <i className="fa-regular fa-comment" />
+ </button>
+ <button>
+ <i className="fa-solid fa-arrow-up-from-bracket" />
+ </button>
+ </div>
+
+ <button className="bookmark">
+ <i className="fa-regular fa-bookmark" />
+ </button>
+ </div>
+
+ <div className="like-user">
+ <div className="like-user-img" />
+ <p>
+ <b>{feedData.likeUser}</b>๋ ์ธ <b>{feedData.like}๋ช
</b>์ด ์ข์ํฉ๋๋ค
+ </p>
+ </div>
+
+ <ul className="comments-ul">
+ {inputList.map((input, idx) => {
+ return <CommentList key={idx} item={input} />;
+ })}
+ </ul>
+
+ <form className="lets-comment" onSubmit={post}>
+ <input
+ className="comment-input"
+ type="text"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={handleInput}
+ value={input}
+ />
+ <button
+ className={input ? 'submitCommentActive' : 'submitCommentInactive'}
+ disabled={!input}
+ >
+ ๊ฒ์
+ </button>
+ </form>
+ </div>
+ );
+};
+
+export default Feeds; | JavaScript | - alt๋ ์ ์ ๊ฐ ๋ณด๋ ํ
์คํธ ์
๋๋ค.
- ์ ์ ์
์ฅ์์ ์์ฑํด ์ฃผ์ธ์. |
@@ -0,0 +1,82 @@
+import React, { useState } from 'react';
+import CommentList from './CommentList';
+
+const Feeds = ({ feedData }) => {
+ const [input, setInput] = useState('');
+ const [inputList, setInputList] = useState([]);
+
+ const post = event => {
+ event.preventDefault();
+ setInputList(inputList.concat(input));
+ setInput('');
+ };
+
+ const handleInput = event => {
+ setInput(event.target.value);
+ };
+
+ return (
+ <div className="feeds" key={feedData.userId}>
+ <div className="user-bar">
+ <div className="user">
+ <div className="user-image" />
+ <em className="user-id">{feedData.userId}</em>
+ </div>
+ <button id="feed-dot">
+ <i className="fa-solid fa-ellipsis" />
+ </button>
+ </div>
+
+ <img className="article-img" src={feedData.url} alt="ํผ๋์ด๋ฏธ์ง" />
+
+ <div className="article-icons">
+ <div className="article-three-icons">
+ <button>
+ <i className="fa-regular fa-heart" />
+ </button>
+ <button>
+ <i className="fa-regular fa-comment" />
+ </button>
+ <button>
+ <i className="fa-solid fa-arrow-up-from-bracket" />
+ </button>
+ </div>
+
+ <button className="bookmark">
+ <i className="fa-regular fa-bookmark" />
+ </button>
+ </div>
+
+ <div className="like-user">
+ <div className="like-user-img" />
+ <p>
+ <b>{feedData.likeUser}</b>๋ ์ธ <b>{feedData.like}๋ช
</b>์ด ์ข์ํฉ๋๋ค
+ </p>
+ </div>
+
+ <ul className="comments-ul">
+ {inputList.map((input, idx) => {
+ return <CommentList key={idx} item={input} />;
+ })}
+ </ul>
+
+ <form className="lets-comment" onSubmit={post}>
+ <input
+ className="comment-input"
+ type="text"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={handleInput}
+ value={input}
+ />
+ <button
+ className={input ? 'submitCommentActive' : 'submitCommentInactive'}
+ disabled={!input}
+ >
+ ๊ฒ์
+ </button>
+ </form>
+ </div>
+ );
+};
+
+export default Feeds; | JavaScript | - onKeyup ๋ณด๋ค๋ ๋ณ์๋ก ๋์ ๊ด๋ฆฌ๋ฅผ ํ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
- ๋ณ์๋ฅผ ๋ง๋ค์ด ๋์ ์ผ๋ก ๊ด๋ฆฌํ๋ค๋ฉด state๊ฐ ์์ด๋ ๋๊ฒ ๋ค์. |
@@ -0,0 +1,82 @@
+import React, { useState } from 'react';
+import CommentList from './CommentList';
+
+const Feeds = ({ feedData }) => {
+ const [input, setInput] = useState('');
+ const [inputList, setInputList] = useState([]);
+
+ const post = event => {
+ event.preventDefault();
+ setInputList(inputList.concat(input));
+ setInput('');
+ };
+
+ const handleInput = event => {
+ setInput(event.target.value);
+ };
+
+ return (
+ <div className="feeds" key={feedData.userId}>
+ <div className="user-bar">
+ <div className="user">
+ <div className="user-image" />
+ <em className="user-id">{feedData.userId}</em>
+ </div>
+ <button id="feed-dot">
+ <i className="fa-solid fa-ellipsis" />
+ </button>
+ </div>
+
+ <img className="article-img" src={feedData.url} alt="ํผ๋์ด๋ฏธ์ง" />
+
+ <div className="article-icons">
+ <div className="article-three-icons">
+ <button>
+ <i className="fa-regular fa-heart" />
+ </button>
+ <button>
+ <i className="fa-regular fa-comment" />
+ </button>
+ <button>
+ <i className="fa-solid fa-arrow-up-from-bracket" />
+ </button>
+ </div>
+
+ <button className="bookmark">
+ <i className="fa-regular fa-bookmark" />
+ </button>
+ </div>
+
+ <div className="like-user">
+ <div className="like-user-img" />
+ <p>
+ <b>{feedData.likeUser}</b>๋ ์ธ <b>{feedData.like}๋ช
</b>์ด ์ข์ํฉ๋๋ค
+ </p>
+ </div>
+
+ <ul className="comments-ul">
+ {inputList.map((input, idx) => {
+ return <CommentList key={idx} item={input} />;
+ })}
+ </ul>
+
+ <form className="lets-comment" onSubmit={post}>
+ <input
+ className="comment-input"
+ type="text"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={handleInput}
+ value={input}
+ />
+ <button
+ className={input ? 'submitCommentActive' : 'submitCommentInactive'}
+ disabled={!input}
+ >
+ ๊ฒ์
+ </button>
+ </form>
+ </div>
+ );
+};
+
+export default Feeds; | JavaScript | - form ํ๊ทธ ์์ ์๋ค๋ฉด ๋ฒํผ์๋ ๋ฐ๋ก onClick์ ๋ถ์ฌํ์ง ์์ผ์
๋ ๋ฉ๋๋ค. |
@@ -0,0 +1,36 @@
+package rentcar.domain;
+
+public class Avante extends Car {
+
+ private static final String NAME = "Avante";
+ private static final double DISTANCE_PER_LITER = 15;
+ private static final String VALIDATE_TRIP_DISTANCE_MESSAGE = "[ERROR] ์ฌํ๊ฑฐ๋ฆฌ๋ 0 ์ด์์
๋๋ค.";
+
+ private double tripDistance;
+
+ public Avante(double tripDistance) {
+ validateTripDistance(tripDistance);
+ this.tripDistance = tripDistance;
+ }
+
+ private void validateTripDistance(double tripDistance) {
+ if (tripDistance < 0) {
+ throw new IllegalArgumentException(VALIDATE_TRIP_DISTANCE_MESSAGE);
+ }
+ }
+
+ @Override
+ double getDistancePerLiter() {
+ return DISTANCE_PER_LITER;
+ }
+
+ @Override
+ double getTripDistance() {
+ return tripDistance;
+ }
+
+ @Override
+ String getName() {
+ return NAME;
+ }
+} | Java | Car (์ถ์) ํด๋์ค์ ํ์ ๊ตฌํ์ฒด๋ค์ ๋ชจ๋ ์ด ๋ก์ง์ด ๋ฐ๋ณต๋๊ณ ์์ด์. ๐
๋ฐ๋ณต๋๋ ์ฝ๋๋ฅผ Car ํด๋์ค์ ๊ตฌํํ๋ฉด ๋ฐ๋ณต๋๋ ์ฝ๋๋ฅผ ์ค์ผ ์ ์์ ๊ฒ ๊ฐ์์. ๐ค |
@@ -0,0 +1,36 @@
+package rentcar.domain;
+
+public class Avante extends Car {
+
+ private static final String NAME = "Avante";
+ private static final double DISTANCE_PER_LITER = 15;
+ private static final String VALIDATE_TRIP_DISTANCE_MESSAGE = "[ERROR] ์ฌํ๊ฑฐ๋ฆฌ๋ 0 ์ด์์
๋๋ค.";
+
+ private double tripDistance;
+
+ public Avante(double tripDistance) {
+ validateTripDistance(tripDistance);
+ this.tripDistance = tripDistance;
+ }
+
+ private void validateTripDistance(double tripDistance) {
+ if (tripDistance < 0) {
+ throw new IllegalArgumentException(VALIDATE_TRIP_DISTANCE_MESSAGE);
+ }
+ }
+
+ @Override
+ double getDistancePerLiter() {
+ return DISTANCE_PER_LITER;
+ }
+
+ @Override
+ double getTripDistance() {
+ return tripDistance;
+ }
+
+ @Override
+ String getName() {
+ return NAME;
+ }
+} | Java | `0`์ด ์ด๋ค ์ซ์์ธ์ง ์์๋ก ์ถ์ถํ์ฌ ์๋ฏธ๋ฅผ ๋ช
ํํ๊ฒ ํด์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์์. ๐ค |
@@ -0,0 +1,7 @@
+package rentcar.domain;
+
+public interface Reportable {
+
+ String generateReport();
+
+} | Java | ์ธํฐํ์ด์ค ํ์ฉ ๐๐ |
@@ -0,0 +1,92 @@
+package blackjack.controller;
+
+import blackjack.domain.card.CardFactory;
+import blackjack.domain.card.Deck;
+import blackjack.domain.report.GameReports;
+import blackjack.domain.request.DrawRequest;
+import blackjack.domain.request.UserNamesRequest;
+import blackjack.domain.user.Dealer;
+import blackjack.domain.user.Player;
+import blackjack.domain.user.Players;
+import blackjack.view.InputView;
+import blackjack.view.OutputView;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class BlackJack {
+
+ private final Players players;
+ private final Deck deck;
+
+ private BlackJack(Players players, Deck deck) {
+ this.players = players;
+ this.deck = deck;
+ }
+
+ public static BlackJack init(UserNamesRequest playerNames) {
+ Dealer dealer = new Dealer();
+ Players candidates = playerNames.userNames()
+ .stream()
+ .map(Player::new)
+ .collect(Collectors.collectingAndThen(Collectors.toList(),
+ players -> new Players(dealer, players)));
+ CardFactory cardFactory = CardFactory.getInstance();
+ Deck deck = new Deck(cardFactory.createCards());
+ return new BlackJack(candidates, deck);
+ }
+
+ public void runGame() {
+ spreadStartCards();
+ if (!players.hasBlackJack()) {
+ drawPlayers();
+ drawDealer();
+ }
+ GameReports reports = getResult();
+ showResult(reports);
+ }
+
+ private void spreadStartCards() {
+ players.drawStartCards(deck);
+ OutputView.printAllPlayersCard(players);
+ }
+
+ private void drawPlayers() {
+ for (Player player : players.findOnlyPlayers()) {
+ drawEachPlayer(player);
+ }
+ }
+
+ private void drawEachPlayer(Player player) {
+ while (player.isDrawable() && getPlayerRequest(player)) {
+ player.drawCard(deck.spreadCard());
+ OutputView.printEachCardInfo(player);
+ }
+ }
+
+ private boolean getPlayerRequest(Player player) {
+ String drawRequest = InputView.getDrawRequest(player);
+ return DrawRequest.valueOf(drawRequest)
+ .isDrawable();
+ }
+
+ private void drawDealer() {
+ Dealer dealer = players.findDealer();
+ while (dealer.isDrawable()) {
+ dealer.drawCard(deck.spreadCard());
+ OutputView.printDealerGetCard();
+ }
+ }
+
+ private GameReports getResult() {
+ Dealer dealer = players.findDealer();
+ List<Player> candidates = players.findOnlyPlayers();
+ return candidates.stream()
+ .map(dealer::createReport)
+ .collect(Collectors.collectingAndThen(Collectors.toList(), GameReports::new));
+ }
+
+ private void showResult(GameReports reports) {
+ OutputView.printResultStatus(players.all());
+ OutputView.printReports(reports);
+ }
+} | Java | `collectingAndThen` ํจ์๋ ์ ๋ ๋ชฐ๋๋๋ฐ, ์ ์ฉํ ๊ฒ ๊ฐ์์! ๐คญ๐ |
@@ -0,0 +1,92 @@
+package blackjack.controller;
+
+import blackjack.domain.card.CardFactory;
+import blackjack.domain.card.Deck;
+import blackjack.domain.report.GameReports;
+import blackjack.domain.request.DrawRequest;
+import blackjack.domain.request.UserNamesRequest;
+import blackjack.domain.user.Dealer;
+import blackjack.domain.user.Player;
+import blackjack.domain.user.Players;
+import blackjack.view.InputView;
+import blackjack.view.OutputView;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class BlackJack {
+
+ private final Players players;
+ private final Deck deck;
+
+ private BlackJack(Players players, Deck deck) {
+ this.players = players;
+ this.deck = deck;
+ }
+
+ public static BlackJack init(UserNamesRequest playerNames) {
+ Dealer dealer = new Dealer();
+ Players candidates = playerNames.userNames()
+ .stream()
+ .map(Player::new)
+ .collect(Collectors.collectingAndThen(Collectors.toList(),
+ players -> new Players(dealer, players)));
+ CardFactory cardFactory = CardFactory.getInstance();
+ Deck deck = new Deck(cardFactory.createCards());
+ return new BlackJack(candidates, deck);
+ }
+
+ public void runGame() {
+ spreadStartCards();
+ if (!players.hasBlackJack()) {
+ drawPlayers();
+ drawDealer();
+ }
+ GameReports reports = getResult();
+ showResult(reports);
+ }
+
+ private void spreadStartCards() {
+ players.drawStartCards(deck);
+ OutputView.printAllPlayersCard(players);
+ }
+
+ private void drawPlayers() {
+ for (Player player : players.findOnlyPlayers()) {
+ drawEachPlayer(player);
+ }
+ }
+
+ private void drawEachPlayer(Player player) {
+ while (player.isDrawable() && getPlayerRequest(player)) {
+ player.drawCard(deck.spreadCard());
+ OutputView.printEachCardInfo(player);
+ }
+ }
+
+ private boolean getPlayerRequest(Player player) {
+ String drawRequest = InputView.getDrawRequest(player);
+ return DrawRequest.valueOf(drawRequest)
+ .isDrawable();
+ }
+
+ private void drawDealer() {
+ Dealer dealer = players.findDealer();
+ while (dealer.isDrawable()) {
+ dealer.drawCard(deck.spreadCard());
+ OutputView.printDealerGetCard();
+ }
+ }
+
+ private GameReports getResult() {
+ Dealer dealer = players.findDealer();
+ List<Player> candidates = players.findOnlyPlayers();
+ return candidates.stream()
+ .map(dealer::createReport)
+ .collect(Collectors.collectingAndThen(Collectors.toList(), GameReports::new));
+ }
+
+ private void showResult(GameReports reports) {
+ OutputView.printResultStatus(players.all());
+ OutputView.printReports(reports);
+ }
+} | Java | `BlackJack` ํด๋์ค๋ Controller์ ์ฉ๋๋ก ์ฌ์ฉํ๋ ค๋ ๊ฒ ๊ฐ์ผ๋ ๋น์ฆ๋์ค ๋ก์ง์ด ์๋น์ ์กด์ฌํ๋ ๊ฒ ๊ฐ์์. ๐ค
Controller๋ ์ํ ๊ฐ์ ๊ฐ์ง์ง ์์์ผํด์. ๐
`BlackJackController` ํด๋์ค์ ๋น์ฆ๋์ค ๋ชจ๋ธ์ธ `BlackJack` ํด๋์ค๋ก ๋ถ๋ฆฌํด๋ณผ ์ ์์ ๊ฒ ๊ฐ์์. ๐ค |
@@ -0,0 +1,34 @@
+package blackjack.domain.card;
+
+public enum Number {
+
+ ACE(1, "A"),
+ TWO(2, "2"),
+ THREE(3, "3"),
+ FOUR(4, "4"),
+ FIVE(5, "5"),
+ SIX(6, "6"),
+ SEVEN(7, "7"),
+ EIGHT(8, "8"),
+ NINE(9, "9"),
+ TEN(10, "10"),
+ JACK(10, "J"),
+ QUEEN(10, "Q"),
+ KING(10, "K");
+
+ private final int score;
+ private final String message;
+
+ Number(int score, String message) {
+ this.score = score;
+ this.message = message;
+ }
+
+ public int score() {
+ return score;
+ }
+
+ public String message() {
+ return message;
+ }
+} | Java | enum ํด๋์ค๋ช
์ด `ACE, JACK, QUEEN, KING`์ ํฌํจํ๋ ์๋ฏธ๋ผ๊ณ ๋ณผ ์ ์์๊น์? ๐ค
`Type` or `CardType`๊ณผ ๊ฐ์ ๋ค์ด๋ฐ์ ์ด๋จ๊น์? ๐ |
@@ -0,0 +1,34 @@
+package blackjack.domain.card;
+
+public enum Number {
+
+ ACE(1, "A"),
+ TWO(2, "2"),
+ THREE(3, "3"),
+ FOUR(4, "4"),
+ FIVE(5, "5"),
+ SIX(6, "6"),
+ SEVEN(7, "7"),
+ EIGHT(8, "8"),
+ NINE(9, "9"),
+ TEN(10, "10"),
+ JACK(10, "J"),
+ QUEEN(10, "Q"),
+ KING(10, "K");
+
+ private final int score;
+ private final String message;
+
+ Number(int score, String message) {
+ this.score = score;
+ this.message = message;
+ }
+
+ public int score() {
+ return score;
+ }
+
+ public String message() {
+ return message;
+ }
+} | Java | ๊ฐ์ฒด์ ์ํ ๊ฐ์ ์ธ๋ถ๋ก ํธ์ถํ๋ ๋ฉ์๋๋ `getter` ๋ฉ์๋๋ฅผ ์ ์ํด์ฃผ์ธ์. ๐
getter, setter์ ๊ฐ์ ๊ด์ต์ ์ธ ๋ฉ์๋ ์์ฑ์ด ๋ฏ์ค๊ฑฐ๋ ์ด๋ ต๋ค๋ฉด `โ + N` ๋จ์ถํค๋ฅผ ํตํด์ ์ด๋ฐ ๋ฉ์๋๋ค์ ์ฝ๊ฒ ์์ฑํ ์ ์์ด์. ๐ค |
@@ -0,0 +1,35 @@
+package blackjack.domain.card;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CardFactory {
+
+ public static CardFactory INSTANCE;
+
+ private CardFactory() {
+ }
+
+ public static CardFactory getInstance() {
+ if (INSTANCE == null) {
+ INSTANCE = new CardFactory();
+ }
+ return INSTANCE;
+ }
+
+ public List<Card> createCards() {
+ List<Card> cards = new ArrayList<>();
+ for (Suit suit : Suit.values()) {
+ createBySuit(cards, suit);
+ }
+ Collections.shuffle(cards);
+ return cards;
+ }
+
+ private void createBySuit(List<Card> cards, Suit suit) {
+ for (Number number : Number.values()) {
+ cards.add(new Card(suit, number));
+ }
+ }
+} | Java | Deck์ผ๋ก ์ฐ์ด๋ ์นด๋๋ค์ ์นด๋์ ํํ์ ๊ฐฏ์๋ค์ด ์ ํด์ ธ์๊ณ ์ฌ์ฌ์ฉํ ํ๋ฅ ์ด ๋๋ค๊ณ ์๊ฐํด์. ๐
๋ฏธ๋ฆฌ ๋ง๋ค์ด๋๋ค๊ฐ ํ์ํ ์์ ์ ์ฌ์ฌ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์? ๐ค
[์ฐธ๊ณ ์๋ฃ](https://tecoble.techcourse.co.kr/post/2020-06-24-caching-instance/) |
@@ -0,0 +1,22 @@
+package blackjack.domain.card;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+public class Deck {
+
+ private final Queue<Card> deck;
+
+ public Deck(List<Card> cards) {
+ this.deck = new LinkedList<>(cards);
+ }
+
+ public Card spreadCard() {
+ return deck.poll();
+ }
+
+ public int remainCardSize() {
+ return deck.size();
+ }
+} | Java | ์ ๋ Stack์ด ์กฐ๊ธ ๋ ์นด๋ ๊ฒ์์ ์ด์ธ๋ฆฐ๋ค๊ณ ์๊ฐํ๋๋ฐ, Queue๋ ์ข์ ์ ๊ทผ์ธ ๊ฒ ๊ฐ์์. ๐ค
`spreadCard` ๋ฉ์๋์์๋ deck์ด ๋น์ด์๋ ๊ฒฝ์ฐ์ ๋ํ ์์ธ ์ฒ๋ฆฌ๋ ํ ์ ์์ ๊ฒ ๊ฐ์์. ๐ |
@@ -0,0 +1,42 @@
+package blackjack.domain.card;
+
+import blackjack.domain.score.ScoreCalculator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CardBundle {
+
+ private static final int BLACK_JACK_SCORE = 21;
+
+ private final List<Card> cards;
+
+ private CardBundle() {
+ this.cards = new ArrayList<>();
+ }
+
+ public static CardBundle emptyBundle() {
+ return new CardBundle();
+ }
+
+ public void addCard(Card card) {
+ cards.add(card);
+ }
+
+ public int calculateScore() {
+ return ScoreCalculator.findByCards(cards)
+ .calculateScore(cards);
+ }
+
+ public List<Card> getCards() {
+ return Collections.unmodifiableList(cards);
+ }
+
+ public boolean isBurst() {
+ return calculateScore() > BLACK_JACK_SCORE;
+ }
+
+ public boolean isBlackJack() {
+ return calculateScore() == BLACK_JACK_SCORE;
+ }
+} | Java | CardBundle.`empty()` ๋ก๋ ์ถฉ๋ถํ ์๋ฏธ๊ฐ ์ ๋ฌ๋๋ ๊ฒ ๊ฐ์์. ๐ |
@@ -0,0 +1,42 @@
+package blackjack.domain.card;
+
+import blackjack.domain.score.ScoreCalculator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CardBundle {
+
+ private static final int BLACK_JACK_SCORE = 21;
+
+ private final List<Card> cards;
+
+ private CardBundle() {
+ this.cards = new ArrayList<>();
+ }
+
+ public static CardBundle emptyBundle() {
+ return new CardBundle();
+ }
+
+ public void addCard(Card card) {
+ cards.add(card);
+ }
+
+ public int calculateScore() {
+ return ScoreCalculator.findByCards(cards)
+ .calculateScore(cards);
+ }
+
+ public List<Card> getCards() {
+ return Collections.unmodifiableList(cards);
+ }
+
+ public boolean isBurst() {
+ return calculateScore() > BLACK_JACK_SCORE;
+ }
+
+ public boolean isBlackJack() {
+ return calculateScore() == BLACK_JACK_SCORE;
+ }
+} | Java | `CardBundle` ๊ฐ์ฒด๋ **์นด๋์ ์ ์๋ฅผ ํฉ์ฐํ๋ ์ญํ **์ ์ํํ๋ค๊ณ ์๊ฐํด์. ๐ค
`ScoreCalculator` enum class ๋ด๋ถ ์ฝ๋๋ ๋งค์ฐ ํฅ๋ฏธ๋กญ๊ฒ ๋ดค์ด์. ๐ ๐
ํ์ง๋ง `AceScoreStrategy`, `DefaultScoreStrategy`์ ๋ด๋ถ ์ฝ๋๋ฅผ ๋ณด์์ ๋, ์ด๋ฐ ์์ผ๋ก (์นด๋ ์ ์ ํฉ์ฐ) ์ ๋ต์ ๊ตฌ๋ถํ์ฌ ๊ตฌํํ๋ ๊ฒ๋ณด๋ค ์นด๋ ์ ์ ํฉ์ฐ ๋ก์ง์ด ํ์ํ `CardBundle ๊ฐ์ฒด ๋ด๋ถ`์ ์ง์ ๊ตฌํํ๋ ๊ฒ์ด ๋ ์์ง์ฑ์ด ๋๋ค๊ณ ์๊ฐํด์. ๐
์ง๊ธ์ ์ฝ๋์์ `์ ์๋ฅผ ํฉ์ฐ`ํ๋ ๊ธฐ๋ฅ์ ํ์
ํ๊ธฐ๊ฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์. ๐ค (์๋์ ๊ฐ์ด ์ฝ๋๋ฅผ ํ์ํด์ผ ํด์. ๐ฑ)
`calculateScore()` -> `ScoreCalculator#findByCards(cards)` -> `ScoreCalculator#isSupportable(cards)` -> `ScoreCalculator#calculateScore(cards)` -> (AceScoreStrategy & DefaultScoreStrategy)`scoreStrategy.calculateScore(cards)`
๋ํ `ScoreCalculator`์ ํจ์๋ฅผ ํธ์ถํ ๋๋ง๋ค, ๊ณ์ํด์ ๋ฉ์๋ ํ๋ผ๋ฏธํฐ(= ์ธ๋ถ)๋ก cards๋ฅผ ์ ๋ฌํ๊ณ ์์ด์. ๐
์ด๋ฐ ๋ถ๋ถ์์ `์นด๋ ์ ์๋ฅผ ํฉ์ฐ`ํ๋ ๊ธฐ๋ฅ์ ๊ฐ์ฒด์ ์ญํ ์ด ์๋๋ผ CardBundle์ ์ญํ ์ด๋ผ๊ณ ์๊ฐ๋ผ์. ๐ค |
@@ -0,0 +1,51 @@
+package blackjack.domain.report;
+
+import java.util.Objects;
+
+public class GameReport {
+
+ private final String name;
+ private final GameResult result;
+
+ public GameReport(String name, GameResult result) {
+ this.name = name;
+ this.result = result;
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public String message() {
+ return result.message();
+ }
+
+ public boolean isWin() {
+ return result == GameResult.WIN;
+ }
+
+ public boolean isDraw() {
+ return result == GameResult.DRAW;
+ }
+
+ public boolean isLose() {
+ return result == GameResult.LOSE;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ GameReport report = (GameReport) o;
+ return Objects.equals(name, report.name) && result == report.result;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, result);
+ }
+} | Java | GameReport ๊ฐ์ฒด์ `๋๋ฑ์ฑ`์ ์ ์ํ ํ์๊ฐ ์๋์? ๐ค
ํน์ ํ์ํ ์์น๊ฐ ์์๊น์? ๐ (์ ๊ฐ ๋ชป ์ฐพ๋ ๊ฑธ๊น์? ๐) |
@@ -0,0 +1,52 @@
+package blackjack.domain.report;
+
+import blackjack.domain.card.CardBundle;
+import java.util.Arrays;
+
+public enum GameResult {
+
+ WIN(1, "์น"),
+ DRAW(0, "๋ฌด"),
+ LOSE(-1, "ํจ");
+
+ private final int result;
+ private final String message;
+
+ GameResult(int result, String message) {
+ this.result = result;
+ this.message = message;
+ }
+
+ public static GameResult comparing(CardBundle playerCardBundle, CardBundle dealerCardBundle) {
+ isComparable(playerCardBundle, dealerCardBundle);
+ if (playerCardBundle.isBurst()) {
+ return GameResult.LOSE;
+ }
+ if (dealerCardBundle.isBurst()) {
+ return GameResult.WIN;
+ }
+ int result = Integer.compare(playerCardBundle.calculateScore(),
+ dealerCardBundle.calculateScore());
+ return findResult(result);
+ }
+
+ public String message() {
+ return message;
+ }
+
+ private static void isComparable(CardBundle dealerCardBundle, CardBundle playerCardBundle) {
+ if (dealerCardBundle == null) {
+ throw new IllegalArgumentException("[ERROR] ๋๋ฌ์ ์นด๋๊ฐ ๋น์์ต๋๋ค");
+ }
+ if (playerCardBundle == null) {
+ throw new IllegalArgumentException("[ERROR] ํ๋ ์ด์ด์ ์นด๋๊ฐ ๋น์์ต๋๋ค.");
+ }
+ }
+
+ private static GameResult findResult(int result) {
+ return Arrays.stream(values())
+ .filter(gameResult -> gameResult.result == result)
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException("[ERROR] ์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ ์
๋๋ค"));
+ }
+} | Java | getter (getter ์ญํ ์ ํ๋ ๋ฉ์๋), setter, compareTo, toString ๋ฑ์ ๋ฉ์๋๋ ํด๋์ค์ ์ตํ๋จ์ ์์น์์ผ์ฃผ์ธ์! |
@@ -0,0 +1,52 @@
+package blackjack.domain.report;
+
+import blackjack.domain.card.CardBundle;
+import java.util.Arrays;
+
+public enum GameResult {
+
+ WIN(1, "์น"),
+ DRAW(0, "๋ฌด"),
+ LOSE(-1, "ํจ");
+
+ private final int result;
+ private final String message;
+
+ GameResult(int result, String message) {
+ this.result = result;
+ this.message = message;
+ }
+
+ public static GameResult comparing(CardBundle playerCardBundle, CardBundle dealerCardBundle) {
+ isComparable(playerCardBundle, dealerCardBundle);
+ if (playerCardBundle.isBurst()) {
+ return GameResult.LOSE;
+ }
+ if (dealerCardBundle.isBurst()) {
+ return GameResult.WIN;
+ }
+ int result = Integer.compare(playerCardBundle.calculateScore(),
+ dealerCardBundle.calculateScore());
+ return findResult(result);
+ }
+
+ public String message() {
+ return message;
+ }
+
+ private static void isComparable(CardBundle dealerCardBundle, CardBundle playerCardBundle) {
+ if (dealerCardBundle == null) {
+ throw new IllegalArgumentException("[ERROR] ๋๋ฌ์ ์นด๋๊ฐ ๋น์์ต๋๋ค");
+ }
+ if (playerCardBundle == null) {
+ throw new IllegalArgumentException("[ERROR] ํ๋ ์ด์ด์ ์นด๋๊ฐ ๋น์์ต๋๋ค.");
+ }
+ }
+
+ private static GameResult findResult(int result) {
+ return Arrays.stream(values())
+ .filter(gameResult -> gameResult.result == result)
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException("[ERROR] ์ฌ๋ฐ๋ฅด์ง ์์ ๊ฐ ์
๋๋ค"));
+ }
+} | Java | ๋ CardBundle (์ฌ์ค์ ๋ ๋ฒ์งธ, ํ๋ผ๋ฏธํฐ๋ก ๋ฐ๋ CardBundle์ Dealer์ CardBundle๋ก ๊ณ ์ ๋๋ ๊ฒ ๊ฐ์์. ๐)์ ๋ฐ์์ `๊ฒ์ ๊ฒฐ๊ณผ`๋ฅผ ๋ฐํํ๋ ์ญํ ์ `Dealer`์ ์ญํ ์ด๋ผ๊ณ ๋ณผ ์ ์์ง ์์๊น์? ๐ค (๊ทธ๋ฌ๋ฉด ์ฒซ ๋ฒ์งธ ํ๋ผ๋ฏธํฐ์ ๋ ๋ฒ์งธ ํ๋ผ๋ฏธํฐ์ ์์๋ฅผ ์๋ชป ๋์
ํ๋ค๊ฑฐ๋ ํ๋ ์ค์๋ฅผ ๋ง์ ์๋ ์์ ๊ฒ ๊ฐ์์. ๐) |
@@ -0,0 +1,45 @@
+package blackjack.domain.request;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class UserNamesRequest {
+
+ private static final String USER_NAME_DELIMITER = ",";
+
+ private final List<String> userNames;
+
+ private UserNamesRequest(List<String> userNames) {
+ this.userNames = userNames;
+ }
+
+ public static UserNamesRequest from(String userNames) {
+ validateUserNames(userNames);
+ List<String> splitUserNames = Arrays.stream(userNames.split(USER_NAME_DELIMITER))
+ .map(String::trim)
+ .collect(Collectors.toList());
+ validateDuplicate(splitUserNames);
+ return new UserNamesRequest(splitUserNames);
+ }
+
+ public List<String> userNames() {
+ return Collections.unmodifiableList(userNames);
+ }
+
+ private static void validateUserNames(String userNames) {
+ if (userNames == null || userNames.trim().isEmpty()) {
+ throw new IllegalArgumentException("[ERROR] ์ด๋ฆ์ ์
๋ ฅํด ์ฃผ์ธ์");
+ }
+ }
+
+ private static void validateDuplicate(List<String> splitUserNames) {
+ Set<String> removeDuplicate = new HashSet<>(splitUserNames);
+ if (removeDuplicate.size() != splitUserNames.size()) {
+ throw new IllegalArgumentException("[ERROR] ํ๋ ์ด์ด ์ด๋ฆ์ ์ค๋ณต๋ ์ ์์ต๋๋ค");
+ }
+ }
+} | Java | ์ด ์ ํจ์ฑ ๊ฒ์ฆ ๋ก์ง์ ๋ธ๋์ญ ๋๋ฉ์ธ ๋ชจ๋ธ์ ๊ผญ ํ์ํ ์ ํจ์ฑ ๊ฒ์ฆ์ธ ๊ฒ ๊ฐ์์. ๐
๋จผ์ Player์ ์ํ ๊ฐ์ธ ์์ ๊ฐ name์ ํฌ์ฅํด๋ณด๋ฉด ์ด๋จ๊น์? ๐ค |
@@ -0,0 +1,55 @@
+package blackjack.domain.user;
+
+import blackjack.domain.card.Card;
+import blackjack.domain.card.CardBundle;
+import java.util.List;
+
+public class Player {
+
+ protected final CardBundle cardBundle;
+ private final String name;
+
+ public Player(String name) {
+ validateName(name);
+ this.name = name;
+ this.cardBundle = CardBundle.emptyBundle();
+ }
+
+ private void validateName(String name) {
+ if (name == null || name.trim().length() == 0) {
+ throw new IllegalArgumentException("[ERROR] ์ฌ๋ฐ๋ฅด์ง ์์ ์ด๋ฆ์ ์
๋ ฅ ๊ฐ์
๋๋ค.");
+ }
+ }
+
+ public void drawCard(Card card) {
+ this.cardBundle.addCard(card);
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public boolean isPlayer() {
+ return true;
+ }
+
+ public boolean isDealer() {
+ return false;
+ }
+
+ public int score() {
+ return cardBundle.calculateScore();
+ }
+
+ public boolean isDrawable() {
+ return !cardBundle.isBlackJack() && !cardBundle.isBurst();
+ }
+
+ public List<Card> getCardBundle() {
+ return cardBundle.getCards();
+ }
+
+ public boolean isBlackJack() {
+ return cardBundle.isBlackJack();
+ }
+} | Java | String์ `isEmpty` ํจ์๋ฅผ ๋์ ์ฌ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์? ๐
```suggestion
if (name == null || name.trim().isEmpty()) {
``` |
@@ -0,0 +1,33 @@
+package blackjack.domain.user;
+
+import blackjack.domain.report.GameResult;
+import blackjack.domain.report.GameReport;
+
+public class Dealer extends Player {
+
+ private static final int DEALER_MUST_DRAW_SCORE = 16;
+
+ public Dealer() {
+ super("๋๋ฌ");
+ }
+
+ public GameReport createReport(Player player) {
+ GameResult gameResult = GameResult.comparing(player.cardBundle, this.cardBundle);
+ return new GameReport(player.name(), gameResult);
+ }
+
+ @Override
+ public boolean isPlayer() {
+ return false;
+ }
+
+ @Override
+ public boolean isDealer() {
+ return true;
+ }
+
+ @Override
+ public boolean isDrawable() {
+ return score() <= DEALER_MUST_DRAW_SCORE;
+ }
+} | Java | Dealer๊ฐ ์จ์ ํ Player ํด๋์ค๋ฅผ ๋ฐ๋ก ์์๋ฐ์๊ธฐ ๋๋ฌธ์ ์ด๋ค ๋ฉ์๋๋ฅผ ์ฌ์ ์ํด์ผ ํ๋์ง ํ์
ํ๊ธฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์. ๐ค
๊ณตํต์ผ๋ก ์ฌ์ฉํ๋ ๋ฉ์๋๋ ๊ทธ๋๋ก ์ฌ์ฉํ ์ ์๊ฒ ํ๋, ํ์ ๊ตฌํ์ฒด์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋ ๊ธฐ๋ฅ๋ค์ `์ถ์ ๋ฉ์๋`๋ก ์ ์ํด์ ํ์ ๊ตฌํ์ฒด์์๋ ์ฌ์ ์๋ฅผ ๊ฐ์ ํ๋๋ก ํ๋ฉด ์ข์ง ์์๊น์? ๐ |
@@ -0,0 +1,33 @@
+package blackjack.domain.user;
+
+import blackjack.domain.report.GameResult;
+import blackjack.domain.report.GameReport;
+
+public class Dealer extends Player {
+
+ private static final int DEALER_MUST_DRAW_SCORE = 16;
+
+ public Dealer() {
+ super("๋๋ฌ");
+ }
+
+ public GameReport createReport(Player player) {
+ GameResult gameResult = GameResult.comparing(player.cardBundle, this.cardBundle);
+ return new GameReport(player.name(), gameResult);
+ }
+
+ @Override
+ public boolean isPlayer() {
+ return false;
+ }
+
+ @Override
+ public boolean isDealer() {
+ return true;
+ }
+
+ @Override
+ public boolean isDrawable() {
+ return score() <= DEALER_MUST_DRAW_SCORE;
+ }
+} | Java | GameReport ๊ฐ์ฒด์ ์ํ ๊ฐ์ผ๋ก Player์ ์ด๋ฆ์ ๋ฐ๋๊ฒ ์๋๋ผ `Player`๋ฅผ ๊ฐ์ง๋ฉด ์ด๋จ๊น์? ๐ค |
@@ -0,0 +1,82 @@
+package blackjack.view;
+
+import static blackjack.domain.user.Players.START_CARD_INIT_SIZE;
+
+import blackjack.domain.report.GameReports;
+import blackjack.domain.card.Card;
+import blackjack.domain.user.Player;
+import blackjack.domain.user.Players;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class OutputView {
+
+ private OutputView() {
+ }
+
+ public static void printAllPlayersCard(Players players) {
+ List<Player> candiates = players.findOnlyPlayers();
+ Player dealer = players.findDealer();
+ System.out.printf("\n๋๋ฌ์ %s์๊ฒ %d์ฅ ๋๋์์ต๋๋ค.\n", collectPlayerNames(candiates),
+ START_CARD_INIT_SIZE);
+ System.out.printf("%s : %s\n", dealer.name(), collectDealerCard(dealer));
+ candiates.forEach(OutputView::printEachCardInfo);
+ System.out.println();
+ }
+
+ public static void printEachCardInfo(Player player) {
+ System.out.printf("%s : %s\n", player.name(), collectPlayerCard(player));
+ }
+
+ public static void printDealerGetCard() {
+ System.out.println("\n๋๋ฌ๋ 16์ดํ๋ผ ํ์ฅ์ ์นด๋๋ฅผ ๋ ๋ฐ์์ต๋๋ค.");
+ }
+
+ public static void printResultStatus(List<Player> players) {
+ System.out.println();
+ players.forEach(OutputView::showEachResult);
+ }
+
+ public static void printReports(GameReports reports) {
+ System.out.println("\n## ์ต์ข
์นํจ");
+ showDealerReports(reports);
+ reports.reports()
+ .stream()
+ .map(report -> String.format("%s: %s", report.name(), report.message()))
+ .forEach(System.out::println);
+ }
+
+ private static void showDealerReports(GameReports reports) {
+ int dealerWinCount = reports.getPlayerLoseCount();
+ int drawCount = reports.getPlayerDrawCount();
+ int dealerLoseCount = reports.getPlayerWinCount();
+ System.out.printf("๋๋ฌ: %d์น %d๋ฌด %dํจ\n", dealerWinCount, drawCount, dealerLoseCount);
+ }
+
+ private static String collectPlayerNames(List<Player> candiates) {
+ return candiates.stream()
+ .map(Player::name)
+ .collect(Collectors.joining(","));
+ }
+
+ private static String collectDealerCard(Player dealer) {
+ List<Card> cards = dealer.getCardBundle();
+ return makeCardInfo(cards.get(0));
+ }
+
+ private static String makeCardInfo(Card card) {
+ return String.join("", card.message(), card.suit());
+ }
+
+ private static String collectPlayerCard(Player player) {
+ List<Card> cards = player.getCardBundle();
+ return cards.stream()
+ .map(OutputView::makeCardInfo)
+ .collect(Collectors.joining(", "));
+ }
+
+ private static void showEachResult(Player player) {
+ System.out.printf("%s์นด๋: %s - ๊ฒฐ๊ณผ : %d\n", player.name(), collectPlayerCard(player),
+ player.score());
+ }
+} | Java | `findOnlyPlayers`์ `findDealer`๋ ๋น์ฆ๋์ค ๋ก์ง์ด๊ธฐ ๋๋ฌธ์ Model์ ์์ญ์ด๋ผ๊ณ ๋ณผ ์ ์์ด์. ๐
Controller์์ ๋ ๋ฉ์๋๋ฅผ ํธ์ถํ ๋ค, ๋ฉ์๋ ํ๋ผ๋ฏธํฐ๋ก ๊ทธ ๊ฒฐ๊ณผ ๊ฐ๋ค์ ์ ๋ฌ๋ฐ๋๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์! ๐ |
@@ -0,0 +1,34 @@
+package blackjack.domain.card;
+
+public enum Number {
+
+ ACE(1, "A"),
+ TWO(2, "2"),
+ THREE(3, "3"),
+ FOUR(4, "4"),
+ FIVE(5, "5"),
+ SIX(6, "6"),
+ SEVEN(7, "7"),
+ EIGHT(8, "8"),
+ NINE(9, "9"),
+ TEN(10, "10"),
+ JACK(10, "J"),
+ QUEEN(10, "Q"),
+ KING(10, "K");
+
+ private final int score;
+ private final String message;
+
+ Number(int score, String message) {
+ this.score = score;
+ this.message = message;
+ }
+
+ public int score() {
+ return score;
+ }
+
+ public String message() {
+ return message;
+ }
+} | Java | ์ ๋ `getXXX`๊ณผ ๊ฐ์ ๋ค์ด๋ฐ์ด ์คํ๋ ค ๋ด๋ถ ์์ฑ์ ๋
ธ์ถํ๋ค๊ณ ์๊ฐํด์
`์๋ฏธ์๋ ๋ค์ด๋ฐ์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋๊ฒ ๋ ๋ซ์ง ์์๊น?` ๋ผ๋ ์๊ฐ์ผ๋ก ๋ฉ์๋์ ๋ค์ด๋ฐ์ ์์ฑํด๋ณด์๋๋ฐ
ํด๋น์ ๋ํด์๋ `getXXX`์ผ๋ก ํต์ผํ๋๊ฒ ๋ ์ข์๊น์? |
@@ -0,0 +1,42 @@
+package blackjack.domain.card;
+
+import blackjack.domain.score.ScoreCalculator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class CardBundle {
+
+ private static final int BLACK_JACK_SCORE = 21;
+
+ private final List<Card> cards;
+
+ private CardBundle() {
+ this.cards = new ArrayList<>();
+ }
+
+ public static CardBundle emptyBundle() {
+ return new CardBundle();
+ }
+
+ public void addCard(Card card) {
+ cards.add(card);
+ }
+
+ public int calculateScore() {
+ return ScoreCalculator.findByCards(cards)
+ .calculateScore(cards);
+ }
+
+ public List<Card> getCards() {
+ return Collections.unmodifiableList(cards);
+ }
+
+ public boolean isBurst() {
+ return calculateScore() > BLACK_JACK_SCORE;
+ }
+
+ public boolean isBlackJack() {
+ return calculateScore() == BLACK_JACK_SCORE;
+ }
+} | Java | `empty()`๋ ๊ด์ฐฎ์ ๋ค์ด๋ฐ์ด๋ผ๊ณ ์๊ฐํ์ง๋ง,
ํด๋น ๋ฒ๋ค์ด ๋น์ด์๋ค๋ ์๋ฏธ(`isEmpty()`)์ ์ ์ฌํ๊ฒ ํด์๋ ์๋ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค. |
@@ -0,0 +1,51 @@
+package blackjack.domain.report;
+
+import java.util.Objects;
+
+public class GameReport {
+
+ private final String name;
+ private final GameResult result;
+
+ public GameReport(String name, GameResult result) {
+ this.name = name;
+ this.result = result;
+ }
+
+ public String name() {
+ return name;
+ }
+
+ public String message() {
+ return result.message();
+ }
+
+ public boolean isWin() {
+ return result == GameResult.WIN;
+ }
+
+ public boolean isDraw() {
+ return result == GameResult.DRAW;
+ }
+
+ public boolean isLose() {
+ return result == GameResult.LOSE;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ GameReport report = (GameReport) o;
+ return Objects.equals(name, report.name) && result == report.result;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, result);
+ }
+} | Java | ์ ์ฒ์์ GameReports์ `Set`์ ์๋ํ๊ณ ๊ตฌํํ๋๋ฐ ์ง๊ธ์ ๋ถํ์ํ ๋ฉ์๋๋ผ๊ณ ์๊ฐ๋์ด ์ญ์ ํ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,19 @@
+import { ShoppingCartIcon } from "../../assets";
+import { BaseButton } from "./BaseButton";
+import { StyledCartButtonImg, StyledCartCount, StyledContainer } from "./CartButton.styled";
+
+interface CartButtonProps {
+ quantity: number;
+ onClick: () => void;
+}
+
+export const CartButton = ({ quantity, onClick }: CartButtonProps) => {
+ return (
+ <BaseButton onClick={onClick}>
+ <StyledContainer>
+ <StyledCartButtonImg src={ShoppingCartIcon} />
+ {quantity && <StyledCartCount>{quantity}</StyledCartCount>}
+ </StyledContainer>
+ </BaseButton>
+ );
+}; | Unknown | ์ ํ๋ฆฌ์ผ์ด์
์ด ์ฒ์ ์คํ๋์ ๋ fetchํ ์ดํ์๋, ๋ด๊ธฐ/๋นผ๊ธฐ ๋ฒํผ์ ๋๋ฌ๋ productCount๊ฐ ๋ณ๊ฒฝ๋์ง ์๊ธฐ ๋๋ฌธ์ ์ค์๊ฐ์ผ๋ก ๊ฐ์๋ฅผ ์
๋ฐ์ดํธํ์ง ๋ชปํ๋ ๊ฒ์ผ๋ก ์ดํดํ์ด์. prop์ผ๋ก `productCount`๊ฐ๊ณผ `updateProductCount` ํจ์๋ฅผ ๋ง๋ค์ด CartActionButton๋ก ๋๊ฒจ์ฃผ๊ณ , CartActionButton์์๋ action์ด ์ผ์ด๋๋ฉด `updateProductCount`์ ๋ฐ๋ ๊ฐ์๋ฅผ CartButton์ผ๋ก ์ ๋ฌํ๋ฉด ์
๋ฐ์ดํธํ ์ ์์ ๊ฒ ๊ฐ์์!๐ |
@@ -0,0 +1,18 @@
+package subway.config;
+
+import lombok.extern.slf4j.*;
+import org.springframework.http.*;
+import org.springframework.web.bind.annotation.*;
+
+@Slf4j
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+ @ExceptionHandler(RuntimeException.class)
+ public ResponseEntity<ErrorResponse> runtimeException(final RuntimeException e) {
+
+ log.error("error: ", e);
+ return ResponseEntity.badRequest()
+ .body(new ErrorResponse(e.getMessage()));
+ }
+} | Java | ์๋ฌ ๊ณตํต ์ฒ๋ฆฌ๋ฅผ ์ ํด์ฃผ์
จ๋ค์! ๐
์์ธ์ข
๋ฅ์ ๋ฐ๋ผ ๋ก๊น
๋ ๋ฒจ์ ์ ์ ํ๊ฒ ๋ถ๋ฆฌํด์ ๋ก๊ทธ๋ฅผ ๋จ๊ธฐ๋ ๊ฒ๋ ์ข์ ๊ฑฐ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
logging level ๊ด๋ จํด์๋ ์๋ ๋ด์ฉ์ ์ฐธ๊ณ ํด ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.
์) log.error("Unexpected exception occurred: {}", e.getMessage(), e);
โ DEBUG : ๊ฐ๋ฐ๋จ๊ณ์์๋ถํฐ ํ์ฑํ.ํ๋ก์ธ์ค์์ฒ๋ฆฌ์์/ํ๋ฆ์๋ถ์ํ๋๋ฐ ๋์์ด ๋๋ ์ ๋ณด ๋ฑ
โ INFO : ๋๋ฒ๊น
์ ๋ณด์ธ์ ํ๋ก์ธ์ค์ค์ / ๊ธฐ๋์ ๊ด๋ จํ ์ ๋ณด ๋ฑ
โ WARN : ์ค๋ฅ์ํฉ์ ์๋์ง๋ง, ์ถํํ์ธ์ด ํ์ํ ์ ๋ณด ๋ฑ
โ ERROR : ์ค๋ฅ๊ฐ ๋ฐ์ํ์ํฉ .์ฆ์ ๋์์ด ํ์ํ ์์์
โ FATAL : ๋งค์ฐ ์ฌ๊ฐํ์ํฉ. ์ฆ์ ๋์์ด ํ์ํจ |
@@ -1,13 +1,13 @@
package subway.line;
import lombok.*;
+import subway.*;
+import subway.line.section.*;
import javax.persistence.*;
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-@AllArgsConstructor(access = AccessLevel.PRIVATE)
-@Builder
@Getter
public class Line {
@@ -21,13 +21,27 @@ public class Line {
private String color;
@Embedded
- @Builder.Default
- private LineStations lineStations = new LineStations();
+ private Sections sections;
+
+ @Builder
+ private Line(
+ final Long id,
+ final String name,
+ final String color,
+ final Section section
+ ) {
+
+ section.changeLine(this);
+ this.id = id;
+ this.name = name;
+ this.color = color;
+ this.sections = new Sections(section);
+ }
- public Line addLineStation(final LineStation lineStation) {
+ public Line addSection(final Section section) {
- this.lineStations.add(lineStation);
- lineStation.changeLine(this);
+ this.sections.add(section);
+ section.changeLine(this);
return this;
}
@@ -37,4 +51,10 @@ public Line change(final String name, final String color) {
return this;
}
+ public Line removeSection(final Station downStation) {
+
+ this.sections.remove(downStation);
+ return this;
+ }
+
} | Java | `@Embedded ์ ์ด์ฉํด ๋๋ฉ์ธ ๋ก์ง์ ์ ๋ถ๋ฆฌํด ์ฃผ์
จ๊ตฐ์! ๐ |
@@ -0,0 +1,49 @@
+package subway.line.section;
+
+import lombok.*;
+import org.springframework.stereotype.*;
+import org.springframework.transaction.annotation.*;
+import subway.*;
+import subway.line.*;
+
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class SectionService {
+
+ private final StationService stationService;
+ private final LineService lineService;
+
+ public void addSection(final Long lineId, final SectionAddRequest request) {
+
+ final var line = lineService.getById(lineId);
+
+ final var upStation = stationService.getById(request.getUpStationId());
+ final var downStation = stationService.getById(request.getDownStationId());
+
+ line.addSection(createSection(request, line, upStation, downStation));
+ }
+
+ private static Section createSection(
+ final SectionAddRequest request,
+ final Line line,
+ final Station upStationId,
+ final Station downStationId
+ ) {
+
+ return Section.builder()
+ .line(line)
+ .upStation(upStationId)
+ .downStation(downStationId)
+ .distance(request.getDistance())
+ .build();
+ }
+
+ public void removeSection(final Long lineId, final Long stationId) {
+
+ final var line = lineService.getById(lineId);
+ final var station = stationService.getById(stationId);
+
+ line.removeSection(station);
+ }
+} | Java | ํด๋น ํจ์๋ SectionService ์์๋ง ์ฌ์ฉํ๋ ๊ฒ์ผ๋ก ๋ณด์ฌ์ง๋๋ฐ static ์ผ๋ก ์ ์ธํ ์ด์ ๊ฐ ์์๊น์? ๐ |
@@ -0,0 +1,81 @@
+package subway.line.section;
+
+import lombok.*;
+import subway.*;
+
+import javax.persistence.*;
+import java.util.*;
+
+@Embeddable
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class Sections {
+
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "line", cascade = CascadeType.ALL, orphanRemoval = true)
+ private List<Section> values = new ArrayList<>();
+
+ public Sections(final Section section) {
+ final ArrayList<Section> sections = new ArrayList<>();
+ sections.add(section);
+ this.values = sections;
+ }
+
+ public Sections add(final Section section) {
+
+ validationLastStation(section.getUpStation());
+
+ if (this.anyMatchStation(section.getDownStation())) {
+ throw new DuplicateSectionStationException();
+ }
+
+ this.values.add(section);
+ return this;
+ }
+
+ private void validationLastStation(final Station section) {
+ if (!this.isLastStation(section)) {
+ throw new NotLastDownStationException();
+ }
+ }
+
+ public Sections remove(final Station downStation) {
+ validationLastStation(downStation);
+ if(isOnlyOne()) {
+ throw new OnlyOneSectionException();
+ }
+
+ this.values.removeIf(section -> section.isDownStation(downStation));
+ return this;
+ }
+
+ private boolean isOnlyOne() {
+ return this.values.size() == 1;
+ }
+
+ public List<Section> getValues() {
+
+ return List.copyOf(this.values);
+ }
+
+ public boolean isLastStation(final Station station) {
+
+ return getLastSection()
+ .map(section -> section.isDownStation(station))
+ .orElse(false);
+ }
+
+ private Optional<Section> getLastSection() {
+ if(this.values.isEmpty()) {
+ return Optional.empty();
+ }
+ return Optional.of(this.values.get(lastIndex()));
+ }
+
+ private int lastIndex() {
+ return this.values.size() - 1;
+ }
+
+ public boolean anyMatchStation(final Station station) {
+ return this.values.stream()
+ .anyMatch(section -> section.anyMatchStation(station));
+ }
+} | Java | ๋งค๊ฐ๋ณ์ ํ์
์ Station ์ธ๋ฐ ๋ณ์ ๋ช
์ section ์ด์ฌ์ ํผ๋์ด ์์ด ๋ณด์ฌ์! ๐ |
@@ -0,0 +1,55 @@
+package subway.given;
+
+import io.restassured.response.*;
+import org.springframework.http.*;
+
+import java.util.*;
+
+import static io.restassured.RestAssured.*;
+
+public class GivenLineApi {
+
+ public static final String LINE_PATH = "/lines";
+ public static final String BG_COLOR_600 = "bg-color-600";
+
+ public static final String LINE_1 = "์ ๋ถ๋น์ ";
+ public static final String LINE_2 = "๋ถ๋น์ ";
+
+ public static final Long LINE_ID_1 = 1L;
+
+ public static final Long STATION_ID_1 = 1L;
+ public static final Long STATION_ID_2 = 2L;
+ public static final Long STATION_ID_3 = 3L;
+
+ public static ExtractableResponse<Response> createLine(
+ final String name,
+ final Long upStationId,
+ final Long downStationId
+ ) {
+
+ final var params = new HashMap<>();
+ params.put("name", name);
+ params.put("color", BG_COLOR_600);
+ params.put("upStationId", upStationId.toString());
+ params.put("downStationId", downStationId.toString());
+ params.put("distance", "10");
+
+ // When
+ return given().log().all()
+ .body(params)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .when()
+ .post(LINE_PATH)
+ .then().log().all()
+ .extract();
+ }
+
+ public static ExtractableResponse<Response> getLineById(final Long lineId) {
+ return given().log().all()
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .when()
+ .get(LINE_PATH + "/" + lineId)
+ .then().log().all()
+ .extract();
+ }
+} | Java | Map ์ผ๋ก ๋ง๋ค์ด์ ๋๊ธฐ๊ธฐ ๋ณด๋ค๋ DTO ๋ก ๋ง๋ค์ด๋ ์ข์ง ์์๊น์? โบ๏ธ |
@@ -0,0 +1,171 @@
+package subway.line.section;
+
+import io.restassured.response.*;
+import org.junit.jupiter.api.*;
+import org.springframework.boot.test.context.*;
+import org.springframework.test.annotation.*;
+
+import java.util.*;
+
+import static io.restassured.RestAssured.*;
+import static org.assertj.core.api.Assertions.*;
+import static org.springframework.http.HttpStatus.*;
+import static org.springframework.http.MediaType.*;
+import static subway.given.GivenLineApi.*;
+import static subway.given.GivenStationApi.*;
+
+@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+public class SectionAcceptanceTest {
+
+ public static final String BASE_SECTION_PATH = "/lines/1/sections";
+
+ @BeforeEach
+ void setUp() {
+ createStationApi(STATION_1);
+ createStationApi(STATION_2);
+ createStationApi(STATION_3);
+ createLine(LINE_1, STATION_ID_1, STATION_ID_2);
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์์ ๋,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ๋ฉด
+ * Then: ๋ชฉ๋ก ์กฐํ ์ ์ถ๊ฐ๋ ๊ตฌ๊ฐ์ ํ์ธํ ์ ์๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก")
+ void addSection() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_2, STATION_ID_3);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(OK.value());
+
+ final var lineResponse = getLineById(LINE_ID_1);
+ final var stationIds = lineResponse.jsonPath().getList("stations.id", Long.class);
+ assertThat(stationIds.size()).isEqualTo(3);
+ assertThat(stationIds).containsAnyOf(1L, 2L, 3L);
+ }
+
+ private static HashMap<Object, Object> getAddSectionParams(final Long upStationId, final Long downStationId) {
+ final var params = new HashMap<>();
+ params.put("upStationId", upStationId);
+ params.put("downStationId", downStationId);
+ params.put("distance", "10");
+ return params;
+ }
+
+ private static ExtractableResponse<Response> addSection(final HashMap<Object, Object> params) {
+ return given().log().all()
+ .when()
+ .contentType(APPLICATION_JSON_VALUE)
+ .body(params)
+ .post(BASE_SECTION_PATH)
+ .then().log().all()
+ .extract();
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ ๋,
+ * Then: ์ํ์ญ์ด ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ํํ ์ข
์ ์ญ์ด ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก - ์ํ์ญ์ ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ํํ ์ข
์ ์ญ์ด ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ void addSectionThrow1() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_1, STATION_ID_3);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๋ ๊ฐ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ ๋,
+ * Then: ์๋ก์ด ๊ตฌ๊ฐ์ ํํ์ญ์ด ํด๋น ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ์ญ์ด๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก - ์๋ก์ด ๊ตฌ๊ฐ์ ํํ์ญ์ ํด๋น ๋
ธ์ ์ ๋ฑ๋ก๋์ด์๋ ์ญ์ผ ์ ์๋ค.")
+ void addSectionThrow2() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_2, STATION_ID_1);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ํํ ์ข
์ ์ญ์ ์ญ์ ํ๋ฉด
+ * Then: ๋ชฉ๋ก ์กฐํ ์ ์ญ์ ๋ ๊ตฌ๊ฐ์ ๋์ค์ง ์๋๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ ")
+ void removeSection() throws Exception {
+ // Given
+ addSection(getAddSectionParams(STATION_ID_2, STATION_ID_3));
+
+ // When
+ final var response = removeSection(STATION_ID_3);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(NO_CONTENT.value());
+
+ final var lineResponse = getLineById(LINE_ID_1);
+ final var stationIds = lineResponse.jsonPath().getList("stations.id", Long.class);
+ assertThat(stationIds.size()).isEqualTo(2);
+ assertThat(stationIds).containsAnyOf(1L, 2L);
+ }
+
+ private static ExtractableResponse<Response> removeSection(final Long stationId) {
+ return given().log().all()
+ .when()
+ .delete(BASE_SECTION_PATH + "?stationId=" + stationId)
+ .then().log().all()
+ .extract();
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๋ ๊ฐ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ญ์ ํ ๋,
+ * Then: ๋ง์ง๋ง ๊ตฌ๊ฐ์ด ์๋๋ฉด ์ญ์ ๋์ง ์๋๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ - ๋ง์ง๋ง ๊ตฌ๊ฐ์ด ์๋๋จ ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ void removeSectionThrow1() throws Exception {
+ // Given
+ addSection(getAddSectionParams(STATION_ID_2, STATION_ID_3));
+
+ // When
+ final var response = removeSection(STATION_ID_2);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์์ ๋
+ * When: ๊ตฌ๊ฐ์ ์ญ์ ํ๋ฉด
+ * Then: ๊ตฌ๊ฐ์ ์ญ์ ํ ์ ์๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ - ๊ตฌ๊ฐ์ด ํ๋์ผ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ๋ค")
+ void removeSectionThrow2() throws Exception {
+ // When
+ final var response = removeSection(STATION_ID_2);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+} | Java | `@DirtiesContext` ๋ฅผ ํ์ฉํด ํ
์คํธ ๊ฒฉ๋ฆฌ๋ฅผ ํด ์ฃผ์
จ๊ตฐ์! ๐
`@DirtiesContext` ๋ ์ปจํ
์คํธ๋ฅผ ๋ค์ ๋ก๋ํ๊ธฐ ๋๋ฌธ์ ํ
์คํธ ์๋๊ฐ ์ค๋ ๊ฑธ๋ฆฐ๋ค๋ ๋จ์ ์ด ์์ต๋๋ค!
์ด ๋ถ๋ถ์ ํ๋ฒ ๊ณ ๋ฏผํด ๋ณด์๋ฉด ์ข์ ๊ฑฐ ๊ฐ์ต๋๋ค ๐ |
@@ -0,0 +1,171 @@
+package subway.line.section;
+
+import io.restassured.response.*;
+import org.junit.jupiter.api.*;
+import org.springframework.boot.test.context.*;
+import org.springframework.test.annotation.*;
+
+import java.util.*;
+
+import static io.restassured.RestAssured.*;
+import static org.assertj.core.api.Assertions.*;
+import static org.springframework.http.HttpStatus.*;
+import static org.springframework.http.MediaType.*;
+import static subway.given.GivenLineApi.*;
+import static subway.given.GivenStationApi.*;
+
+@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+public class SectionAcceptanceTest {
+
+ public static final String BASE_SECTION_PATH = "/lines/1/sections";
+
+ @BeforeEach
+ void setUp() {
+ createStationApi(STATION_1);
+ createStationApi(STATION_2);
+ createStationApi(STATION_3);
+ createLine(LINE_1, STATION_ID_1, STATION_ID_2);
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์์ ๋,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ๋ฉด
+ * Then: ๋ชฉ๋ก ์กฐํ ์ ์ถ๊ฐ๋ ๊ตฌ๊ฐ์ ํ์ธํ ์ ์๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก")
+ void addSection() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_2, STATION_ID_3);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(OK.value());
+
+ final var lineResponse = getLineById(LINE_ID_1);
+ final var stationIds = lineResponse.jsonPath().getList("stations.id", Long.class);
+ assertThat(stationIds.size()).isEqualTo(3);
+ assertThat(stationIds).containsAnyOf(1L, 2L, 3L);
+ }
+
+ private static HashMap<Object, Object> getAddSectionParams(final Long upStationId, final Long downStationId) {
+ final var params = new HashMap<>();
+ params.put("upStationId", upStationId);
+ params.put("downStationId", downStationId);
+ params.put("distance", "10");
+ return params;
+ }
+
+ private static ExtractableResponse<Response> addSection(final HashMap<Object, Object> params) {
+ return given().log().all()
+ .when()
+ .contentType(APPLICATION_JSON_VALUE)
+ .body(params)
+ .post(BASE_SECTION_PATH)
+ .then().log().all()
+ .extract();
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ ๋,
+ * Then: ์ํ์ญ์ด ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ํํ ์ข
์ ์ญ์ด ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก - ์ํ์ญ์ ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ํํ ์ข
์ ์ญ์ด ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ void addSectionThrow1() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_1, STATION_ID_3);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๋ ๊ฐ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ถ๊ฐ ๋ฑ๋กํ ๋,
+ * Then: ์๋ก์ด ๊ตฌ๊ฐ์ ํํ์ญ์ด ํด๋น ๋
ธ์ ์ ๋ฑ๋ก๋์ด ์๋ ์ญ์ด๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ๋ฑ๋ก - ์๋ก์ด ๊ตฌ๊ฐ์ ํํ์ญ์ ํด๋น ๋
ธ์ ์ ๋ฑ๋ก๋์ด์๋ ์ญ์ผ ์ ์๋ค.")
+ void addSectionThrow2() throws Exception {
+ // Given
+ final var params = getAddSectionParams(STATION_ID_2, STATION_ID_1);
+
+ // When
+ final var response = addSection(params);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ํํ ์ข
์ ์ญ์ ์ญ์ ํ๋ฉด
+ * Then: ๋ชฉ๋ก ์กฐํ ์ ์ญ์ ๋ ๊ตฌ๊ฐ์ ๋์ค์ง ์๋๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ ")
+ void removeSection() throws Exception {
+ // Given
+ addSection(getAddSectionParams(STATION_ID_2, STATION_ID_3));
+
+ // When
+ final var response = removeSection(STATION_ID_3);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(NO_CONTENT.value());
+
+ final var lineResponse = getLineById(LINE_ID_1);
+ final var stationIds = lineResponse.jsonPath().getList("stations.id", Long.class);
+ assertThat(stationIds.size()).isEqualTo(2);
+ assertThat(stationIds).containsAnyOf(1L, 2L);
+ }
+
+ private static ExtractableResponse<Response> removeSection(final Long stationId) {
+ return given().log().all()
+ .when()
+ .delete(BASE_SECTION_PATH + "?stationId=" + stationId)
+ .then().log().all()
+ .extract();
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ๋ ๊ฐ์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์๊ณ ,
+ * When: ๊ตฌ๊ฐ์ ์ญ์ ํ ๋,
+ * Then: ๋ง์ง๋ง ๊ตฌ๊ฐ์ด ์๋๋ฉด ์ญ์ ๋์ง ์๋๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ - ๋ง์ง๋ง ๊ตฌ๊ฐ์ด ์๋๋จ ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ void removeSectionThrow1() throws Exception {
+ // Given
+ addSection(getAddSectionParams(STATION_ID_2, STATION_ID_3));
+
+ // When
+ final var response = removeSection(STATION_ID_2);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+
+ /**
+ * Given: ๋
ธ์ ์ ํ๋์ ๊ตฌ๊ฐ์ด ๋ฑ๋ก๋์ด ์์ ๋
+ * When: ๊ตฌ๊ฐ์ ์ญ์ ํ๋ฉด
+ * Then: ๊ตฌ๊ฐ์ ์ญ์ ํ ์ ์๋ค.
+ */
+ @Test
+ @DisplayName("๊ตฌ๊ฐ ์ญ์ - ๊ตฌ๊ฐ์ด ํ๋์ผ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ๋ค")
+ void removeSectionThrow2() throws Exception {
+ // When
+ final var response = removeSection(STATION_ID_2);
+
+ // Then
+ assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.value());
+ }
+} | Java | ์์ธ ์๋๋ฆฌ์ค์ ๋ํด ํ
์คํธ๋ฅผ ์ํด์ฃผ์
จ๋ค์! ๐ |
@@ -0,0 +1,21 @@
+import React from 'react';
+
+class InputBox extends React.Component {
+ // eslint-disable-next-line no-useless-constructor
+ constructor(props) {
+ super(props);
+ }
+ render() {
+ const { name, type, placeholder, recivedValue } = this.props;
+ return (
+ <input
+ name={name}
+ type={type}
+ placeholder={placeholder}
+ onChange={recivedValue}
+ />
+ );
+ }
+}
+
+export default InputBox; | JavaScript | ์ด๋ถ๋ถ ์ ์ฃผ์์ฒ๋ฆฌํ์
จ๋์?
์ด๋ ๊ฒ ์์ฐ๋ ์ฝ๋๋ฅผ ์ฃผ์์ฒ๋ฆฌํด์ ๋จ๊ฒจ๋๋ฉด ๋ค๋ฅธ์ฌ๋๋ ์ด ์ฝ๋๊ฐ ์ด๋์ ์ฐ์ด๋๊ฑด๊ฐ ํด์ ๋ชจ๋ ๋ชป์ง์ฐ๊ณ ๊ฒฐ๊ตญ ์๋ฌด ์ธ๋ชจ ์์ง๋ง ๊ณ์ ์ ํด ๋ด๋ ค๊ฐ๋ ์ฃผ์์ฝ๋๊ฐ ๋ฉ๋๋ค
ํ์์๋ ์ฝ๋๋ ์ญ์ ํด์ฃผ์ธ์!
์ปค๋ฐ๋ง ์ ๋จ๊ฒจ๋๋ฉด ๋ค์ ๋์์ฌ ์ ์์ผ๋๊น ๊ณผ๊ฐํ๊ฒ ์ง์๋ ๋ฉ๋๋ค! |
@@ -0,0 +1,21 @@
+import React from 'react';
+
+class InputBox extends React.Component {
+ // eslint-disable-next-line no-useless-constructor
+ constructor(props) {
+ super(props);
+ }
+ render() {
+ const { name, type, placeholder, recivedValue } = this.props;
+ return (
+ <input
+ name={name}
+ type={type}
+ placeholder={placeholder}
+ onChange={recivedValue}
+ />
+ );
+ }
+}
+
+export default InputBox; | JavaScript | ```suggestion
const {name, type, placeholder, recivedValue} = this.props;
return (
<input
name={name}
type={type}
placeholder={placeholder}
onChange={recivedValue}
/>
);
```
๊ตฌ์กฐ๋ถํดํ ๋นํด์ ์ฐ๋ฉด ์ข ๋ ๊น๋ํ๊ฒ ๋ค์ |
@@ -0,0 +1,85 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import InputBox from './InputBox/InputBox';
+import './JaehyunLogin.scss';
+
+class JaehyunLogin extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: '',
+ password: '',
+ };
+ }
+
+ inputChangeHandler = e => {
+ const { name, value } = e.target;
+ let userIdCheck = true;
+ if (name === 'userName') {
+ this.setState({
+ userName: value,
+ });
+ userIdCheck = value.indexOf('@') === -1;
+ }
+ if (name === 'password') {
+ let passwordCheck = true;
+ this.setState({
+ password: value,
+ });
+ passwordCheck = value.length < 5;
+ }
+ };
+
+ goToMain = e => {
+ e.preventDefault();
+ fetch('http://10.58.0.158:8000/users/signup', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.userName,
+ password: this.state.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+
+ this.props.history.push('./JaehyunMain');
+ };
+
+ render() {
+ return (
+ <main className="container">
+ <div className="titleText">Westagram</div>
+ <form action="summit">
+ <InputBox
+ name="userName"
+ type="email"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <InputBox
+ name="password"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <button
+ id="loginButton"
+ onClick={this.goToMain}
+ disabled={this.userIdCheck || this.passwordCheck}
+ style={
+ this.userIdCheck || this.passwordCheck
+ ? { opacity: '10%' }
+ : { opacity: '100%' }
+ }
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ <h3 className="passwordText">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</h3>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunLogin); | JavaScript | import ์์ ๋ง์ถฐ์ฃผ์ธ์ |
@@ -0,0 +1,85 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import InputBox from './InputBox/InputBox';
+import './JaehyunLogin.scss';
+
+class JaehyunLogin extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: '',
+ password: '',
+ };
+ }
+
+ inputChangeHandler = e => {
+ const { name, value } = e.target;
+ let userIdCheck = true;
+ if (name === 'userName') {
+ this.setState({
+ userName: value,
+ });
+ userIdCheck = value.indexOf('@') === -1;
+ }
+ if (name === 'password') {
+ let passwordCheck = true;
+ this.setState({
+ password: value,
+ });
+ passwordCheck = value.length < 5;
+ }
+ };
+
+ goToMain = e => {
+ e.preventDefault();
+ fetch('http://10.58.0.158:8000/users/signup', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.userName,
+ password: this.state.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+
+ this.props.history.push('./JaehyunMain');
+ };
+
+ render() {
+ return (
+ <main className="container">
+ <div className="titleText">Westagram</div>
+ <form action="summit">
+ <InputBox
+ name="userName"
+ type="email"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <InputBox
+ name="password"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <button
+ id="loginButton"
+ onClick={this.goToMain}
+ disabled={this.userIdCheck || this.passwordCheck}
+ style={
+ this.userIdCheck || this.passwordCheck
+ ? { opacity: '10%' }
+ : { opacity: '100%' }
+ }
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ <h3 className="passwordText">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</h3>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunLogin); | JavaScript | peer review์ ํ์ต์๋ฃ๋ก ์ ๊ณต๋ ๋ฆฌํฉํ ๋ง ์ฒดํฌ๋ฆฌ์คํธ ํ์ธํด๋ณด์๋ฉด ๋ฉ๋๋ค. |
@@ -0,0 +1,85 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import InputBox from './InputBox/InputBox';
+import './JaehyunLogin.scss';
+
+class JaehyunLogin extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: '',
+ password: '',
+ };
+ }
+
+ inputChangeHandler = e => {
+ const { name, value } = e.target;
+ let userIdCheck = true;
+ if (name === 'userName') {
+ this.setState({
+ userName: value,
+ });
+ userIdCheck = value.indexOf('@') === -1;
+ }
+ if (name === 'password') {
+ let passwordCheck = true;
+ this.setState({
+ password: value,
+ });
+ passwordCheck = value.length < 5;
+ }
+ };
+
+ goToMain = e => {
+ e.preventDefault();
+ fetch('http://10.58.0.158:8000/users/signup', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.userName,
+ password: this.state.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+
+ this.props.history.push('./JaehyunMain');
+ };
+
+ render() {
+ return (
+ <main className="container">
+ <div className="titleText">Westagram</div>
+ <form action="summit">
+ <InputBox
+ name="userName"
+ type="email"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <InputBox
+ name="password"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <button
+ id="loginButton"
+ onClick={this.goToMain}
+ disabled={this.userIdCheck || this.passwordCheck}
+ style={
+ this.userIdCheck || this.passwordCheck
+ ? { opacity: '10%' }
+ : { opacity: '100%' }
+ }
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ <h3 className="passwordText">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</h3>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunLogin); | JavaScript | [๊ณต์๋ฌธ์ React๋ก ์ฌ๊ณ ํ๊ธฐ](https://ko.reactjs.org/docs/thinking-in-react.html#step-3-identify-the-minimal-but-complete-representation-of-ui-state) ๋ฅผ ๋ณด์๋ฉด ์ด๋ค ๊ฐ๋ค์ด state๊ฐ ๋์ด์ผํ๋์ง์ ๋ํด ์ ํ์์ต๋๋ค.
> ๊ฐ๊ฐ ์ดํด๋ณด๊ณ ์ด๋ค ๊ฒ state๊ฐ ๋์ด์ผ ํ๋ ์ง ์ดํด๋ด
์๋ค. ์ด๋ ๊ฐ ๋ฐ์ดํฐ์ ๋ํด ์๋์ ์ธ ๊ฐ์ง ์ง๋ฌธ์ ํตํด ๊ฒฐ์ ํ ์ ์์ต๋๋ค
> 1. ๋ถ๋ชจ๋ก๋ถํฐ props๋ฅผ ํตํด ์ ๋ฌ๋ฉ๋๊น? ๊ทธ๋ฌ๋ฉด ํ์คํ state๊ฐ ์๋๋๋ค.
> 2. ์๊ฐ์ด ์ง๋๋ ๋ณํ์ง ์๋์? ๊ทธ๋ฌ๋ฉด ํ์คํ state๊ฐ ์๋๋๋ค.
> 3. ์ปดํฌ๋ํธ ์์ ๋ค๋ฅธ state๋ props๋ฅผ ๊ฐ์ง๊ณ ๊ณ์ฐ ๊ฐ๋ฅํ๊ฐ์? ๊ทธ๋ ๋ค๋ฉด state๊ฐ ์๋๋๋ค.
- userIdCheck, passwordCheck๋ ๋ชจ๋ userName, password ๊ฐ์ผ๋ก๋ถํฐ ๊ณ์ฐ ๊ฐ๋ฅํ ๊ฐ์
๋๋ค -> state๋ก ๊ด๋ฆฌํ ํ์ ์์ต๋๋ค.
- ๋ ๋ํ ๋ ๊ณ์ฐํด์ ์ฌ์ฉํ ์ ์์ด ๋ณด์
๋๋ค. |
@@ -0,0 +1,85 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import InputBox from './InputBox/InputBox';
+import './JaehyunLogin.scss';
+
+class JaehyunLogin extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: '',
+ password: '',
+ };
+ }
+
+ inputChangeHandler = e => {
+ const { name, value } = e.target;
+ let userIdCheck = true;
+ if (name === 'userName') {
+ this.setState({
+ userName: value,
+ });
+ userIdCheck = value.indexOf('@') === -1;
+ }
+ if (name === 'password') {
+ let passwordCheck = true;
+ this.setState({
+ password: value,
+ });
+ passwordCheck = value.length < 5;
+ }
+ };
+
+ goToMain = e => {
+ e.preventDefault();
+ fetch('http://10.58.0.158:8000/users/signup', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.userName,
+ password: this.state.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+
+ this.props.history.push('./JaehyunMain');
+ };
+
+ render() {
+ return (
+ <main className="container">
+ <div className="titleText">Westagram</div>
+ <form action="summit">
+ <InputBox
+ name="userName"
+ type="email"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <InputBox
+ name="password"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <button
+ id="loginButton"
+ onClick={this.goToMain}
+ disabled={this.userIdCheck || this.passwordCheck}
+ style={
+ this.userIdCheck || this.passwordCheck
+ ? { opacity: '10%' }
+ : { opacity: '100%' }
+ }
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ <h3 className="passwordText">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</h3>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunLogin); | JavaScript | ์ฃผ์ ์ญ์ ํด์ฃผ์ธ์~ |
@@ -0,0 +1,85 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import InputBox from './InputBox/InputBox';
+import './JaehyunLogin.scss';
+
+class JaehyunLogin extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: '',
+ password: '',
+ };
+ }
+
+ inputChangeHandler = e => {
+ const { name, value } = e.target;
+ let userIdCheck = true;
+ if (name === 'userName') {
+ this.setState({
+ userName: value,
+ });
+ userIdCheck = value.indexOf('@') === -1;
+ }
+ if (name === 'password') {
+ let passwordCheck = true;
+ this.setState({
+ password: value,
+ });
+ passwordCheck = value.length < 5;
+ }
+ };
+
+ goToMain = e => {
+ e.preventDefault();
+ fetch('http://10.58.0.158:8000/users/signup', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.userName,
+ password: this.state.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+
+ this.props.history.push('./JaehyunMain');
+ };
+
+ render() {
+ return (
+ <main className="container">
+ <div className="titleText">Westagram</div>
+ <form action="summit">
+ <InputBox
+ name="userName"
+ type="email"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <InputBox
+ name="password"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <button
+ id="loginButton"
+ onClick={this.goToMain}
+ disabled={this.userIdCheck || this.passwordCheck}
+ style={
+ this.userIdCheck || this.passwordCheck
+ ? { opacity: '10%' }
+ : { opacity: '100%' }
+ }
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ <h3 className="passwordText">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</h3>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunLogin); | JavaScript | ```suggestion
const { name, value } = e.target;
this.setState({[name]:value});
}
```
๊ณ์ฐ๋ ์์ฑ๋ช
์ฌ์ฉํด์ ์ค์ผ ์ ์์ด๋ณด์
๋๋ค, passwordCheck, userIdCheck๋ ํ์์๋ ๊ฐ์ด๋๊น ์์ ๋ ๋๋ณด์
๋๋ค.
๊ทธ๋ฆฌ๊ณ check๋ ๋ญ๊ฐ ์ฒดํฌ๋ฐ์ค๊ฐ ์ฒดํฌ๋๊ณ ์๋๊ณ ๊ฐ์ง ์๋์? isPasswordValid ๋ฑ์ ์๋ฏธ๊ฐ ๋๋ฌ๋๊ณ , boolean์์ ์์๋ณผ ์ ์๋ ๋ค์ด๋ฐ์ ํด์ฃผ์ธ์ |
@@ -0,0 +1,85 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import InputBox from './InputBox/InputBox';
+import './JaehyunLogin.scss';
+
+class JaehyunLogin extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: '',
+ password: '',
+ };
+ }
+
+ inputChangeHandler = e => {
+ const { name, value } = e.target;
+ let userIdCheck = true;
+ if (name === 'userName') {
+ this.setState({
+ userName: value,
+ });
+ userIdCheck = value.indexOf('@') === -1;
+ }
+ if (name === 'password') {
+ let passwordCheck = true;
+ this.setState({
+ password: value,
+ });
+ passwordCheck = value.length < 5;
+ }
+ };
+
+ goToMain = e => {
+ e.preventDefault();
+ fetch('http://10.58.0.158:8000/users/signup', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.userName,
+ password: this.state.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+
+ this.props.history.push('./JaehyunMain');
+ };
+
+ render() {
+ return (
+ <main className="container">
+ <div className="titleText">Westagram</div>
+ <form action="summit">
+ <InputBox
+ name="userName"
+ type="email"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <InputBox
+ name="password"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <button
+ id="loginButton"
+ onClick={this.goToMain}
+ disabled={this.userIdCheck || this.passwordCheck}
+ style={
+ this.userIdCheck || this.passwordCheck
+ ? { opacity: '10%' }
+ : { opacity: '100%' }
+ }
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ <h3 className="passwordText">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</h3>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunLogin); | JavaScript | ๋ฐ๋ณต๋๋ UI๋ก ๋ณด์
๋๋ค, ์์๋ฐ์ดํฐ + Array.map method ํ์ฉํด์ ํํํด๋ณด์ธ์ |
@@ -0,0 +1,85 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import InputBox from './InputBox/InputBox';
+import './JaehyunLogin.scss';
+
+class JaehyunLogin extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: '',
+ password: '',
+ };
+ }
+
+ inputChangeHandler = e => {
+ const { name, value } = e.target;
+ let userIdCheck = true;
+ if (name === 'userName') {
+ this.setState({
+ userName: value,
+ });
+ userIdCheck = value.indexOf('@') === -1;
+ }
+ if (name === 'password') {
+ let passwordCheck = true;
+ this.setState({
+ password: value,
+ });
+ passwordCheck = value.length < 5;
+ }
+ };
+
+ goToMain = e => {
+ e.preventDefault();
+ fetch('http://10.58.0.158:8000/users/signup', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.userName,
+ password: this.state.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+
+ this.props.history.push('./JaehyunMain');
+ };
+
+ render() {
+ return (
+ <main className="container">
+ <div className="titleText">Westagram</div>
+ <form action="summit">
+ <InputBox
+ name="userName"
+ type="email"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <InputBox
+ name="password"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <button
+ id="loginButton"
+ onClick={this.goToMain}
+ disabled={this.userIdCheck || this.passwordCheck}
+ style={
+ this.userIdCheck || this.passwordCheck
+ ? { opacity: '10%' }
+ : { opacity: '100%' }
+ }
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ <h3 className="passwordText">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</h3>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunLogin); | JavaScript | - `id` ๋ณด๋ค๋ `className` ์ ํ์ฉํด์ฃผ์๊ธฐ ๋ฐ๋๋๋ค.
- HTML์์ `id` ๋ ๋ฌธ์ ๋ด์์ ์ ์ผํด์ผ ํฉ๋๋ค. ์ด๋ฌํ ์ด์ ๋ก ๋จ์ผ ์์๋ฅผ ๋ค๋ฃจ๋ ๊ฒฝ์ฐ `id`๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- ํ์ง๋งย ์ ๋ง๋ก ํด๋น ์์์ ๋ํ ์ด๋ฒคํธ๋ ์คํ์ผ ํธ๋ค๋ง์ด ํ๋ก์ ํธ ์ ์ฒด์์ ๋จ ํ๋ฒ๋ง ์ฌ์ฉ ๋๋์งย ์ถฉ๋ถํ ๊ณ ๋ฏผํด์ผํฉ๋๋ค. ์ผ๋ฐ์ ์ผ๋ก ์ปดํฌ๋ํธ๋ ์ฌ์ฌ์ฉ ๋ ์ ์๊ธฐ ๋๋ฌธ์ ๊ฐ์ ์์๊ฐ ์ฌ๋ฌ๋ฒ ์์ฑ๋ ์ ์์ต๋๋ค. ์ด๋ฌํ ์ด์ ๋ก ๋ณดํต์ ๊ฒฝ์ฐ์๋ `className` ์ ์ฌ์ฉํฉ๋๋ค. |
@@ -0,0 +1,85 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+import InputBox from './InputBox/InputBox';
+import './JaehyunLogin.scss';
+
+class JaehyunLogin extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: '',
+ password: '',
+ };
+ }
+
+ inputChangeHandler = e => {
+ const { name, value } = e.target;
+ let userIdCheck = true;
+ if (name === 'userName') {
+ this.setState({
+ userName: value,
+ });
+ userIdCheck = value.indexOf('@') === -1;
+ }
+ if (name === 'password') {
+ let passwordCheck = true;
+ this.setState({
+ password: value,
+ });
+ passwordCheck = value.length < 5;
+ }
+ };
+
+ goToMain = e => {
+ e.preventDefault();
+ fetch('http://10.58.0.158:8000/users/signup', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.userName,
+ password: this.state.password,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+
+ this.props.history.push('./JaehyunMain');
+ };
+
+ render() {
+ return (
+ <main className="container">
+ <div className="titleText">Westagram</div>
+ <form action="summit">
+ <InputBox
+ name="userName"
+ type="email"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <InputBox
+ name="password"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ recivedValue={this.inputChangeHandler}
+ />
+ <button
+ id="loginButton"
+ onClick={this.goToMain}
+ disabled={this.userIdCheck || this.passwordCheck}
+ style={
+ this.userIdCheck || this.passwordCheck
+ ? { opacity: '10%' }
+ : { opacity: '100%' }
+ }
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ <h3 className="passwordText">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</h3>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunLogin); | JavaScript | inline-style๋ณด๋ค className์ ๋์ ์ผ๋ก ๋ฐ๊พธ๋ ์์ผ๋ก ์คํ์ผ๋ง ํด์ฃผ์ธ์ |
@@ -0,0 +1,20 @@
+import React from 'react';
+
+class Content extends React.Component {
+ constructor(props) {
+ super(props);
+ }
+
+ render() {
+ return (
+ <li key={this.props.key} style={{ listStyle: 'none' }}>
+ <span style={{ fontWeight: 'bold', marginRight: '20px' }}>
+ {this.props.userName}
+ </span>
+ <span>{this.props.content}</span>
+ </li>
+ );
+ }
+}
+
+export default Content; | JavaScript | state๋ฅผ ๋ง๋ค์ง ์์ ๊ฒฝ์ฐ constructor ์ํด์ฃผ์
๋ ๋ฉ๋๋ค! |
@@ -0,0 +1,20 @@
+import React from 'react';
+
+class Content extends React.Component {
+ constructor(props) {
+ super(props);
+ }
+
+ render() {
+ return (
+ <li key={this.props.key} style={{ listStyle: 'none' }}>
+ <span style={{ fontWeight: 'bold', marginRight: '20px' }}>
+ {this.props.userName}
+ </span>
+ <span>{this.props.content}</span>
+ </li>
+ );
+ }
+}
+
+export default Content; | JavaScript | key props์ Array.map method๋ฅผ ํ์ฉํ์ฌ ์ฌ๋ฌ ์๋ฆฌ๋จผํธ๋ฅผ ์์ฑํ ๋ ๋ถ์ฌํด์ํ๋ ๊ฒ์ธ๋ฐ ์ฌ๊ธฐ์๋ map์ ์ฌ์ฉํ๊ณ ์์ง ์์ต๋๋ค. key prop ๋ถ์ฌํ๋ ์๋ฏธ๊ฐ ์์ด๋ณด์
๋๋ค,
๊ทธ๋ฆฌ๊ณ inline-style์ ์ง์ํด์ฃผ์๊ณ className์ ํตํ ์คํ์ผ๋ง ํด์ฃผ์ธ์, ๋๋จธ์ง ๋ถ๋ถ๋ ๋ง์ฐฌ๊ฐ์ง์
๋๋ค, |
@@ -0,0 +1,26 @@
+import React from 'react';
+
+class InputForm extends React.Component {
+ constructor(props) {
+ super(props);
+ }
+
+ render() {
+ return (
+ <form onSubmit={this.addContent}>
+ <input
+ name="comment"
+ className="replyInput"
+ type="text"
+ placeholder="๋๊ธ๋ฌ๊ธฐ..."
+ onKeyUp={this.currentState}
+ />
+ <button className="postButton" type="submit">
+ ๊ฒ์
+ </button>
+ </form>
+ );
+ }
+}
+
+export default InputForm; | JavaScript | currenState๋ผ๋ ํจ์๋ ๋ณด์ด์ง ์์ต๋๋ค! undefined๊ฐ ํ ๋น๋๊ณ ์์ ๊ฒ ๊ฐ๋ค์ |
@@ -0,0 +1,26 @@
+import React from 'react';
+
+class InputForm extends React.Component {
+ constructor(props) {
+ super(props);
+ }
+
+ render() {
+ return (
+ <form onSubmit={this.addContent}>
+ <input
+ name="comment"
+ className="replyInput"
+ type="text"
+ placeholder="๋๊ธ๋ฌ๊ธฐ..."
+ onKeyUp={this.currentState}
+ />
+ <button className="postButton" type="submit">
+ ๊ฒ์
+ </button>
+ </form>
+ );
+ }
+}
+
+export default InputForm; | JavaScript | addContent๋ ๋ง์ฐฌ๊ฐ์ง๋ก ์์ด๋ณด์
๋๋ค! |
@@ -0,0 +1,183 @@
+import React from 'react';
+import { withRouter } from 'react-router';
+import './JaehyunMain.scss';
+import Nav from '../../../components/Nav/Nav';
+import Content from './Content/Content';
+
+class JaehyunMain extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: [],
+ newContent: '',
+ contents: [],
+ };
+ }
+
+ currentState = e => {
+ const newContent = e.target.value;
+ this.setState({ newContent: newContent });
+ if (e.key === 'Enter') {
+ e.target.value = '';
+ }
+ };
+
+ addContent = e => {
+ e.preventDefault();
+ const newContent = this.state.newContent;
+ if (!newContent.length) {
+ alert('๋๊ธ์ ์
๋ ฅํด์ฃผ์ธ์!!');
+ return;
+ }
+ this.setState({
+ contents: this.state.contents.concat(newContent),
+ newConetent: '',
+ });
+ e.target.reset();
+ };
+
+ render() {
+ return (
+ <main className="JaehyunMain">
+ <Nav />
+ <section className="feedWraper">
+ <article>
+ <div className="feedHeader">
+ <div className="feedProfile">
+ <img
+ className="feedProfileImage"
+ src="/images/jaehyun/hoit_logo.jpg"
+ alt="Profile"
+ />
+ <div className="userId">hoit_studio</div>
+ </div>
+ <img
+ className="moreButtonImage"
+ src="/images/jaehyun/more.png"
+ alt="more"
+ />
+ </div>
+ <img
+ className="firstFeed"
+ src="/images/jaehyun/styx.png"
+ alt="feedimage"
+ />
+ <div className="feedContent">
+ <div className="feedIcons">
+ <div className="feedLeftIcons">
+ <img
+ className="likeIcon"
+ src="/images/jaehyun/heart.png"
+ alt="like"
+ />
+ <img
+ className="dmIcon"
+ src="/images/jaehyun/speech-bubble.png"
+ alt="dm"
+ />
+ <img
+ className="shareIcon"
+ src="/images/jaehyun/send.png"
+ alt="share"
+ />
+ </div>
+ <img
+ className="bookmarkIcon"
+ src="/images/jaehyun/ribbon.png"
+ alt="bookmark"
+ />
+ </div>
+ <div className="feedDescription">
+ <p className="feedLike">์ข์์ 2๊ฐ</p>
+ <span className="userId">hoit_studio</span> Styx : isonomiฤ
+ official trailer
+ <p className="hashTag">#Styx #hoitstudio</p>
+ <ul id="reply">
+ {this.state.contents.map((content, index) => {
+ return (
+ <Content key={index} userName={index} content={content} />
+ );
+ })}
+ </ul>
+ </div>
+ </div>
+ <div className="feedReply">
+ <img
+ className="smileIcon"
+ src="/images/jaehyun/smile.png"
+ alt="smile"
+ />
+ <form onSubmit={this.addContent}>
+ <input
+ name="comment"
+ className="replyInput"
+ type="text"
+ placeholder="๋๊ธ๋ฌ๊ธฐ..."
+ onKeyUp={this.currentState}
+ />
+ <button className="postButton" type="submit">
+ ๊ฒ์
+ </button>
+ </form>
+ </div>
+ </article>
+ <aside>
+ <div className="account">
+ <div className="accountUser">
+ <img
+ className="accountUserIcon"
+ src="/images/jaehyun/hoit_logo.jpg"
+ alt="profile"
+ />
+ <div className="accountUserId">
+ hoit_studio
+ <p>hoit_studio</p>
+ </div>
+ </div>
+ <p>์ ํ</p>
+ </div>
+ <div className="story">
+ <div className="storyTop">
+ <p>์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyContent">
+ <img
+ className="otherUserIcon"
+ src="/images/jaehyun/user.png"
+ alt="profile"
+ />
+ <p className="otherUserId">hoit_studio</p>
+ </div>
+ </div>
+ <div className="recommendUser">
+ <div className="recommendUserTop">
+ <p>ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="recommendUserContent">
+ <div className="recommendUserLeftContent">
+ <img
+ className="otherUserIcon"
+ src="/images/jaehyun/user.png"
+ alt="profile "
+ />
+ <p className="otherUserId">hoit_studio</p>
+ </div>
+ <p>ํ๋ก์ฐ</p>
+ </div>
+ </div>
+ <footer>
+ ์๊ฐ ใป ๋์๋ง ใป ํ๋ณด ์ผํฐ ใป API ใป ์ฑ์ฉ ์ ๋ณด ใป
+ ๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ ใป ์ฝ๊ด ใป ์์น ใป ์ธ๊ธฐ ใป ๊ณ์ ใป ํด์ํ๊ทธ
+ ใป์ธ์ด ยฉ 2021 INSTAGRAM FROM FACEBOOK
+ </footer>
+ </aside>
+ </section>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunMain); | JavaScript | ```suggestion
this.setState({ newContent });
```
๊ฐ์ฒด ๋จ์ถ ์์ฑ๋ช
์ ์ด์ฉํ ์ ์์ต๋๋ค. |
@@ -0,0 +1,183 @@
+import React from 'react';
+import { withRouter } from 'react-router';
+import './JaehyunMain.scss';
+import Nav from '../../../components/Nav/Nav';
+import Content from './Content/Content';
+
+class JaehyunMain extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: [],
+ newContent: '',
+ contents: [],
+ };
+ }
+
+ currentState = e => {
+ const newContent = e.target.value;
+ this.setState({ newContent: newContent });
+ if (e.key === 'Enter') {
+ e.target.value = '';
+ }
+ };
+
+ addContent = e => {
+ e.preventDefault();
+ const newContent = this.state.newContent;
+ if (!newContent.length) {
+ alert('๋๊ธ์ ์
๋ ฅํด์ฃผ์ธ์!!');
+ return;
+ }
+ this.setState({
+ contents: this.state.contents.concat(newContent),
+ newConetent: '',
+ });
+ e.target.reset();
+ };
+
+ render() {
+ return (
+ <main className="JaehyunMain">
+ <Nav />
+ <section className="feedWraper">
+ <article>
+ <div className="feedHeader">
+ <div className="feedProfile">
+ <img
+ className="feedProfileImage"
+ src="/images/jaehyun/hoit_logo.jpg"
+ alt="Profile"
+ />
+ <div className="userId">hoit_studio</div>
+ </div>
+ <img
+ className="moreButtonImage"
+ src="/images/jaehyun/more.png"
+ alt="more"
+ />
+ </div>
+ <img
+ className="firstFeed"
+ src="/images/jaehyun/styx.png"
+ alt="feedimage"
+ />
+ <div className="feedContent">
+ <div className="feedIcons">
+ <div className="feedLeftIcons">
+ <img
+ className="likeIcon"
+ src="/images/jaehyun/heart.png"
+ alt="like"
+ />
+ <img
+ className="dmIcon"
+ src="/images/jaehyun/speech-bubble.png"
+ alt="dm"
+ />
+ <img
+ className="shareIcon"
+ src="/images/jaehyun/send.png"
+ alt="share"
+ />
+ </div>
+ <img
+ className="bookmarkIcon"
+ src="/images/jaehyun/ribbon.png"
+ alt="bookmark"
+ />
+ </div>
+ <div className="feedDescription">
+ <p className="feedLike">์ข์์ 2๊ฐ</p>
+ <span className="userId">hoit_studio</span> Styx : isonomiฤ
+ official trailer
+ <p className="hashTag">#Styx #hoitstudio</p>
+ <ul id="reply">
+ {this.state.contents.map((content, index) => {
+ return (
+ <Content key={index} userName={index} content={content} />
+ );
+ })}
+ </ul>
+ </div>
+ </div>
+ <div className="feedReply">
+ <img
+ className="smileIcon"
+ src="/images/jaehyun/smile.png"
+ alt="smile"
+ />
+ <form onSubmit={this.addContent}>
+ <input
+ name="comment"
+ className="replyInput"
+ type="text"
+ placeholder="๋๊ธ๋ฌ๊ธฐ..."
+ onKeyUp={this.currentState}
+ />
+ <button className="postButton" type="submit">
+ ๊ฒ์
+ </button>
+ </form>
+ </div>
+ </article>
+ <aside>
+ <div className="account">
+ <div className="accountUser">
+ <img
+ className="accountUserIcon"
+ src="/images/jaehyun/hoit_logo.jpg"
+ alt="profile"
+ />
+ <div className="accountUserId">
+ hoit_studio
+ <p>hoit_studio</p>
+ </div>
+ </div>
+ <p>์ ํ</p>
+ </div>
+ <div className="story">
+ <div className="storyTop">
+ <p>์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyContent">
+ <img
+ className="otherUserIcon"
+ src="/images/jaehyun/user.png"
+ alt="profile"
+ />
+ <p className="otherUserId">hoit_studio</p>
+ </div>
+ </div>
+ <div className="recommendUser">
+ <div className="recommendUserTop">
+ <p>ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="recommendUserContent">
+ <div className="recommendUserLeftContent">
+ <img
+ className="otherUserIcon"
+ src="/images/jaehyun/user.png"
+ alt="profile "
+ />
+ <p className="otherUserId">hoit_studio</p>
+ </div>
+ <p>ํ๋ก์ฐ</p>
+ </div>
+ </div>
+ <footer>
+ ์๊ฐ ใป ๋์๋ง ใป ํ๋ณด ์ผํฐ ใป API ใป ์ฑ์ฉ ์ ๋ณด ใป
+ ๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ ใป ์ฝ๊ด ใป ์์น ใป ์ธ๊ธฐ ใป ๊ณ์ ใป ํด์ํ๊ทธ
+ ใป์ธ์ด ยฉ 2021 INSTAGRAM FROM FACEBOOK
+ </footer>
+ </aside>
+ </section>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunMain); | JavaScript | alt ์์ฑ์ด ์ต์๋จ์ ์์นํ๋๋ก ์์ ์กฐ์ ํด์ฃผ์ธ์ |
@@ -0,0 +1,183 @@
+import React from 'react';
+import { withRouter } from 'react-router';
+import './JaehyunMain.scss';
+import Nav from '../../../components/Nav/Nav';
+import Content from './Content/Content';
+
+class JaehyunMain extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ userName: [],
+ newContent: '',
+ contents: [],
+ };
+ }
+
+ currentState = e => {
+ const newContent = e.target.value;
+ this.setState({ newContent: newContent });
+ if (e.key === 'Enter') {
+ e.target.value = '';
+ }
+ };
+
+ addContent = e => {
+ e.preventDefault();
+ const newContent = this.state.newContent;
+ if (!newContent.length) {
+ alert('๋๊ธ์ ์
๋ ฅํด์ฃผ์ธ์!!');
+ return;
+ }
+ this.setState({
+ contents: this.state.contents.concat(newContent),
+ newConetent: '',
+ });
+ e.target.reset();
+ };
+
+ render() {
+ return (
+ <main className="JaehyunMain">
+ <Nav />
+ <section className="feedWraper">
+ <article>
+ <div className="feedHeader">
+ <div className="feedProfile">
+ <img
+ className="feedProfileImage"
+ src="/images/jaehyun/hoit_logo.jpg"
+ alt="Profile"
+ />
+ <div className="userId">hoit_studio</div>
+ </div>
+ <img
+ className="moreButtonImage"
+ src="/images/jaehyun/more.png"
+ alt="more"
+ />
+ </div>
+ <img
+ className="firstFeed"
+ src="/images/jaehyun/styx.png"
+ alt="feedimage"
+ />
+ <div className="feedContent">
+ <div className="feedIcons">
+ <div className="feedLeftIcons">
+ <img
+ className="likeIcon"
+ src="/images/jaehyun/heart.png"
+ alt="like"
+ />
+ <img
+ className="dmIcon"
+ src="/images/jaehyun/speech-bubble.png"
+ alt="dm"
+ />
+ <img
+ className="shareIcon"
+ src="/images/jaehyun/send.png"
+ alt="share"
+ />
+ </div>
+ <img
+ className="bookmarkIcon"
+ src="/images/jaehyun/ribbon.png"
+ alt="bookmark"
+ />
+ </div>
+ <div className="feedDescription">
+ <p className="feedLike">์ข์์ 2๊ฐ</p>
+ <span className="userId">hoit_studio</span> Styx : isonomiฤ
+ official trailer
+ <p className="hashTag">#Styx #hoitstudio</p>
+ <ul id="reply">
+ {this.state.contents.map((content, index) => {
+ return (
+ <Content key={index} userName={index} content={content} />
+ );
+ })}
+ </ul>
+ </div>
+ </div>
+ <div className="feedReply">
+ <img
+ className="smileIcon"
+ src="/images/jaehyun/smile.png"
+ alt="smile"
+ />
+ <form onSubmit={this.addContent}>
+ <input
+ name="comment"
+ className="replyInput"
+ type="text"
+ placeholder="๋๊ธ๋ฌ๊ธฐ..."
+ onKeyUp={this.currentState}
+ />
+ <button className="postButton" type="submit">
+ ๊ฒ์
+ </button>
+ </form>
+ </div>
+ </article>
+ <aside>
+ <div className="account">
+ <div className="accountUser">
+ <img
+ className="accountUserIcon"
+ src="/images/jaehyun/hoit_logo.jpg"
+ alt="profile"
+ />
+ <div className="accountUserId">
+ hoit_studio
+ <p>hoit_studio</p>
+ </div>
+ </div>
+ <p>์ ํ</p>
+ </div>
+ <div className="story">
+ <div className="storyTop">
+ <p>์คํ ๋ฆฌ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="storyContent">
+ <img
+ className="otherUserIcon"
+ src="/images/jaehyun/user.png"
+ alt="profile"
+ />
+ <p className="otherUserId">hoit_studio</p>
+ </div>
+ </div>
+ <div className="recommendUser">
+ <div className="recommendUserTop">
+ <p>ํ์๋์ ์ํ ์ถ์ฒ</p>
+ <p>๋ชจ๋ ๋ณด๊ธฐ</p>
+ </div>
+ <div className="recommendUserContent">
+ <div className="recommendUserLeftContent">
+ <img
+ className="otherUserIcon"
+ src="/images/jaehyun/user.png"
+ alt="profile "
+ />
+ <p className="otherUserId">hoit_studio</p>
+ </div>
+ <p>ํ๋ก์ฐ</p>
+ </div>
+ </div>
+ <footer>
+ ์๊ฐ ใป ๋์๋ง ใป ํ๋ณด ์ผํฐ ใป API ใป ์ฑ์ฉ ์ ๋ณด ใป
+ ๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ ใป ์ฝ๊ด ใป ์์น ใป ์ธ๊ธฐ ใป ๊ณ์ ใป ํด์ํ๊ทธ
+ ใป์ธ์ด ยฉ 2021 INSTAGRAM FROM FACEBOOK
+ </footer>
+ </aside>
+ </section>
+ </main>
+ );
+ }
+}
+
+export default withRouter(JaehyunMain); | JavaScript | className ์ฌ์ฉํด์ฃผ์ธ์ |
@@ -0,0 +1,280 @@
+.JaehyunMain {
+ .fixedTop {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ background-color: white;
+ border-bottom: 2px solid #ebebeb;
+
+ nav {
+ display: flex;
+ justify-content: space-between;
+ padding: 15px;
+ max-width: 1100px;
+ width: 100%;
+ margin: 0 auto;
+
+ .westagramTitle {
+ margin: 0 15px;
+ font-size: 25px;
+ font-family: 'Lobster', cursive;
+ cursor: pointer;
+ }
+
+ .inputContainer {
+ position: relative;
+ }
+
+ .searchInput {
+ width: 250px;
+ height: 30px;
+
+ border: 1px solid #b2b4b7;
+ border-radius: 3px;
+ background-color: #fafafa;
+ padding-left: 25px;
+ }
+
+ .searchIcon {
+ position: absolute;
+ top: 10px;
+ left: 90px;
+ width: 10px;
+ height: 10px;
+ }
+
+ .searchText {
+ position: absolute;
+ top: 7px;
+ left: 100px;
+ width: 30px;
+ font-size: 14px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon {
+ width: 25px;
+ height: 25px;
+ margin: 0 15px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon:hover {
+ cursor: pointer;
+ }
+ }
+ }
+
+ .feedWraper {
+ display: flex;
+ padding-top: 100px;
+ max-width: 1100px;
+ margin: 0 auto;
+
+ article {
+ background-color: white;
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-right: 30px;
+ width: 700px;
+ text-align: center;
+
+ .feedHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ height: 60px;
+ padding: 15px 15px;
+ border-bottom: 1px solid lightgray;
+
+ .feedProfile {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
+ .feedProfileImage {
+ width: 35px;
+ height: 35px;
+ border-radius: 70%;
+ }
+
+ .userId {
+ margin-left: 10px;
+ font-weight: bold;
+ }
+ }
+
+ .moreButtonImage {
+ width: 13px;
+ height: 13px;
+ cursor: pointer;
+ }
+
+ .firstFeed {
+ width: 300px;
+ height: 500px;
+ }
+
+ .feedIcons {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 0 10px;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon,
+ .bookmarkIcon {
+ width: 25px;
+ height: 25px;
+ cursor: pointer;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon {
+ margin-left: 15px;
+ }
+
+ .feedDescription {
+ margin-left: 20px;
+ text-align: left;
+ }
+
+ .feedReply {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ border-top: 1px solid lightgray;
+ padding: 10px;
+ margin-top: 20px;
+
+ .replyContent {
+ margin-right: 100px;
+ }
+
+ .smileIcon {
+ width: 25px;
+ height: 25px;
+ }
+
+ .replyInput {
+ width: 570px;
+ height: 30px;
+ border: 0;
+ }
+ .postButton {
+ color: #0996f6;
+ border: 0;
+ margin-left: 5px;
+ cursor: pointer;
+ background-color: white;
+ }
+ }
+ .name {
+ font-weight: bold;
+ }
+
+ .delete {
+ float: right;
+ margin-right: 20px;
+ cursor: pointer;
+ }
+ }
+ }
+
+ aside {
+ width: calc(100% - 700px);
+
+ .account {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .accountUser {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .accountUserIcon {
+ width: 50px;
+ height: 50px;
+ margin-right: 20px;
+
+ border-radius: 70%;
+ }
+ }
+
+ .story {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 20px;
+ }
+
+ .storyTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .storyContent {
+ display: flex;
+ justify-content: left;
+ align-items: center;
+ padding: 10px;
+ }
+ .otherUserId {
+ margin-left: 10px;
+ font-size: 15px;
+ }
+ .otherUserIcon {
+ width: 30px;
+ height: 30px;
+ border-radius: 70%;
+ }
+
+ .recommendUser {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 10px;
+ }
+
+ .recommendUserTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .recommendUserContent {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 10px;
+ }
+ .recommendUserLeftContent {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ footer {
+ color: #dfdfdf;
+ font-size: 12px;
+ text-align: left;
+ margin-top: 20px;
+ }
+ }
+} | Unknown | ์ต์์ ๋ค์คํ
ํ๋ ์์์ ํด๋์ค๋ค์์ ์ปดํฌ๋ํธ ๋ช
๊ณผ ๋์ผํ๊ฒ ๋ถ์ฌํด์ฃผ์๊ณ , ํด๋์ค ๋ค์์ ์ด์ฉํด์ ์ต์์ ๋ค์คํ
์ ํด์ฃผ์๋๊ฒ ๋ค๋ฅธ ์ปดํฌ๋ํธ์ css ์ถฉ๋์ด ๋ฐ์ํ ํ๋ฅ ์ ๋ฎ์ถ ์ ์์ต๋๋ค. |
@@ -0,0 +1,280 @@
+.JaehyunMain {
+ .fixedTop {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ background-color: white;
+ border-bottom: 2px solid #ebebeb;
+
+ nav {
+ display: flex;
+ justify-content: space-between;
+ padding: 15px;
+ max-width: 1100px;
+ width: 100%;
+ margin: 0 auto;
+
+ .westagramTitle {
+ margin: 0 15px;
+ font-size: 25px;
+ font-family: 'Lobster', cursive;
+ cursor: pointer;
+ }
+
+ .inputContainer {
+ position: relative;
+ }
+
+ .searchInput {
+ width: 250px;
+ height: 30px;
+
+ border: 1px solid #b2b4b7;
+ border-radius: 3px;
+ background-color: #fafafa;
+ padding-left: 25px;
+ }
+
+ .searchIcon {
+ position: absolute;
+ top: 10px;
+ left: 90px;
+ width: 10px;
+ height: 10px;
+ }
+
+ .searchText {
+ position: absolute;
+ top: 7px;
+ left: 100px;
+ width: 30px;
+ font-size: 14px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon {
+ width: 25px;
+ height: 25px;
+ margin: 0 15px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon:hover {
+ cursor: pointer;
+ }
+ }
+ }
+
+ .feedWraper {
+ display: flex;
+ padding-top: 100px;
+ max-width: 1100px;
+ margin: 0 auto;
+
+ article {
+ background-color: white;
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-right: 30px;
+ width: 700px;
+ text-align: center;
+
+ .feedHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ height: 60px;
+ padding: 15px 15px;
+ border-bottom: 1px solid lightgray;
+
+ .feedProfile {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
+ .feedProfileImage {
+ width: 35px;
+ height: 35px;
+ border-radius: 70%;
+ }
+
+ .userId {
+ margin-left: 10px;
+ font-weight: bold;
+ }
+ }
+
+ .moreButtonImage {
+ width: 13px;
+ height: 13px;
+ cursor: pointer;
+ }
+
+ .firstFeed {
+ width: 300px;
+ height: 500px;
+ }
+
+ .feedIcons {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 0 10px;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon,
+ .bookmarkIcon {
+ width: 25px;
+ height: 25px;
+ cursor: pointer;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon {
+ margin-left: 15px;
+ }
+
+ .feedDescription {
+ margin-left: 20px;
+ text-align: left;
+ }
+
+ .feedReply {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ border-top: 1px solid lightgray;
+ padding: 10px;
+ margin-top: 20px;
+
+ .replyContent {
+ margin-right: 100px;
+ }
+
+ .smileIcon {
+ width: 25px;
+ height: 25px;
+ }
+
+ .replyInput {
+ width: 570px;
+ height: 30px;
+ border: 0;
+ }
+ .postButton {
+ color: #0996f6;
+ border: 0;
+ margin-left: 5px;
+ cursor: pointer;
+ background-color: white;
+ }
+ }
+ .name {
+ font-weight: bold;
+ }
+
+ .delete {
+ float: right;
+ margin-right: 20px;
+ cursor: pointer;
+ }
+ }
+ }
+
+ aside {
+ width: calc(100% - 700px);
+
+ .account {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .accountUser {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .accountUserIcon {
+ width: 50px;
+ height: 50px;
+ margin-right: 20px;
+
+ border-radius: 70%;
+ }
+ }
+
+ .story {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 20px;
+ }
+
+ .storyTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .storyContent {
+ display: flex;
+ justify-content: left;
+ align-items: center;
+ padding: 10px;
+ }
+ .otherUserId {
+ margin-left: 10px;
+ font-size: 15px;
+ }
+ .otherUserIcon {
+ width: 30px;
+ height: 30px;
+ border-radius: 70%;
+ }
+
+ .recommendUser {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 10px;
+ }
+
+ .recommendUserTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .recommendUserContent {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 10px;
+ }
+ .recommendUserLeftContent {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ footer {
+ color: #dfdfdf;
+ font-size: 12px;
+ text-align: left;
+ margin-top: 20px;
+ }
+ }
+} | Unknown | section์ ์ด๋ฏธ display:block์ ์์ฑ์ด๊ธฐ๋๋ฌธ์, width:100%๋ฅผ ๋ถ์ฌํ ํ์๊ฐ ์์ต๋๋ค. |
@@ -0,0 +1,280 @@
+.JaehyunMain {
+ .fixedTop {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ background-color: white;
+ border-bottom: 2px solid #ebebeb;
+
+ nav {
+ display: flex;
+ justify-content: space-between;
+ padding: 15px;
+ max-width: 1100px;
+ width: 100%;
+ margin: 0 auto;
+
+ .westagramTitle {
+ margin: 0 15px;
+ font-size: 25px;
+ font-family: 'Lobster', cursive;
+ cursor: pointer;
+ }
+
+ .inputContainer {
+ position: relative;
+ }
+
+ .searchInput {
+ width: 250px;
+ height: 30px;
+
+ border: 1px solid #b2b4b7;
+ border-radius: 3px;
+ background-color: #fafafa;
+ padding-left: 25px;
+ }
+
+ .searchIcon {
+ position: absolute;
+ top: 10px;
+ left: 90px;
+ width: 10px;
+ height: 10px;
+ }
+
+ .searchText {
+ position: absolute;
+ top: 7px;
+ left: 100px;
+ width: 30px;
+ font-size: 14px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon {
+ width: 25px;
+ height: 25px;
+ margin: 0 15px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon:hover {
+ cursor: pointer;
+ }
+ }
+ }
+
+ .feedWraper {
+ display: flex;
+ padding-top: 100px;
+ max-width: 1100px;
+ margin: 0 auto;
+
+ article {
+ background-color: white;
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-right: 30px;
+ width: 700px;
+ text-align: center;
+
+ .feedHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ height: 60px;
+ padding: 15px 15px;
+ border-bottom: 1px solid lightgray;
+
+ .feedProfile {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
+ .feedProfileImage {
+ width: 35px;
+ height: 35px;
+ border-radius: 70%;
+ }
+
+ .userId {
+ margin-left: 10px;
+ font-weight: bold;
+ }
+ }
+
+ .moreButtonImage {
+ width: 13px;
+ height: 13px;
+ cursor: pointer;
+ }
+
+ .firstFeed {
+ width: 300px;
+ height: 500px;
+ }
+
+ .feedIcons {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 0 10px;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon,
+ .bookmarkIcon {
+ width: 25px;
+ height: 25px;
+ cursor: pointer;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon {
+ margin-left: 15px;
+ }
+
+ .feedDescription {
+ margin-left: 20px;
+ text-align: left;
+ }
+
+ .feedReply {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ border-top: 1px solid lightgray;
+ padding: 10px;
+ margin-top: 20px;
+
+ .replyContent {
+ margin-right: 100px;
+ }
+
+ .smileIcon {
+ width: 25px;
+ height: 25px;
+ }
+
+ .replyInput {
+ width: 570px;
+ height: 30px;
+ border: 0;
+ }
+ .postButton {
+ color: #0996f6;
+ border: 0;
+ margin-left: 5px;
+ cursor: pointer;
+ background-color: white;
+ }
+ }
+ .name {
+ font-weight: bold;
+ }
+
+ .delete {
+ float: right;
+ margin-right: 20px;
+ cursor: pointer;
+ }
+ }
+ }
+
+ aside {
+ width: calc(100% - 700px);
+
+ .account {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .accountUser {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .accountUserIcon {
+ width: 50px;
+ height: 50px;
+ margin-right: 20px;
+
+ border-radius: 70%;
+ }
+ }
+
+ .story {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 20px;
+ }
+
+ .storyTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .storyContent {
+ display: flex;
+ justify-content: left;
+ align-items: center;
+ padding: 10px;
+ }
+ .otherUserId {
+ margin-left: 10px;
+ font-size: 15px;
+ }
+ .otherUserIcon {
+ width: 30px;
+ height: 30px;
+ border-radius: 70%;
+ }
+
+ .recommendUser {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 10px;
+ }
+
+ .recommendUserTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .recommendUserContent {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 10px;
+ }
+ .recommendUserLeftContent {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ footer {
+ color: #dfdfdf;
+ font-size: 12px;
+ text-align: left;
+ margin-top: 20px;
+ }
+ }
+} | Unknown | ๊ฐ๋ฅํ ํ๊ทธ ์
๋ ํฐ๋ณด๋ค ํด๋์ค๋ค์์ ๋ถ์ฌํด์ ์ ํํด์ฃผ์ธ์! ํ๊ทธ์
๋ ํฐ๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ค๋ฅธ ์์๋ค์ ์ํฅ์ ๋ฏธ์น ์ฌ์ง๊ฐ ์์ต๋๋ค! |
@@ -0,0 +1,280 @@
+.JaehyunMain {
+ .fixedTop {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ background-color: white;
+ border-bottom: 2px solid #ebebeb;
+
+ nav {
+ display: flex;
+ justify-content: space-between;
+ padding: 15px;
+ max-width: 1100px;
+ width: 100%;
+ margin: 0 auto;
+
+ .westagramTitle {
+ margin: 0 15px;
+ font-size: 25px;
+ font-family: 'Lobster', cursive;
+ cursor: pointer;
+ }
+
+ .inputContainer {
+ position: relative;
+ }
+
+ .searchInput {
+ width: 250px;
+ height: 30px;
+
+ border: 1px solid #b2b4b7;
+ border-radius: 3px;
+ background-color: #fafafa;
+ padding-left: 25px;
+ }
+
+ .searchIcon {
+ position: absolute;
+ top: 10px;
+ left: 90px;
+ width: 10px;
+ height: 10px;
+ }
+
+ .searchText {
+ position: absolute;
+ top: 7px;
+ left: 100px;
+ width: 30px;
+ font-size: 14px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon {
+ width: 25px;
+ height: 25px;
+ margin: 0 15px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon:hover {
+ cursor: pointer;
+ }
+ }
+ }
+
+ .feedWraper {
+ display: flex;
+ padding-top: 100px;
+ max-width: 1100px;
+ margin: 0 auto;
+
+ article {
+ background-color: white;
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-right: 30px;
+ width: 700px;
+ text-align: center;
+
+ .feedHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ height: 60px;
+ padding: 15px 15px;
+ border-bottom: 1px solid lightgray;
+
+ .feedProfile {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
+ .feedProfileImage {
+ width: 35px;
+ height: 35px;
+ border-radius: 70%;
+ }
+
+ .userId {
+ margin-left: 10px;
+ font-weight: bold;
+ }
+ }
+
+ .moreButtonImage {
+ width: 13px;
+ height: 13px;
+ cursor: pointer;
+ }
+
+ .firstFeed {
+ width: 300px;
+ height: 500px;
+ }
+
+ .feedIcons {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 0 10px;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon,
+ .bookmarkIcon {
+ width: 25px;
+ height: 25px;
+ cursor: pointer;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon {
+ margin-left: 15px;
+ }
+
+ .feedDescription {
+ margin-left: 20px;
+ text-align: left;
+ }
+
+ .feedReply {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ border-top: 1px solid lightgray;
+ padding: 10px;
+ margin-top: 20px;
+
+ .replyContent {
+ margin-right: 100px;
+ }
+
+ .smileIcon {
+ width: 25px;
+ height: 25px;
+ }
+
+ .replyInput {
+ width: 570px;
+ height: 30px;
+ border: 0;
+ }
+ .postButton {
+ color: #0996f6;
+ border: 0;
+ margin-left: 5px;
+ cursor: pointer;
+ background-color: white;
+ }
+ }
+ .name {
+ font-weight: bold;
+ }
+
+ .delete {
+ float: right;
+ margin-right: 20px;
+ cursor: pointer;
+ }
+ }
+ }
+
+ aside {
+ width: calc(100% - 700px);
+
+ .account {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .accountUser {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .accountUserIcon {
+ width: 50px;
+ height: 50px;
+ margin-right: 20px;
+
+ border-radius: 70%;
+ }
+ }
+
+ .story {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 20px;
+ }
+
+ .storyTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .storyContent {
+ display: flex;
+ justify-content: left;
+ align-items: center;
+ padding: 10px;
+ }
+ .otherUserId {
+ margin-left: 10px;
+ font-size: 15px;
+ }
+ .otherUserIcon {
+ width: 30px;
+ height: 30px;
+ border-radius: 70%;
+ }
+
+ .recommendUser {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 10px;
+ }
+
+ .recommendUserTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .recommendUserContent {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 10px;
+ }
+ .recommendUserLeftContent {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ footer {
+ color: #dfdfdf;
+ font-size: 12px;
+ text-align: left;
+ margin-top: 20px;
+ }
+ }
+} | Unknown | ์ด๋ ๊ฒ ์์ฃผ ์ฌ์ฉํ๋ ์์ฑ๋ค์ mixin์ผ๋ก ๋ง๋ค์ด์ ์ฌ์ฉํด๋ ์ข๊ฒ ๋ค์ |
@@ -0,0 +1,280 @@
+.JaehyunMain {
+ .fixedTop {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ background-color: white;
+ border-bottom: 2px solid #ebebeb;
+
+ nav {
+ display: flex;
+ justify-content: space-between;
+ padding: 15px;
+ max-width: 1100px;
+ width: 100%;
+ margin: 0 auto;
+
+ .westagramTitle {
+ margin: 0 15px;
+ font-size: 25px;
+ font-family: 'Lobster', cursive;
+ cursor: pointer;
+ }
+
+ .inputContainer {
+ position: relative;
+ }
+
+ .searchInput {
+ width: 250px;
+ height: 30px;
+
+ border: 1px solid #b2b4b7;
+ border-radius: 3px;
+ background-color: #fafafa;
+ padding-left: 25px;
+ }
+
+ .searchIcon {
+ position: absolute;
+ top: 10px;
+ left: 90px;
+ width: 10px;
+ height: 10px;
+ }
+
+ .searchText {
+ position: absolute;
+ top: 7px;
+ left: 100px;
+ width: 30px;
+ font-size: 14px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon {
+ width: 25px;
+ height: 25px;
+ margin: 0 15px;
+ }
+
+ .homeIcon,
+ .sendIcon,
+ .exploreIcon,
+ .heartIcon,
+ .profileIcon:hover {
+ cursor: pointer;
+ }
+ }
+ }
+
+ .feedWraper {
+ display: flex;
+ padding-top: 100px;
+ max-width: 1100px;
+ margin: 0 auto;
+
+ article {
+ background-color: white;
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-right: 30px;
+ width: 700px;
+ text-align: center;
+
+ .feedHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ height: 60px;
+ padding: 15px 15px;
+ border-bottom: 1px solid lightgray;
+
+ .feedProfile {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
+ .feedProfileImage {
+ width: 35px;
+ height: 35px;
+ border-radius: 70%;
+ }
+
+ .userId {
+ margin-left: 10px;
+ font-weight: bold;
+ }
+ }
+
+ .moreButtonImage {
+ width: 13px;
+ height: 13px;
+ cursor: pointer;
+ }
+
+ .firstFeed {
+ width: 300px;
+ height: 500px;
+ }
+
+ .feedIcons {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 0 10px;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon,
+ .bookmarkIcon {
+ width: 25px;
+ height: 25px;
+ cursor: pointer;
+ }
+
+ .likeIcon,
+ .dmIcon,
+ .shareIcon {
+ margin-left: 15px;
+ }
+
+ .feedDescription {
+ margin-left: 20px;
+ text-align: left;
+ }
+
+ .feedReply {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ border-top: 1px solid lightgray;
+ padding: 10px;
+ margin-top: 20px;
+
+ .replyContent {
+ margin-right: 100px;
+ }
+
+ .smileIcon {
+ width: 25px;
+ height: 25px;
+ }
+
+ .replyInput {
+ width: 570px;
+ height: 30px;
+ border: 0;
+ }
+ .postButton {
+ color: #0996f6;
+ border: 0;
+ margin-left: 5px;
+ cursor: pointer;
+ background-color: white;
+ }
+ }
+ .name {
+ font-weight: bold;
+ }
+
+ .delete {
+ float: right;
+ margin-right: 20px;
+ cursor: pointer;
+ }
+ }
+ }
+
+ aside {
+ width: calc(100% - 700px);
+
+ .account {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .accountUser {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .accountUserIcon {
+ width: 50px;
+ height: 50px;
+ margin-right: 20px;
+
+ border-radius: 70%;
+ }
+ }
+
+ .story {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 20px;
+ }
+
+ .storyTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .storyContent {
+ display: flex;
+ justify-content: left;
+ align-items: center;
+ padding: 10px;
+ }
+ .otherUserId {
+ margin-left: 10px;
+ font-size: 15px;
+ }
+ .otherUserIcon {
+ width: 30px;
+ height: 30px;
+ border-radius: 70%;
+ }
+
+ .recommendUser {
+ border: 2px solid #e9e9e9;
+ border-radius: 3px;
+ margin-top: 10px;
+ }
+
+ .recommendUserTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px;
+ }
+
+ .recommendUserContent {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 10px;
+ }
+ .recommendUserLeftContent {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ footer {
+ color: #dfdfdf;
+ font-size: 12px;
+ text-align: left;
+ margin-top: 20px;
+ }
+ }
+} | Unknown | ์ฐ์ฑ๋ ๋ฆฌ๋ทฐ ๋๋ฌด ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,9 @@
+# ํ์ด 1 - Counter ์ด์ฉ
+from collections import Counter
+
+def solution(participant, completion):
+ # Counter๋ฅผ ์ด์ฉํ๋ฉด ๋ฆฌ์คํธ ๋ด์ ์ฑ๋ถ์ ์ซ์๋ฅผ ๋์
๋๋ฆฌ ํํ๋ก ๋ฐํํด์ค๋ค
+ # ex) list1 =['a', 'b', 'c', 'a'] => Counter(list1) : {'a':2, 'b':1, 'c':1}
+ not_completion = Counter(participant) - Counter(completion) # Counter์ ๊ฒฝ์ฐ ์ฌ์น์ฐ์ฐ๋ ๊ฐ๋ฅ
+
+ return list(not_completion.keys())[0] | Python | `Counter`๋ฅผ ์ด์ฉํ๋ ๋ฐฉ๋ฒ์ด ๊ต์ฅํ ์ ์ฉํ๊ตฐ์ ! ๐ฏ |
@@ -0,0 +1,21 @@
+package lotto.constants;
+
+public enum ErrorMessage {
+ DUPLICATION("[ERROR] ๊ฐ์ด ์ค๋ณต๋์์ต๋๋ค"),
+ ISNOTINTEGER("[ERROR] ์ซ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ SIXNUMBER("[ERROR] ๋ฒํธ 6๊ฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ OUTFRANGE("[ERROR] ๋ก๋ ๋ฒํธ๋ 1๋ถํฐ 45 ์ฌ์ด์ ์ซ์์ฌ์ผ ํฉ๋๋ค."),
+ ONENUMBER("[ERROR] ์ซ์ ๋ฒํธ 1๊ฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ NOTTHOUSAND("[ERROR] 1000์ ๋จ์๋ก ์
๋ ฅํด ์ฃผ์ธ์");
+
+
+ private final String message;
+
+ ErrorMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | ์ค๋ณต๋๋ ๋ถ๋ถ์ ๋ํด์ ์์์ฒ๋ฆฌ ํด์ค๋ ์ข์๊ฑฐ๊ฐ์์ |
@@ -0,0 +1,50 @@
+package lotto.controller;
+
+import lotto.model.Lotto;
+import lotto.model.LottoNumberMaker;
+import lotto.model.LottoPercentageCalculation;
+import lotto.model.constants.LottoPrize;
+import lotto.view.LottoInput;
+import lotto.view.LottoOutput;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static lotto.model.constants.LottoPrize.*;
+
+public class LottoController {
+ private static final LottoNumberMaker lottoNumberMaker = new LottoNumberMaker();
+ private static final LottoInput lottoInput = new LottoInput();
+ private static final LottoOutput lottoOutput = new LottoOutput();
+ private static final LottoPercentageCalculation lottoPercentageCalculation = new LottoPercentageCalculation();
+ public static void setPrice() {
+ lottoNumberMaker.checkInt();
+ }
+
+// static List<LottoPrize> LottoPrizelist= asList(FIFTH_PRIZE,FOURTH_PRIZE,THIRD_PRIZE,SECOND_PRIZE,FIRST_PRIZE);
+ public static void setBuyLottoNumberPrint() {
+ lottoOutput.buyLottoNumberPrint(lottoNumberMaker.getLottoNumber());
+ }
+
+ public static void setPrizeNumberInput() {
+ Lotto lotto = new Lotto(lottoInput.prizeNumberInput());
+ lotto.checkSame(lottoInput.bonusNumberInput(),lottoNumberMaker.getLottoNumber());
+ }
+
+ public static void winningStatistic() {
+ List<String> lottoPrizes = new ArrayList<>();
+ for(LottoPrize lottoPrize: LottoPrize.values()){
+ lottoPrizes.add(lottoPrize.getText()+lottoPrize.getWinCount()+lottoPrize.getUnit());
+ }
+ LottoOutput.seeWinningStatstic(lottoPrizes);
+ }
+
+ public static void PerformanceCalculation() {
+ lottoOutput.seePercentage(lottoPercentageCalculation.percentageCalculation(LottoPrize.values(),lottoNumberMaker.getBuyPrice()));
+ }
+
+ public String askPrice() {
+ return lottoInput.askPrice();
+ }
+}
\ No newline at end of file | Java | ์ปจํธ๋กค๋ฌ ์์ ๋๋ถ๋ถ์ ๋ฉ์๋์ ๋ณ์๋ฅผ static ์ฒ๋ฆฌํ ๋ณ๋์ ์ด์ ๊ฐ ์๋์? |
@@ -0,0 +1,79 @@
+package lotto.model;
+
+import lotto.model.constants.LottoPrize;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+import static lotto.constants.ErrorMessage.DUPLICATION;
+import static lotto.constants.ErrorMessage.SIXNUMBER;
+import static lotto.model.constants.LottoPrize.*;
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validate(numbers);
+ duplicate(numbers);
+ this.numbers = numbers;
+ }
+
+ private void duplicate(List<Integer> numbers) {
+ List<Integer> duplication = numbers.stream()
+ .distinct()
+ .toList();
+ if (duplication.size() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+ }
+
+ private void validate(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(SIXNUMBER.getMessage());
+ }
+ }
+ public void checkSame(Integer bonusNumber, List<List<Integer>> lottoNumber) {
+ bonusDuplication(bonusNumber);
+ for (List<Integer> integers : lottoNumber) {
+ List<Integer> Result = integers.stream()
+ .filter(i -> this.numbers.stream().anyMatch(Predicate.isEqual(i)))
+ .toList();
+ long bonusResult = integers.stream()
+ .filter(bonusNumber::equals).count();
+ CheckPrize(Result.size(), bonusResult).addWinCount();
+
+ }
+ }
+
+ private void bonusDuplication(Integer bonusNumber) {
+ List<Integer> Result = this.numbers.stream()
+ .filter(i-> !Objects.equals(i, bonusNumber))
+ .toList();
+ if(Result.size()!=6){
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+
+ }
+
+ public LottoPrize CheckPrize(int result, long bonusResult){
+ if(result==6){
+ return FIRST_PRIZE;
+ }
+ if(result==5&&bonusResult==1){
+ return SECOND_PRIZE;
+ }
+ if(result==5&&bonusResult==0){
+ return THIRD_PRIZE;
+ }
+ if(result==4){
+ return FOURTH_PRIZE;
+ }
+ if(result==3){
+ return FIFTH_PRIZE;
+ }
+ if(result<3){
+ return LOOSE;
+ }
+ throw new IllegalArgumentException("์กด์ฌ ํ์ง ์๋ ์์์
๋๋ค.");
+ }
+} | Java | bonus์ ๊ฒฝ์ฐ longํ์ ์ฌ์ฉํ ์ด์ ๊ฐ ์๋์?
๊ทธ๋ฆฌ๊ณ ํด๋น ๋ฉ์๋๊ฐ lotto ๋๋ฉ์ธ์์ ๊ผญ ์ ์ธ๋์ผ ํ๋ ์ด์ ๊ฐ ์๋์ง ๊ถ๊ธํฉ๋๋ค !!(lotto๊ฐ์ฒด๊ฐ ๊ฐ์ง๋ ๋ณ์๋ฅผ ์ฌ์ฉํ์ง ์์๊ฑฐ ๊ฐ์์์ !!) |
@@ -0,0 +1,67 @@
+package lotto.model;
+
+import camp.nextstep.edu.missionutils.Randoms;
+import lotto.controller.LottoController;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static lotto.constants.ErrorMessage.ISNOTINTEGER;
+import static lotto.constants.ErrorMessage.NOTTHOUSAND;
+
+public class LottoNumberMaker {
+ private static int buyPrice;
+ private static final List<List<Integer>> numbers = new ArrayList<>();
+ private static final LottoController lottoController = new LottoController();
+
+ public static int getBuyPrice() {
+ return buyPrice;
+ }
+
+ public void makeLottoNumber(Integer count) {
+ buyPrice = count;
+ checkThousand(count);
+ IntStream.range(0, count / 1000)
+ .forEach(i -> numbers.add(makeRandomNumber()));
+ }
+
+ private void checkThousand(Integer count) {
+ if(count%1000!=0){
+ throw new IllegalArgumentException(NOTTHOUSAND.getMessage());
+ }
+ return;
+ }
+
+ private List<Integer> makeRandomNumber() {
+ return Randoms.pickUniqueNumbersInRange(1, 45, 6).stream()
+ .sorted()
+ .collect(Collectors.toList());
+ }
+
+ public void checkInt() {
+ while (true) {
+ try {
+ int number = checkCount();
+ makeLottoNumber(number);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(ISNOTINTEGER.getMessage());
+ System.out.println(NOTTHOUSAND.getMessage());
+ }
+ }
+ }
+
+ private int checkCount() {
+ try {
+ return Integer.parseInt(lottoController.askPrice());
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(ISNOTINTEGER.getMessage());
+ }
+ }
+
+ public List<List<Integer>> getLottoNumber() {
+ return numbers;
+ }
+} | Java | Lotto๊ฐ List'<'Integer'>'ํ์ ๊ฐ์ง๋๋ฐ List'<'Lotto'>'๋ก ๋ง๋ค์๋ค๋ฉด ์ด๋จ๊น์ ?! |
@@ -0,0 +1,67 @@
+package lotto.model;
+
+import camp.nextstep.edu.missionutils.Randoms;
+import lotto.controller.LottoController;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static lotto.constants.ErrorMessage.ISNOTINTEGER;
+import static lotto.constants.ErrorMessage.NOTTHOUSAND;
+
+public class LottoNumberMaker {
+ private static int buyPrice;
+ private static final List<List<Integer>> numbers = new ArrayList<>();
+ private static final LottoController lottoController = new LottoController();
+
+ public static int getBuyPrice() {
+ return buyPrice;
+ }
+
+ public void makeLottoNumber(Integer count) {
+ buyPrice = count;
+ checkThousand(count);
+ IntStream.range(0, count / 1000)
+ .forEach(i -> numbers.add(makeRandomNumber()));
+ }
+
+ private void checkThousand(Integer count) {
+ if(count%1000!=0){
+ throw new IllegalArgumentException(NOTTHOUSAND.getMessage());
+ }
+ return;
+ }
+
+ private List<Integer> makeRandomNumber() {
+ return Randoms.pickUniqueNumbersInRange(1, 45, 6).stream()
+ .sorted()
+ .collect(Collectors.toList());
+ }
+
+ public void checkInt() {
+ while (true) {
+ try {
+ int number = checkCount();
+ makeLottoNumber(number);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(ISNOTINTEGER.getMessage());
+ System.out.println(NOTTHOUSAND.getMessage());
+ }
+ }
+ }
+
+ private int checkCount() {
+ try {
+ return Integer.parseInt(lottoController.askPrice());
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(ISNOTINTEGER.getMessage());
+ }
+ }
+
+ public List<List<Integer>> getLottoNumber() {
+ return numbers;
+ }
+} | Java | ๋๋ฉ์ธ์์ ์ปจํธ๋กค๋ฌ๋ฅผ ์ฌ์ฉํ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค |
@@ -0,0 +1,67 @@
+package lotto.model;
+
+import camp.nextstep.edu.missionutils.Randoms;
+import lotto.controller.LottoController;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static lotto.constants.ErrorMessage.ISNOTINTEGER;
+import static lotto.constants.ErrorMessage.NOTTHOUSAND;
+
+public class LottoNumberMaker {
+ private static int buyPrice;
+ private static final List<List<Integer>> numbers = new ArrayList<>();
+ private static final LottoController lottoController = new LottoController();
+
+ public static int getBuyPrice() {
+ return buyPrice;
+ }
+
+ public void makeLottoNumber(Integer count) {
+ buyPrice = count;
+ checkThousand(count);
+ IntStream.range(0, count / 1000)
+ .forEach(i -> numbers.add(makeRandomNumber()));
+ }
+
+ private void checkThousand(Integer count) {
+ if(count%1000!=0){
+ throw new IllegalArgumentException(NOTTHOUSAND.getMessage());
+ }
+ return;
+ }
+
+ private List<Integer> makeRandomNumber() {
+ return Randoms.pickUniqueNumbersInRange(1, 45, 6).stream()
+ .sorted()
+ .collect(Collectors.toList());
+ }
+
+ public void checkInt() {
+ while (true) {
+ try {
+ int number = checkCount();
+ makeLottoNumber(number);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(ISNOTINTEGER.getMessage());
+ System.out.println(NOTTHOUSAND.getMessage());
+ }
+ }
+ }
+
+ private int checkCount() {
+ try {
+ return Integer.parseInt(lottoController.askPrice());
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(ISNOTINTEGER.getMessage());
+ }
+ }
+
+ public List<List<Integer>> getLottoNumber() {
+ return numbers;
+ }
+} | Java | ๋ก๋ ๊ตฌ์
๊ธ์ก๋ํ 1000์ผ๋ก ๊ณ ์ ์ํค๋ ๊ฒ ๋ณด๋ค ํ์ฅ์ฑ ์ธก๋ฉด์์ ๊ณ ๋ คํ์ฌ ์์ ์ฒ๋ฆฌํด์ ์ฌ์ฉํด๋ ์ข์๊ฑฐ๊ฐ์์ |
@@ -1,5 +1,7 @@
package lotto;
+import lotto.model.Lotto;
+import lotto.model.LottoNumberMaker;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -22,6 +24,11 @@ void createLottoByDuplicatedNumber() {
assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 5)))
.isInstanceOf(IllegalArgumentException.class);
}
+ @DisplayName("๋ก๋ ๋ฒํธ๊ฐ 6๊ฐ ๋ฏธ๋ง์ด๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void createLottoByMinSize() {
+ assertThatThrownBy(() -> new Lotto(List.of(1)))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
- // ์๋์ ์ถ๊ฐ ํ
์คํธ ์์ฑ ๊ฐ๋ฅ
}
\ No newline at end of file | Java | ๋จ์ ํ
์คํธ๋ ๋๋ฉ์ธ ๋ณ๋ก ๋ค์ํ๊ฒ ์งํํด๋ณด๋ฉด ๋ ์ข์๊ฑฐ ๊ฐ์์ :) |
@@ -1,7 +1,13 @@
package lotto;
+import lotto.controller.LottoController;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ LottoController.setPrice();
+ LottoController.setBuyLottoNumberPrint();
+ LottoController.setPrizeNumberInput();
+ LottoController.winningStatistic();
+ LottoController.PerformanceCalculation();
}
} | Java | ์์๋๋ก ๋ชจ๋ ์คํํด์ผํ๋ค๋ฉด controller์์์ ํ๋์ ๋ฉ์๋๋ก ์คํํ๋ฉด ์กฐ๊ธ ๋ ์ฝ๋๊ฐ ๊น๋ํด์ง ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,79 @@
+package lotto.model;
+
+import lotto.model.constants.LottoPrize;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+import static lotto.constants.ErrorMessage.DUPLICATION;
+import static lotto.constants.ErrorMessage.SIXNUMBER;
+import static lotto.model.constants.LottoPrize.*;
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validate(numbers);
+ duplicate(numbers);
+ this.numbers = numbers;
+ }
+
+ private void duplicate(List<Integer> numbers) {
+ List<Integer> duplication = numbers.stream()
+ .distinct()
+ .toList();
+ if (duplication.size() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+ }
+
+ private void validate(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(SIXNUMBER.getMessage());
+ }
+ }
+ public void checkSame(Integer bonusNumber, List<List<Integer>> lottoNumber) {
+ bonusDuplication(bonusNumber);
+ for (List<Integer> integers : lottoNumber) {
+ List<Integer> Result = integers.stream()
+ .filter(i -> this.numbers.stream().anyMatch(Predicate.isEqual(i)))
+ .toList();
+ long bonusResult = integers.stream()
+ .filter(bonusNumber::equals).count();
+ CheckPrize(Result.size(), bonusResult).addWinCount();
+
+ }
+ }
+
+ private void bonusDuplication(Integer bonusNumber) {
+ List<Integer> Result = this.numbers.stream()
+ .filter(i-> !Objects.equals(i, bonusNumber))
+ .toList();
+ if(Result.size()!=6){
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+
+ }
+
+ public LottoPrize CheckPrize(int result, long bonusResult){
+ if(result==6){
+ return FIRST_PRIZE;
+ }
+ if(result==5&&bonusResult==1){
+ return SECOND_PRIZE;
+ }
+ if(result==5&&bonusResult==0){
+ return THIRD_PRIZE;
+ }
+ if(result==4){
+ return FOURTH_PRIZE;
+ }
+ if(result==3){
+ return FIFTH_PRIZE;
+ }
+ if(result<3){
+ return LOOSE;
+ }
+ throw new IllegalArgumentException("์กด์ฌ ํ์ง ์๋ ์์์
๋๋ค.");
+ }
+} | Java | set์ ์ด์ฉํ์ง ์๋ ๋ฐฉ๋ฒ๋ ์์๋ค์. |
@@ -0,0 +1,79 @@
+package lotto.model;
+
+import lotto.model.constants.LottoPrize;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+import static lotto.constants.ErrorMessage.DUPLICATION;
+import static lotto.constants.ErrorMessage.SIXNUMBER;
+import static lotto.model.constants.LottoPrize.*;
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validate(numbers);
+ duplicate(numbers);
+ this.numbers = numbers;
+ }
+
+ private void duplicate(List<Integer> numbers) {
+ List<Integer> duplication = numbers.stream()
+ .distinct()
+ .toList();
+ if (duplication.size() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+ }
+
+ private void validate(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(SIXNUMBER.getMessage());
+ }
+ }
+ public void checkSame(Integer bonusNumber, List<List<Integer>> lottoNumber) {
+ bonusDuplication(bonusNumber);
+ for (List<Integer> integers : lottoNumber) {
+ List<Integer> Result = integers.stream()
+ .filter(i -> this.numbers.stream().anyMatch(Predicate.isEqual(i)))
+ .toList();
+ long bonusResult = integers.stream()
+ .filter(bonusNumber::equals).count();
+ CheckPrize(Result.size(), bonusResult).addWinCount();
+
+ }
+ }
+
+ private void bonusDuplication(Integer bonusNumber) {
+ List<Integer> Result = this.numbers.stream()
+ .filter(i-> !Objects.equals(i, bonusNumber))
+ .toList();
+ if(Result.size()!=6){
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+
+ }
+
+ public LottoPrize CheckPrize(int result, long bonusResult){
+ if(result==6){
+ return FIRST_PRIZE;
+ }
+ if(result==5&&bonusResult==1){
+ return SECOND_PRIZE;
+ }
+ if(result==5&&bonusResult==0){
+ return THIRD_PRIZE;
+ }
+ if(result==4){
+ return FOURTH_PRIZE;
+ }
+ if(result==3){
+ return FIFTH_PRIZE;
+ }
+ if(result<3){
+ return LOOSE;
+ }
+ throw new IllegalArgumentException("์กด์ฌ ํ์ง ์๋ ์์์
๋๋ค.");
+ }
+} | Java | ํด๋น ๋ถ๋ถ์ LottoPrize์์ ํด์ฃผ๋ฉด lotto์ ์ญํ ์ ์ค์ผ ์ ์์ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ๋๋ฐ ์ด๋ ์ ๊ฐ์?
stream์ ์ด์ฉํด์ filter๋ฅผ ํ๋ฉด ์กฐ๊ธ ๋ ๊น๋ํด ์ง ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,67 @@
+package lotto.model;
+
+import camp.nextstep.edu.missionutils.Randoms;
+import lotto.controller.LottoController;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static lotto.constants.ErrorMessage.ISNOTINTEGER;
+import static lotto.constants.ErrorMessage.NOTTHOUSAND;
+
+public class LottoNumberMaker {
+ private static int buyPrice;
+ private static final List<List<Integer>> numbers = new ArrayList<>();
+ private static final LottoController lottoController = new LottoController();
+
+ public static int getBuyPrice() {
+ return buyPrice;
+ }
+
+ public void makeLottoNumber(Integer count) {
+ buyPrice = count;
+ checkThousand(count);
+ IntStream.range(0, count / 1000)
+ .forEach(i -> numbers.add(makeRandomNumber()));
+ }
+
+ private void checkThousand(Integer count) {
+ if(count%1000!=0){
+ throw new IllegalArgumentException(NOTTHOUSAND.getMessage());
+ }
+ return;
+ }
+
+ private List<Integer> makeRandomNumber() {
+ return Randoms.pickUniqueNumbersInRange(1, 45, 6).stream()
+ .sorted()
+ .collect(Collectors.toList());
+ }
+
+ public void checkInt() {
+ while (true) {
+ try {
+ int number = checkCount();
+ makeLottoNumber(number);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(ISNOTINTEGER.getMessage());
+ System.out.println(NOTTHOUSAND.getMessage());
+ }
+ }
+ }
+
+ private int checkCount() {
+ try {
+ return Integer.parseInt(lottoController.askPrice());
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(ISNOTINTEGER.getMessage());
+ }
+ }
+
+ public List<List<Integer>> getLottoNumber() {
+ return numbers;
+ }
+} | Java | ๋งค์ง ๋๋ฒ ํด์ฃผ์๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,62 @@
+package lotto.view;
+
+import camp.nextstep.edu.missionutils.Console;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static lotto.constants.ErrorMessage.*;
+import static lotto.view.ConstantsMessage.*;
+
+public class LottoInput {
+ public String askPrice() {
+ System.out.println(ASK_BUY_PRICE.getMessage());
+ String input = Console.readLine();
+ return input;
+
+ }
+
+ public List<Integer> prizeNumberInput() {
+ while (true) {
+ try {
+ printNewLine();
+ System.out.println(ASK_PRIZE_NUMBER.getMessage());
+ return changeInt(Arrays.asList(Console.readLine().split(",")));
+ }catch (IllegalArgumentException e){
+ System.out.println(OUTFRANGE.getMessage());
+ }
+ }
+ }
+ public Integer bonusNumberInput() {
+ try{
+ printNewLine();
+ System.out.println(ASK_BONUS_NUMBER.getMessage());
+ String input = Console.readLine();
+
+ return Integer.parseInt(input);
+ }catch (NumberFormatException e){
+ throw new IllegalArgumentException(ONENUMBER.getMessage());
+ }
+
+ }
+ private List<Integer> changeInt(List<String> prizeNumbers) {
+ try{
+ List<Integer> numbers = prizeNumbers.stream()
+ .map(Integer::parseInt)
+ .filter(i->i>0&&i<45)
+ .toList();
+ if(numbers.size() != prizeNumbers.size()){
+ throw new NumberFormatException();
+ }
+ return numbers;
+ }catch (NumberFormatException e){
+ throw new IllegalArgumentException(OUTFRANGE.getMessage());
+ }
+
+ }
+
+ private void printNewLine() {
+ System.out.println();
+ }
+} | Java | ๋ฉ์์ง ์์ %n๋ฅผ ์ด์ฉํด์ printf๋ฅผ ์ด์ฉํ๋ค๋ฉด printNewLine ์ฝ๋๋ฅผ ์์จ๋ ๋ ๊ฒ ๊ฐ์๋ฐ ์ด ๋ถ๋ถ์ ๋ํด์ ์ด๋ป๊ฒ ์๊ฐํ์๋์ง ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,21 @@
+package lotto.constants;
+
+public enum ErrorMessage {
+ DUPLICATION("[ERROR] ๊ฐ์ด ์ค๋ณต๋์์ต๋๋ค"),
+ ISNOTINTEGER("[ERROR] ์ซ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ SIXNUMBER("[ERROR] ๋ฒํธ 6๊ฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ OUTFRANGE("[ERROR] ๋ก๋ ๋ฒํธ๋ 1๋ถํฐ 45 ์ฌ์ด์ ์ซ์์ฌ์ผ ํฉ๋๋ค."),
+ ONENUMBER("[ERROR] ์ซ์ ๋ฒํธ 1๊ฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์"),
+ NOTTHOUSAND("[ERROR] 1000์ ๋จ์๋ก ์
๋ ฅํด ์ฃผ์ธ์");
+
+
+ private final String message;
+
+ ErrorMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | constants ํจํค์ง๊ฐ ๋๊ฐ๊ฐ ์กด์ฌํ๋๋ฐ ์ด๋ฆ์ ๋ฌ๋ฆฌํด์ ๊ตฌ๋ถํ๋๊ฒ ์กฐ๊ธ ๋ ๊ฐ๋
์ฑ์๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,34 @@
+# ๋ก๋
+
+## ๊ธฐ๋ฅ ๋ชฉ๋ก
+- [V] ๋๋ค ํ๊ฒ ์์ฑํ ๋ก๋ ๋ฒํธ์ ์ฌ์ฉ์๊ฐ ์์๋ก ์ ์ ํ ๋น์ฒจ ๋ฒํธ๋ฅผ ๋น๊ตํ์ฌ
+ ๋น์ฒจ๋ ๋ฑ์์ ์์ต๋ฅ ์ ๊ณ์ฐํ๋ค.
+ - [V] ์ฌ์ฉ์๋ก๋ถํฐ ๋ก๋ ๊ตฌ์
๊ธ์ก์ ์
๋ ฅ ๋ฐ๋๋ค.
+ - [V] ์
๋ ฅ ๋ฐ์ ๊ธ์ก์ ๋ฐ๋ผ ๋๋คํ๊ฒ 6๊ฐ์ ์ซ์๋ฅผ ์์ฑํ์ฌ ๋ก๋ ๋ฒํธ๋ฅผ ์์ฑํ๋ค.(1~45๋ฒ์, ์ค๋ณตX, ์ค๋ฆ์ฐจ์ ์ ๋ ฌ)
+ - [V] ์ฌ์ฉ์๋ก๋ถํฐ ๋น์ฒจ ๋ฒํธ์ ๋ณด๋์ค ๋ฒํธ๋ฅผ ์
๋ ฅ ๋ฐ์ ํ, ์์ฑํ ๋ก๋ ๋ฒํธ์ ๋น๊ตํ์ฌ ๋ฑ์๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [V] ์์ต๋ฅ ์ ๊ณ์ฐํ์ฌ ์ถ๋ ฅํ๋ค.(์์์ ๋๋ ์๋ฆฌ ๋ฐ์ฌ๋ฆผ)
+ -[]์
๋ ฅ๊ฐ ์์ธ์ฒ๋ฆฌ
+ -[V]๋ก๋ ๋ฒํธ ์ค๋ณต ์์ธ์ฒ๋ฆฌ
+ -[V]๋ก๋ ๋ฒํธ ๋ฒ์ ๋ฒ์ด๋จ ์์ธ์ฒ๋ฆฌ
+ -[] ๋ณด๋์ค ๋ฒํธ ์์ธ์ฒ๋ฆฌ
+## ๊ธฐ๋ฅ ์๊ตฌ ์ฌํญ
+- ๋ก๋ ๋ฒํธ์ ์ซ์ ๋ฒ์๋ 1~45๊น์ง์ด๋ค.
+- 1๊ฐ์ ๋ก๋๋ฅผ ๋ฐํํ ๋ ์ค๋ณต๋์ง ์๋ 6๊ฐ์ ์ซ์๋ฅผ ๋ฝ๋๋ค.
+- ๋น์ฒจ ๋ฒํธ ์ถ์ฒจ ์ ์ค๋ณต๋์ง ์๋ ์ซ์ 6๊ฐ์ ๋ณด๋์ค ๋ฒํธ 1๊ฐ๋ฅผ ๋ฝ๋๋ค.
+- ๋น์ฒจ์ 1๋ฑ๋ถํฐ 5๋ฑ๊น์ง ์๋ค. ๋น์ฒจ ๊ธฐ์ค๊ณผ ๊ธ์ก์ ์๋์ ๊ฐ๋ค.
+ - 1๋ฑ: 6๊ฐ ๋ฒํธ ์ผ์น / 2,000,000,000์
+ - 2๋ฑ: 5๊ฐ ๋ฒํธ + ๋ณด๋์ค ๋ฒํธ ์ผ์น / 30,000,000์
+ - 3๋ฑ: 5๊ฐ ๋ฒํธ ์ผ์น / 1,500,000์
+ - 4๋ฑ: 4๊ฐ ๋ฒํธ ์ผ์น / 50,000์
+ - 5๋ฑ: 3๊ฐ ๋ฒํธ ์ผ์น / 5,000์
+
+### ์ถ๊ฐ๋ ์๊ตฌ ์ฌํญ
+-[V] ํจ์(๋๋ ๋ฉ์๋)์ ๊ธธ์ด๊ฐ 15๋ผ์ธ์ ๋์ด๊ฐ์ง ์๋๋ก ๊ตฌํํ๋ค.
+- ํจ์(๋๋ ๋ฉ์๋)๊ฐ ํ ๊ฐ์ง ์ผ๋ง ์ ํ๋๋ก ๊ตฌํํ๋ค.
+-[V] else ์์ฝ์ด๋ฅผ ์ฐ์ง ์๋๋ค.
+- ํํธ: if ์กฐ๊ฑด์ ์์ ๊ฐ์ returnํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๋ฉด else๋ฅผ ์ฌ์ฉํ์ง ์์๋ ๋๋ค.
+- else๋ฅผ ์ฐ์ง ๋ง๋ผ๊ณ ํ๋ switch/case๋ก ๊ตฌํํ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ switch/case๋ ํ์ฉํ์ง ์๋๋ค.
+-[V] Java Enum์ ์ ์ฉํ๋ค.
+-[] ๋๋ฉ์ธ ๋ก์ง์ ๋จ์ ํ
์คํธ๋ฅผ ๊ตฌํํด์ผ ํ๋ค. ๋จ, UI(System.out, System.in, Scanner) ๋ก์ง์ ์ ์ธํ๋ค.
+ - ํต์ฌ ๋ก์ง์ ๊ตฌํํ๋ ์ฝ๋์ UI๋ฅผ ๋ด๋นํ๋ ๋ก์ง์ ๋ถ๋ฆฌํด ๊ตฌํํ๋ค.
+ - ๋จ์ ํ
์คํธ ์์ฑ์ด ์ต์ํ์ง ์๋ค๋ฉดย `test/java/lotto/LottoTest`๋ฅผ ์ฐธ๊ณ ํ์ฌ ํ์ตํ ํ ํ
์คํธ๋ฅผ ๊ตฌํํ๋ค.
\ No newline at end of file | Unknown | ์๋ฃ๋ ๋ถ๋ถ ์ฒดํฌํ์ฌ ๋ฆฌ๋๋ฏธ๋ ๊ผผ๊ผผํ๊ฒ ๊ด๋ฆฌํด์ฃผ์๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค~ |
@@ -0,0 +1,50 @@
+package lotto.controller;
+
+import lotto.model.Lotto;
+import lotto.model.LottoNumberMaker;
+import lotto.model.LottoPercentageCalculation;
+import lotto.model.constants.LottoPrize;
+import lotto.view.LottoInput;
+import lotto.view.LottoOutput;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static lotto.model.constants.LottoPrize.*;
+
+public class LottoController {
+ private static final LottoNumberMaker lottoNumberMaker = new LottoNumberMaker();
+ private static final LottoInput lottoInput = new LottoInput();
+ private static final LottoOutput lottoOutput = new LottoOutput();
+ private static final LottoPercentageCalculation lottoPercentageCalculation = new LottoPercentageCalculation();
+ public static void setPrice() {
+ lottoNumberMaker.checkInt();
+ }
+
+// static List<LottoPrize> LottoPrizelist= asList(FIFTH_PRIZE,FOURTH_PRIZE,THIRD_PRIZE,SECOND_PRIZE,FIRST_PRIZE);
+ public static void setBuyLottoNumberPrint() {
+ lottoOutput.buyLottoNumberPrint(lottoNumberMaker.getLottoNumber());
+ }
+
+ public static void setPrizeNumberInput() {
+ Lotto lotto = new Lotto(lottoInput.prizeNumberInput());
+ lotto.checkSame(lottoInput.bonusNumberInput(),lottoNumberMaker.getLottoNumber());
+ }
+
+ public static void winningStatistic() {
+ List<String> lottoPrizes = new ArrayList<>();
+ for(LottoPrize lottoPrize: LottoPrize.values()){
+ lottoPrizes.add(lottoPrize.getText()+lottoPrize.getWinCount()+lottoPrize.getUnit());
+ }
+ LottoOutput.seeWinningStatstic(lottoPrizes);
+ }
+
+ public static void PerformanceCalculation() {
+ lottoOutput.seePercentage(lottoPercentageCalculation.percentageCalculation(LottoPrize.values(),lottoNumberMaker.getBuyPrice()));
+ }
+
+ public String askPrice() {
+ return lottoInput.askPrice();
+ }
+}
\ No newline at end of file | Java | set์ด๋ผ๋ ๋ฉ์๋๋ช
์ Setter์ ๋๋์ด ๊ฐํ๋ฐ ํน์ ๋ค๋ฅธ ๋ณ์๋ช
์ ๊ณ ๋ คํด๋ณด์๋๊ฑด ์ด๋ ์ค๊น์? |
@@ -0,0 +1,79 @@
+package lotto.model;
+
+import lotto.model.constants.LottoPrize;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+import static lotto.constants.ErrorMessage.DUPLICATION;
+import static lotto.constants.ErrorMessage.SIXNUMBER;
+import static lotto.model.constants.LottoPrize.*;
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validate(numbers);
+ duplicate(numbers);
+ this.numbers = numbers;
+ }
+
+ private void duplicate(List<Integer> numbers) {
+ List<Integer> duplication = numbers.stream()
+ .distinct()
+ .toList();
+ if (duplication.size() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+ }
+
+ private void validate(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(SIXNUMBER.getMessage());
+ }
+ }
+ public void checkSame(Integer bonusNumber, List<List<Integer>> lottoNumber) {
+ bonusDuplication(bonusNumber);
+ for (List<Integer> integers : lottoNumber) {
+ List<Integer> Result = integers.stream()
+ .filter(i -> this.numbers.stream().anyMatch(Predicate.isEqual(i)))
+ .toList();
+ long bonusResult = integers.stream()
+ .filter(bonusNumber::equals).count();
+ CheckPrize(Result.size(), bonusResult).addWinCount();
+
+ }
+ }
+
+ private void bonusDuplication(Integer bonusNumber) {
+ List<Integer> Result = this.numbers.stream()
+ .filter(i-> !Objects.equals(i, bonusNumber))
+ .toList();
+ if(Result.size()!=6){
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+
+ }
+
+ public LottoPrize CheckPrize(int result, long bonusResult){
+ if(result==6){
+ return FIRST_PRIZE;
+ }
+ if(result==5&&bonusResult==1){
+ return SECOND_PRIZE;
+ }
+ if(result==5&&bonusResult==0){
+ return THIRD_PRIZE;
+ }
+ if(result==4){
+ return FOURTH_PRIZE;
+ }
+ if(result==3){
+ return FIFTH_PRIZE;
+ }
+ if(result<3){
+ return LOOSE;
+ }
+ throw new IllegalArgumentException("์กด์ฌ ํ์ง ์๋ ์์์
๋๋ค.");
+ }
+} | Java | ์ ๋ ๋์น ๋ถ๋ถ์ด๊ธดํ๋ฐ ๋งค์ง๋๋ฒ ์ฒ๋ฆฌํด์ฃผ์๋๊ฒ ์ข์๋ฏ ํฉ๋๋ค! |
@@ -0,0 +1,79 @@
+package lotto.model;
+
+import lotto.model.constants.LottoPrize;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+import static lotto.constants.ErrorMessage.DUPLICATION;
+import static lotto.constants.ErrorMessage.SIXNUMBER;
+import static lotto.model.constants.LottoPrize.*;
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validate(numbers);
+ duplicate(numbers);
+ this.numbers = numbers;
+ }
+
+ private void duplicate(List<Integer> numbers) {
+ List<Integer> duplication = numbers.stream()
+ .distinct()
+ .toList();
+ if (duplication.size() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+ }
+
+ private void validate(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(SIXNUMBER.getMessage());
+ }
+ }
+ public void checkSame(Integer bonusNumber, List<List<Integer>> lottoNumber) {
+ bonusDuplication(bonusNumber);
+ for (List<Integer> integers : lottoNumber) {
+ List<Integer> Result = integers.stream()
+ .filter(i -> this.numbers.stream().anyMatch(Predicate.isEqual(i)))
+ .toList();
+ long bonusResult = integers.stream()
+ .filter(bonusNumber::equals).count();
+ CheckPrize(Result.size(), bonusResult).addWinCount();
+
+ }
+ }
+
+ private void bonusDuplication(Integer bonusNumber) {
+ List<Integer> Result = this.numbers.stream()
+ .filter(i-> !Objects.equals(i, bonusNumber))
+ .toList();
+ if(Result.size()!=6){
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+
+ }
+
+ public LottoPrize CheckPrize(int result, long bonusResult){
+ if(result==6){
+ return FIRST_PRIZE;
+ }
+ if(result==5&&bonusResult==1){
+ return SECOND_PRIZE;
+ }
+ if(result==5&&bonusResult==0){
+ return THIRD_PRIZE;
+ }
+ if(result==4){
+ return FOURTH_PRIZE;
+ }
+ if(result==3){
+ return FIFTH_PRIZE;
+ }
+ if(result<3){
+ return LOOSE;
+ }
+ throw new IllegalArgumentException("์กด์ฌ ํ์ง ์๋ ์์์
๋๋ค.");
+ }
+} | Java | ```suggestion
.filter(i -> this.numbers
.stream()
.anyMatch(Predicate.isEqual(i)))
```
๋ค์๊ณผ ๊ฐ์ด ๊ฐํ์ฒ๋ฆฌ ํด์ฃผ์๋๊ฒ ๊ฐ๋
์ฑ์ ์ข์๋ณด์
๋๋ค! |
@@ -0,0 +1,79 @@
+package lotto.model;
+
+import lotto.model.constants.LottoPrize;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+import static lotto.constants.ErrorMessage.DUPLICATION;
+import static lotto.constants.ErrorMessage.SIXNUMBER;
+import static lotto.model.constants.LottoPrize.*;
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validate(numbers);
+ duplicate(numbers);
+ this.numbers = numbers;
+ }
+
+ private void duplicate(List<Integer> numbers) {
+ List<Integer> duplication = numbers.stream()
+ .distinct()
+ .toList();
+ if (duplication.size() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+ }
+
+ private void validate(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(SIXNUMBER.getMessage());
+ }
+ }
+ public void checkSame(Integer bonusNumber, List<List<Integer>> lottoNumber) {
+ bonusDuplication(bonusNumber);
+ for (List<Integer> integers : lottoNumber) {
+ List<Integer> Result = integers.stream()
+ .filter(i -> this.numbers.stream().anyMatch(Predicate.isEqual(i)))
+ .toList();
+ long bonusResult = integers.stream()
+ .filter(bonusNumber::equals).count();
+ CheckPrize(Result.size(), bonusResult).addWinCount();
+
+ }
+ }
+
+ private void bonusDuplication(Integer bonusNumber) {
+ List<Integer> Result = this.numbers.stream()
+ .filter(i-> !Objects.equals(i, bonusNumber))
+ .toList();
+ if(Result.size()!=6){
+ throw new IllegalArgumentException(DUPLICATION.getMessage());
+ }
+
+ }
+
+ public LottoPrize CheckPrize(int result, long bonusResult){
+ if(result==6){
+ return FIRST_PRIZE;
+ }
+ if(result==5&&bonusResult==1){
+ return SECOND_PRIZE;
+ }
+ if(result==5&&bonusResult==0){
+ return THIRD_PRIZE;
+ }
+ if(result==4){
+ return FOURTH_PRIZE;
+ }
+ if(result==3){
+ return FIFTH_PRIZE;
+ }
+ if(result<3){
+ return LOOSE;
+ }
+ throw new IllegalArgumentException("์กด์ฌ ํ์ง ์๋ ์์์
๋๋ค.");
+ }
+} | Java | ๋งค์ง๋๋ฒ ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์
์ผ ํ ๊ฒ ๊ฐ์์! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.