From a4abe1424ab5aa2f2c8d21873476c24b252dd733 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 27 Aug 2015 08:01:37 -0700 Subject: [PATCH] fix news page listing bugs --- .gitignore | 1 + news/news.go | 20 ++++---------------- templates.go | 7 ++----- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 63160bd..17ac108 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Compiled Object files, Static and Dynamic libs (Shared Objects) transmet +db/dbconf.yml .project *~ *.o diff --git a/news/news.go b/news/news.go index 4fa35b0..6787832 100644 --- a/news/news.go +++ b/news/news.go @@ -69,7 +69,7 @@ func addContainer(category_id int, flat, tree map[int]*NewsContainer) { 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 category_id ASC") + rows, err := db.Query("SELECT 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 @@ -99,7 +99,7 @@ func convertSqlToNews(rows *sql.Rows) ([]News, int, error) { for rows.Next() { newsItem := News{} var url, title, notes sql.NullString - var date, category_id sql.NullInt64 + var category_id sql.NullInt64 err := rows.Scan(&url, &title, &category_id, &newsItem.Date, ¬es) if err != nil { fmt.Println("Error reading news from DB: " + err.Error()) @@ -109,13 +109,7 @@ func convertSqlToNews(rows *sql.Rows) ([]News, int, error) { newsItem.Url = nullStringToString(&url) newsItem.Title = nullStringToString(&title) newsItem.Notes = nullStringToString(¬es) - - if date.Valid { - newsItem.Date = time.Unix(date.Int64, 0) - } else { - newsItem.Date = time.Now() - } - + if category_id.Valid { newsItem.Category_id = int(category_id.Int64) } else { @@ -137,7 +131,7 @@ func convertSqlToNewsContainer(rows *sql.Rows) (map[int]*NewsContainer, int, err for rows.Next() { news := News{} var url, title, notes sql.NullString - var date, category_id sql.NullInt64 + var category_id sql.NullInt64 err := rows.Scan(&url, &title, &category_id, &news.Date, ¬es) if err != nil { fmt.Println("Error reading news from DB: " + err.Error()) @@ -148,12 +142,6 @@ func convertSqlToNewsContainer(rows *sql.Rows) (map[int]*NewsContainer, int, err news.Title = nullStringToString(&title) news.Notes = nullStringToString(¬es) - if date.Valid { - news.Date = time.Unix(date.Int64, 0) - } else { - news.Date = time.Now() - } - if category_id.Valid { news.Category_id = int(category_id.Int64) } else { diff --git a/templates.go b/templates.go index 80ec0d8..1552cbc 100644 --- a/templates.go +++ b/templates.go @@ -49,12 +49,9 @@ func dateFormat(t time.Time) string { // takes a category_id and returns "Root / Parent / Category" func fullCategoryPath(categoriesFlat map[int]*categories.Category, category_id int) string { - fmt.Println("fullCategoryPath: ", category_id) var categoryNames []string = nil - var category *categories.Category = categoriesFlat[category_id] - for ; category.Parent.Valid; category = categoriesFlat[int(category.Parent.Int64)] { - fmt.Println("fullCategoryPath LOOP: ", category.Name) - categoryNames = append(categoryNames, category.Name) + for category := categoriesFlat[category_id]; category != nil; category = categoriesFlat[int(category.Parent.Int64)] { + categoryNames = append([]string{category.Name}, categoryNames...) } return strings.Join(categoryNames, " / ") }