-
Notifications
You must be signed in to change notification settings - Fork 2
feat: study handwriting API 추가 #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
|
||
| import { type paths } from '@schema'; | ||
| import { client, TanstackQueryClient } from '@/apis/client'; | ||
|
|
||
| type UpdateStudyHandwritingRequest = | ||
| paths['/api/student/study/problem/{publishId}/{problemId}/handwriting']['put']['requestBody']['content']['application/json']; | ||
| type UpdateStudyHandwritingResponse = | ||
| paths['/api/student/study/problem/{publishId}/{problemId}/handwriting']['put']['responses']['200']['content']['*/*']; | ||
|
|
||
| interface UpdateStudyHandwritingParams { | ||
| publishId: number; | ||
| problemId: number; | ||
| request: UpdateStudyHandwritingRequest; | ||
| } | ||
|
|
||
| export const useUpdateStudyHandwriting = () => { | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: async ({ | ||
| publishId, | ||
| problemId, | ||
| request, | ||
| }: UpdateStudyHandwritingParams): Promise<UpdateStudyHandwritingResponse> => { | ||
| const { data } = await client.PUT( | ||
| '/api/student/study/problem/{publishId}/{problemId}/handwriting', | ||
| { | ||
| params: { | ||
| path: { publishId, problemId }, | ||
| }, | ||
| body: request, | ||
| } | ||
| ); | ||
| return data as UpdateStudyHandwritingResponse; | ||
| }, | ||
| onSuccess: (_, { publishId, problemId, request }) => { | ||
| queryClient.setQueryData( | ||
| TanstackQueryClient.queryOptions( | ||
| 'get', | ||
| '/api/student/study/problem/{publishId}/{problemId}/handwriting', | ||
| { | ||
| params: { path: { publishId, problemId } }, | ||
| } | ||
| ).queryKey, | ||
| { data: request.data } | ||
| ); | ||
| }, | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||
| import { TanstackQueryClient } from '@/apis/client'; | ||||||||
|
|
||||||||
| export const useGetStudyHandwriting = (publishId: number, problemId: number, enabled = true) => { | ||||||||
| return TanstackQueryClient.useQuery( | ||||||||
| 'get', | ||||||||
| '/api/student/study/problem/{publishId}/{problemId}/handwriting', | ||||||||
| { | ||||||||
| params: { | ||||||||
| path: { publishId, problemId }, | ||||||||
| }, | ||||||||
| }, | ||||||||
| { | ||||||||
| enabled, | ||||||||
| staleTime: Infinity, | ||||||||
|
||||||||
| staleTime: Infinity, | |
| staleTime: Infinity, | |
| gcTime: Infinity, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onSuccessupdates the handwriting query cache with{ data: request.data }, which does not match the query’s response type (StudyHandwritingRespincludespublishId,problemId, and optionallyupdatedAt). This can leave the cache in an inconsistent shape and break consumers that expect those fields. Update the cache with the actual mutation response (or merge with existing cached value while preserving required fields).