fix news page listing bugs
This commit is contained in:
parent
6438250ef7
commit
a4abe1424a
|
@ -1,5 +1,6 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
transmet
|
||||
db/dbconf.yml
|
||||
.project
|
||||
*~
|
||||
*.o
|
||||
|
|
20
news/news.go
20
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 {
|
||||
|
|
|
@ -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, " / ")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue