Skip to content

Adds product payload to creation call - #82

Merged
jlpdeveloper merged 3 commits into
mainfrom
bugs/product-creation
Jun 18, 2026
Merged

Adds product payload to creation call#82
jlpdeveloper merged 3 commits into
mainfrom
bugs/product-creation

Conversation

@jlpdeveloper

@jlpdeveloper jlpdeveloper commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Description

Code Rabbit Summary

Summary by CodeRabbit

  • New Features
    • Create Product endpoint now returns the created product details (ID, name, description, platform, and timestamps) in the JSON response body with HTTP 201 status code.

Fixes

Closes #81

Post Deployment Tasks?

@jlpdeveloper jlpdeveloper added this to the Phase 2: API Endpoints milestone Jun 18, 2026
@jlpdeveloper jlpdeveloper self-assigned this Jun 18, 2026
@jlpdeveloper jlpdeveloper added bug Something isn't working skip-changelog Won't be added to the release notes labels Jun 18, 2026
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jlpdeveloper, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 52 minutes and 41 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d9d4674-d949-4434-b45a-f556d7abbb5d

📥 Commits

Reviewing files that changed from the base of the PR and between 48e6a78 and eceae9c.

📒 Files selected for processing (1)
  • internal/product/service_test.go
📝 Walkthrough

Walkthrough

CreateProduct is changed from a fire-and-forget insert to a returning insert across the full stack. The SQL query switches from :exec to :one with RETURNING *, the generated DB layer and Querier interface return (Product, error), the service and handler propagate the created product, and the handler now writes a JSON response body. Tests and the Bruno fixture are updated accordingly.

Changes

CreateProduct returns created product row

Layer / File(s) Summary
SQL query and generated DB layer
internal/product/products.sql, internal/product/db/products.sql.gen.go, internal/product/db/querier.gen.go
products.sql changes CreateProduct from :exec to :one with RETURNING *. The generated products.sql.gen.go switches from Exec to QueryRow+Scan, returning (Product, error). The Querier interface is updated to match.
Service interface and implementation
internal/product/service.go
productService interface and postgresService.CreateProduct are updated to return (db.Product, error). The implementation now directly returns the result of the query call.
HTTP handler response
internal/product/handler.go
CreateProduct captures the returned db.Product and writes it as a JSON body with status 201, replacing the previous header-only response.
Tests and Bruno fixture
internal/product/service_test.go, internal/product/handler_test.go, _bruno/Product/Create Product.yml
Mock querier and service are updated to return (db.Product, error). Service tests assert the returned product name on success. Handler tests return a populated db.Product on success and db.Product{} on failure. The Bruno fixture updates platform_id to 2 and adds a JSON response body with the created product fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • service-atlas/products#42: Originally introduced the CreateProduct SQL query, sqlc-generated layer, and productService interface that this PR modifies to switch from :exec/error to :one/(Product, error).
  • service-atlas/products#52: Added json struct tags to the generated Product model, which is directly relevant since this PR now returns the db.Product as a JSON response body.

Suggested labels

enhancement

🐇 A hop, a skip, a database row,
Now CREATE returns the product you sow!
No more empty replies, just JSON delight,
platform_id: 2 gleaming bright.
The rabbit approves — the response is right! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding product payload to the creation call response.
Linked Issues check ✅ Passed All code changes implement the acceptance criteria from issue #81: CreateProduct now returns the created product payload, includes generated ID and persisted fields, and maintains compatible success status.
Out of Scope Changes check ✅ Passed All changes are scoped to the CreateProduct feature: SQL query, generated code, service layer, handlers, and related tests are modified to support returning the created product.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 bugs/product-creation

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
internal/product/handler_test.go (1)

116-141: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add response-body assertions for CreateProduct success.

Line 138 validates only status code. The test does not verify that the 201 response actually contains the created product payload (ID + persisted fields), which is the main behavior introduced by this PR.

Suggested assertions for the success case
      h.CreateProduct(rr, req)

      if rr.Code != tt.expectedStatus {
          t.Errorf("expected status %v, got %v", tt.expectedStatus, rr.Code)
      }
+     if tt.name == "Success" {
+         var got db.Product
+         if err := json.NewDecoder(rr.Body).Decode(&got); err != nil {
+             t.Fatalf("failed to decode response body: %v", err)
+         }
+         if got.ID == 0 || got.Name != "Test Product" || got.PlatformID != 1 {
+             t.Errorf("unexpected created product payload: %+v", got)
+         }
+         if rr.Header().Get("Content-Type") != "application/json" {
+             t.Errorf("expected Content-Type application/json, got %v", rr.Header().Get("Content-Type"))
+         }
+     }

As per coding guidelines, "**/*_test.go: Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request".

🤖 Prompt for 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.

In `@internal/product/handler_test.go` around lines 116 - 141, The test for
CreateProduct handler only validates the HTTP status code at line 138 but does
not verify the response body content. Add assertions after the status code check
to deserialize the response body from the httptest.ResponseRecorder (rr) for
successful cases and verify that it contains the expected created product data
including the ID and persisted fields. For each test case in the tests slice,
when the expected status is success (201), unmarshal the response body and
assert that the returned product matches the expected payload to ensure the main
behavior of returning the created product is properly tested.

Source: Coding guidelines

🤖 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 `@internal/product/service_test.go`:
- Around line 41-55: The test case for the CreateProduct success scenario in the
postgresService test only asserts that the returned product's Name field is
correct. Expand the assertions after line 52 to verify additional fields of the
returned product contract, including the PlatformID that was passed in the
request and any generated identifier field that should be present in a created
product. This ensures the test adequately covers the full contract of what
CreateProduct returns, not just the name validation.

---

Outside diff comments:
In `@internal/product/handler_test.go`:
- Around line 116-141: The test for CreateProduct handler only validates the
HTTP status code at line 138 but does not verify the response body content. Add
assertions after the status code check to deserialize the response body from the
httptest.ResponseRecorder (rr) for successful cases and verify that it contains
the expected created product data including the ID and persisted fields. For
each test case in the tests slice, when the expected status is success (201),
unmarshal the response body and assert that the returned product matches the
expected payload to ensure the main behavior of returning the created product is
properly tested.
🪄 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: d805b320-3d63-4288-a8bd-99fc2a7bef7a

📥 Commits

Reviewing files that changed from the base of the PR and between 9fe64b7 and 48e6a78.

📒 Files selected for processing (8)
  • _bruno/Product/Create Product.yml
  • internal/product/db/products.sql.gen.go
  • internal/product/db/querier.gen.go
  • internal/product/handler.go
  • internal/product/handler_test.go
  • internal/product/products.sql
  • internal/product/service.go
  • internal/product/service_test.go

Comment thread internal/product/service_test.go
@jlpdeveloper
jlpdeveloper merged commit 1dfd7fc into main Jun 18, 2026
3 checks passed
@jlpdeveloper
jlpdeveloper deleted the bugs/product-creation branch June 18, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working skip-changelog Won't be added to the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create product call should return the newly created product

1 participant