260928_01_ENH: 신청서 파일 업로드/다운로드 추가

This commit is contained in:
2026-09-28 15:40:08 +09:00
parent 17c34d76b9
commit 2647b88daf
5 changed files with 168 additions and 2 deletions

View File

@@ -3,8 +3,16 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type { ExcelUploadResult } from "@kri/common";
import { nextApi } from "@/lib/http-client";
import { clientEnv } from "@/lib/env.client";
import { downloadFromApiUrl } from "@/lib/kmusical/file";
import { queryKeys } from "@/query/key/keys";
import type { PerformanceCompact, PerformanceFull } from "@/types/kmusical";
import type { PerformanceCompact, PerformanceFull, RequestFormType } from "@/types/kmusical";
const requestFormPath = (performanceId: string, formType: RequestFormType) =>
`/performance/request-form/upload/${encodeURIComponent(performanceId)}/${formType}`;
const requestFormDownloadUrl = (performanceId: string, formType: RequestFormType) =>
`${clientEnv.API_BASE}/performance/request-form/download/${encodeURIComponent(performanceId)}/${formType}`;
export const usePerformanceListQuery = () => useQuery({
queryKey: queryKeys.performance.list,
@@ -58,3 +66,27 @@ export function useUploadPerformanceExcelMutation() {
onSuccess: () => client.invalidateQueries({ queryKey: queryKeys.performance.all }),
});
}
/*
* 신청서 파일 업로드. 같은 공연·formType으로 다시 올리면 기존 파일이 교체된다.
* 응답 본문은 저장된 원본 파일명 문자열이다.
*/
export function useUploadRequestFormMutation() {
const client = useQueryClient();
return useMutation({
mutationFn: ({ performanceId, formType, formData }: { performanceId: string; formType: RequestFormType; formData: FormData }) =>
nextApi.postForm<string>(requestFormPath(performanceId, formType), formData),
onSuccess: () => client.invalidateQueries({ queryKey: queryKeys.performance.all }),
});
}
/*
* 신청서 파일 다운로드. Blob으로 받아 Content-Disposition의 파일명으로 저장한다.
* 파일이 없으면 404(HttpError)로 전파된다.
*/
export function useDownloadRequestFormMutation() {
return useMutation({
mutationFn: ({ performanceId, formType }: { performanceId: string; formType: RequestFormType }) =>
downloadFromApiUrl(requestFormDownloadUrl(performanceId, formType)),
});
}