add delete endpoint for blog articles

Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
2026-05-24 09:23:02 +02:00
parent f327509f5e
commit bf391ed7d5
3 changed files with 61 additions and 0 deletions
+37
View File
@@ -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)