fix(仓储): 修复软删除过滤与事务测试

修复软删除拦截器使用错误,确保默认查询过滤已删记录
仓储层改用 ent.Tx 与扫描辅助,避免 sql.Tx 断言问题
同步更新集成测试以覆盖事务与统计变动
This commit is contained in:
yangjianbo
2025-12-29 19:23:49 +08:00
parent b436da7249
commit ae191f72a4
20 changed files with 565 additions and 326 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"time"
"github.com/Wei-Shaw/sub2api/ent/intercept"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
@@ -79,16 +80,13 @@ func SkipSoftDelete(parent context.Context) context.Context {
// 确保软删除的记录不会出现在普通查询结果中。
func (d SoftDeleteMixin) Interceptors() []ent.Interceptor {
return []ent.Interceptor{
ent.TraverseFunc(func(ctx context.Context, q ent.Query) error {
intercept.TraverseFunc(func(ctx context.Context, q intercept.Query) error {
// 检查是否需要跳过软删除过滤
if skip, _ := ctx.Value(softDeleteKey{}).(bool); skip {
return nil
}
// 为查询添加 deleted_at IS NULL 条件
w, ok := q.(interface{ WhereP(...func(*sql.Selector)) })
if ok {
d.applyPredicate(w)
}
d.applyPredicate(q)
return nil
}),
}