summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/item.go40
-rw-r--r--content/post.go83
2 files changed, 27 insertions, 96 deletions
diff --git a/content/item.go b/content/item.go
index c847ed7..9eb3c16 100644
--- a/content/item.go
+++ b/content/item.go
@@ -1,6 +1,10 @@
package content
-import "net/http"
+import (
+ "net/http"
+
+ uuid "github.com/satori/go.uuid"
+)
// 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,
@@ -10,12 +14,14 @@ type Sluggable interface {
SetSlug(string)
}
-// Identifiable enables a struct to have its ID set. Typically this is done
+// Identifiable enables a struct to have its ID set/get. 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 {
+ ItemID() int
SetItemID(int)
+ UniqueID() uuid.UUID
}
// Hookable provides our user with an easy way to intercept or add functionality
@@ -35,13 +41,13 @@ type Hookable interface {
AfterReject(req *http.Request) error
}
-
// Item should only be embedded into content type structs.
type Item struct {
- ID int `json:"id"`
- Slug string `json:"slug"`
- Timestamp int64 `json:"timestamp"`
- Updated int64 `json:"updated"`
+ UUID uuid.UUID `json:"uuid"`
+ ID int `json:"id"`
+ Slug string `json:"slug"`
+ Timestamp int64 `json:"timestamp"`
+ Updated int64 `json:"updated"`
}
// Time partially implements the Sortable interface
@@ -54,21 +60,29 @@ func (i Item) Touch() int64 {
return i.Updated
}
-// ItemID partially implements the Sortable interface
-func (i Item) ItemID() int {
- return i.ID
-}
-
// SetSlug sets the item's slug for its URL
func (i *Item) SetSlug(slug string) {
i.Slug = slug
}
+// ItemID gets the Item's ID field
+// partially implements the Identifiable interface
+func (i Item) ItemID() int {
+ return i.ID
+}
+
// SetItemID sets the Item's ID field
+// partially implements the Identifiable interface
func (i *Item) SetItemID(id int) {
i.ID = id
}
+// UniqueID gets the Item's UUID field
+// partially implements the Identifiable interface
+func (i Item) UniqueID() uuid.UUID {
+ return i.UUID
+}
+
// BeforeSave is a no-op to ensure structs which embed Item implement Hookable
func (i Item) BeforeSave(req *http.Request) error {
return nil
@@ -107,4 +121,4 @@ func (i Item) BeforeReject(req *http.Request) error {
// 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
+}
diff --git a/content/post.go b/content/post.go
deleted file mode 100644
index b81bb5a..0000000
--- a/content/post.go
+++ /dev/null
@@ -1,83 +0,0 @@
-package content
-
-import (
- "fmt"
-
- "github.com/bosssauce/ponzu/management/editor"
-)
-
-// Post is the generic content struct
-type Post struct {
- Item
- editor editor.Editor
-
- Title string `json:"title"`
- Content string `json:"content"`
- Photo string `json:"photo"`
- Author string `json:"author"`
- Category []string `json:"category"`
- Theme string `json:"theme"`
-}
-
-// MarshalEditor writes a buffer of html to edit a Post and partially implements editor.Editable
-func (p *Post) MarshalEditor() ([]byte, error) {
- view, err := editor.Form(p,
- editor.Field{
- View: editor.Input("Title", p, map[string]string{
- "label": "Post Title",
- "type": "text",
- "placeholder": "Enter your Post Title here",
- }),
- },
- editor.Field{
- View: editor.Richtext("Content", p, map[string]string{
- "label": "Content",
- "placeholder": "Add the content of your post here",
- }),
- },
- editor.Field{
- View: editor.File("Photo", p, map[string]string{
- "label": "Author Photo",
- "placeholder": "Upload a profile picture for the author",
- }),
- },
- editor.Field{
- View: editor.Input("Author", p, map[string]string{
- "label": "Author",
- "type": "text",
- "placeholder": "Enter the author name here",
- }),
- },
- editor.Field{
- View: editor.Tags("Category", p, map[string]string{
- "label": "Post Categories",
- }),
- },
- editor.Field{
- View: editor.Select("Theme", p, map[string]string{
- "label": "Theme Style",
- }, map[string]string{
- "dark": "Dark",
- "light": "Light",
- }),
- },
- )
-
- if err != nil {
- return nil, fmt.Errorf("Failed to render Post editor view: %s", err.Error())
- }
-
- return view, nil
-}
-
-func init() {
- Types["Post"] = func() interface{} { return new(Post) }
-}
-
-// ContentName is required to set the display name for a piece of content in the editor
-// Partially implements editor.Editable
-func (p *Post) ContentName() string { return p.Title }
-
-// Editor is a buffer of bytes for the Form function to write input views
-// partially implements editor.Editable
-func (p *Post) Editor() *editor.Editor { return &p.editor }