feat:#150 rewrite error handling for routes

This commit is contained in:
Elmar Kresse
2024-01-23 18:16:12 +01:00
parent 1582154d5f
commit 0198e74652
3 changed files with 66 additions and 60 deletions

View File

@@ -1,7 +1,6 @@
package events
import (
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"htwkalender/model"
"htwkalender/service/db"
@@ -40,21 +39,17 @@ func replaceEmptyEntry(namedList []Named, replacement string) {
// GetAllModulesDistinct returns all modules distinct by name and course from the database
// That means you get all modules with duplicates if they have different courses
func GetAllModulesDistinct(app *pocketbase.PocketBase, c echo.Context) error {
func GetAllModulesDistinct(app *pocketbase.PocketBase) ([]model.ModuleDTO, error) {
modules, err := db.GetAllModulesDistinctByNameAndCourse(app)
if err != nil {
return nil, err
}
var namedModules []Named
for _, module := range modules {
namedModules = append(namedModules, &module)
}
replaceEmptyEntry(namedModules, "Sonderveranstaltungen")
if err != nil {
return c.JSON(400, err)
} else {
return c.JSON(200, modules)
}
return modules, nil
}
func GetModuleByUUID(app *pocketbase.PocketBase, uuid string) (model.Module, error) {