|
| 1 | +import { apiSlice } from "./baseApiSlice"; |
| 2 | +import { TIMETABLES_URL } from "./config"; |
| 3 | + |
| 4 | +// Endpoints for /api/timetables |
| 5 | +export const timetableApiSlice = apiSlice.injectEndpoints({ |
| 6 | + endpoints: (builder) => ({ |
| 7 | + createTimetable: builder.mutation({ |
| 8 | + query: (data) => ({ |
| 9 | + url: `${TIMETABLES_URL}`, |
| 10 | + method: "POST", |
| 11 | + headers: { |
| 12 | + "Content-Type": "application/json", |
| 13 | + Accept: "application/json, text/plain, */*", |
| 14 | + }, |
| 15 | + providesTags: ["Timetable"], |
| 16 | + body: data, |
| 17 | + credentials: "include", |
| 18 | + }), |
| 19 | + }), |
| 20 | + getTimetables: builder.query<unknown, void>({ |
| 21 | + query: () => ({ |
| 22 | + url: `${TIMETABLES_URL}`, |
| 23 | + method: "GET", |
| 24 | + headers: { |
| 25 | + "Content-Type": "application/json", |
| 26 | + Accept: "application/json, text/plain, */*", |
| 27 | + }, |
| 28 | + providesTags: ["Timetable"], |
| 29 | + credentials: "include", |
| 30 | + }), |
| 31 | + }), |
| 32 | + updateTimetable: builder.mutation({ |
| 33 | + query: (data) => ({ |
| 34 | + url: `${TIMETABLES_URL}/${data.id}`, |
| 35 | + method: "PUT", |
| 36 | + headers: { |
| 37 | + "Content-Type": "application/json", |
| 38 | + Accept: "application/json, text/plain, */*", |
| 39 | + }, |
| 40 | + providesTags: ["Timetable"], |
| 41 | + body: data, |
| 42 | + credentials: "include", |
| 43 | + }), |
| 44 | + }), |
| 45 | + deleteTimetable: builder.mutation({ |
| 46 | + query: (id) => ({ |
| 47 | + url: `${TIMETABLES_URL}/${id}`, |
| 48 | + method: "DELETE", |
| 49 | + headers: { |
| 50 | + "Content-Type": "application/json", |
| 51 | + Accept: "application/json, text/plain, */*", |
| 52 | + }, |
| 53 | + providesTags: ["Timetable"], |
| 54 | + credentials: "include", |
| 55 | + }), |
| 56 | + }), |
| 57 | + }), |
| 58 | +}); |
| 59 | + |
| 60 | +export const { |
| 61 | + useGetTimetablesQuery, |
| 62 | + useUpdateTimetableMutation, |
| 63 | + useCreateTimetableMutation, |
| 64 | + useDeleteTimetableMutation, |
| 65 | +} = timetableApiSlice; |
0 commit comments