Skip to content

Commit

Permalink
feat: add names filter (#5865)
Browse files Browse the repository at this point in the history
  • Loading branch information
WitoDelnat authored Sep 25, 2024
1 parent 4567a1a commit 894db7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/repository/testworkflow/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type FilterImpl struct {
FName string
FNames []string
FLastNDays int
FStartDate *time.Time
FEndDate *time.Time
Expand All @@ -30,6 +31,11 @@ func (f *FilterImpl) WithName(name string) *FilterImpl {
return f
}

func (f *FilterImpl) WithNames(names []string) *FilterImpl {
f.FNames = names
return f
}

func (f *FilterImpl) WithLastNDays(days int) *FilterImpl {
f.FLastNDays = days
return f
Expand Down Expand Up @@ -91,6 +97,14 @@ func (f FilterImpl) NameDefined() bool {
return f.FName != ""
}

func (f FilterImpl) Names() []string {
return f.FNames
}

func (f FilterImpl) NamesDefined() bool {
return len(f.FNames) > 0
}

func (f FilterImpl) LastNDaysDefined() bool {
return f.FLastNDays > 0
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/repository/testworkflow/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const PageDefaultLimit int = 100
type Filter interface {
Name() string
NameDefined() bool
Names() []string
NamesDefined() bool
LastNDays() int
LastNDaysDefined() bool
StartDate() time.Time
Expand Down
4 changes: 4 additions & 0 deletions pkg/repository/testworkflow/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ func composeQueryAndOpts(filter Filter) (bson.M, *options.FindOptions) {
query["workflow.name"] = filter.Name()
}

if filter.NamesDefined() {
query["workflow.name"] = bson.M{"$in": filter.Names()}
}

if filter.TextSearchDefined() {
query["name"] = bson.M{"$regex": primitive.Regex{Pattern: filter.TextSearch(), Options: "i"}}
}
Expand Down

0 comments on commit 894db7e

Please sign in to comment.