update for frontend

This commit is contained in:
Elmar Kresse
2023-09-10 10:39:00 +02:00
parent 991d069931
commit eeb84db0cc
6 changed files with 114 additions and 6 deletions

View File

@@ -0,0 +1,12 @@
package events
import (
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"htwk-planner/service/db"
)
func GetAllCourses(app *pocketbase.PocketBase, c echo.Context) error {
courses := db.GetAllCourses(app)
return c.JSON(200, courses)
}

View File

@@ -0,0 +1,40 @@
package events
import (
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"htwk-planner/service/db"
"unicode"
)
func GetModulesForCourseDistinct(app *pocketbase.PocketBase, c echo.Context, course string, semester string) error {
modules, err := db.GetAllModulesForCourse(app, course, semester)
replaceEmptyEntry(modules, "Sonderveranstaltungen")
if err != nil {
return c.JSON(400, err)
} else {
return c.JSON(200, modules)
}
}
func replaceEmptyEntry(courses []string, replacement string) {
//replace empty string with "Sonderveranstaltungen"
for i, course := range courses {
if checkIfOnlyWhitespace(course) {
courses[i] = replacement
}
}
}
// check if course is empty or contains only whitespaces
func checkIfOnlyWhitespace(word string) bool {
for _, letter := range word {
if !unicode.IsSpace(letter) || !(letter == int32(160)) {
return false
}
}
return true
}