Skip to content

Commit

Permalink
Merge pull request #1375 from openmeterio/notification-api
Browse files Browse the repository at this point in the history
fix: Notification API in backend
  • Loading branch information
chrisgacsal authored Aug 15, 2024
2 parents 75649ca + 49a9dd4 commit fbf29c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ func main() {
Notification: notificationService,
// modules
EntitlementsEnabled: conf.Entitlements.Enabled,
NotificationEnabled: conf.Notification.Enabled,
},
RouterHook: func(r chi.Router) {
r.Use(func(h http.Handler) http.Handler {
Expand Down
2 changes: 1 addition & 1 deletion internal/notification/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (h *handler) dispatchWebhook(ctx context.Context, event *Event) error {
Namespace: event.Namespace,
EventID: event.ID,
EventType: string(event.Type),
Channels: channelIDs,
Channels: []string{event.Rule.ID},
}

switch event.Type {
Expand Down
11 changes: 11 additions & 0 deletions internal/notification/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/openmeterio/openmeter/internal/notification/webhook"
"github.com/openmeterio/openmeter/internal/productcatalog"
"github.com/openmeterio/openmeter/pkg/models"
)

type Service interface {
Expand Down Expand Up @@ -406,6 +407,16 @@ func (c service) CreateEvent(ctx context.Context, params CreateEventInput) (*Eve
if err != nil {
return nil, fmt.Errorf("failed to get rule: %w", err)
}

if rule.DeletedAt != nil {
return nil, NotFoundError{
NamespacedID: models.NamespacedID{
Namespace: params.Namespace,
ID: params.RuleID,
},
}
}

if rule.Disabled {
return nil, ValidationError{
Err: errors.New("failed to send event: rule is disabled"),
Expand Down

0 comments on commit fbf29c2

Please sign in to comment.