-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from kakao-tech-campus-2nd-step3/Week10
Week10 1차
- Loading branch information
Showing
62 changed files
with
1,209 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { queryOptions } from '@tanstack/react-query' | ||
|
||
import { authorizationInstance } from '@/api/instance' | ||
import { Hint } from '@/types' | ||
|
||
type HintRequestParams = { | ||
answerId: number | ||
} | ||
|
||
type HintResponse = { | ||
hints: Hint[] | ||
} | ||
|
||
const getHint = async ({ answerId }: HintRequestParams) => { | ||
const response = await authorizationInstance.get<HintResponse>( | ||
`/api/answer/hint/${answerId}` | ||
) | ||
|
||
return response.data.hints | ||
} | ||
|
||
type BuyHintRequestBody = { | ||
answerId: number | ||
} | ||
|
||
export const buyHint = async ({ answerId }: BuyHintRequestBody) => { | ||
await authorizationInstance.post('/api/answer/hint', { | ||
answerId, | ||
}) | ||
} | ||
|
||
export const hintQuries = { | ||
all: () => ['hints'], | ||
hints: (answerId: number) => | ||
queryOptions({ | ||
queryKey: [...hintQuries.all(), answerId], | ||
queryFn: () => getHint({ answerId }), | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useMutation } from '@tanstack/react-query' | ||
|
||
import { authorizationInstance } from '@/api/instance' | ||
|
||
type AnswerQuestionParam = { | ||
questionId: number | ||
pickedId: number | ||
} | ||
|
||
type AnswerQuestionResponse = { | ||
message: string | ||
} | ||
|
||
const answerRandomQuestion = async ({ | ||
questionId, | ||
pickedId, | ||
}: AnswerQuestionParam): Promise<AnswerQuestionResponse> => { | ||
const response = await authorizationInstance.post('/api/answer/common', { | ||
questionId, | ||
pickedId, | ||
}) | ||
|
||
return response.data | ||
} | ||
|
||
export const useAnswerRandomQuestion = () => { | ||
return useMutation({ | ||
mutationFn: (params: AnswerQuestionParam) => answerRandomQuestion(params), | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
src/api/services/answer/record-paging/useAnswerRecordPaging.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useSuspenseInfiniteQuery } from '@tanstack/react-query' | ||
|
||
import { authorizationInstance } from '@/api/instance' | ||
import { appendParamsToUrl } from '@/api/utils/common/appendParamsToUrl' | ||
import { AnswerRecord, PagingRequestParams, PagingResponse } from '@/types' | ||
|
||
type AnswerRecordPagingResponse = PagingResponse<AnswerRecord[]> | ||
|
||
type AnswerRecordRequsetParams = { | ||
date?: string | ||
} & PagingRequestParams | ||
|
||
const getAnswerRecordPaging = async (params: AnswerRecordRequsetParams) => { | ||
const response = await authorizationInstance.get<AnswerRecordPagingResponse>( | ||
appendParamsToUrl('/api/answer/record', params) | ||
) | ||
|
||
const { data } = response | ||
|
||
return { | ||
records: data.content, | ||
nextPageToken: | ||
data.page !== data.totalPages ? (data.page + 1).toString() : undefined, | ||
} | ||
} | ||
|
||
interface AnswerRecordPagingProps extends PagingRequestParams { | ||
initPageToken?: string | ||
date?: string | ||
} | ||
|
||
export const useAnswerRecordPaging = ({ | ||
size = 10, | ||
sort, | ||
initPageToken, | ||
date, | ||
}: AnswerRecordPagingProps) => { | ||
return useSuspenseInfiniteQuery({ | ||
queryKey: ['answer', 'record', initPageToken], | ||
queryFn: ({ pageParam = initPageToken }) => | ||
getAnswerRecordPaging({ page: pageParam, size, sort, date }), | ||
initialPageParam: initPageToken, | ||
getNextPageParam: (lastPage) => lastPage.nextPageToken, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/api/services/friend/useFriends.ts → src/api/services/friend/queries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.