Skip to content

feat(cases): add role-filtered deterministic case summaries - #142

Merged
cg8-5712 merged 3 commits into
mainfrom
feature/issue-30-role-filtered-case-summary
Jul 28, 2026
Merged

cg8-5712 merged 3 commits into
mainfrom
feature/issue-30-role-filtered-case-summary

Conversation

@cg8-5712

@cg8-5712 cg8-5712 commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator
  • Add GET /api/cases/{case_id}/summary endpoint
  • Classify confirmed, pending, and excluded clues by review status
  • Restrict summary data, tasks, and focus areas by case role
  • Include generation time, source scope, and safety reminders
  • Add summary response models and service module
  • Document endpoint and schemas in API and OpenAPI specs
  • Add API and OpenAPI contract coverage for role-filtered summaries

close #30

Summary by CodeRabbit

  • 新功能
    • 新增“案件确定性摘要”接口(GET /api/cases/{case_id}/summary),按访问角色返回:已确认线索、待核实事项、排除方向、当前关注与任务状态、安全提醒及生成时间。
    • 摘要以确定性规则生成,并提供数据来源范围,用于界定可见信息范围。
  • 文档
    • 更新接口文档与 OpenAPI:新增接口与 CaseSummary 相关字段/结构说明。
  • 测试
    • 新增多角色集成测试及接口契约校验,覆盖默认与缺失内容场景。
  • 改进
    • 地图视图的任务汇总获取逻辑优化,提升一致性。

- Add GET /api/cases/{case_id}/summary endpoint
- Classify confirmed, pending, and excluded clues by review status
- Restrict summary data, tasks, and focus areas by case role
- Include generation time, source scope, and safety reminders
- Add summary response models and service module
- Document endpoint and schemas in API and OpenAPI specs
- Add API and OpenAPI contract coverage for role-filtered summaries
Copilot AI review requested due to automatic review settings July 28, 2026 03:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ff8d388-2a27-4bb6-bafd-bc13f6311bea

📥 Commits

Reviewing files that changed from the base of the PR and between 575a75a and 3d3c06f.

📒 Files selected for processing (1)
  • src/application/services/task_service.rs

📝 Walkthrough

Walkthrough

Changes

新增 GET /api/cases/{case_id}/summary,聚合案件线索与当前可见任务,按指挥、家属和志愿者角色返回确定性摘要,并补充响应模型、OpenAPI 文档、路由及集成测试。

案件摘要 API

Layer / File(s) Summary
摘要契约与数据结构
docs/API.md, docs/openapi.yaml, src/api/models.rs, src/application/services/mod.rs
新增摘要字段、角色裁剪规则、OpenAPI schema 和公开服务模块。
任务可见性与摘要聚合
src/application/services/task_service.rs, src/application/services/case_summary_service.rs, src/api/routes/cases.rs
统一加载全部可见任务,并按角色和线索审核状态生成确认线索、待核实事项、已排除方向、当前重点、任务状态、来源范围及安全提醒。
路由接入与接口验证
src/api/routes/cases.rs, tests/api/case_summary_get.rs, tests/api/openapi_intake_contract.rs, tests/api/mod.rs
注册摘要端点,验证角色可见内容、确定性空结果、Learner 访问限制及 OpenAPI 契约。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant CasesRoute
  participant CaseSummaryService
  participant CaseService
  participant TaskService
  Client->>CasesRoute: GET /api/cases/{case_id}/summary
  CasesRoute->>CaseSummaryService: get_case_summary(case_id, auth)
  CaseSummaryService->>CaseService: get_case(case_id)
  CaseSummaryService->>TaskService: list_all_visible_tasks(case_id, auth)
  TaskService->>TaskService: load_visible_tasks
  CaseSummaryService-->>CasesRoute: role-filtered CaseSummaryResponse
  CasesRoute-->>Client: 200 JSON response
Loading

Possibly related PRs

  • AG-Angui/Angui#130:引入摘要服务复用的任务列表和任务可见性能力。
  • AG-Angui/Angui#141:与本次地图视图改用 list_all_visible_tasks 的路由改动直接相关。
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning 实现了角色裁剪的确定性案件摘要,但未覆盖链接需求中的人工发布、版本回溯和撤销/回退流程。 补充草稿/发布/撤销/回退与版本追踪流程,并确保失败时回退到最近的确认版本或可编辑草稿。
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题简洁且准确概括了新增按角色裁剪的确定性案件摘要接口。
Out of Scope Changes check ✅ Passed 新增路由、模型、服务、文档和测试都围绕案件摘要功能,没有明显无关改动。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/issue-30-role-filtered-case-summary

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/api/case_summary_get.rs (1)

10-148: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

建议补充多条已确认线索时 last_confirmed_information 排序的边界测试。

当前用例仅制造 1 条 confirmed 线索,未验证存在多条已确认线索时 last_confirmed_information 是否始终返回“最近上报”的那条(case_summary_service.rs 中依赖 confirmed_clues.first())。建议追加一个含 2+ 条已确认线索的用例,锁定该排序行为,避免未来回归。

As per path instructions for tests/**, changed behavior should have meaningful positive, negative, and boundary-case coverage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/api/case_summary_get.rs` around lines 10 - 148, Extend
get_case_summary_classifies_review_states_and_crops_each_role with at least two
confirmed clues created at different times, then assert
last_confirmed_information identifies the most recently reported clue rather
than relying on a single confirmed item. Preserve the existing role-specific
assertions and add coverage for the multi-confirmed boundary case.

Source: Path instructions

src/application/services/case_summary_service.rs (1)

93-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

分页拉取全部任务的循环逻辑与 get_map_view 重复。

list_visible_tasks 与 src/api/routes/cases.rs 中 get_map_view(第 220-238 行)几乎逐行重复了“按 100 条一页循环拉取直到 items.len() >= total”的逻辑,包括 checked_add 溢出保护。建议提取为共享辅助函数(例如 task_service 下的 list_all_visible_tasks),避免后续两处出现行为分叉或需要重复修复同一 bug。

♻️ 提取共享分页辅助函数示例
+// in src/application/services/task_service.rs
+pub async fn list_all_visible_tasks(
+    db: &DatabaseConnection,
+    auth: &AuthenticatedUser,
+    case_id: &str,
+) -> Result<Vec<TaskResponse>, ApiError> {
+    let mut items = Vec::new();
+    let mut page = 1;
+    loop {
+        let response = list_tasks(
+            db,
+            auth,
+            case_id,
+            TaskListQuery { page: Some(page), page_size: Some(100) },
+        )
+        .await?;
+        items.extend(response.items);
+        if u64::try_from(items.len()).map_err(|_| ApiError::Internal)? >= response.total {
+            return Ok(items);
+        }
+        page = page.checked_add(1).ok_or(ApiError::Internal)?;
+    }
+}

然后在 case_summary_service.rs 和 cases.rs::get_map_view 中都改为调用该共享函数。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/application/services/case_summary_service.rs` around lines 93 - 117,
提取共享分页辅助函数(例如 task_service::list_all_visible_tasks),统一封装按每页 100 条拉取任务、累积结果、按
total 判断完成及 checked_add 溢出保护的逻辑;将 case_summary_service::list_visible_tasks 和
cases::get_map_view 中的重复循环改为调用该函数,并保持现有认证、数据库、case_id 参数及错误行为不变。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/application/services/case_summary_service.rs`:
- Around line 93-117: 提取共享分页辅助函数(例如
task_service::list_all_visible_tasks),统一封装按每页 100 条拉取任务、累积结果、按 total 判断完成及
checked_add 溢出保护的逻辑;将 case_summary_service::list_visible_tasks 和
cases::get_map_view 中的重复循环改为调用该函数,并保持现有认证、数据库、case_id 参数及错误行为不变。

In `@tests/api/case_summary_get.rs`:
- Around line 10-148: Extend
get_case_summary_classifies_review_states_and_crops_each_role with at least two
confirmed clues created at different times, then assert
last_confirmed_information identifies the most recently reported clue rather
than relying on a single confirmed item. Preserve the existing role-specific
assertions and add coverage for the multi-confirmed boundary case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c295ea9c-cff7-4b2c-bef0-6db3e850fa9c

📥 Commits

Reviewing files that changed from the base of the PR and between c1d0739 and abab5c7.

📒 Files selected for processing (9)
  • docs/API.md
  • docs/openapi.yaml
  • src/api/models.rs
  • src/api/routes/cases.rs
  • src/application/services/case_summary_service.rs
  • src/application/services/mod.rs
  • tests/api/case_summary_get.rs
  • tests/api/mod.rs
  • tests/api/openapi_intake_contract.rs

- add reusable service method to retrieve all visible case tasks
- reuse maximum task page size for paginated task collection
- replace duplicated pagination in map and case summary views
- sort confirmed clues by report time for latest summary information
- extend summary tests for confirmed clue ordering

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/application/services/task_service.rs`:
- Around line 252-263: 抽取一个一次性加载并过滤“可见任务”的内部查询,供 list_tasks
进行分页切片以及当前全量汇总逻辑复用;更新此处循环,避免反复调用 list_tasks,并保留现有授权、过滤及排序行为。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d21ea7ba-d236-401e-8a12-a8ed28407e79

📥 Commits

Reviewing files that changed from the base of the PR and between abab5c7 and 575a75a.

📒 Files selected for processing (4)
  • src/api/routes/cases.rs
  • src/application/services/case_summary_service.rs
  • src/application/services/task_service.rs
  • tests/api/case_summary_get.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/api/case_summary_get.rs

Comment thread src/application/services/task_service.rs Outdated
@github-actions

Copy link
Copy Markdown

Preview ready

The preview for this build is available at https://pr-142-575a75acf8aa.angui.cg8.site.

Temporary demo accounts (all use the password 30a164fb9f304c7c547688cf9e89051ceb7e7585453b803b):

Role Email
Family family@demo.invalid
Commander commander@demo.invalid
Volunteer volunteer@demo.invalid
Learner learner@demo.invalid
Administrator admin@demo.invalid

These accounts and all preview data belong only to this deployment. The next preview deployment resets the SQLite database and invalidates these credentials.

- extract role-filtered task retrieval into `load_visible_tasks`
- paginate task responses after loading visible tasks
- simplify all-visible task listing without page iteration
@github-actions

Copy link
Copy Markdown

Preview ready

The preview for this build is available at https://pr-142-3d3c06f4feaf.angui.cg8.site.

Temporary demo accounts (all use the password d0b6c88df16bae50ecf288fa7388881ea638dd711c6dee1f):

Role Email
Family family@demo.invalid
Commander commander@demo.invalid
Volunteer volunteer@demo.invalid
Learner learner@demo.invalid
Administrator admin@demo.invalid

These accounts and all preview data belong only to this deployment. The next preview deployment resets the SQLite database and invalidates these credentials.

@cg8-5712
cg8-5712 merged commit bf28637 into main Jul 28, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API] GET /api/cases/{case_id}/summary - 获取角色裁剪的经授权共享案情总结

2 participants