From 7da98fb2abdf9f385366d145cf9f2c77caaaa022 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sat, 1 Mar 2025 09:42:15 +0100 Subject: [PATCH] Check if content exists before adding article to DB --- cmd/frontend/articles.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/frontend/articles.go b/cmd/frontend/articles.go index 6e417c7..2bee14f 100644 --- a/cmd/frontend/articles.go +++ b/cmd/frontend/articles.go @@ -155,13 +155,6 @@ func SubmitArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFun return } - article.ID, err = db.AddArticle(article) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - content := []byte(r.PostFormValue("article-content")) if len(content) == 0 { http.Error(w, "Bitte den Artikel eingeben.", http.StatusBadRequest) @@ -173,6 +166,13 @@ func SubmitArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFun return } + article.ID, err = db.AddArticle(article) + if err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + if err = db.WriteArticleAuthors(article.ID, authors); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError)