diff --git a/api/audit.go b/api/audit.go index 61dec7725..085c8941c 100644 --- a/api/audit.go +++ b/api/audit.go @@ -2,12 +2,13 @@ package api import ( "errors" - "github.com/gin-gonic/gin" + "net/http" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" + "github.com/gin-gonic/gin" "gorm.io/gorm" - "net/http" ) type auditRoutes struct { diff --git a/api/audit_test.go b/api/audit_test.go index 186c71546..b8790fad2 100644 --- a/api/audit_test.go +++ b/api/audit_test.go @@ -1,16 +1,17 @@ package api import ( - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" - "net/http" - "testing" ) func TestGetAudits(t *testing.T) { diff --git a/api/bookmarks.go b/api/bookmarks.go index 353709961..6f3bfa8e0 100644 --- a/api/bookmarks.go +++ b/api/bookmarks.go @@ -2,13 +2,14 @@ package api import ( "errors" - "github.com/gin-gonic/gin" + "net/http" + "strconv" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" + "github.com/gin-gonic/gin" "gorm.io/gorm" - "net/http" - "strconv" ) func configGinBookmarksRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { diff --git a/api/bookmarks_test.go b/api/bookmarks_test.go index fa4aee13f..5b604465f 100644 --- a/api/bookmarks_test.go +++ b/api/bookmarks_test.go @@ -3,17 +3,18 @@ package api import ( "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" "gorm.io/gorm" - "net/http" - "testing" ) func BookmarksRouterWrapper(r *gin.Engine) { diff --git a/api/chat.go b/api/chat.go index f66c02dba..72f459b36 100644 --- a/api/chat.go +++ b/api/chat.go @@ -62,7 +62,6 @@ func RegisterRealtimeChatChannel() { } req, err := parseChatPayload(message) - if err != nil { logger.Warn("could not unmarshal request", "err", err) return @@ -93,7 +92,7 @@ func RegisterRealtimeChatChannel() { }, }) - //delete closed sessions every second + // delete closed sessions every second go func() { c := time.Tick(time.Second) for range c { diff --git a/api/chat_test.go b/api/chat_test.go index e9986d22a..1235b6e5e 100644 --- a/api/chat_test.go +++ b/api/chat_test.go @@ -5,13 +5,13 @@ import ( "net/http" "testing" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" "gorm.io/gorm" ) @@ -77,7 +77,8 @@ func TestMessages(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextStudent)), ExpectedCode: http.StatusOK, ExpectedResponse: chats, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) @@ -141,7 +142,8 @@ func TestActivePoll(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: res, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) @@ -197,7 +199,8 @@ func TestUsers(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextStudent)), ExpectedCode: http.StatusOK, ExpectedResponse: usersResponse, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) diff --git a/api/courseimport.go b/api/courseimport.go index 18db73131..b25c80af6 100644 --- a/api/courseimport.go +++ b/api/courseimport.go @@ -5,6 +5,13 @@ import ( "context" "errors" "fmt" + "html/template" + "net/http" + "strconv" + "strings" + "time" + "unicode" + campusonline "github.com/RBG-TUM/CAMPUSOnline" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" @@ -12,12 +19,6 @@ import ( "github.com/getsentry/sentry-go" "github.com/gin-gonic/gin" uuid "github.com/satori/go.uuid" - "html/template" - "net/http" - "strconv" - "strings" - "time" - "unicode" ) func (r lectureHallRoutes) postSchedule(c *gin.Context) { @@ -215,7 +216,7 @@ func (r lectureHallRoutes) getSchedule(c *gin.Context) { }) return } - //todo figure out right token + // todo figure out right token campus, err := campusonline.New(tools.Cfg.Campus.Tokens[0], "") if err != nil { logger.Error("Can't create campus client", "err", err) diff --git a/api/courses.go b/api/courses.go index 599f2bbaa..2a2230aa9 100644 --- a/api/courses.go +++ b/api/courses.go @@ -5,16 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/RBG-TUM/commons" - "github.com/TUM-Dev/gocast/dao" - "github.com/TUM-Dev/gocast/model" - "github.com/TUM-Dev/gocast/tools" - "github.com/TUM-Dev/gocast/tools/tum" - "github.com/getsentry/sentry-go" - "github.com/gin-gonic/gin" - "github.com/meilisearch/meilisearch-go" - uuid "github.com/satori/go.uuid" - "gorm.io/gorm" "io" "net/http" "net/http/httputil" @@ -25,6 +15,17 @@ import ( "strconv" "strings" "time" + + "github.com/RBG-TUM/commons" + "github.com/TUM-Dev/gocast/dao" + "github.com/TUM-Dev/gocast/model" + "github.com/TUM-Dev/gocast/tools" + "github.com/TUM-Dev/gocast/tools/tum" + "github.com/getsentry/sentry-go" + "github.com/gin-gonic/gin" + "github.com/meilisearch/meilisearch-go" + uuid "github.com/satori/go.uuid" + "gorm.io/gorm" ) func configGinCourseRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { @@ -1343,7 +1344,7 @@ func (r coursesRoutes) createCourse(c *gin.Context) { return } - //verify teaching term input, should either be Sommersemester 2020 or Wintersemester 2020/21 + // verify teaching term input, should either be Sommersemester 2020 or Wintersemester 2020/21 match, err = regexp.MatchString("(Sommersemester [0-9]{4}|Wintersemester [0-9]{4}/[0-9]{2})$", req.TeachingTerm) if err != nil || !match { _ = c.Error(tools.RequestError{ @@ -1481,7 +1482,7 @@ func (r coursesRoutes) deleteCourse(c *gin.Context) { } type createCourseRequest struct { - Access string //enrolled, public, hidden or loggedin + Access string // enrolled, public, hidden or loggedin CourseID string EnChat bool EnDL bool diff --git a/api/courses_test.go b/api/courses_test.go index dcc979f8e..45e36a9a5 100644 --- a/api/courses_test.go +++ b/api/courses_test.go @@ -3,22 +3,23 @@ package api import ( "errors" "fmt" + "html/template" + "net/http" + "testing" + "time" + "github.com/Masterminds/sprig/v3" - "github.com/dgraph-io/ristretto" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/dgraph-io/ristretto" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" "github.com/u2takey/go-utils/uuid" "gorm.io/gorm" - "html/template" - "net/http" - "testing" - "time" ) func CourseRouterWrapper(r *gin.Engine) { @@ -146,7 +147,8 @@ func TestCoursesCRUD(t *testing.T) { Viewers: 0, }, }, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) @@ -521,7 +523,8 @@ func TestCoursesCRUD(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodDelete). Url(fmt.Sprintf("%s?token=%s", url, token)). Run(t, testutils.Equal) @@ -997,7 +1000,8 @@ func TestCoursesLectureActions(t *testing.T) { }, }, ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) @@ -1049,8 +1053,10 @@ func TestCoursesLectureActions(t *testing.T) { configGinCourseRouter(r, wrapper) }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), - Body: deleteLecturesRequest{StreamIDs: []string{ - fmt.Sprintf("%d", testutils.StreamGBSLive.ID)}, + Body: deleteLecturesRequest{ + StreamIDs: []string{ + fmt.Sprintf("%d", testutils.StreamGBSLive.ID), + }, }, ExpectedCode: http.StatusForbidden, }, @@ -1077,11 +1083,14 @@ func TestCoursesLectureActions(t *testing.T) { configGinCourseRouter(r, wrapper) }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), - Body: deleteLecturesRequest{StreamIDs: []string{ - fmt.Sprintf("%d", testutils.StreamFPVLive.ID)}, + Body: deleteLecturesRequest{ + StreamIDs: []string{ + fmt.Sprintf("%d", testutils.StreamFPVLive.ID), + }, }, ExpectedCode: http.StatusOK, - }}.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) + }, + }.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) }) t.Run("POST/api/course/:courseID/renameLecture/:streamID", func(t *testing.T) { url := fmt.Sprintf("/api/course/%d/renameLecture/%d", testutils.CourseFPV.ID, testutils.StreamFPVLive.ID) @@ -1199,7 +1208,8 @@ func TestCoursesLectureActions(t *testing.T) { Name: "Proofs #1", }, ExpectedCode: http.StatusOK, - }}.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) + }, + }.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) }) t.Run("POST/api/course/:courseID/updateLectureSeries/:streamID", func(t *testing.T) { url := fmt.Sprintf("/api/course/%d/updateLectureSeries/%d", testutils.CourseFPV.ID, testutils.StreamFPVLive.ID) @@ -1286,7 +1296,8 @@ func TestCoursesLectureActions(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) @@ -1338,7 +1349,7 @@ func TestCoursesLectureActions(t *testing.T) { streamsMock. EXPECT(). GetStreamByID(gomock.Any(), gomock.Any()). - Return(testutils.StreamGBSLive, nil). //StreamGBSLive.SeriesIdentifier == "" + Return(testutils.StreamGBSLive, nil). // StreamGBSLive.SeriesIdentifier == "" AnyTimes() return streamsMock }(), @@ -1397,7 +1408,8 @@ func TestCoursesLectureActions(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodDelete). Url(url). Run(t, testutils.Equal) @@ -1501,7 +1513,8 @@ func TestCoursesLectureActions(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: body, ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPut). Url(url). Run(t, testutils.Equal) @@ -1604,7 +1617,8 @@ func TestUnits(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: request, ExpectedCode: http.StatusOK, - }}.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) + }, + }.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) }) t.Run("POST/api/course/:courseID/deleteUnit/:unitID", func(t *testing.T) { unit := testutils.StreamFPVLive.Units[0] @@ -1656,7 +1670,8 @@ func TestUnits(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) + }, + }.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) }) } @@ -1754,7 +1769,8 @@ func TestCuts(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: request, ExpectedCode: http.StatusOK, - }}.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) + }, + }.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) }) } @@ -1832,7 +1848,8 @@ func TestAdminFunctions(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: response, - }}.Method(http.MethodGet).Url(url).Run(t, testutils.Equal) + }, + }.Method(http.MethodGet).Url(url).Run(t, testutils.Equal) }) t.Run("PUT/api/course/:courseID/admins/:userID", func(t *testing.T) { url := fmt.Sprintf("/api/course/%d/admins/%d", testutils.CourseFPV.ID, testutils.Admin.ID) @@ -2030,7 +2047,8 @@ func TestAdminFunctions(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: resStudent, - }}. + }, + }. Method(http.MethodPut). Url(url). Run(t, testutils.Equal) @@ -2204,7 +2222,8 @@ func TestAdminFunctions(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: response, - }}. + }, + }. Method(http.MethodDelete). Url(url). Run(t, testutils.Equal) @@ -2221,10 +2240,12 @@ func TestLectureHallsById(t *testing.T) { var sourceMode model.SourceMode = 0 response := []lhResp{ - {LectureHallName: testutils.LectureHall.Name, - LectureHallID: testutils.LectureHall.ID, - Presets: testutils.LectureHall.CameraPresets, - SourceMode: sourceMode}, + { + LectureHallName: testutils.LectureHall.Name, + LectureHallID: testutils.LectureHall.ID, + Presets: testutils.LectureHall.CameraPresets, + SourceMode: sourceMode, + }, } gomino.TestCases{ @@ -2377,7 +2398,8 @@ func TestActivateToken(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextUserNil)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) @@ -2503,7 +2525,8 @@ func TestPresets(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: request, ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) @@ -2737,7 +2760,8 @@ func TestGetTranscodingProgress(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextStudent)), ExpectedCode: http.StatusForbidden, - }}. + }, + }. Method(http.MethodGet). Url("/api/course/40/stream/1969/transcodingProgress"). Run(t, testutils.Equal) diff --git a/api/download.go b/api/download.go index 76fc97201..a42aab79c 100644 --- a/api/download.go +++ b/api/download.go @@ -3,13 +3,14 @@ package api import ( "errors" "fmt" + "net/http" + "os" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/getsentry/sentry-go" "github.com/gin-gonic/gin" - "net/http" - "os" ) func configGinDownloadRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { diff --git a/api/download_ics.go b/api/download_ics.go index 3660f658c..4dfa821a6 100644 --- a/api/download_ics.go +++ b/api/download_ics.go @@ -1,14 +1,15 @@ package api import ( - "github.com/TUM-Dev/gocast/dao" - "github.com/TUM-Dev/gocast/model" - "github.com/TUM-Dev/gocast/tools" - "github.com/gin-gonic/gin" "html/template" "net/http" "strconv" "strings" + + "github.com/TUM-Dev/gocast/dao" + "github.com/TUM-Dev/gocast/model" + "github.com/TUM-Dev/gocast/tools" + "github.com/gin-gonic/gin" ) func configGinDownloadICSRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { @@ -79,7 +80,7 @@ type CalendarEntry struct { func streamToCalendarEntry(s model.Stream, c model.Course) CalendarEntry { layout := "20060102T150405" - var location = "" + location := "" if len(s.RoomName) > 0 { location += s.RoomName + " " } diff --git a/api/download_ics_test.go b/api/download_ics_test.go index aa478a5bd..ce63f322a 100644 --- a/api/download_ics_test.go +++ b/api/download_ics_test.go @@ -4,17 +4,18 @@ import ( "bytes" "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "html/template" + "net/http" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" - "html/template" - "net/http" - "testing" ) func TestDownloadICS(t *testing.T) { @@ -82,7 +83,8 @@ func TestDownloadICS(t *testing.T) { }, ExpectedCode: http.StatusOK, ExpectedResponse: res.Bytes(), - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) diff --git a/api/download_test.go b/api/download_test.go index d613f7588..4d488ab08 100644 --- a/api/download_test.go +++ b/api/download_test.go @@ -3,18 +3,19 @@ package api import ( "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "log" + "net/http" + "os" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" - "log" - "net/http" - "os" - "testing" ) func DownloadRouterWrapper(r *gin.Engine) { @@ -214,7 +215,8 @@ func TestDownload(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: fileContent, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) diff --git a/api/info-pages.go b/api/info-pages.go index 4991e21bf..e4b0acc9a 100644 --- a/api/info-pages.go +++ b/api/info-pages.go @@ -1,12 +1,13 @@ package api import ( - "github.com/gin-gonic/gin" + "net/http" + "strconv" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" - "net/http" - "strconv" + "github.com/gin-gonic/gin" ) func configInfoPageRouter(router *gin.Engine, wrapper dao.DaoWrapper) { diff --git a/api/info-pages_test.go b/api/info-pages_test.go index 29804c4f3..cc1775afc 100644 --- a/api/info-pages_test.go +++ b/api/info-pages_test.go @@ -3,18 +3,19 @@ package api import ( "errors" "fmt" + "html/template" + "net/http" + "testing" + "github.com/Masterminds/sprig/v3" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" - "html/template" - "net/http" - "testing" ) func InfoPagesRouterWrapper(r *gin.Engine) { @@ -102,7 +103,8 @@ func TestInfoPagesCRUD(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: req, ExpectedCode: http.StatusOK, - }}. + }, + }. Router(InfoPagesRouterWrapper). Method(http.MethodPut). Url(url). diff --git a/api/lecture_halls.go b/api/lecture_halls.go index 7c2f40da0..28fb26a85 100644 --- a/api/lecture_halls.go +++ b/api/lecture_halls.go @@ -4,16 +4,17 @@ import ( "embed" "errors" "fmt" - "github.com/TUM-Dev/gocast/dao" - "github.com/TUM-Dev/gocast/model" - "github.com/TUM-Dev/gocast/tools" - "github.com/getsentry/sentry-go" - "github.com/gin-gonic/gin" "net/http" "strconv" "strings" "text/template" "time" + + "github.com/TUM-Dev/gocast/dao" + "github.com/TUM-Dev/gocast/model" + "github.com/TUM-Dev/gocast/tools" + "github.com/getsentry/sentry-go" + "github.com/gin-gonic/gin" ) func configGinLectureHallApiRouter(router *gin.Engine, daoWrapper dao.DaoWrapper, utility tools.PresetUtility) { diff --git a/api/lecture_halls_test.go b/api/lecture_halls_test.go index e259112b9..500f2737a 100644 --- a/api/lecture_halls_test.go +++ b/api/lecture_halls_test.go @@ -4,19 +4,20 @@ import ( "bytes" "errors" "fmt" + "html/template" + "net/http" + "testing" + "time" + campusonline "github.com/RBG-TUM/CAMPUSOnline" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" - "html/template" - "net/http" - "testing" - "time" ) func LectureHallRouterWrapper(t *testing.T) func(r *gin.Engine) { @@ -81,7 +82,8 @@ func TestLectureHallsCRUD(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: body, ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) @@ -172,7 +174,8 @@ func TestLectureHallsCRUD(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, Body: updateLectureHallReq{CamIp: "0.0.0.0"}, - }}. + }, + }. Router(LectureHallRouterWrapper(t)). Method(http.MethodPut). Url(url). @@ -305,7 +308,8 @@ func TestLectureHallsCRUD(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}. + }, + }. Router(LectureHallRouterWrapper(t)). Method(http.MethodDelete). Url(url). @@ -430,7 +434,8 @@ func TestLectureHallsCRUD(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: body, ExpectedCode: http.StatusOK, - }}. + }, + }. Router(LectureHallRouterWrapper(t)). Method(http.MethodPost). Url(url). @@ -467,7 +472,8 @@ func TestCourseImport(t *testing.T) { Url: "/api/course-schedule?range=2022-05-23 to 2022-05-24&department=Ap", Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusBadRequest, - }}. + }, + }. Router(LectureHallRouterWrapper(t)). Method(http.MethodGet). Run(t, testutils.Equal) @@ -480,17 +486,20 @@ func TestCourseImport(t *testing.T) { OptIn bool `json:"optIn"` } testData := []campusonline.Course{ - {Title: "GBS", + { + Title: "GBS", Slug: "GBS", Import: false, Events: []campusonline.Event{{RoomName: "1"}}, }, - {Title: "GDB", + { + Title: "GDB", Slug: "GDB", Import: true, Events: []campusonline.Event{{RoomName: "1"}}, }, - {Title: "FPV", + { + Title: "FPV", Slug: "FPV", Import: true, Events: []campusonline.Event{{RoomName: "1"}}, @@ -500,11 +509,13 @@ func TestCourseImport(t *testing.T) { "POST [no context]": { Url: "/api/course-schedule/2022/S", Middlewares: testutils.GetMiddlewares(tools.ErrorHandler), - ExpectedCode: http.StatusInternalServerError}, + ExpectedCode: http.StatusInternalServerError, + }, "POST [invalid body]": { Url: "/api/course-schedule/2022/S", Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), - ExpectedCode: http.StatusBadRequest}, + ExpectedCode: http.StatusBadRequest, + }, "POST [invalid year]": { Url: "/api/course-schedule/ABC/S", Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), @@ -516,7 +527,8 @@ func TestCourseImport(t *testing.T) { }, OptIn: false, }, - ExpectedCode: http.StatusBadRequest}, + ExpectedCode: http.StatusBadRequest, + }, "POST [invalid term]": { Url: "/api/course-schedule/2022/T", Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), @@ -524,7 +536,8 @@ func TestCourseImport(t *testing.T) { Courses: testData, OptIn: false, }, - ExpectedCode: http.StatusBadRequest}, + ExpectedCode: http.StatusBadRequest, + }, "POST [CreateCourse returns error]": { Router: func(r *gin.Engine) { wrapper := dao.DaoWrapper{ @@ -558,7 +571,8 @@ func TestCourseImport(t *testing.T) { Courses: testData, OptIn: false, }, - ExpectedCode: http.StatusInternalServerError}, + ExpectedCode: http.StatusInternalServerError, + }, "POST [GetLectureHallByPartialName returns error]": { Router: func(r *gin.Engine) { wrapper := dao.DaoWrapper{ @@ -592,7 +606,8 @@ func TestCourseImport(t *testing.T) { Courses: testData, OptIn: false, }, - ExpectedCode: http.StatusOK}, + ExpectedCode: http.StatusOK, + }, "POST [AddAdminToCourse returns error]": { Router: func(r *gin.Engine) { wrapper := dao.DaoWrapper{ @@ -662,7 +677,8 @@ func TestCourseImport(t *testing.T) { OptIn: false, }, ExpectedCode: http.StatusOK, - }}. + }, + }. Router(LectureHallRouterWrapper(t)). Method(http.MethodPost). Run(t, testutils.Equal) @@ -775,7 +791,8 @@ func TestLectureHallIcal(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextStudent)), ExpectedResponse: icalLoggedIn.Bytes(), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) @@ -823,7 +840,8 @@ func TestLectureHallPresets(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) @@ -900,7 +918,8 @@ func TestLectureHallPresets(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusNotFound, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) @@ -978,7 +997,8 @@ func TestLectureHallTakeSnapshot(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: gin.H{"path": fmt.Sprintf("/public/%s", testutils.CameraPreset.Image)}, - }}.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) + }, + }.Method(http.MethodPost).Url(url).Run(t, testutils.Equal) }) } @@ -1138,7 +1158,8 @@ func TestLectureHallSetLH(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: request, ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) diff --git a/api/live_update.go b/api/live_update.go index d728d0750..7b7c756cf 100644 --- a/api/live_update.go +++ b/api/live_update.go @@ -3,6 +3,8 @@ package api import ( "encoding/json" "errors" + "sync" + "github.com/RBG-TUM/commons" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" @@ -11,7 +13,6 @@ import ( "github.com/TUM-Dev/gocast/tools/tum" "github.com/getsentry/sentry-go" "github.com/gin-gonic/gin" - "sync" ) const ( diff --git a/api/notifications.go b/api/notifications.go index aa11b9265..3ca2ff940 100644 --- a/api/notifications.go +++ b/api/notifications.go @@ -1,12 +1,13 @@ package api import ( + "net/http" + "strconv" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/gin-gonic/gin" - "net/http" - "strconv" ) func configNotificationsRouter(r *gin.Engine, daoWrapper dao.DaoWrapper) { diff --git a/api/notifications_test.go b/api/notifications_test.go index 1ad35ec98..26cd5ee7a 100644 --- a/api/notifications_test.go +++ b/api/notifications_test.go @@ -4,16 +4,17 @@ import ( "encoding/json" "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" - "net/http" - "testing" ) func NotificationsRouterWrapper(r *gin.Engine) { @@ -103,7 +104,8 @@ func TestNotifications(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: notifications, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) @@ -186,7 +188,8 @@ func TestNotifications(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: notification, ExpectedCode: http.StatusOK, - }}. + }, + }. Router(NotificationsRouterWrapper). Method(http.MethodPost). Url(url). @@ -241,7 +244,8 @@ func TestNotifications(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: res, - }}. + }, + }. Router(NotificationsRouterWrapper). Method(http.MethodDelete). Url(url). @@ -299,10 +303,10 @@ func TestNotifications(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextLecturer)), ExpectedCode: http.StatusOK, ExpectedResponse: notifications, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) - }) } diff --git a/api/progress.go b/api/progress.go index bcf50ab73..134881744 100644 --- a/api/progress.go +++ b/api/progress.go @@ -2,15 +2,16 @@ package api import ( "errors" - "github.com/TUM-Dev/gocast/dao" - "github.com/TUM-Dev/gocast/model" - "github.com/TUM-Dev/gocast/tools" - "gorm.io/gorm" "net/http" "strconv" "sync" "time" + "github.com/TUM-Dev/gocast/dao" + "github.com/TUM-Dev/gocast/model" + "github.com/TUM-Dev/gocast/tools" + "gorm.io/gorm" + "github.com/gin-gonic/gin" ) @@ -88,7 +89,6 @@ type progressRequest struct { func (r progressRoutes) saveProgress(c *gin.Context) { var request progressRequest err := c.BindJSON(&request) - if err != nil { logger.Warn("Could not bind JSON.", "err", err) _ = c.Error(tools.RequestError{ diff --git a/api/progress_test.go b/api/progress_test.go index ede63b0a8..4ffb31c6a 100644 --- a/api/progress_test.go +++ b/api/progress_test.go @@ -3,22 +3,24 @@ package api import ( "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" "gorm.io/gorm" - "net/http" - "testing" ) func ProgressRouterWrapper(r *gin.Engine) { configProgressRouter(r, dao.DaoWrapper{}) } + func TestProgressReport(t *testing.T) { gin.SetMode(gin.TestMode) @@ -53,7 +55,8 @@ func TestProgressReport(t *testing.T) { Body: req, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextStudent)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) @@ -124,7 +127,8 @@ func TestWatched(t *testing.T) { Body: req, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextStudent)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodPost). Url(url). Run(t, testutils.Equal) @@ -224,10 +228,10 @@ func TestUserProgress(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextStudent)), ExpectedCode: http.StatusOK, ExpectedResponse: []model.StreamProgress{{StreamID: 16, Watched: true, Progress: 0.5}}, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) - }) } diff --git a/api/router.go b/api/router.go index 1b03a7eec..f38b96eb0 100755 --- a/api/router.go +++ b/api/router.go @@ -1,9 +1,9 @@ package api import ( - "github.com/gin-gonic/gin" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/tools" + "github.com/gin-gonic/gin" ) // ConfigChatRouter configure gin router for chat (without gzip) diff --git a/api/search.go b/api/search.go index 791e654f3..ca48e76e8 100644 --- a/api/search.go +++ b/api/search.go @@ -1,10 +1,11 @@ package api import ( - "github.com/gin-gonic/gin" + "net/http" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/tools" - "net/http" + "github.com/gin-gonic/gin" ) func configGinSearchRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { diff --git a/api/seek_stats.go b/api/seek_stats.go index f2e2a5510..294c34b1e 100644 --- a/api/seek_stats.go +++ b/api/seek_stats.go @@ -1,9 +1,10 @@ package api import ( + "net/http" + "github.com/TUM-Dev/gocast/dao" "github.com/gin-gonic/gin" - "net/http" ) // progressRoutes contains a DaoWrapper object and all route functions dangle from it. @@ -47,7 +48,6 @@ const ( // getSeek get seeks for a video func (r seekStatsRoutes) getSeek(c *gin.Context) { chunks, err := r.VideoSeekDao.Get(c.Param("streamID")) - if err != nil { logger.Error("Could not get seek hits", "err", err) c.AbortWithStatus(http.StatusInternalServerError) diff --git a/api/seek_stats_test.go b/api/seek_stats_test.go index dd6b5cfa6..a281f5cd8 100644 --- a/api/seek_stats_test.go +++ b/api/seek_stats_test.go @@ -6,12 +6,12 @@ import ( "net/http" "testing" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" ) @@ -85,7 +85,8 @@ func TestReportSeek(t *testing.T) { }, Body: body, ExpectedCode: http.StatusOK, - }}. + }, + }. Router(ReportSeekRouterWrapper). Method(http.MethodPost). Url(fmt.Sprintf("%s/%d", baseUrl, testutils.StreamFPVNotLive.ID)). @@ -153,7 +154,8 @@ func TestReportSeek(t *testing.T) { }, ExpectedResponse: testResponse, ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodGet). Url(fmt.Sprintf("%s/%d", baseUrl, testutils.StreamFPVNotLive.ID)). Run(t, testutils.Equal) diff --git a/api/semesters.go b/api/semesters.go index 244e50633..9c5e5190a 100644 --- a/api/semesters.go +++ b/api/semesters.go @@ -2,10 +2,11 @@ package api import ( "context" - "github.com/gin-gonic/gin" + "net/http" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/tools/tum" - "net/http" + "github.com/gin-gonic/gin" ) func configSemestersRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { diff --git a/api/statistics.go b/api/statistics.go index af063ab5e..dfc879bad 100644 --- a/api/statistics.go +++ b/api/statistics.go @@ -2,12 +2,13 @@ package api import ( "encoding/json" + "net/http" + "strconv" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/gin-gonic/gin" - "net/http" - "strconv" ) type statReq struct { diff --git a/api/statistics_test.go b/api/statistics_test.go index 238cfb48c..f13643777 100644 --- a/api/statistics_test.go +++ b/api/statistics_test.go @@ -3,17 +3,18 @@ package api import ( "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" "gorm.io/gorm" - "net/http" - "testing" ) func TestStatistics(t *testing.T) { diff --git a/api/stream.go b/api/stream.go index 104d5c38f..9058a25cf 100644 --- a/api/stream.go +++ b/api/stream.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "github.com/TUM-Dev/gocast/tools/pathprovider" "net/http" "os" "path/filepath" @@ -12,6 +11,8 @@ import ( "strings" "time" + "github.com/TUM-Dev/gocast/tools/pathprovider" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" @@ -352,7 +353,8 @@ func (r streamRoutes) getStream(c *gin.Context) { "end": stream.End, "ingest": fmt.Sprintf("%s%s-%d?secret=%s", tools.Cfg.IngestBase, course.Slug, stream.ID, stream.StreamKey), "live": stream.LiveNow, - "vod": stream.Recording}) + "vod": stream.Recording, + }) } func (r streamRoutes) getStreamPlaylist(c *gin.Context) { @@ -536,7 +538,8 @@ func (r streamRoutes) updateVideoSection(c *gin.Context) { Description: update.Description, StartHours: update.StartHours, StartMinutes: update.StartMinutes, - StartSeconds: update.StartSeconds}) + StartSeconds: update.StartSeconds, + }) if err != nil { logger.Error("failed to update video section", "err", err) _ = c.Error(tools.RequestError{ @@ -860,5 +863,4 @@ func (r streamRoutes) updateChatEnabled(c *gin.Context) { c.AbortWithStatusJSON(http.StatusBadRequest, "could not update stream") return } - } diff --git a/api/stream_test.go b/api/stream_test.go index f186e38d2..cf4c6a5d2 100644 --- a/api/stream_test.go +++ b/api/stream_test.go @@ -3,18 +3,19 @@ package api import ( "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "os" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" "gorm.io/gorm" - "net/http" - "os" - "testing" ) func StreamRouterWrapper(r *gin.Engine) { @@ -127,7 +128,8 @@ func TestStream(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler), ExpectedCode: http.StatusOK, ExpectedResponse: response, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) @@ -145,7 +147,8 @@ func TestStream(t *testing.T) { "end": stream.End, "ingest": fmt.Sprintf("%s%s-%d?secret=%s", tools.Cfg.IngestBase, course.Slug, stream.ID, stream.StreamKey), "live": stream.LiveNow, - "vod": stream.Recording} + "vod": stream.Recording, + } url := fmt.Sprintf("/api/stream/%d", testutils.StreamFPVLive.ID) @@ -161,7 +164,8 @@ func TestStream(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, ExpectedResponse: response, - }}. + }, + }. Router(StreamDefaultRouter(t)). Method(http.MethodGet). Url(url). @@ -264,7 +268,8 @@ func TestStream(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: gin.H{"private": false}, ExpectedCode: http.StatusOK, - }}. + }, + }. Router(StreamDefaultRouter(t)). Method(http.MethodPatch). Url(url). @@ -318,7 +323,8 @@ func TestStreamVideoSections(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextStudent)), ExpectedCode: http.StatusOK, ExpectedResponse: testutils.StreamFPVLive.VideoSections, - }}. + }, + }. Method(http.MethodGet). Url(url). Run(t, testutils.Equal) @@ -848,7 +854,8 @@ func TestAttachments(t *testing.T) { Body: "file_url=https://storage.com/test.txt", Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}. + }, + }. Router(StreamRouterWrapper). Method(http.MethodPost). Url(endpoint). @@ -956,7 +963,8 @@ func TestAttachments(t *testing.T) { Before: func() { _, _ = os.Create(testFile.Path) }, - }}. + }, + }. Method(http.MethodDelete). Url(url). Run(t, testutils.Equal) @@ -1034,7 +1042,8 @@ func TestSubtitles(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextEmpty)), ExpectedCode: http.StatusOK, ExpectedResponse: testutils.SubtitlesFPVLive.Content, - }}. + }, + }. Router(StreamDefaultRouter(t)). Method(http.MethodGet). Url(endpoint). diff --git a/api/token.go b/api/token.go index 420ae01a2..60788f074 100644 --- a/api/token.go +++ b/api/token.go @@ -2,13 +2,14 @@ package api import ( "database/sql" + "net/http" + "time" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/gin-gonic/gin" uuid "github.com/satori/go.uuid" - "net/http" - "time" ) func configTokenRouter(r *gin.Engine, daoWrapper dao.DaoWrapper) { diff --git a/api/token_test.go b/api/token_test.go index d69f356fa..01c6bb5f0 100644 --- a/api/token_test.go +++ b/api/token_test.go @@ -2,17 +2,18 @@ package api import ( "errors" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "testing" + "time" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" - "net/http" - "testing" - "time" ) func TokenRouterWrapper(r *gin.Engine) { @@ -71,7 +72,8 @@ func TestToken(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), Body: req{Expires: &now, Scope: model.TokenScopeAdmin}, ExpectedCode: http.StatusOK, - }}. + }, + }. Router(TokenRouterWrapper). Method(http.MethodPost). Url(url). @@ -108,7 +110,8 @@ func TestToken(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodDelete). Url(url). Run(t, testutils.Equal) diff --git a/api/users.go b/api/users.go index aed805dd8..2afc0e454 100644 --- a/api/users.go +++ b/api/users.go @@ -25,6 +25,7 @@ func configGinUsersRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { router.POST("/api/users/settings/name", routes.updatePreferredName) router.POST("/api/users/settings/greeting", routes.updatePreferredGreeting) router.POST("/api/users/settings/playbackSpeeds", routes.updatePlaybackSpeeds) + router.POST("/api/users/settings/seekingTime", routes.updateSeekingTime) router.POST("/api/users/settings/customSpeeds", routes.updateCustomSpeeds) router.POST("/api/users/resetPassword", routes.resetPassword) @@ -89,7 +90,7 @@ func (r usersRoutes) impersonateUser(c *gin.Context) { } func (r usersRoutes) updateUser(c *gin.Context) { - var req = struct { + req := struct { ID uint `json:"id"` Role uint `json:"role"` }{} @@ -278,7 +279,6 @@ func (r usersRoutes) CreateUserForCourse(c *gin.Context) { }) return } - } func (r usersRoutes) addUserBatchToCourse(users string, course model.Course) { @@ -347,7 +347,7 @@ func (r usersRoutes) getPinForCourse(c *gin.Context) { tumLiveContext := c.MustGet("TUMLiveContext").(tools.TUMLiveContext) - var has = false + has := false var err error if tumLiveContext.User != nil { has, err = r.UsersDao.HasPinnedCourse(*tumLiveContext.User, uri.CourseId) @@ -484,7 +484,7 @@ func (r usersRoutes) CreateUser(c *gin.Context) { } func (r usersRoutes) createUserHelper(request createUserRequest, userType uint) (user model.User, err error) { - var u = model.User{ + u := model.User{ Name: request.Name, Email: sql.NullString{String: request.Email, Valid: true}, Role: userType, @@ -499,7 +499,7 @@ func (r usersRoutes) createUserHelper(request createUserRequest, userType uint) if dbErr != nil { return u, errors.New("user could not be created") } - if userType != model.AdminType { //generate password set link and send out email + if userType != model.AdminType { // generate password set link and send out email go r.forgotPassword(request.Email) } return u, nil @@ -585,15 +585,19 @@ func (r usersRoutes) updatePreferredName(c *gin.Context) { } } -func (r usersRoutes) updatePreferredGreeting(c *gin.Context) { +func getUserFromContext(c *gin.Context) *model.User { u := c.MustGet("TUMLiveContext").(tools.TUMLiveContext).User if u == nil { _ = c.Error(tools.RequestError{ Status: http.StatusUnauthorized, CustomMessage: "login required", }) - return + return nil } + return u +} + +func getRequestFromContext(c *gin.Context) *userSettingsRequest { var request userSettingsRequest err := json.NewDecoder(c.Request.Body).Decode(&request) if err != nil { @@ -602,9 +606,16 @@ func (r usersRoutes) updatePreferredGreeting(c *gin.Context) { CustomMessage: "can not bind body", Err: err, }) - return + return nil } - err = r.UsersDao.AddUserSetting(&model.UserSetting{ + return &request +} + +func (r usersRoutes) updatePreferredGreeting(c *gin.Context) { + u := getUserFromContext(c) + request := getRequestFromContext(c) + + err := r.UsersDao.AddUserSetting(&model.UserSetting{ UserID: u.ID, Type: model.Greeting, Value: request.Value, @@ -659,7 +670,7 @@ func (r usersRoutes) updatePlaybackSpeeds(c *gin.Context) { if u == nil { _ = c.Error(tools.RequestError{ Status: http.StatusUnauthorized, - CustomMessage: "login required", + CustomMessage: "login required for updating user settings", }) return } @@ -667,7 +678,7 @@ func (r usersRoutes) updatePlaybackSpeeds(c *gin.Context) { if err := c.BindJSON(&req); err != nil { _ = c.Error(tools.RequestError{ Status: http.StatusBadRequest, - CustomMessage: "can not bind body", + CustomMessage: "can not bind body to request", Err: err, }) return @@ -691,6 +702,27 @@ func (r usersRoutes) updatePlaybackSpeeds(c *gin.Context) { } } +func (r usersRoutes) updateSeekingTime(c *gin.Context) { + u := getUserFromContext(c) + request := getRequestFromContext(c) + + // Add the user's seeking time setting to the database. + err := r.UsersDao.AddUserSetting(&model.UserSetting{ + UserID: u.ID, + Type: model.SeekingTime, + Value: request.Value, + }) + // Handle errors that may occur during the database operation. + if err != nil { + _ = c.Error(tools.RequestError{ + Status: http.StatusInternalServerError, + CustomMessage: "can not add user setting", + Err: err, + }) + return + } +} + func (r usersRoutes) exportPersonalData(c *gin.Context) { var resp personalData u := c.MustGet("TUMLiveContext").(tools.TUMLiveContext).User diff --git a/api/users_test.go b/api/users_test.go index 511536a87..37ace3b5b 100644 --- a/api/users_test.go +++ b/api/users_test.go @@ -4,17 +4,18 @@ import ( "bytes" "database/sql" "errors" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" "gorm.io/gorm" - "net/http" - "testing" ) func UsersRouterWrapper(r *gin.Engine) { @@ -38,15 +39,20 @@ func TestUsersCRUD(t *testing.T) { }, } response := []userSearchDTO{ - {ID: users[0].ID, + { + ID: users[0].ID, LrzID: tools.MaskLogin(users[0].LrzID), Email: gomino.First(tools.MaskEmail(users[0].Email.String)).(string), Name: users[0].Name, - Role: users[0].Role}, - {ID: users[1].ID, + Role: users[0].Role, + }, + { + ID: users[1].ID, LrzID: tools.MaskLogin(users[1].LrzID), Email: gomino.First(tools.MaskEmail(users[1].Email.String)).(string), - Name: users[1].Name, Role: users[1].Role}} + Name: users[1].Name, Role: users[1].Role, + }, + } gomino.TestCases{ "GET[Query to short]": { Router: UsersRouterWrapper, @@ -96,7 +102,8 @@ func TestUsersCRUD(t *testing.T) { userLecturer := model.User{ Name: "Hansi", Email: sql.NullString{String: "hansi@tum.de", Valid: true}, - Role: model.LecturerType} + Role: model.LecturerType, + } request := createUserRequest{ Name: userLecturer.Name, Email: userLecturer.Email.String, @@ -491,7 +498,8 @@ func TestSearchUserForCourse(t *testing.T) { Name: "Hannes", Email: sql.NullString{String: "hannes@tum.de", Valid: true}, Role: model.StudentType, - }} + }, + } response := []userForLecturerDto{ { ID: users[0].ID, @@ -504,7 +512,8 @@ func TestSearchUserForCourse(t *testing.T) { Name: users[1].Name, LastName: users[1].LastName, Login: users[1].GetLoginString(), - }} + }, + } gomino.TestCases{ "GET[success]": { Router: func(r *gin.Engine) { diff --git a/api/voice_service_grpc.go b/api/voice_service_grpc.go index ed195728f..d76345e9c 100644 --- a/api/voice_service_grpc.go +++ b/api/voice_service_grpc.go @@ -5,6 +5,9 @@ package api import ( "context" "fmt" + "net" + "time" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" @@ -14,8 +17,6 @@ import ( "google.golang.org/grpc/keepalive" "google.golang.org/grpc/reflection" "google.golang.org/protobuf/types/known/emptypb" - "net" - "time" ) type subtitleReceiverServer struct { diff --git a/api/worker.go b/api/worker.go index ba2787248..39ec38fd7 100644 --- a/api/worker.go +++ b/api/worker.go @@ -1,10 +1,11 @@ package api import ( + "net/http" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/tools" "github.com/gin-gonic/gin" - "net/http" ) func configWorkerRouter(r *gin.Engine, daoWrapper dao.DaoWrapper) { diff --git a/api/worker_grpc.go b/api/worker_grpc.go index 26eb20267..13c909055 100644 --- a/api/worker_grpc.go +++ b/api/worker_grpc.go @@ -7,7 +7,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/TUM-Dev/gocast/tools/pathprovider" "io" "net" "net/http" @@ -18,6 +17,8 @@ import ( "sync" "time" + "github.com/TUM-Dev/gocast/tools/pathprovider" + go_anel_pwrctrl "github.com/RBG-TUM/go-anel-pwrctrl" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" @@ -115,7 +116,6 @@ func (s server) NotifySilenceResults(ctx context.Context, request *pb.SilenceRes return nil, err } return &pb.Status{Ok: true}, nil - } // SendSelfStreamRequest handles the request from a worker when a stream starts publishing via obs, etc. @@ -679,7 +679,7 @@ func CreateStreamRequest(daoWrapper dao.DaoWrapper, stream model.Stream, course return } var slot model.StreamName - if sourceType == "COMB" { //try to find a transcoding slot for comb view: + if sourceType == "COMB" { // try to find a transcoding slot for comb view: slot, err = daoWrapper.IngestServerDao.GetTranscodedStreamSlot(server.ID) } if sourceType != "COMB" || err != nil { diff --git a/api/worker_test.go b/api/worker_test.go index 1df793a91..2b967e980 100644 --- a/api/worker_test.go +++ b/api/worker_test.go @@ -3,15 +3,16 @@ package api import ( "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/golang/mock/gomock" + "net/http" + "testing" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/testutils" + "github.com/gin-gonic/gin" + "github.com/golang/mock/gomock" "github.com/matthiasreumann/gomino" - "net/http" - "testing" ) func TestWorker(t *testing.T) { @@ -55,7 +56,8 @@ func TestWorker(t *testing.T) { }, Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusOK, - }}. + }, + }. Method(http.MethodDelete). Url(url). Run(t, testutils.Equal) diff --git a/api/wsHub.go b/api/wsHub.go index 0a4265165..3067b1ec4 100644 --- a/api/wsHub.go +++ b/api/wsHub.go @@ -5,15 +5,16 @@ import ( "encoding/json" "errors" "fmt" + "strconv" + "strings" + "sync" + "time" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/tools" "github.com/TUM-Dev/gocast/tools/realtime" "github.com/getsentry/sentry-go" "github.com/gin-gonic/gin" - "strconv" - "strings" - "sync" - "time" ) var wsMapLock sync.RWMutex @@ -86,7 +87,6 @@ func sendServerMessage(msg string, t string, sessions ...*realtime.Context) { logger.Error("can't write server message to session", "err", err) } } - } func BroadcastStats(streamsDao dao.StreamsDao) { diff --git a/cmd/tumlive/tumlive.go b/cmd/tumlive/tumlive.go index 5b326a018..82175b75d 100755 --- a/cmd/tumlive/tumlive.go +++ b/cmd/tumlive/tumlive.go @@ -84,7 +84,7 @@ func GinServer() (err error) { api.ConfigGinRouter(router) web.ConfigGinRouter(router) err = router.Run(":8081") - //err = router.RunTLS(":443", tools.Cfg.Saml.Cert, tools.Cfg.Saml.Privkey) + // err = router.RunTLS(":443", tools.Cfg.Saml.Cert, tools.Cfg.Saml.Privkey) if err != nil { sentry.CaptureException(err) logger.Error("Error starting tumlive", "err", err) @@ -92,9 +92,7 @@ func GinServer() (err error) { return } -var ( - osSignal chan os.Signal -) +var osSignal chan os.Signal func main() { initAll(initializers) @@ -144,7 +142,6 @@ func main() { PrepareStmt: true, Logger: gormJSONLogger, }) - if err != nil { sentry.CaptureException(err) sentry.Flush(time.Second * 5) @@ -240,13 +237,13 @@ func main() { func initCron() { daoWrapper := dao.NewDaoWrapper() tools.InitCronService() - //Fetch students every 12 hours + // Fetch students every 12 hours _ = tools.Cron.AddFunc("fetchCourses", tum.FetchCourses(daoWrapper), "0 */12 * * *") - //Collect livestream stats (viewers) every minute + // Collect livestream stats (viewers) every minute _ = tools.Cron.AddFunc("collectStats", api.CollectStats(daoWrapper), "0-59 * * * *") - //Flush stale sentry exceptions and transactions every 5 minutes + // Flush stale sentry exceptions and transactions every 5 minutes _ = tools.Cron.AddFunc("sentryFlush", func() { sentry.Flush(time.Minute * 2) }, "0-59/5 * * * *") - //Look for due streams and notify workers about them + // Look for due streams and notify workers about them _ = tools.Cron.AddFunc("triggerDueStreams", api.NotifyWorkers(daoWrapper), "0-59 * * * *") // update courses available _ = tools.Cron.AddFunc("prefetchCourses", tum.PrefetchCourses(daoWrapper), "30 3 * * *") diff --git a/dao/chat.go b/dao/chat.go index a8f93e01c..be03526f1 100644 --- a/dao/chat.go +++ b/dao/chat.go @@ -2,8 +2,9 @@ package dao import ( "errors" - "github.com/go-sql-driver/mysql" + "github.com/TUM-Dev/gocast/model" + "github.com/go-sql-driver/mysql" "gorm.io/gorm" ) diff --git a/dao/email.go b/dao/email.go index 64632a743..6aec64c1e 100644 --- a/dao/email.go +++ b/dao/email.go @@ -2,9 +2,10 @@ package dao import ( "context" + "time" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" - "time" ) //go:generate mockgen -source=email.go -destination ../mock_dao/email.go diff --git a/dao/ingest_server.go b/dao/ingest_server.go index a21fdcb27..bfd2ac6b3 100644 --- a/dao/ingest_server.go +++ b/dao/ingest_server.go @@ -1,9 +1,10 @@ package dao import ( + "time" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" - "time" ) //go:generate mockgen -source=ingest_server.go -destination ../mock_dao/ingest_server.go diff --git a/dao/lecture_halls.go b/dao/lecture_halls.go index 9e7e82558..6a54b561d 100644 --- a/dao/lecture_halls.go +++ b/dao/lecture_halls.go @@ -1,10 +1,11 @@ package dao import ( + "time" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" "gorm.io/gorm/clause" - "time" ) //go:generate mockgen -source=lecture_halls.go -destination ../mock_dao/lecture_halls.go diff --git a/dao/migrations/202201280.go b/dao/migrations/202201280.go index 3a76179ac..4f2691912 100644 --- a/dao/migrations/202201280.go +++ b/dao/migrations/202201280.go @@ -1,8 +1,8 @@ package migrations import ( - "github.com/go-gormigrate/gormigrate/v2" "github.com/TUM-Dev/gocast/model" + "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) diff --git a/dao/migrations/202207240.go b/dao/migrations/202207240.go index 33859c108..4ee22f3e4 100644 --- a/dao/migrations/202207240.go +++ b/dao/migrations/202207240.go @@ -1,8 +1,8 @@ package migrations import ( - "github.com/go-gormigrate/gormigrate/v2" "github.com/TUM-Dev/gocast/model" + "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) diff --git a/dao/migrations/202208100.go b/dao/migrations/202208100.go index bfe15e8c5..df553b799 100644 --- a/dao/migrations/202208100.go +++ b/dao/migrations/202208100.go @@ -1,8 +1,8 @@ package migrations import ( - "github.com/go-gormigrate/gormigrate/v2" "github.com/TUM-Dev/gocast/model" + "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) diff --git a/dao/migrations/202208110.go b/dao/migrations/202208110.go index accb92e22..3e4160a30 100644 --- a/dao/migrations/202208110.go +++ b/dao/migrations/202208110.go @@ -1,8 +1,8 @@ package migrations import ( - "github.com/go-gormigrate/gormigrate/v2" "github.com/TUM-Dev/gocast/model" + "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) diff --git a/dao/migrations/202210270.go b/dao/migrations/202210270.go index 9bc60de9c..a4082a270 100644 --- a/dao/migrations/202210270.go +++ b/dao/migrations/202210270.go @@ -1,8 +1,8 @@ package migrations import ( - "github.com/go-gormigrate/gormigrate/v2" "github.com/TUM-Dev/gocast/model" + "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) diff --git a/dao/migrations/202212010.go b/dao/migrations/202212010.go index 93362726c..e533e2c31 100644 --- a/dao/migrations/202212010.go +++ b/dao/migrations/202212010.go @@ -1,8 +1,8 @@ package migrations import ( - "github.com/go-gormigrate/gormigrate/v2" "github.com/TUM-Dev/gocast/model" + "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) diff --git a/dao/migrator.go b/dao/migrator.go index acdc28944..a5b6471ff 100644 --- a/dao/migrator.go +++ b/dao/migrator.go @@ -1,8 +1,8 @@ package dao import ( - "github.com/go-gormigrate/gormigrate/v2" "github.com/TUM-Dev/gocast/dao/migrations" + "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) diff --git a/dao/server-notification.go b/dao/server-notification.go index 6b61e5453..8920c8380 100644 --- a/dao/server-notification.go +++ b/dao/server-notification.go @@ -1,9 +1,10 @@ package dao import ( + "time" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" - "time" ) //go:generate mockgen -source=server-notification.go -destination ../mock_dao/server-notification.go @@ -27,13 +28,13 @@ func NewServerNotificationDao() ServerNotificationDao { return serverNotificationDao{db: DB} } -//CreateServerNotification creates a new ServerNotification +// CreateServerNotification creates a new ServerNotification func (d serverNotificationDao) CreateServerNotification(notification model.ServerNotification) error { err := DB.Create(¬ification).Error return err } -//GetCurrentServerNotifications returns all tumlive notifications that are active +// GetCurrentServerNotifications returns all tumlive notifications that are active func (d serverNotificationDao) GetCurrentServerNotifications() (res []model.ServerNotification, err error) { err = DB.Model(&model.ServerNotification{}). Where("start < ? AND expires > ?", time.Now(), time.Now()). @@ -41,20 +42,20 @@ func (d serverNotificationDao) GetCurrentServerNotifications() (res []model.Serv return res, err } -//GetAllServerNotifications returns all tumlive notifications +// GetAllServerNotifications returns all tumlive notifications func (d serverNotificationDao) GetAllServerNotifications() ([]model.ServerNotification, error) { var res []model.ServerNotification err := DB.Find(&res).Error return res, err } -//UpdateServerNotification updates a notification by its id +// UpdateServerNotification updates a notification by its id func (d serverNotificationDao) UpdateServerNotification(notification model.ServerNotification, id string) error { err := DB.Model(&model.ServerNotification{}).Where("id = ?", id).Updates(notification).Error return err } -//DeleteServerNotification deletes the notification specified by notificationId +// DeleteServerNotification deletes the notification specified by notificationId func (d serverNotificationDao) DeleteServerNotification(notificationId string) error { err := DB.Delete(&model.ServerNotification{}, notificationId).Error return err diff --git a/dao/statistics.go b/dao/statistics.go index 931e0a7ba..4b4399246 100644 --- a/dao/statistics.go +++ b/dao/statistics.go @@ -2,6 +2,7 @@ package dao import ( "fmt" + "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools/timing" "gorm.io/gorm" @@ -125,7 +126,7 @@ func (d statisticsDao) GetStudentActivityCourseStats(courseID uint, live bool) ( JOIN streams s ON s.id = stats.stream_id WHERE (s.course_id = ? OR ? = 0) AND stats.live = ? AND week(stats.time) > 0 GROUP BY year, week - ORDER BY year, week;`, //or ? = 0 -> if courseID is 0, all stats are selected + ORDER BY year, week;`, // or ? = 0 -> if courseID is 0, all stats are selected courseID, courseID, live).Scan(&res).Error var retVal []Stat diff --git a/dao/streams.go b/dao/streams.go index b6da68ba5..fb838b531 100755 --- a/dao/streams.go +++ b/dao/streams.go @@ -3,10 +3,11 @@ package dao import ( "context" "fmt" - "gorm.io/gorm/clause" "strconv" "time" + "gorm.io/gorm/clause" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" ) @@ -321,7 +322,8 @@ func (d streamsDao) UpdateStream(stream model.Stream) error { "description": stream.Description, "start": stream.Start, "end": stream.End, - "chat_enabled": stream.ChatEnabled}).Error + "chat_enabled": stream.ChatEnabled, + }).Error return err } diff --git a/dao/subtitles.go b/dao/subtitles.go index cc04ad91f..61a283280 100644 --- a/dao/subtitles.go +++ b/dao/subtitles.go @@ -3,6 +3,7 @@ package dao import ( "context" "errors" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" ) diff --git a/dao/token.go b/dao/token.go index 213ee13e5..d91fc45b5 100644 --- a/dao/token.go +++ b/dao/token.go @@ -1,9 +1,10 @@ package dao import ( + "time" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" - "time" ) //go:generate mockgen -source=token.go -destination ../mock_dao/token.go diff --git a/dao/transcoding-failure.go b/dao/transcoding-failure.go index 88682c694..45e20b293 100644 --- a/dao/transcoding-failure.go +++ b/dao/transcoding-failure.go @@ -8,13 +8,13 @@ import ( //go:generate mockgen -source=transcoding-failure.go -destination ../mock_dao/transcoding-failure.go type TranscodingFailureDao interface { - //All returns all open transcoding failures + // All returns all open transcoding failures All() ([]model.TranscodingFailure, error) - //New creates a new transcoding failure + // New creates a new transcoding failure New(*model.TranscodingFailure) error - //Delete deletes a transcoding failure + // Delete deletes a transcoding failure Delete(id uint) error } diff --git a/dao/users.go b/dao/users.go index aabbea98b..a8e828727 100644 --- a/dao/users.go +++ b/dao/users.go @@ -4,11 +4,12 @@ import ( "context" "errors" "fmt" + "time" + "github.com/TUM-Dev/gocast/model" uuid "github.com/satori/go.uuid" "gorm.io/gorm" "gorm.io/gorm/clause" - "time" ) //go:generate mockgen -source=users.go -destination ../mock_dao/users.go @@ -102,8 +103,8 @@ func (d usersDao) GetUserByID(ctx context.Context, id uint) (user model.User, er } func (d usersDao) CreateRegisterLink(ctx context.Context, user model.User) (registerLink model.RegisterLink, err error) { - var link = uuid.NewV4().String() - var registerLinkObj = model.RegisterLink{ + link := uuid.NewV4().String() + registerLinkObj := model.RegisterLink{ UserID: user.ID, RegisterSecret: link, } @@ -157,7 +158,7 @@ func (d usersDao) UpsertUser(user *model.User) error { var foundUser *model.User err := DB.Model(&model.User{}).Where("matriculation_number = ?", user.MatriculationNumber).First(&foundUser).Error if err == nil && foundUser != nil { - //User found: update + // User found: update user.Model = foundUser.Model foundUser.LrzID = user.LrzID foundUser.Name = user.Name diff --git a/dao/video-seek.go b/dao/video-seek.go index 165650cc0..9c0ffb412 100644 --- a/dao/video-seek.go +++ b/dao/video-seek.go @@ -2,6 +2,7 @@ package dao import ( "errors" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" "gorm.io/gorm/clause" diff --git a/dao/worker.go b/dao/worker.go index 3c30316e3..3a72fae1f 100644 --- a/dao/worker.go +++ b/dao/worker.go @@ -2,6 +2,7 @@ package dao import ( "context" + "github.com/TUM-Dev/gocast/model" "gorm.io/gorm" ) diff --git a/mock_dao/audit.go b/mock_dao/audit.go index 122c2c0bf..ee55e78f2 100644 --- a/mock_dao/audit.go +++ b/mock_dao/audit.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockAuditDao is a mock of AuditDao interface. diff --git a/mock_dao/bookmark.go b/mock_dao/bookmark.go index 4a77d8138..921c2626b 100644 --- a/mock_dao/bookmark.go +++ b/mock_dao/bookmark.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockBookmarkDao is a mock of BookmarkDao interface. diff --git a/mock_dao/camera-preset.go b/mock_dao/camera-preset.go index c05ffa639..f6dc6a44e 100644 --- a/mock_dao/camera-preset.go +++ b/mock_dao/camera-preset.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockCameraPresetDao is a mock of CameraPresetDao interface. diff --git a/mock_dao/chat.go b/mock_dao/chat.go index dc92f62a5..d6d17ec08 100644 --- a/mock_dao/chat.go +++ b/mock_dao/chat.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockChatDao is a mock of ChatDao interface. diff --git a/mock_dao/courses.go b/mock_dao/courses.go index 7a508b40b..069d1332c 100644 --- a/mock_dao/courses.go +++ b/mock_dao/courses.go @@ -8,9 +8,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" dao "github.com/TUM-Dev/gocast/dao" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockCoursesDao is a mock of CoursesDao interface. diff --git a/mock_dao/email.go b/mock_dao/email.go index e27a77d22..b79db2da6 100644 --- a/mock_dao/email.go +++ b/mock_dao/email.go @@ -8,8 +8,8 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockEmailDao is a mock of EmailDao interface. diff --git a/mock_dao/file.go b/mock_dao/file.go index 90a782392..43011c5de 100644 --- a/mock_dao/file.go +++ b/mock_dao/file.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockFileDao is a mock of FileDao interface. diff --git a/mock_dao/info-page.go b/mock_dao/info-page.go index 3ce7bf621..07944e569 100644 --- a/mock_dao/info-page.go +++ b/mock_dao/info-page.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockInfoPageDao is a mock of InfoPageDao interface. diff --git a/mock_dao/ingest_server.go b/mock_dao/ingest_server.go index 7d38fc8bc..25ed2836b 100644 --- a/mock_dao/ingest_server.go +++ b/mock_dao/ingest_server.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockIngestServerDao is a mock of IngestServerDao interface. diff --git a/mock_dao/lecture_halls.go b/mock_dao/lecture_halls.go index 2cec5abff..3dc06957c 100644 --- a/mock_dao/lecture_halls.go +++ b/mock_dao/lecture_halls.go @@ -7,9 +7,9 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" dao "github.com/TUM-Dev/gocast/dao" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockLectureHallsDao is a mock of LectureHallsDao interface. diff --git a/mock_dao/notifications.go b/mock_dao/notifications.go index b9b94b5f7..e81445492 100644 --- a/mock_dao/notifications.go +++ b/mock_dao/notifications.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockNotificationsDao is a mock of NotificationsDao interface. diff --git a/mock_dao/progress.go b/mock_dao/progress.go index e0a4c7843..26dd5aeae 100644 --- a/mock_dao/progress.go +++ b/mock_dao/progress.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockProgressDao is a mock of ProgressDao interface. diff --git a/mock_dao/server-notification.go b/mock_dao/server-notification.go index c5a8d4131..e1cb3fb0c 100644 --- a/mock_dao/server-notification.go +++ b/mock_dao/server-notification.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockServerNotificationDao is a mock of ServerNotificationDao interface. diff --git a/mock_dao/statistics.go b/mock_dao/statistics.go index 6370ebe3a..349f3d2ea 100644 --- a/mock_dao/statistics.go +++ b/mock_dao/statistics.go @@ -7,9 +7,9 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" dao "github.com/TUM-Dev/gocast/dao" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockStatisticsDao is a mock of StatisticsDao interface. diff --git a/mock_dao/streams.go b/mock_dao/streams.go index f5b32c272..c3d7f3253 100644 --- a/mock_dao/streams.go +++ b/mock_dao/streams.go @@ -9,9 +9,9 @@ import ( reflect "reflect" time "time" - gomock "github.com/golang/mock/gomock" dao "github.com/TUM-Dev/gocast/dao" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockStreamsDao is a mock of StreamsDao interface. diff --git a/mock_dao/subtitles.go b/mock_dao/subtitles.go index f8a0249de..ba086919e 100644 --- a/mock_dao/subtitles.go +++ b/mock_dao/subtitles.go @@ -8,8 +8,8 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockSubtitlesDao is a mock of SubtitlesDao interface. diff --git a/mock_dao/token.go b/mock_dao/token.go index 1a3266432..a25fc1963 100644 --- a/mock_dao/token.go +++ b/mock_dao/token.go @@ -7,9 +7,9 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" dao "github.com/TUM-Dev/gocast/dao" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockTokenDao is a mock of TokenDao interface. diff --git a/mock_dao/transcoding-failure.go b/mock_dao/transcoding-failure.go index c222c7fc8..ea4dd3205 100644 --- a/mock_dao/transcoding-failure.go +++ b/mock_dao/transcoding-failure.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockTranscodingFailureDao is a mock of TranscodingFailureDao interface. diff --git a/mock_dao/upload_key.go b/mock_dao/upload_key.go index c3b92c9e4..915aa8128 100644 --- a/mock_dao/upload_key.go +++ b/mock_dao/upload_key.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockUploadKeyDao is a mock of UploadKeyDao interface. diff --git a/mock_dao/users.go b/mock_dao/users.go index fb97525b3..8f8e8a05a 100644 --- a/mock_dao/users.go +++ b/mock_dao/users.go @@ -8,8 +8,8 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockUsersDao is a mock of UsersDao interface. diff --git a/mock_dao/video-section.go b/mock_dao/video-section.go index 83619ed2d..df80d9d99 100644 --- a/mock_dao/video-section.go +++ b/mock_dao/video-section.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockVideoSectionDao is a mock of VideoSectionDao interface. diff --git a/mock_dao/video-seek.go b/mock_dao/video-seek.go index 47bfba104..a5dc2c318 100644 --- a/mock_dao/video-seek.go +++ b/mock_dao/video-seek.go @@ -7,8 +7,8 @@ package mock_dao import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockVideoSeekDao is a mock of VideoSeekDao interface. diff --git a/mock_dao/worker.go b/mock_dao/worker.go index 1095c0e71..9db0b2eb5 100644 --- a/mock_dao/worker.go +++ b/mock_dao/worker.go @@ -8,8 +8,8 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockWorkerDao is a mock of WorkerDao interface. diff --git a/mock_tools/mock_camera/camera.go b/mock_tools/mock_camera/camera.go index 2e2c42486..2fd5f41f1 100644 --- a/mock_tools/mock_camera/camera.go +++ b/mock_tools/mock_camera/camera.go @@ -7,8 +7,8 @@ package mock_camera import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" + gomock "github.com/golang/mock/gomock" ) // MockCam is a mock of Cam interface. diff --git a/mock_tools/presets.go b/mock_tools/presets.go index 4a2c05abe..0645946f6 100644 --- a/mock_tools/presets.go +++ b/mock_tools/presets.go @@ -8,9 +8,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" model "github.com/TUM-Dev/gocast/model" camera "github.com/TUM-Dev/gocast/tools/camera" + gomock "github.com/golang/mock/gomock" ) // MockPresetUtility is a mock of PresetUtility interface. diff --git a/model/audit.go b/model/audit.go index cc2cd9589..e3e54b563 100644 --- a/model/audit.go +++ b/model/audit.go @@ -37,7 +37,8 @@ func (t AuditType) String() string { } func GetAllAuditTypes() []AuditType { - return []AuditType{AuditInfo, + return []AuditType{ + AuditInfo, AuditWarning, AuditError, AuditCourseCreate, diff --git a/model/course.go b/model/course.go index 65c3524f8..5514d390e 100755 --- a/model/course.go +++ b/model/course.go @@ -3,10 +3,11 @@ package model import ( "encoding/json" "fmt" - "github.com/gin-gonic/gin" - "gorm.io/gorm" "log" "time" + + "github.com/gin-gonic/gin" + "gorm.io/gorm" ) // SourceMode 0 -> COMB, 1-> PRES, 2 -> CAM diff --git a/model/email.go b/model/email.go index 981de2f55..cfd8421aa 100644 --- a/model/email.go +++ b/model/email.go @@ -1,8 +1,9 @@ package model import ( - "gorm.io/gorm" "time" + + "gorm.io/gorm" ) // Email represents an email to be sent. diff --git a/model/file.go b/model/file.go index 46bdb5f61..824b3300c 100644 --- a/model/file.go +++ b/model/file.go @@ -1,9 +1,10 @@ package model import ( - "gorm.io/gorm" "net/url" "strings" + + "gorm.io/gorm" ) type FileType uint diff --git a/model/info-page.go b/model/info-page.go index 4916ec4b5..b5fe0d046 100644 --- a/model/info-page.go +++ b/model/info-page.go @@ -1,10 +1,11 @@ package model import ( + "html/template" + "github.com/microcosm-cc/bluemonday" "github.com/russross/blackfriday/v2" "gorm.io/gorm" - "html/template" ) type InfoPageType uint diff --git a/model/lecture_hall.go b/model/lecture_hall.go index 35193e0f8..383029058 100644 --- a/model/lecture_hall.go +++ b/model/lecture_hall.go @@ -5,8 +5,8 @@ import "gorm.io/gorm" type LectureHall struct { gorm.Model - Name string `gorm:"not null"` //as in smp (e.g. room_00_13_009A) - FullName string `gorm:"not null"` //e.g. '5613.EG.009A (00.13.009A, Seminarraum), Boltzmannstr. 3(5613), 85748 Garching b. München' + Name string `gorm:"not null"` // as in smp (e.g. room_00_13_009A) + FullName string `gorm:"not null"` // e.g. '5613.EG.009A (00.13.009A, Seminarraum), Boltzmannstr. 3(5613), 85748 Garching b. München' CombIP string PresIP string CamIP string diff --git a/model/model-base.go b/model/model-base.go index 515b3a92b..bc85b0159 100644 --- a/model/model-base.go +++ b/model/model-base.go @@ -1,8 +1,9 @@ package model import ( - "gorm.io/gorm" "time" + + "gorm.io/gorm" ) // Model is a base model that can be embedded in other models diff --git a/model/notification.go b/model/notification.go index d42448922..2fe9f6e31 100644 --- a/model/notification.go +++ b/model/notification.go @@ -1,21 +1,22 @@ package model import ( + "html/template" + "github.com/microcosm-cc/bluemonday" "github.com/russross/blackfriday/v2" "gorm.io/gorm" - "html/template" ) // NotificationTarget is a User group the Notification is displayed to type NotificationTarget int const ( - TargetAll = iota + 1 //TargetAll Is any user, regardless if logged in or not - TargetUser //TargetUser Are all users that are logged in - TargetStudent //TargetStudent Are all users that are logged in and are students - TargetLecturer //TargetLecturer Are all users that are logged in and are lecturers - TargetAdmin //TargetAdmin Are all users that are logged in and are admins + TargetAll = iota + 1 // TargetAll Is any user, regardless if logged in or not + TargetUser // TargetUser Are all users that are logged in + TargetStudent // TargetStudent Are all users that are logged in and are students + TargetLecturer // TargetLecturer Are all users that are logged in and are lecturers + TargetAdmin // TargetAdmin Are all users that are logged in and are admins ) diff --git a/model/server-notification.go b/model/server-notification.go index 901871257..074d0ed6c 100644 --- a/model/server-notification.go +++ b/model/server-notification.go @@ -2,9 +2,10 @@ package model import ( "errors" - "gorm.io/gorm" "html/template" "time" + + "gorm.io/gorm" ) // ServerNotification todo: rename to ServerAlert to avoid confusion with Notification diff --git a/model/shortlink.go b/model/shortlink.go index 41ba8af5a..ea41a26b5 100644 --- a/model/shortlink.go +++ b/model/shortlink.go @@ -2,7 +2,7 @@ package model import "gorm.io/gorm" -//ShortLink friendly name for a link to courses highlight page +// ShortLink friendly name for a link to courses highlight page type ShortLink struct { gorm.Model diff --git a/model/stat.go b/model/stat.go index aa8b1ebbc..52070c067 100644 --- a/model/stat.go +++ b/model/stat.go @@ -1,8 +1,9 @@ package model import ( - "gorm.io/gorm" "time" + + "gorm.io/gorm" ) type Stat struct { diff --git a/model/stream-name.go b/model/stream-name.go index 70007301c..b314bb75d 100644 --- a/model/stream-name.go +++ b/model/stream-name.go @@ -1,11 +1,12 @@ package model import ( - "gorm.io/gorm" "time" + + "gorm.io/gorm" ) -//StreamName is essentially a "streaming slot" used for load balancing +// StreamName is essentially a "streaming slot" used for load balancing type StreamName struct { gorm.Model diff --git a/model/stream-unit.go b/model/stream-unit.go index aa4d83bed..ded7391ac 100644 --- a/model/stream-unit.go +++ b/model/stream-unit.go @@ -2,10 +2,11 @@ package model import ( "fmt" + "html/template" + "github.com/microcosm-cc/bluemonday" "github.com/russross/blackfriday/v2" "gorm.io/gorm" - "html/template" ) type StreamUnit struct { diff --git a/model/stream.go b/model/stream.go index 35de2d675..ba717b9ca 100755 --- a/model/stream.go +++ b/model/stream.go @@ -4,14 +4,15 @@ import ( "database/sql" "encoding/json" "fmt" + "strings" + "time" + "github.com/gin-gonic/gin" "github.com/jinzhu/now" "github.com/microcosm-cc/bluemonday" "github.com/russross/blackfriday/v2" log "github.com/sirupsen/logrus" "gorm.io/gorm" - "strings" - "time" ) type Stream struct { @@ -88,7 +89,7 @@ func (s Stream) GetVodFiles() []DownloadableVod { } func (s Stream) GetLGThumbnail() (string, error) { - var thumbs = map[string]string{} + thumbs := map[string]string{} for _, file := range s.Files { if file.Type == FILETYPE_THUMB_LG_CAM_PRES { thumbs["CAM_PRES"] = file.Path diff --git a/model/token.go b/model/token.go index b6ddee555..2ae80c731 100644 --- a/model/token.go +++ b/model/token.go @@ -2,6 +2,7 @@ package model import ( "database/sql" + "gorm.io/gorm" ) diff --git a/model/user.go b/model/user.go index b526b010f..999adc4ab 100755 --- a/model/user.go +++ b/model/user.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "sort" + "strconv" "strings" "time" @@ -55,6 +56,7 @@ const ( PreferredName UserSettingType = iota + 1 Greeting CustomPlaybackSpeeds + SeekingTime UserDefinedSpeeds ) @@ -63,7 +65,7 @@ type UserSetting struct { UserID uint `gorm:"not null"` Type UserSettingType `gorm:"not null"` - Value string `gorm:"not null"` //json encoded setting + Value string `gorm:"not null"` // json encoded setting } // GetPreferredName returns the preferred name of the user if set, otherwise the firstName from TUMOnline @@ -163,6 +165,28 @@ func (u User) GetPreferredGreeting() string { return "Moin" } +// GetSeekingTime returns the seeking time preference for the user. +// If the user is nil, the default seeking time of 15 seconds is returned. +func (u *User) GetSeekingTime() int { + // Check if the user is nil + if u == nil { + return 15 + } + // Check if the setting type is SeekingTime + for _, setting := range u.Settings { + if setting.Type == SeekingTime { + // Attempt to convert the setting value from string to an integer + seekingTime, err := strconv.Atoi(setting.Value) + if err != nil { + break + } + return seekingTime + } + } + // If no seeking time setting is found, return the default seeking time + return 15 +} + // PreferredNameChangeAllowed returns false if the user has set a preferred name within the last 3 months, otherwise true func (u User) PreferredNameChangeAllowed() bool { for _, setting := range u.Settings { @@ -207,7 +231,7 @@ func (u *User) IsEligibleToWatchCourse(course Course) bool { } func (u *User) CoursesForSemester(year int, term string, context context.Context) []Course { - var cMap = make(map[uint]Course) + cMap := make(map[uint]Course) for _, c := range u.Courses { if c.Year == year && c.TeachingTerm == term { cMap[c.ID] = c diff --git a/tools/api-errors.go b/tools/api-errors.go index f0dba43b2..f0c8298a1 100644 --- a/tools/api-errors.go +++ b/tools/api-errors.go @@ -1,8 +1,9 @@ package tools import ( - "github.com/gin-gonic/gin" "net/http" + + "github.com/gin-gonic/gin" ) type RequestError struct { diff --git a/tools/bot/bot.go b/tools/bot/bot.go index 87272a37a..7c23132b0 100644 --- a/tools/bot/bot.go +++ b/tools/bot/bot.go @@ -1,12 +1,13 @@ package bot import ( + "strings" + "time" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/getsentry/sentry-go" "github.com/microcosm-cc/bluemonday" - "strings" - "time" ) // Bot is the bot that will be used to send messages to the chat. diff --git a/tools/bot/matrix.go b/tools/bot/matrix.go index f1e81f7ed..01e294ed9 100644 --- a/tools/bot/matrix.go +++ b/tools/bot/matrix.go @@ -5,17 +5,17 @@ import ( "encoding/json" "errors" "fmt" - "github.com/TUM-Dev/gocast/tools" - "github.com/getsentry/sentry-go" "io" "math/rand" "net/http" "strconv" + + "github.com/TUM-Dev/gocast/tools" + "github.com/getsentry/sentry-go" ) // Matrix strategy -type Matrix struct { -} +type Matrix struct{} // matrixMessage represents a Matrix message event that includes html formatting as specified // in https://spec.matrix.org/v1.2/client-server-api/#mroommessage-msgtypes @@ -97,7 +97,7 @@ func (m *Matrix) sendMessageToRoom(roomID string, message Message) error { return errors.New("authentication failed, could not get token") } - var roomMessageSuffix = roomMsgPrefix + id + accessTokenSuffix + roomMessageSuffix := roomMsgPrefix + id + accessTokenSuffix url := m.getClientUrl() + roomSuffix + roomID + roomMessageSuffix + authToken matrixMessage := matrixMessage{ MsgType: msgType, diff --git a/tools/branding.go b/tools/branding.go index 5abd222c9..60d07ee70 100644 --- a/tools/branding.go +++ b/tools/branding.go @@ -2,6 +2,7 @@ package tools import ( "fmt" + "github.com/spf13/viper" ) diff --git a/tools/cache.go b/tools/cache.go index 12a12f1e9..942755834 100644 --- a/tools/cache.go +++ b/tools/cache.go @@ -1,8 +1,9 @@ package tools import ( - "github.com/dgraph-io/ristretto" "time" + + "github.com/dgraph-io/ristretto" ) var cache *ristretto.Cache diff --git a/tools/camera/axis.go b/tools/camera/axis.go index 8e887ec5b..5d5e738f7 100644 --- a/tools/camera/axis.go +++ b/tools/camera/axis.go @@ -3,13 +3,14 @@ package camera import ( "errors" "fmt" - "github.com/TUM-Dev/gocast/model" - uuid "github.com/satori/go.uuid" "strconv" "strings" + + "github.com/TUM-Dev/gocast/model" + uuid "github.com/satori/go.uuid" ) -//AxisCam represents AXIS IP cameras the TUM uses +// AxisCam represents AXIS IP cameras the TUM uses type AxisCam struct { Ip string Auth string @@ -17,9 +18,9 @@ type AxisCam struct { const axisBaseURL = "http://%s" -//NewAxisCam Acts as a constructor for cameras. -//ip: the ip address of the camera -//auth: username and password of the camera (e.g. "user:password") +// NewAxisCam Acts as a constructor for cameras. +// ip: the ip address of the camera +// auth: username and password of the camera (e.g. "user:password") func NewAxisCam(ip string, auth string) Cam { return &AxisCam{Ip: ip, Auth: auth} } @@ -35,7 +36,7 @@ func (c *AxisCam) TakeSnapshot(outDir string) (filename string, err error) { return filename, err } -//SetPreset tells the camera to use a preset specified by presetId +// SetPreset tells the camera to use a preset specified by presetId func (c AxisCam) SetPreset(presetId int) error { _, err := makeAuthenticatedRequest(&c.Auth, "GET", "", fmt.Sprintf("%s/axis-cgi/com/ptz.cgi?gotoserverpresetno=%d&camera=1", fmt.Sprintf(axisBaseURL, c.Ip), presetId)) if err != nil { @@ -44,7 +45,7 @@ func (c AxisCam) SetPreset(presetId int) error { return nil } -//GetPresets fetches all presets stored on the camera +// GetPresets fetches all presets stored on the camera func (c AxisCam) GetPresets() ([]model.CameraPreset, error) { var presetsForLectureHall []model.CameraPreset resp, err := makeAuthenticatedRequest(&c.Auth, "POST", "action=list&group=root.PTZ.Preset.P0.Position.*.Name", fmt.Sprintf("%s/axis-cgi/param.cgi", fmt.Sprintf(axisBaseURL, c.Ip))) diff --git a/tools/camera/camera.go b/tools/camera/camera.go index 27d2554fa..4a5046dde 100644 --- a/tools/camera/camera.go +++ b/tools/camera/camera.go @@ -3,12 +3,13 @@ package camera import ( "bytes" "fmt" - "github.com/icholy/digest" - "github.com/TUM-Dev/gocast/model" "io" "net/http" "os" "strings" + + "github.com/TUM-Dev/gocast/model" + "github.com/icholy/digest" ) //go:generate mockgen -source=camera.go -destination ../../mock_tools/mock_camera/camera.go @@ -22,9 +23,9 @@ type Cam interface { GetPresets() ([]model.CameraPreset, error) } -//makeAuthenticatedRequest Sends a request to the camera. -//Example usage: c.makeAuthenticatedRequest("GET", "/base","/some.cgi?preset=1") -//Returns the response body as a buffer. +// makeAuthenticatedRequest Sends a request to the camera. +// Example usage: c.makeAuthenticatedRequest("GET", "/base","/some.cgi?preset=1") +// Returns the response body as a buffer. func makeAuthenticatedRequest(auth *string, method string, body string, url string) (*bytes.Buffer, error) { // var camCurl *exec.Cmd client := http.DefaultClient diff --git a/tools/camera/panasonic.go b/tools/camera/panasonic.go index 27c0ab10a..d043bd4b1 100644 --- a/tools/camera/panasonic.go +++ b/tools/camera/panasonic.go @@ -2,6 +2,7 @@ package camera import ( "fmt" + "github.com/TUM-Dev/gocast/model" uuid "github.com/satori/go.uuid" ) diff --git a/tools/config.go b/tools/config.go index 145fd3cad..8d2190007 100644 --- a/tools/config.go +++ b/tools/config.go @@ -7,11 +7,12 @@ import ( "encoding/pem" "errors" "fmt" + "os" + "time" + "github.com/meilisearch/meilisearch-go" uuid "github.com/satori/go.uuid" "github.com/spf13/viper" - "os" - "time" ) var Cfg Config diff --git a/tools/email.go b/tools/email.go index 270f959f1..e0f7a7210 100644 --- a/tools/email.go +++ b/tools/email.go @@ -4,11 +4,12 @@ import ( "bytes" "context" "fmt" - "github.com/TUM-Dev/gocast/dao" "net/smtp" "os/exec" "strings" "time" + + "github.com/TUM-Dev/gocast/dao" ) type Mailer struct { diff --git a/tools/functions.go b/tools/functions.go index 6053e14ae..6cfea0431 100644 --- a/tools/functions.go +++ b/tools/functions.go @@ -2,11 +2,12 @@ package tools import ( "errors" - "github.com/TUM-Dev/gocast/model" "log" "os/exec" "regexp" "strings" + + "github.com/TUM-Dev/gocast/model" ) // CourseListContains checks whether courses contain a course with a given courseId diff --git a/tools/meiliExporter.go b/tools/meiliExporter.go index d72da9833..b3906fd93 100644 --- a/tools/meiliExporter.go +++ b/tools/meiliExporter.go @@ -3,10 +3,11 @@ package tools import ( "errors" "fmt" + "strings" + "github.com/TUM-Dev/gocast/dao" "github.com/asticode/go-astisub" "github.com/meilisearch/meilisearch-go" - "strings" ) type MeiliStream struct { @@ -77,7 +78,7 @@ func (m *MeiliExporter) Export() { logger.Warn("could not parse subtitles", "err", err) continue } - for i, _ := range vtt.Items { + for i := range vtt.Items { sub := MeiliSubtitles{ ID: fmt.Sprintf("%d-%d", stream.ID, vtt.Items[i].StartAt.Milliseconds()), StreamID: stream.ID, @@ -104,7 +105,6 @@ func (m *MeiliExporter) Export() { if err != nil { logger.Error("issue adding documents to meili", "err", err) } - }) } diff --git a/tools/meiliSearch.go b/tools/meiliSearch.go index 4770dfae1..ae86717b3 100644 --- a/tools/meiliSearch.go +++ b/tools/meiliSearch.go @@ -2,6 +2,7 @@ package tools import ( "fmt" + "github.com/meilisearch/meilisearch-go" ) diff --git a/tools/middlewares.go b/tools/middlewares.go index dee069940..a1de2c36b 100644 --- a/tools/middlewares.go +++ b/tools/middlewares.go @@ -2,16 +2,17 @@ package tools import ( "errors" + "net/http" + "net/url" + "strconv" + "strings" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools/realtime" "github.com/getsentry/sentry-go" "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt/v4" - "net/http" - "net/url" - "strconv" - "strings" ) var templateExecutor TemplateExecutor diff --git a/tools/pathprovider/pathprovider.go b/tools/pathprovider/pathprovider.go index 48a917d90..39e75e065 100644 --- a/tools/pathprovider/pathprovider.go +++ b/tools/pathprovider/pathprovider.go @@ -6,9 +6,7 @@ import ( "path/filepath" ) -var ( - TUMLiveTemporary = filepath.Join(os.TempDir(), "TUM-Live") -) +var TUMLiveTemporary = filepath.Join(os.TempDir(), "TUM-Live") func LiveThumbnail(streamID string) string { return filepath.Join(TUMLiveTemporary, fmt.Sprintf("%s.jpeg", streamID)) diff --git a/tools/presets.go b/tools/presets.go index b0d3f8647..d3f364730 100644 --- a/tools/presets.go +++ b/tools/presets.go @@ -3,11 +3,12 @@ package tools import ( "context" "errors" + "time" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools/camera" "github.com/getsentry/sentry-go" - "time" ) //go:generate mockgen -source=presets.go -destination ../mock_tools/presets.go diff --git a/tools/realtime/channel.go b/tools/realtime/channel.go index 8a3b9e7f9..e0c26d21b 100644 --- a/tools/realtime/channel.go +++ b/tools/realtime/channel.go @@ -2,8 +2,9 @@ package realtime import ( "errors" - "github.com/getsentry/sentry-go" "strings" + + "github.com/getsentry/sentry-go" ) // channelPathSep describes the separator of paths in a channel name. e.g 'stream/123' is seperated by channelPathSep diff --git a/tools/realtime/client-store.go b/tools/realtime/client-store.go index a081743b8..86c9acdf0 100644 --- a/tools/realtime/client-store.go +++ b/tools/realtime/client-store.go @@ -1,8 +1,9 @@ package realtime import ( - "github.com/google/uuid" "sync" + + "github.com/google/uuid" ) type ClientStore struct { @@ -15,7 +16,7 @@ func (c *ClientStore) init() { } func (c *ClientStore) NextId() string { - var uuidGen, _ = uuid.NewUUID() + uuidGen, _ := uuid.NewUUID() uuidString := uuidGen.String() if _, ok := c.clients[uuidString]; ok { return c.NextId() diff --git a/tools/realtime/connector.go b/tools/realtime/connector.go index f9a47e222..330601f0b 100644 --- a/tools/realtime/connector.go +++ b/tools/realtime/connector.go @@ -4,10 +4,12 @@ import ( "net/http" ) -type ConnectHookFunc func(*Client) -type DisconnectHookFunc func(*Client) -type MessageHookFunc func(*Client, []byte) -type RequestHandlerFunc func(writer http.ResponseWriter, request *http.Request, properties map[string]interface{}) error +type ( + ConnectHookFunc func(*Client) + DisconnectHookFunc func(*Client) + MessageHookFunc func(*Client, []byte) + RequestHandlerFunc func(writer http.ResponseWriter, request *http.Request, properties map[string]interface{}) error +) type Connector struct { requestHandler RequestHandlerFunc diff --git a/tools/realtime/connector/melody.go b/tools/realtime/connector/melody.go index 83573d087..d16b4c106 100644 --- a/tools/realtime/connector/melody.go +++ b/tools/realtime/connector/melody.go @@ -1,9 +1,10 @@ package connector import ( - "github.com/gabstv/melody" - "github.com/TUM-Dev/gocast/tools/realtime" "net/http" + + "github.com/TUM-Dev/gocast/tools/realtime" + "github.com/gabstv/melody" ) func NewMelodyConnector() *realtime.Connector { diff --git a/tools/realtime/realtime_test.go b/tools/realtime/realtime_test.go index 2e02199db..2fb527bc8 100644 --- a/tools/realtime/realtime_test.go +++ b/tools/realtime/realtime_test.go @@ -5,10 +5,12 @@ import ( "testing" ) -type FakeSocketHandleConnectFunc func(session *FakeSocketSession) -type FakeSocketHandleDisconnectFunc func(session *FakeSocketSession) -type FakeSocketHandleMessageFunc func(session *FakeSocketSession, msg []byte) -type FakeSocketHandleOutgoingMessageFunc func(msg []byte) +type ( + FakeSocketHandleConnectFunc func(session *FakeSocketSession) + FakeSocketHandleDisconnectFunc func(session *FakeSocketSession) + FakeSocketHandleMessageFunc func(session *FakeSocketSession, msg []byte) + FakeSocketHandleOutgoingMessageFunc func(msg []byte) +) type FakeSocket struct { handleConnect FakeSocketHandleConnectFunc @@ -35,7 +37,7 @@ type FakeSocketSession struct { onOutgoingMessage FakeSocketHandleOutgoingMessageFunc } -/// Send emulate a data message from the frontend +// / Send emulate a data message from the frontend func (s *FakeSocketSession) Send(data []byte) { s.onMessage(s, data) } @@ -118,7 +120,6 @@ func UnsubMessage(path string) []byte { } func TestRealtimeConnection(t *testing.T) { - t.Run("Simple Connect Disconnect", func(t *testing.T) { fakeConnector, fakeSocket := NewFakeConnector() @@ -139,7 +140,6 @@ func TestRealtimeConnection(t *testing.T) { t.Errorf("len(fakeConnector.clients.clients) = %d, want %d", len(fakeConnector.clients.clients), 0) return } - }) t.Run("IsConnected should return connection status", func(t *testing.T) { @@ -216,13 +216,10 @@ func TestRealtimeConnection(t *testing.T) { t.Errorf("unsubContext = nil, want *Context") return } - }) - } func TestRealtimeMessaging(t *testing.T) { - t.Run("Client Sends Message", func(t *testing.T) { testChannelPath := "example/path/foobar" testPayload := map[string]interface{}{"name": "Jon Doe", "admin": false} @@ -276,7 +273,6 @@ func TestRealtimeMessaging(t *testing.T) { }) fakeClient := fakeSocket.NewClientConnects(func(msg []byte) { - }) fakeClient.Send(SubMessage(channelA)) fakeClient.Send(SubMessage(channelB)) @@ -331,5 +327,4 @@ func TestRealtimeMessaging(t *testing.T) { return } }) - } diff --git a/tools/realtime/subscribers.go b/tools/realtime/subscribers.go index e5792b11c..ecdf477eb 100644 --- a/tools/realtime/subscribers.go +++ b/tools/realtime/subscribers.go @@ -18,14 +18,14 @@ func (subs *ChannelSubscribers) init() { func (subs *ChannelSubscribers) IsSubscribed(clientId string, path string) bool { subs.mutex.Lock() defer subs.mutex.Unlock() - var _, exists = subs.subscribers[createKey(clientId, path)] + _, exists := subs.subscribers[createKey(clientId, path)] return exists } func (subs *ChannelSubscribers) GetContext(clientId string, path string) (*Context, bool) { subs.mutex.Lock() defer subs.mutex.Unlock() - var context, exists = subs.subscribers[createKey(clientId, path)] + context, exists := subs.subscribers[createKey(clientId, path)] return context, exists } diff --git a/tools/session.go b/tools/session.go index 2d8112010..41f485ca7 100644 --- a/tools/session.go +++ b/tools/session.go @@ -1,9 +1,10 @@ package tools import ( + "time" + "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt/v4" - "time" ) type SessionData struct { diff --git a/tools/stats_export.dart.go b/tools/stats_export.dart.go index 73ec0a911..5bc85672c 100644 --- a/tools/stats_export.dart.go +++ b/tools/stats_export.dart.go @@ -1,10 +1,11 @@ package tools import ( - "github.com/gin-gonic/gin" - "github.com/TUM-Dev/gocast/dao" "strconv" "strings" + + "github.com/TUM-Dev/gocast/dao" + "github.com/gin-gonic/gin" ) type ExportDataEntry struct { @@ -18,8 +19,10 @@ type ExportStatsContainer struct { data []*ExportDataEntry } -const CSVSep = "," -const CSVLb = "\n\r" +const ( + CSVSep = "," + CSVLb = "\n\r" +) func csvCell(val string) string { val = strings.ReplaceAll(val, "\"", "\"\"") diff --git a/tools/stream-signing.go b/tools/stream-signing.go index 60ff1af01..aaec473f7 100644 --- a/tools/stream-signing.go +++ b/tools/stream-signing.go @@ -2,10 +2,11 @@ package tools import ( "fmt" - "github.com/golang-jwt/jwt/v4" - "github.com/TUM-Dev/gocast/model" "strings" "time" + + "github.com/TUM-Dev/gocast/model" + "github.com/golang-jwt/jwt/v4" ) type JWTPlaylistClaims struct { diff --git a/tools/template_executor.go b/tools/template_executor.go index cfc62c5f4..1696fef7c 100644 --- a/tools/template_executor.go +++ b/tools/template_executor.go @@ -1,9 +1,10 @@ package tools import ( - "github.com/Masterminds/sprig/v3" "html/template" "io" + + "github.com/Masterminds/sprig/v3" ) type TemplateExecutor interface { @@ -19,7 +20,7 @@ func (e DebugTemplateExecutor) ExecuteTemplate(w io.Writer, name string, data in panic("Provide at least one pattern for the debug template executor.") } - var t, err = template.New("base").Funcs(sprig.FuncMap()).ParseGlob(e.Patterns[0]) + t, err := template.New("base").Funcs(sprig.FuncMap()).ParseGlob(e.Patterns[0]) if err != nil { logger.Error("Failed to load pattern: '"+e.Patterns[0], "err", err.Error()) } diff --git a/tools/testutils/testdata.go b/tools/testutils/testdata.go index fed7833b3..6fc92b2cd 100644 --- a/tools/testutils/testdata.go +++ b/tools/testutils/testdata.go @@ -2,17 +2,18 @@ package testutils import ( "fmt" - "github.com/gin-gonic/gin" "math" "testing" "time" - "github.com/golang/mock/gomock" + "github.com/gin-gonic/gin" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/mock_dao" "github.com/TUM-Dev/gocast/mock_tools" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" + "github.com/golang/mock/gomock" "gorm.io/gorm" ) diff --git a/tools/testutils/testutils.go b/tools/testutils/testutils.go index 296149332..22f3bd9cc 100644 --- a/tools/testutils/testutils.go +++ b/tools/testutils/testutils.go @@ -1,10 +1,11 @@ package testutils import ( - "github.com/gin-gonic/gin" + "testing" + "github.com/TUM-Dev/gocast/tools" + "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" - "testing" ) func Equal(t *testing.T, a, b interface{}) { diff --git a/tools/timing/time.go b/tools/timing/time.go index a1c468c03..6b4092264 100644 --- a/tools/timing/time.go +++ b/tools/timing/time.go @@ -2,8 +2,9 @@ package timing import ( - "github.com/jinzhu/now" "time" + + "github.com/jinzhu/now" ) // GetWeeksInYear returns the number of weeks in the given year diff --git a/tools/truncate.go b/tools/truncate.go index 41808d34b..46d14ea7b 100644 --- a/tools/truncate.go +++ b/tools/truncate.go @@ -8,9 +8,11 @@ import ( "unicode/utf8" ) -var ErrUnbalancedTags = errors.New("unbalanced tags") -var TagExpr = regexp.MustCompile("<(/?)([A-Za-z0-9]+).*?>") -var EntityExpr = regexp.MustCompile("&#?[A-Za-z0-9]+;") +var ( + ErrUnbalancedTags = errors.New("unbalanced tags") + TagExpr = regexp.MustCompile("<(/?)([A-Za-z0-9]+).*?>") + EntityExpr = regexp.MustCompile("&#?[A-Za-z0-9]+;") +) // TruncateHtml will truncate a given byte slice to a maximum of maxlen visible // characters and optionally append ellipsis. HTML tags are automatically closed @@ -30,9 +32,11 @@ func TruncateHtml(buf []byte, maxlen int, ellipsis string) ([]byte, error) { // of void elements and may appear simply as . Hence, if one of the // following is picked up by the tag expression as a start tag, do not add // it to the stack of tags that should be closed. - voidElementTags := []string{"area", "base", "br", "col", "embed", "hr", + voidElementTags := []string{ + "area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", - "param", "source", "track", "wbr"} + "param", "source", "track", "wbr", + } // Check to see if no input was provided. if len(buf) == 0 || maxlen == 0 { diff --git a/tools/tum/campus-online-base.go b/tools/tum/campus-online-base.go index 7cb8c63b4..0614ce875 100644 --- a/tools/tum/campus-online-base.go +++ b/tools/tum/campus-online-base.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/tools" "github.com/antchfx/xmlquery" @@ -14,7 +15,7 @@ func GetCourseInformation(courseID string, token string) (CourseInfo, error) { if err != nil { return CourseInfo{}, fmt.Errorf("GetCourseInformation: Can't LoadURL: %v", err) } - var isError = len(xmlquery.Find(doc, "//Error")) != 0 + isError := len(xmlquery.Find(doc, "//Error")) != 0 if isError { return CourseInfo{}, errors.New("course not found") } @@ -37,7 +38,7 @@ func FetchCourses(daoWrapper dao.DaoWrapper) func() { return } FindStudentsForCourses(courses, daoWrapper.UsersDao) - //GetEventsForCourses(courses) + // GetEventsForCourses(courses) } } diff --git a/tools/tum/courses.go b/tools/tum/courses.go index 93ecc870b..16b692b94 100644 --- a/tools/tum/courses.go +++ b/tools/tum/courses.go @@ -3,12 +3,13 @@ package tum import ( "context" "fmt" + "strconv" + "strings" + "github.com/TUM-Dev/CampusProxy/client" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model/search" "github.com/TUM-Dev/gocast/tools" - "strconv" - "strings" ) // PrefetchCourses loads all courses from tumonline, so we can use them in the course creation from search diff --git a/tools/tum/events.go b/tools/tum/events.go index e61eaab2b..4113a2bc9 100644 --- a/tools/tum/events.go +++ b/tools/tum/events.go @@ -4,14 +4,15 @@ import ( "context" "errors" "fmt" + "strconv" + "strings" + "time" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" "github.com/antchfx/xmlquery" uuid "github.com/satori/go.uuid" - "strconv" - "strings" - "time" ) func getEventsForCourse(courseID string, token string) (events map[time.Time]Event, deleted []Event, err error) { diff --git a/tools/tum/ldap.go b/tools/tum/ldap.go index 809d6a0f9..907cb2e67 100644 --- a/tools/tum/ldap.go +++ b/tools/tum/ldap.go @@ -4,11 +4,12 @@ import ( "database/sql" "errors" "fmt" - "github.com/getsentry/sentry-go" - "github.com/go-ldap/ldap/v3" + "time" + "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" - "time" + "github.com/getsentry/sentry-go" + "github.com/go-ldap/ldap/v3" ) var ErrLdapBadAuth = errors.New("login failed") @@ -20,7 +21,7 @@ type LdapResp struct { LastName *string } -//LoginWithTumCredentials returns student id if login and password match, err otherwise +// LoginWithTumCredentials returns student id if login and password match, err otherwise func LoginWithTumCredentials(username string, password string) (*LdapResp, error) { // sanitize possibly malicious username username = ldap.EscapeFilter(username) @@ -92,7 +93,6 @@ func LoginWithTumCredentials(username string, password string) (*LdapResp, error FirstName: name, LastName: lastName, }, nil - } func FindUserWithEmail(email string) (*model.User, error) { diff --git a/tools/tum/students.go b/tools/tum/students.go index f8def6ff8..98569235b 100644 --- a/tools/tum/students.go +++ b/tools/tum/students.go @@ -3,6 +3,7 @@ package tum import ( "errors" "fmt" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" diff --git a/web/admin.go b/web/admin.go index 63e9fc1dc..775ec19dd 100755 --- a/web/admin.go +++ b/web/admin.go @@ -5,6 +5,9 @@ import ( "encoding/json" "errors" "fmt" + "net/http" + "regexp" + "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" "github.com/TUM-Dev/gocast/tools" @@ -12,8 +15,6 @@ import ( "github.com/getsentry/sentry-go" "github.com/gin-gonic/gin" "gorm.io/gorm" - "net/http" - "regexp" ) // AdminPage serves all administration pages. todo: refactor into multiple methods @@ -121,7 +122,8 @@ func (r mainRoutes) AdminPage(c *gin.Context) { semesters := r.CoursesDao.GetAvailableSemesters(c) y, t := tum.GetCurrentSemester() err = templateExecutor.ExecuteTemplate(c.Writer, "admin.gohtml", - AdminPageData{Users: users, + AdminPageData{ + Users: users, Courses: courses, IndexData: indexData, LectureHalls: lectureHalls, diff --git a/web/course.go b/web/course.go index f9fde23ec..dea090411 100644 --- a/web/course.go +++ b/web/course.go @@ -182,7 +182,7 @@ func (r mainRoutes) CoursePage(c *gin.Context) { Recording bool `json:"recording"` } - var clientWatchState = make([]watchedStateData, 0) + clientWatchState := make([]watchedStateData, 0) for _, s := range streamsWithWatchState { clientWatchState = append(clientWatchState, watchedStateData{ ID: s.Model.ID, diff --git a/web/index.go b/web/index.go index 8179ae34a..f915ceac1 100644 --- a/web/index.go +++ b/web/index.go @@ -3,6 +3,11 @@ package web import ( "context" "errors" + "html/template" + "net/http" + "sort" + "strconv" + "github.com/RBG-TUM/commons" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/model" @@ -11,10 +16,6 @@ import ( "github.com/getsentry/sentry-go" "github.com/gin-gonic/gin" "gorm.io/gorm" - "html/template" - "net/http" - "sort" - "strconv" ) var VersionTag string @@ -228,8 +229,7 @@ func (d *IndexData) LoadCoursesForRole(c *gin.Context, spanMain *sentry.Span, co case model.LecturerType: { courses = d.TUMLiveContext.User.CoursesForSemester(d.CurrentYear, d.CurrentTerm, spanMain.Context()) - coursesForLecturer, err := - coursesDao.GetCourseForLecturerIdByYearAndTerm(c, d.CurrentYear, d.CurrentTerm, d.TUMLiveContext.User.ID) + coursesForLecturer, err := coursesDao.GetCourseForLecturerIdByYearAndTerm(c, d.CurrentYear, d.CurrentTerm, d.TUMLiveContext.User.ID) if err == nil { courses = append(courses, coursesForLecturer...) } diff --git a/web/popup.go b/web/popup.go index f39f6eb0a..d2b081287 100644 --- a/web/popup.go +++ b/web/popup.go @@ -2,10 +2,11 @@ package web import ( "errors" + "net/http" + "github.com/TUM-Dev/gocast/tools" "github.com/getsentry/sentry-go" "github.com/gin-gonic/gin" - "net/http" ) func (r mainRoutes) PopOutChat(c *gin.Context) { diff --git a/web/router.go b/web/router.go index 89a6943e8..d2881aa78 100755 --- a/web/router.go +++ b/web/router.go @@ -3,12 +3,13 @@ package web import ( "embed" "fmt" - "github.com/getsentry/sentry-go" "html/template" "net/http" "os" "path" + "github.com/getsentry/sentry-go" + "github.com/Masterminds/sprig/v3" "github.com/TUM-Dev/gocast/dao" "github.com/TUM-Dev/gocast/tools" diff --git a/web/template/user-settings.gohtml b/web/template/user-settings.gohtml index 7a2de0242..b24214b21 100644 --- a/web/template/user-settings.gohtml +++ b/web/template/user-settings.gohtml @@ -118,6 +118,27 @@ +
+

Seeking Time in Seconds

+
+ + + + + + + + +
+

Privacy & Data Protection