forked from jason/cpolis
		
	Let the article deletion logic happen entirely in the backend
This commit is contained in:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user