Add ability to update tags when resubmitting article

This commit is contained in:
2024-03-28 07:29:49 +01:00
parent 548d2c6023
commit e82a0c6abe
2 changed files with 37 additions and 7 deletions

View File

@ -100,7 +100,7 @@ func ResubmitArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
description := r.PostFormValue("article-description")
content := r.PostFormValue("article-content")
if err := db.UpdateAttributes(
if err = db.UpdateAttributes(
&model.Attribute{Table: "articles", ID: id, AttName: "title", Value: title},
&model.Attribute{Table: "articles", ID: id, AttName: "description", Value: description},
&model.Attribute{Table: "articles", ID: id, AttName: "content", Value: content},
@ -111,6 +111,23 @@ func ResubmitArticle(db *model.DB, s *control.CookieStore) http.HandlerFunc {
return
}
r.ParseForm()
tags := make([]int64, 0)
for _, tag := range r.Form["tags"] {
tagID, err := strconv.ParseInt(tag, 10, 64)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tags = append(tags, tagID)
}
if err = db.UpdateArticleTags(id, tags); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
session, err := s.Get(r, "cookie")
if err != nil {
tmpl, err := template.ParseFiles("web/templates/login.html")