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 4d1e8e4e..c9c991b3 100644 --- a/internal/api/graphql/graph/generated.go +++ b/internal/api/graphql/graph/generated.go @@ -23518,7 +23518,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 { @@ -23532,6 +23532,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 111a10d9..df91e326 100644 --- a/internal/api/graphql/graph/model/models_gen.go +++ b/internal/api/graphql/graph/model/models_gen.go @@ -231,6 +231,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 c553b5d7..cebb4e36 100644 --- a/internal/api/graphql/graph/schema/component_version.graphqls +++ b/internal/api/graphql/graph/schema/component_version.graphqls @@ -28,4 +28,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{}