add delete endpoint for blog articles
Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
@@ -354,6 +354,43 @@ func (db *Database) SetBlogArticleStatus(id int64, status ArticleStatus) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *Database) DeleteBlogArticle(id int64) error {
|
||||
tx, err := db.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec("DELETE FROM blog_file WHERE article_id = ?", id)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec("DELETE FROM blog_article_to_tag WHERE article_id = ?", id)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := tx.Exec("DELETE FROM blog_article WHERE id = ?", id)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
affected, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
_ = tx.Rollback()
|
||||
return ErrNotFound
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (db *Database) GetBlogTags(showAll bool, offset int, limit int) ([]string, int64, error) {
|
||||
filter := ""
|
||||
filterArgs := make([]interface{}, 0)
|
||||
|
||||
Reference in New Issue
Block a user