From 9db0046fadcd703d9903c7abd4159ded0730bf3a Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 3 Nov 2016 00:54:13 -0700 Subject: simplifying Editable interface by adding Sluggable and Identifiable interfaces, moving relevant interface methods to be implemented by other types and updating caller code to assert the new interface types as needed --- system/admin/config/config.go | 9 --------- system/admin/handlers.go | 20 +++++++++++++------- system/db/content.go | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) (limited to 'system') diff --git a/system/admin/config/config.go b/system/admin/config/config.go index 66f767d..ba8ffb3 100644 --- a/system/admin/config/config.go +++ b/system/admin/config/config.go @@ -18,18 +18,9 @@ type Config struct { CacheInvalidate []string `json:"-"` } -// SetContentID partially implements editor.Editable -func (c *Config) SetContentID(id int) { c.ID = id } - -// ContentID partially implements editor.Editable -func (c *Config) ContentID() int { return c.ID } - // ContentName partially implements editor.Editable func (c *Config) ContentName() string { return c.Name } -// SetSlug partially implements editor.Editable -func (c *Config) SetSlug(slug string) { c.Slug = slug } - // Editor partially implements editor.Editable func (c *Config) Editor() *editor.Editor { return &c.editor } diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 12750e2..18faec9 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -752,10 +752,10 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { // adminPostListItem is a helper to create the li containing a post. // p is the asserted post as an Editable, t is the Type of the post. // specifier is passed to append a name to a namespace like _pending -func adminPostListItem(p editor.Editable, t, status string) []byte { - s, ok := p.(editor.Sortable) +func adminPostListItem(e editor.Editable, typeName, status string) []byte { + s, ok := e.(editor.Sortable) if !ok { - log.Println("Content type", t, "doesn't implement editor.Sortable") + log.Println("Content type", typeName, "doesn't implement editor.Sortable") post := `
  • Error retreiving data. Your data type doesn't implement necessary interfaces.
  • ` return []byte(post) } @@ -766,7 +766,7 @@ func adminPostListItem(p editor.Editable, t, status string) []byte { updatedTime := upTime.Format("01/02/06 03:04 PM") publishTime := tsTime.Format("01/02/06") - cid := fmt.Sprintf("%d", p.ContentID()) + cid := fmt.Sprintf("%d", s.ItemID()) switch status { case "public", "": @@ -777,14 +777,14 @@ func adminPostListItem(p editor.Editable, t, status string) []byte { post := `
  • - ` + p.ContentName() + ` + ` + e.ContentName() + ` Updated: ` + updatedTime + ` ` + publishTime + `
    Delete - +
  • ` @@ -940,7 +940,13 @@ func editHandler(res http.ResponseWriter, req *http.Request) { return } } else { - post.(editor.Editable).SetContentID(-1) + s, ok := post.(content.Identifiable) + if !ok { + log.Println("Content type", typeName, "doesn't implement editor.Sortable") + return + } + s.SetContentID(-1) + } m, err := manager.Manage(post.(editor.Editable), t) diff --git a/system/db/content.go b/system/db/content.go index cfbd4ef..b43d611 100644 --- a/system/db/content.go +++ b/system/db/content.go @@ -381,7 +381,7 @@ func postToJSON(ns string, data url.Values) ([]byte, error) { if err != nil { return nil, err } - post.(editor.Editable).SetSlug(slug) + post.(content.Sluggable).SetSlug(slug) // marshall content struct to json for db storage j, err := json.Marshal(post) -- cgit v1.2.3