Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 질문에 대한 도메인 용어를 question에서 content로 수정 #44

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions frontend/.husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Comment on lines +9 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L5 - 참고 의견

쉘 스크립트의 함수랑 반복문은 사실 처음 봐서 대략 감으로 유추하자면
return 0 정상 동작이고 return 1이 나오면 비정상 동작으로 에러가 발생하는 함수인 것 같군요.

모든 경우의 브랜치 이름 확인하는 거 좋네요 ㅎㅎ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지피티 참고하긴했는데, 기존 로직대로 추가하면 if문이 많아져서 나중에 브랜치 전략이 변경되어도 수정하기 편하도록 정규표현식으로 작성해보았습니다!!


# 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..."

Expand All @@ -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
fi
6 changes: 3 additions & 3 deletions frontend/.husky/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -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
fi
26 changes: 26 additions & 0 deletions frontend/src/apis/balanceContent.ts
Original file line number Diff line number Diff line change
@@ -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<BalanceContent> => {
const res = await fetcher.get({ url: API_URL.balanceContent(roomId) });

const data = await res.json();

return data;
};
Comment on lines +6 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L5 - 참고 의견

일단 API가 나오지 않아서 roomId의 기본값을 1로 넣은 건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

백엔드와 협의할 때 일단 1을 넣어 API 보내라고 해서 설정한 값입니다!!!


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;
};
26 changes: 0 additions & 26 deletions frontend/src/apis/question.ts

This file was deleted.

8 changes: 4 additions & 4 deletions frontend/src/components/RoundVoteResult/RoundVoteResult.tsx
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L5 - 참고 의견

data를 question으로 받는 형식이 아닌 balanceContent로 변경한 이유가 무엇인가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useQuery를 그대로 반환하고, data는 사용처에서 적절하게 변수명 바꿔주는 게 확장성 측면에서 좋다고 생각하였습니다!
하지만 훅 특성상 여러 상황에서 쓰인다기보단 고정적으로 balanceContent로만 사용되기 때문에 변수값을 고정적으로 설정하였습니다!


return (
<div css={layout({ percentage: 72 })}>
<div css={voteContent}>
<div css={fontBold}>{question?.firstOption.content}</div>
<div css={fontBold}>{balanceContent?.firstOption.name}</div>
<div css={fontBold}>72%</div>
</div>
<span>vs</span>
<div css={voteContent}>
<div css={fontBold}>{question?.secondOption.content}</div>
<div css={fontBold}>{balanceContent?.secondOption.name}</div>
<div>28%</div>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/SelectContainer/SelectContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -24,17 +24,17 @@ const SelectContainer = () => {

return (
<>
{question && (
{balanceContent && (
<div css={layout}>
<section css={selectSection}>
<SelectOption
option={question.firstOption}
option={balanceContent.firstOption}
selectedId={selectedId}
handleSelectOption={handleSelectOption}
/>
<span>VS</span>
<SelectOption
option={question.secondOption}
option={balanceContent.secondOption}
selectedId={selectedId}
handleSelectOption={handleSelectOption}
/>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/SelectOption/SelectOption.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ type Story = StoryObj<typeof meta>;

export const 선택되지_않은_옵션: Story = {
args: {
option: { content: '100억 빚 송강', optionId: 1 },
option: { name: '100억 빚 송강', optionId: 1 },
selectedId: 0,
},
render: ({ ...args }) => <SelectOption {...args} />,
};

export const 선택된_옵션: Story = {
args: {
option: { content: '100억 빚 송강', optionId: 1 },
option: { name: '100억 빚 송강', optionId: 1 },
selectedId: 1,
},

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/SelectOption/SelectOption.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -14,7 +14,7 @@ const SelectOption = ({ option, selectedId, handleSelectOption }: SelectOptionPr
css={layout(Boolean(selectedId === option.optionId))}
onClick={() => handleSelectOption(option.optionId)}
>
{option.content}
{option.name}
</button>
);
};
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/TopicContainer/TopicContainer.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<section css={topicLayout}>
<span css={categoryText}>{question?.category}</span>
<span css={topicText}>{question?.title}</span>
<span css={categoryText}>{balanceContent?.category}</span>
<span css={topicText}>{balanceContent?.question}</span>
</section>
);
};
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/constants/url.ts
Original file line number Diff line number Diff line change
@@ -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',
};
14 changes: 14 additions & 0 deletions frontend/src/hooks/useBalanceContentQuery.ts
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 0 additions & 12 deletions frontend/src/hooks/useQuestionQuery.ts

This file was deleted.

13 changes: 13 additions & 0 deletions frontend/src/mocks/data/balanceContent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"contentId": 1,
"category": "연애",
"question": "당신의 결혼 상대는?",
"firstOption": {
"optionId": 1,
"name": "100억 빚 송강"
},
"secondOption": {
"optionId": 2,
"name": "100억 부자 송강호"
}
}
13 changes: 0 additions & 13 deletions frontend/src/mocks/data/question.json

This file was deleted.

11 changes: 11 additions & 0 deletions frontend/src/mocks/handlers/balanceContentHandler.ts
Original file line number Diff line number Diff line change
@@ -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)];
4 changes: 2 additions & 2 deletions frontend/src/mocks/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -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];
11 changes: 0 additions & 11 deletions frontend/src/mocks/handlers/questionHandler.ts

This file was deleted.

4 changes: 2 additions & 2 deletions frontend/src/mocks/handlers/voteHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)];
Original file line number Diff line number Diff line change
@@ -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;
};
}