Skip to content

Adds create flow call#63

Merged
jlpdeveloper merged 9 commits into
mainfrom
flows/post-flow
May 16, 2026
Merged

Adds create flow call#63
jlpdeveloper merged 9 commits into
mainfrom
flows/post-flow

Conversation

@jlpdeveloper
Copy link
Copy Markdown
Contributor

@jlpdeveloper jlpdeveloper commented May 16, 2026

Description

Code Rabbit Summary

Summary by CodeRabbit

Release Notes

  • New Features

    • Added new flow creation endpoint that accepts name and description parameters
    • Flow creation endpoint returns complete flow details with a 201 Created response
  • Tests

    • Added comprehensive test coverage for flow creation functionality, including validation and error handling scenarios

Review Change Stack

Fixes

Closes #34

Post Deployment Tasks?

- Modify SQLC query to use `:one` annotation and include `RETURNING *`.
- Adjust `CreateFlow` function to return detailed `Flow` object with proper scanning.
- Update `Querier` interface signature to reflect the change.
- Implement `createFlowRequest` struct with request fields and `ToParams` method.
- Add `CreateFlow` method to `Handler` interface and `flowHandler` struct.
- Validate request body and required fields in `CreateFlow` handler.
- Write response using `application/json` with appropriate status codes.
- Add unit tests for `CreateFlow`, covering success, bad request, and internal server error cases.
- Combine platform, product, and flow route registration for improved readability.
- Introduce `CreateFlow` route under `/api/products/{id}/flows`.
- Modify `createFlowRequest.ToParams` to accept `productID` as a parameter.
- Update `CreateFlow` handler to parse and validate `productID` from the request path.
- Add test cases to validate behavior for valid, missing, and invalid `productID`.
- Introduce `Flows` folder and define its sequence metadata.
- Add `Create Flow` POST request to create a product flow.
- Include example request and response for testing and documentation.
@jlpdeveloper jlpdeveloper added this to the Phase 2: API Endpoints milestone May 16, 2026
@jlpdeveloper jlpdeveloper self-assigned this May 16, 2026
@jlpdeveloper jlpdeveloper added enhancement New feature or request skip-changelog Won't be added to the release notes labels May 16, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

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

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ 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: 9ae4abf1-30cb-49f4-ae60-4ad0de386e62

📥 Commits

Reviewing files that changed from the base of the PR and between 0f0b053 and b5709cf.

📒 Files selected for processing (4)
  • _bruno/Flows/Create Flow.yml
  • internal/flow/handler.go
  • internal/flow/handler_test.go
  • router/router.go
📝 Walkthrough

Walkthrough

This PR implements the POST /products/{id}/flows endpoint to create flows under a product. Changes flow from database layer updates (SQL query now returns full row), through request validation, HTTP handler with error responses, routing wiring, and Bruno documentation for manual testing.

Changes

Create Flow Endpoint

Layer / File(s) Summary
Database query and contract updates
internal/flow/flows.sql, internal/flow/flows.sql.gen.go, internal/flow/querier.gen.go
CreateFlow SQL query changes from :execrows to :one with RETURNING * clause. Generated Queries.CreateFlow method updated to use QueryRow and return (Flow, error) instead of int64. Querier interface signature updated to match.
Request type and conversion
internal/flow/request.go, internal/flow/request_test.go
createFlowRequest struct defined with Name (required) and Description (optional) JSON fields. ToParams method converts request into CreateFlowParams, setting timestamp to current UTC and conditional pgtype.Text validity for description.
HTTP handler implementation and interface
internal/flow/handler.go, internal/flow/interface.go, internal/flow/handler_test.go
CreateFlow handler method parses product ID from path, decodes and validates JSON body, applies 5-second context timeout, calls database query, encodes result as JSON, and responds with 201 Created. Handler interface extended with CreateFlow method. Handler tests use mock querier and table-driven test cases covering success, invalid JSON, missing name, database failure, context deadline, and invalid product ID.
Router integration
router/router.go
products/internal/flow import added. flowHandler constructed and POST /api/products/{id}/flows endpoint mounted in router hierarchy. registerPlatformCallHandler converted to empty stub.
Bruno HTTP documentation
_bruno/Flows/folder.yml, _bruno/Flows/Create Flow.yml
Flows folder configuration added with sequence 3 and inherited authentication. Create Flow request definition includes POST method to {{baseUrl}}/api/products/:id/flows, JSON body with name and description fields, and 201 success response example with flow entity structure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • service-atlas/products#60: Main PR extends the same internal/flow sqlc-based flows implementation introduced in PR #60 by updating CreateFlow to :one with RETURNING * and changing the generated CreateFlow/Querier return type, then wiring a concrete flowHandler.CreateFlow endpoint that uses the updated query.
  • service-atlas/products#43: Both PRs overlap at the routing layer: #43 adds the CreateProduct handler and hooks product creation into router/router.go, while the main PR rewires router/router.go to mount the product handler alongside the new flow creation endpoint under /{id}/flows.

Poem

🐰 A flow finds its path from request to rest,
Five seconds of timeout, then back to the nest,
One query returns, with all columns blessed,
POST to the products, the endpoint's impressed! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Title check ❓ Inconclusive The title 'Adds create flow call' is vague and non-descriptive, using generic language that lacks specificity about what aspect of flow creation was implemented. Revise the title to be more specific and descriptive, such as 'Implement POST /products/{id}/flows endpoint to create flows' or 'Add flow creation endpoint with validation and persistence'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request successfully implements all core requirements from issue #34: the POST endpoint, request validation, database persistence, and correct response formatting with appropriate status codes.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the flow creation endpoint and supporting infrastructure; no unrelated or out-of-scope modifications are present.

✏️ 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 flows/post-flow

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

🧹 Nitpick comments (3)
internal/flow/request_test.go (1)

7-27: ⚡ Quick win

Add a case for empty description mapping.

ToParams has a branch where empty description should produce Description.Valid == false, but this test only covers the non-empty branch.

Suggested test extension
 func TestCreateFlowRequest_ToParams(t *testing.T) {
+	t.Run("non-empty description", func(t *testing.T) {
 	req := createFlowRequest{
 		Name:        "Test Flow",
 		Description: "Test Description",
 	}
 	productID := 123
 	params := req.ToParams(productID)
@@
 	if !params.TimeStamp.Valid {
 		t.Error("expected TimeStamp to be valid")
 	}
+	})
+
+	t.Run("empty description becomes null", func(t *testing.T) {
+		req := createFlowRequest{Name: "Test Flow", Description: ""}
+		params := req.ToParams(123)
+		if params.Description.Valid {
+			t.Error("expected Description.Valid to be false for empty description")
+		}
+	})
 }

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/flow/request_test.go` around lines 7 - 27, Extend the
TestCreateFlowRequest_ToParams test to include a subcase where
createFlowRequest.Description is an empty string and verify ToParams(productID)
yields params.Description.Valid == false (and params.Description.String is
empty), while still asserting params.Name == req.Name, params.ProductID ==
productID, and params.TimeStamp.Valid is true; update or add a new subtest
within TestCreateFlowRequest_ToParams to cover this branch of the
createFlowRequest.ToParams logic.
internal/flow/handler_test.go (1)

57-186: ⚡ Quick win

Add a test case for product not found -> 404.

This table set does not verify the endpoint’s required 404 behavior for unknown product IDs, so that contract can regress unnoticed.

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/flow/handler_test.go` around lines 57 - 186, Add a test case to
TestCreateFlow that verifies a missing product returns 404: add a new table
entry named e.g. "Product Not Found" with pathID "1", requestBody
createFlowRequest{Name: "Missing Product"}, mockSetup that sets
mock.createFlowFunc = func(ctx context.Context, arg CreateFlowParams) (Flow,
error) { return Flow{}, sql.ErrNoRows } (or the repository’s sentinel NotFound
error), and expectedStatus http.StatusNotFound; ensure the test uses the
existing flowHandler.CreateFlow call and checks rr.Code equals
http.StatusNotFound (no response body assertions needed).
router/router.go (1)

69-71: ⚡ Quick win

Remove unused empty function.

registerPlatformCallHandler is flagged as unused by golangci-lint. The function body is empty and route registration has been moved inline into SetupRouter. Remove this dead code.

♻️ Proposed fix
-func registerPlatformCallHandler(platformHandler platform.Handler, r *chi.Mux) {
-
-}
🤖 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 `@router/router.go` around lines 69 - 71, Remove the dead unused function
registerPlatformCallHandler by deleting its declaration and empty body from the
file since route registration is already handled inline in SetupRouter; ensure
there are no remaining references to registerPlatformCallHandler elsewhere (if
found, update those call sites to use the inline registration in SetupRouter or
remove the calls).
🤖 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 `@_bruno/Flows/Create` Flow.yml:
- Around line 22-26: The assertion in the runtime assertions block currently
checks res.status == "200" but the endpoint should return 201; update the
assertion under runtime.assertions (the entry with expression: res.status,
operator: eq) to expect "201" (or numeric 201) so the test matches the example
response and PR objectives.

In `@internal/flow/handler.go`:
- Around line 44-46: The current error branch always returns 500 on create
failures; update the error handling around the err from the flow creation call
so that if err represents a missing product (e.g., errors.Is(err, sql.ErrNoRows)
or matches your product-service sentinel like product.ErrNotFound) you call
internal.HandleHttpError(w, internal.ErrorEnvelope{Detail: "Product not found"},
http.StatusNotFound), otherwise preserve the existing internal server error
behavior (internal.HandleHttpError(..., "Failed to create flow",
http.StatusInternalServerError)). Use the existing err variable and
internal.HandleHttpError/internal.ErrorEnvelope symbols to implement this
branching.
- Around line 37-39: The handler currently treats whitespace-only names as valid
because it checks req.Name == ""; change the validation to trim whitespace first
(use strings.TrimSpace) and treat the trimmed result as empty to reject names
like "   "; update the check around the block that calls
internal.HandleHttpError (and either assign the trimmed value back to req.Name
or use a local trimmedName variable) and ensure the strings package is imported
so whitespace-only inputs are rejected.

In `@router/router.go`:
- Line 42: The route registration has a typo: u.Get("/}",
platformHandler.GetPlatform) should use a correct path string; update the route
call on the router (the u.Get invocation that registers
platformHandler.GetPlatform) to use the correct pattern (replace "/}" with "/")
so the GetPlatform handler is registered correctly and GET /api/platforms/{id}
requests will match.

---

Nitpick comments:
In `@internal/flow/handler_test.go`:
- Around line 57-186: Add a test case to TestCreateFlow that verifies a missing
product returns 404: add a new table entry named e.g. "Product Not Found" with
pathID "1", requestBody createFlowRequest{Name: "Missing Product"}, mockSetup
that sets mock.createFlowFunc = func(ctx context.Context, arg CreateFlowParams)
(Flow, error) { return Flow{}, sql.ErrNoRows } (or the repository’s sentinel
NotFound error), and expectedStatus http.StatusNotFound; ensure the test uses
the existing flowHandler.CreateFlow call and checks rr.Code equals
http.StatusNotFound (no response body assertions needed).

In `@internal/flow/request_test.go`:
- Around line 7-27: Extend the TestCreateFlowRequest_ToParams test to include a
subcase where createFlowRequest.Description is an empty string and verify
ToParams(productID) yields params.Description.Valid == false (and
params.Description.String is empty), while still asserting params.Name ==
req.Name, params.ProductID == productID, and params.TimeStamp.Valid is true;
update or add a new subtest within TestCreateFlowRequest_ToParams to cover this
branch of the createFlowRequest.ToParams logic.

In `@router/router.go`:
- Around line 69-71: Remove the dead unused function registerPlatformCallHandler
by deleting its declaration and empty body from the file since route
registration is already handled inline in SetupRouter; ensure there are no
remaining references to registerPlatformCallHandler elsewhere (if found, update
those call sites to use the inline registration in SetupRouter or remove the
calls).
🪄 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: bf42d04e-843e-41fb-b645-d15107a9373b

📥 Commits

Reviewing files that changed from the base of the PR and between ef21d47 and 0f0b053.

📒 Files selected for processing (11)
  • _bruno/Flows/Create Flow.yml
  • _bruno/Flows/folder.yml
  • internal/flow/flows.sql
  • internal/flow/flows.sql.gen.go
  • internal/flow/handler.go
  • internal/flow/handler_test.go
  • internal/flow/interface.go
  • internal/flow/querier.gen.go
  • internal/flow/request.go
  • internal/flow/request_test.go
  • router/router.go

Comment thread _bruno/Flows/Create Flow.yml Outdated
Comment thread internal/flow/handler.go Outdated
Comment thread internal/flow/handler.go
Comment thread router/router.go Outdated
@jlpdeveloper jlpdeveloper merged commit 7211743 into main May 16, 2026
3 checks passed
@jlpdeveloper jlpdeveloper deleted the flows/post-flow branch May 16, 2026 00:32
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.

POST /products/{id}/flows — Create a flow under a product

1 participant