-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Create deployment endpoints #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@adityachoudhari26 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 44 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (4)
WalkthroughThis pull request introduces new OpenAPI specifications and request handlers for managing deployments within the Ctrlplane system. It defines GET and DELETE endpoints for retrieving and removing individual deployments (using deploymentId) and a POST endpoint for creating new deployments. The changes incorporate middleware for authentication, authorization, and body parsing. Updates are also made to the database insertion logic and schema to handle optional descriptions and provide clearer type definitions. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant A as API ([deploymentId] Routes)
participant DB as Database
C->>A: Send GET or DELETE request with deploymentId
A->>DB: Query deployment using deploymentId
alt Deployment exists
DB-->>A: Return deployment data
A-->>C: Success response (200)
Note over A: (For DELETE, delete entry in DB)
else Deployment not found
DB-->>A: No data found
A-->>C: Error response (404)
end
sequenceDiagram
participant C as Client
participant A as API (POST Route)
participant DB as Database
C->>A: Send POST request with deployment details
A->>DB: Check for existing deployment using systemId and slug
alt Deployment exists
DB-->>A: Conflict found
A-->>C: Return error response (409)
else No conflict
A->>DB: Insert new deployment (default description applied)
DB-->>A: Return created deployment record
A-->>C: Success response (201)
end
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
apps/webservice/src/app/api/v1/deployments/route.ts (1)
24-57: Enhance error handling and logging.Consider the following improvements:
- Include more context in error logging (e.g., systemId, slug).
- Structure error responses consistently with a common error format.
Apply this diff to enhance error handling:
try { const deployment = await ctx.db .insert(SCHEMA.deployment) .values({ ...ctx.body, description: ctx.body.description ?? "" }) .returning() .then(takeFirst); return NextResponse.json(deployment, { status: httpStatus.CREATED }); } catch (error) { - logger.error("Failed to create deployment", { error }); + logger.error("Failed to create deployment", { + error, + systemId: ctx.body.systemId, + slug: ctx.body.slug, + }); return NextResponse.json( - { error: "Failed to create deployment" }, + { + error: "Failed to create deployment", + details: "An unexpected error occurred while creating the deployment", + }, { status: httpStatus.INTERNAL_SERVER_ERROR }, ); }apps/webservice/src/app/api/v1/deployments/openapi.ts (1)
1-115: Enhance OpenAPI documentation.The OpenAPI specification is well-structured but could benefit from:
- Adding descriptions for error responses
- Including validation constraints in property descriptions
Apply this diff to enhance the documentation:
"409": { - description: "Deployment already exists", + description: "Deployment already exists with the given systemId and slug combination", content: { "application/json": { schema: { type: "object", properties: { - error: { type: "string" }, - id: { type: "string", format: "uuid" }, + error: { + type: "string", + description: "Error message explaining the conflict" + }, + id: { + type: "string", + format: "uuid", + description: "ID of the existing deployment" + }, }, required: ["error", "id"], }, }, }, }, "500": { - description: "Failed to create deployment", + description: "Internal server error occurred while creating the deployment", content: { "application/json": { schema: { type: "object", properties: { - error: { type: "string" }, + error: { + type: "string", + description: "Error message describing the internal error" + }, }, required: ["error"], }, }, }, },apps/webservice/src/app/api/v1/deployments/[deploymentId]/openapi.ts (1)
3-93: Consider reusing error schema definitionsEach error response currently defines its own inline schema. You could define a single “Error” schema in
#/components/schemasfor consistency, making updates and maintenance simpler in the future.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/webservice/src/app/api/v1/deployments/[deploymentId]/openapi.ts(1 hunks)apps/webservice/src/app/api/v1/deployments/[deploymentId]/route.ts(1 hunks)apps/webservice/src/app/api/v1/deployments/openapi.ts(1 hunks)apps/webservice/src/app/api/v1/deployments/route.ts(1 hunks)packages/api/src/router/deployment.ts(1 hunks)packages/db/src/schema/deployment.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
apps/webservice/src/app/api/v1/deployments/route.ts (1)
Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.
apps/webservice/src/app/api/v1/deployments/[deploymentId]/route.ts (1)
Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.
packages/api/src/router/deployment.ts (1)
Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.
apps/webservice/src/app/api/v1/deployments/[deploymentId]/openapi.ts (1)
Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.
apps/webservice/src/app/api/v1/deployments/openapi.ts (1)
Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.
packages/db/src/schema/deployment.ts (1)
Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Typecheck
- GitHub Check: Lint
🔇 Additional comments (5)
apps/webservice/src/app/api/v1/deployments/route.ts (2)
1-13: LGTM!The imports are well-organized and include all necessary dependencies for the deployment route handler.
14-23: LGTM!The route setup follows best practices with a well-structured middleware chain for authentication, body parsing, and authorization.
packages/db/src/schema/deployment.ts (1)
90-90: LGTM!The schema changes are well-structured:
- Making description optional in deploymentInsert schema
- Adding type exports for better type safety
Also applies to: 94-96
packages/api/src/router/deployment.ts (1)
447-451: LGTM!The create mutation correctly handles the optional description field by defaulting to an empty string.
apps/webservice/src/app/api/v1/deployments/[deploymentId]/route.ts (1)
14-39: Implementation is well-structured and secureThe GET handler is straightforward, with appropriate permission checks, fallback handling for missing deployments, and a clean response format. Great job!
| const deployment = await db | ||
| .select() | ||
| .from(SCHEMA.deployment) | ||
| .where(eq(SCHEMA.deployment.id, params.deploymentId)) | ||
| .then(takeFirstOrNull); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use consistent database context
You are using db in the select query, but ctx.db for the delete operation. If you intend both queries to run within the same transaction, it’s best to consistently rely on ctx.db.
Here's a suggested fix:
- const deployment = await db
+ const deployment = await ctx.db
.select()
.from(SCHEMA.deployment)
.where(eq(SCHEMA.deployment.id, params.deploymentId))
.then(takeFirstOrNull);Also applies to: 65-67
Summary by CodeRabbit
New Features
Refactor