119 lines
3.2 KiB
TypeScript
119 lines
3.2 KiB
TypeScript
import { createApi } from "@reduxjs/toolkit/query/react";
|
|
import { baseQueryWithErrorHandling } from "core/helper/api";
|
|
import {
|
|
Lesson,
|
|
LessonContent,
|
|
LessonQuestion,
|
|
LessonSettings,
|
|
UpdateLessonPreviewThumbnail,
|
|
} from "core/types/lesson";
|
|
|
|
export const lessonsApi = createApi({
|
|
reducerPath: "lessonsApi",
|
|
baseQuery: baseQueryWithErrorHandling,
|
|
endpoints: (builder) => ({
|
|
getLessons: builder.query<Lesson[], undefined>({
|
|
query: () => ({
|
|
url: "lessons",
|
|
method: "GET",
|
|
}),
|
|
}),
|
|
createLesson: builder.mutation({
|
|
query: () => ({
|
|
url: "lessons",
|
|
method: "POST",
|
|
}),
|
|
}),
|
|
getLessonSettings: builder.query<LessonSettings, string>({
|
|
query: (lessonId) => ({
|
|
url: `lessons/${lessonId}/settings`,
|
|
method: "GET",
|
|
}),
|
|
}),
|
|
getLessonContents: builder.query<LessonContent[], string>({
|
|
query: (lessonId) => ({
|
|
url: `lessons/${lessonId}/contents`,
|
|
method: "GET",
|
|
}),
|
|
}),
|
|
updateLessonPreviewTitle: builder.mutation({
|
|
query: ({ lessonId, newTitle }) => ({
|
|
url: `lessons/${lessonId}/preview/title`,
|
|
method: "PATCH",
|
|
body: { Title: newTitle },
|
|
}),
|
|
}),
|
|
updateLessonPreviewThumbnail: builder.mutation<
|
|
void,
|
|
UpdateLessonPreviewThumbnail
|
|
>({
|
|
query: ({ lessonId, formData }) => ({
|
|
url: `lessons/${lessonId}/preview/thumbnail`,
|
|
method: "PATCH",
|
|
body: formData,
|
|
}),
|
|
}),
|
|
updateLessonState: builder.mutation({
|
|
query: ({ lessonId, newState }) => ({
|
|
url: `lessons/${lessonId}/state`,
|
|
method: "PATCH",
|
|
body: { State: newState },
|
|
}),
|
|
}),
|
|
addLessonContent: builder.mutation({
|
|
query: ({ lessonId, type, data }) => ({
|
|
url: `lessons/${lessonId}/contents`,
|
|
method: "POST",
|
|
body: {
|
|
Type: type,
|
|
Data: data,
|
|
},
|
|
}),
|
|
}),
|
|
updateLessonContent: builder.mutation({
|
|
query: ({ lessonId, contentId, data }) => ({
|
|
url: `lessons/${lessonId}/contents/${contentId}`,
|
|
method: "PATCH",
|
|
body: {
|
|
Data: data,
|
|
},
|
|
}),
|
|
}),
|
|
updateLessonContentPosition: builder.mutation({
|
|
query: ({ lessonId, contentId, newPosition }) => ({
|
|
url: `lessons/${lessonId}/contents/${contentId}/position`,
|
|
method: "PATCH",
|
|
body: {
|
|
Position: newPosition,
|
|
},
|
|
}),
|
|
}),
|
|
deleteLessonContent: builder.mutation({
|
|
query: ({ lessonId, contentId }) => ({
|
|
url: `lessons/${lessonId}/contents/${contentId}`,
|
|
method: "DELETE",
|
|
}),
|
|
}),
|
|
getQuestions: builder.query<LessonQuestion[], string>({
|
|
query: (lessonId) => ({
|
|
url: `lessons/${lessonId}/questions`,
|
|
method: "GET",
|
|
}),
|
|
}),
|
|
}),
|
|
});
|
|
|
|
export const {
|
|
useGetLessonsQuery,
|
|
useCreateLessonMutation,
|
|
useGetLessonSettingsQuery,
|
|
useGetLessonContentsQuery,
|
|
useUpdateLessonPreviewTitleMutation,
|
|
useUpdateLessonPreviewThumbnailMutation,
|
|
useUpdateLessonStateMutation,
|
|
useAddLessonContentMutation,
|
|
useUpdateLessonContentMutation,
|
|
useUpdateLessonContentPositionMutation,
|
|
useDeleteLessonContentMutation,
|
|
} = lessonsApi;
|