From 0139f7ab9ab3825811d2e258cd5286568a5356cb Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Mon, 1 Apr 2024 15:30:24 +0200 Subject: [PATCH] Use ID in path rather than an invisible input when publishing, rejecting or resubmitting an article --- cmd/main.go | 6 +++--- cmd/view/articles.go | 6 +++--- web/static/css/input.css | 2 +- web/templates/rework-article.html | 4 ++-- web/templates/to-be-published.html | 7 +++---- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 8aed844..79edb58 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -69,9 +69,9 @@ func main() { mux.HandleFunc("POST /add-tag/", view.AddTag(args, db, store)) mux.HandleFunc("POST /add-user/", view.AddUser(args, db, store)) mux.HandleFunc("POST /login/", view.Login(args, db, store)) - mux.HandleFunc("POST /publish-article/", view.PublishArticle(args, db, store)) - mux.HandleFunc("POST /reject-article/", view.RejectArticle(args, db, store)) - mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(args, db, store)) + mux.HandleFunc("POST /publish-article/{id}/", view.PublishArticle(args, db, store)) + mux.HandleFunc("POST /reject-article/{id}/", view.RejectArticle(args, db, store)) + mux.HandleFunc("POST /resubmit-article/{id}/", view.ResubmitArticle(args, db, store)) mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(args, db, store)) mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(args, db, store)) mux.HandleFunc("POST /submit-article/", view.SubmitArticle(args, db, store)) diff --git a/cmd/view/articles.go b/cmd/view/articles.go index ac13cca..7633102 100644 --- a/cmd/view/articles.go +++ b/cmd/view/articles.go @@ -92,7 +92,7 @@ func SubmitArticle(c *control.CliArgs, db *model.DB, s *control.CookieStore) htt func ResubmitArticle(c *control.CliArgs, db *model.DB, s *control.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - id, err := strconv.ParseInt(r.PostFormValue("article-id"), 10, 64) + id, err := strconv.ParseInt(r.PathValue("id"), 10, 64) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -278,7 +278,7 @@ func ReviewRejectedArticle(c *control.CliArgs, db *model.DB, s *control.CookieSt func PublishArticle(c *control.CliArgs, db *model.DB, s *control.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64) + id, err := strconv.ParseInt(r.PathValue("id"), 10, 64) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -333,7 +333,7 @@ func PublishArticle(c *control.CliArgs, db *model.DB, s *control.CookieStore) ht func RejectArticle(c *control.CliArgs, db *model.DB, s *control.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - id, err := strconv.ParseInt(r.PostFormValue("id"), 10, 64) + id, err := strconv.ParseInt(r.PathValue("id"), 10, 64) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/web/static/css/input.css b/web/static/css/input.css index 85bc705..1bf2e9f 100644 --- a/web/static/css/input.css +++ b/web/static/css/input.css @@ -8,7 +8,7 @@ body { } h2 { - @apply font-bold mb-2 mx-2 text-2xl; + @apply font-bold mb-2 text-2xl; } form { diff --git a/web/templates/rework-article.html b/web/templates/rework-article.html index 2785734..6bd4c72 100644 --- a/web/templates/rework-article.html +++ b/web/templates/rework-article.html @@ -13,7 +13,6 @@ -
{{range .Tags}} @@ -31,7 +30,8 @@
- +
diff --git a/web/templates/to-be-published.html b/web/templates/to-be-published.html index 74b871a..fa9226c 100644 --- a/web/templates/to-be-published.html +++ b/web/templates/to-be-published.html @@ -10,12 +10,11 @@ {{end}}

- -
- + -