Skip to content

[Customer Entity] Add GET /cases/{id} with enriched CaseView response - #822

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

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

Conversation

@cloby99

@cloby99 cloby99 commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add GET /cases/{id} endpoint returning an enriched CaseView with display refs for createdBy, project, deployment, and deployedProduct
  • Add POST /cases/search response updated to use CaseView (search returns createdByDetails with id and displayName only; GET returns full userId and email too)
  • Update server startup log to print "Customer Entity REST Service started in PORT : port"

Summary by CodeRabbit

  • New Features

    • Case retrieval and search results now include enriched details for related entities: creator info, project, deployment, and deployed product.
    • Search results use a compact creator representation (ID + email) for faster display.
  • Documentation

    • API spec updated to reflect the new enriched response shapes for single-case and search endpoints.
  • Chores

    • Improved server startup log message formatting.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds enriched case view types (CaseView, SearchCaseView and reference types), updates repository reads to join related tables and return these views, changes service method signatures, and updates the OpenAPI schemas and a startup log message.

Changes

Case Enrichment with Related Entity Details

Layer / File(s) Summary
Domain contracts: enriched case view types
entity-service/internal/domain/entity.go
Adds UserRef, UserIDEmailRef, EntityRef, DeployedProductRef, CaseView, and SearchCaseView; adjusts Case docs and SearchCasesResponse to use the search-specific view.
Repository case read operations
entity-service/internal/repository/case_repo.go
Updates CaseRepository signatures; implements GetCaseByID with joins mapping to domain.CaseView; rewrites SearchCases to build c.-qualified WHERE clauses, support array/enum/text filters, run concurrent COUNT+SELECT, and scan rows into domain.SearchCaseView.
Service interface and implementation
entity-service/internal/service/interfaces.go, entity-service/internal/service/case_service.go
CaseService.GetCaseByID signature and docs updated to return domain.CaseView; service validates UUID and delegates to repository.
OpenAPI specification
entity-service/openapi.yaml
Adds UserRef, UserIDEmailRef, EntityRef, DeployedProductRef, and CaseView/CaseSearchView schemas; updates GET /cases/{id} response and SearchCasesResponse.cases[] to reference the new view schemas.
Startup log message
entity-service/cmd/api/main.go
Change goroutine startup log to print "Customer Entity REST Service started in PORT : " using cfg.ServerPort.

Sequence Diagram

sequenceDiagram
  participant Client
  participant CaseService
  participant CaseRepository
  participant Database
  Client->>CaseService: GetCaseByID(id)
  CaseService->>CaseRepository: GetCaseByID(id)
  CaseRepository->>Database: SELECT c JOIN users, projects, deployments, deployed_products, products, product_versions
  Database-->>CaseRepository: enriched case row
  CaseRepository-->>CaseService: domain.CaseView
  CaseService-->>Client: domain.CaseView
  Client->>CaseService: SearchCases(req)
  CaseService->>CaseRepository: SearchCases(req)
  CaseRepository->>Database: COUNT(*) and SELECT with JOINs + dynamic WHERE
  Database-->>CaseRepository: count and enriched rows
  CaseRepository-->>CaseService: []domain.SearchCaseView, total
  CaseService-->>Client: SearchCasesResponse with CaseSearchView items
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

Type/New Feature, Area/Backend, Entity Service

Suggested reviewers

  • Rashmika998
  • shayanmalinda

Poem

🐰 New views hop into the glen,
Joined tables whisper now and then,
IDs and names in tidy rows,
A rabbit nods — the data grows,
Hooray for views and gentle code!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete. It provides only a brief summary of changes but is missing most required template sections including Purpose, Goals, Approach, User stories, Release notes, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations, Test environment, and Learning. Complete the PR description by filling in the required sections from the template, particularly Purpose/Goals, test coverage details, security checks, documentation links, and the test environment used for validation.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 PR title clearly summarizes the main change: adding a GET /cases/{id} endpoint with enriched CaseView response, which aligns with the primary objective of the changeset.
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 commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
entity-service/internal/repository/case_repo.go (1)

289-333: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Drop user_name and email from the search SELECT.

SearchCases intentionally omits those fields from the response, but this query still reads them for every row and discards them via ignoredUserID/ignoredEmail. On the bulk search path that widens PII access without changing the payload.

Suggested diff
-		`SELECT c.id, c.number, c.wso2_id,
-		        c.subject, c.description, c.priority, c.issue_type, c.state,
-		        c.created_at, c.updated_at, c.closed_at,
-		        u.id, u.first_name || ' ' || u.last_name, u.user_name, u.email,
-		        p.id, p.name,
-		        d.id, d.name,
-		        dp.id, prod.name || COALESCE(' ' || pv.version, '')
+		`SELECT c.id, c.number, c.wso2_id,
+		        c.subject, c.description, c.priority, c.issue_type, c.state,
+		        c.created_at, c.updated_at, c.closed_at,
+		        u.id, u.first_name || ' ' || u.last_name,
+		        p.id, p.name,
+		        d.id, d.name,
+		        dp.id, prod.name || COALESCE(' ' || pv.version, '')
 		 FROM cases c %s %s
 		 ORDER BY %s %s NULLS LAST, c.id
 		 LIMIT $%d OFFSET $%d`,
-			var cv domain.CaseView
-			var ignoredUserID, ignoredEmail string
+			var cv domain.CaseView
 			if err := rows.Scan(
 				&cv.ID, &cv.Number, &cv.Wso2ID,
 				&cv.Subject, &cv.Description, &cv.Priority, &cv.IssueType, &cv.State,
 				&cv.CreatedAt, &cv.UpdatedAt, &cv.ClosedAt,
-				&cv.CreatedByDetails.ID, &cv.CreatedByDetails.DisplayName, &ignoredUserID, &ignoredEmail,
+				&cv.CreatedByDetails.ID, &cv.CreatedByDetails.DisplayName,
 				&cv.ProjectDetails.ID, &cv.ProjectDetails.Name,
 				&cv.DeploymentDetails.ID, &cv.DeploymentDetails.Name,
 				&cv.DeployedProductDetails.ID, &cv.DeployedProductDetails.DisplayName,

Based on PR objectives, /cases/search is only supposed to expose createdBy.id and createdBy.displayName.

🤖 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 `@entity-service/internal/repository/case_repo.go` around lines 289 - 333, The
SELECT in dataQuery currently fetches user_name and email and then discards them
into ignoredUserID/ignoredEmail in the rows.Scan, widening PII access; update
the SQL string (the formatted query used to build dataQuery) to remove the two
fields for the created-by user (user_name and email) and then remove the
corresponding ignoredUserID and ignoredEmail from the rows.Scan call so Scan
maps directly into CreatedByDetails.ID and CreatedByDetails.DisplayName; ensure
the order of selected columns still matches the Scan arguments (see dataQuery,
rows.Scan, ignoredUserID, ignoredEmail).
entity-service/openapi.yaml (1)

968-1084: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Mark the guaranteed fields as required in the new schemas.

The Go/domain models make all of these fields mandatory except closedAt and the GET-only UserRef.userId / UserRef.email. Without required, generated clients will treat createdBy, project, deployment, deployedProduct, and the core scalar fields as optional even though the service always populates them.

Suggested diff
     UserRef:
       type: object
+      required: [id, displayName]
       properties:
         id:
           type: string
           format: uuid
@@
     EntityRef:
       type: object
+      required: [id, name]
       properties:
         id:
           type: string
           format: uuid
@@
     DeployedProductRef:
       type: object
+      required: [id, displayName]
       properties:
         id:
           type: string
           format: uuid
@@
     CaseView:
       type: object
+      required:
+        - id
+        - number
+        - wso2Id
+        - subject
+        - description
+        - priority
+        - issueType
+        - state
+        - createdAt
+        - updatedAt
+        - createdBy
+        - project
+        - deployment
+        - deployedProduct
       properties:
         id:
           type: string
           format: uuid

Based on learnings, the entity API contract is expected to guarantee non-optional response fields.

🤖 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 `@entity-service/openapi.yaml` around lines 968 - 1084, Add JSON Schema
"required" arrays to the new OpenAPI schemas so guaranteed response fields are
non-optional: for UserRef mark id and displayName as required (do not mark
userId or email), for EntityRef mark id and name required, for
DeployedProductRef mark id and displayName required, for Case mark all core
scalar fields and ids as required (e.g. id, number, wso2Id, createdBy,
projectId, deploymentId, deployedProductId, subject, description, priority,
issueType, state, createdAt, updatedAt — leave closedAt nullable/omitted), and
for CaseView mark the response fields as required (e.g. id, number, wso2Id,
subject, description, priority, issueType, state, createdAt, updatedAt,
createdBy, project, deployment, deployedProduct — leave closedAt nullable);
update the schemas UserRef, EntityRef, DeployedProductRef, Case, and CaseView
accordingly so generated clients treat these fields as required.

Source: Learnings

🤖 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/openapi.yaml`:
- Line 300: The OpenAPI spec currently reuses CaseView for both GET /cases/{id}
and /cases/search which hides that the two operations expose different createdBy
shapes; define two separate response schemas (e.g., CaseView and CaseSearchView)
under components.schemas with the differing createdBy sub-schemas
(CaseView.createdBy contains userId and email; CaseSearchView.createdBy contains
id and displayName), then update the response $ref for the GET /cases/{id}
operation (operationId like getCaseById) to point to CaseView and update the
/cases/search response (operationId like searchCases) to point to
CaseSearchView, and also replace any other $ref occurrences (the other instance
around the same schema reference) so generated clients see the redaction
boundary.

---

Outside diff comments:
In `@entity-service/internal/repository/case_repo.go`:
- Around line 289-333: The SELECT in dataQuery currently fetches user_name and
email and then discards them into ignoredUserID/ignoredEmail in the rows.Scan,
widening PII access; update the SQL string (the formatted query used to build
dataQuery) to remove the two fields for the created-by user (user_name and
email) and then remove the corresponding ignoredUserID and ignoredEmail from the
rows.Scan call so Scan maps directly into CreatedByDetails.ID and
CreatedByDetails.DisplayName; ensure the order of selected columns still matches
the Scan arguments (see dataQuery, rows.Scan, ignoredUserID, ignoredEmail).

In `@entity-service/openapi.yaml`:
- Around line 968-1084: Add JSON Schema "required" arrays to the new OpenAPI
schemas so guaranteed response fields are non-optional: for UserRef mark id and
displayName as required (do not mark userId or email), for EntityRef mark id and
name required, for DeployedProductRef mark id and displayName required, for Case
mark all core scalar fields and ids as required (e.g. id, number, wso2Id,
createdBy, projectId, deploymentId, deployedProductId, subject, description,
priority, issueType, state, createdAt, updatedAt — leave closedAt
nullable/omitted), and for CaseView mark the response fields as required (e.g.
id, number, wso2Id, subject, description, priority, issueType, state, createdAt,
updatedAt, createdBy, project, deployment, deployedProduct — leave closedAt
nullable); update the schemas UserRef, EntityRef, DeployedProductRef, Case, and
CaseView accordingly so generated clients treat these fields as required.
🪄 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: 1a6e70d8-e5ec-44d3-834c-f844e67aeb05

📥 Commits

Reviewing files that changed from the base of the PR and between 8d37dfa and 17d6bb0.

📒 Files selected for processing (6)
  • entity-service/cmd/api/main.go
  • entity-service/internal/domain/entity.go
  • entity-service/internal/repository/case_repo.go
  • entity-service/internal/service/case_service.go
  • entity-service/internal/service/interfaces.go
  • entity-service/openapi.yaml

Comment thread entity-service/openapi.yaml
@cloby99
cloby99 requested a review from Rashmika998 June 8, 2026 09:41
@Rashmika998 Rashmika998 added Type/Improvement Marks enhancements or improvements to existing features Entity Service labels Jun 8, 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: 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 `@entity-service/internal/domain/entity.go`:
- Around line 405-409: Change the search-result user reference to remove PII:
replace usages of UserIDEmailRef (and any struct named SearchCaseView or fields
named CreatedBy/createdBy that currently use email) with a compact reference
containing only ID and DisplayName (e.g., UserIDDisplayRef or struct fields ID
and DisplayName) so search/list endpoints do not expose emails; update the
struct definition(s) in entity.go (the current UserIDEmailRef and any duplicate
around the 460-477 region) and adjust SearchCaseView's CreatedBy type
accordingly, then mirror the same schema change in entity-service/openapi.yaml
so the /cases/search contract only returns {id, displayName} while GET
/cases/{id} can still return userId/email.
🪄 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: 6645b366-bb3c-4d07-832e-577833e085a6

📥 Commits

Reviewing files that changed from the base of the PR and between 17d6bb0 and 71564a9.

📒 Files selected for processing (3)
  • entity-service/internal/domain/entity.go
  • entity-service/internal/repository/case_repo.go
  • entity-service/openapi.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • entity-service/internal/repository/case_repo.go

Comment thread entity-service/internal/domain/entity.go
@Rashmika998
Rashmika998 merged commit 7320ddf into wso2-open-operations:v2 Jun 8, 2026
1 check passed
Rashmika998 added a commit to Rashmika998/cs-tools that referenced this pull request Jun 8, 2026
- GET /cases/{id} now references CaseView (enriched FK objects) instead
  of the flat Case schema, matching entity-service PR wso2-open-operations#822
- CaseSearchResponse items now reference CaseSearchView
- Add UserRef, UserIDEmailRef, EntityRef, DeployedProductRef, CaseView,
  and CaseSearchView schemas
- nextStates (portal-injected) lives on CaseView only; removed from Case

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Entity Service Type/Improvement Marks enhancements or improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants