Skip to content

Commit

Permalink
fix: set default value for notification silence ID for gorm
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 11, 2024
1 parent 9a4adb3 commit 3b34799
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions models/notifications.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package models

import (
"fmt"
"time"

"github.com/flanksource/duty/types"
Expand Down Expand Up @@ -119,15 +118,18 @@ type NotificationSilenceResource struct {
CheckID *string `json:"check_id,omitempty"`
}

func (t NotificationSilenceResource) Key() string {
return fmt.Sprintf("%s:%s:%s:%s", lo.FromPtr(t.ConfigID), lo.FromPtr(t.CanaryID), lo.FromPtr(t.ComponentID), lo.FromPtr(t.CheckID))
func (t NotificationSilenceResource) Empty() bool {
return lo.FromPtr(t.ConfigID) == "" &&
lo.FromPtr(t.CanaryID) == "" &&
lo.FromPtr(t.ComponentID) == "" &&
lo.FromPtr(t.CheckID) == ""
}

type NotificationSilence struct {
NotificationSilenceResource `json:",inline" yaml:",inline"`

ID uuid.UUID `json:"id"`
Namespace string `json:"namespace"`
ID uuid.UUID `json:"id" gorm:"default:generate_ulid()"`
Namespace string `json:"namespace,omitempty"`
From time.Time `json:"from"`
Until time.Time `json:"until"`
Source string `json:"source"`
Expand Down

0 comments on commit 3b34799

Please sign in to comment.