feat: add useCourse composable for managing course-related API interactions and data fetching.
This commit is contained in:
parent
06ff2c0d9f
commit
e6549cda44
1 changed files with 26 additions and 1 deletions
|
|
@ -211,13 +211,38 @@ export const useCourse = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkLessonAccess = async (courseId: number, lessonId: number) => {
|
||||||
|
try {
|
||||||
|
const data = await $fetch<{ code: number; message: string; data: any }>(`${API_BASE_URL}/students/courses/${courseId}/lessons/${lessonId}/access-check`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: token.value ? {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
} : {}
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: data.data
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('Check lesson access failed:', err)
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: err.data?.message || err.message || 'Error checking lesson access',
|
||||||
|
code: err.data?.code,
|
||||||
|
status: err.status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fetchCourses,
|
fetchCourses,
|
||||||
fetchCourseById,
|
fetchCourseById,
|
||||||
enrollCourse,
|
enrollCourse,
|
||||||
fetchEnrolledCourses,
|
fetchEnrolledCourses,
|
||||||
fetchCourseLearningInfo,
|
fetchCourseLearningInfo,
|
||||||
fetchLessonContent
|
fetchLessonContent,
|
||||||
|
checkLessonAccess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue