| 1 |
import { apiSlice } from '../api/apiSlice'; |
| 2 |
|
| 3 |
export const imageUploadApi = apiSlice.injectEndpoints({ |
| 4 |
endpoints: (builder) => ({ |
| 5 |
uploadImage: builder.mutation({ |
| 6 |
query: ({ file, type }) => { |
| 7 |
const formData = new FormData(); |
| 8 |
formData.append('image', file); |
| 9 |
formData.append('type', type); |
| 10 |
return { |
| 11 |
url: 'image-upload', |
| 12 |
method: 'POST', |
| 13 |
body: formData, |
| 14 |
}; |
| 15 |
}, |
| 16 |
invalidatesTags: (result, error, { type }) => [ |
| 17 |
{ type: 'UploadedImages', id: type }, |
| 18 |
], |
| 19 |
}), |
| 20 |
deleteImage: builder.mutation({ |
| 21 |
query: (id) => ({ |
| 22 |
url: `image-upload/${id}`, |
| 23 |
method: 'DELETE', |
| 24 |
}), |
| 25 |
invalidatesTags: ['UploadedImages'], |
| 26 |
}), |
| 27 |
getUploadedImages: builder.query({ |
| 28 |
query: (type) => `image-upload/${type}`, |
| 29 |
providesTags: (result, error, type) => [ |
| 30 |
{ type: 'UploadedImages', id: type }, |
| 31 |
], |
| 32 |
}), |
| 33 |
}), |
| 34 |
}); |
| 35 |
|
| 36 |
export const { |
| 37 |
useUploadImageMutation, |
| 38 |
useDeleteImageMutation, |
| 39 |
useGetUploadedImagesQuery, |
| 40 |
} = imageUploadApi; |
| 41 |
|