Skip to content

Commit e00a31b

Browse files
authored
게스트 모집 참여 신청 api mocking (#85)
* fix: 잘못된 함수명 patchGameParticipate으로 수정 * feat: 게임 참여하기 mutation 훅 작성 - useGameParticipateCreateMutation 훅 작성 * feat: mockPostGameParticipate msw handler 구현
1 parent 61039e2 commit e00a31b

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/api/games/patchGameParticipate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { axiosInstance } from '@api/axiosInstance';
33
import { PatchGameParticipateApplyRequest } from '@type/api/games';
44
import { Game, Member } from '@type/models';
55

6-
export const patchMannerScoreReview = async ({
6+
export const patchGameParticipate = async ({
77
payload,
88
gameId,
99
memberId,
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 { postGameParticipate } from '@api/games/postGameParticipate';
4+
5+
export const useGameParticipateCreateMutation = () => {
6+
return useMutation({
7+
mutationFn: postGameParticipate,
8+
});
9+
};

src/mocks/handlers/game.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CommonErrorResponse } from '@type/api/error';
44
import {
55
GetGameDetailResponse,
66
GetGameMembersResponse,
7+
PostGameParticipateRequest,
78
PostGameRequest,
89
PostGameResponse,
910
} from '@type/api/games';
@@ -65,6 +66,34 @@ const mockGetGames = http.get('/api/games', ({ request }) => {
6566
return HttpResponse.json(games.slice(startIndex, startIndex + size));
6667
});
6768

69+
const mockPostGameParticipate = http.post<
70+
{ gameId: string },
71+
{ data: PostGameParticipateRequest }
72+
>('/api/games/:gameId/members', async ({ params, request }) => {
73+
const gameId = Number(params.gameId);
74+
const {
75+
data: { memberId },
76+
} = await request.json();
77+
78+
const game = games.find((game) => game.id === gameId);
79+
if (!game) {
80+
return;
81+
}
82+
83+
game.members.push({
84+
id: memberId,
85+
email: 'james123@pickple.kr',
86+
nickname: 'james123',
87+
introduction: '안녕하십니까. 제임스입니다. 아이고~ 사장님~~',
88+
profileImageUrl: 'https://s3.amazonaws.com/pickple/james123.jpg',
89+
mannerScore: 21,
90+
mannerScoreCount: 30,
91+
addressDepth1: '서울시',
92+
addressDepth2: '강남구',
93+
positions: ['C', 'PF'],
94+
});
95+
});
96+
6897
const mockGetGameMembers = http.get<
6998
{ gameId: string },
7099
DefaultBodyType,
@@ -106,4 +135,10 @@ const mockGetGameDetail = http.get<
106135
return HttpResponse.json(game);
107136
});
108137

109-
export const gameHandlers = [mockPostGame, mockGetGames, mockGetGameDetail, mockGetGameMembers];
138+
export const gameHandlers = [
139+
mockPostGame,
140+
mockGetGames,
141+
mockGetGameDetail,
142+
mockGetGameMembers,
143+
mockPostGameParticipate,
144+
];

0 commit comments

Comments
 (0)