add changes for Refactoring Deployment API Endpoints for Better RESTful design#946
add changes for Refactoring Deployment API Endpoints for Better RESTful design#946
Conversation
WalkthroughIntroduces 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 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 |
There was a problem hiding this comment.
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}/deployto/apis/{apiId}/deploymentsand undeploy from/apis/{apiId}/deployments/{deploymentId}/undeployto/apis/{apiId}/deployments/undeploy - Added
gatewayIdparameter 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
gatewayIdparameter, returningErrGatewayIDMismatchon 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"),
There was a problem hiding this comment.
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 | 🟠 MajorAdd gatewayId to the remaining RestoreDeployment test cases.
Without gatewayId set in the “gateway not found” and “set current deployment fails” cases, the service returns
ErrGatewayIDMismatchand 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",
Summary by CodeRabbit