diff --git a/api/courses.go b/api/courses.go index d9d1bafb4..f8c7f924d 100644 --- a/api/courses.go +++ b/api/courses.go @@ -1059,7 +1059,7 @@ func (r coursesRoutes) fetchLectures(c *gin.Context) { tlctx := c.MustGet("TUMLiveContext").(tools.TUMLiveContext) lectureHalls := r.LectureHallsDao.GetAllLectureHalls() - streams := tlctx.Course.AdminJson(lectureHalls) + streams := tools.AdminCourseJson(tlctx.Course, lectureHalls, tlctx.User) c.JSON(http.StatusOK, gin.H{ "streams": streams, diff --git a/model/course.go b/model/course.go index 00e80b330..7b83661a8 100755 --- a/model/course.go +++ b/model/course.go @@ -6,7 +6,6 @@ import ( "log" "time" - "github.com/gin-gonic/gin" "gorm.io/gorm" ) @@ -332,12 +331,3 @@ func (c Course) IsLoggedIn() bool { func (c Course) IsEnrolled() bool { return c.Visibility == "enrolled" } - -// AdminJson is the JSON representation of a courses streams for the admin panel -func (c Course) AdminJson(lhs []LectureHall) []gin.H { - var res []gin.H - for _, s := range c.Streams { - res = append(res, s.getJson(lhs, c)) - } - return res -} diff --git a/model/stream.go b/model/stream.go index fc3572c71..a081618c9 100755 --- a/model/stream.go +++ b/model/stream.go @@ -307,7 +307,7 @@ func (s Stream) Color() string { } } -func (s Stream) getJson(lhs []LectureHall, course Course) gin.H { +func (s Stream) GetJson(lhs []LectureHall, course Course) gin.H { var files []gin.H for _, file := range s.Files { files = append(files, gin.H{ diff --git a/tools/json-generator.go b/tools/json-generator.go new file mode 100644 index 000000000..0aac0c47e --- /dev/null +++ b/tools/json-generator.go @@ -0,0 +1,20 @@ +package tools + +import ( + "github.com/TUM-Dev/gocast/model" + "github.com/gin-gonic/gin" +) + +// AdminCourseJson is the JSON representation of a courses streams for the admin panel +func AdminCourseJson(c *model.Course, lhs []model.LectureHall, u *model.User) []gin.H { + var res []gin.H + streams := c.Streams + for _, s := range streams { + err := SetSignedPlaylists(&s, u, true) + if err != nil { + logger.Error("Could not sign playlist for admin", "err", err) + } + res = append(res, s.GetJson(lhs, *c)) + } + return res +}