[Customer Entity] Add SN case search and unify search response shape - #855
Conversation
📝 WalkthroughWalkthrough
ChangesServiceNow CaseService integration
Sequence Diagram(s)sequenceDiagram
participant Client
participant Router as NewRouter
participant snCaseService
participant ChoreoAPI as Choreo POST /cases/search
participant pgCaseService
Client->>Router: SearchCases request
Router->>snCaseService: SearchCases(ctx, req) [DataSource=ServiceNow]
snCaseService->>snCaseService: validate pagination & search query
snCaseService->>snCaseService: extract x-user-id-token from ctx
snCaseService->>ChoreoAPI: POST /cases/search (caseTypes, filters, pagination)
ChoreoAPI-->>snCaseService: snSearchCasesResponse
snCaseService->>snCaseService: parse timestamps, map state/severity/issueType
snCaseService-->>Client: SearchCasesResponse
Client->>Router: CreateCase / UpdateCase / GetCaseByID
Router->>snCaseService: delegate call
snCaseService->>pgCaseService: forward to pgFallback
pgCaseService-->>Client: result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" 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/internal/service/sn_case_service.go`:
- Around line 122-143: The SearchCases method in snCaseService is not forwarding
the stateKeys, priorityKeys, issueTypeKeys, and sortBy fields from the
SearchCasesRequest to the snCaseSearchPayload that is sent to ServiceNow. These
fields are being silently dropped, which violates expected filtering and sorting
behavior. Add validation logic to either: (1) include these fields in the
snCaseFilters struct and forward them to the search payload if Choreo/ServiceNow
supports them, or (2) explicitly return a ValidationError when any of these
unsupported fields are provided in the request.
In `@entity-service/migrations/000008_create_cases.up.sql`:
- Around line 47-49: Remove the three newly added column definitions
(assigned_engineer, parent_case_id, and related_case_id) from the existing
000008_create_cases.up.sql migration file to restore it to its original state.
Then create a new migration file (000009_add_case_columns.up.sql) with ALTER
TABLE cases ADD COLUMN statements to add these three columns, and create a
corresponding down migration (000009_add_case_columns.down.sql) with DROP COLUMN
statements. This ensures that databases which already applied version 000008
will receive these new columns through the new migration, preventing schema
drift between upgraded and fresh environments.
🪄 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: 46044f02-d753-4851-bb75-e41bec564a0a
📒 Files selected for processing (5)
entity-service/internal/domain/entity.goentity-service/internal/repository/case_repo.goentity-service/internal/server/routes.goentity-service/internal/service/sn_case_service.goentity-service/migrations/000008_create_cases.up.sql
Summary
sn_case_service.go— implementsCaseService.SearchCasesvia the ChoreoPOST /cases/searchAPI withcaseTypes: ["default_case"]in the filters; all write and read-by-id operations delegate to the postgres fallbackSearchCaseView.CreatedAt/UpdatedAt→CreatedOn/UpdatedOn(JSON:createdOn/updatedOn) to align the search response shape with the unified contract shared by both datasourcesNewSNCaseServiceinroutes.gowhenDATA_SOURCE=servicenowSummary by CodeRabbit
New Features
Bug Fixes
createdAt/updatedAttocreatedOn/updatedOn.