mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-02 17:59:14 +02:00
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package events
|
|
|
|
import (
|
|
"github.com/labstack/echo/v5"
|
|
"github.com/pocketbase/pocketbase"
|
|
"htwkalender/model"
|
|
"htwkalender/service/db"
|
|
"htwkalender/service/functions"
|
|
)
|
|
|
|
func GetModulesForCourseDistinct(app *pocketbase.PocketBase, c echo.Context, course string, semester string) error {
|
|
|
|
modules, err := db.GetAllModulesForCourse(app, course, semester)
|
|
replaceEmptyEntryInStringArray(modules, "Sonderveranstaltungen")
|
|
|
|
if err != nil {
|
|
return c.JSON(400, err)
|
|
} else {
|
|
return c.JSON(200, modules)
|
|
}
|
|
}
|
|
|
|
func replaceEmptyEntryInStringArray(modules []string, replacement string) {
|
|
//replace empty functions with "Sonderveranstaltungen"
|
|
for i, module := range modules {
|
|
if functions.OnlyWhitespace(module) {
|
|
modules[i] = replacement
|
|
}
|
|
}
|
|
}
|
|
|
|
func replaceEmptyEntry(modules model.Events, replacement string) {
|
|
//replace empty functions with "Sonderveranstaltungen"
|
|
for i, module := range modules {
|
|
if functions.OnlyWhitespace(module.Name) {
|
|
modules[i].Name = replacement
|
|
}
|
|
}
|
|
}
|
|
|
|
func GetAllModulesDistinct(app *pocketbase.PocketBase, c echo.Context) error {
|
|
modules, err := db.GetAllModulesDistinct(app)
|
|
|
|
replaceEmptyEntry(modules, "Sonderveranstaltungen")
|
|
|
|
if err != nil {
|
|
return c.JSON(400, err)
|
|
} else {
|
|
return c.JSON(200, modules)
|
|
}
|
|
}
|