Skip to content

Commit

Permalink
make a proper item for Hookable methods
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ivanov committed May 22, 2017
1 parent 66c3ad7 commit 1b15bb3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions system/admin/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,23 @@ func editHandler(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)
errView, err := Error400()
if err != nil {
return
}

res.Write(errView)
return
}

if cid == "-1" {
err = hook.BeforeAdminCreate(res, req)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions system/api/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1b15bb3

Please sign in to comment.