Skip to content

Commit 836aa33

Browse files
1g2g1eecan
andauthored
회원 API, MSW 구현 (#84)
* feat: member 도메인 데이터 추가 Co-authored-by: Chan Lee <[email protected]> * feat: res, req 타입 정의 Co-authored-by: Chan Lee <[email protected]> * feat: member 관련 api 정의 Co-authored-by: Chan Lee <[email protected]> * fix: request 타입 추가 * feat: msw handler Co-authored-by: Chan Lee <[email protected]> * feat: member 관련 query, mutation * refactor: member 관련 handler * chore: api 주석 삭제 --------- Co-authored-by: Chan Lee <[email protected]>
1 parent d75f328 commit 836aa33

15 files changed

+835
-2
lines changed

src/api/member/getConfirmedGames.ts

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 {
4+
GetConfiremdGamesRequest,
5+
GetConfiremdGamesResponse,
6+
} from '@type/api/member';
7+
8+
export const getConfirmedGames = async ({
9+
memberId,
10+
}: GetConfiremdGamesRequest) => {
11+
const { data } = await axiosInstance.get<GetConfiremdGamesResponse>(
12+
`/members/${memberId}/confirmed-games`,
13+
{}
14+
);
15+
16+
return data;
17+
};

src/api/member/getCreatedGames.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import {
4+
GetCreatedGamesRequest,
5+
GetCreatedGamesResponse,
6+
} from '@type/api/member';
7+
8+
export const getCreatedGames = async ({ memberId }: GetCreatedGamesRequest) => {
9+
const { data } = await axiosInstance.get<GetCreatedGamesResponse>(
10+
`/members/${memberId}/created-games`,
11+
{}
12+
);
13+
14+
return data;
15+
};

src/api/member/getLogin.ts

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 { GetLoginRequest, GetLoginResponse } from '@type/api/member';
4+
5+
export const getLogin = async ({
6+
oauthProvider,
7+
authCode,
8+
}: GetLoginRequest) => {
9+
const { data } = await axiosInstance.get<GetLoginResponse>(
10+
`/auth/login/${oauthProvider}`,
11+
{
12+
params: { authCode },
13+
}
14+
);
15+
16+
return data;
17+
};

src/api/member/getMemberProfile.ts

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 {
4+
GetMemberProfileRequest,
5+
GetMemberProfileResponse,
6+
} from '@type/api/member';
7+
8+
export const getMemberProfile = async ({
9+
memberId,
10+
}: GetMemberProfileRequest) => {
11+
const { data } = await axiosInstance.get<GetMemberProfileResponse>(
12+
`/members/${memberId}`,
13+
{}
14+
);
15+
16+
return data;
17+
};
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 { PostRefreshAccessTokenResponse } from '@type/api/member';
4+
5+
export const postRefreshAccessToken = async () => {
6+
const { data } =
7+
await axiosInstance.post<PostRefreshAccessTokenResponse>('/auth/refresh');
8+
9+
return data;
10+
};

src/api/member/postRegistration.ts

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 {
4+
PostRegistrationRequest,
5+
PostRegistrationResponse,
6+
} from '@type/api/member';
7+
8+
export const postRegistration = async (payload: PostRegistrationRequest) => {
9+
const { data } = await axiosInstance.post<PostRegistrationResponse>(
10+
'/members',
11+
{
12+
data: payload,
13+
}
14+
);
15+
16+
return data;
17+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useMutation } from '@tanstack/react-query';
2+
3+
import { postRefreshAccessToken } from '@api/member/postRefreshAccessToken';
4+
5+
export const useRefreshAccessTokenMutation = () => {
6+
const mutation = useMutation({
7+
mutationFn: postRefreshAccessToken,
8+
onSuccess: ({ accessToken }) => {
9+
console.log('useRefreshAccessTokenMutation Success!');
10+
localStorage.setItem('ACCESS_TOKEN', accessToken);
11+
},
12+
onError: () => console.log('useRefreshAccessTokenMutation Error!'),
13+
});
14+
15+
return mutation;
16+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useMutation } from '@tanstack/react-query';
2+
3+
import { postRegistration } from '@api/member/postRegistration';
4+
5+
export const useRegistrationMutation = () => {
6+
const mutation = useMutation({
7+
mutationFn: postRegistration,
8+
onSuccess: (data) => {
9+
console.log('useRegistrationMutation Success!');
10+
// TODO : 쿠키와 사용자 정보에 대한 처리 필요
11+
localStorage.setItem('LOGIN_INFO', JSON.stringify(data));
12+
},
13+
onError: () => {
14+
console.log('useRegistrationMutation Error!');
15+
},
16+
});
17+
18+
return mutation;
19+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useSuspenseQuery } from '@tanstack/react-query';
2+
3+
import { getConfirmedGames } from '@api/member/getConfirmedGames';
4+
5+
import { GetConfiremdGamesRequest } from '@type/api/member';
6+
7+
export const useConfirmGamesQuery = ({
8+
memberId,
9+
}: GetConfiremdGamesRequest) => {
10+
return useSuspenseQuery({
11+
queryKey: ['confirmed-games', memberId],
12+
queryFn: () => getConfirmedGames({ memberId }),
13+
});
14+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useSuspenseQuery } from '@tanstack/react-query';
2+
3+
import { getCreatedGames } from '@api/member/getCreatedGames';
4+
5+
import { GetCreatedGamesRequest } from '@type/api/member';
6+
7+
export const useCreatedGamesQuery = ({ memberId }: GetCreatedGamesRequest) => {
8+
return useSuspenseQuery({
9+
queryKey: ['created-games', memberId],
10+
queryFn: () => getCreatedGames({ memberId }),
11+
});
12+
};

0 commit comments

Comments
 (0)