mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-07 04:09:17 +02:00
added api for room and day check
This commit is contained in:
@@ -71,6 +71,25 @@ func AddRoutes(app *pocketbase.PocketBase) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||||
|
_, err := e.Router.AddRoute(echo.Route{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/api/schedule/day",
|
||||||
|
Handler: func(c echo.Context) error {
|
||||||
|
roomParam := c.QueryParam("room")
|
||||||
|
date := c.QueryParam("date")
|
||||||
|
return room.GetRoomScheduleForDay(c, app, roomParam, date)
|
||||||
|
},
|
||||||
|
Middlewares: []echo.MiddlewareFunc{
|
||||||
|
apis.ActivityLogger(app),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||||
_, err := e.Router.AddRoute(echo.Route{
|
_, err := e.Router.AddRoute(echo.Route{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
|
@@ -118,6 +118,18 @@ func GetRooms(app *pocketbase.PocketBase) []string {
|
|||||||
return roomArray
|
return roomArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetRoomScheduleForDay(app *pocketbase.PocketBase, room string, date string) []model.Event {
|
||||||
|
var events []model.Event
|
||||||
|
|
||||||
|
// get all events from event records in the events collection
|
||||||
|
err := app.Dao().DB().Select("*").From("events").Where(dbx.Like("Rooms", room)).AndWhere(dbx.Like("Start", date)).All(&events)
|
||||||
|
if err != nil {
|
||||||
|
print("Error while getting events from database: ", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return events
|
||||||
|
}
|
||||||
|
|
||||||
type Events []*model.Event
|
type Events []*model.Event
|
||||||
|
|
||||||
// EmitICal implements the interface for goics
|
// EmitICal implements the interface for goics
|
||||||
|
@@ -11,3 +11,8 @@ func GetRooms(c echo.Context, app *pocketbase.PocketBase) error {
|
|||||||
rooms := db.GetRooms(app)
|
rooms := db.GetRooms(app)
|
||||||
return c.JSON(http.StatusOK, rooms)
|
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, events)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user