feat:#7 added new folder structure and updated api in ical

This commit is contained in:
Elmar Kresse
2024-05-26 11:59:32 +02:00
parent 2f55076e36
commit cb76b5c188
113 changed files with 250 additions and 266 deletions

View File

@@ -0,0 +1,84 @@
package service
import (
"github.com/gofiber/fiber/v3"
"htwkalender-ical/service/ical"
"log/slog"
"net/http"
)
// 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)
})
app.Delete("/api/feed", func(c fiber.Ctx) error {
token := c.Query("token")
err := ical.DeleteFeedRecord(token)
if err != nil {
slog.Error("Feed could not be deleted", "error", err)
return c.JSON(http.StatusNotFound, "Feed could not be deleted")
} else {
return c.JSON(http.StatusOK, "Feed deleted")
}
})
app.Put("/api/feed", func(c fiber.Ctx) error {
token := c.Query("token")
return c.JSON(http.StatusOK, "token: "+token)
})
app.Head("/api/feed", func(c fiber.Ctx) error {
return c.JSON(http.StatusOK, "")
})
app.Add([]string{"PROPFIND"}, "/api/feed", func(c fiber.Ctx) error {
return c.JSON(http.StatusOK, "")
})
// Route for Thunderbird to get calendar server information
// Response is a 200 OK without additional content
app.Add([]string{"PROPFIND"}, "/.well-known/caldav", func(c fiber.Ctx) error {
return c.JSON(http.StatusOK, "")
})
// Route for Thunderbird to get calendar server information
// Response is a 200 OK without additional content
app.Add([]string{"PROPFIND"}, "/", func(c fiber.Ctx) error {
return c.JSON(http.StatusOK, "")
})
}