diff --git a/src/constants/queryKeys.ts b/src/constants/queryKeys.ts index 77a0704..dc5ba44 100644 --- a/src/constants/queryKeys.ts +++ b/src/constants/queryKeys.ts @@ -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', diff --git a/src/pages/User/api/index.ts b/src/pages/User/api/index.ts index 522e80b..d37c5da 100644 --- a/src/pages/User/api/index.ts +++ b/src/pages/User/api/index.ts @@ -17,4 +17,8 @@ const resetPassword = (payload: ResetPasswordRequest): Promise => return api.patch(`${API_URL}/{username}/`, payload); }; -export { loginUser, registerUser, resetPassword }; +const getUserCompetitionList = (username: string): Promise => { + return api.get(`${API_URL}/${username}/competitions`); +}; + +export { loginUser, registerUser, resetPassword, getUserCompetitionList }; diff --git a/src/pages/User/hooks/query/index.ts b/src/pages/User/hooks/query/index.ts index ab2626f..a109609 100644 --- a/src/pages/User/hooks/query/index.ts +++ b/src/pages/User/hooks/query/index.ts @@ -1,3 +1,4 @@ export * from './useLoginMutation'; export * from './useRegisterMutation'; export * from './useResetPasswordMutation'; +export * from './useUserCompetitionListQuery'; diff --git a/src/pages/User/hooks/query/useUserCompetitionListQuery.ts b/src/pages/User/hooks/query/useUserCompetitionListQuery.ts new file mode 100644 index 0000000..bc305f9 --- /dev/null +++ b/src/pages/User/hooks/query/useUserCompetitionListQuery.ts @@ -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, + } + ); +}; diff --git a/src/types/user.d.ts b/src/types/user.d.ts index 7c21bde..d1b9e43 100644 --- a/src/types/user.d.ts +++ b/src/types/user.d.ts @@ -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;