refactoring to clear db functions

This commit is contained in:
Elmar Kresse
2023-09-30 22:45:58 +02:00
parent b1927864c2
commit f982feec4f
3 changed files with 84 additions and 3 deletions

View File

@@ -30,6 +30,8 @@ func GetSeminarEvents(c echo.Context, app *pocketbase.PocketBase) error {
seminarGroups = clearEmptySeminarGroups(seminarGroups)
seminarGroups = replaceEmptyEventNames(seminarGroups)
savedRecords, dbError := db.SaveEvents(seminarGroups, collection, app)
if dbError != nil {
@@ -39,6 +41,17 @@ func GetSeminarEvents(c echo.Context, app *pocketbase.PocketBase) error {
return c.JSON(http.StatusOK, savedRecords)
}
func replaceEmptyEventNames(groups []model.SeminarGroup) []model.SeminarGroup {
for i, group := range groups {
for j, event := range group.Events {
if event.Name == "" {
groups[i].Events[j].Name = "Sonderveranstaltungen"
}
}
}
return groups
}
func clearEmptySeminarGroups(seminarGroups []model.SeminarGroup) []model.SeminarGroup {
var newSeminarGroups []model.SeminarGroup
for _, seminarGroup := range seminarGroups {