Skip to content

Commit

Permalink
Add channelUUID to MsgCatalog assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Oct 26, 2023
1 parent a31ea5a commit 0bd3915
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions assets/msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type MsgCatalog interface {
UUID() MsgCatalogUUID
Name() string
Type() string
ChannelUUID() ChannelUUID
}

type MsgCatalogReference struct {
Expand Down
18 changes: 11 additions & 7 deletions assets/static/msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ import (
)

type MsgCatalog struct {
UUID_ assets.MsgCatalogUUID `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"`
ChannelUUID_ assets.ChannelUUID `json:"channel_uuid" validate:"required,channel_uuid`
}

func NewMsgCatalog(uuid assets.MsgCatalogUUID, name string, type_ string) assets.MsgCatalog {
func NewMsgCatalog(uuid assets.MsgCatalogUUID, name string, type_ string, channelUUID assets.ChannelUUID) assets.MsgCatalog {
return &MsgCatalog{
UUID_: uuid,
Name_: name,
Type_: type_,
UUID_: uuid,
Name_: name,
Type_: type_,
ChannelUUID_: channelUUID,
}
}

func (mc *MsgCatalog) UUID() assets.MsgCatalogUUID { return mc.UUID_ }

func (mc *MsgCatalog) ChannelUUID() assets.ChannelUUID { return mc.ChannelUUID_ }

func (mc *MsgCatalog) Name() string { return mc.Name_ }

func (mc *MsgCatalog) Type() string { return mc.Type_ }
2 changes: 1 addition & 1 deletion flows/actions/send_msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (a *SendMsgCatalogAction) Execute(run flows.FlowRun, step flows.Step, logMo
/////////////////////

msgCatalog := run.Session().Assets().MsgCatalogs()
mc := msgCatalog.Get(a.MsgCatalog.UUID)
mc := msgCatalog.GetByChannelUUID(channelRef.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
11 changes: 9 additions & 2 deletions flows/msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (s *MsgCatalogAssets) Get(uuid assets.MsgCatalogUUID) *MsgCatalog {
return s.byUUID[uuid]
}

func (s *MsgCatalogAssets) GetByChannelUUID(uuid assets.ChannelUUID) *MsgCatalog {
return s.byChannelUUID[uuid]
}

func (e *MsgCatalog) Asset() assets.MsgCatalog { return e.MsgCatalog }

// Reference returns a reference to this external service
Expand All @@ -61,15 +65,18 @@ func (e *MsgCatalog) Reference() *assets.MsgCatalogReference {
}

type MsgCatalogAssets struct {
byUUID map[assets.MsgCatalogUUID]*MsgCatalog
byUUID map[assets.MsgCatalogUUID]*MsgCatalog
byChannelUUID map[assets.ChannelUUID]*MsgCatalog
}

func NewMsgCatalogAssets(msgCatalogs []assets.MsgCatalog) *MsgCatalogAssets {
s := &MsgCatalogAssets{
byUUID: make(map[assets.MsgCatalogUUID]*MsgCatalog, len(msgCatalogs)),
byUUID: make(map[assets.MsgCatalogUUID]*MsgCatalog, len(msgCatalogs)),
byChannelUUID: make(map[assets.ChannelUUID]*MsgCatalog, len(msgCatalogs)),
}
for _, asset := range msgCatalogs {
s.byUUID[asset.UUID()] = NewMsgCatalog(asset)
s.byChannelUUID[asset.ChannelUUID()] = NewMsgCatalog(asset)
}
return s
}
Expand Down

0 comments on commit 0bd3915

Please sign in to comment.