feat: Добавлен API для файлов приема
This commit is contained in:
parent
eb4890e97b
commit
6cf3238ad4
55
web-app/src/Api/appointmentFilesApi.js
Normal file
55
web-app/src/Api/appointmentFilesApi.js
Normal file
@ -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;
|
||||
Loading…
x
Reference in New Issue
Block a user