support parsing item page info

This commit is contained in:
2024-02-03 20:28:33 +03:00
parent 6044e116f8
commit be6aec73df
10 changed files with 262 additions and 61 deletions

View File

@ -8,19 +8,20 @@ import (
)
type GoodsItem struct {
Articul string `json:"sku"`
Photo string `json:"photo"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
Type string `json:"type"`
Producer string `json:"producer"`
Pack int `json:"pack"`
Step int `json:"step"`
Price float64 `json:"price"`
TariffPrice float64 `json:"tariff_price"`
Cart int64 `json:"cart"`
Stock int `json:"stock"`
Articul string `json:"sku"`
PhotoURLs []string `json:"photo"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
Type string `json:"type"`
Producer string `json:"producer"`
Pack int `json:"pack"`
Step int `json:"step"`
Price float64 `json:"price"`
TariffPrice float64 `json:"tariff_price"`
Cart int64 `json:"cart"`
Stock int `json:"stock"`
Parameters map[string]string `json:"parameters"`
}
type GoodsItemRaw struct {
@ -42,12 +43,18 @@ type GoodsItemRaw struct {
Other string
}
type GoodsItemInfo struct {
Parameters map[string]string
PhotoURLs []string
}
type MappedGoodsRemnants map[int]GoodsRemnant
type GoodsRemnant [4]int32
func MakeGoodsItem(
gi GoodsItemRaw,
remnants MappedGoodsRemnants,
info GoodsItemInfo,
) (out GoodsItem, err error) {
var name, desc string
var pack, step int
@ -95,9 +102,13 @@ func MakeGoodsItem(
return out, fmt.Errorf("getting step count (%s): %w", gi.Step, err)
}
photoURLs := info.PhotoURLs
if len(photoURLs) > 7 {
photoURLs = info.PhotoURLs[:7]
}
return GoodsItem{
Articul: gi.SKU,
Photo: gi.Photo,
Name: name,
Description: desc,
Category: gi.Category,
@ -109,5 +120,7 @@ func MakeGoodsItem(
TariffPrice: tariffPrice,
Cart: int64(gi.Cart),
Stock: int(remnants[int(gi.Cart)][0]),
PhotoURLs: photoURLs,
Parameters: info.Parameters,
}, nil
}