Set pubDate to published time and date

This commit is contained in:
Jason Streifling 2024-03-17 09:41:09 +01:00
parent ceab7281e9
commit 4fffc1c696
2 changed files with 5 additions and 3 deletions

View File

@ -23,8 +23,8 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
` `
result, err := db.Exec(query, a.Title, a.Description, a.Content, a.Published, result, err := db.Exec(query, a.Title, a.Description, a.Content,
a.Rejected, a.AuthorID) a.Published, a.Rejected, a.AuthorID)
if err != nil { if err != nil {
return 0, fmt.Errorf("error inserting article into DB: %v", err) return 0, fmt.Errorf("error inserting article into DB: %v", err)
} }

View File

@ -5,6 +5,7 @@ import (
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
"time"
"streifling.com/jason/cpolis/cmd/control" "streifling.com/jason/cpolis/cmd/control"
"streifling.com/jason/cpolis/cmd/model" "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 { func ShowRejectedArticles(db *model.DB, s *control.CookieStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
type htmlData struct { type htmlData struct {
RejectedArticles []*model.Article
MyIDs map[int64]bool MyIDs map[int64]bool
RejectedArticles []*model.Article
} }
data := new(htmlData) data := new(htmlData)
@ -274,6 +275,7 @@ func PublishArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
if err = db.UpdateAttributes( if err = db.UpdateAttributes(
&model.Attribute{Table: "articles", ID: id, AttName: "published", Value: true}, &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: "rejected", Value: false},
&model.Attribute{Table: "articles", ID: id, AttName: "created", Value: time.Now().Format("2006-01-02 15:04:05")},
); err != nil { ); err != nil {
log.Println(err) log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)