mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-03 10:19:14 +02:00
feat:#150 extracted functions rewrote error pipe for feed routes
This commit is contained in:
@@ -1,45 +1,36 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"htwkalender/model"
|
||||
"htwkalender/service/db"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
)
|
||||
|
||||
func GetRooms(c echo.Context, app *pocketbase.PocketBase) error {
|
||||
func GetRooms(app *pocketbase.PocketBase) ([]string, error) {
|
||||
rooms, err := db.GetRooms(app)
|
||||
|
||||
if err != nil {
|
||||
slog.Error("Error getting rooms: ", err)
|
||||
return c.JSON(http.StatusNotFound, "No rooms found")
|
||||
return nil, err
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, rooms)
|
||||
return rooms, nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetRoomScheduleForDay(c echo.Context, app *pocketbase.PocketBase, room string, date string) error {
|
||||
|
||||
events, err := db.GetRoomScheduleForDay(app, room, date)
|
||||
|
||||
func GetRoomScheduleForDay(app *pocketbase.PocketBase, room string, date string) ([]model.AnonymizedEventDTO, error) {
|
||||
roomSchedule, err := db.GetRoomScheduleForDay(app, room, date)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, err)
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, anonymizeRooms(events))
|
||||
return nil, err
|
||||
}
|
||||
anonymizedRoomSchedule := anonymizeRooms(roomSchedule)
|
||||
return anonymizedRoomSchedule, nil
|
||||
}
|
||||
|
||||
func GetRoomSchedule(c echo.Context, app *pocketbase.PocketBase, room string, from string, to string) error {
|
||||
events, err := db.GetRoomSchedule(app, room, from, to)
|
||||
|
||||
func GetRoomSchedule(app *pocketbase.PocketBase, room string, from string, to string) ([]model.AnonymizedEventDTO, error) {
|
||||
roomSchedule, err := db.GetRoomSchedule(app, room, from, to)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, err)
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, anonymizeRooms(events))
|
||||
return nil, err
|
||||
}
|
||||
anonymizedRoomSchedule := anonymizeRooms(roomSchedule)
|
||||
return anonymizedRoomSchedule, nil
|
||||
}
|
||||
|
||||
// Transform the events to anonymized events throwing away all unnecessary information
|
||||
|
Reference in New Issue
Block a user