mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-03 02:09:15 +02:00
feat:#150 rewrote error handling for backend
This commit is contained in:
@@ -10,23 +10,39 @@ import (
|
||||
)
|
||||
|
||||
func GetRooms(c echo.Context, app *pocketbase.PocketBase) error {
|
||||
rooms := db.GetRooms(app)
|
||||
return c.JSON(http.StatusOK, rooms)
|
||||
rooms, err := db.GetRooms(app)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusNotFound, err)
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, rooms)
|
||||
}
|
||||
}
|
||||
|
||||
func GetRoomScheduleForDay(c echo.Context, app *pocketbase.PocketBase, room string, date string) error {
|
||||
events := db.GetRoomScheduleForDay(app, room, date)
|
||||
return c.JSON(http.StatusOK, anonymizeRooms(events))
|
||||
|
||||
events, err := db.GetRoomScheduleForDay(app, room, date)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, err)
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, anonymizeRooms(events))
|
||||
}
|
||||
}
|
||||
|
||||
func GetRoomSchedule(c echo.Context, app *pocketbase.PocketBase, room string, from string, to string) error {
|
||||
events := db.GetRoomSchedule(app, room, from, to)
|
||||
return c.JSON(http.StatusOK, anonymizeRooms(events))
|
||||
events, err := db.GetRoomSchedule(app, room, from, to)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, err)
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, anonymizeRooms(events))
|
||||
}
|
||||
}
|
||||
|
||||
// Transform the events to anonymized events throwing away all unnecessary information
|
||||
func anonymizeRooms(events []model.Event) []model.AnonymizedEventDTO {
|
||||
var anonymizedEvents = []model.AnonymizedEventDTO{}
|
||||
var anonymizedEvents []model.AnonymizedEventDTO
|
||||
for _, event := range events {
|
||||
anonymizedEvents = append(anonymizedEvents, event.AnonymizeEvent())
|
||||
}
|
||||
|
Reference in New Issue
Block a user