refactor(b1b-c3): 聚合体路由由 spec 声明 —— 控制器零硬编码实体名

- TableSpec 增字段 aggregate_detail: bool
- Resource / Dataset 置 true,其余 16 个置 false
- controller/crud.rs 删掉 find("Resource")/find("Dataset") + expect,改为遍历 ALL_SPECS 按 flag 注册
- 补单测 aggregate_detail_is_pinned_to_the_resource_side(聚合体 ⊆ 有子表)
- 边界账本删掉已失效的两条 CP3(controller/crud.rs find(...))
This commit is contained in:
admin committed 2026-10-26 20:26:19 +08:00
1 parent c4840a3aa2
commit 8b4721601f
21 files changed
+62 -35

No files matched your search

-2
View File
@@ -16,6 +16,4 @@ CP1 auth.rs /api/ssw/tdc/ C5:白名单清单待归业务层 src/tdc/support/pu
CP1 db.rs tdc_identity C4:schema 探针待通用化(改查 pg_catalog.pg_tables) B1b
CP2 session.rs Identity 假阳性:SessionKind::Identity 是**会话口径**,不是业务实体 tdc_identity 永久
CP2 auth.rs SessionKind::Identity 假阳性:Principal::Session 分支里的会话种类,不是业务实体 永久
CP3 controller/crud.rs find("Resource") C3:聚合详情注册待改成遍历 spec B1b
CP3 controller/crud.rs find("Dataset") C3:聚合详情注册待改成遍历 spec B1b
CP4 auth.rs /api/ C5:白名单清单待归业务层(含 /api/oauth/Login 与 /api/health 两条) B1b
+19 -33
View File
@@ -94,43 +94,29 @@ pub fn router() -> Router<AppState> {
}
// ------------------------------------------------------------------
// 资源侧只读聚合体(上游 `ResourceController#detailOf` / `DatasetController#detailOf`)
// 只读聚合体(上游 `ResourceController#detailOf` / `DatasetController#detailOf`)
//
// 🔴 路径里的 `{id}` 与上面的 `/{Entity}/{id}` **同层并存** ——
// matchit 允许「参数段 + 更深的静态段」,静态段优先匹配,无冲突。
// 🔴 **零硬编码实体名**:注册哪些聚合体由 `TableSpec::aggregate_detail` 决定
// (v3 spec §2.3.1 C3)⇒ 控制器只**遍历 spec**。
// 🔴 `Dataset` 在注册表里 `table = "tdc_resource"`(只读视图)⇒ 聚合体与 Resource 同源。
{
let res_spec: &'static TableSpec =
entity::find("Resource").expect("Resource 必须在注册表里");
let ds_spec: &'static TableSpec =
entity::find("Dataset").expect("Dataset 必须在注册表里");
r = r
.route(
&format!("{}/{{id}}/Detail", res_spec.path),
get(
move |Path(id): Path<String>,
State(st): State<AppState>,
p: Option<Extension<Principal>>| {
let principal = p.map(|e| e.0);
async move {
crud::detail_aggregate(&st, res_spec, &id, principal.as_ref()).await
}
},
),
)
.route(
&format!("{}/{{id}}/Detail", ds_spec.path),
get(
move |Path(id): Path<String>,
State(st): State<AppState>,
p: Option<Extension<Principal>>| {
let principal = p.map(|e| e.0);
async move {
crud::detail_aggregate(&st, ds_spec, &id, principal.as_ref()).await
}
},
),
);
for spec in entity::ALL_SPECS {
if !spec.aggregate_detail {
continue;
}
let s: &'static TableSpec = spec;
r = r.route(
&format!("{}/{{id}}/Detail", s.path),
get(
move |Path(id): Path<String>,
State(st): State<AppState>,
p: Option<Extension<Principal>>| {
let principal = p.map(|e| e.0);
async move { crud::detail_aggregate(&st, s, &id, principal.as_ref()).await }
},
),
);
}
r
}
+1
View File
@@ -33,4 +33,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -29,4 +29,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -34,4 +34,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -30,4 +30,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &["secretKey"],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -23,4 +23,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -26,4 +26,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[("fieldRules", "tdc_resource_field"), ("maskRules", "tdc_resource_mask_rule")],
not_found_msg: "数据集不存在或资源已删除",
aggregate_detail: true,
};
+1
View File
@@ -28,4 +28,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -25,4 +25,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -47,4 +47,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &["devUrl", "devToken"],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -25,4 +25,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -37,4 +37,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &["secretKey"],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+25
View File
@@ -105,6 +105,12 @@ pub struct TableSpec {
/// 🔴 引擎**零 `match api_name`** ⇒ 文案由**业务 spec 声明**
/// (v3 spec §2.3.1 C2;与技能 `EntitySpec.creator_fixed` 同一手法)。
pub not_found_msg: &'static str,
/// 是否注册**只读聚合体**路由 `GET {path}/{id}/Detail`(上游 `ResourceController#detailOf` /
/// `DatasetController#detailOf`)。
///
/// 🔴 引擎**零硬编码实体名** ⇒ 控制器**遍历 spec** 决定注册哪条
/// (v3 spec §2.3.1 C3)。聚合体里挂哪些子表由 [`TableSpec::child_tables`] 决定。
pub aggregate_detail: bool,
}
/// `DeliveryTask` 的 41 个服务端权威列。
@@ -544,6 +550,25 @@ mod tests {
assert_eq!(find("Product").unwrap().tenant_column, Some("f_tenant_id"));
}
/// 🔴 **聚合体路由的注册口径**(C3):只有资源侧两个实体有 `/Detail`,
/// 且**开了聚合体就必须有子表**(否则聚合体与普通详情无异 ⇒ 白开一条路由)。
#[test]
fn aggregate_detail_is_pinned_to_the_resource_side() {
let agg: Vec<&str> = ALL_SPECS
.iter()
.filter(|s| s.aggregate_detail)
.map(|s| s.api_name)
.collect();
assert_eq!(agg, vec!["Dataset", "Resource"]);
for s in ALL_SPECS.iter().filter(|s| s.aggregate_detail) {
assert!(
!s.child_tables.is_empty(),
"{} 开了聚合体却没有子表",
s.api_name
);
}
}
/// 🔴 **不外泄字段清单**(上游 `@JsonIgnore`)**字面钉住**。
///
/// 上游全仓只有 **3 个属性**标了 `@JsonIgnore`(2026-10-25 核对 `ssw-tdc-entity`):
+1
View File
@@ -28,4 +28,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -32,4 +32,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -25,4 +25,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -26,4 +26,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -21,4 +21,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -32,4 +32,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[],
not_found_msg: "记录不存在或已删除",
aggregate_detail: false,
};
+1
View File
@@ -31,4 +31,5 @@ pub const SPEC: TableSpec = TableSpec {
hidden_fields: &[],
child_tables: &[("fieldRules", "tdc_resource_field"), ("maskRules", "tdc_resource_mask_rule")],
not_found_msg: "记录不存在或已删除",
aggregate_detail: true,
};