Skip to content

Commit 7e18ee1

Browse files
authored
refactor: pagination (#3393)
1 parent 765c9ee commit 7e18ee1

File tree

103 files changed

+894
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+894
-449
lines changed

openmeter/app/adapter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AppAdapter interface {
1616
// Marketplace
1717
RegisterMarketplaceListing(input RegisterMarketplaceListingInput) error
1818
GetMarketplaceListing(ctx context.Context, input MarketplaceGetInput) (RegistryItem, error)
19-
ListMarketplaceListings(ctx context.Context, input MarketplaceListInput) (pagination.PagedResponse[RegistryItem], error)
19+
ListMarketplaceListings(ctx context.Context, input MarketplaceListInput) (pagination.Result[RegistryItem], error)
2020
InstallMarketplaceListingWithAPIKey(ctx context.Context, input InstallAppWithAPIKeyInput) (App, error)
2121
InstallMarketplaceListing(ctx context.Context, input InstallAppInput) (App, error)
2222
GetMarketplaceListingOauth2InstallURL(ctx context.Context, input GetOauth2InstallURLInput) (GetOauth2InstallURLOutput, error)
@@ -26,12 +26,12 @@ type AppAdapter interface {
2626
CreateApp(ctx context.Context, input CreateAppInput) (AppBase, error)
2727
GetApp(ctx context.Context, input GetAppInput) (App, error)
2828
UpdateApp(ctx context.Context, input UpdateAppInput) (App, error)
29-
ListApps(ctx context.Context, input ListAppInput) (pagination.PagedResponse[App], error)
29+
ListApps(ctx context.Context, input ListAppInput) (pagination.Result[App], error)
3030
UninstallApp(ctx context.Context, input UninstallAppInput) (*AppBase, error)
3131
UpdateAppStatus(ctx context.Context, input UpdateAppStatusInput) error
3232

3333
// Customer data
34-
ListCustomerData(ctx context.Context, input ListCustomerInput) (pagination.PagedResponse[CustomerApp], error)
34+
ListCustomerData(ctx context.Context, input ListCustomerInput) (pagination.Result[CustomerApp], error)
3535
EnsureCustomer(ctx context.Context, input EnsureCustomerInput) error
3636
DeleteCustomer(ctx context.Context, input DeleteCustomerInput) error
3737
}

openmeter/app/adapter/app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ func (a *adapter) UpdateAppStatus(ctx context.Context, input app.UpdateAppStatus
7272
}
7373

7474
// ListApps lists apps
75-
func (a *adapter) ListApps(ctx context.Context, params app.ListAppInput) (pagination.PagedResponse[app.App], error) {
75+
func (a *adapter) ListApps(ctx context.Context, params app.ListAppInput) (pagination.Result[app.App], error) {
7676
return entutils.TransactingRepo(
7777
ctx,
7878
a,
79-
func(ctx context.Context, repo *adapter) (pagination.PagedResponse[app.App], error) {
79+
func(ctx context.Context, repo *adapter) (pagination.Result[app.App], error) {
8080
query := repo.db.App.
8181
Query().
8282
Where(appdb.Namespace(params.Namespace))
@@ -107,7 +107,7 @@ func (a *adapter) ListApps(ctx context.Context, params app.ListAppInput) (pagina
107107
query = query.Where(appdb.IDIn(appIDs...))
108108
}
109109

110-
response := pagination.PagedResponse[app.App]{
110+
response := pagination.Result[app.App]{
111111
Page: params.Page,
112112
}
113113

openmeter/app/adapter/customer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
var _ app.AppAdapter = (*adapter)(nil)
1818

1919
// ListCustomerData lists app customer data
20-
func (a *adapter) ListCustomerData(ctx context.Context, input app.ListCustomerInput) (pagination.PagedResponse[app.CustomerApp], error) {
20+
func (a *adapter) ListCustomerData(ctx context.Context, input app.ListCustomerInput) (pagination.Result[app.CustomerApp], error) {
2121
if err := input.Validate(); err != nil {
22-
return pagination.PagedResponse[app.CustomerApp]{}, models.NewGenericValidationError(
22+
return pagination.Result[app.CustomerApp]{}, models.NewGenericValidationError(
2323
fmt.Errorf("error listing customer data: %w", err),
2424
)
2525
}
@@ -37,10 +37,10 @@ func (a *adapter) ListCustomerData(ctx context.Context, input app.ListCustomerIn
3737

3838
apps, err := a.ListApps(ctx, listInput)
3939
if err != nil {
40-
return pagination.PagedResponse[app.CustomerApp]{}, fmt.Errorf("failed to list apps: %w", err)
40+
return pagination.Result[app.CustomerApp]{}, fmt.Errorf("failed to list apps: %w", err)
4141
}
4242

43-
response := pagination.PagedResponse[app.CustomerApp]{
43+
response := pagination.Result[app.CustomerApp]{
4444
Page: input.Page,
4545
TotalCount: apps.TotalCount,
4646
Items: make([]app.CustomerApp, 0, len(apps.Items)),
@@ -51,7 +51,7 @@ func (a *adapter) ListCustomerData(ctx context.Context, input app.ListCustomerIn
5151
CustomerID: input.CustomerID,
5252
})
5353
if err != nil {
54-
return pagination.PagedResponse[app.CustomerApp]{}, fmt.Errorf("failed to get customer data for app %s: %w", customerApp.GetID().ID, err)
54+
return pagination.Result[app.CustomerApp]{}, fmt.Errorf("failed to get customer data for app %s: %w", customerApp.GetID().ID, err)
5555
}
5656

5757
response.Items = append(response.Items, app.CustomerApp{

openmeter/app/adapter/marketplace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
)
1414

1515
// ListMarketplaceListings lists marketplace listings
16-
func (a adapter) ListMarketplaceListings(ctx context.Context, input app.MarketplaceListInput) (pagination.PagedResponse[app.RegistryItem], error) {
16+
func (a adapter) ListMarketplaceListings(ctx context.Context, input app.MarketplaceListInput) (pagination.Result[app.RegistryItem], error) {
1717
items := lo.Values(a.registry)
1818
items = lo.Subset(items, (input.PageNumber-1)*input.PageSize, uint(input.PageSize))
1919

20-
response := pagination.PagedResponse[app.RegistryItem]{
20+
response := pagination.Result[app.RegistryItem]{
2121
Page: input.Page,
2222
Items: items,
2323
TotalCount: len(a.registry),

openmeter/app/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type AppService interface {
1414
// Marketplace
1515
RegisterMarketplaceListing(input RegisterMarketplaceListingInput) error
1616
GetMarketplaceListing(ctx context.Context, input MarketplaceGetInput) (RegistryItem, error)
17-
ListMarketplaceListings(ctx context.Context, input MarketplaceListInput) (pagination.PagedResponse[RegistryItem], error)
17+
ListMarketplaceListings(ctx context.Context, input MarketplaceListInput) (pagination.Result[RegistryItem], error)
1818
InstallMarketplaceListingWithAPIKey(ctx context.Context, input InstallAppWithAPIKeyInput) (App, error)
1919
InstallMarketplaceListing(ctx context.Context, input InstallAppInput) (App, error)
2020
GetMarketplaceListingOauth2InstallURL(ctx context.Context, input GetOauth2InstallURLInput) (GetOauth2InstallURLOutput, error)
@@ -25,11 +25,11 @@ type AppService interface {
2525
GetApp(ctx context.Context, input GetAppInput) (App, error)
2626
UpdateAppStatus(ctx context.Context, input UpdateAppStatusInput) error
2727
UpdateApp(ctx context.Context, input UpdateAppInput) (App, error)
28-
ListApps(ctx context.Context, input ListAppInput) (pagination.PagedResponse[App], error)
28+
ListApps(ctx context.Context, input ListAppInput) (pagination.Result[App], error)
2929
UninstallApp(ctx context.Context, input UninstallAppInput) error
3030

3131
// Customer data
32-
ListCustomerData(ctx context.Context, input ListCustomerInput) (pagination.PagedResponse[CustomerApp], error)
32+
ListCustomerData(ctx context.Context, input ListCustomerInput) (pagination.Result[CustomerApp], error)
3333
EnsureCustomer(ctx context.Context, input EnsureCustomerInput) error
3434
DeleteCustomer(ctx context.Context, input DeleteCustomerInput) error
3535
}

openmeter/app/service/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ func (s *Service) UpdateApp(ctx context.Context, input app.UpdateAppInput) (app.
8080
})
8181
}
8282

83-
func (s *Service) ListApps(ctx context.Context, input app.ListAppInput) (pagination.PagedResponse[app.App], error) {
83+
func (s *Service) ListApps(ctx context.Context, input app.ListAppInput) (pagination.Result[app.App], error) {
8484
if err := input.Validate(); err != nil {
85-
return pagination.PagedResponse[app.App]{}, models.NewGenericValidationError(err)
85+
return pagination.Result[app.App]{}, models.NewGenericValidationError(err)
8686
}
8787

8888
return s.adapter.ListApps(ctx, input)

openmeter/app/service/customer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
var _ app.AppService = (*Service)(nil)
1111

12-
func (s *Service) ListCustomerData(ctx context.Context, input app.ListCustomerInput) (pagination.PagedResponse[app.CustomerApp], error) {
12+
func (s *Service) ListCustomerData(ctx context.Context, input app.ListCustomerInput) (pagination.Result[app.CustomerApp], error) {
1313
return s.adapter.ListCustomerData(ctx, input)
1414
}
1515

openmeter/app/service/marketplace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func (s *Service) GetMarketplaceListing(ctx context.Context, input app.Marketpla
2626
return s.adapter.GetMarketplaceListing(ctx, input)
2727
}
2828

29-
func (s *Service) ListMarketplaceListings(ctx context.Context, input app.MarketplaceListInput) (pagination.PagedResponse[app.RegistryItem], error) {
29+
func (s *Service) ListMarketplaceListings(ctx context.Context, input app.MarketplaceListInput) (pagination.Result[app.RegistryItem], error) {
3030
if err := input.Validate(); err != nil {
31-
return pagination.PagedResponse[app.RegistryItem]{}, models.NewGenericValidationError(err)
31+
return pagination.Result[app.RegistryItem]{}, models.NewGenericValidationError(err)
3232
}
3333

3434
return s.adapter.ListMarketplaceListings(ctx, input)

openmeter/billing/adapter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Adapter interface {
2626

2727
type ProfileAdapter interface {
2828
CreateProfile(ctx context.Context, input CreateProfileInput) (*BaseProfile, error)
29-
ListProfiles(ctx context.Context, input ListProfilesInput) (pagination.PagedResponse[BaseProfile], error)
29+
ListProfiles(ctx context.Context, input ListProfilesInput) (pagination.Result[BaseProfile], error)
3030
GetProfile(ctx context.Context, input GetProfileInput) (*AdapterGetProfileResponse, error)
3131
GetDefaultProfile(ctx context.Context, input GetDefaultProfileInput) (*AdapterGetProfileResponse, error)
3232
DeleteProfile(ctx context.Context, input DeleteProfileInput) error

openmeter/billing/adapter/customeroverride.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (a *adapter) ListCustomerOverrides(ctx context.Context, input billing.ListC
262262
return billing.ListCustomerOverridesAdapterResult{}, err
263263
}
264264

265-
return pagination.MapPagedResponseError(res, func(dbCustomer *db.Customer) (billing.CustomerOverrideWithCustomerID, error) {
265+
return pagination.MapResultErr(res, func(dbCustomer *db.Customer) (billing.CustomerOverrideWithCustomerID, error) {
266266
if dbCustomer.Edges.BillingCustomerOverride == nil {
267267
return billing.CustomerOverrideWithCustomerID{
268268
CustomerID: customer.CustomerID{

0 commit comments

Comments
 (0)