diff --git a/cmd/backend/articles.go b/cmd/backend/articles.go index 656e71e..e8c5802 100644 --- a/cmd/backend/articles.go +++ b/cmd/backend/articles.go @@ -257,11 +257,23 @@ func (db *DB) AddArticleToCurrentIssue(id int64) error { func (db *DB) DeleteArticle(id int64) error { articlesTagsQuery := "DELETE FROM articles_tags WHERE article_id = ?" + articlesContributorsQuery := "DELETE FROM articles_contributors WHERE article_id = ?" + articlesAuthorsQuery := "DELETE FROM articles_authors WHERE article_id = ?" articlesQuery := "DELETE FROM articles WHERE id = ?" _, err := db.Exec(articlesTagsQuery, id) if err != nil { - return fmt.Errorf("error deleting article %v from DB: %v", id, err) + return fmt.Errorf("error deleting articles_tags %v from DB: %v", id, err) + } + + _, err = db.Exec(articlesContributorsQuery, id) + if err != nil { + return fmt.Errorf("error deleting articles_contributors %v from DB: %v", id, err) + } + + _, err = db.Exec(articlesAuthorsQuery, id) + if err != nil { + return fmt.Errorf("error deleting articles_authors %v from DB: %v", id, err) } _, err = db.Exec(articlesQuery, id) diff --git a/cmd/backend/articles_authors.go b/cmd/backend/articles_authors.go index 2b5d451..0f4ef9e 100644 --- a/cmd/backend/articles_authors.go +++ b/cmd/backend/articles_authors.go @@ -112,14 +112,3 @@ func (db *DB) UpdateArticleAuthors(articleID int64, authorIDs []int64) error { } return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries) } - -func (db *DB) DeleteArticleAuthors(articleID int64) error { - query := "DELETE FROM articles_authors WHERE article_id = ?" - - _, err := db.Exec(query, articleID) - if err != nil { - return fmt.Errorf("error deleting articles_authors %v from DB: %v", articleID, err) - } - - return nil -} diff --git a/cmd/backend/articles_contributors.go b/cmd/backend/articles_contributors.go index 4f6182d..696c606 100644 --- a/cmd/backend/articles_contributors.go +++ b/cmd/backend/articles_contributors.go @@ -112,14 +112,3 @@ func (db *DB) UpdateArticleContributors(articleID int64, contributorIDs []int64) } return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries) } - -func (db *DB) DeleteArticleContributors(articleID int64) error { - query := "DELETE FROM articles_contributors WHERE article_id = ?" - - _, err := db.Exec(query, articleID) - if err != nil { - return fmt.Errorf("error deleting articles_contributors %v from DB: %v", articleID, err) - } - - return nil -} diff --git a/cmd/frontend/articles.go b/cmd/frontend/articles.go index be873e4..5d768a3 100644 --- a/cmd/frontend/articles.go +++ b/cmd/frontend/articles.go @@ -590,18 +590,6 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return } - if err = db.DeleteArticleContributors(oldArticle.ID); err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if err = db.DeleteArticleAuthors(oldArticle.ID); err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - if err = db.DeleteArticle(oldArticle.ID); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError)