feat: Implement course discovery page with browsing, filtering, and detail view, powered by a new useCourse composable.
This commit is contained in:
parent
e6a73c836c
commit
122bb2332f
2 changed files with 55 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue