Skip to content

Commit 5d2d2bd

Browse files
authored
Merge pull request #5 from HSNM2/feature/instructor-course-lesson
Feature/instructor course lesson
2 parents 7f8545b + b80152d commit 5d2d2bd

File tree

3 files changed

+130
-47
lines changed

3 files changed

+130
-47
lines changed

src/models/instructor.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ export function DeleteCourseRequest(params: { id: number }) {
2929
})
3030
}
3131

32+
export function PublishCourseRequest(params: { courseId: number }) {
33+
return request({
34+
url: `api/courseProvider/course/${params.courseId}/inStack`,
35+
method: 'post'
36+
})
37+
}
38+
39+
export function UnpublishCourseRequest(params: { courseId: number }) {
40+
return request({
41+
url: `api/courseProvider/course/${params.courseId}/offStack`,
42+
method: 'post'
43+
})
44+
}
45+
3246
export function CourseChaptersRequest(params: { courseId: number }) {
3347
return request({
3448
url: `/api/courseProvider/course/${params.courseId}/chapter`,
@@ -124,6 +138,28 @@ export function DeleteCourseLessonRequest(params: {
124138
})
125139
}
126140

141+
export function PublishCourseLessonRequest(params: {
142+
courseId: number
143+
chapterId: number
144+
lessonId: number
145+
}) {
146+
return request({
147+
url: `api/courseProvider/course/${params.courseId}/chapter/${params.chapterId}/lesson/${params.lessonId}/inStack`,
148+
method: 'post'
149+
})
150+
}
151+
152+
export function UnPublishCourseLessonRequest(params: {
153+
courseId: number
154+
chapterId: number
155+
lessonId: number
156+
}) {
157+
return request({
158+
url: `api/courseProvider/course/${params.courseId}/chapter/${params.chapterId}/lesson/${params.lessonId}/offStack`,
159+
method: 'post'
160+
})
161+
}
162+
127163
export function CourseFAQsRequest(params: { courseId: number }) {
128164
return request({
129165
url: `/api/courseProvider/course/${params.courseId}/faq`,
@@ -227,17 +263,3 @@ export function UnpublishCourseFAQQuestionRequest(params: {
227263
method: 'post'
228264
})
229265
}
230-
231-
export function PublishCourseRequest(params: { courseId: number }) {
232-
return request({
233-
url: `api/courseProvider/course/${params.courseId}/inStack`,
234-
method: 'post'
235-
})
236-
}
237-
238-
export function UnpublishCourseRequest(params: { courseId: number }) {
239-
return request({
240-
url: `api/courseProvider/course/${params.courseId}/offStack`,
241-
method: 'post'
242-
})
243-
}

src/stores/instructor.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
AddCourseRequest,
77
CourseRequest,
88
DeleteCourseRequest,
9+
PublishCourseRequest,
10+
UnpublishCourseRequest,
911
CourseChaptersRequest,
1012
AddCourseChapterRequest,
1113
DeleteCourseChapterRequest,
@@ -14,6 +16,8 @@ import {
1416
AddCourseLessonRequest,
1517
EditCourseLessonRequest,
1618
DeleteCourseLessonRequest,
19+
PublishCourseLessonRequest,
20+
UnPublishCourseLessonRequest,
1721
CourseFAQsRequest,
1822
AddCourseFAQCategoryRequest,
1923
editCourseFAQCategoryRequest,
@@ -22,9 +26,7 @@ import {
2226
EditCourseFAQQuestionRequest,
2327
DeleteCourseFAQQuestionRequest,
2428
PublishCourseFAQQuestionRequest,
25-
UnpublishCourseFAQQuestionRequest,
26-
PublishCourseRequest,
27-
UnpublishCourseRequest
29+
UnpublishCourseFAQQuestionRequest
2830
} from '@/models/instructor'
2931

3032
interface Course {
@@ -94,6 +96,14 @@ export const useInstructorStore = defineStore('instructor', () => {
9496
return DeleteCourseRequest(payload)
9597
}
9698

99+
function coursePublish(payload: { courseId: number }) {
100+
return PublishCourseRequest(payload)
101+
}
102+
103+
function courseUnpublish(payload: { courseId: number }) {
104+
return UnpublishCourseRequest(payload)
105+
}
106+
97107
//
98108
// 課程章節相關
99109
//
@@ -161,6 +171,18 @@ export const useInstructorStore = defineStore('instructor', () => {
161171
return DeleteCourseLessonRequest(payload)
162172
}
163173

174+
function publishCourseLesson(payload: { courseId: number; chapterId: number; lessonId: number }) {
175+
return PublishCourseLessonRequest(payload)
176+
}
177+
178+
function unPublishCourseLesson(payload: {
179+
courseId: number
180+
chapterId: number
181+
lessonId: number
182+
}) {
183+
return UnPublishCourseLessonRequest(payload)
184+
}
185+
164186
//
165187
// 常見問題相關
166188
//
@@ -230,16 +252,6 @@ export const useInstructorStore = defineStore('instructor', () => {
230252
return UnpublishCourseFAQQuestionRequest(payload)
231253
}
232254

233-
//
234-
// 課程上下架
235-
//
236-
function coursePublish(payload: { courseId: number }) {
237-
return PublishCourseRequest(payload)
238-
}
239-
function courseUnpublish(payload: { courseId: number }) {
240-
return UnpublishCourseRequest(payload)
241-
}
242-
243255
return {
244256
courses,
245257
course,
@@ -253,6 +265,8 @@ export const useInstructorStore = defineStore('instructor', () => {
253265
addCourse,
254266
getCourse,
255267
deleteCourse,
268+
coursePublish,
269+
courseUnpublish,
256270

257271
getCourseChapters,
258272
getCourseChapter,
@@ -264,6 +278,8 @@ export const useInstructorStore = defineStore('instructor', () => {
264278
addCourseLesson,
265279
editCourseLesson,
266280
deleteCourseLesson,
281+
publishCourseLesson,
282+
unPublishCourseLesson,
267283

268284
getCourseFAQs,
269285
addCourseFAQCategory,
@@ -273,9 +289,6 @@ export const useInstructorStore = defineStore('instructor', () => {
273289
editCourseFAQQuestion,
274290
deleteCourseFAQQuestion,
275291
FAQQuestionPublish,
276-
FAQQuestionUnpublish,
277-
278-
coursePublish,
279-
courseUnpublish
292+
FAQQuestionUnpublish
280293
}
281294
})

src/views/instructor/course/CourseChapterView.vue

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,33 @@
6767
>
6868
<template #item="{ element: lesson }">
6969
<li class="border">
70-
<div
71-
@click="editLesson(chapter.id, lesson.id)"
70+
<router-link
71+
:to="`/instructor/course/${+route.params.courseId}/chapter/${chapter.id}/lesson/${
72+
lesson.id
73+
}`"
7274
class="flex cursor-pointer items-center p-4"
7375
>
7476
<i class="material-icons js-draggable me-2 cursor-row-resize">sort</i>
7577
<span class="me-3">{{ lesson.title }}</span>
7678
<span
77-
:class="[lesson.is_publish ? 'text-emerald-700' : 'text-neutral-600']"
79+
:class="[lesson.isPublish ? 'text-emerald-700' : 'text-neutral-600']"
7880
class="rounded-full border bg-neutral-50 px-4 py-1 text-sm"
79-
>{{ lesson.is_publish ? '已發布' : '未發布' }}</span
81+
>{{ lesson.isPublish ? '已發布' : '未發布' }}</span
8082
>
8183
<i class="material-icons me-4 ms-auto cursor-pointer text-neutral-800"
8284
>visibility</i
8385
>
8486
<i
85-
:class="[lesson.is_publish ? 'text-emerald-700' : 'text-neutral-600']"
87+
:class="[lesson.isPublish ? 'text-emerald-700' : 'text-neutral-600']"
8688
class="material-icons cursor-pointer"
89+
@click.prevent="
90+
lesson.isPublish
91+
? unPublishLesson(chapter.id, lesson.id)
92+
: publishLesson(chapter.id, lesson.id)
93+
"
8794
>check_circle_outline</i
8895
>
89-
</div>
96+
</router-link>
9097
</li>
9198
</template>
9299
</draggable>
@@ -145,11 +152,25 @@ const { updateLoading } = useStatusStore()
145152
const { showError } = useErrorHandler()
146153
147154
const instructor = useInstructorStore()
148-
const { getCourseChapters, addCourseChapter, deleteCourseChapter, editCourseChapterTitle } =
149-
instructor
155+
const {
156+
getCourseChapters,
157+
addCourseChapter,
158+
deleteCourseChapter,
159+
editCourseChapterTitle,
160+
publishCourseLesson,
161+
unPublishCourseLesson
162+
} = instructor
150163
const { chapters, course } = storeToRefs(instructor)
151164
152165
onMounted(() => {
166+
getChapter()
167+
})
168+
169+
//
170+
// 章節
171+
//
172+
173+
function getChapter() {
153174
updateLoading(true)
154175
getCourseChapters({ courseId: +route.params.courseId })
155176
.catch((err) => {
@@ -158,11 +179,8 @@ onMounted(() => {
158179
.finally(() => {
159180
updateLoading(false)
160181
})
161-
})
182+
}
162183
163-
//
164-
// 章節
165-
//
166184
function deleteChapter(chapterId: number) {
167185
Swal.fire({
168186
icon: 'warning',
@@ -256,9 +274,39 @@ function addLesson(chapterId: number) {
256274
router.push(`/instructor/course/${+route.params.courseId}/chapter/${chapterId}/lesson`)
257275
}
258276
259-
function editLesson(chapterId: number, lessonId: number) {
260-
router.push(
261-
`/instructor/course/${+route.params.courseId}/chapter/${chapterId}/lesson/${lessonId}`
262-
)
277+
function publishLesson(chapterId: number, lessonId: number) {
278+
updateLoading(true)
279+
publishCourseLesson({ courseId: +route.params.courseId, chapterId, lessonId })
280+
.then(() => {
281+
const chapterIdx = chapters.value.findIndex((chapter) => chapter.id === chapterId)
282+
const lessonIdx = chapters.value[chapterIdx].lessons.findIndex(
283+
(lesson) => lesson.id === lessonId
284+
)
285+
chapters.value[chapterIdx].lessons[lessonIdx].isPublish = true
286+
})
287+
.catch((err) => {
288+
showError(err)
289+
})
290+
.finally(() => {
291+
updateLoading(false)
292+
})
293+
}
294+
295+
function unPublishLesson(chapterId: number, lessonId: number) {
296+
updateLoading(true)
297+
unPublishCourseLesson({ courseId: +route.params.courseId, chapterId, lessonId })
298+
.then(() => {
299+
const chapterIdx = chapters.value.findIndex((chapter) => chapter.id === chapterId)
300+
const lessonIdx = chapters.value[chapterIdx].lessons.findIndex(
301+
(lesson) => lesson.id === lessonId
302+
)
303+
chapters.value[chapterIdx].lessons[lessonIdx].isPublish = false
304+
})
305+
.catch((err) => {
306+
showError(err)
307+
})
308+
.finally(() => {
309+
updateLoading(false)
310+
})
263311
}
264312
</script>

0 commit comments

Comments
 (0)