feat: Implement My Courses page with course cards, filtering, and certificate download functionality.

This commit is contained in:
supalerk-ar66 2026-01-30 14:34:45 +07:00
parent 9ed2347843
commit c4f68eb927
4 changed files with 107 additions and 157 deletions

View file

@ -103,6 +103,18 @@ export interface QuizResult {
// - ดึงข้อมูลคอร์ส (Public & Protected)
// - ลงทะเบียนเรียน (Enroll)
// - ติดตามความคืบหน้าการเรียน (Progress tracking)
// Interface สำหรับ Certificate
export interface Certificate {
certificate_id: number
course_id: number
course_title: {
en: string
th: string
}
issued_at: string
download_url: string
}
// ==========================================
export const useCourse = () => {
const config = useRuntimeConfig()
@ -522,6 +534,59 @@ export const useCourse = () => {
}
// ฟังก์ชันสร้างใบ Certificate (Create/Generate)
// Endpoint: POST /certificates/:courseId/generate
const generateCertificate = async (courseId: number) => {
try {
const data = await $fetch<{ code: number; message: string; data: Certificate }>(`${API_BASE_URL}/certificates/${courseId}/generate`, {
method: 'POST',
headers: token.value ? {
Authorization: `Bearer ${token.value}`
} : {}
})
return {
success: true,
data: data.data
}
} catch (err: any) {
console.error('Generate certificate failed:', err)
return {
success: false,
error: err.data?.message || err.message || 'Error generating certificate',
code: err.data?.code,
status: err.status
}
}
}
// ฟังก์ชันดึงใบ Certificate ของคอร์สที่ระบุ (แบบเดี่ยว - ใหม่)
// Endpoint: GET /certificates/:courseId
const getCertificate = async (courseId: number) => {
try {
const data = await $fetch<{ code: number; message: string; data: Certificate }>(`${API_BASE_URL}/certificates/${courseId}`, {
method: 'GET',
headers: token.value ? {
Authorization: `Bearer ${token.value}`
} : {}
})
return {
success: true,
data: data.data // Return single certificate object
}
} catch (err: any) {
console.error('Get certificate failed:', err)
return {
success: false,
error: err.data?.message || err.message || 'Error getting certificate',
code: err.data?.code,
status: err.status
}
}
}
return {
fetchCourses,
fetchCourseById,
@ -533,7 +598,9 @@ export const useCourse = () => {
saveVideoProgress,
fetchVideoProgress,
markLessonComplete,
submitQuiz
submitQuiz,
generateCertificate,
getCertificate
}
}