mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2026-01-16 11:32:26 +01:00
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v3"
|
|
"htwkalender-ical/service/ical"
|
|
"log/slog"
|
|
)
|
|
|
|
// add routes to the app instance for the backend ical service
|
|
// with golang fiber
|
|
func AddFeedRoutes(app *fiber.App) {
|
|
|
|
// Define a route for the GET method on the root path '/'
|
|
app.Get("/api/feed", func(c fiber.Ctx) error {
|
|
|
|
token := c.Query("token")
|
|
results, err := ical.Feed(token)
|
|
|
|
if err != nil {
|
|
slog.Error("Failed to get feed", "error", err)
|
|
return c.SendStatus(fiber.StatusInternalServerError)
|
|
}
|
|
c.Response().Header.Set("Content-type", "text/calendar")
|
|
c.Response().Header.Set("charset", "utf-8")
|
|
c.Response().Header.Set("Content-Disposition", "inline")
|
|
c.Response().Header.Set("filename", "calendar.ics")
|
|
|
|
return c.SendString(results)
|
|
})
|
|
|
|
// Define a route for the GET method on the root path '/'
|
|
app.Get("/api/collections/feeds/records/:token", func(c fiber.Ctx) error {
|
|
|
|
token := c.Params("token")
|
|
results, err := ical.FeedRecord(token)
|
|
|
|
if err != nil {
|
|
slog.Error("Failed to get feed", "error", err)
|
|
return c.SendStatus(fiber.StatusInternalServerError)
|
|
}
|
|
c.Response().Header.Set("Content-type", "application/json; charset=UTF-8")
|
|
|
|
return c.JSON(results)
|
|
})
|
|
}
|