Let the article deletion logic happen entirely in the backend

This commit is contained in:
Jason Streifling 2024-12-27 10:40:34 +01:00
parent 7f85b60916
commit 82faacb9ec
4 changed files with 13 additions and 35 deletions

View File

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

View File

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

View File

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

View File

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