Skip to content

Commit

Permalink
is: Use default if page limit is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaplots committed Oct 16, 2024
1 parent 3f8d901 commit af342ba
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 36 deletions.
16 changes: 14 additions & 2 deletions pkg/identityserver/application_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ func (is *IdentityServer) listApplicationAPIKeys(
}
ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down Expand Up @@ -398,7 +404,13 @@ func (is *IdentityServer) listApplicationCollaborators(

ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
8 changes: 7 additions & 1 deletion pkg/identityserver/application_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ func (is *IdentityServer) listApplications( // nolint:gocyclo
}
ctx = store.WithOrder(ctx, req.Order)
var total uint64
paginateCtx := store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
paginateCtx := store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
8 changes: 7 additions & 1 deletion pkg/identityserver/client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ func (is *IdentityServer) listClientCollaborators(

ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
8 changes: 7 additions & 1 deletion pkg/identityserver/client_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ func (is *IdentityServer) listClients(

ctx = store.WithOrder(ctx, req.Order)
var total uint64
paginateCtx := store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
paginateCtx := store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
8 changes: 4 additions & 4 deletions pkg/identityserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ import (
)

// Config for the Identity Server.

type Pagination struct {
DefaultLimit uint32 `name:"default-limit" description:"The default limit applied to paginated requests if not specified"`
}
type Config struct {
DatabaseURI string `name:"database-uri" description:"Database connection URI"`
UserRegistration struct {
Expand Down Expand Up @@ -128,6 +124,10 @@ type Config struct {
Pagination Pagination `name:"pagination" description:"Pagination settings"`
}

type Pagination struct {

Check failure on line 127 in pkg/identityserver/config.go

View workflow job for this annotation

GitHub Actions / Code Quality

exported: exported type Pagination should have comment or be unexported (revive)
DefaultLimit uint32 `name:"default-limit" description:"The default limit applied to paginated requests if not specified"`
}

type emailTemplatesConfig struct {
Source string `name:"source" description:"Source of the email template files (directory, url, blob)"` // nolint:lll
Static map[string][]byte `name:"-"`
Expand Down
8 changes: 7 additions & 1 deletion pkg/identityserver/end_device_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,13 @@ func (is *IdentityServer) listEndDevices(ctx context.Context, req *ttnpb.ListEnd
}
ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
16 changes: 14 additions & 2 deletions pkg/identityserver/gateway_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ func (is *IdentityServer) listGatewayAPIKeys(
}
ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down Expand Up @@ -389,7 +395,13 @@ func (is *IdentityServer) listGatewayCollaborators(

ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
8 changes: 7 additions & 1 deletion pkg/identityserver/gateway_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,13 @@ func (is *IdentityServer) listGateways( // nolint:gocyclo

ctx = store.WithOrder(ctx, req.Order)
var total uint64
paginateCtx := store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
paginateCtx := store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
8 changes: 7 additions & 1 deletion pkg/identityserver/invitation_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ func (is *IdentityServer) listInvitations(ctx context.Context, req *ttnpb.ListIn
return nil, errNoInviteRights.New()
}
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
8 changes: 7 additions & 1 deletion pkg/identityserver/notification_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,13 @@ func (is *IdentityServer) listNotifications(ctx context.Context, req *ttnpb.List
res := &ttnpb.ListNotificationsResponse{}
err := is.store.Transact(ctx, func(ctx context.Context, st store.Store) (err error) {
var total uint64
paginateCtx := store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
paginateCtx := store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
16 changes: 14 additions & 2 deletions pkg/identityserver/oauth_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ func (is *IdentityServer) listOAuthClientAuthorizations(ctx context.Context, req
}
ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down Expand Up @@ -60,7 +66,13 @@ func (is *IdentityServer) listOAuthAccessTokens(ctx context.Context, req *ttnpb.
}
ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
16 changes: 14 additions & 2 deletions pkg/identityserver/organization_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ func (is *IdentityServer) listOrganizationAPIKeys(
}
ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down Expand Up @@ -402,7 +408,13 @@ func (is *IdentityServer) listOrganizationCollaborators(

ctx = store.WithOrder(ctx, req.Order)
var total uint64
ctx = store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
ctx = store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
8 changes: 7 additions & 1 deletion pkg/identityserver/organization_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ func (is *IdentityServer) listOrganizations(

ctx = store.WithOrder(ctx, req.Order)
var total uint64
paginateCtx := store.WithPagination(ctx, req.Limit, req.Page, &total)
var limit uint32
if req.Limit == 0 {
limit = is.config.Pagination.DefaultLimit
} else {
limit = req.Limit
}
paginateCtx := store.WithPagination(ctx, limit, req.Page, &total)
defer func() {
if err == nil {
setTotalHeader(ctx, total)
Expand Down
Loading

0 comments on commit af342ba

Please sign in to comment.