Skip to content

[Customer Entity] Add deployments search API and move product versions to resource-scoped route - #751

Merged
Rashmika998 merged 4 commits into
wso2-open-operations:v2from
cloby99:task/entity-service
May 28, 2026
Merged

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

Conversation

@cloby99

@cloby99 cloby99 commented May 28, 2026 •

Copy link
Copy Markdown
Member

Purpose

  • Add POST /deployments/search endpoint with pagination and optional filters: projectIds[], deploymentTypeKeys[], and searchQuery (ILIKE on name)
  • Add migration for deployments table with deployment_type_enum and supporting indexes
  • Move product versions search from POST /product-versions/search to POST /products/{id}/versions/search — product ID is now a path parameter, removed from the request body

Summary by CodeRabbit

Release Notes

  • New Features

    • Added deployments search capability with optional filtering by project and deployment type
    • Support for six deployment environments: primary production, staging, QA, stress, UAT, and development
    • Search results include pagination metadata and total count
  • API Changes

    • Restructured product versions search endpoint from /product-versions/search to /products/{id}/versions/search for improved scoping

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

More reviews will be available in 49 minutes and 52 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: 6a46cd13-be0d-47a1-bed9-c40e4fca6f10

📥 Commits

Reviewing files that changed from the base of the PR and between 9f909b1 and e9eeb96.

📒 Files selected for processing (9)
  • entity-service/internal/domain/entity.go
  • entity-service/internal/handler/deployment_handler.go
  • entity-service/internal/handler/product_version_handler.go
  • entity-service/internal/repository/deployment_repo.go
  • entity-service/internal/server/routes.go
  • entity-service/internal/service/deployment_service.go
  • entity-service/internal/service/interfaces.go
  • entity-service/migrations/000006_create_deployments.down.sql
  • entity-service/migrations/000006_create_deployments.up.sql
📝 Walkthrough

Walkthrough

This PR introduces a complete deployment search feature across the entity-service stack (domain types, database schema, repository, service, and HTTP handler), while also refactoring the product versions search endpoint to treat ProductID as a URL path parameter instead of a JSON request field.

Changes

Deployment search feature and product versions endpoint refactor

Layer / File(s) Summary
Deployment domain model and database schema
entity-service/internal/domain/entity.go, entity-service/migrations/000006_create_deployments.*
DeploymentType enum and Deployment struct model deployment environments. Database migration creates deployments table with UUID PK, foreign keys to projects and users, and composite unique constraint on (project_id, name) with indexes for efficient project/type lookups.
Deployment repository with search implementation
entity-service/internal/repository/deployment_repo.go
DeploymentRepository interface and implementation search deployments by assembling parameterized SQL filters (project IDs, deployment type keys, ILIKE search pattern), executing COUNT and paginated SELECT concurrently via errgroup, and scanning rows with error wrapping.
Deployment service with business logic
entity-service/internal/service/interfaces.go, entity-service/internal/service/deployment_service.go
DeploymentService interface and implementation normalize pagination, validate search query, delegate to repository, and return SearchDeploymentsResponse with HasMore computed from offset/limit/total.
Product versions endpoint request model refactoring
entity-service/internal/domain/entity.go, entity-service/internal/handler/product_version_handler.go
SearchProductVersionsRequest removes ProductID from JSON body (json:"-") to treat it as a URL path parameter. Handler extracts ProductID from path value and populates request before service invocation.
HTTP handlers and API route wiring
entity-service/internal/handler/deployment_handler.go, entity-service/internal/server/routes.go
DeploymentHandler implements POST /deployments/search with JSON request/response. Router wires deployment repository/service/handler and updates product-versions route from POST /product-versions/search to POST /products/{id}/versions/search.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Type/Improvement, Area/Backend

Suggested reviewers

  • Rashmika998
  • kasunsiyambalapitiya
  • v15a1

🐰 A database schema takes shape,
And repositories spring to life,
Search flows through the layers true,
From client click to database might,
Deployments now discoverable! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the Purpose with specific endpoint details, but lacks sections for Goals, Approach, User stories, Release notes, Documentation, and other required template sections. Complete the PR description by filling in remaining template sections: Goals, Approach, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations details, Test environment, and Learning.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the two main changes: adding a deployments search API and moving product versions to a resource-scoped route, matching the actual changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

@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)
entity-service/internal/server/routes.go (1)

65-65: Document the breaking API change for consumers.

The route change from POST /product-versions/search to POST /products/{id}/versions/search breaks existing API consumers. Although this is intentional and improves the REST design by making the product ID a path parameter, ensure that:

  • Migration guides or changelog document this breaking change
  • API consumers are notified before deployment
  • Any API versioning or deprecation strategy is followed
🤖 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/server/routes.go` at line 65, The new route
registration using "POST /products/{id}/versions/search" (handler
productVersionHandler.SearchProductVersions) is a breaking change from the old
"POST /product-versions/search"; update documentation and release artifacts to
reflect this: add an entry to the changelog and migration guide describing the
exact path change and example requests, create a deployment/notification note
for API consumers, and apply your project’s versioning/deprecation policy (e.g.,
bump API version or add a deprecated endpoint proxy) so clients are warned or
can migrate before removal.
🤖 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/repository/deployment_repo.go`:
- Around line 53-69: SearchDeployments is currently casting the columns
(project_id::text, type::text) which prevents use of existing btree indexes;
instead stop casting the columns in the WHERE string and cast the parameter
arrays to the correct DB types. Update the clauses built around the where
variable (where += ...) to use "project_id = ANY($%d::<uuid array type>)" and
"type = ANY($%d::<deployment_type_enum array type>)" (keeping argIdx and
filterArgs logic), ensure req.ProjectIDs is passed as the appropriate UUID-typed
slice and req.DeploymentTypeKeys is converted to the correct enum-typed slice
(the existing typeStrings conversion can remain if you cast the parameter to the
enum array in SQL), and leave argIdx/filterArgs updates as-is so the DB can use
idx_deployments_project_id and idx_deployments_type.

In `@entity-service/migrations/000006_create_deployments.up.sql`:
- Around line 1-8: The migration creates the enum deployment_type_enum
unconditionally which makes the migration non-rerunnable; change the enum
creation in 000006_create_deployments.up.sql to be idempotent by checking for
the type first and only creating it when absent (e.g., wrap in a DO block that
queries pg_type/pg_namespace for typname = 'deployment_type_enum' and runs
CREATE TYPE ... only if not present, or use CREATE TYPE IF NOT EXISTS on PG
versions that support it) so retries after partial failure won’t error on an
existing type.

---

Nitpick comments:
In `@entity-service/internal/server/routes.go`:
- Line 65: The new route registration using "POST
/products/{id}/versions/search" (handler
productVersionHandler.SearchProductVersions) is a breaking change from the old
"POST /product-versions/search"; update documentation and release artifacts to
reflect this: add an entry to the changelog and migration guide describing the
exact path change and example requests, create a deployment/notification note
for API consumers, and apply your project’s versioning/deprecation policy (e.g.,
bump API version or add a deprecated endpoint proxy) so clients are warned or
can migrate before removal.
🪄 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: 7705c69f-cf3e-4590-a00b-82b038259e3a

📥 Commits

Reviewing files that changed from the base of the PR and between 34735fc and 9f909b1.

📒 Files selected for processing (9)
  • entity-service/internal/domain/entity.go
  • entity-service/internal/handler/deployment_handler.go
  • entity-service/internal/handler/product_version_handler.go
  • entity-service/internal/repository/deployment_repo.go
  • entity-service/internal/server/routes.go
  • entity-service/internal/service/deployment_service.go
  • entity-service/internal/service/interfaces.go
  • entity-service/migrations/000006_create_deployments.down.sql
  • entity-service/migrations/000006_create_deployments.up.sql

Comment thread entity-service/internal/repository/deployment_repo.go
Comment thread entity-service/migrations/000006_create_deployments.up.sql
@cloby99
cloby99 force-pushed the task/entity-service branch from 9f909b1 to e9eeb96 Compare May 28, 2026 10:55
@Rashmika998
Rashmika998 merged commit 80ecd9c into wso2-open-operations:v2 May 28, 2026
1 check passed
Rashmika998 added a commit to Rashmika998/cs-tools that referenced this pull request May 28, 2026
Wires POST /deployments/search into the csm-portal backend, proxying to
the entity service endpoint added in wso2-open-operations#751.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rashmika998 added a commit to Rashmika998/cs-tools that referenced this pull request May 28, 2026
Wires POST /deployments/search into the csm-portal backend, proxying to
the entity service endpoint added in wso2-open-operations#751.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants