Repository navigation
[CSM Portal] Add deployed products search endpoint - #776
Conversation
|
Warning Review limit reached
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 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 adds a new ChangesDeployed Products Search Endpoint
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
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)
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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
apps/csm-portal/backend/internal/handler/deployments_test.go (1)
120-207: ⚡ Quick winAdd a
nullbody case (and a missing-id case) to harden the suite.The suite doesn't exercise a JSON
nullbody, which currently triggers a panic ininjectDeploymentID(see deployments.go review). A case asserting400fornullwould guard against regressions, and a missing-idcase would mirrorTestSearchDeployments.🤖 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
📒 Files selected for processing (6)
apps/csm-portal/backend/cmd/server/main.goapps/csm-portal/backend/internal/entity/entity.goapps/csm-portal/backend/internal/handler/deployments.goapps/csm-portal/backend/internal/handler/deployments_test.goapps/csm-portal/backend/internal/handler/helpers_test.goapps/csm-portal/backend/openapi.yaml
…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>
Summary
POST /deployments/{id}/products/searchto the CSM Portal backenddeploymentIdsin the request body before forwarding to the entity service'sPOST /deployed-products/searchendpointopenapi.yamlwith the new path andDeployedProductSearchPayload,DeployedProductSearchResponse, andDeployedProductschemasTest plan
TestSearchDeployedProductstest suite covers: unauthenticated requests, oversized body, invalid JSON, correctdeploymentIdsinjection, and upstream error mapping🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests