Skip to content

Commit

Permalink
feat: executions list filtered by type (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
exu authored Jan 28, 2022
1 parent 62a1ed2 commit d4d0d70
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
9 changes: 9 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ paths:
operationId: listExecutions
parameters:
- $ref: "#/components/parameters/TestName"
- $ref: "#/components/parameters/Type"
- $ref: "#/components/parameters/TextSearch"
- $ref: "#/components/parameters/PageSize"
- $ref: "#/components/parameters/PageIndex"
Expand Down Expand Up @@ -1631,6 +1632,14 @@ components:
default: ""
description: test namespaced name to filter
required: false
Type:
in: query
name: type
schema:
type: string
default: ""
description: object type
required: false
TextSearch:
in: query
name: textSearch
Expand Down
5 changes: 5 additions & 0 deletions internal/app/api/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ func getFilterFromRequest(c *fiber.Ctx) result.Filter {
filter = filter.WithStatus(testkube.ExecutionStatus(status))
}

objectType := c.Query("type", "")
if objectType != "" {
filter = filter.WithType(objectType)
}

dFilter := datefilter.NewDateFilter(c.Query("startDate", ""), c.Query("endDate", ""))
if dFilter.IsStartValid {
filter = filter.WithStartDate(dFilter.Start)
Expand Down
13 changes: 13 additions & 0 deletions internal/pkg/api/repository/result/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type filter struct {
pageSize int
textSearch string
tags []string
objectType string
}

func NewExecutionsFilter() *filter {
Expand Down Expand Up @@ -62,6 +63,10 @@ func (f *filter) WithTags(tags []string) *filter {
return f
}

func (f *filter) WithType(objectType string) *filter {
f.objectType = objectType
return f
}
func (f filter) ScriptName() string {
return f.scriptName
}
Expand Down Expand Up @@ -110,6 +115,14 @@ func (f filter) TextSearch() string {
return f.textSearch
}

func (f filter) TypeDefined() bool {
return f.objectType != ""
}

func (f filter) Type() string {
return f.objectType
}

func (f filter) Tags() []string {
return f.tags
}
2 changes: 2 additions & 0 deletions internal/pkg/api/repository/result/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type Filter interface {
TextSearchDefined() bool
TextSearch() string
Tags() []string
TypeDefined() bool
Type() string
}

type Repository interface {
Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/api/repository/result/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func (r *MongoRepository) EndExecution(ctx context.Context, id string, endTime t
}

func composeQueryAndOpts(filter Filter) (bson.M, *options.FindOptions) {

query := bson.M{}
opts := options.Find()
startTimeQuery := bson.M{}
Expand Down Expand Up @@ -197,6 +196,10 @@ func composeQueryAndOpts(filter Filter) (bson.M, *options.FindOptions) {
query["tags"] = filter.Tags()
}

if filter.TypeDefined() {
query["scripttype"] = filter.Type()
}

opts.SetSkip(int64(filter.Page() * filter.PageSize()))
opts.SetLimit(int64(filter.PageSize()))
opts.SetSort(bson.D{{"starttime", -1}})
Expand Down

0 comments on commit d4d0d70

Please sign in to comment.