Skip to content

Commit

Permalink
Use hideUnavailable for product search
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Oct 24, 2024
1 parent 610ba90 commit 38a5ed5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 39 deletions.
40 changes: 21 additions & 19 deletions assets/msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ type MsgCatalogReference struct {
}

type MsgCatalogParam struct {
ProductSearch string `json:"product_search,omitempty"`
ChannelUUID uuids.UUID `json:"channel_uuid,omitempty"`
SearchType string `json:"search_type,omitempty"`
SearchUrl string `json:"search_url,omitempty"`
ApiType string `json:"api_type,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
SellerId string `json:"seller_id,omitempty"`
HasVtexAds bool `json:"vtex_ads,omitempty"`
Language string `json:"language"`
ProductSearch string `json:"product_search,omitempty"`
ChannelUUID uuids.UUID `json:"channel_uuid,omitempty"`
SearchType string `json:"search_type,omitempty"`
SearchUrl string `json:"search_url,omitempty"`
ApiType string `json:"api_type,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
SellerId string `json:"seller_id,omitempty"`
HasVtexAds bool `json:"vtex_ads,omitempty"`
HideUnavaliable bool `json:"hide_unavaliable"`
Language string `json:"language"`
}

func NewMsgCatalogParam(productSearch string, channelUUID uuids.UUID, searchType string, searchUrl string, apiType string, postalCode string, sellerId string, hasVtexAds bool, language string) MsgCatalogParam {
func NewMsgCatalogParam(productSearch string, channelUUID uuids.UUID, searchType string, searchUrl string, apiType string, postalCode string, sellerId string, hasVtexAds bool, hideUnavaliable bool, language string) MsgCatalogParam {
p := MsgCatalogParam{
ProductSearch: productSearch,
ChannelUUID: channelUUID,
SearchType: searchType,
SearchUrl: searchUrl,
ApiType: apiType,
PostalCode: postalCode,
SellerId: sellerId,
HasVtexAds: hasVtexAds,
Language: language,
ProductSearch: productSearch,
ChannelUUID: channelUUID,
SearchType: searchType,
SearchUrl: searchUrl,
ApiType: apiType,
PostalCode: postalCode,
SellerId: sellerId,
HasVtexAds: hasVtexAds,
HideUnavaliable: hideUnavaliable,
Language: language,
}
return p
}
Expand Down
14 changes: 8 additions & 6 deletions assets/org_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ type OrgContext interface {
ChannelUUID() ChannelUUID
ProjectUUID() uuids.UUID
HasVtexAds() bool
HideUnavaliable() bool
}

type OrgContextReference struct {
Context string `json:"context"`
UUID string `json:"uuid"`
ProjectUUID uuids.UUID `json:"project_uuid"`
HasVtexAds bool `json:"vtex_ads"`
Context string `json:"context"`
UUID string `json:"uuid"`
ProjectUUID uuids.UUID `json:"project_uuid"`
HasVtexAds bool `json:"vtex_ads"`
HideUnavaliable bool `json:"hide_unavaliable"`
}

func NewOrgContextReference(orgContext string, projectUUID uuids.UUID, hasVtexAds bool) *OrgContextReference {
return &OrgContextReference{Context: orgContext, ProjectUUID: projectUUID, HasVtexAds: hasVtexAds}
func NewOrgContextReference(orgContext string, projectUUID uuids.UUID, hasVtexAds bool, hideUnavaliable bool) *OrgContextReference {
return &OrgContextReference{Context: orgContext, ProjectUUID: projectUUID, HasVtexAds: hasVtexAds, HideUnavaliable: hideUnavaliable}
}

func (r *OrgContextReference) Type() string {
Expand Down
22 changes: 13 additions & 9 deletions assets/static/org_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import (
)

type OrgContext struct {
Context_ string `json:"context" validate:"required,context"`
ChannelUUID_ assets.ChannelUUID `json:"channel_uuid"`
ProjectUUID_ uuids.UUID `json:"project_uuid"`
HasVtexAds_ bool `json:"vtex_ads"`
Context_ string `json:"context" validate:"required,context"`
ChannelUUID_ assets.ChannelUUID `json:"channel_uuid"`
ProjectUUID_ uuids.UUID `json:"project_uuid"`
HasVtexAds_ bool `json:"vtex_ads"`
HideUnavaliable_ bool `json:"hide_unavaliable"`
}

func NewOrgContext(context string, channelUUID assets.ChannelUUID, projectUUID uuids.UUID, hasVtexAds bool) assets.OrgContext {
func NewOrgContext(context string, channelUUID assets.ChannelUUID, projectUUID uuids.UUID, hasVtexAds bool, hideUnavaliable bool) assets.OrgContext {
return &OrgContext{
Context_: context,
ChannelUUID_: channelUUID,
ProjectUUID_: projectUUID,
HasVtexAds_: hasVtexAds,
Context_: context,
ChannelUUID_: channelUUID,
ProjectUUID_: projectUUID,
HasVtexAds_: hasVtexAds,
HideUnavaliable_: hideUnavaliable,
}
}

Expand All @@ -28,3 +30,5 @@ func (c *OrgContext) ChannelUUID() assets.ChannelUUID { return c.ChannelUUID_ }
func (c *OrgContext) ProjectUUID() uuids.UUID { return c.ProjectUUID_ }

func (c *OrgContext) HasVtexAds() bool { return c.HasVtexAds_ }

func (c *OrgContext) HideUnavaliable() bool { return c.HideUnavaliable_ }
2 changes: 1 addition & 1 deletion assets/static/org_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestOrgContext(t *testing.T) {
oc := static.NewOrgContext("context 1", assets.ChannelUUID("e3c07fe2-7542-42c6-a394-18d968999f51"), uuids.UUID("80cb8631-b84a-4949-a483-a3103f00edc2"), false)
oc := static.NewOrgContext("context 1", assets.ChannelUUID("e3c07fe2-7542-42c6-a394-18d968999f51"), uuids.UUID("80cb8631-b84a-4949-a483-a3103f00edc2"), false, false)

assert.Equal(t, "context 1", oc.Context())
assert.Equal(t, assets.ChannelUUID("e3c07fe2-7542-42c6-a394-18d968999f51"), oc.ChannelUUID())
Expand Down
8 changes: 7 additions & 1 deletion flows/actions/send_msg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,18 @@ func (a *SendMsgCatalogAction) Execute(run flows.FlowRun, step flows.Step, logMo
hasVtexAds = context.OrgContext.HasVtexAds()
}

context = orgContext.GetHideUnavaliableByChannelUUID()
var hideUnavaliable bool
if context != nil {
hideUnavaliable = context.OrgContext.HideUnavaliable()
}

language := "eng"
if run.Contact().Language() != envs.NilLanguage && run.Contact().Language() != "base" {
language = string(run.Contact().Language())
}

params := assets.NewMsgCatalogParam(evaluatedSearch, uuids.UUID(dest.Channel.UUID()), a.SearchType, evaluatedURL, apiType, evaluatedPostalCode, evaluatedSellerId, hasVtexAds, language)
params := assets.NewMsgCatalogParam(evaluatedSearch, uuids.UUID(dest.Channel.UUID()), a.SearchType, evaluatedURL, apiType, evaluatedPostalCode, evaluatedSellerId, hasVtexAds, hideUnavaliable, language)
catalogCall, err := a.call(run, step, params, mc, logEvent)
if err != nil {
if catalogCall != nil {
Expand Down
11 changes: 10 additions & 1 deletion flows/org_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,23 @@ func (c *OrgContextAssets) GetHasVtexAdsByChannelUUID() *OrgContext {
return nil
}

func (c *OrgContextAssets) GetHideUnavaliableByChannelUUID() *OrgContext {
for _, c := range c.byChannelUUID {
if c.OrgContext.HideUnavaliable() {
return c
}
}
return nil
}

func (c *OrgContext) Asset() assets.OrgContext { return c.OrgContext }

// Reference returns a reference to this context
func (c *OrgContext) Reference() *assets.OrgContextReference {
if c == nil {
return nil
}
return assets.NewOrgContextReference(c.Context(), c.ProjectUUID(), c.HasVtexAds())
return assets.NewOrgContextReference(c.Context(), c.ProjectUUID(), c.HasVtexAds(), c.HideUnavaliable())
}

type OrgContextAssets struct {
Expand Down
4 changes: 2 additions & 2 deletions flows/org_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestOrgContext(t *testing.T) {
oc1 := static.NewOrgContext("context 1", assets.ChannelUUID("e3c07fe2-7542-42c6-a394-18d968999f51"), uuids.UUID("80cb8631-b84a-4949-a483-a3103f00edc2"), false)
oc1 := static.NewOrgContext("context 1", assets.ChannelUUID("e3c07fe2-7542-42c6-a394-18d968999f51"), uuids.UUID("80cb8631-b84a-4949-a483-a3103f00edc2"), false, false)

oc := flows.NewOrgContextAssets([]assets.OrgContext{oc1})

Expand All @@ -21,7 +21,7 @@ func TestOrgContext(t *testing.T) {
assert.Equal(t, assets.ChannelUUID("e3c07fe2-7542-42c6-a394-18d968999f51"), o1.ChannelUUID())
assert.Equal(t, uuids.UUID("80cb8631-b84a-4949-a483-a3103f00edc2"), o1.ProjectUUID())
assert.Equal(t, oc1, o1.Asset())
assert.Equal(t, assets.NewOrgContextReference("context 1", uuids.UUID("80cb8631-b84a-4949-a483-a3103f00edc2"), false), o1.Reference())
assert.Equal(t, assets.NewOrgContextReference("context 1", uuids.UUID("80cb8631-b84a-4949-a483-a3103f00edc2"), false, false), o1.Reference())

// nil object returns nil reference
assert.Nil(t, (*flows.OrgContext)(nil).Reference())
Expand Down

0 comments on commit 38a5ed5

Please sign in to comment.