feat: Implement course discovery page with browsing, filtering, and detail view, powered by a new useCourse composable.

This commit is contained in:
supalerk-ar66 2026-01-20 15:01:01 +07:00
parent e6a73c836c
commit 122bb2332f
2 changed files with 55 additions and 5 deletions

View file

@ -88,9 +88,34 @@ export const useCourse = () => {
}
}
const enrollCourse = async (courseId: number) => {
try {
const data = await $fetch<{ code: number; message: string; data: any }>(`${API_BASE_URL}/students/courses/${courseId}/enroll`, {
method: 'POST',
headers: token.value ? {
Authorization: `Bearer ${token.value}`
} : {}
})
return {
success: true,
data: data.data,
message: data.message
}
} catch (err: any) {
console.error('Enroll course failed:', err)
return {
success: false,
error: err.data?.message || err.message || 'Error enrolling in course',
code: err.data?.code
}
}
}
return {
fetchCourses,
fetchCourseById
fetchCourseById,
enrollCourse
}
}