Skip to content

Commit

Permalink
Refactor assets.MsgCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Oct 26, 2023
1 parent 04d9e56 commit a31ea5a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
15 changes: 5 additions & 10 deletions assets/msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
}

Expand Down
17 changes: 8 additions & 9 deletions assets/static/msg_catalog.go
Original file line number Diff line number Diff line change
@@ -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_ }

Expand Down
4 changes: 2 additions & 2 deletions flows/actions/send_msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion flows/engine/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion flows/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type SessionAssets interface {
Groups() *GroupAssets
Labels() *LabelAssets
Locations() *LocationAssets
MsgCatalog() *MsgCatalogAssets
MsgCatalogs() *MsgCatalogAssets
Resthooks() *ResthookAssets
Templates() *TemplateAssets
Ticketers() *TicketerAssets
Expand Down
10 changes: 5 additions & 5 deletions flows/msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ 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]
}

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
}
Expand Down

0 comments on commit a31ea5a

Please sign in to comment.