Skip to content

Commit

Permalink
feat(componentVersion): add version filter (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: David Rochow <[email protected]>
  • Loading branch information
MR2011 and drochow authored Jul 31, 2024
1 parent 43e0b1f commit e6985b0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion internal/api/graphql/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/api/graphql/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ type ComponentVersionEdge implements Edge {

input ComponentVersionFilter {
issueId: [String],
version: [String],
}
2 changes: 2 additions & 0 deletions internal/database/mariadb/component_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions internal/database/mariadb/component_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions internal/entity/component_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit e6985b0

Please sign in to comment.