Repository navigation
feat(api): add-ons v3 - #4138
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (12)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughWalkthroughAdds a new API v3 add‑ons surface: handlers for create/read/update/list/delete/publish/archive, a conversion module mapping domain ↔ API models (extensive billing/rate‑card logic), and server wiring to expose the addon service through the v3 server. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant V3Server as "v3 Server"
participant Handler as "addons.Handler"
participant Service as "addon.Service"
participant Repo as "Repository/ProductCatalog"
Client->>V3Server: HTTP request (e.g., POST /addons)
V3Server->>Handler: invoke CreateAddon (resolve namespace, parse body)
Handler->>Service: CreateAddon(ctx, domainInput)
Service->>Repo: persist / validate / rate-card logic
Repo-->>Service: domain addon result
Service-->>Handler: addon pointer
Handler-->>V3Server: API addon payload (ToAPIAddon)
V3Server-->>Client: HTTP 201 JSON response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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: 3
🧹 Nitpick comments (3)
api/v3/server/server.go (1)
192-197: Move theAddonServicerequired-check up with the other always-required services
AddonServiceis unconditionally required (it's not gated onCredits.Enabled), so sticking the nil-check after theif c.Credits.Enabled { ... }block reads a bit oddly — every other always-required service is checked above that block. Hoisting this next to theFeatureConnectorcheck keeps the file's "required first, conditional second" flow intact.♻️ Small reorder
if c.FeatureConnector == nil { errs = append(errs, errors.New("feature connector is required")) } + if c.AddonService == nil { + errs = append(errs, errors.New("addon service is required")) + } + if c.Credits.Enabled { ... } - if c.AddonService == nil { - errs = append(errs, errors.New("addon service is required")) - } - return errors.Join(errs...)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/v3/server/server.go` around lines 192 - 197, The AddonService nil-check should be moved up into the same "always-required" section where FeatureConnector is validated so the file keeps required services first and conditional checks (like the c.Credits.Enabled block) after; locate the current check for AddonService and relocate it immediately after the FeatureConnector validation (preserving the same error text: errors.New("addon service is required")), ensuring no behavioral change beyond the reorder.api/v3/handlers/addons/list.go (1)
57-76: Consider returning service errors unwrappedSmall consistency nit:
plans/list.goand friends return the service/convert error directly so the generic error encoder sees the original type. Here thefmt.Errorf("failed to list add-ons: %w", err)/"failed to convert add-on: %w"wrapping still unwraps fine, but it adds a prefix that clients will see in the final message. Either is valid — just flagging for consistency across the v3 handlers.♻️ Suggested tweak
- resp, err := h.service.ListAddons(ctx, request) - if err != nil { - return ListAddonsResponse{}, fmt.Errorf("failed to list add-ons: %w", err) - } + resp, err := h.service.ListAddons(ctx, request) + if err != nil { + return ListAddonsResponse{}, err + } items := make([]apiv3.Addon, 0, len(resp.Items)) for _, a := range resp.Items { - apiAddon, err := ToAPIAddon(a) - if err != nil { - return ListAddonsResponse{}, fmt.Errorf("failed to convert add-on: %w", err) - } + apiAddon, err := ToAPIAddon(a) + if err != nil { + return ListAddonsResponse{}, err + } items = append(items, apiAddon) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/v3/handlers/addons/list.go` around lines 57 - 76, The handler currently wraps service and conversion errors with fmt.Errorf in the anonymous ListAddons handler; instead return the original errors from h.service.ListAddons and ToAPIAddon directly so the generic error encoder sees the original error type (replace fmt.Errorf("failed to list add-ons: %w", err) and fmt.Errorf("failed to convert add-on: %w", err) with returning err unchanged when h.service.ListAddons(ctx, request) or ToAPIAddon(a) fail), leaving the rest of the function (building items and calling response.NewPagePaginationResponse) untouched.api/v3/handlers/addons/create.go (1)
40-40: Add a clarifying comment forIgnoreNonCriticalIssues = trueThis hard-coded flag is intentional and follows the same pattern across all create/update handlers for plans and addons. The service layer documents that it allows resources with non-critical validation issues—expected for draft resources. A brief comment here (e.g.,
// Allow draft addons with non-critical issues, fully validated on publish) would save future readers the archaeology.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/v3/handlers/addons/create.go` at line 40, Add a short inline comment explaining why IgnoreNonCriticalIssues is set to true in the create handler: next to the assignment of req.IgnoreNonCriticalIssues = true, add a one-line comment such as "// Allow draft addons with non-critical validation issues; full validation occurs on publish" so future readers know this is intentional and consistent with other create/update handlers (referencing the req.IgnoreNonCriticalIssues flag in the create addon handler).
🤖 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/v3/handlers/addons/archive.go`:
- Around line 37-47: The current nil-result guard after calling
h.service.ArchiveAddon returns a vague fmt.Errorf("failed to archive add-on");
instead, treat this as an unexpected internal invariant violation and return a
richer error: log or wrap the condition with contextual details (e.g., include
request.AddonID and request.Namespace or other identifying fields from
ArchiveAddonRequest) and return a clear internal error (e.g., errors.New or an
internal-server-error wrapper) so callers get traceable diagnostics; apply the
same change pattern to the analogous check in create.go (the nil check after
h.service.CreateAddon) using the CreateAddonRequest identifiers and the
corresponding service call names to locate the code.
In `@api/v3/handlers/addons/convert.go`:
- Around line 430-437: Change both ToAPIBillingPricePaymentTerm and
FromAPIBillingPriceFlat to explicitly handle only known enum values and return
an error for any unrecognized value instead of silently defaulting; update
ToAPIBillingPricePaymentTerm to return (*apiv3.BillingPricePaymentTerm, error)
and map productcatalog.InArrearsPaymentTerm to
apiv3.BillingPricePaymentTermInArrears and productcatalog.InAdvancePaymentTerm
(or whichever explicit enum represents advance) to
apiv3.BillingPricePaymentTermInAdvance, returning fmt.Errorf("unknown payment
term: %v", t) for anything else; similarly update FromAPIBillingPriceFlat to
validate paymentTermPtr against apiv3.BillingPricePaymentTermInArrears and
BillingPricePaymentTermInAdvance and return an error for nil/unknown values
instead of returning DefaultPaymentTerm, mirroring the explicit-error behavior
used in ToAPIAddonInstanceType.
In `@api/v3/handlers/addons/get.go`:
- Around line 37-44: The handler dereferences *a without checking for nil after
calling h.service.GetAddon, which can panic if GetAddon returns (nil, nil); add
a nil-check for the returned addon (variable a) before calling ToAPIAddon and
return a descriptive error (e.g., fmt.Errorf("addon not found")) wrapped as the
handler error, and add "fmt" to imports; check the same code path in the
anonymous handler function that currently calls ToAPIAddon(*a) and change it to
return GetAddonResponse{}, fmt.Errorf(...) when a == nil.
---
Nitpick comments:
In `@api/v3/handlers/addons/create.go`:
- Line 40: Add a short inline comment explaining why IgnoreNonCriticalIssues is
set to true in the create handler: next to the assignment of
req.IgnoreNonCriticalIssues = true, add a one-line comment such as "// Allow
draft addons with non-critical validation issues; full validation occurs on
publish" so future readers know this is intentional and consistent with other
create/update handlers (referencing the req.IgnoreNonCriticalIssues flag in the
create addon handler).
In `@api/v3/handlers/addons/list.go`:
- Around line 57-76: The handler currently wraps service and conversion errors
with fmt.Errorf in the anonymous ListAddons handler; instead return the original
errors from h.service.ListAddons and ToAPIAddon directly so the generic error
encoder sees the original error type (replace fmt.Errorf("failed to list
add-ons: %w", err) and fmt.Errorf("failed to convert add-on: %w", err) with
returning err unchanged when h.service.ListAddons(ctx, request) or ToAPIAddon(a)
fail), leaving the rest of the function (building items and calling
response.NewPagePaginationResponse) untouched.
In `@api/v3/server/server.go`:
- Around line 192-197: The AddonService nil-check should be moved up into the
same "always-required" section where FeatureConnector is validated so the file
keeps required services first and conditional checks (like the c.Credits.Enabled
block) after; locate the current check for AddonService and relocate it
immediately after the FeatureConnector validation (preserving the same error
text: errors.New("addon service is required")), ensuring no behavioral change
beyond the reorder.
🪄 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: 5fe16f01-fd81-4ed6-8e1b-f988a3e60378
📒 Files selected for processing (12)
api/v3/handlers/addons/archive.goapi/v3/handlers/addons/convert.goapi/v3/handlers/addons/create.goapi/v3/handlers/addons/delete.goapi/v3/handlers/addons/get.goapi/v3/handlers/addons/handler.goapi/v3/handlers/addons/list.goapi/v3/handlers/addons/publish.goapi/v3/handlers/addons/update.goapi/v3/server/routes.goapi/v3/server/server.goopenmeter/server/server.go
Overview
Fixes #(issue)
Notes for reviewer
Summary by CodeRabbit