Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions api/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func checkAndFillResponse(c *gin.Context, user *model.User, limit int64, daoWrap
switch res.IndexUID {
case "STREAMS":
hits := res.Hits
res.Hits = []any{}
res.Hits = []meilisearch.Hit{}
response.Results[i] = meilisearch.SearchResponse{}

var meiliStreams []SearchStreamDTO
Expand All @@ -237,7 +237,10 @@ func checkAndFillResponse(c *gin.Context, user *model.User, limit int64, daoWrap

meiliStream.CourseSlug = course.Slug
if userEligibleToSeeResultsOfHiddenCourse(course) && (!stream.Private || user.IsAdminOfCourse(course)) {
res.Hits = append(res.Hits, meiliStream)
hit, err := dtoToHit(meiliStream)
if err == nil {
res.Hits = append(res.Hits, hit)
}
}

if len(res.Hits) >= int(limit) {
Expand All @@ -247,7 +250,7 @@ func checkAndFillResponse(c *gin.Context, user *model.User, limit int64, daoWrap
response.Results[i] = res
case "COURSES":
hits := res.Hits
res.Hits = []any{}
res.Hits = []meilisearch.Hit{}
response.Results[i] = meilisearch.SearchResponse{}

var meiliCourses []SearchCourseDTO
Expand All @@ -265,7 +268,10 @@ func checkAndFillResponse(c *gin.Context, user *model.User, limit int64, daoWrap
for _, meiliCourse := range meiliCourses {
course, err := daoWrapper.CoursesDao.GetCourseBySlugYearAndTerm(c, meiliCourse.Slug, meiliCourse.TeachingTerm, meiliCourse.Year)
if err == nil && user.IsEligibleToSearchForCourse(course) {
res.Hits = append(res.Hits, meiliCourse)
hit, err := dtoToHit(meiliCourse)
if err == nil {
res.Hits = append(res.Hits, hit)
}
}

if len(res.Hits) >= int(limit) {
Expand All @@ -275,7 +281,7 @@ func checkAndFillResponse(c *gin.Context, user *model.User, limit int64, daoWrap
response.Results[i] = res
case "SUBTITLES":
hits := res.Hits
res.Hits = []any{}
res.Hits = []meilisearch.Hit{}
response.Results[i] = meilisearch.SearchResponse{}

var meiliSubtitles []SearchSubtitlesDTO
Expand Down Expand Up @@ -308,7 +314,10 @@ func checkAndFillResponse(c *gin.Context, user *model.User, limit int64, daoWrap
meiliSubtitle.CourseYear = course.Year
meiliSubtitle.CourseTeachingTerm = course.TeachingTerm
if userEligibleToSeeResultsOfHiddenCourse(course) && (!stream.Private || user.IsAdminOfCourse(course)) {
res.Hits = append(res.Hits, meiliSubtitle)
hit, err := dtoToHit(meiliSubtitle)
if err == nil {
res.Hits = append(res.Hits, hit)
}
}

if len(res.Hits) >= int(limit) {
Expand Down Expand Up @@ -671,3 +680,17 @@ func ToSearchSubtitleDTO(wrapper dao.DaoWrapper, subtitles ...tools.MeiliSubtitl
}
return res
}

func dtoToHit(v any) (meilisearch.Hit, error) {
b, err := json.Marshal(v)
if err != nil {
return nil, err
}

var h meilisearch.Hit
if err := json.Unmarshal(b, &h); err != nil {
return nil, err
}

return h, nil
}
66 changes: 44 additions & 22 deletions api/search_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"encoding/json"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -354,15 +355,15 @@ func getMeiliSearchMock(t *testing.T, daoWrapper dao.DaoWrapper) *mock_tools.Moc
func(q interface{}, limit interface{}, searchType interface{}, courseFilter string, streamFilter string, subtitleFilter string) *meilisearch.MultiSearchResponse {
streams, _ := tools.ToMeiliStreams(testutils.AllStreamsForSearchTests, daoWrapper)
return &meilisearch.MultiSearchResponse{Results: []meilisearch.SearchResponse{
{IndexUID: "COURSES", Hits: meiliCourseSliceToInterfaceSlice(tools.ToMeiliCourses(testutils.AllCoursesForSearchTests))},
{IndexUID: "STREAMS", Hits: meiliStreamSliceToInterfaceSlice(streams)},
{IndexUID: "COURSES", Hits: meiliCourseSliceToHitSlice(tools.ToMeiliCourses(testutils.AllCoursesForSearchTests))},
{IndexUID: "STREAMS", Hits: meiliStreamSliceToHitSlice(streams)},
}}
}).AnyTimes()

mock.EXPECT().Search(gomock.Any(), gomock.Any(), 4, gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
func(q interface{}, limit interface{}, searchType interface{}, courseFilter string, streamFilter string, subtitleFilter string) *meilisearch.MultiSearchResponse {
return &meilisearch.MultiSearchResponse{Results: []meilisearch.SearchResponse{
{IndexUID: "COURSES", Hits: meiliCourseSliceToInterfaceSlice(tools.ToMeiliCourses(testutils.AllCoursesForSearchTests))},
{IndexUID: "COURSES", Hits: meiliCourseSliceToHitSlice(tools.ToMeiliCourses(testutils.AllCoursesForSearchTests))},
}}
}).AnyTimes()

Expand Down Expand Up @@ -398,8 +399,8 @@ func getMeiliSearchMock(t *testing.T, daoWrapper dao.DaoWrapper) *mock_tools.Moc
}
returnStreams, _ := tools.ToMeiliStreams(streams, daoWrapper)
return &meilisearch.MultiSearchResponse{Results: []meilisearch.SearchResponse{
{IndexUID: "STREAMS", Hits: meiliStreamSliceToInterfaceSlice(returnStreams)},
{IndexUID: "SUBTITLES", Hits: meiliSubtitleSliceToInterfaceSlice(subtitles)},
{IndexUID: "STREAMS", Hits: meiliStreamSliceToHitSlice(returnStreams)},
{IndexUID: "SUBTITLES", Hits: meiliSubtitleSliceToHitSlice(subtitles)},
}}
}).AnyTimes()
return mock
Expand All @@ -411,33 +412,54 @@ func getMeiliSearchMockReturningEveryStreamAndSubtitle(t *testing.T, daoWrapper
func(q interface{}, limit interface{}, searchType interface{}, courseFilter string, streamFilter string, subtitleFilter string) *meilisearch.MultiSearchResponse {
streams, _ := tools.ToMeiliStreams(testutils.AllStreamsForSearchTests, daoWrapper)
return &meilisearch.MultiSearchResponse{Results: []meilisearch.SearchResponse{
{IndexUID: "STREAMS", Hits: meiliStreamSliceToInterfaceSlice(streams)},
{IndexUID: "SUBTITLES", Hits: meiliSubtitleSliceToInterfaceSlice(testutils.AllSubtitlesForSearchTests)},
{IndexUID: "STREAMS", Hits: meiliStreamSliceToHitSlice(streams)},
{IndexUID: "SUBTITLES", Hits: meiliSubtitleSliceToHitSlice(testutils.AllSubtitlesForSearchTests)},
}}
}).AnyTimes()
return mock
}

func meiliCourseSliceToInterfaceSlice(cs []tools.MeiliCourse) []interface{} {
s := make([]interface{}, len(cs))
for i, c := range cs {
s[i] = c
func meiliCourseSliceToHitSlice(cs []tools.MeiliCourse) []meilisearch.Hit {
hits := make([]meilisearch.Hit, 0, len(cs))

for _, c := range cs {
b, _ := json.Marshal(c)

var h meilisearch.Hit
_ = json.Unmarshal(b, &h)

hits = append(hits, h)
}
return s

return hits
}

func meiliStreamSliceToInterfaceSlice(cs []tools.MeiliStream) []interface{} {
s := make([]interface{}, len(cs))
for i, c := range cs {
s[i] = c
func meiliStreamSliceToHitSlice(cs []tools.MeiliStream) []meilisearch.Hit {
hits := make([]meilisearch.Hit, 0, len(cs))

for _, c := range cs {
b, _ := json.Marshal(c)

var h meilisearch.Hit
_ = json.Unmarshal(b, &h)

hits = append(hits, h)
}
return s

return hits
}

func meiliSubtitleSliceToInterfaceSlice(cs []tools.MeiliSubtitles) []interface{} {
s := make([]interface{}, len(cs))
for i, c := range cs {
s[i] = c
func meiliSubtitleSliceToHitSlice(cs []tools.MeiliSubtitles) []meilisearch.Hit {
hits := make([]meilisearch.Hit, 0, len(cs))

for _, c := range cs {
b, _ := json.Marshal(c)

var h meilisearch.Hit
_ = json.Unmarshal(b, &h)

hits = append(hits, h)
}
return s

return hits
}
2 changes: 1 addition & 1 deletion cmd/tumlive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func serveHttp(ctx context.Context, manager *runner_manager.Manager, camService
}

router.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
if param.StatusCode >= 400 && VersionTag == "development" {
if param.StatusCode >= 400 && VersionTag == "development" {
return fmt.Sprintf("{\"service\": \"GIN\", \"time\": %s, \"status\": %d, \"client\": \"%s\", \"path\": \"%s\", \"agent\": %s}\n",
param.TimeStamp.Format(time.DateTime),
param.StatusCode,
Expand Down
100 changes: 51 additions & 49 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ tool go.uber.org/mock/mockgen
require (
github.com/RBG-TUM/CAMPUSOnline v0.0.0-20251116171131-fe44da0a604a
github.com/RBG-TUM/go-anel-pwrctrl v1.0.0
github.com/antchfx/xmlquery v1.4.4
github.com/antchfx/xmlquery v1.5.1
github.com/gabstv/melody v1.0.2
github.com/gin-contrib/gzip v1.2.2
github.com/gin-gonic/gin v1.10.0
github.com/go-asn1-ber/asn1-ber v1.5.7 // indirect
github.com/go-gormigrate/gormigrate/v2 v2.1.3
github.com/go-ldap/ldap/v3 v3.4.10
github.com/go-sql-driver/mysql v1.9.1
github.com/gin-contrib/gzip v1.2.6
github.com/gin-gonic/gin v1.12.0
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
github.com/go-gormigrate/gormigrate/v2 v2.1.5
github.com/go-ldap/ldap/v3 v3.4.13
github.com/go-sql-driver/mysql v1.9.3
github.com/gorilla/websocket v1.5.3 // indirect
github.com/jinzhu/now v1.1.5
github.com/microcosm-cc/bluemonday v1.0.27
github.com/robfig/cron/v3 v3.0.1
github.com/russross/blackfriday/v2 v2.1.0
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.20.0
gorm.io/driver/mysql v1.5.7
github.com/sirupsen/logrus v1.9.4
github.com/spf13/viper v1.21.0
gorm.io/driver/mysql v1.6.0
mvdan.cc/xurls/v2 v2.6.0
)

require (
github.com/Masterminds/sprig/v3 v3.3.0
github.com/RBG-TUM/commons v0.0.0-20220406105618-030c095f6a1b
github.com/crewjam/saml v0.4.14
github.com/crewjam/saml v0.5.1
github.com/icholy/digest v1.1.0
github.com/stretchr/testify v1.11.1
github.com/u2takey/go-utils v0.3.1
Expand All @@ -39,22 +39,23 @@ require (
require (
github.com/TUM-Dev/CampusProxy/client v0.0.0-20250907134856-9d3b4d5385a2
github.com/TUM-Dev/gocast/worker v0.0.0-20251102182539-4e087e888c3c
github.com/asticode/go-astisub v0.34.0
github.com/dgraph-io/ristretto/v2 v2.1.0
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3
github.com/asticode/go-astisub v0.39.0
github.com/dgraph-io/ristretto/v2 v2.4.0
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0
github.com/matthiasreumann/gomino v0.0.2
github.com/meilisearch/meilisearch-go v0.31.0
github.com/meilisearch/meilisearch-go v0.36.2
github.com/orandin/slog-gorm v1.4.0
github.com/soheilhy/cmux v0.1.5
github.com/tum-dev/gocast/runner v0.0.0-20260409082233-af97fc2cd196
go.uber.org/mock v0.6.0
golang.org/x/crypto v0.48.0
golang.org/x/crypto v0.50.0
golang.org/x/oauth2 v0.35.0
golang.org/x/sync v0.20.0
google.golang.org/genproto/googleapis/api v0.0.0-20260406210006-6f92a3bedf2d
google.golang.org/grpc v1.79.3
google.golang.org/grpc v1.80.0
google.golang.org/protobuf v1.36.11
gorm.io/gorm v1.25.12
gorm.io/gorm v1.31.1
)

require (
Expand All @@ -63,47 +64,48 @@ require (
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/asticode/go-astikit v0.51.1 // indirect
github.com/asticode/go-astits v1.13.0 // indirect
github.com/bytedance/sonic v1.12.7 // indirect
github.com/bytedance/sonic/loader v0.2.2 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.15.0 // indirect
github.com/bytedance/sonic/loader v0.5.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/golang/glog v1.2.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.59.0 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.13.0 // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/tools v0.42.0 // indirect
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.22.0 // indirect
golang.org/x/mod v0.34.0 // indirect
golang.org/x/tools v0.43.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect
)

require (
// this version works - newer commits may have breaking changes
// github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e // indirect
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
github.com/Azure/go-ntlmssp v0.1.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/antchfx/xpath v1.3.6 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beevik/etree v1.4.1 // indirect
github.com/beevik/etree v1.5.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/crewjam/httperr v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/gin-contrib/sse v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.24.0 // indirect
github.com/goccy/go-json v0.10.4 // indirect
github.com/go-playground/validator/v10 v10.30.1 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/uuid v1.6.0
github.com/gorilla/css v1.0.1 // indirect
Expand All @@ -118,18 +120,18 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/russellhaering/goxmldsig v1.4.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/net v0.50.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.35.0 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
golang.org/x/net v0.52.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/text v0.36.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading