From 6cf3238ad4d314e417ebcb52bd2cebcbf14cfb09 Mon Sep 17 00:00:00 2001 From: andrei Date: Tue, 3 Jun 2025 22:48:50 +0500 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20API=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8=D0=B5=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web-app/src/Api/appointmentFilesApi.js | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 web-app/src/Api/appointmentFilesApi.js diff --git a/web-app/src/Api/appointmentFilesApi.js b/web-app/src/Api/appointmentFilesApi.js new file mode 100644 index 0000000..1f72772 --- /dev/null +++ b/web-app/src/Api/appointmentFilesApi.js @@ -0,0 +1,55 @@ +import { createApi } from "@reduxjs/toolkit/query/react"; +import { baseQueryWithAuth } from "./baseQuery.js"; + +export const appointmentFilesApi = createApi({ + reducerPath: 'appointmentFilesApi', + baseQuery: baseQueryWithAuth, + tagTypes: ['AppointmentFile'], + endpoints: (builder) => ({ + getAppointmentFiles: builder.query({ + query: (appointmentId) => `/appointment-files/${appointmentId}/`, + providesTags: ['AppointmentFile'], + refetchOnMountOrArgChange: 5, + }), + downloadAppointmentFile: builder.query({ + query: (fileId) => ({ + url: `/appointment-files/${fileId}/file`, + responseHandler: async (response) => { + const blob = await response.blob(); + const contentDisposition = response.headers.get('content-disposition'); + const filename = contentDisposition + ? contentDisposition.match(/filename="(.+)"/)?.[1] || `file_${fileId}` + : `file_${fileId}`; + return { blob, filename }; + }, + cache: 'no-cache', + }), + }), + uploadAppointmentFile: builder.mutation({ + query: ({ appointmentId, file }) => { + const formData = new FormData(); + formData.append('file', file); + return { + url: `/appointment-files/${appointmentId}/upload`, + method: 'POST', + body: formData, + }; + }, + invalidatesTags: ['AppointmentFile'], + }), + deleteAppointmentFile: builder.mutation({ + query: (fileId) => ({ + url: `/appointment-files/${fileId}/`, + method: 'DELETE', + }), + invalidatesTags: ['AppointmentFile'], + }), + }), +}); + +export const { + useGetAppointmentFilesQuery, + useDownloadAppointmentFileQuery, + useUploadAppointmentFileMutation, + useDeleteAppointmentFileMutation, +} = appointmentFilesApi; \ No newline at end of file