Skip to content

Commit

Permalink
Remove duplicate products from the list
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Nov 7, 2023
1 parent b1eba2b commit a630c32
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions services/external/weni/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *service) Call(session flows.Session, params assets.MsgCatalogParam, log
return callResult, err
}
channelUUID := params.ChannelUUID
channel, err := models.GetActiveChannelByUUID(ctx, db, channelUUID)
channel, err := models.GetActiveChannelByUUID(ctx, *db, channelUUID)

Check failure on line 86 in services/external/weni/service.go

View workflow job for this annotation

GitHub Actions / Test (12)

cannot use *db (type sqlx.DB) as type models.Queryer in argument to models.GetActiveChannelByUUID:

Check failure on line 86 in services/external/weni/service.go

View workflow job for this annotation

GitHub Actions / Test (12)

cannot use *db (type sqlx.DB) as type models.Queryer in argument to models.GetActiveChannelByUUID:

Check failure on line 86 in services/external/weni/service.go

View workflow job for this annotation

GitHub Actions / Test (13)

cannot use *db (type sqlx.DB) as type models.Queryer in argument to models.GetActiveChannelByUUID:

Check failure on line 86 in services/external/weni/service.go

View workflow job for this annotation

GitHub Actions / Test (13)

cannot use *db (type sqlx.DB) as type models.Queryer in argument to models.GetActiveChannelByUUID:

Check failure on line 86 in services/external/weni/service.go

View workflow job for this annotation

GitHub Actions / Test (12)

cannot use *db (type sqlx.DB) as type models.Queryer in argument to models.GetActiveChannelByUUID:

Check failure on line 86 in services/external/weni/service.go

View workflow job for this annotation

GitHub Actions / Test (13)

cannot use *db (type sqlx.DB) as type models.Queryer in argument to models.GetActiveChannelByUUID:

Check failure on line 86 in services/external/weni/service.go

View workflow job for this annotation

GitHub Actions / Test (13)

cannot use *db (type sqlx.DB) as type models.Queryer in argument to models.GetActiveChannelByUUID:
if err != nil {
return callResult, err
}
Expand Down Expand Up @@ -160,15 +160,19 @@ func GetProductListFromSentenX(productSearch string, catalogID string, threshold
return nil, trace, errors.New("no products found on sentenx")
}

pmap := make(map[string]struct{})
productMap := make(map[string]struct{})
result := []map[string]string{}

for _, p := range searchResponse.Products {
pmap[p.ProductRetailerID] = struct{}{}
}
productID := p.ProductRetailerID

result := []map[string]string{}
for k := range pmap {
mapElement := map[string]string{"product_retailer_id": k}
result = append(result, mapElement)
_, exists := productMap[productID]
if !exists {
mapElement := map[string]string{"product_retailer_id": productID}
result = append(result, mapElement)

productMap[productID] = struct{}{}
}
}

return result, trace, nil
Expand Down

0 comments on commit a630c32

Please sign in to comment.