Let the article deletion logic happen entirely in the backend
This commit is contained in:
parent
7f85b60916
commit
82faacb9ec
@ -257,11 +257,23 @@ func (db *DB) AddArticleToCurrentIssue(id int64) error {
|
|||||||
|
|
||||||
func (db *DB) DeleteArticle(id int64) error {
|
func (db *DB) DeleteArticle(id int64) error {
|
||||||
articlesTagsQuery := "DELETE FROM articles_tags WHERE article_id = ?"
|
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 = ?"
|
articlesQuery := "DELETE FROM articles WHERE id = ?"
|
||||||
|
|
||||||
_, err := db.Exec(articlesTagsQuery, id)
|
_, err := db.Exec(articlesTagsQuery, id)
|
||||||
if err != nil {
|
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)
|
_, err = db.Exec(articlesQuery, id)
|
||||||
|
@ -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)
|
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
|
|
||||||
}
|
|
||||||
|
@ -112,14 +112,3 @@ func (db *DB) UpdateArticleContributors(articleID int64, contributorIDs []int64)
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
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
|
|
||||||
}
|
|
||||||
|
@ -590,18 +590,6 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
return
|
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 {
|
if err = db.DeleteArticle(oldArticle.ID); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user