feat: Implement course management composable with course fetching and enrollment, and create a user dashboard to display enrolled courses.

This commit is contained in:
supalerk-ar66 2026-02-09 10:53:42 +07:00
parent eb248f7ca2
commit f736eb7f38
2 changed files with 33 additions and 3 deletions

View file

@ -608,6 +608,32 @@ export const useCourse = () => {
}
}
// ฟังก์ชันดึงรายการใบ Certificate ทั้งหมดของผู้ใช้ (ใหม่)
// Endpoint: GET /certificates
const fetchAllCertificates = async () => {
try {
const data = await $fetch<{ code: number; message: string; data: Certificate[] }>(`${API_BASE_URL}/certificates`, {
method: 'GET',
headers: token.value ? {
Authorization: `Bearer ${token.value}`
} : {}
})
return {
success: true,
data: data.data || []
}
} catch (err: any) {
console.error('Fetch all certificates failed:', err)
return {
success: false,
error: err.data?.message || err.message || 'Error fetching certificates',
code: err.data?.code,
status: err.status
}
}
}
return {
fetchCourses,
fetchCourseById,
@ -622,6 +648,7 @@ export const useCourse = () => {
submitQuiz,
generateCertificate,
getCertificate,
fetchAllCertificates,
fetchCourseAnnouncements
}
}