feat: Add instructor course management pages for creating, listing, and viewing course details.
This commit is contained in:
parent
69eb60f901
commit
af7890cc8f
7 changed files with 229 additions and 28 deletions
|
|
@ -258,10 +258,11 @@ export const instructorService = {
|
|||
return MOCK_COURSE_DETAIL.chapters;
|
||||
}
|
||||
|
||||
const response = await authRequest<{ code: number; data: ChapterResponse[]; total: number }>(
|
||||
`/api/instructors/courses/${courseId}/chapters`
|
||||
// Get chapters from course detail endpoint
|
||||
const response = await authRequest<{ code: number; data: { chapters: ChapterResponse[] } }>(
|
||||
`/api/instructors/courses/${courseId}`
|
||||
);
|
||||
return response.data;
|
||||
return response.data.chapters || [];
|
||||
},
|
||||
|
||||
async createChapter(courseId: number, data: CreateChapterRequest): Promise<ChapterResponse> {
|
||||
|
|
@ -333,6 +334,92 @@ export const instructorService = {
|
|||
`/api/instructors/courses/${courseId}/chapters/${chapterId}/reorder`,
|
||||
{ method: 'PUT', body: { sort_order: sortOrder } }
|
||||
);
|
||||
},
|
||||
|
||||
// Lesson CRUD
|
||||
async getLesson(courseId: number, chapterId: number, lessonId: number): Promise<LessonDetailResponse> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
if (useMockData) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
return MOCK_COURSE_DETAIL.chapters[0].lessons[0] as LessonDetailResponse;
|
||||
}
|
||||
|
||||
const response = await authRequest<{ code: number; data: LessonDetailResponse }>(
|
||||
`/api/instructors/courses/${courseId}/chapters/${chapterId}/lessons/${lessonId}`
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createLesson(courseId: number, chapterId: number, data: CreateLessonRequest): Promise<LessonResponse> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
if (useMockData) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
return {
|
||||
...MOCK_COURSE_DETAIL.chapters[0].lessons[0],
|
||||
id: Date.now(),
|
||||
...data
|
||||
};
|
||||
}
|
||||
|
||||
const response = await authRequest<{ code: number; data: LessonResponse }>(
|
||||
`/api/instructors/courses/${courseId}/chapters/${chapterId}/lessons`,
|
||||
{ method: 'POST', body: data }
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateLesson(courseId: number, chapterId: number, lessonId: number, data: UpdateLessonRequest): Promise<LessonResponse> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
if (useMockData) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
return {
|
||||
...MOCK_COURSE_DETAIL.chapters[0].lessons[0],
|
||||
id: lessonId,
|
||||
...data
|
||||
};
|
||||
}
|
||||
|
||||
const response = await authRequest<{ code: number; data: LessonResponse }>(
|
||||
`/api/instructors/courses/${courseId}/chapters/${chapterId}/lessons/${lessonId}`,
|
||||
{ method: 'PUT', body: data }
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteLesson(courseId: number, chapterId: number, lessonId: number): Promise<void> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
if (useMockData) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
return;
|
||||
}
|
||||
|
||||
await authRequest(
|
||||
`/api/instructors/courses/${courseId}/chapters/${chapterId}/lessons/${lessonId}`,
|
||||
{ method: 'DELETE' }
|
||||
);
|
||||
},
|
||||
|
||||
async reorderLesson(courseId: number, chapterId: number, lessonId: number, sortOrder: number): Promise<void> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
if (useMockData) {
|
||||
await new Promise(resolve => setTimeout(resolve, 300));
|
||||
return;
|
||||
}
|
||||
|
||||
await authRequest(
|
||||
`/api/instructors/courses/${courseId}/chapters/${chapterId}/lessons/reorder`,
|
||||
{ method: 'PUT', body: { lesson_id: lessonId, sort_order: sortOrder } }
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -407,6 +494,34 @@ export interface CreateChapterRequest {
|
|||
is_published?: boolean;
|
||||
}
|
||||
|
||||
export interface CreateLessonRequest {
|
||||
title: { th: string; en: string };
|
||||
content?: { th: string; en: string } | null;
|
||||
type: 'VIDEO' | 'QUIZ';
|
||||
sort_order?: number;
|
||||
}
|
||||
|
||||
export interface UpdateLessonRequest {
|
||||
title: { th: string; en: string };
|
||||
content?: { th: string; en: string } | null;
|
||||
}
|
||||
|
||||
export interface AttachmentResponse {
|
||||
id: number;
|
||||
lesson_id: number;
|
||||
file_name: string;
|
||||
file_path: string;
|
||||
file_size: number;
|
||||
mime_type: string;
|
||||
description: { th: string; en: string };
|
||||
sort_order: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface LessonDetailResponse extends LessonResponse {
|
||||
attachments: AttachmentResponse[];
|
||||
}
|
||||
|
||||
// Mock course detail
|
||||
const MOCK_COURSE_DETAIL: CourseDetailResponse = {
|
||||
...MOCK_COURSES[0],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue