summaryrefslogtreecommitdiff
path: root/content/item.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2016-11-16 02:51:26 -0800
committerGitHub <noreply@github.com>2016-11-16 02:51:26 -0800
commitf252472047f86d1bdf956dc59b89541ea0260d68 (patch)
tree6c0d5938c21505325ad50446f5ebcd1483d6b278 /content/item.go
parent9a531ac701990bb932664039b11614227467e03a (diff)
parent6f5893828077eb0034dca01344f3742eb5cd5fa6 (diff)
Merge pull request #17 from bosssauce/ponzu-dev
[core] Adding lifecycle hooks for Save, Delete, Approve, Reject
Diffstat (limited to 'content/item.go')
-rw-r--r--content/item.go88
1 files changed, 74 insertions, 14 deletions
diff --git a/content/item.go b/content/item.go
index 81593b6..c847ed7 100644
--- a/content/item.go
+++ b/content/item.go
@@ -1,5 +1,41 @@
package content
+import "net/http"
+
+// Sluggable makes a struct locatable by URL with it's own path
+// As an Item implementing Sluggable, slugs may overlap. If this is an issue,
+// make your content struct (or one which imbeds Item) implement Sluggable
+// and it will override the slug created by Item's SetSlug with your struct's
+type Sluggable interface {
+ SetSlug(string)
+}
+
+// Identifiable enables a struct to have its ID set. Typically this is done
+// to set an ID to -1 indicating it is new for DB inserts, since by default
+// a newly initialized struct would have an ID of 0, the int zero-value, and
+// BoltDB's starting key per bucket is 0, thus overwriting the first record.
+type Identifiable interface {
+ SetItemID(int)
+}
+
+// Hookable provides our user with an easy way to intercept or add functionality
+// to the different lifecycles/events a struct may encounter. Item implements
+// Hookable with no-ops so our user can override only whichever ones necessary.
+type Hookable interface {
+ BeforeSave(req *http.Request) error
+ AfterSave(req *http.Request) error
+
+ BeforeDelete(req *http.Request) error
+ AfterDelete(req *http.Request) error
+
+ BeforeApprove(req *http.Request) error
+ AfterApprove(req *http.Request) error
+
+ BeforeReject(req *http.Request) error
+ AfterReject(req *http.Request) error
+}
+
+
// Item should only be embedded into content type structs.
type Item struct {
ID int `json:"id"`
@@ -28,23 +64,47 @@ func (i *Item) SetSlug(slug string) {
i.Slug = slug
}
-// SetContentID sets the Item's ID field
-func (i *Item) SetContentID(id int) {
+// SetItemID sets the Item's ID field
+func (i *Item) SetItemID(id int) {
i.ID = id
}
-// Sluggable makes a struct locatable by URL with it's own path
-// As an Item implementing Sluggable, slugs may overlap. If this is an issue,
-// make your content struct (or one which imbeds Item) implement Sluggable
-// and it will override the slug created by Item's SetSlug with your struct's
-type Sluggable interface {
- SetSlug(string)
+// BeforeSave is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) BeforeSave(req *http.Request) error {
+ return nil
}
-// Identifiable enables a struct to have its ID set. Typically this is done
-// to set an ID to -1 indicating it is new for DB inserts, since by default
-// a newly initialized struct would have an ID of 0, the int zero-value, and
-// BoltDB's starting key per bucket is 0, thus overwriting the first record.
-type Identifiable interface {
- SetContentID(int)
+// AfterSave is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) AfterSave(req *http.Request) error {
+ return nil
}
+
+// BeforeDelete is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) BeforeDelete(req *http.Request) error {
+ return nil
+}
+
+// AfterDelete is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) AfterDelete(req *http.Request) error {
+ return nil
+}
+
+// BeforeApprove is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) BeforeApprove(req *http.Request) error {
+ return nil
+}
+
+// AfterApprove is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) AfterApprove(req *http.Request) error {
+ return nil
+}
+
+// BeforeReject is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) BeforeReject(req *http.Request) error {
+ return nil
+}
+
+// AfterReject is a no-op to ensure structs which embed Item implement Hookable
+func (i Item) AfterReject(req *http.Request) error {
+ return nil
+} \ No newline at end of file