We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8ab30a4 commit 7f481bcCopy full SHA for 7f481bc
internal/app/repository/category_repository.go
@@ -84,15 +84,16 @@ func (cr CategoryRepository) BatchDeleteCategoryByIds(categoryIds []string) erro
84
if err != nil {
85
return err
86
}
87
- j := 0
+ // 校验分类是否可以删除
88
for _, category := range categorys {
89
- if category.ID != known.DEFAULT_ID && !isPID(int64((category.ID))) {
90
- categorys[j] = category
91
- j++
+ if category.ID == known.DEFAULT_ID {
+ return errors.New("默认分类不允许删除")
+ }
92
+ if isPID(int64(category.ID)) {
93
+ return errors.New("该分类下包含子分类,请先删除子分类")
94
95
- // Slice categorys to new size.
- categorys = categorys[:j]
96
+
97
err = common.DB.Unscoped().Delete(&categorys).Error
98
99
0 commit comments