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

@ -153,9 +153,9 @@ func ParseGoodsItem(data []byte) (item entity.GoodsItem, err error) {
}
item.Sizes = entity.GoodsItemSize{
Width: entity.NewMilimeterDimension(w),
Height: entity.NewMilimeterDimension(h),
Length: entity.NewMilimeterDimension(l),
Width: entity.NewCentimeterDimensionOrEmpty(w),
Height: entity.NewCentimeterDimensionOrEmpty(h),
Length: entity.NewCentimeterDimensionOrEmpty(l),
}
createdAt := itemFBS.CreatedAt()

View File

@ -49,7 +49,15 @@ type Dimension struct {
Kind DimensionKind
}
func (d Dimension) IsZero() bool {
return d.Value == 0
}
func (d Dimension) MarshalText() ([]byte, error) {
if d.Value == 0 && d.Kind == DimensionKindUnspecified {
return nil, nil
}
value := strconv.FormatFloat(d.Value, 'f', 4, 64) + " " + d.Kind.String()
return []byte(value), nil
}
@ -114,10 +122,14 @@ func ParseDimention(value string, locale DimensionLocale) (Dimension, error) {
return out, nil
}
func NewMilimeterDimension(value float64) Dimension {
func NewCentimeterDimensionOrEmpty(value float64) Dimension {
if value == 0 {
return Dimension{}
}
return Dimension{
Value: value,
Kind: DimensionKindMilimeter,
Kind: DimensionKindCentimeter,
}
}

View File

@ -23,6 +23,7 @@ type Offer struct {
TypePrefix string `xml:"typePrefix"`
Description string `xml:"description"`
ManufacturerWarrany bool `xml:"manufacturer_warranty"`
Dimensions string `xml:"dimensions"`
Params []Param `xml:"param"`
}

View File

@ -385,7 +385,7 @@ func (c *client) getProductInfo(ctx context.Context, cartID int64) (pi entity.Go
}
cleanText := func(t string) string {
return strings.TrimSuffix(strings.TrimSpace(t), ":")
return strings.TrimSpace(strings.TrimSuffix(strings.TrimSpace(t), ":"))
}
const parametersSelector = "body > div.page-container > div.page-content > div.content-wrapper > div.content > div.row > div.col-md-4 > div > div > div:nth-child(6)"

View File

@ -34,6 +34,9 @@ func TestRadixMatcherWithPattern(t *testing.T) {
}, {
name: "should not match 2",
in: "whoa",
}, {
name: "should not match 3",
in: "alohaya",
}}
for _, tc := range tt {