Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: executions list filtered by type #889

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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