Add further support for clicks counter

This commit is contained in:
Jason Streifling 2024-12-27 10:52:57 +01:00
parent 82faacb9ec
commit 376a1264f5
2 changed files with 13 additions and 1 deletions

View File

@ -50,6 +50,17 @@ func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
return
}
fmt.Fprint(w, content)
article.Clicks++
if err = db.UpdateAttributes(&b.Attribute{Table: "articles", ID: article.ID, AttName: "clicks", Value: article.Clicks}); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if _, err = fmt.Fprint(w, content); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}

View File

@ -35,6 +35,7 @@ CREATE TABLE articles (
creator_id INT NOT NULL,
issue_id INT NOT NULL,
edited_id INT,
clicks INT NOT NULL,
is_in_issue BOOL NOT NULL,
auto_generated BOOL NOT NULL,
PRIMARY KEY (id),