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
๋งค์ง๋„˜๋ฒ„ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ์…”์•ผ ํ• ๊ฒƒ ๊ฐ™์•„์š”!