Skip to content

Commit

Permalink
changing works
Browse files Browse the repository at this point in the history
  • Loading branch information
mono424 committed Sep 27, 2023
1 parent 3aa37df commit a1f8d82
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
38 changes: 38 additions & 0 deletions api/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
}})"
/>
Expand Down
13 changes: 5 additions & 8 deletions web/ts/api/admin-lecture-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 });
},

/**
Expand Down
11 changes: 6 additions & 5 deletions web/ts/data-store/admin-lecture-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { StreamableMapProvider } from "./provider";
import {
AdminLectureList,
Lecture,
LectureFile, UpdateLectureDateTimeRequest,
LectureFile,
UpdateLectureMetaRequest,
UpdateLectureStartEndRequest,
VideoSection,
videoSectionSort,
} from "../api/admin-lecture-list";
Expand Down Expand Up @@ -113,15 +114,15 @@ export class AdminLectureListProvider extends StreamableMapProvider<number, Lect
await this.triggerUpdate(courseId);
}

async updateDateTime(courseId: number, lectureId: number, payload: UpdateLectureDateTimeRequest) {
await AdminLectureList.updateDateTime(courseId, lectureId, payload);
async updateStartEnd(courseId: number, lectureId: number, payload: UpdateLectureStartEndRequest) {
await AdminLectureList.updateStartEnd(courseId, lectureId, payload);

this.data[courseId] = (await this.getData(courseId)).map((s) => {
if (s.lectureId === lectureId) {
return {
...s,
start: payload.startDate,
end: payload.endTime,
start: payload.start,
end: payload.end,
};
}
return s;
Expand Down
7 changes: 6 additions & 1 deletion web/ts/edit-course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1f8d82

Please sign in to comment.