summaryrefslogtreecommitdiff
path: root/system/api
diff options
context:
space:
mode:
authorPaul Ivanov <pi@berkeley.edu>2017-05-21 22:54:44 -0700
committerPaul Ivanov <pi@berkeley.edu>2017-05-21 22:54:44 -0700
commit1b15bb3c1a2dc8f3a73260e4034913089d7bbcfc (patch)
treeca178b2ea9e48d01ce914a7c54c445c88b6de38c /system/api
parent66c3ad778ccf54566086d535a6ebe4805bf4241f (diff)
make a proper item for Hookable methods
We have all of the information, it's nice to be access the item's members in a natural way, without having to look at the reqest.
Diffstat (limited to 'system/api')
-rw-r--r--system/api/create.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/system/api/create.go b/system/api/create.go
index 3328bd6..3b748cc 100644
--- a/system/api/create.go
+++ b/system/api/create.go
@@ -12,6 +12,8 @@ import (
"github.com/ponzu-cms/ponzu/system/admin/upload"
"github.com/ponzu-cms/ponzu/system/db"
"github.com/ponzu-cms/ponzu/system/item"
+
+ "github.com/gorilla/schema"
)
// Createable accepts or rejects external POST requests to endpoints such as:
@@ -131,6 +133,17 @@ func createContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
+ // Let's be nice and make a proper item for the Hookable methods
+ dec := schema.NewDecoder()
+ dec.IgnoreUnknownKeys(true)
+ dec.SetAliasTag("json")
+ err = dec.Decode(post, req.PostForm)
+ if err != nil {
+ log.Println("Error decoding post form for edit handler:", t, err)
+ res.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
err = hook.BeforeAPICreate(res, req)
if err != nil {
log.Println("[Create] error calling BeforeAccept:", err)