From 4fffc1c696d030dab9e7cdc16bc8fa1798f46fc2 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sun, 17 Mar 2024 09:41:09 +0100 Subject: [PATCH] Set pubDate to published time and date --- cmd/model/articles.go | 4 ++-- cmd/view/articles.go | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/model/articles.go b/cmd/model/articles.go index 38737a9..4866bcb 100644 --- a/cmd/model/articles.go +++ b/cmd/model/articles.go @@ -23,8 +23,8 @@ func (db *DB) AddArticle(a *Article) (int64, error) { VALUES (?, ?, ?, ?, ?, ?) ` - result, err := db.Exec(query, a.Title, a.Description, a.Content, a.Published, - a.Rejected, a.AuthorID) + result, err := db.Exec(query, a.Title, a.Description, a.Content, + a.Published, a.Rejected, a.AuthorID) if err != nil { return 0, fmt.Errorf("error inserting article into DB: %v", err) } diff --git a/cmd/view/articles.go b/cmd/view/articles.go index 05509c2..a69b78d 100644 --- a/cmd/view/articles.go +++ b/cmd/view/articles.go @@ -5,6 +5,7 @@ import ( "log" "net/http" "strconv" + "time" "streifling.com/jason/cpolis/cmd/control" "streifling.com/jason/cpolis/cmd/model" @@ -141,8 +142,8 @@ func ShowUnpublishedArticles(db *model.DB) http.HandlerFunc { func ShowRejectedArticles(db *model.DB, s *control.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { type htmlData struct { - RejectedArticles []*model.Article MyIDs map[int64]bool + RejectedArticles []*model.Article } data := new(htmlData) @@ -274,6 +275,7 @@ func PublishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc { if err = db.UpdateAttributes( &model.Attribute{Table: "articles", ID: id, AttName: "published", Value: true}, &model.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false}, + &model.Attribute{Table: "articles", ID: id, AttName: "created", Value: time.Now().Format("2006-01-02 15:04:05")}, ); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError)