[Customer Entity] Implement cases search endpoint - #778
Conversation
…ount and dynamic filters
|
Warning Review limit reached
More reviews will be available in 13 minutes and 2 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis PR implements a complete case search feature for the entity service. It adds domain types for cases and search requests, database schema with validation triggers, a repository layer with dynamic SQL query building and concurrent execution, service-layer validation and orchestration, an HTTP handler, dependency wiring in the router, and OpenAPI documentation for the new ChangesCase Search Feature
Sequence DiagramsequenceDiagram
participant Client
participant Handler as CaseHandler
participant Service as CaseService
participant Repository as CaseRepository
participant Database as PostgreSQL
Client->>Handler: POST /cases/search (SearchCasesRequest)
Handler->>Service: SearchCases(ctx, req)
Service->>Service: Validate pagination, query, filters, sort
Service->>Repository: SearchCases(ctx, req)
Repository->>Repository: Build WHERE and ORDER BY clauses
par Concurrent Queries
Repository->>Database: SELECT COUNT(*)
Repository->>Database: SELECT * LIMIT/OFFSET
and
end
Database-->>Repository: rows + count
Repository->>Repository: Scan rows into Case objects
Repository-->>Service: (cases, total, error)
Service->>Service: Compute HasMore flag
Service-->>Handler: SearchCasesResponse
Handler-->>Client: JSON response 200/400/500
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@entity-service/migrations/000008_create_cases.up.sql`:
- Around line 42-97: The current checks (functions
check_case_deployment_belongs_to_project,
check_case_deployed_product_belongs_to_deployment,
check_case_catastrophic_priority and their trg_case_* triggers) only run on
cases INSERT/UPDATE and miss violations introduced when parent rows change; add
complementary parent-table triggers to enforce invariants when
deployments.project_id, deployed_products.deployment_id or
projects.subscription_type are updated (e.g., create AFTER UPDATE OF project_id
on deployments that scans cases and raises using the same logic as
check_case_deployment_belongs_to_project, AFTER UPDATE OF deployment_id on
deployed_products that scans cases using
check_case_deployed_product_belongs_to_deployment logic, and AFTER UPDATE OF
subscription_type on projects that scans cases for priority='catastrophic' using
check_case_catastrophic_priority logic), or alternatively prevent updates to
those parent columns by making them immutable via BEFORE UPDATE triggers on
deployments, deployed_products and projects; implement one of these fixes
referencing the existing function names and trigger purposes.
- Around line 99-108: The current btree indexes won't help ILIKE '%...%'
searches; update the migration to enable pg_trgm (CREATE EXTENSION IF NOT EXISTS
pg_trgm) and add trigram GIN indexes for the searchable text columns used by
/cases/search: create trigram indexes for subject, number and wso2_id (e.g.
idx_cases_subject_trgm, idx_cases_number_trgm, idx_cases_wso2_id_trgm) using
LOWER(...) or gin_trgm_ops so ILIKE queries can use them, and also add an index
for the exposed sort key updated_at (e.g. idx_cases_updated_at) so explicit
sorts avoid full scans; keep the existing btree indexes for equality filters
(project_id, state, etc.) as-is.
🪄 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
Run ID: 4024dd08-3513-40ba-a977-bc3ef9f5f2a5
📒 Files selected for processing (9)
entity-service/internal/domain/entity.goentity-service/internal/handler/case_handler.goentity-service/internal/repository/case_repo.goentity-service/internal/server/routes.goentity-service/internal/service/case_service.goentity-service/internal/service/interfaces.goentity-service/migrations/000008_create_cases.down.sqlentity-service/migrations/000008_create_cases.up.sqlentity-service/openapi.yaml
Purpose
casestable migration withcase_priority_enumandcase_state_enumtypes, referential integrity triggers (deployment → project, deployed product → deployment, catastrophic priority → managed_cloud_subscription only), and covering indexesCasedomain types withCasePriority,CaseState, andCaseSort(field + order) enumsPOST /cases/searchhandler and route/cases/searchpath and request/response schemas to OpenAPI specRequest payload
{ "pagination": { "limit": 20, "offset": 0 }, "searchQuery": "gateway", "projectIds": ["..."], "deploymentIds": ["..."], "deployedProductIds": ["..."], "stateKeys": ["open", "work_in_progress"], "priorityKeys": ["critical", "high"], "sortBy": { "field": "created_at", "order": "desc" } } <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes **New Features** - Added comprehensive case search capability with filtering by project, deployment, deployed product, state, and priority. Search results can be sorted by creation date, last update, or closure date with full pagination support. <!-- end of auto-generated comment: release notes by coderabbit.ai -->