Feat: 이미지, 폴더 관련 쿼리 추가

This commit is contained in:
정현조 2024-10-01 17:10:39 +09:00
parent 38f7add1b4
commit 3349cbf9ef
7 changed files with 117 additions and 18 deletions

View File

@ -0,0 +1,23 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { createFolder } from '@/api/folderApi';
import { FolderRequest } from '@/types';
interface CreateFolderMutationVariables {
projectId: number;
memberId: number;
folderData: FolderRequest;
}
export default function useCreateFolderQuery() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ projectId, memberId, folderData }: CreateFolderMutationVariables) =>
createFolder(projectId, memberId, folderData),
onSuccess: (_, variables) => {
queryClient.invalidateQueries({
queryKey: ['folderList', variables.projectId, variables.memberId],
});
},
});
}

View File

@ -0,0 +1,22 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { deleteFolder } from '@/api/folderApi';
interface DeleteFolderMutationVariables {
projectId: number;
folderId: number;
memberId: number;
}
export default function useDeleteFolderQuery() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ projectId, folderId, memberId }: DeleteFolderMutationVariables) =>
deleteFolder(projectId, folderId, memberId),
onSuccess: (_, variables) => {
queryClient.invalidateQueries({
queryKey: ['folderList', variables.projectId, variables.folderId],
});
},
});
}

View File

@ -0,0 +1,24 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { updateFolder } from '@/api/folderApi';
import { FolderRequest } from '@/types';
interface UpdateFolderMutationVariables {
projectId: number;
folderId: number;
memberId: number;
folderData: FolderRequest;
}
export default function useUpdateFolderQuery() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ projectId, folderId, memberId, folderData }: UpdateFolderMutationVariables) =>
updateFolder(projectId, folderId, memberId, folderData),
onSuccess: (_, variables) => {
queryClient.invalidateQueries({
queryKey: ['folderList', variables.projectId, variables.folderId],
});
},
});
}

View File

@ -1,18 +0,0 @@
import { useMutation } from '@tanstack/react-query';
import { changeImageStatus } from '@/api/imageApi';
import { ImageStatusChangeRequest } from '@/types';
export default function useChangeImageStatusQuery(onSuccess?: () => void) {
return useMutation({
mutationFn: ({
imageId,
memberId,
statusChangeRequest,
}: {
imageId: number;
memberId: number;
statusChangeRequest: ImageStatusChangeRequest;
}) => changeImageStatus(imageId, memberId, statusChangeRequest),
onSuccess,
});
}

View File

@ -0,0 +1,18 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { deleteImage } from '@/api/imageApi';
interface DeleteImageMutationVariables {
imageId: number;
memberId: number;
}
export default function useDeleteImageQuery() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ imageId, memberId }: DeleteImageMutationVariables) => deleteImage(imageId, memberId),
onSuccess: (_, variables) => {
queryClient.invalidateQueries({ queryKey: ['image', variables.imageId] });
},
});
}

View File

@ -0,0 +1,9 @@
import { getImage } from '@/api/imageApi';
import { useSuspenseQuery } from '@tanstack/react-query';
export default function useImageQuery(imageId: number, memberId: number) {
return useSuspenseQuery({
queryKey: ['image', imageId, memberId],
queryFn: () => getImage(imageId, memberId),
});
}

View File

@ -0,0 +1,21 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { moveImage } from '@/api/imageApi';
import { ImageMoveRequest } from '@/types';
interface MoveImageMutationVariables {
imageId: number;
memberId: number;
moveRequest: ImageMoveRequest;
}
export default function useMoveImageQuery() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ imageId, memberId, moveRequest }: MoveImageMutationVariables) =>
moveImage(imageId, memberId, moveRequest),
onSuccess: (_, variables) => {
queryClient.invalidateQueries({ queryKey: ['image', variables.imageId] });
},
});
}