Refactor: 이미지 호출 함수 수정

This commit is contained in:
정현조 2024-10-04 05:01:10 +09:00
parent 92a368f172
commit 1bbf0bc77e
3 changed files with 15 additions and 7 deletions

View File

@ -2,10 +2,8 @@ import api from '@/api/axiosConfig';
import { ImageMoveRequest, ImageStatusChangeRequest, ImagePresignedUrlResponse } from '@/types';
import axios from 'axios';
export async function getImage(imageId: number, memberId: number) {
return api.get(`/images/${imageId}`, {
params: { memberId },
});
export async function getImage(projectId: number, folderId: number, imageId: number) {
return api.get(`/api/projects/${projectId}/folders/${folderId}/images/${imageId}`);
}
export async function moveImage(projectId: number, folderId: number, imageId: number, moveRequest: ImageMoveRequest) {

View File

@ -0,0 +1,10 @@
import { getImage } from '@/api/imageApi';
import { useQuery } from '@tanstack/react-query';
export default function useImage(projectId: number, folderId: number, imageId: number) {
return useQuery({
queryKey: ['image', projectId, folderId, imageId],
queryFn: () => getImage(projectId, folderId, imageId),
enabled: Boolean(projectId && folderId && imageId),
});
}

View File

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