From 30e20034435afd96758830e37a7daf7d6d99dcfb Mon Sep 17 00:00:00 2001 From: minkyung00 Date: Fri, 10 Feb 2023 21:01:38 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EB=8C=80?= =?UTF-8?q?=ED=9A=8C=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20(#65)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/queryKeys.ts | 1 + src/pages/User/api/index.ts | 6 +++- src/pages/User/hooks/query/index.ts | 1 + .../query/useUserCompetitionListQuery.ts | 28 +++++++++++++++++++ src/types/user.d.ts | 12 ++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/pages/User/hooks/query/useUserCompetitionListQuery.ts 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;