Skip to content

Commit

Permalink
Add inverted filter also for public event types
Browse files Browse the repository at this point in the history
  • Loading branch information
violog committed Jun 18, 2024
1 parent d157735 commit 9f5d99b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ get:
items:
type: string
example: "passport_scan"
- in: query
name: 'filter[name][not]'
description: |
Inverted filter by type name: excludes provided values
required: false
schema:
type: array
items:
type: string
example: "referral_specific"
- in: query
name: 'filter[flag]'
description: Filter by configuration flags. Values are disjunctive (OR).
Expand Down
3 changes: 3 additions & 0 deletions internal/service/handlers/list_event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func ListEventTypes(w http.ResponseWriter, r *http.Request) {
types := EventTypes(r).List(
evtypes.FilterByNames(req.FilterName...),
evtypes.FilterByFlags(req.FilterFlag...),
func(ev evtypes.EventConfig) bool {
return len(req.FilterNotName) > 0 && !evtypes.FilterByNames(req.FilterNotName...)(ev)
},
)

resTypes := make([]resources.EventType, len(types))
Expand Down
9 changes: 6 additions & 3 deletions internal/service/requests/list_event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

type ListExpiredEvents struct {
FilterName []string `filter:"name"`
FilterFlag []string `filter:"flag"`
FilterName []string `filter:"name"`
FilterFlag []string `filter:"flag"`
FilterNotName []string `url:"filter[name][not]"`
}

func NewListEventTypes(r *http.Request) (req ListExpiredEvents, err error) {
Expand All @@ -25,7 +26,9 @@ func NewListEventTypes(r *http.Request) (req ListExpiredEvents, err error) {
evtypes.FlagNotStarted,
evtypes.FlagExpired,
evtypes.FlagDisabled,
)))}.Filter()
))),
"filter[name][not]": val.Validate(req.FilterNotName, val.When(len(req.FilterName) > 0, val.Nil, val.Empty)),
}.Filter()

return
}
9 changes: 5 additions & 4 deletions internal/service/requests/list_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"strings"

validation "github.com/go-ozzo/ozzo-validation/v4"
val "github.com/go-ozzo/ozzo-validation/v4"
"github.com/rarimo/rarime-points-svc/internal/data"
"github.com/rarimo/rarime-points-svc/internal/service/page"
"gitlab.com/distributed_lab/urlval/v4"
Expand Down Expand Up @@ -33,9 +33,10 @@ func NewListEvents(r *http.Request) (req ListEvents, err error) {
*req.FilterNullifier = strings.ToLower(*req.FilterNullifier)
}

err = validation.Errors{
"filter[nullifier]": validation.Validate(req.FilterNullifier, validation.Required, validation.Match(nullifierRegexp)),
"filter[status]": validation.Validate(req.FilterStatus, validation.Each(validation.In(data.EventOpen, data.EventFulfilled, data.EventClaimed))),
err = val.Errors{
"filter[nullifier]": val.Validate(req.FilterNullifier, val.Required, val.Match(nullifierRegexp)),
"filter[status]": val.Validate(req.FilterStatus, val.Each(val.In(data.EventOpen, data.EventFulfilled, data.EventClaimed))),
"filter[meta.static.name][not]": val.Validate(req.FilterNotType, val.When(len(req.FilterType) > 0, val.Nil, val.Empty)),
}.Filter()
return
}

0 comments on commit 9f5d99b

Please sign in to comment.