Skip to content

Commit

Permalink
Merge pull request #131 from checkr/zz/add-description-like
Browse files Browse the repository at this point in the history
Add description_like query param
  • Loading branch information
zhouzhuojie authored Jun 18, 2018
2 parents 806b61a + c048085 commit 854a5f0
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 13 deletions.
8 changes: 6 additions & 2 deletions docs/api_docs/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ paths:
- in: query
name: enabled
type: boolean
description: return only flags having given enabled status
description: return flags having given enabled status
- in: query
name: description
type: string
description: return only flags matching given description
description: return flags exactly matching given description
- in: query
name: description_like
type: string
description: return flags partially matching given description
responses:
'200':
description: list all the flags
Expand Down
12 changes: 12 additions & 0 deletions pkg/entity/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
package entity

import (
"fmt"
"strings"

"github.com/jinzhu/gorm"
)

Expand Down Expand Up @@ -67,3 +70,12 @@ func (f *Flag) PrepareEvaluation() error {
}
return nil
}

// DescriptionLike patches the autogenerated queryset for find flags that
// partially match the description
func (qs FlagQuerySet) DescriptionLike(description string) FlagQuerySet {
return qs.w(qs.db.Where(
"lower(description) like ?",
fmt.Sprintf("%%%s%%", strings.ToLower(description)),
))
}
3 changes: 3 additions & 0 deletions pkg/handler/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func (c *crud) FindFlags(params flag.FindFlagsParams) middleware.Responder {
if params.Description != nil {
q = q.DescriptionEq(*params.Description)
}
if params.DescriptionLike != nil {
q = q.DescriptionLike(*params.DescriptionLike)
}
if params.Limit != nil {
q = q.Limit(int(*params.Limit))
}
Expand Down
8 changes: 6 additions & 2 deletions swagger/flags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ get:
- in: query
name: enabled
type: boolean
description: return only flags having given enabled status
description: return flags having given enabled status
- in: query
name: description
type: string
description: return only flags matching given description
description: return flags exactly matching given description
- in: query
name: description_like
type: string
description: return flags partially matching given description
responses:
200:
description: list all the flags
Expand Down
20 changes: 16 additions & 4 deletions swagger_gen/restapi/embedded_spec.go

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

31 changes: 29 additions & 2 deletions swagger_gen/restapi/operations/flag/find_flags_parameters.go

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

15 changes: 12 additions & 3 deletions swagger_gen/restapi/operations/flag/find_flags_urlbuilder.go

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

0 comments on commit 854a5f0

Please sign in to comment.