Skip to content

Commit

Permalink
feat: 사용자 대회 리스트 조회 API (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
newminkyung committed Feb 10, 2023
1 parent 2b86ba6 commit 30e2003
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/constants/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const QUERY_KEYS = {
USER: 'user',
ADMIN_USER_EDIT: 'admin-user-edit',
ADMIN_ALL_PROBLEMS: 'admin-all-problems',
ADMIN_ALL_ANNOUNCEMENTS: 'admin-all-announcements',
Expand Down
6 changes: 5 additions & 1 deletion src/pages/User/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ const resetPassword = (payload: ResetPasswordRequest): Promise<AxiosResponse> =>
return api.patch(`${API_URL}/{username}/`, payload);
};

export { loginUser, registerUser, resetPassword };
const getUserCompetitionList = (username: string): Promise<AxiosResponse> => {
return api.get(`${API_URL}/${username}/competitions`);
};

export { loginUser, registerUser, resetPassword, getUserCompetitionList };
1 change: 1 addition & 0 deletions src/pages/User/hooks/query/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './useLoginMutation';
export * from './useRegisterMutation';
export * from './useResetPasswordMutation';
export * from './useUserCompetitionListQuery';
28 changes: 28 additions & 0 deletions src/pages/User/hooks/query/useUserCompetitionListQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AxiosError } from 'axios';
import { UseQueryOptions } from 'react-query';

import { QUERY_KEYS } from '@/constants';
import { useSuspenseQuery } from '@/hooks/useSuspenseQuery';

import { getUserCompetitionList } from '../../api';

export const useUserCompetitionListQuery = (
username: string,
options?: UseQueryOptions<
UserCompetitionListResponse,
AxiosError,
UserCompetitionListResponse,
string[]
>
) => {
return useSuspenseQuery(
[QUERY_KEYS.USER, username],
async ({ queryKey: [, username] }) => {
const { data } = await getUserCompetitionList(username);
return data;
},
{
...options,
}
);
};
12 changes: 12 additions & 0 deletions src/types/user.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ type ResetPasswordRequest = {
new_password: string;
new_password2: string;
};

type UserCompetitionList = {
id: number;
problem_id: number;
title: string;
start_time: string;
end_time: string;
rank: number;
user_total: number;
}[];

type UserCompetitionListResponse = ApiResponse<UserCompetitionList>;

0 comments on commit 30e2003

Please sign in to comment.