Compare commits

...

2 Commits

Author SHA1 Message Date
523bdb24cd Cleanup 2024-12-27 10:53:06 +01:00
376a1264f5 Add further support for clicks counter 2024-12-27 10:52:57 +01:00
3 changed files with 21 additions and 8 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

@ -121,6 +121,7 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
Rejected: false,
IsInIssue: r.PostFormValue("issue") == "on",
AutoGenerated: false,
EditedID: 0,
}
if len(article.Title) == 0 {

View File

@ -34,7 +34,8 @@ CREATE TABLE articles (
rejected BOOL NOT NULL,
creator_id INT NOT NULL,
issue_id INT NOT NULL,
edited_id INT,
edited_id INT NOT NULL,
clicks INT NOT NULL,
is_in_issue BOOL NOT NULL,
auto_generated BOOL NOT NULL,
PRIMARY KEY (id),
@ -49,24 +50,24 @@ CREATE TABLE tags (
);
CREATE TABLE articles_authors (
article_id INT,
author_id INT,
article_id INT NOT NULL,
author_id INT NOT NULL,
PRIMARY KEY (article_id, author_id),
FOREIGN KEY (article_id) REFERENCES articles (id),
FOREIGN KEY (author_id) REFERENCES users (id)
);
CREATE TABLE articles_contributors (
article_id INT,
contributor_id INT,
article_id INT NOT NULL,
contributor_id INT NOT NULL,
PRIMARY KEY (article_id, contributor_id),
FOREIGN KEY (article_id) REFERENCES articles (id),
FOREIGN KEY (contributor_id) REFERENCES users (id)
);
CREATE TABLE articles_tags (
article_id INT,
tag_id INT,
article_id INT NOT NULL,
tag_id INT NOT NULL,
PRIMARY KEY (article_id, tag_id),
FOREIGN KEY (article_id) REFERENCES articles (id),
FOREIGN KEY (tag_id) REFERENCES tags (id)