Skip to content

[Customer Entity] Add SN case search and unify search response shape - #855

Merged
Rashmika998 merged 3 commits into
wso2-open-operations:v2from
cloby99:task/entity-service
Jun 15, 2026
Merged

Rashmika998 merged 3 commits into
wso2-open-operations:v2from
cloby99:task/entity-service

Conversation

@cloby99

@cloby99 cloby99 commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add sn_case_service.go — implements CaseService.SearchCases via the Choreo POST /cases/search API with caseTypes: ["default_case"] in the filters; all write and read-by-id operations delegate to the postgres fallback
  • Rename SearchCaseView.CreatedAt/UpdatedAt → CreatedOn/UpdatedOn (JSON: createdOn/updatedOn) to align the search response shape with the unified contract shared by both datasources
  • Wire NewSNCaseService in routes.go when DATA_SOURCE=servicenow

Summary by CodeRabbit

  • New Features

    • Integrated ServiceNow as an optional case management backend with automatic fallback to database-backed storage.
    • Added three new case fields: assigned engineer, parent case, and related case references to support case relationships and hierarchies.
  • Bug Fixes

    • Corrected timestamp field naming in case search responses from createdAt/updatedAt to createdOn/updatedOn.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SearchCaseView timestamp fields are renamed from CreatedAt/UpdatedAt to CreatedOn/UpdatedOn with matching JSON tag and repository scan updates. A new snCaseService is added that delegates write operations to a Postgres fallback and implements SearchCases via the Choreo API. The router conditionally selects this service when DataSource is ServiceNow. Three nullable FK columns are added to the cases table.

Changes

ServiceNow CaseService integration

Layer / File(s) Summary
Domain contract and DB schema changes
entity-service/internal/domain/entity.go, entity-service/migrations/000008_create_cases.up.sql
SearchCaseView.CreatedAt/UpdatedAt renamed to CreatedOn/UpdatedOn with updated JSON tags. Migration adds assigned_engineer, parent_case_id, and related_case_id nullable FK columns to the cases table.
ServiceNow CaseService implementation
entity-service/internal/service/sn_case_service.go
Defines internal Choreo request/response structs, implements NewSNCaseService constructor and full CaseService method set. SearchCases normalizes pagination, extracts user token from context, POSTs to Choreo /cases/search, parses timestamps, maps SN state/severity/issueType to domain enums, and computes HasMore. Write/read-by-id methods delegate to pgFallback.
Router wiring and repo scan fix
entity-service/internal/server/routes.go, entity-service/internal/repository/case_repo.go
NewRouter conditionally creates snCaseService when cfg.DataSource == DataSourceServiceNow, otherwise uses the existing Postgres service. Repository SearchCases scan updated to populate CreatedOn/UpdatedOn fields.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • wso2-open-operations/cs-tools#822: Directly related — modifies SearchCaseView and case search response model in entity.go, the same struct whose timestamp fields are renamed in this PR.
  • wso2-open-operations/cs-tools#778: Related — implements the Postgres-backed SearchCases repository and endpoint wiring that the new snCaseService delegates write operations to.

Suggested labels

Type/Improvement, Area/Backend, Entity Service

Suggested reviewers

  • Rashmika998

Poem

🐰 Hop hop, the timestamps align,
createdOn and updatedOn now shine!
ServiceNow gets its own little lane,
Postgres still catches the write-siderain.
New columns sprout in the cases tree —
A rabbit approves this PR with glee! 🎉

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the key changes but lacks most required template sections like Purpose, Goals, User stories, Release notes, Documentation, and Testing details. Expand the description to include Purpose/Goals, User stories, Release notes, Documentation links, and details about Unit/Integration tests performed, following the repository template.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding ServiceNow case search capability and unifying the search response shape with renamed timestamp fields.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@cloby99 cloby99 changed the title Task/entity service [Customer Entity] Add SN case search and unify search response shape Jun 15, 2026

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between f551faf and 233804b.

📒 Files selected for processing (5)
  • entity-service/internal/domain/entity.go
  • entity-service/internal/repository/case_repo.go
  • entity-service/internal/server/routes.go
  • entity-service/internal/service/sn_case_service.go
  • entity-service/migrations/000008_create_cases.up.sql

Comment thread entity-service/internal/service/sn_case_service.go
Comment thread entity-service/migrations/000008_create_cases.up.sql
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.

2 participants