mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-02 09:49:13 +02:00
Merge branch 'main' into 150-fix-error-response
# Conflicts: # backend/service/addSchedule.go # backend/service/fetch/v2/fetcher.go # frontend/package-lock.json
This commit is contained in:
@@ -127,20 +127,14 @@ func buildIcalQueryForModules(modules []model.FeedCollection) dbx.Expression {
|
||||
|
||||
//second check if modules has only one element
|
||||
if len(modules) == 1 {
|
||||
return dbx.And(
|
||||
dbx.HashExp{"Name": modules[0].Name},
|
||||
dbx.HashExp{"course": modules[0].Course},
|
||||
)
|
||||
return dbx.HashExp{"uuid": modules[0].UUID}
|
||||
}
|
||||
|
||||
//third check if modules has more than one element
|
||||
var wheres []dbx.Expression
|
||||
|
||||
for _, module := range modules {
|
||||
where := dbx.And(
|
||||
dbx.HashExp{"Name": module.Name},
|
||||
dbx.HashExp{"course": module.Course},
|
||||
)
|
||||
where := dbx.HashExp{"uuid": module.UUID}
|
||||
wheres = append(wheres, where)
|
||||
}
|
||||
|
||||
@@ -196,16 +190,16 @@ func GetAllModulesForCourse(app *pocketbase.PocketBase, course string, semester
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func GetAllModulesDistinctByNameAndCourse(app *pocketbase.PocketBase) (model.Events, error) {
|
||||
var events model.Events
|
||||
func GetAllModulesDistinctByNameAndCourse(app *pocketbase.PocketBase) ([]model.ModuleDTO, error) {
|
||||
var modules []model.ModuleDTO
|
||||
|
||||
err := app.Dao().DB().Select("*").From("events").GroupBy("Name").Distinct(true).All(&events)
|
||||
err := app.Dao().DB().Select("Name", "EventType", "Prof", "course", "semester", "uuid").From("events").GroupBy("Name", "Course").Distinct(true).All(&modules)
|
||||
if err != nil {
|
||||
slog.Error("Error while getting events from database: ", err)
|
||||
return nil, fmt.Errorf("error while getting events distinct by name and course from data")
|
||||
}
|
||||
|
||||
return events, nil
|
||||
return modules, nil
|
||||
}
|
||||
|
||||
func DeleteAllEventsForCourse(app *pocketbase.PocketBase, course string, semester string) error {
|
||||
|
@@ -23,13 +23,13 @@ func Test_buildIcalQueryForModules(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "one module",
|
||||
args: args{modules: []model.FeedCollection{{Name: "test", Course: "test"}}},
|
||||
want: dbx.And(dbx.HashExp{"Name": "test"}, dbx.HashExp{"course": "test"}),
|
||||
args: args{modules: []model.FeedCollection{{Name: "test", Course: "test", UUID: "test"}}},
|
||||
want: dbx.HashExp{"uuid": "test"},
|
||||
},
|
||||
{
|
||||
name: "two modules",
|
||||
args: args{modules: []model.FeedCollection{{Name: "test", Course: "test"}, {Name: "test2", Course: "test2"}}},
|
||||
want: dbx.Or(dbx.And(dbx.HashExp{"Name": "test"}, dbx.HashExp{"course": "test"}), dbx.And(dbx.HashExp{"Name": "test2"}, dbx.HashExp{"course": "test2"})),
|
||||
args: args{modules: []model.FeedCollection{{Name: "test", Course: "test", UUID: "test"}, {Name: "test2", Course: "test2", UUID: "test2"}}},
|
||||
want: dbx.Or(dbx.HashExp{"uuid": "test"}, dbx.HashExp{"uuid": "test2"}),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@@ -13,25 +13,47 @@ import (
|
||||
func GetRooms(app *pocketbase.PocketBase) ([]string, error) {
|
||||
|
||||
var events []struct {
|
||||
Rooms string `db:"Rooms" json:"Rooms"`
|
||||
Rooms string `db:"Rooms" json:"Rooms"`
|
||||
Course string `db:"course" json:"Course"`
|
||||
}
|
||||
|
||||
// get all rooms from event records in the events collection
|
||||
err := app.Dao().DB().Select("Rooms").From("events").All(&events)
|
||||
err := app.Dao().DB().Select("Rooms", "course").From("events").Distinct(true).All(&events)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var roomArray []string
|
||||
roomArray := clearAndSeparateRooms([]struct {
|
||||
Rooms string
|
||||
Course string
|
||||
}(events))
|
||||
|
||||
return roomArray
|
||||
}
|
||||
|
||||
func clearAndSeparateRooms(events []struct {
|
||||
Rooms string
|
||||
Course string
|
||||
}) []string {
|
||||
var roomArray []string
|
||||
for _, event := range events {
|
||||
var room = strings.FieldsFunc(event.Rooms, functions.IsSeparator(
|
||||
[]rune{',', ' ', '\t', '\n', '\r', '\u00A0'},
|
||||
))
|
||||
|
||||
var room []string
|
||||
|
||||
// sport rooms don't have to be separated
|
||||
if event.Course != "Sport" {
|
||||
//split rooms by comma, tab, newline, carriage return, semicolon, space and non-breaking space
|
||||
room = strings.FieldsFunc(event.Rooms, functions.IsSeparator(
|
||||
[]rune{',', '\t', '\n', '\r', ';', ' ', '\u00A0'}),
|
||||
)
|
||||
} else {
|
||||
room = append(room, event.Rooms)
|
||||
}
|
||||
|
||||
//split functions room by space and add each room to array if it is not already in there
|
||||
for _, r := range room {
|
||||
var text = strings.TrimSpace(r)
|
||||
if !functions.Contains(roomArray, text) && !strings.Contains(text, " ") && len(text) >= 1 {
|
||||
if !functions.Contains(roomArray, text) && len(text) >= 1 {
|
||||
roomArray = append(roomArray, text)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user