Skip to content

Commit

Permalink
fix: post notification override
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh committed Nov 28, 2024
1 parent 84dbeb1 commit a52b77a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 41 deletions.
25 changes: 0 additions & 25 deletions core/notification/receiver_selectors.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package notification

import (
"fmt"

"github.com/goto/siren/pkg/errors"
)

Expand Down Expand Up @@ -42,26 +40,3 @@ func (rs ReceiverSelectors) parseAndValidate() ([]map[string]string, map[string]

return castedSelectors, selectorConfig, nil
}

func (rs *ReceiverSelectors) FromMapString(rsMapString []map[string]string) {
*rs = ReceiverSelectors{}
for _, s := range rsMapString {
dSelector := map[string]any{}
for k, v := range s {
dSelector[k] = v
}
*rs = append(*rs, dSelector)
}
}

func (rs ReceiverSelectors) ToMapString() []map[string]string {
rcvSelectors := []map[string]string{}
for _, s := range rs {
selector := map[string]string{}
for k, v := range s {
selector[k] = fmt.Sprintf("%v", v)
}
rcvSelectors = append(rcvSelectors, selector)
}
return rcvSelectors
}
2 changes: 2 additions & 0 deletions internal/api/v1beta1/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func (s *GRPCServer) PostNotification(ctx context.Context, req *sirenv1beta1.Pos
for _, pbSelector := range req.GetReceivers() {
var mss = make(map[string]any)
for k, v := range pbSelector.AsMap() {
// skip if key is config
if k == "config" {
mss[k] = v
continue
}
vString, ok := v.(string)
Expand Down
24 changes: 12 additions & 12 deletions internal/store/model/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
)

type Notification struct {
ID string `db:"id"`
NamespaceID sql.NullInt64 `db:"namespace_id"`
Type string `db:"type"`
Data pgc.StringAnyMap `db:"data"`
Labels pgc.StringStringMap `db:"labels"`
ValidDuration pgc.TimeDuration `db:"valid_duration"`
UniqueKey sql.NullString `db:"unique_key"`
Template sql.NullString `db:"template"`
CreatedAt time.Time `db:"created_at"`
ReceiverSelectors pgc.ListStringStringMap `db:"receiver_selectors"`
ID string `db:"id"`
NamespaceID sql.NullInt64 `db:"namespace_id"`
Type string `db:"type"`
Data pgc.StringAnyMap `db:"data"`
Labels pgc.StringStringMap `db:"labels"`
ValidDuration pgc.TimeDuration `db:"valid_duration"`
UniqueKey sql.NullString `db:"unique_key"`
Template sql.NullString `db:"template"`
CreatedAt time.Time `db:"created_at"`
ReceiverSelectors pgc.ListStringAnyMap `db:"receiver_selectors"`
}

func (n *Notification) FromDomain(d notification.Notification) {
Expand Down Expand Up @@ -47,13 +47,13 @@ func (n *Notification) FromDomain(d notification.Notification) {
}

n.CreatedAt = d.CreatedAt
n.ReceiverSelectors = d.ReceiverSelectors.ToMapString()
n.ReceiverSelectors = pgc.ListStringAnyMap(d.ReceiverSelectors)
}

func (n *Notification) ToDomain() *notification.Notification {
var rcvSelectors notification.ReceiverSelectors
if len(n.ReceiverSelectors) > 0 {
rcvSelectors.FromMapString(n.ReceiverSelectors)
rcvSelectors = []map[string]any(n.ReceiverSelectors)
}
return &notification.Notification{
ID: n.ID,
Expand Down
8 changes: 4 additions & 4 deletions pkg/pgc/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func (t TimeDuration) Value() (driver.Value, error) {
return time.Duration(t).String(), nil
}

type ListStringStringMap []map[string]string
type ListStringAnyMap []map[string]any

func (m *ListStringStringMap) Scan(value interface{}) error {
func (m *ListStringAnyMap) Scan(value interface{}) error {
if value == nil {
m = new(ListStringStringMap)
m = new(ListStringAnyMap)
return nil
}
b, ok := value.([]byte)
Expand All @@ -90,7 +90,7 @@ func (m *ListStringStringMap) Scan(value interface{}) error {
return json.Unmarshal(b, &m)
}

func (a ListStringStringMap) Value() (driver.Value, error) {
func (a ListStringAnyMap) Value() (driver.Value, error) {
if len(a) == 0 {
return nil, nil
}
Expand Down

0 comments on commit a52b77a

Please sign in to comment.