From d157735d5036b98e9a055d8211476690be0e59e7 Mon Sep 17 00:00:00 2001 From: violog <51th.apprent1ce.f0rce@gmail.com> Date: Tue, 18 Jun 2024 11:09:33 +0300 Subject: [PATCH] Add inverted filter by event type --- ...ntegrations@rarime-points-svc@v1@public@events.yaml | 10 ++++++++++ internal/data/events.go | 1 + internal/data/pg/events.go | 7 +++++++ internal/service/handlers/list_events.go | 1 + internal/service/requests/list_events.go | 1 + 5 files changed, 20 insertions(+) diff --git a/docs/spec/paths/integrations@rarime-points-svc@v1@public@events.yaml b/docs/spec/paths/integrations@rarime-points-svc@v1@public@events.yaml index 00249fd..85ddae2 100644 --- a/docs/spec/paths/integrations@rarime-points-svc@v1@public@events.yaml +++ b/docs/spec/paths/integrations@rarime-points-svc@v1@public@events.yaml @@ -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. diff --git a/internal/data/events.go b/internal/data/events.go index 2cba7cd..cf2c62f 100644 --- a/internal/data/events.go +++ b/internal/data/events.go @@ -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 diff --git a/internal/data/pg/events.go b/internal/data/pg/events.go index 5ac1550..265cb87 100644 --- a/internal/data/pg/events.go +++ b/internal/data/pg/events.go @@ -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}) } diff --git a/internal/service/handlers/list_events.go b/internal/service/handlers/list_events.go index 42e4659..7cf1d72 100644 --- a/internal/service/handlers/list_events.go +++ b/internal/service/handlers/list_events.go @@ -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() diff --git a/internal/service/requests/list_events.go b/internal/service/requests/list_events.go index b30cc2a..340f4dd 100644 --- a/internal/service/requests/list_events.go +++ b/internal/service/requests/list_events.go @@ -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"` }