fixed schedule and update process

This commit is contained in:
masterelmar
2023-10-08 18:22:34 +02:00
parent 3225a9040e
commit 9a1342b954
5 changed files with 82 additions and 29 deletions

View File

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