Version: 0.2.5.dev.260211

feat: 🗑️ 新增删除任务类接口并实现级联删除

- 通过 task_class 与 task_item 两张表建立级联关系 🔗
- 删除 task_class 时自动删除关联的 task_item
- 保证数据一致性,避免产生孤立数据 
This commit is contained in:
LoveLosita
2026-02-11 18:44:13 +08:00
parent a2da9a2aa4
commit e5a4114202
5 changed files with 70 additions and 0 deletions

View File

@@ -218,3 +218,16 @@ func (dao *TaskClassDAO) DeleteTaskClassItemByID(ctx context.Context, id int) er
Delete(&model.TaskClassItem{}).Error
return err
}
func (dao *TaskClassDAO) DeleteTaskClassByID(ctx context.Context, id int) error {
res := dao.db.WithContext(ctx).
Where("id = ?", id).
Delete(&model.TaskClass{})
if res.Error != nil {
return res.Error
}
if res.RowsAffected == 0 {
return respond.WrongTaskClassID
}
return nil
}