From e905f640bad3c8a8a058b49e658e09188f06c977 Mon Sep 17 00:00:00 2001 From: Michael Reimsbach Date: Wed, 31 Jul 2024 15:28:26 +0200 Subject: [PATCH] feat(componentVersion): add version filter --- .../graph/baseResolver/component_version.go | 1 + internal/api/graphql/graph/generated.go | 9 ++++++++- internal/api/graphql/graph/model/models_gen.go | 1 + .../graph/schema/component_version.graphqls | 1 + internal/database/mariadb/component_version.go | 2 ++ .../database/mariadb/component_version_test.go | 17 +++++++++++++++++ internal/entity/component_version.go | 7 ++++--- 7 files changed, 34 insertions(+), 4 deletions(-) diff --git a/internal/api/graphql/graph/baseResolver/component_version.go b/internal/api/graphql/graph/baseResolver/component_version.go index 12f0dcbd..8b08978d 100644 --- a/internal/api/graphql/graph/baseResolver/component_version.go +++ b/internal/api/graphql/graph/baseResolver/component_version.go @@ -91,6 +91,7 @@ func ComponentVersionBaseResolver(app app.Heureka, ctx context.Context, filter * Paginated: entity.Paginated{First: first, After: afterId}, IssueId: issueId, ComponentId: componentId, + Version: filter.Version, } opt := GetListOptions(requestedFields) diff --git a/internal/api/graphql/graph/generated.go b/internal/api/graphql/graph/generated.go index 73f98935..e77fcea6 100644 --- a/internal/api/graphql/graph/generated.go +++ b/internal/api/graphql/graph/generated.go @@ -22900,7 +22900,7 @@ func (ec *executionContext) unmarshalInputComponentVersionFilter(ctx context.Con asMap[k] = v } - fieldsInOrder := [...]string{"issueId"} + fieldsInOrder := [...]string{"issueId", "version"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -22914,6 +22914,13 @@ func (ec *executionContext) unmarshalInputComponentVersionFilter(ctx context.Con return it, err } it.IssueID = data + case "version": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("version")) + data, err := ec.unmarshalOString2ᚕᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Version = data } } diff --git a/internal/api/graphql/graph/model/models_gen.go b/internal/api/graphql/graph/model/models_gen.go index 13a8f7bb..19d5e77f 100644 --- a/internal/api/graphql/graph/model/models_gen.go +++ b/internal/api/graphql/graph/model/models_gen.go @@ -230,6 +230,7 @@ func (this ComponentVersionEdge) GetCursor() *string { return this.Cursor } type ComponentVersionFilter struct { IssueID []*string `json:"issueId,omitempty"` + Version []*string `json:"version,omitempty"` } type ComponentVersionInput struct { diff --git a/internal/api/graphql/graph/schema/component_version.graphqls b/internal/api/graphql/graph/schema/component_version.graphqls index 74382730..e5938640 100644 --- a/internal/api/graphql/graph/schema/component_version.graphqls +++ b/internal/api/graphql/graph/schema/component_version.graphqls @@ -27,4 +27,5 @@ type ComponentVersionEdge implements Edge { input ComponentVersionFilter { issueId: [String], + version: [String], } \ No newline at end of file diff --git a/internal/database/mariadb/component_version.go b/internal/database/mariadb/component_version.go index d3989c52..c0e61032 100644 --- a/internal/database/mariadb/component_version.go +++ b/internal/database/mariadb/component_version.go @@ -59,6 +59,7 @@ func (s *SqlDatabase) getComponentVersionFilterString(filter *entity.ComponentVe fl = append(fl, buildFilterQuery(filter.Id, "CV.componentversion_id = ?", OP_OR)) fl = append(fl, buildFilterQuery(filter.IssueId, "CVI.componentversionissue_issue_id = ?", OP_OR)) fl = append(fl, buildFilterQuery(filter.ComponentId, "CV.componentversion_component_id = ?", OP_OR)) + fl = append(fl, buildFilterQuery(filter.Version, "CV.componentversion_version = ?", OP_OR)) fl = append(fl, "CV.componentversion_deleted_at IS NULL") return combineFilterQueries(fl, OP_AND) @@ -106,6 +107,7 @@ func (s *SqlDatabase) buildComponentVersionStatement(baseQuery string, filter *e filterParameters = buildQueryParameters(filterParameters, filter.Id) filterParameters = buildQueryParameters(filterParameters, filter.IssueId) filterParameters = buildQueryParameters(filterParameters, filter.ComponentId) + filterParameters = buildQueryParameters(filterParameters, filter.Version) if withCursor { filterParameters = append(filterParameters, cursor.Value) filterParameters = append(filterParameters, cursor.Limit) diff --git a/internal/database/mariadb/component_version_test.go b/internal/database/mariadb/component_version_test.go index 0e56c819..489da085 100644 --- a/internal/database/mariadb/component_version_test.go +++ b/internal/database/mariadb/component_version_test.go @@ -225,6 +225,23 @@ var _ = Describe("ComponentVersion", Label("database", "ComponentVersion"), func } }) }) + It("can filter by a version", func() { + cv := seedCollection.ComponentVersionRows[rand.Intn(len(seedCollection.ComponentVersionRows))] + + filter := &entity.ComponentVersionFilter{Version: []*string{&cv.Version.String}} + + entries, err := db.GetComponentVersions(filter) + + By("throwing no error", func() { + Expect(err).To(BeNil()) + }) + + By("returning expected elements", func() { + for _, entry := range entries { + Expect(entry.Version).To(BeEquivalentTo(cv.Version.String)) + } + }) + }) }) Context("and using pagination", func() { DescribeTable("can correctly paginate with x elements", func(pageSize int) { diff --git a/internal/entity/component_version.go b/internal/entity/component_version.go index b3b93cb5..9d88b2f2 100644 --- a/internal/entity/component_version.go +++ b/internal/entity/component_version.go @@ -7,9 +7,10 @@ import "time" type ComponentVersionFilter struct { Paginated - Id []*int64 `json:"id"` - IssueId []*int64 `json:"issue_id"` - ComponentId []*int64 `json:"component_id"` + Id []*int64 `json:"id"` + IssueId []*int64 `json:"issue_id"` + ComponentId []*int64 `json:"component_id"` + Version []*string `json:"version"` } type ComponentVersionAggregations struct{}