minor rework and filter dimensions

This commit is contained in:
Aleksandr Trushkin
2024-02-13 21:19:39 +03:00
parent 23a4f007fc
commit 8f26b8ba6d
13 changed files with 969 additions and 780 deletions

View File

@ -19,45 +19,52 @@ func (d dimensionDispatcher) isDimensionParam(value string) bool {
return d.heigth.Match(value) || d.width.Match(value) || d.length.Match(value)
}
func (d dimensionDispatcher) dispatch(ctx context.Context, value, key string, in *entity.GoodsItemSize) {
if !d.isDimensionParam(value) {
return
func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in *entity.GoodsItemSize) (updated bool) {
if !d.isDimensionParam(key) {
return false
}
log := zerolog.Ctx(ctx).With().Str("key", key).Str("value", value).Logger()
if strings.Contains(value, "/") {
dimensionValues := strings.Split(value, "/")
for _, dv := range dimensionValues {
d.dispatch(ctx, dv, key, in)
updated = updated || d.dispatch(ctx, key, dv, in)
}
} else {
out, err := entity.ParseDimention(key, entity.DimensionLocalRU)
out, err := entity.ParseDimention(value, entity.DimensionLocalRU)
if err != nil {
zerolog.Ctx(ctx).Warn().Err(err).Msg("unable to parse key, skipping")
return
log.Warn().Err(err).Msg("unable to parse key, skipping")
return false
}
out = out.AdjustTo(entity.DimensionKindCentimeter)
updated = true
switch {
case d.heigth.Match(value):
case d.heigth.Match(key):
in.Height = out
case d.width.Match(value):
case d.width.Match(key):
in.Width = out
case d.width.Match(value):
case d.length.Match(key):
in.Length = out
default:
zerolog.Ctx(ctx).Error().Str("key", key).Msg("unable to find proper matcher")
log.Error().Str("key", key).Msg("unable to find proper matcher")
updated = false
}
}
return updated
}
func makeDefaultDimensionDispatcher() dimensionDispatcher {
h := matcher.NewRadix(matcher.RadixCaseInsensitive())
h.Register("Высота")
h.Register("Высота/*")
w := matcher.NewRadix(matcher.RadixCaseInsensitive())
w.Register("Ширина")
w.Register("Ширина/*")
l := matcher.NewRadix(matcher.RadixCaseInsensitive())
l.Register("Длина")
l.Register("Длина/*")