Skip to content

[CSM Portal] Add deployed products search endpoint - #776

Merged
cloby99 merged 2 commits into
wso2-open-operations:v2from
Rashmika998:v2
May 29, 2026
Merged

cloby99 merged 2 commits into
wso2-open-operations:v2from
Rashmika998:v2

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds POST /deployments/{id}/products/search to the CSM Portal backend
  • Handler extracts the deployment ID from the path and injects it as deploymentIds in the request body before forwarding to the entity service's POST /deployed-products/search endpoint
  • Updates openapi.yaml with the new path and DeployedProductSearchPayload, DeployedProductSearchResponse, and DeployedProduct schemas

Test plan

  • New TestSearchDeployedProducts test suite covers: unauthenticated requests, oversized body, invalid JSON, correct deploymentIds injection, and upstream error mapping
  • All existing handler tests continue to pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new search endpoint to query deployed products within a specific deployment, supporting pagination in search requests and responses.
  • Tests

    • Added comprehensive test coverage for the new search functionality, validating authentication requirements, request validation, error handling, and correct response mapping.

Review Change Stack

@Rashmika998 Rashmika998 self-assigned this May 29, 2026
@Rashmika998
Rashmika998 changed the base branch from main to v2 May 29, 2026 09:28
@Rashmika998 Rashmika998 added the Type/Improvement Marks enhancements or improvements to existing features label May 29, 2026
@wso2-open-operations wso2-open-operations deleted a comment from coderabbitai Bot May 29, 2026
@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Rashmika998, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 50 minutes and 26 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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 40a13771-5f5f-4ee3-8d02-ade10c3ab802

📥 Commits

Reviewing files that changed from the base of the PR and between ec8bda9 and b4471af.

📒 Files selected for processing (6)
  • apps/csm-portal/backend/cmd/server/main.go
  • apps/csm-portal/backend/internal/entity/entity.go
  • apps/csm-portal/backend/internal/handler/deployments.go
  • apps/csm-portal/backend/internal/handler/deployments_test.go
  • apps/csm-portal/backend/internal/handler/helpers_test.go
  • apps/csm-portal/backend/openapi.yaml
📝 Walkthrough

Walkthrough

This PR adds a new POST /deployments/{id}/products/search HTTP endpoint that enables searching for deployed products within a specific deployment. The change spans the OpenAPI contract definition, entity service client integration, HTTP handler with request body injection, comprehensive test coverage, and server route registration.

Changes

Deployed Products Search Endpoint

Layer / File(s) Summary
API Contract & Schemas
apps/csm-portal/backend/openapi.yaml
Endpoint POST /deployments/{id}/products/search with request body (DeployedProductSearchPayload), response schema (DeployedProductSearchResponse), and entity schema (DeployedProduct) defining deployment product search with pagination and product metadata.
Entity Service Client
apps/csm-portal/backend/internal/entity/entity.go
SearchDeployedProducts method on entity.Client posts request to upstream /deployed-products/search endpoint and returns raw JSON response bytes.
Handler Implementation, Tests & Wiring
apps/csm-portal/backend/internal/handler/deployments.go, apps/csm-portal/backend/internal/handler/deployments_test.go, apps/csm-portal/backend/internal/handler/helpers_test.go, apps/csm-portal/backend/cmd/server/main.go
DeploymentHandler.SearchDeployedProducts enforces authentication, caps request size, validates JSON, injects deployment ID into request payload via injectDeploymentID helper, calls entity client, and maps errors to HTTP responses. TestSearchDeployedProducts validates authentication, request validation, deployment ID injection, upstream error handling, and successful forwarding. Mock client extended with SearchDeployedProducts callback field and method. Route registered in server mux.

Sequence Diagram

sequenceDiagram
  participant Client
  participant Handler as SearchDeployedProducts Handler
  participant Injector as injectDeploymentID
  participant Entity as entity.SearchDeployedProducts
  participant Upstream as Upstream Service
  Client->>Handler: POST /deployments/{id}/products/search
  Handler->>Handler: Authenticate request
  Handler->>Handler: Read & validate JSON body
  Handler->>Injector: Pass body + deploymentID
  Injector->>Injector: Unmarshal JSON
  Injector->>Injector: Add deploymentIds field
  Injector->>Injector: Marshal updated JSON
  Injector->>Handler: Return modified body
  Handler->>Entity: SearchDeployedProducts(ctx, body)
  Entity->>Upstream: POST /deployed-products/search
  Upstream->>Entity: JSON response
  Entity->>Handler: Return response bytes
  Handler->>Client: Write JSON response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • wso2-open-operations/cs-tools#542: Extends DeployedProductSearchPayload schema with new filter fields that apply to this new endpoint's request contract.
  • wso2-open-operations/cs-tools#445: Implements the same POST /deployments/{id}/products/search search flow in Customer Portal's entity/service APIs alongside this CSM Portal handler addition.
  • wso2-open-operations/cs-tools#752: Adds similar search operations to DeploymentHandler and extends mockEntityDeploymentClient infrastructure in the same handler files.

Suggested reviewers

  • cloby99
  • kasunsiyambalapitiya

Poem

🐰 A search endpoint hops into view,
With deployment IDs injected just right and true,
Handler validates, entity delegates with care,
Tests ensure the request flows everywhere! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is significantly incomplete against the required template, missing critical sections like Purpose, Goals, Approach, User stories, Release note, Documentation, Security checks, and other required sections. Complete the PR description by filling in all required template sections, particularly Purpose/Goals/Approach, User stories, Release note, Documentation link, and Security checks confirmation.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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 clearly and concisely summarizes the main change: adding a deployed products search endpoint to the CSM Portal backend.
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

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.

@Rashmika998

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

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.

Adds POST /deployments/{id}/products/search which calls the entity service's
POST /deployed-products/search with the deployment ID injected from the path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@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

🧹 Nitpick comments (1)
apps/csm-portal/backend/internal/handler/deployments_test.go (1)

120-207: ⚡ Quick win

Add a null body case (and a missing-id case) to harden the suite.

The suite doesn't exercise a JSON null body, which currently triggers a panic in injectDeploymentID (see deployments.go review). A case asserting 400 for null would guard against regressions, and a missing-id case would mirror TestSearchDeployments.

🤖 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 `@apps/csm-portal/backend/internal/handler/deployments_test.go` around lines
120 - 207, Add two subtests inside TestSearchDeployedProducts: one that sends a
JSON null body to h.SearchDeployedProducts (use withUser on a POST to
"/deployments/dep-1/products/search" with body "null",
SetPathValue("id","dep-1")) and assert a 400 Bad Request and ErrMsgBadRequest;
and another that omits the path id (call withUser on the same POST but do not
call r.SetPathValue) and assert the handler returns 400 (or the same response as
TestSearchDeployments for missing id). These will exercise
injectDeploymentID/SearchDeployedProducts and guard against the panic and
missing-id behavior.
🤖 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 `@apps/csm-portal/backend/internal/handler/deployments.go`:
- Around line 113-114: Add the same empty-id guard used in SearchDeployments:
after extracting deploymentID, check if deploymentID == "" and return an HTTP
400 using the same error-response helper/logic as SearchDeployments (so you
return early and do not forward deploymentIds: [""] to the entity service);
reference the deploymentID variable and mirror the guard/response behavior from
SearchDeployments.
- Around line 30-42: injectDeploymentID can panic when body is JSON null because
json.Unmarshal into var m map[...] leaves m nil; before assigning
m["deploymentIds"] = ids initialize the map if nil (e.g., if m == nil { m =
make(map[string]json.RawMessage) }). Update the injectDeploymentID function to
check m for nil after unmarshal and allocate it when necessary, then continue to
set "deploymentIds" and marshal the map.

---

Nitpick comments:
In `@apps/csm-portal/backend/internal/handler/deployments_test.go`:
- Around line 120-207: Add two subtests inside TestSearchDeployedProducts: one
that sends a JSON null body to h.SearchDeployedProducts (use withUser on a POST
to "/deployments/dep-1/products/search" with body "null",
SetPathValue("id","dep-1")) and assert a 400 Bad Request and ErrMsgBadRequest;
and another that omits the path id (call withUser on the same POST but do not
call r.SetPathValue) and assert the handler returns 400 (or the same response as
TestSearchDeployments for missing id). These will exercise
injectDeploymentID/SearchDeployedProducts and guard against the panic and
missing-id behavior.
🪄 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: 861214a1-ebea-4fed-b10b-49303bc661a8

📥 Commits

Reviewing files that changed from the base of the PR and between 24c3f95 and ec8bda9.

📒 Files selected for processing (6)
  • apps/csm-portal/backend/cmd/server/main.go
  • apps/csm-portal/backend/internal/entity/entity.go
  • apps/csm-portal/backend/internal/handler/deployments.go
  • apps/csm-portal/backend/internal/handler/deployments_test.go
  • apps/csm-portal/backend/internal/handler/helpers_test.go
  • apps/csm-portal/backend/openapi.yaml

Comment thread apps/csm-portal/backend/internal/handler/deployments.go
Comment thread apps/csm-portal/backend/internal/handler/deployments.go
…edProducts

- injectDeploymentID: initialize map when json.Unmarshal sets it nil (JSON null body)
- SearchDeployedProducts: reject empty deployment ID with 400, consistent with SearchDeployments
- Add tests for null body and missing deployment ID cases

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloby99
cloby99 merged commit fe99fd1 into wso2-open-operations:v2 May 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

App/CSM Portal Area/Backend Type/Improvement Marks enhancements or improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants