From fddf4b504520eecb30a465be09768db0e7befb12 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Sun, 30 Aug 2015 20:48:55 -0700 Subject: [PATCH] make news populate id, add edit del links --- news/news.go | 22 +++++++++++++--------- templates/pages/news.html | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/news/news.go b/news/news.go index 6787832..253d6df 100644 --- a/news/news.go +++ b/news/news.go @@ -10,7 +10,7 @@ import ( ) type News struct { - news_id int + id int Url string Title string Category_id int @@ -66,10 +66,10 @@ func addContainer(category_id int, flat, tree map[int]*NewsContainer) { } // Load and return in NewsContainer format all the unexported news items -func LoadPage(db *sql.DB, offset, amount int) ([]News, int, error) { +func LoadPage(db *sql.DB, offset, amount int) ([]*News, int, error) { categories.LoadCategories(db) // required by addContainer - rows, err := db.Query("SELECT url, title, category_id, timestamp, notes FROM news WHERE exported is null order by timestamp DESC") + rows, err := db.Query("SELECT id, url, title, category_id, timestamp, notes FROM news WHERE exported is null order by timestamp DESC") if err != nil { fmt.Println("DB errpr reading LoadPage news: ", err) return nil, 0, err @@ -83,7 +83,7 @@ func LoadPage(db *sql.DB, offset, amount int) ([]News, int, error) { func Unexported(db *sql.DB) (map[int]*NewsContainer, int, error) { categories.LoadCategories(db) // required by addContainer - rows, err := db.Query("SELECT url, title, category_id, timestamp, notes FROM news WHERE exported is null order by category_id ASC") + rows, err := db.Query("SELECT id, url, title, category_id, timestamp, notes FROM news WHERE exported is null order by category_id ASC") if err != nil { fmt.Println("DB errpr reading unexported news: ", err) return nil, 0, err @@ -93,14 +93,14 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, int, error) { return convertSqlToNewsContainer(rows) } -func convertSqlToNews(rows *sql.Rows) ([]News, int, error) { - news := []News{} +func convertSqlToNews(rows *sql.Rows) ([]*News, int, error) { + news := []*News{} count := 0 for rows.Next() { - newsItem := News{} + newsItem := &News{} var url, title, notes sql.NullString var category_id sql.NullInt64 - err := rows.Scan(&url, &title, &category_id, &newsItem.Date, ¬es) + err := rows.Scan(&newsItem.id, &url, &title, &category_id, &newsItem.Date, ¬es) if err != nil { fmt.Println("Error reading news from DB: " + err.Error()) return nil, 0, err @@ -132,7 +132,7 @@ func convertSqlToNewsContainer(rows *sql.Rows) (map[int]*NewsContainer, int, err news := News{} var url, title, notes sql.NullString var category_id sql.NullInt64 - err := rows.Scan(&url, &title, &category_id, &news.Date, ¬es) + err := rows.Scan(&news.id, &url, &title, &category_id, &news.Date, ¬es) if err != nil { fmt.Println("Error reading news from DB: " + err.Error()) return nil, 0, err @@ -173,4 +173,8 @@ func MarkExported(db *sql.DB) error { fmt.Println("DB errror: news.MarkExported():", err) } return err +} + +func (news *News) Id() int { + return news.id } \ No newline at end of file diff --git a/templates/pages/news.html b/templates/pages/news.html index 0d727d5..a765f29 100644 --- a/templates/pages/news.html +++ b/templates/pages/news.html @@ -28,12 +28,12 @@
{{truncate .post.Url 100}}
-
 
+
Edit
 
{{truncate .post.Notes 500}}
-
 
+
{{end}}