summaryrefslogtreecommitdiff
path: root/examples/updateable
diff options
context:
space:
mode:
Diffstat (limited to 'examples/updateable')
-rw-r--r--examples/updateable/README.md4
-rw-r--r--examples/updateable/content/song.go21
2 files changed, 12 insertions, 13 deletions
diff --git a/examples/updateable/README.md b/examples/updateable/README.md
index 1cc50f8..06f4188 100644
--- a/examples/updateable/README.md
+++ b/examples/updateable/README.md
@@ -23,8 +23,8 @@ See the file `content/song.go` and read the comments to understand the various
methods needed to satisfy required interfaces for this kind of activity.
### Overview
-1. Implement `api.Updateable` with the `AcceptUpdate(http.ResponseWriter, *http.Request)` method to allow outside POST requests.
-2. Consistent with the externalable example, authentication can be validated in `BeforeAcceptUdate(http.ResponseWriter, *http.Request)`
+1. Implement `api.Updateable` with the `Update(http.ResponseWriter, *http.Request)` method to allow outside POST requests.
+2. Consistent with the createable example, authentication can be validated in `BeforeAPIUpdate(http.ResponseWriter, *http.Request)`
There are various validation and request checks shown in this example as well.
Please feel free to modify and submit a PR for updates or bug fixes!
diff --git a/examples/updateable/content/song.go b/examples/updateable/content/song.go
index 1ebe232..a2dc7f8 100644
--- a/examples/updateable/content/song.go
+++ b/examples/updateable/content/song.go
@@ -9,6 +9,7 @@ import (
"github.com/ponzu-cms/ponzu/management/editor"
"github.com/ponzu-cms/ponzu/system/admin/user"
+ "github.com/ponzu-cms/ponzu/system/api"
"github.com/ponzu-cms/ponzu/system/item"
)
@@ -79,31 +80,29 @@ func init() {
// String defines the display name of a Song in the CMS list-view
func (s *Song) String() string { return s.Title }
-// BeforeAcceptUpdate is only called if the Song type implements api.Updateable
-// It is called before AcceptUpdate, and returning an error will cancel the request
+// BeforeAPIUpdate is only called if the Song type implements api.Updateable
+// It is called before Update, and returning an error will cancel the request
// causing the system to reject the data sent in the POST
-func (s *Song) BeforeAcceptUpdate(res http.ResponseWriter, req *http.Request) error {
+func (s *Song) BeforeAPIUpdate(res http.ResponseWriter, req *http.Request) error {
// do initial user authentication here on the request, checking for a
// token or cookie, or that certain form fields are set and valid
// for example, this will check if the request was made by a CMS admin user:
if !user.IsValid(req) {
- addr := req.RemoteAddr
- err := fmt.Errorf("request rejected, invalid user. IP: %s", addr)
- return err
+ return api.ErrNoAuth
}
// you could then to data validation on the request post form, or do it in
- // the Accept method, which is called after BeforeAccept
+ // the Update method, which is called after BeforeAPIUpdate
return nil
}
-// AcceptUpdate is called after BeforeAccept and is where you may influence the
+// Update is called after BeforeAPIUpdate and is where you may influence the
// merge process. For example, maybe you don't want an empty string for the Title
// or Artist field to be accepted by the update request. Updates will always merge
// with existing values, but by default will accept zero value as an update if sent.
-func (s *Song) AcceptUpdate(res http.ResponseWriter, req *http.Request) error {
+func (s *Song) Update(res http.ResponseWriter, req *http.Request) error {
addr := req.RemoteAddr
log.Println("Song update sent by:", addr, "id:", req.URL.Query().Get("id"))
@@ -129,11 +128,11 @@ func (s *Song) AcceptUpdate(res http.ResponseWriter, req *http.Request) error {
return nil
}
-// AfterAcceptUpdate is called after AcceptUpdate, and is useful for logging or triggering
+// AfterAPIUpdate is called after Update, and is useful for logging or triggering
// notifications, etc. after the data is saved to the database, etc.
// The request has a context containing the databse 'target' affected by the
// request.
-func (s *Song) AfterAcceptUpdate(res http.ResponseWriter, req *http.Request) error {
+func (s *Song) AfterAPIUpdate(res http.ResponseWriter, req *http.Request) error {
addr := req.RemoteAddr
log.Println("Song updated by:", addr, "id:", req.URL.Query().Get("id"))