Skip to content

Commit

Permalink
Merge pull request #1151 from openmeterio/list-entitlements-from-name…
Browse files Browse the repository at this point in the history
…spaces

feat: allow to list entitlements across namespaces
  • Loading branch information
chrisgacsal authored Jul 5, 2024
2 parents 663dac1 + 8ca61d7 commit de93f6a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/entitlement/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
)

type ListEntitlementsParams struct {
Namespace string
Namespaces []string
SubjectKey string
FeatureIDs []string
Limit int
Expand Down
6 changes: 3 additions & 3 deletions internal/entitlement/httpdriver/entitlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ func (h *entitlementHandler) ListEntitlements() ListEntitlementsHandler {
}

p := entitlement.ListEntitlementsParams{
Namespace: ns,
Limit: defaultx.WithDefault(params.Limit, 1000),
Offset: defaultx.WithDefault(params.Offset, 0),
Namespaces: []string{ns},
Limit: defaultx.WithDefault(params.Limit, 1000),
Offset: defaultx.WithDefault(params.Offset, 0),
}

switch defaultx.WithDefault(params.OrderBy, "") {
Expand Down
9 changes: 7 additions & 2 deletions internal/entitlement/postgresadapter/entitlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ func (a *entitlementDBAdapter) GetEntitlementsOfSubject(ctx context.Context, nam
}

func (a *entitlementDBAdapter) ListEntitlements(ctx context.Context, params entitlement.ListEntitlementsParams) ([]entitlement.Entitlement, error) {
query := withLatestUsageReset(a.db.Entitlement.Query().
Where(db_entitlement.Namespace(params.Namespace)))
query := a.db.Entitlement.Query()

if len(params.Namespaces) > 0 {
query = query.Where(db_entitlement.NamespaceIn(params.Namespaces...))
}

query = withLatestUsageReset(query)

if params.SubjectKey != "" {
query = query.Where(db_entitlement.SubjectKeyEQ(params.SubjectKey))
Expand Down

0 comments on commit de93f6a

Please sign in to comment.