Repository navigation
feat(cases): add role-filtered deterministic case summaries - #142
Conversation
- 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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughChanges新增 案件摘要 API
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (9)
docs/API.mddocs/openapi.yamlsrc/api/models.rssrc/api/routes/cases.rssrc/application/services/case_summary_service.rssrc/application/services/mod.rstests/api/case_summary_get.rstests/api/mod.rstests/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
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
src/api/routes/cases.rssrc/application/services/case_summary_service.rssrc/application/services/task_service.rstests/api/case_summary_get.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/api/case_summary_get.rs
Preview readyThe preview for this build is available at https://pr-142-575a75acf8aa.angui.cg8.site. Temporary demo accounts (all use the password
|
- extract role-filtered task retrieval into `load_visible_tasks` - paginate task responses after loading visible tasks - simplify all-visible task listing without page iteration
Preview readyThe preview for this build is available at https://pr-142-3d3c06f4feaf.angui.cg8.site. Temporary demo accounts (all use the password
|
close #30
Summary by CodeRabbit
/api/cases/{case_id}/summary),按访问角色返回:已确认线索、待核实事项、排除方向、当前关注与任务状态、安全提醒及生成时间。CaseSummary相关字段/结构说明。