diff --git a/internal/entitlement/connector.go b/internal/entitlement/connector.go index d83f261ad..4aebb05d3 100644 --- a/internal/entitlement/connector.go +++ b/internal/entitlement/connector.go @@ -20,7 +20,7 @@ const ( ) type ListEntitlementsParams struct { - Namespace string + Namespaces []string SubjectKey string FeatureIDs []string Limit int diff --git a/internal/entitlement/httpdriver/entitlement.go b/internal/entitlement/httpdriver/entitlement.go index ced221b9b..019d00374 100644 --- a/internal/entitlement/httpdriver/entitlement.go +++ b/internal/entitlement/httpdriver/entitlement.go @@ -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, "") { diff --git a/internal/entitlement/postgresadapter/entitlement.go b/internal/entitlement/postgresadapter/entitlement.go index c62ac2785..f1db92f00 100644 --- a/internal/entitlement/postgresadapter/entitlement.go +++ b/internal/entitlement/postgresadapter/entitlement.go @@ -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))