mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-02 17:59:14 +02:00
fixed merge issue with main
This commit is contained in:
@@ -107,6 +107,26 @@ func AddRoutes(app *pocketbase.PocketBase) {
|
||||
})
|
||||
|
||||
// API Endpoint to create a new iCal feed
|
||||
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||
_, err := e.Router.AddRoute(echo.Route{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/schedule",
|
||||
Handler: func(c echo.Context) error {
|
||||
roomParam := c.QueryParam("room")
|
||||
to := c.QueryParam("to")
|
||||
from := c.QueryParam("from")
|
||||
return room.GetRoomSchedule(c, app, roomParam, from, to)
|
||||
},
|
||||
Middlewares: []echo.MiddlewareFunc{
|
||||
apis.ActivityLogger(app),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||
_, err := e.Router.AddRoute(echo.Route{
|
||||
Method: http.MethodPost,
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"fmt"
|
||||
"htwkalender/model"
|
||||
"htwkalender/service/functions"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
)
|
||||
|
||||
func GetRooms(app *pocketbase.PocketBase) []string {
|
||||
@@ -47,3 +50,31 @@ func GetRoomScheduleForDay(app *pocketbase.PocketBase, room string, date string)
|
||||
}
|
||||
return events
|
||||
}
|
||||
|
||||
func GetRoomSchedule(app *pocketbase.PocketBase, room string, from string, to string) []model.Event {
|
||||
var events []model.Event
|
||||
|
||||
fromDate, err := time.Parse("2006-01-02", from)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing date 'from':", err)
|
||||
return nil
|
||||
}
|
||||
toDate, err := time.Parse("2006-01-02", to)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing date 'to':", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
// get all events from event records in the events collection
|
||||
err = app.Dao().DB().Select("*").From("events").
|
||||
Where(dbx.Like("Rooms", room)).
|
||||
AndWhere(dbx.Between("Start", fromDate, toDate)).
|
||||
GroupBy("Week", "Start", "End", "Rooms").
|
||||
All(&events)
|
||||
|
||||
if err != nil {
|
||||
print("Error while getting events from database: ", err)
|
||||
return nil
|
||||
}
|
||||
return events
|
||||
}
|
||||
|
@@ -16,3 +16,8 @@ func GetRoomScheduleForDay(c echo.Context, app *pocketbase.PocketBase, room stri
|
||||
events := db.GetRoomScheduleForDay(app, room, date)
|
||||
return c.JSON(http.StatusOK, 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, events)
|
||||
}
|
||||
|
Reference in New Issue
Block a user