diff --git a/apis/challenge.ts b/apis/challenge.ts index 3ea3c3b..40afdc3 100644 --- a/apis/challenge.ts +++ b/apis/challenge.ts @@ -25,6 +25,11 @@ interface getChallengeSearchResponse extends ResponseBody2 { result: Challenge[]; } +export interface AttendanceRequestBody { + challengeIdx: number; + attendanceCode: string; +} + async function getMyChallengeList(): Promise { const { data } = await client.get(`/challenges`); return data; @@ -49,9 +54,17 @@ async function postNewChallenge(challengeIdx: number): Promise { return data; } +async function postAttendance( + body: AttendanceRequestBody, +): Promise { + const { data } = await client.post(`/challenges/attendance`, body); + return data; +} + export { getMyChallengeList, getChallengeAds, getChallengeSearch, postNewChallenge, + postAttendance, }; diff --git a/apis/hooks/challenge.ts b/apis/hooks/challenge.ts index 3055a43..e990c9a 100644 --- a/apis/hooks/challenge.ts +++ b/apis/hooks/challenge.ts @@ -1,7 +1,9 @@ import { + AttendanceRequestBody, getChallengeAds, getChallengeSearch, getMyChallengeList, + postAttendance, postNewChallenge, } from "../challenge"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; @@ -54,9 +56,20 @@ function usePostNewChallenge( return { mutate }; } +function usePostAttendance() { + const queryClient = useQueryClient(); + const { mutate } = useMutation({ + mutationKey: ["postAttendance"], + mutationFn: (body: AttendanceRequestBody) => postAttendance(body), + }); + + return { mutate }; +} + export { useGetMyChallengeList, useGetChallengeAds, useGetChallengeSearch, usePostNewChallenge, + usePostAttendance, };