diff --git a/Frontend-Learner/composables/useCourse.ts b/Frontend-Learner/composables/useCourse.ts index 23d3d596..6b48f6ef 100644 --- a/Frontend-Learner/composables/useCourse.ts +++ b/Frontend-Learner/composables/useCourse.ts @@ -62,11 +62,20 @@ interface EnrolledCourseResponse { limit: number } +// ========================================== +// Composable: useCourse +// หน้าที่: จัดการ Logic ทุกอย่างเกี่ยวกับคอร์สเรียน +// - ดึงข้อมูลคอร์ส (Public & Protected) +// - ลงทะเบียนเรียน (Enroll) +// - ติดตามความคืบหน้าการเรียน (Progress tracking) +// ========================================== export const useCourse = () => { const config = useRuntimeConfig() const API_BASE_URL = config.public.apiBase as string const { token } = useAuth() + // ฟังก์ชันดึงรายชื่อคอร์สทั้งหมด (Catalog) + // Endpoint: GET /courses const fetchCourses = async () => { try { const data = await $fetch(`${API_BASE_URL}/courses`, { @@ -90,6 +99,8 @@ export const useCourse = () => { } } + // ฟังก์ชันดึงรายละเอียดคอร์สตาม ID + // Endpoint: GET /courses/:id const fetchCourseById = async (id: number) => { try { const data = await $fetch(`${API_BASE_URL}/courses/${id}`, { @@ -130,6 +141,8 @@ export const useCourse = () => { } } + // ฟังก์ชันลงทะเบียนเรียน + // Endpoint: POST /students/courses/:id/enroll const enrollCourse = async (courseId: number) => { try { const data = await $fetch<{ code: number; message: string; data: any }>(`${API_BASE_URL}/students/courses/${courseId}/enroll`, { @@ -197,6 +210,8 @@ export const useCourse = () => { } } + // ฟังก์ชันดึงข้อมูลสำหรับการเรียน (Chapters, Lessons, Progress) + // Endpoint: GET /students/courses/:id/learn const fetchCourseLearningInfo = async (courseId: number) => { try { const data = await $fetch<{ code: number; message: string; data: any }>(`${API_BASE_URL}/students/courses/${courseId}/learn`, { @@ -220,6 +235,8 @@ export const useCourse = () => { } } + // ฟังก์ชันดึงเนื้อหาบทเรียน (Video, Content) + // Endpoint: GET /students/courses/:cid/lessons/:lid const fetchLessonContent = async (courseId: number, lessonId: number) => { try { const data = await $fetch<{ code: number; message: string; data: any; progress?: any }>(`${API_BASE_URL}/students/courses/${courseId}/lessons/${lessonId}`, { @@ -269,6 +286,8 @@ export const useCourse = () => { } } + // ฟังก์ชันบันทึกเวลาที่ดูวิดีโอ (Video Progress) + // Endpoint: POST /students/lessons/:id/progress const saveVideoProgress = async (lessonId: number, progressSeconds: number, durationSeconds: number) => { try { const data = await $fetch<{ code: number; message: string; data: any }>(`${API_BASE_URL}/students/lessons/${lessonId}/progress`, { @@ -320,6 +339,8 @@ export const useCourse = () => { } } + // ฟังก์ชันบันทึกว่าเรียนจบบทเรียนแล้ว (Mark Complete) + // Endpoint: POST /students/courses/:cid/lessons/:lid/complete const markLessonComplete = async (courseId: number, lessonId: number) => { try { const data = await $fetch<{ code: number; message: string; data: any }>(`${API_BASE_URL}/students/courses/${courseId}/lessons/${lessonId}/complete`, { diff --git a/Frontend-Learner/pages/auth/login.vue b/Frontend-Learner/pages/auth/login.vue index ca15a9b6..9bf3e9db 100644 --- a/Frontend-Learner/pages/auth/login.vue +++ b/Frontend-Learner/pages/auth/login.vue @@ -1,9 +1,8 @@