feat:#34 refactored function to intended service, fixed docker files

This commit is contained in:
Elmar Kresse
2024-06-10 16:57:40 +02:00
parent cb76b5c188
commit 2d7701b0c9
96 changed files with 212 additions and 79 deletions

View File

@@ -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 {