Skip to content

Add Delete Product Handler#45

Merged
jlpdeveloper merged 6 commits into
mainfrom
delete-product
May 5, 2026
Merged

Add Delete Product Handler#45
jlpdeveloper merged 6 commits into
mainfrom
delete-product

Conversation

@jlpdeveloper
Copy link
Copy Markdown
Contributor

@jlpdeveloper jlpdeveloper commented May 4, 2026

Description

  • adds bruno
  • adds delete endpoint

Code Rabbit Summary

Summary by CodeRabbit

  • New Features

    • Added API endpoints to create products (platform ID, name, description) and delete products by ID.
  • Tests

    • Added comprehensive tests for product deletion covering invalid IDs, database errors, idempotent deletes, and timeout behavior.
  • Chores

    • Added automated linting target to the development workflow.
    • Added structured product API collection entries and examples for testing.

Fixes

Closes #26

Post Deployment Tasks?

* 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.
@jlpdeveloper jlpdeveloper added this to the Phase 2: API Endpoints milestone May 4, 2026
@jlpdeveloper jlpdeveloper self-assigned this May 4, 2026
@jlpdeveloper jlpdeveloper added enhancement New feature or request skip-changelog Won't be added to the release notes labels May 4, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@jlpdeveloper has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 50 minutes and 30 seconds before requesting another review.

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 @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 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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8d6c5092-162f-4e7e-9df6-e2aae7d9de13

📥 Commits

Reviewing files that changed from the base of the PR and between f5a7bd0 and 6b5f12d.

📒 Files selected for processing (2)
  • api/product/delete.go
  • api/product/product_test.go
📝 Walkthrough

Walkthrough

Adds 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.

Changes

Delete Product Flow

Layer / File(s) Summary
API Folder Metadata
_bruno/Product/folder.yml
Adds Product Bruno folder with request: { auth: inherit }.
API Examples / Docs
_bruno/Product/Create Product.yml, _bruno/Product/Delete Product.yml
Adds Create and Delete request definitions, examples, and "Possible Responses" docs (Create: 201/400/500; Delete: 204/400/500).
Handler Implementation
api/product/delete.go
Adds (*ProductHandler).DeleteProduct: parses id from path, returns 400 for invalid IDs, creates a 5s timeout context, calls h.queries.DeleteProduct, treats sql.ErrNoRows as success, returns 204 on success or 500 on DB error.
Router Integration
router/router.go
Registers DELETE /api/products/{id} route mapped to handler.DeleteProduct.
Tests
api/product/product_test.go
Adds TestDeleteProduct table-driven tests covering success (204), invalid IDs ("abc", "0", "-1" => 400), DB failure => 500, context deadline behavior (~5s), and idempotent delete returning sql.ErrNoRows => 204.
Developer Tasks
justfile
Adds lint target (golangci-lint run) and inserts git pull into main recipe sequence.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • service-atlas/products#42: Adds DeleteProduct handler, router entry, tests and depends on the product SQL querier used by this change.

Poem

🐰 I hopped to remove a product line,
ID checked, a five-second time,
DB nods or says it's gone,
204 sings a quiet song,
Bruno notes the endpoint fine.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes include out-of-scope additions: Bruno API files for testing purposes and a new lint recipe in justfile are unrelated to the core issue #26 requirements. Remove Bruno API definition files (_bruno/Product/*) and the lint recipe from justfile, or document their necessity within the PR description.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically summarizes the main change: adding a delete product handler functionality.
Linked Issues check ✅ Passed All coding requirements from issue #26 are met: DeleteProduct handler extracts ID with 400 validation, creates 5-second timeout context, calls h.queries.DeleteProduct, returns 204 on success/non-existent, and 500 on database error.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch delete-product

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Copy Markdown

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between a2dda9e and 9236ec4.

📒 Files selected for processing (7)
  • _bruno/Product/Create Product.yml
  • _bruno/Product/Delete Product.yml
  • _bruno/Product/folder.yml
  • api/product/delete.go
  • api/product/product_test.go
  • justfile
  • router/router.go

Comment thread api/product/product_test.go
…meout and handling of non-existent product deletion
Copy link
Copy Markdown

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9236ec4 and f5a7bd0.

📒 Files selected for processing (2)
  • api/product/delete.go
  • api/product/product_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/product/product_test.go

Comment thread api/product/delete.go Outdated
@jlpdeveloper jlpdeveloper merged commit 5a17c71 into main May 5, 2026
3 checks passed
@jlpdeveloper jlpdeveloper deleted the delete-product branch May 5, 2026 00:06
@coderabbitai coderabbitai Bot mentioned this pull request May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request skip-changelog Won't be added to the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Delete Product Handler

1 participant