Add Delete Product Handler#45
Conversation
* Add `Create Product` HTTP request with examples and documentation. * Add `Delete Product` HTTP request with examples and documentation. * Create `Product` folder in Bruno collection.
- Implement `DeleteProduct` handler for deleting products by ID with timeout context.
- Integrate route for `DELETE /api/products/{id}`.
- Add unit tests for `DeleteProduct` handler, including success and error scenarios.
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ 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. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a DELETE /api/products/{id} handler and router entry, Bruno API docs for Product create/delete, tests covering delete behaviors (including timeout and sql.ErrNoRows), and a small justfile update (lint target and git pull in main). The handler enforces a 5s context timeout and returns 204/400/500 as appropriate. ChangesDelete Product Flow
Sequence Diagram(s)sequenceDiagram
participant Client
participant Router
participant Handler
participant QueriesDB
Client->>Router: DELETE /api/products/{id}
Router->>Handler: Forward request with path param
Handler->>Handler: Parse id, validate
alt invalid id
Handler-->>Client: 400 Bad Request
else valid id
Handler->>QueriesDB: DeleteProduct(ctx with 5s timeout, id)
alt db error (non-ErrNoRows)
QueriesDB-->>Handler: error
Handler-->>Client: 500 Internal Server Error
else success or sql.ErrNoRows
QueriesDB-->>Handler: success / sql.ErrNoRows
Handler-->>Client: 204 No Content
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@api/product/product_test.go`:
- Around line 134-201: Add two test cases to TestDeleteProduct: one named
"Timeout context set to ~5s" where mockProductQuerier.deleteProductFunc inspects
the ctx passed into DeleteProduct to assert ctx.Deadline() exists and that
deadline.Sub(time.Now()) is approximately 5 seconds (allow a small epsilon),
then return nil so the handler responds 204; and another named "Idempotent
non-existent delete" where deleteProductFunc returns sql.ErrNoRows (or your
not-found sentinel) and the test asserts the handler still returns
http.StatusNoContent. Reference TestDeleteProduct,
mockProductQuerier.deleteProductFunc, NewProductHandler and DeleteProduct to
locate where to add these cases.
🪄 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: 7aee8845-1afb-4c2a-9600-ff4d14b60821
📒 Files selected for processing (7)
_bruno/Product/Create Product.yml_bruno/Product/Delete Product.yml_bruno/Product/folder.ymlapi/product/delete.goapi/product/product_test.gojustfilerouter/router.go
…error responses for missing products
…meout and handling of non-existent product deletion
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@api/product/delete.go`:
- Around line 21-24: The delete handler in api/product/delete.go checks
errors.Is(err, sql.ErrNoRows) which never matches pgx sentinel errors; update
the error check to use pgx.ErrNoRows instead (and add the pgx import) so the
handler returns the idempotent 204 for non-existent products; also update the
corresponding test in api/product/product_test.go to mock/expect pgx.ErrNoRows
rather than database/sql's sql.ErrNoRows. Ensure the symbol references: the
error check in the delete handler (where errors.Is is used), the import list for
the file, and the test case that currently references sql.ErrNoRows are all
changed to pgx.ErrNoRows.
🪄 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: 0f1a5700-0b0b-417d-b3ce-9036b2bd7183
📒 Files selected for processing (2)
api/product/delete.goapi/product/product_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- api/product/product_test.go
Description
Code Rabbit Summary
Summary by CodeRabbit
New Features
Tests
Chores
Fixes
Closes #26
Post Deployment Tasks?