feat: Add admin user and category management services and instructor course creation and listing pages.
This commit is contained in:
parent
715d94fbf9
commit
9fa70efaf6
4 changed files with 299 additions and 3 deletions
|
|
@ -185,7 +185,7 @@ export const adminService = {
|
|||
}
|
||||
|
||||
const token = getAuthToken();
|
||||
const response = await $fetch<CategoriesListResponse>('/api/admin/categories', {
|
||||
const response = await $fetch<CategoriesListResponse>('/api/categories', {
|
||||
baseURL: config.public.apiBaseUrl as string,
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
|
|
|
|||
|
|
@ -126,6 +126,54 @@ export const instructorService = {
|
|||
}
|
||||
});
|
||||
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createCourse(data: CreateCourseRequest): Promise<CourseResponse> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
if (useMockData) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
return {
|
||||
...MOCK_COURSES[0],
|
||||
id: Date.now(),
|
||||
...data,
|
||||
price: String(data.price), // Convert number to string to match CourseResponse type
|
||||
status: 'DRAFT',
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString()
|
||||
} as CourseResponse;
|
||||
}
|
||||
|
||||
const token = getAuthToken();
|
||||
const response = await $fetch<{ code: number; data: CourseResponse }>('/api/instructors/courses', {
|
||||
method: 'POST',
|
||||
baseURL: config.public.apiBaseUrl as string,
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
body: { data }
|
||||
});
|
||||
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
// Create course request
|
||||
export interface CreateCourseRequest {
|
||||
category_id: number;
|
||||
title: {
|
||||
en: string;
|
||||
th: string;
|
||||
};
|
||||
slug: string;
|
||||
description: {
|
||||
en: string;
|
||||
th: string;
|
||||
};
|
||||
thumbnail_url?: string | null;
|
||||
price: number;
|
||||
is_free: boolean;
|
||||
have_certificate: boolean;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue