Skip to content

Commit

Permalink
Merge pull request #1410 from openmeterio/feat/event-filtering
Browse files Browse the repository at this point in the history
feat: add filtering by rule and channel
  • Loading branch information
chrisgacsal authored Aug 22, 2024
2 parents cfa5260 + 9854c59 commit 1244af9
Show file tree
Hide file tree
Showing 6 changed files with 695 additions and 590 deletions.
617 changes: 322 additions & 295 deletions api/api.gen.go

Large diffs are not rendered by default.

633 changes: 338 additions & 295 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,28 @@ paths:
- $ref: "#/components/parameters/queryTo"
- $ref: "#/components/parameters/queryFilterFeature"
- $ref: "#/components/parameters/queryFilterSubject"
- name: rule
description: |
Filtering by multiple rules.
Usage: `?rule=ID1&rule=rule=ID2`
in: query
required: false
schema:
type: array
items:
type: string
- name: channel
description: |
Filtering by multiple channels.
Usage: `?channel=ID1&channel=ID2`
in: query
required: false
schema:
type: array
items:
type: string
responses:
"200":
description: List of notification events.
Expand Down
3 changes: 3 additions & 0 deletions internal/notification/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ type ListEventsInput struct {
Subjects []string `json:"subjects,omitempty"`
Features []string `json:"features,omitempty"`

Rules []string `json:"rules,omitempty"`
Channels []string `json:"channels,omitempty"`

DeduplicationHashes []string `json:"deduplicationHashes,omitempty"`

DeliveryStatusStates []EventDeliveryStatusState `json:"deliveryStatusStates,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions internal/notification/httpdriver/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (h *handler) ListEvents() ListEventsHandler {
},
Subjects: defaultx.WithDefault(params.Subject, nil),
Features: defaultx.WithDefault(params.Feature, nil),
Rules: defaultx.WithDefault(params.Rule, nil),
Channels: defaultx.WithDefault(params.Channel, nil),
From: defaultx.WithDefault(params.From, time.Time{}),
To: defaultx.WithDefault(params.To, time.Time{}),
}
Expand Down
8 changes: 8 additions & 0 deletions internal/notification/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ func (r repository) ListEvents(ctx context.Context, params notification.ListEven
)
}

if len(params.Rules) > 0 {
query = query.Where(eventdb.RuleIDIn(params.Rules...))
}

if len(params.Channels) > 0 {
query = query.Where(eventdb.HasRulesWith(ruledb.HasChannelsWith(channeldb.IDIn(params.Channels...))))
}

query = query.WithRules(func(query *entdb.NotificationRuleQuery) {
query.WithChannels()
})
Expand Down

0 comments on commit 1244af9

Please sign in to comment.