From 9495678b6d1054153082fe8ccd121c29ae28026e Mon Sep 17 00:00:00 2001 From: rbgksqkr Date: Mon, 22 Jul 2024 17:29:04 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EC=A7=88=EB=AC=B8=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=88=98=EC=A0=95=20#43?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/.husky/prepare-commit-msg | 6 +++--- frontend/src/mocks/data/balanceContent.json | 13 +++++++++++++ frontend/src/mocks/data/question.json | 13 ------------- .../src/types/{question.ts => balanceContent.ts} | 10 +++++----- 4 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 frontend/src/mocks/data/balanceContent.json delete mode 100644 frontend/src/mocks/data/question.json rename frontend/src/types/{question.ts => balanceContent.ts} (50%) diff --git a/frontend/.husky/prepare-commit-msg b/frontend/.husky/prepare-commit-msg index 584fc7514..0e6deab0d 100644 --- a/frontend/.husky/prepare-commit-msg +++ b/frontend/.husky/prepare-commit-msg @@ -21,7 +21,7 @@ fi # 이슈 번호가 이미 커밋 메시지에 있는지 확인 if ! echo "$COMMIT_MSG" | grep -q "#$ISSUE_NUMBER"; then # 이슈 번호가 없으면 커밋 메시지 끝에 추가 - echo -n "$COMMIT_MSG" > $COMMIT_MSG_FILE - echo " #$ISSUE_NUMBER" >> $COMMIT_MSG_FILE + NEW_COMMIT_MSG="$COMMIT_MSG #$ISSUE_NUMBER" + echo "$NEW_COMMIT_MSG" > "$COMMIT_MSG_FILE" echo "Issue number #$ISSUE_NUMBER has been automatically added to the commit message." -fi \ No newline at end of file +fi diff --git a/frontend/src/mocks/data/balanceContent.json b/frontend/src/mocks/data/balanceContent.json new file mode 100644 index 000000000..5b1a4952b --- /dev/null +++ b/frontend/src/mocks/data/balanceContent.json @@ -0,0 +1,13 @@ +{ + "contentId": 1, + "category": "연애", + "question": "당신의 결혼 상대는?", + "firstOption": { + "optionId": 1, + "name": "100억 빚 송강" + }, + "secondOption": { + "optionId": 2, + "name": "100억 부자 송강호" + } +} diff --git a/frontend/src/mocks/data/question.json b/frontend/src/mocks/data/question.json deleted file mode 100644 index fe52b267c..000000000 --- a/frontend/src/mocks/data/question.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "questionId": 1, - "category": "연애", - "title": "당신의 결혼 상대는?", - "firstOption": { - "optionId": 1, - "content": "100억 빚 송강" - }, - "secondOption": { - "optionId": 2, - "content": "100억 부자 송강호" - } -} diff --git a/frontend/src/types/question.ts b/frontend/src/types/balanceContent.ts similarity index 50% rename from frontend/src/types/question.ts rename to frontend/src/types/balanceContent.ts index 21b4a7fec..e619566c4 100644 --- a/frontend/src/types/question.ts +++ b/frontend/src/types/balanceContent.ts @@ -1,13 +1,13 @@ -export interface Question { - questionId: number; - title: string; +export interface BalanceContent { + contentId: number; category: string; + question: string; firstOption: { - content: string; optionId: number; + name: string; }; secondOption: { - content: string; optionId: number; + name: string; }; } From d7d0baf441f2519b6732d816458337fb8f371f4c Mon Sep 17 00:00:00 2001 From: rbgksqkr Date: Mon, 22 Jul 2024 17:43:48 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20husky=20pre-push=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=EC=97=90=20=EB=B8=8C=EB=9E=9C?= =?UTF-8?q?=EC=B9=98=20=EC=A0=95=EC=B1=85=20=EC=B6=94=EA=B0=80=20#43?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/.husky/pre-push | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/frontend/.husky/pre-push b/frontend/.husky/pre-push index 994b392e5..60e403807 100644 --- a/frontend/.husky/pre-push +++ b/frontend/.husky/pre-push @@ -5,8 +5,23 @@ # 현재 브랜치 이름 가져오기 current_branch=$(git rev-parse --abbrev-ref HEAD) + +# 브랜치 패턴을 변수로 선언 +branch_patterns=("feat/" "hotfix/" "fix/" "refactor/" "test/") + +# 브랜치가 패턴에 맞는지 확인하는 함수 +matches_pattern() { + local branch=$1 + for pattern in "${branch_patterns[@]}"; do + if [[ $branch == $pattern* ]]; then + return 0 + fi + done + return 1 +} + # feat/ 로 시작하는 브랜치인지 확인 -if [[ $current_branch == feat/* ]] || [[ $current_branch == hotfix/* ]]; then +if matches_pattern "$current_branch"; then echo "Feature branch detected: $current_branch" echo "Starting rebase process..." @@ -31,4 +46,4 @@ if [[ $current_branch == feat/* ]] || [[ $current_branch == hotfix/* ]]; then else echo "Not a feature branch. Proceeding with normal push." exit 0 -fi \ No newline at end of file +fi From 7404128976335771eddaba6b398b7ad6fd4864d6 Mon Sep 17 00:00:00 2001 From: rbgksqkr Date: Mon, 22 Jul 2024 17:45:16 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20content=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=9A=A9=EC=96=B4=20=EB=B3=80=EA=B2=BD=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=20#43?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/apis/balanceContent.ts | 26 +++++++++++++++++++ frontend/src/apis/question.ts | 26 ------------------- .../SelectOption/SelectOption.stories.tsx | 4 +-- .../components/SelectOption/SelectOption.tsx | 6 ++--- frontend/src/constants/url.ts | 10 +++---- .../mocks/handlers/balanceContentHandler.ts | 11 ++++++++ frontend/src/mocks/handlers/index.ts | 4 +-- .../src/mocks/handlers/questionHandler.ts | 11 -------- frontend/src/mocks/handlers/voteHandler.ts | 4 +-- 9 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 frontend/src/apis/balanceContent.ts delete mode 100644 frontend/src/apis/question.ts create mode 100644 frontend/src/mocks/handlers/balanceContentHandler.ts delete mode 100644 frontend/src/mocks/handlers/questionHandler.ts diff --git a/frontend/src/apis/balanceContent.ts b/frontend/src/apis/balanceContent.ts new file mode 100644 index 000000000..c000cb598 --- /dev/null +++ b/frontend/src/apis/balanceContent.ts @@ -0,0 +1,26 @@ +import fetcher from './fetcher'; + +import { API_URL } from '@/constants/url'; +import { BalanceContent } from '@/types/balanceContent'; + +export const fetchBalanceContent = async (roomId = 1): Promise => { + const res = await fetcher.get({ url: API_URL.balanceContent(roomId) }); + + const data = await res.json(); + + return data; +}; + +export const voteBalanceContent = async (optionId: number, roomId = 1, contentId = 1) => { + const res = await fetcher.post({ + url: API_URL.vote(roomId, contentId), + body: { + memberId: 1, + optionId, + }, + }); + + const data = await res.json(); + + return data; +}; diff --git a/frontend/src/apis/question.ts b/frontend/src/apis/question.ts deleted file mode 100644 index dd2ab0f5d..000000000 --- a/frontend/src/apis/question.ts +++ /dev/null @@ -1,26 +0,0 @@ -import fetcher from './fetcher'; - -import { API_URL } from '@/constants/url'; -import { Question } from '@/types/question'; - -export const fetchQuestion = async (roomId = 1): Promise => { - const res = await fetcher.get({ url: API_URL.question(roomId) }); - - const data = await res.json(); - - return data; -}; - -export const voteQuestion = async (choiceId: number, roomId = 1, questionId = 1) => { - const res = await fetcher.post({ - url: API_URL.vote(roomId, questionId), - body: { - memberId: 1, - choiceId, - }, - }); - - const data = await res.json(); - - return data; -}; diff --git a/frontend/src/components/SelectOption/SelectOption.stories.tsx b/frontend/src/components/SelectOption/SelectOption.stories.tsx index 8f77d693e..376ef2a2b 100644 --- a/frontend/src/components/SelectOption/SelectOption.stories.tsx +++ b/frontend/src/components/SelectOption/SelectOption.stories.tsx @@ -21,7 +21,7 @@ type Story = StoryObj; export const 선택되지_않은_옵션: Story = { args: { - option: { content: '100억 빚 송강', optionId: 1 }, + option: { name: '100억 빚 송강', optionId: 1 }, selectedId: 0, }, render: ({ ...args }) => , @@ -29,7 +29,7 @@ export const 선택되지_않은_옵션: Story = { export const 선택된_옵션: Story = { args: { - option: { content: '100억 빚 송강', optionId: 1 }, + option: { name: '100억 빚 송강', optionId: 1 }, selectedId: 1, }, diff --git a/frontend/src/components/SelectOption/SelectOption.tsx b/frontend/src/components/SelectOption/SelectOption.tsx index 9690ff493..4070eb93a 100644 --- a/frontend/src/components/SelectOption/SelectOption.tsx +++ b/frontend/src/components/SelectOption/SelectOption.tsx @@ -1,9 +1,9 @@ import { layout } from './SelectOption.styled'; -import { Question } from '@/types/question'; +import { BalanceContent } from '@/types/balanceContent'; interface SelectOptionProps { - option: Question['firstOption']; + option: BalanceContent['firstOption']; selectedId: number; handleSelectOption: (selectedId: number) => void; } @@ -14,7 +14,7 @@ const SelectOption = ({ option, selectedId, handleSelectOption }: SelectOptionPr css={layout(Boolean(selectedId === option.optionId))} onClick={() => handleSelectOption(option.optionId)} > - {option.content} + {option.name} ); }; diff --git a/frontend/src/constants/url.ts b/frontend/src/constants/url.ts index 53584e079..0200c3a81 100644 --- a/frontend/src/constants/url.ts +++ b/frontend/src/constants/url.ts @@ -1,12 +1,12 @@ const BASE_URL = process.env.NODE_ENV === 'production' ? process.env.API_BASE_URL : ''; export const API_URL = { - question: (roomId: number) => `${BASE_URL}/api/balances/rooms/${roomId}/question`, - vote: (roomId: number, questionId: number) => - `${BASE_URL}/api/balances/rooms/${roomId}/questions/${questionId}/votes`, + balanceContent: (roomId: number) => `${BASE_URL}/api/balances/rooms/${roomId}/content`, + vote: (roomId: number, contentId: number) => + `${BASE_URL}/api/balances/rooms/${roomId}/contents/${contentId}/votes`, }; export const MOCK_API_URL = { - question: '/api/balances/rooms/:roomId/question', - vote: '/api/balances/rooms/:roomId/questions/:questionId/votes', + balanceContent: '/api/balances/rooms/:roomId/content', + vote: '/api/balances/rooms/:roomId/contents/:contentId/votes', }; diff --git a/frontend/src/mocks/handlers/balanceContentHandler.ts b/frontend/src/mocks/handlers/balanceContentHandler.ts new file mode 100644 index 000000000..53921c9e2 --- /dev/null +++ b/frontend/src/mocks/handlers/balanceContentHandler.ts @@ -0,0 +1,11 @@ +import { http, HttpResponse } from 'msw'; + +import BALANCE_CONTENT from '../data/balanceContent.json'; + +import { MOCK_API_URL } from '@/constants/url'; + +const fetchBalanceContentHandler = () => { + return HttpResponse.json(BALANCE_CONTENT); +}; + +export const contentHandler = [http.get(MOCK_API_URL.balanceContent, fetchBalanceContentHandler)]; diff --git a/frontend/src/mocks/handlers/index.ts b/frontend/src/mocks/handlers/index.ts index ddef20832..05552ea89 100644 --- a/frontend/src/mocks/handlers/index.ts +++ b/frontend/src/mocks/handlers/index.ts @@ -1,4 +1,4 @@ -import { questionHandler } from './questionHandler'; +import { contentHandler } from './balanceContentHandler'; import { voteHandler } from './voteHandler'; -export const handlers = [...questionHandler, ...voteHandler]; +export const handlers = [...contentHandler, ...voteHandler]; diff --git a/frontend/src/mocks/handlers/questionHandler.ts b/frontend/src/mocks/handlers/questionHandler.ts deleted file mode 100644 index 1fd5347e6..000000000 --- a/frontend/src/mocks/handlers/questionHandler.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { http, HttpResponse } from 'msw'; - -import QUESTION from '../data/question.json'; - -import { MOCK_API_URL } from '@/constants/url'; - -const fetchQuestionHandler = () => { - return HttpResponse.json(QUESTION); -}; - -export const questionHandler = [http.get(MOCK_API_URL.question, fetchQuestionHandler)]; diff --git a/frontend/src/mocks/handlers/voteHandler.ts b/frontend/src/mocks/handlers/voteHandler.ts index 4ea8caff8..a8dc35b22 100644 --- a/frontend/src/mocks/handlers/voteHandler.ts +++ b/frontend/src/mocks/handlers/voteHandler.ts @@ -2,7 +2,7 @@ import { http, HttpResponse } from 'msw'; import { MOCK_API_URL } from '@/constants/url'; -const voteQuestionHandler = async ({ request }: { request: Request }) => { +const voteBalanceContentHandler = async ({ request }: { request: Request }) => { const body = await request.json(); return HttpResponse.json( @@ -13,4 +13,4 @@ const voteQuestionHandler = async ({ request }: { request: Request }) => { ); }; -export const voteHandler = [http.post(MOCK_API_URL.vote, voteQuestionHandler)]; +export const voteHandler = [http.post(MOCK_API_URL.vote, voteBalanceContentHandler)]; From a6cdf2ea04279053690c087e54789ee7fa416574 Mon Sep 17 00:00:00 2001 From: rbgksqkr Date: Mon, 22 Jul 2024 17:46:04 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20useBalanceContentQuery=20?= =?UTF-8?q?=EC=9D=98=20data=20=EB=B0=98=ED=99=98=EA=B0=92=EC=9D=84=20balan?= =?UTF-8?q?ceContent=EB=A1=9C=20=EA=B3=A0=EC=A0=95=20#43?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/RoundVoteResult/RoundVoteResult.tsx | 8 ++++---- .../components/SelectContainer/SelectContainer.tsx | 10 +++++----- .../components/TopicContainer/TopicContainer.tsx | 8 ++++---- frontend/src/hooks/useBalanceContentQuery.ts | 14 ++++++++++++++ frontend/src/hooks/useQuestionQuery.ts | 12 ------------ 5 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 frontend/src/hooks/useBalanceContentQuery.ts delete mode 100644 frontend/src/hooks/useQuestionQuery.ts diff --git a/frontend/src/components/RoundVoteResult/RoundVoteResult.tsx b/frontend/src/components/RoundVoteResult/RoundVoteResult.tsx index cd382c38b..a780a1187 100644 --- a/frontend/src/components/RoundVoteResult/RoundVoteResult.tsx +++ b/frontend/src/components/RoundVoteResult/RoundVoteResult.tsx @@ -1,19 +1,19 @@ import { layout, fontBold, voteContent } from './RoundVoteResult.styled'; -import useQuestionQuery from '@/hooks/useQuestionQuery'; +import useBalanceContentQuery from '@/hooks/useBalanceContentQuery'; const RoundVoteResult = () => { - const { data: question } = useQuestionQuery(); + const { balanceContent } = useBalanceContentQuery(); return (
-
{question?.firstOption.content}
+
{balanceContent?.firstOption.name}
72%
vs
-
{question?.secondOption.content}
+
{balanceContent?.secondOption.name}
28%
diff --git a/frontend/src/components/SelectContainer/SelectContainer.tsx b/frontend/src/components/SelectContainer/SelectContainer.tsx index 21f8019a5..65eed1455 100644 --- a/frontend/src/components/SelectContainer/SelectContainer.tsx +++ b/frontend/src/components/SelectContainer/SelectContainer.tsx @@ -5,11 +5,11 @@ import { layout, selectSection } from './SelectContainer.styled'; import Button from '@/components/common/Button/Button'; import SelectOption from '@/components/SelectOption/SelectOption'; -import useQuestionQuery from '@/hooks/useQuestionQuery'; +import useBalanceContentQuery from '@/hooks/useBalanceContentQuery'; const SelectContainer = () => { const navigate = useNavigate(); - const { data: question, isLoading } = useQuestionQuery(); + const { balanceContent, isLoading } = useBalanceContentQuery(); const [selectedId, setSelectedId] = useState(0); const goToRoundResult = () => { @@ -24,17 +24,17 @@ const SelectContainer = () => { return ( <> - {question && ( + {balanceContent && (
VS diff --git a/frontend/src/components/TopicContainer/TopicContainer.tsx b/frontend/src/components/TopicContainer/TopicContainer.tsx index d8523c041..a375be173 100644 --- a/frontend/src/components/TopicContainer/TopicContainer.tsx +++ b/frontend/src/components/TopicContainer/TopicContainer.tsx @@ -1,14 +1,14 @@ import { categoryText, topicLayout, topicText } from './TopicContainer.styled'; -import useQuestionQuery from '@/hooks/useQuestionQuery'; +import useBalanceContentQuery from '@/hooks/useBalanceContentQuery'; const TopicContainer = () => { - const { data: question } = useQuestionQuery(); + const { balanceContent } = useBalanceContentQuery(); return (
- {question?.category} - {question?.title} + {balanceContent?.category} + {balanceContent?.question}
); }; diff --git a/frontend/src/hooks/useBalanceContentQuery.ts b/frontend/src/hooks/useBalanceContentQuery.ts new file mode 100644 index 000000000..39a945312 --- /dev/null +++ b/frontend/src/hooks/useBalanceContentQuery.ts @@ -0,0 +1,14 @@ +import { useQuery } from '@tanstack/react-query'; + +import { fetchBalanceContent } from '@/apis/balanceContent'; + +const useBalanceContentQuery = () => { + const balanceContentQuery = useQuery({ + queryKey: ['balanceContent'], + queryFn: async () => await fetchBalanceContent(), + }); + + return { ...balanceContentQuery, balanceContent: balanceContentQuery.data }; +}; + +export default useBalanceContentQuery; diff --git a/frontend/src/hooks/useQuestionQuery.ts b/frontend/src/hooks/useQuestionQuery.ts deleted file mode 100644 index cb4a6f359..000000000 --- a/frontend/src/hooks/useQuestionQuery.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { useQuery } from '@tanstack/react-query'; - -import { fetchQuestion } from '@/apis/question'; - -const useQuestionQuery = () => { - return useQuery({ - queryKey: ['question'], - queryFn: async () => await fetchQuestion(), - }); -}; - -export default useQuestionQuery;