mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-03 10:19:16 +02:00
fixed schedule and update process
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"htwkalender/model"
|
||||
"htwkalender/service/db"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@@ -63,18 +62,12 @@ func writeSuccess(message string, w http.ResponseWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
func CreateIndividualFeed(c echo.Context, app *pocketbase.PocketBase) error {
|
||||
|
||||
// read json from request body
|
||||
func CreateIndividualFeed(requestBody []byte, app *pocketbase.PocketBase) (string, error) {
|
||||
var modules []model.FeedCollection
|
||||
requestBodyBytes, err := io.ReadAll(c.Request().Body)
|
||||
if err != nil {
|
||||
return apis.NewApiError(400, "Could not bind request body", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(requestBodyBytes, &modules)
|
||||
err := json.Unmarshal(requestBody, &modules)
|
||||
if err != nil {
|
||||
return apis.NewApiError(400, "Could not bind request body", err)
|
||||
return "", apis.NewNotFoundError("Could not parse request body", err)
|
||||
}
|
||||
|
||||
var feed model.Feed
|
||||
@@ -83,13 +76,13 @@ func CreateIndividualFeed(c echo.Context, app *pocketbase.PocketBase) error {
|
||||
|
||||
collection, dbError := db.FindCollection(app, "feeds")
|
||||
if dbError != nil {
|
||||
return apis.NewNotFoundError("Collection not found", dbError)
|
||||
return "", apis.NewNotFoundError("Collection could not be found", dbError)
|
||||
}
|
||||
|
||||
record, err := db.SaveFeed(feed, collection, app)
|
||||
if err != nil {
|
||||
return apis.NewNotFoundError("Feed could not be saved", dbError)
|
||||
return "", apis.NewNotFoundError("Could not save feed", err)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, record.Id)
|
||||
return record.Id, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user