Skip to content

add changes for Refactoring Deployment API Endpoints for Better RESTful design#946

Open
dushaniw wants to merge 2 commits intowso2:mainfrom
dushaniw:main
Open

add changes for Refactoring Deployment API Endpoints for Better RESTful design#946
dushaniw wants to merge 2 commits intowso2:mainfrom
dushaniw:main

Conversation

@dushaniw
Copy link
Contributor

@dushaniw dushaniw commented Feb 5, 2026

Summary by CodeRabbit

  • New Features
    • Restore (formerly rollback) now requires gateway ID for undeploy/restore flows and enforces gateway-scoped validation.
  • Bug Fixes
    • Clearer error responses when a provided gateway ID does not match a deployment's bound gateway; updated conflict/validation messages.
  • API Changes
    • Endpoints consolidated under /deployments; undeploy and restore operations require deploymentId and gatewayId query parameters.

Copilot AI review requested due to automatic review settings February 5, 2026 11:15
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

Introduces gatewayId validation for undeploy and restore operations, renames rollback to restore, and propagates gatewayId through handlers, services, tests, error constants, and OpenAPI docs to ensure the provided gateway matches the deployment’s bound gateway.

Changes

Cohort / File(s) Summary
Error Constants
platform-api/src/internal/constants/error.go
Adds exported ErrGatewayIDMismatch and updates ErrDeploymentAlreadyDeployed message text.
Handlers
platform-api/src/internal/handler/deployment.go
Renames rollback → RestoreDeployment, modifies UndeployDeployment, requires gatewayId query param, validates gateway binding, and returns specific 400 for gateway mismatches. Route registrations updated.
Service Logic
platform-api/src/internal/service/deployment.go
Renames and updates signatures: RestoreDeployment/UndeployDeployment and their -ByHandle variants to accept gatewayID; adds gatewayID match checks and adjusts internal calls.
Tests
platform-api/src/internal/service/deployment_test.go
Updates tests to call RestoreDeployment/UndeployDeployment with gatewayId, adds mismatch test cases, and adjusts assertions and mocks accordingly.
API Spec
platform-api/src/resources/openapi.yaml
Renames endpoints and parameters: /apis/{apiId}/deploy/apis/{apiId}/deployments, undeploy → /apis/{apiId}/deployments/undeploy, rollback → /apis/{apiId}/deployments/restore; adds required deploymentId and gatewayId query parameters and updates descriptions.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  participant API as API Router
  participant Handler as DeploymentHandler
  participant Service as DeploymentService
  participant Repo as DeploymentRepo/DB

  Client->>API: HTTP POST /api/v1/apis/:apiId/deployments/restore?deploymentId&gatewayId
  API->>Handler: forward request
  Handler->>Handler: parse apiId, deploymentId, gatewayId, orgId
  Handler->>Service: RestoreDeploymentByHandle(apiId, deploymentId, gatewayId, orgId)
  Service->>Repo: Fetch deployment by id/handle
  Repo-->>Service: deployment (includes boundGatewayId)
  Service->>Service: compare gatewayId with boundGatewayId
  alt gateway matches
    Service->>Repo: perform restore/undeploy state changes
    Repo-->>Service: updated deployment
    Service-->>Handler: success (deployment)
  else gateway mismatch
    Service-->>Handler: ErrGatewayIDMismatch
  end
  Handler-->>API: HTTP 200 / 400 / 409 etc.
  API-->>Client: HTTP response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hop through code with tiny paws,
I match the gateways, check the laws,
Restore and undeploy now hold tight,
IDs aligned — the system's right,
A bunny cheers for safe deploys and pauses.

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is entirely missing; no content was provided by the author despite a detailed template being available. Add a comprehensive description following the provided template, including Purpose (with issue links), Goals, Approach, User stories, Documentation impact, test coverage details, security checks, and Test environment information.
Title check ❓ Inconclusive The title partially relates to the changeset but is vague about the specific changes, using the generic phrase 'add changes for' which obscures the main objective. Revise the title to be more specific and actionable, such as 'Refactor deployment endpoints to use RESTful paths and add gateway validation' to clearly convey the primary changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the deployment API endpoints for better RESTful design by renaming operations from "rollback" to "restore", consolidating endpoint paths under /deployments, and adding gateway ID validation for safety.

Changes:

  • Renamed "rollback" operation to "restore" across the codebase (API spec, service layer, handlers, tests)
  • Moved deploy endpoint from /apis/{apiId}/deploy to /apis/{apiId}/deployments and undeploy from /apis/{apiId}/deployments/{deploymentId}/undeploy to /apis/{apiId}/deployments/undeploy
  • Added gatewayId parameter to undeploy and restore operations with validation to ensure the deployment is bound to the specified gateway
  • Updated service layer functions to accept and validate gatewayId parameter, returning ErrGatewayIDMismatch on mismatch
  • Updated all tests to accommodate the new function signatures

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
platform-api/src/resources/openapi.yaml Refactored endpoint paths and updated operation IDs, descriptions, and parameter definitions for undeploy and restore operations
platform-api/src/internal/service/deployment.go Renamed RollbackDeployment to RestoreDeployment, added gatewayID parameter validation in both RestoreDeployment and UndeployDeployment
platform-api/src/internal/service/deployment_test.go Updated test function names and added gatewayID parameter to test cases for the refactored operations
platform-api/src/internal/handler/deployment.go Updated route paths, renamed handler functions, changed parameter extraction from path to query parameters, and added gateway ID mismatch error handling
platform-api/src/internal/constants/error.go Added new ErrGatewayIDMismatch error constant for gateway validation
Comments suppressed due to low confidence (1)

platform-api/src/internal/service/deployment_test.go:600

  • The test cases updated with the new gatewayID parameter all use matching gateway IDs (testGatewayID matches the deployment's GatewayID). There is no test case coverage for the new gateway ID mismatch validation added in the service layer (lines 237-240 of deployment.go). Consider adding a test case that validates the ErrGatewayIDMismatch error is returned when the provided gatewayID doesn't match the deployment's bound gateway.
		{
			name:         "gateway organization mismatch",
			deploymentID: testDeploymentID,
			gatewayID:    testGatewayID,
			mockDeployment: &model.APIDeployment{
				DeploymentID: testDeploymentID,
				Name:         "test-deployment",
				ApiID:        testAPIUUID,
				GatewayID:    testGatewayID,
				Content:      []byte("test content"),

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

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

⚠️ Outside diff range comments (1)
platform-api/src/internal/service/deployment_test.go (1)

455-633: ⚠️ Potential issue | 🟠 Major

Add gatewayId to the remaining RestoreDeployment test cases.

Without gatewayId set in the “gateway not found” and “set current deployment fails” cases, the service returns ErrGatewayIDMismatch and the tests won’t reach the intended branches.

🔧 Suggested fix
@@
 		{
 			name:         "gateway not found",
 			deploymentID: testDeploymentID,
+			gatewayID:    testGatewayID,
 			mockDeployment: &model.APIDeployment{
 				DeploymentID: testDeploymentID,
 				Name:         "test-deployment",
@@
 		{
 			name:         "set current deployment fails",
 			deploymentID: testDeploymentID,
+			gatewayID:    testGatewayID,
 			mockDeployment: &model.APIDeployment{
 				DeploymentID: testDeploymentID,
 				Name:         "test-deployment",

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.

1 participant