make news populate id, add edit del links
This commit is contained in:
parent
470b011ded
commit
fddf4b5045
22
news/news.go
22
news/news.go
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type News struct {
|
type News struct {
|
||||||
news_id int
|
id int
|
||||||
Url string
|
Url string
|
||||||
Title string
|
Title string
|
||||||
Category_id int
|
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
|
// 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
|
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 {
|
if err != nil {
|
||||||
fmt.Println("DB errpr reading LoadPage news: ", err)
|
fmt.Println("DB errpr reading LoadPage news: ", err)
|
||||||
return nil, 0, 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) {
|
func Unexported(db *sql.DB) (map[int]*NewsContainer, int, error) {
|
||||||
categories.LoadCategories(db) // required by addContainer
|
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 {
|
if err != nil {
|
||||||
fmt.Println("DB errpr reading unexported news: ", err)
|
fmt.Println("DB errpr reading unexported news: ", err)
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -93,14 +93,14 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, int, error) {
|
||||||
return convertSqlToNewsContainer(rows)
|
return convertSqlToNewsContainer(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertSqlToNews(rows *sql.Rows) ([]News, int, error) {
|
func convertSqlToNews(rows *sql.Rows) ([]*News, int, error) {
|
||||||
news := []News{}
|
news := []*News{}
|
||||||
count := 0
|
count := 0
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
newsItem := News{}
|
newsItem := &News{}
|
||||||
var url, title, notes sql.NullString
|
var url, title, notes sql.NullString
|
||||||
var category_id sql.NullInt64
|
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 {
|
if err != nil {
|
||||||
fmt.Println("Error reading news from DB: " + err.Error())
|
fmt.Println("Error reading news from DB: " + err.Error())
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -132,7 +132,7 @@ func convertSqlToNewsContainer(rows *sql.Rows) (map[int]*NewsContainer, int, err
|
||||||
news := News{}
|
news := News{}
|
||||||
var url, title, notes sql.NullString
|
var url, title, notes sql.NullString
|
||||||
var category_id sql.NullInt64
|
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 {
|
if err != nil {
|
||||||
fmt.Println("Error reading news from DB: " + err.Error())
|
fmt.Println("Error reading news from DB: " + err.Error())
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -174,3 +174,7 @@ func MarkExported(db *sql.DB) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (news *News) Id() int {
|
||||||
|
return news.id
|
||||||
|
}
|
|
@ -28,12 +28,12 @@
|
||||||
<div class="col-xs-8">
|
<div class="col-xs-8">
|
||||||
<a href="{{.post.Url}}">{{truncate .post.Url 100}}</a>
|
<a href="{{.post.Url}}">{{truncate .post.Url 100}}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-2"> </div>
|
<div class="col-xs-2"><a href="/edit/{{.post.Id}}">Edit</a></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-2"> </div>
|
<div class="col-xs-2"> </div>
|
||||||
<div class="col-xs-8">{{truncate .post.Notes 500}}</div>
|
<div class="col-xs-8">{{truncate .post.Notes 500}}</div>
|
||||||
<div class="col-xs-2"> </div>
|
<div class="col-xs-2"><a class="delete" href="/delete/{{.post.Id}}">Delete</a></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in New Issue