mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-07 04:09:15 +02:00
feat:#34 refactored function to intended service, fixed docker files
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
"htwkalender-ical/model"
|
||||
"htwkalender-ical/service/ical"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// add routes to the app instance for the backend ical service
|
||||
// add routes to the app instance for the data-manager ical service
|
||||
// with golang fiber
|
||||
func AddFeedRoutes(app *fiber.App) {
|
||||
|
||||
@@ -29,6 +32,27 @@ func AddFeedRoutes(app *fiber.App) {
|
||||
return c.SendString(results)
|
||||
})
|
||||
|
||||
// Define a route for the POST method on the root path '/api/feed'
|
||||
app.Post("/api/feed", func(c fiber.Ctx) error {
|
||||
modules := []model.FeedCollection{}
|
||||
//obtain the body of the request
|
||||
err := json.Unmarshal(c.Body(), &modules)
|
||||
if err != nil {
|
||||
log.Error("Failed to unmarshal request body", "error", err)
|
||||
return c.SendStatus(fiber.StatusBadRequest)
|
||||
}
|
||||
|
||||
//create a new feed
|
||||
token, err := ical.CreateFeed(modules)
|
||||
if err != nil {
|
||||
println(err)
|
||||
log.Error("Failed to create feed", "error", err)
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return c.JSON(token)
|
||||
})
|
||||
|
||||
// Define a route for the GET method on the root path '/'
|
||||
app.Get("/api/collections/feeds/records/:token", func(c fiber.Ctx) error {
|
||||
|
||||
|
Reference in New Issue
Block a user