Skip to content

Commit d75f328

Browse files
dlwl98imb96
andauthored
경기(매치) 관련 api 함수 구현 (#78)
* feat: 게임 도메인 관련 요청, 응답 타입 선언 Co-authored-by: Minjae Kim <[email protected]> * feat: games mock 데이터 추가 Co-authored-by: Minjae Kim <[email protected]> * feat: postGame api 함수 작성 Co-authored-by: Minjae Kim <[email protected]> * feat: 게스트 모집글 생성 mutation 작성 - useGameMutation 함수 작성 Co-authored-by: Minjae Kim <[email protected]> * feat: 게스트 모집글 작성 api msw handler 작성 - mockPostGame 함수 작성 Co-authored-by: Minjae Kim <[email protected]> * feat: 경기 목록 가져오는 api 작성 - getGames 함수 작성 * feat: 경기 목록 가져오는 Query 작성 - useGamesQuery 훅 작성 * feat: 경기 목록 가져오는 mock api handler 작성 - mockGetGames 작성 * feat: 경기(매치)관련 api 함수 작성 Co-authored-by: Minjae Kim <[email protected]> --------- Co-authored-by: Minjae Kim <[email protected]>
1 parent cec67f8 commit d75f328

File tree

13 files changed

+333
-1
lines changed

13 files changed

+333
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import { DeleteGameParticipateRequest } from '@type/api/games';
4+
5+
export const deleteGameParticipate = async ({
6+
gameId,
7+
memberId,
8+
}: DeleteGameParticipateRequest) => {
9+
await axiosInstance.delete(`/api/games/${gameId}/members/${memberId}`, {});
10+
};

src/api/games/getGameDetail.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import { GetGameDetailResponse } from '@type/api/games';
4+
import { Game } from '@type/models';
5+
6+
export const getGameDetail = async ({ gameId }: { gameId: Game['id'] }) => {
7+
const { data } = await axiosInstance.get<GetGameDetailResponse>(
8+
`api/games/${gameId}`,
9+
{}
10+
);
11+
12+
return data;
13+
};

src/api/games/getGameMembers.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import { GetGameMembersResponse } from '@type/api/games';
4+
import { Game } from '@type/models';
5+
6+
export const getGameMebers = async ({
7+
gameId,
8+
status,
9+
}: {
10+
gameId: Game['id'];
11+
status: '대기' | '확정';
12+
}) => {
13+
const { data } = await axiosInstance.get<GetGameMembersResponse>(
14+
`/api/games/${gameId}/members`,
15+
{
16+
params: { status },
17+
}
18+
);
19+
20+
return data;
21+
};

src/api/games/getGames.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import { GetGamesResponse } from '@type/api/games';
4+
5+
export const getGames = async ({
6+
category,
7+
value,
8+
page,
9+
size,
10+
}: {
11+
category?: string;
12+
value?: string;
13+
page: number;
14+
size: number;
15+
}) => {
16+
const { data } = await axiosInstance.get<GetGamesResponse>('/api/games', {
17+
params: { category, value, page, size },
18+
});
19+
20+
return data;
21+
};

src/api/games/patchGameParticipate.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import { PatchGameParticipateApplyRequest } from '@type/api/games';
4+
import { Game, Member } from '@type/models';
5+
6+
export const patchMannerScoreReview = async ({
7+
payload,
8+
gameId,
9+
memberId,
10+
}: {
11+
payload: PatchGameParticipateApplyRequest;
12+
gameId: Game['id'];
13+
memberId: Member['id'];
14+
}) => {
15+
await axiosInstance.patch(`api/games/${gameId}/members/${memberId}`, {
16+
data: payload,
17+
});
18+
return;
19+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import { PatchGameMannerScoreReviewRequest } from '@type/api/games';
4+
import { Game } from '@type/models';
5+
6+
export const patchMannerScoreReview = async ({
7+
payload,
8+
gameId,
9+
}: {
10+
payload: PatchGameMannerScoreReviewRequest;
11+
gameId: Game['id'];
12+
}) => {
13+
await axiosInstance.patch(`api/games/${gameId}/members/manner-scores`, {
14+
data: payload,
15+
});
16+
return;
17+
};

src/api/games/postGame.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import { PostGameRequest, PostGameResponse } from '@type/api/games';
4+
5+
export const postGame = async (payload: PostGameRequest) => {
6+
const { data } = await axiosInstance.post<PostGameResponse>('/api/games', {
7+
data: payload,
8+
});
9+
10+
return data;
11+
};

src/api/games/postGameParticipate.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import { PostGameParticipateRequest } from '@type/api/games';
4+
import { Game } from '@type/models';
5+
6+
export const postGameParticipate = async ({
7+
payload,
8+
gameId,
9+
}: {
10+
payload: PostGameParticipateRequest;
11+
gameId: Game['id'];
12+
}) => {
13+
await axiosInstance.post(`/api/games/${gameId}/members`, {
14+
data: payload,
15+
});
16+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useMutation } from '@tanstack/react-query';
2+
3+
import { postGame } from '@api/games/postGame';
4+
5+
export const useGameMutation = () => {
6+
return useMutation({
7+
mutationFn: postGame,
8+
});
9+
};

src/hooks/queries/useGamesQuery.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
2+
3+
import { getGames } from '@api/games/getGames';
4+
5+
const FETCH_SIZE = 20;
6+
7+
export const useGamesQuery = ({
8+
category,
9+
value,
10+
}: {
11+
category?: string;
12+
value?: string;
13+
}) => {
14+
return useSuspenseInfiniteQuery({
15+
queryKey: ['games', category, value],
16+
queryFn: ({ pageParam }) =>
17+
getGames({ category, value, page: pageParam, size: FETCH_SIZE }),
18+
getNextPageParam: (page) => {
19+
return page.length / FETCH_SIZE;
20+
},
21+
initialPageParam: 0,
22+
});
23+
};

0 commit comments

Comments
 (0)