From 4ded17ed08d7df738b27e8ed075eb98835102b2d Mon Sep 17 00:00:00 2001 From: Alex Goth <64845621+GAlexIHU@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:28:44 +0200 Subject: [PATCH] Pass a list of IDs for exact querying (#1288) * feat: pass a list of IDs for exact querying * feat: support both id and key --- internal/productcatalog/feature_connector.go | 1 + internal/productcatalog/postgresadapter/feature.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/internal/productcatalog/feature_connector.go b/internal/productcatalog/feature_connector.go index 6e7c39439..7b48c6f97 100644 --- a/internal/productcatalog/feature_connector.go +++ b/internal/productcatalog/feature_connector.go @@ -58,6 +58,7 @@ func (f FeatureOrderBy) StrValues() []string { } type ListFeaturesParams struct { + IDsOrKeys []string Namespace string MeterSlugs []string IncludeArchived bool diff --git a/internal/productcatalog/postgresadapter/feature.go b/internal/productcatalog/postgresadapter/feature.go index 5ab8161c3..f5bcd8f1b 100644 --- a/internal/productcatalog/postgresadapter/feature.go +++ b/internal/productcatalog/postgresadapter/feature.go @@ -112,6 +112,12 @@ func (c *featureDBAdapter) ListFeatures(ctx context.Context, params productcatal query.Where(db_feature.MeterSlugIn(params.MeterSlugs...)) } + if len(params.IDsOrKeys) > 0 { + for _, idOrKey := range params.IDsOrKeys { + query.Where(db_feature.Or(db_feature.Key(idOrKey), db_feature.ID(idOrKey))) + } + } + if !params.IncludeArchived { query = query.Where(db_feature.Or(db_feature.ArchivedAtIsNil(), db_feature.ArchivedAtGT(clock.Now()))) }