From a1f8d82be25d2e94a8137c0cda18e1f5573d51f1 Mon Sep 17 00:00:00 2001 From: Khadim Date: Thu, 28 Sep 2023 00:03:33 +0200 Subject: [PATCH] changing works --- api/courses.go | 38 +++++++++++++++++++ .../manage/lecture-management-card.gohtml | 2 +- web/ts/api/admin-lecture-list.ts | 13 +++---- web/ts/data-store/admin-lecture-list.ts | 11 +++--- web/ts/edit-course.ts | 7 +++- 5 files changed, 56 insertions(+), 15 deletions(-) diff --git a/api/courses.go b/api/courses.go index 7502d87f5..c092cb4d8 100644 --- a/api/courses.go +++ b/api/courses.go @@ -70,6 +70,7 @@ func configGinCourseRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { courses.POST("/deleteLectures", routes.deleteLectures) courses.POST("/renameLecture/:streamID", routes.renameLecture) courses.POST("/updateLectureSeries/:streamID", routes.updateLectureSeries) + courses.POST("/updateStartEnd/:streamID", routes.updateStartEnd) courses.PUT("/updateDescription/:streamID", routes.updateDescription) courses.DELETE("/deleteLectureSeries/:streamID", routes.deleteLectureSeries) courses.POST("/submitCut", routes.submitCut) @@ -991,6 +992,43 @@ func (r coursesRoutes) updateDescription(c *gin.Context) { } } +type changeDateTime struct { + Start time.Time `json:"start" binding:"required"` + End time.Time `json:"end" binding:"required"` +} + +func (r coursesRoutes) updateStartEnd(c *gin.Context) { + var req changeDateTime + if err := c.Bind(&req); err != nil { + _ = c.Error(tools.RequestError{ + Status: http.StatusBadRequest, + CustomMessage: "invalid body", + Err: err, + }) + return + } + + stream, err := r.StreamsDao.GetStreamByID(context.Background(), c.Param("streamID")) + if err != nil { + _ = c.Error(tools.RequestError{ + Status: http.StatusNotFound, + CustomMessage: "can not find stream", + Err: err, + }) + return + } + stream.Start = req.Start + stream.End = req.End + if err = r.StreamsDao.UpdateStream(stream); err != nil { + _ = c.Error(tools.RequestError{ + Status: http.StatusInternalServerError, + CustomMessage: "couldn't update lecture Description", + Err: err, + }) + return + } +} + func (r coursesRoutes) renameLecture(c *gin.Context) { sIDInt, err := strconv.Atoi(c.Param("streamID")) if err != nil { diff --git a/web/template/partial/course/manage/lecture-management-card.gohtml b/web/template/partial/course/manage/lecture-management-card.gohtml index 17935dfea..06b823270 100644 --- a/web/template/partial/course/manage/lecture-management-card.gohtml +++ b/web/template/partial/course/manage/lecture-management-card.gohtml @@ -289,7 +289,7 @@ let val = date[0]; val.setDate(startDate.getDate()); val.setMonth(startDate.getMonth()); - val.setYear(startDate.getFullYear()); + val.setFullYear(startDate.getFullYear()); changeSet.patch('end', flatpickr.formatDate(val, 'Z')) }})" /> diff --git a/web/ts/api/admin-lecture-list.ts b/web/ts/api/admin-lecture-list.ts index bdd4fd82a..5f5ae7578 100644 --- a/web/ts/api/admin-lecture-list.ts +++ b/web/ts/api/admin-lecture-list.ts @@ -17,9 +17,9 @@ export interface UpdateLectureMetaRequest { isChatEnabled?: boolean; } -export interface UpdateLectureDateTimeRequest { - startDate: Date; - endTime: Date; +export interface UpdateLectureStartEndRequest { + start: Date; + end: Date; } export class LectureFile { @@ -293,11 +293,8 @@ export const AdminLectureList = { * @param lectureId * @param request */ - updateDateTime: async function (courseId: number, lectureId: number, request: UpdateLectureDateTimeRequest) { - await post(`/api/course/${courseId}/updateDateTime/${lectureId}`, { - startDate: request.startDate, - endTime: request.endTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), - }); + updateStartEnd: async function (courseId: number, lectureId: number, { start, end }: UpdateLectureStartEndRequest) { + await post(`/api/course/${courseId}/updateStartEnd/${lectureId}`, { start, end }); }, /** diff --git a/web/ts/data-store/admin-lecture-list.ts b/web/ts/data-store/admin-lecture-list.ts index b637d57d4..c5295e95d 100644 --- a/web/ts/data-store/admin-lecture-list.ts +++ b/web/ts/data-store/admin-lecture-list.ts @@ -2,8 +2,9 @@ import { StreamableMapProvider } from "./provider"; import { AdminLectureList, Lecture, - LectureFile, UpdateLectureDateTimeRequest, + LectureFile, UpdateLectureMetaRequest, + UpdateLectureStartEndRequest, VideoSection, videoSectionSort, } from "../api/admin-lecture-list"; @@ -113,15 +114,15 @@ export class AdminLectureListProvider extends StreamableMapProvider { if (s.lectureId === lectureId) { return { ...s, - start: payload.startDate, - end: payload.endTime, + start: payload.start, + end: payload.end, }; } return s; diff --git a/web/ts/edit-course.ts b/web/ts/edit-course.ts index 98cb20f4f..bb48bc6d5 100644 --- a/web/ts/edit-course.ts +++ b/web/ts/edit-course.ts @@ -433,7 +433,12 @@ export function lectureEditor(lecture: Lecture): AlpineComponent { // Save new date and time if (changedKeys.includes("start") || changedKeys.includes("end")) { - await DataStore.adminLectureList.updateDateTime(courseId, lectureId, { startDate: new Date(start), endTime: new Date(end) }); + const startDate = new Date(start); + const endDate = new Date(end) + endDate.setFullYear(startDate.getFullYear()); + endDate.setMonth(startDate.getMonth()); + endDate.setDate(startDate.getDate()); + await DataStore.adminLectureList.updateStartEnd(courseId, lectureId, { start: startDate, end: endDate }); } // Saving VideoSections