[as] feat: 행정지원 문서 파일 첨부 로직 수정

This commit is contained in:
2026-08-25 09:42:05 +09:00
parent 4bd5276fc5
commit a4c14433cd
26 changed files with 270 additions and 714 deletions
@@ -16,7 +16,14 @@ async function downloadAttachmentByAtflCd(atflCd: string): Promise<AxiosResponse
});
}
async function downloadAttachmentByAtflId(atflId: string): Promise<AxiosResponse> {
return await client.get<Blob>(`${ENDPOINT.ATTACH_SERVICE.DOWNLOAD_BY_ATFL_ID}/${atflId}`, {
responseType: "blob",
});
}
export const attachService = {
deleteAttachmentByAtflId,
downloadAttachmentByAtflCd,
downloadAttachmentByAtflId,
} satisfies AttachService;
+28 -13
View File
@@ -1,4 +1,5 @@
import { useMutation } from "@tanstack/react-query";
import type { AxiosResponse } from "axios";
import { ENDPOINT } from "@/shared/config";
@@ -8,6 +9,22 @@ import { attachService } from "./attach-service";
const attachBaseKey = [ENDPOINT.ATTACH_SERVICE.ATTACHMENTS] as const;
const attachDownloadBaseKey = [ENDPOINT.ATTACH_SERVICE.DOWNLOAD] as const;
const attachDownloadByAtflIdKey = [ENDPOINT.ATTACH_SERVICE.DOWNLOAD_BY_ATFL_ID] as const;
function triggerBlobDownload(response: AxiosResponse) {
const filename = parseFilenameFromResponse(response);
const blob = new Blob([response.data]);
const url = window.URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(link);
}
export function useDeleteAttachment() {
return useMutation({
@@ -21,19 +38,17 @@ export function useDownloadAttachmentByAtflCd() {
mutationKey: [...attachDownloadBaseKey, "download"],
mutationFn: async (atflCd: string) => {
const response = await attachService.downloadAttachmentByAtflCd(atflCd);
const filename = parseFilenameFromResponse(response);
const blob = new Blob([response.data]);
const url = window.URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(link);
triggerBlobDownload(response);
},
});
}
export function useDownloadAttachmentByAtflId() {
return useMutation({
mutationKey: [...attachDownloadByAtflIdKey, "download"],
mutationFn: async (atflId: string) => {
const response = await attachService.downloadAttachmentByAtflId(atflId);
triggerBlobDownload(response);
},
});
}
+5 -1
View File
@@ -1,3 +1,7 @@
export { attachService } from "./api/attach-service";
export { useDeleteAttachment, useDownloadAttachmentByAtflCd } from "./api/queries";
export {
useDeleteAttachment,
useDownloadAttachmentByAtflCd,
useDownloadAttachmentByAtflId,
} from "./api/queries";
export type { Attach, AttachService } from "./model/attach-interface";
@@ -19,4 +19,5 @@ export interface Attach {
export interface AttachService {
deleteAttachmentByAtflId: (atflId: string) => Promise<void>;
downloadAttachmentByAtflCd: (atflCd: string) => Promise<AxiosResponse>;
downloadAttachmentByAtflId: (atflId: string) => Promise<AxiosResponse>;
}