package room import ( "htwkalender/model" "htwkalender/service/db" "net/http" "github.com/labstack/echo/v5" "github.com/pocketbase/pocketbase" ) func GetRooms(c echo.Context, app *pocketbase.PocketBase) error { 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, 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, 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 for _, event := range events { anonymizedEvents = append(anonymizedEvents, event.AnonymizeEvent()) } return anonymizedEvents }