From a31ea5a34295124099da60d9532835df7e0587d5 Mon Sep 17 00:00:00 2001 From: Robi9 Date: Thu, 26 Oct 2023 12:37:16 -0300 Subject: [PATCH] Refactor assets.MsgCatalog --- assets/msg_catalog.go | 15 +++++---------- assets/static/msg_catalog.go | 17 ++++++++--------- flows/actions/send_msg_catalog.go | 4 ++-- flows/engine/assets.go | 2 +- flows/interfaces.go | 2 +- flows/msg_catalog.go | 10 +++++----- 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/assets/msg_catalog.go b/assets/msg_catalog.go index 555c5e5f7..e4e9424fe 100644 --- a/assets/msg_catalog.go +++ b/assets/msg_catalog.go @@ -7,17 +7,17 @@ import ( "github.com/nyaruka/goflow/envs" ) -//type MsgCatalogUUID uuids.UUID +type MsgCatalogUUID uuids.UUID type MsgCatalog interface { - ChannelUUID() uuids.UUID + UUID() MsgCatalogUUID Name() string Type() string } type MsgCatalogReference struct { - UUID uuids.UUID `json:"uuid" validate:"required,uuid"` - Name string `json:"name"` + UUID MsgCatalogUUID `json:"uuid" validate:"required,uuid"` + Name string `json:"name"` } type MsgCatalogParam struct { @@ -49,12 +49,7 @@ func NewMsgCatalogParam(header string, body string, footer string, products []st return p } -type MsgCatalogCallAction struct { - Name string `json:"name"` - Value string `json:"value"` -} - -func NewMsgCatalogReference(uuid uuids.UUID, name string) *MsgCatalogReference { +func NewMsgCatalogReference(uuid MsgCatalogUUID, name string) *MsgCatalogReference { return &MsgCatalogReference{UUID: uuid, Name: name} } diff --git a/assets/static/msg_catalog.go b/assets/static/msg_catalog.go index 30812c79c..64af69cfe 100644 --- a/assets/static/msg_catalog.go +++ b/assets/static/msg_catalog.go @@ -1,25 +1,24 @@ package static import ( - "github.com/nyaruka/gocommon/uuids" "github.com/nyaruka/goflow/assets" ) type MsgCatalog struct { - ChannelUUID_ uuids.UUID `json:"uuid" validate:"required,uuid` - Name_ string `json:"name"` - Type_ string `json:"type"` + UUID_ assets.MsgCatalogUUID `json:"uuid" validate:"required,uuid` + Name_ string `json:"name"` + Type_ string `json:"type"` } -func NewMsgCatalog(uuid uuids.UUID, name string, type_ string) assets.MsgCatalog { +func NewMsgCatalog(uuid assets.MsgCatalogUUID, name string, type_ string) assets.MsgCatalog { return &MsgCatalog{ - ChannelUUID_: uuid, - Name_: name, - Type_: type_, + UUID_: uuid, + Name_: name, + Type_: type_, } } -func (mc *MsgCatalog) ChannelUUID() uuids.UUID { return mc.ChannelUUID_ } +func (mc *MsgCatalog) UUID() assets.MsgCatalogUUID { return mc.UUID_ } func (mc *MsgCatalog) Name() string { return mc.Name_ } diff --git a/flows/actions/send_msg_catalog.go b/flows/actions/send_msg_catalog.go index 3181c06ad..c3ff80a23 100644 --- a/flows/actions/send_msg_catalog.go +++ b/flows/actions/send_msg_catalog.go @@ -126,8 +126,8 @@ func (a *SendMsgCatalogAction) Execute(run flows.FlowRun, step flows.Step, logMo ///////////////////// - msgCatalog := run.Session().Assets().MsgCatalog() - mc := msgCatalog.Get(uuids.UUID(channelRef.UUID)) + msgCatalog := run.Session().Assets().MsgCatalogs() + mc := msgCatalog.Get(a.MsgCatalog.UUID) params := assets.NewMsgCatalogParam(evaluatedHeader, evaluatedBody, evaluatedFooter, products, a.ProductViewSettings.Action, string(a.Topic), a.AutomaticSearch, evaluatedSearch, envs.NilLanguage, uuids.UUID(dest.Channel.UUID())) c, err := a.call(run, step, params, mc, logEvent) if err != nil { diff --git a/flows/engine/assets.go b/flows/engine/assets.go index 6e6850872..c972f33c4 100644 --- a/flows/engine/assets.go +++ b/flows/engine/assets.go @@ -128,7 +128,7 @@ func (s *sessionAssets) Templates() *flows.TemplateAssets { return func (s *sessionAssets) Ticketers() *flows.TicketerAssets { return s.ticketers } func (s *sessionAssets) Topics() *flows.TopicAssets { return s.topics } func (s *sessionAssets) Users() *flows.UserAssets { return s.users } -func (s *sessionAssets) MsgCatalog() *flows.MsgCatalogAssets { return s.msgCatalog } +func (s *sessionAssets) MsgCatalogs() *flows.MsgCatalogAssets { return s.msgCatalog } func (s *sessionAssets) ResolveField(key string) assets.Field { f := s.Fields().Get(key) diff --git a/flows/interfaces.go b/flows/interfaces.go index b41e9a7e6..6026e5275 100644 --- a/flows/interfaces.go +++ b/flows/interfaces.go @@ -109,7 +109,7 @@ type SessionAssets interface { Groups() *GroupAssets Labels() *LabelAssets Locations() *LocationAssets - MsgCatalog() *MsgCatalogAssets + MsgCatalogs() *MsgCatalogAssets Resthooks() *ResthookAssets Templates() *TemplateAssets Ticketers() *TicketerAssets diff --git a/flows/msg_catalog.go b/flows/msg_catalog.go index 5613be553..55d02d923 100644 --- a/flows/msg_catalog.go +++ b/flows/msg_catalog.go @@ -49,7 +49,7 @@ func NewMsgCatalog(asset assets.MsgCatalog) *MsgCatalog { } } -func (s *MsgCatalogAssets) Get(uuid uuids.UUID) *MsgCatalog { +func (s *MsgCatalogAssets) Get(uuid assets.MsgCatalogUUID) *MsgCatalog { return s.byUUID[uuid] } @@ -57,19 +57,19 @@ func (e *MsgCatalog) Asset() assets.MsgCatalog { return e.MsgCatalog } // Reference returns a reference to this external service func (e *MsgCatalog) Reference() *assets.MsgCatalogReference { - return assets.NewMsgCatalogReference(e.ChannelUUID(), e.Name()) + return assets.NewMsgCatalogReference(e.UUID(), e.Name()) } type MsgCatalogAssets struct { - byUUID map[uuids.UUID]*MsgCatalog + byUUID map[assets.MsgCatalogUUID]*MsgCatalog } func NewMsgCatalogAssets(msgCatalogs []assets.MsgCatalog) *MsgCatalogAssets { s := &MsgCatalogAssets{ - byUUID: make(map[uuids.UUID]*MsgCatalog, len(msgCatalogs)), + byUUID: make(map[assets.MsgCatalogUUID]*MsgCatalog, len(msgCatalogs)), } for _, asset := range msgCatalogs { - s.byUUID[asset.ChannelUUID()] = NewMsgCatalog(asset) + s.byUUID[asset.UUID()] = NewMsgCatalog(asset) } return s }