Skip to content

Commit

Permalink
Add inverted filter by event type
Browse files Browse the repository at this point in the history
  • Loading branch information
violog committed Jun 18, 2024
1 parent 5585bd2 commit d157735
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ get:
items:
type: string
example: "passport_scan"
- in: query
name: 'filter[meta.static.name][not]'
description: |
Inverted filter by event type name: excludes provided values
required: false
schema:
type: array
items:
type: string
example: "referral_specific"
- in: query
name: 'filter[has_expiration]'
description: Filter events by type which has or hasn't expiration.
Expand Down
1 change: 1 addition & 0 deletions internal/data/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type EventsQ interface {
FilterByNullifier(string) EventsQ
FilterByStatus(...EventStatus) EventsQ
FilterByType(...string) EventsQ
FilterByNotType(types ...string) EventsQ
FilterByUpdatedAtBefore(int64) EventsQ
FilterByExternalID(string) EventsQ
FilterInactiveNotClaimed(types ...string) EventsQ
Expand Down
7 changes: 7 additions & 0 deletions internal/data/pg/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ func (q *events) FilterByType(types ...string) data.EventsQ {
return q.applyCondition(squirrel.Eq{"type": types})
}

func (q *events) FilterByNotType(types ...string) data.EventsQ {
if len(types) == 0 {
return q
}
return q.applyCondition(squirrel.NotEq{"type": types})
}

func (q *events) FilterByExternalID(id string) data.EventsQ {
return q.applyCondition(squirrel.Eq{"external_id": id})
}
Expand Down
1 change: 1 addition & 0 deletions internal/service/handlers/list_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func ListEvents(w http.ResponseWriter, r *http.Request) {
FilterByNullifier(*req.FilterNullifier).
FilterByStatus(req.FilterStatus...).
FilterByType(req.FilterType...).
FilterByNotType(req.FilterNotType...).
FilterInactiveNotClaimed(inactiveTypes...).
Page(&req.OffsetPageParams).
Select()
Expand Down
1 change: 1 addition & 0 deletions internal/service/requests/list_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ListEvents struct {
FilterStatus []data.EventStatus `filter:"status"`
FilterType []string `filter:"meta.static.name"`
FilterHasExpiration *bool `filter:"has_expiration"`
FilterNotType []string `url:"filter[meta.static.name][not]"`
Count bool `url:"count"`
}

Expand Down

0 comments on commit d157735

Please sign in to comment.