fix(用户): 修复删除用户软删除钩子

避免软删除钩子类型断言失败导致 500\n删除无记录时返回未找到错误并记录日志
This commit is contained in:
yangjianbo
2025-12-29 16:57:50 +08:00
parent 5584709ac9
commit 4dab18a94f
3 changed files with 14 additions and 7 deletions

View File

@@ -169,8 +169,14 @@ func (r *userRepository) Update(ctx context.Context, userIn *service.User) error
}
func (r *userRepository) Delete(ctx context.Context, id int64) error {
_, err := r.client.User.Delete().Where(dbuser.IDEQ(id)).Exec(ctx)
return err
affected, err := r.client.User.Delete().Where(dbuser.IDEQ(id)).Exec(ctx)
if err != nil {
return translatePersistenceError(err, service.ErrUserNotFound, nil)
}
if affected == 0 {
return service.ErrUserNotFound
}
return nil
}
func (r *userRepository) List(ctx context.Context, params pagination.PaginationParams) ([]service.User, *pagination.PaginationResult, error) {