From 168225daa21fe494bcd74ab6c90d6498ecf9f1e3 Mon Sep 17 00:00:00 2001 From: knotteye Date: Thu, 1 Jul 2021 20:26:49 -0500 Subject: Make news list links to full page news articles --- database.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'database.go') diff --git a/database.go b/database.go index 5fcebf0..037fde2 100644 --- a/database.go +++ b/database.go @@ -1504,6 +1504,9 @@ func getNewsFromDB(db *sql.DB) []NewsItem { for rows.Next() { n := NewsItem{} err = rows.Scan(&n.Title, &n.Content, &n.Time) + if CheckError(err, "error scanning news from db") != nil { + return make([]NewsItem, 0) + } news.PushBack(n) } @@ -1519,6 +1522,27 @@ func getNewsFromDB(db *sql.DB) []NewsItem { return anews } +func getNewsItemFromDB(db *sql.DB, timestamp int) (NewsItem, error) { + var news NewsItem + query := `select title, content, time from newsItem where time=$1 limit 1` + + rows, err := db.Query(query, timestamp) + + if err != nil { + return news, err + } + + defer rows.Close() + rows.Next() + err = rows.Scan(&news.Title, &news.Content, &news.Time) + + if err != nil { + return news, err + } + + return news, nil +} + func WriteNewsToDB(db *sql.DB, news NewsItem) { query := `insert into newsItem (title, content, time) values ($1, $2, $3)` -- cgit v1.2.3