Use ID in path rather than an invisible input when publishing, rejecting or resubmitting an article

This commit is contained in:
Jason Streifling 2024-04-01 15:30:24 +02:00
parent 7fc115bcc3
commit 0139f7ab9a
5 changed files with 12 additions and 13 deletions

View File

@ -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))

View File

@ -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)

View File

@ -8,7 +8,7 @@ body {
}
h2 {
@apply font-bold mb-2 mx-2 text-2xl;
@apply font-bold mb-2 text-2xl;
}
form {

View File

@ -13,7 +13,6 @@
<label for="article-content">Artikel</label>
<textarea name="article-content" placeholder="Artikel">{{.Article.Content}}</textarea>
</div>
<input name="article-id" type="hidden" value="{{.Article.ID}}" />
<div class="flex gap-4">
{{range .Tags}}
@ -31,7 +30,8 @@
</div>
<div class="btn-area">
<input class="action-btn" type="submit" value="Senden" hx-post="/resubmit-article/" hx-target="#page-content" />
<input class="action-btn" type="submit" value="Senden" hx-post="/resubmit-article/{{.Article.ID}}/"
hx-target="#page-content" />
<button class="btn" hx-get="/hub/" hx-target="#page-content">Zurück</button>
</div>
</form>

View File

@ -10,12 +10,11 @@
{{end}}
</p>
<input name="id" type="hidden" value="{{.Article.ID}}" />
<div class="btn-area">
<input class="action-btn" type="submit" value="Veröffentlichen" hx-post="/publish-article/"
<input class="action-btn" type="submit" value="Veröffentlichen" hx-post="/publish-article/{{.Article.ID}}/"
hx-target="#page-content" />
<input class="btn" type="submit" value="Ablehnen" hx-post="/reject-article/{{.Article.ID}}/"
hx-target="#page-content" />
<input class="btn" type="submit" value="Ablehnen" hx-post="/reject-article/" hx-target="#page-content" />
<button class="btn" hx-get="/hub/" hx-target="#page-content">Zurück</button>
</div>
</form>