-
Notifications
You must be signed in to change notification settings - Fork 152
feat(api): add app endpoints to v3 api #3782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughAdds v3 app endpoints (ListApps, GetApp), wires AppService into the v3 server, and implements conversion/mapping code to translate internal app types and marketplace listings into v3 API representations with explicit error propagation. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ListAppsHandler
participant AppService
participant Converter
Client->>ListAppsHandler: GET /apps?page=&size=
ListAppsHandler->>ListAppsHandler: resolve namespace, validate page
ListAppsHandler->>AppService: ListApps(namespace, page)
AppService-->>ListAppsHandler: ([]app.App, PageMeta)
ListAppsHandler->>Converter: ConvertAppsToBillingApps(apps)
loop per app
Converter->>Converter: MapAppToAPI(app)
Converter->>Converter: ConvertAppTypeToV3Api(type)
Converter->>Converter: ConvertMetadataToLabels(metadata)
end
Converter-->>ListAppsHandler: []v3.BillingApp
ListAppsHandler->>Converter: ConvertToListAppResponse(paginated)
Converter-->>ListAppsHandler: v3.AppPagePaginatedResponse
ListAppsHandler-->>Client: 200 OK (paginated apps)
sequenceDiagram
participant Client
participant GetAppHandler
participant AppService
participant Converter
Client->>GetAppHandler: GET /apps/{appId}
GetAppHandler->>GetAppHandler: resolve namespace, extract appId
GetAppHandler->>AppService: GetApp(namespace, appId)
AppService-->>GetAppHandler: app.App
GetAppHandler->>Converter: MapAppToAPI(app)
Converter->>Converter: ConvertAppTypeToV3Api(type)
Converter->>Converter: ConvertMetadataToLabels(metadata)
Converter-->>GetAppHandler: v3.BillingApp
GetAppHandler-->>Client: 200 OK (single app)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@api/v3/handlers/apps/convert.gen.go`:
- Around line 13-27: ConvertAppTypeToV3Api currently panics on unknown
app.AppType in the switch default; replace that panic with a safe fallback or an
explicit error return: either map the default case to a safe enum like
v3.BillingAppTypeUnknown/v3.BillingAppTypeUnspecified (modify the default branch
of ConvertAppTypeToV3Api to assign that value) or change ConvertAppTypeToV3Api’s
signature to return (v3.BillingAppType, error) and return a typed error from the
default branch, then update callers to handle the error accordingly.
In `@api/v3/handlers/apps/convert.go`:
- Around line 17-27: The converter currently uses the goverter `@panic` behavior
for app.AppType (ConvertAppTypeToV3Api) which will crash on unknown enum values;
change the conversion to error-returning behavior instead: update
ConvertAppTypeToV3Api to return (apiv3.BillingAppType, error) (or return a safe
“unknown” value plus error) and regenerate the converters so the mapping no
longer panics, then update all call sites that use ConvertAppTypeToV3Api to
handle the returned error (or handle the unknown fallback) in request paths to
avoid crashing on future enum additions.
In `@api/v3/handlers/apps/mapper.go`:
- Around line 22-49: The switch branches perform unchecked type assertions
(e.g., item.(appstripeentityapp.App), item.(appsandbox.App),
item.(appcustominvoicing.App)) which can panic if concrete type differs; update
each branch (the Stripe, Sandbox, and CustomInvoicing cases) to use the
two-value form (v, ok := item.(Type)) and, if !ok, return a clear error instead
of asserting, then continue to call
mapStripeAppToAPI/mapSandboxAppToAPI/mapCustomInvoicingAppToAPI and the
respective api.BillingApp methods (FromBillingAppStripe, FromBillingAppSandbox,
FromBillingAppExternalInvoicing) only when ok is true.
🧹 Nitpick comments (1)
api/v3/handlers/apps/list_app.go (1)
66-71: Add app ID to mapping errors for easier debugging.
If a single item fails to map, including the app ID speeds up triage.💡 Suggested tweak
- apiAppItem, err := MapAppToAPI(item) - if err != nil { - return ListAppsResponse{}, fmt.Errorf("failed to map app to apiv3: %w", err) - } + apiAppItem, err := MapAppToAPI(item) + if err != nil { + return ListAppsResponse{}, fmt.Errorf("failed to map app %s to apiv3: %w", item.GetID(), err) + }
There was a problem hiding this 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
🤖 Fix all issues with AI agents
In `@api/v3/handlers/apps/convert.go`:
- Around line 109-125: In mapSandboxAppToAPI, populate the missing Description
and Labels fields on the returned api.BillingAppSandbox to match other mappers:
set Description to a pointer of sandboxApp.GetDescription() (e.g.,
lo.ToPtr(sandboxApp.GetDescription())) and set Labels to the metadata from
sandboxApp.GetMetadata() (or convert it the same way
mapStripeAppToAPI/mapCustomInvoicingAppToAPI do) so the sandbox mapping is
consistent with other app types.
🧹 Nitpick comments (1)
api/v3/handlers/apps/convert.go (1)
127-156: Looks good overall!Minor observation: the conditional check for metadata (lines 151-153) is good defensive coding. Just noting that
mapCustomInvoicingAppToAPIalways callsConvertMetadataToLabelswithout the nil check - the converter handles nil fine, but the inconsistency might confuse future readers.
Summary by CodeRabbit
New Features
Bug Fixes / Reliability
Infrastructure
✏️ Tip: You can customize this high-level summary in your review settings.