update db
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Владимир Фёдоров 2024-05-27 02:42:22 +07:00
parent 20a2f975fd
commit f2aedd7a98
3 changed files with 1109 additions and 39 deletions

View File

@ -9,6 +9,21 @@ import (
"os" "os"
) )
type Product struct {
Id int64 `json:"id"`
Article string `json:"article"`
Name string `json:"name"`
Uri string `json:"uri"`
Images []string `json:"images"`
Description string `json:"description"`
Group int64 `json:"group"`
Unit string `json:"unit"`
Inventory float64 `json:"inventory"`
Variants []*crm.Variant `json:"variants"`
Characteristics []*crm.Characteristic `json:"characteristics"`
Category int64 `json:"category"`
}
var ( var (
ErrProductNotFound = errors.New("product not found") ErrProductNotFound = errors.New("product not found")
) )
@ -54,16 +69,48 @@ func (s *storageFile) GetProduct(_ context.Context, id int64) (*crm.Product, err
if err != nil { if err != nil {
return nil, err return nil, err
} }
var products []*crm.Product var products []*Product
if err := json.Unmarshal(data, &products); err != nil { if err := json.Unmarshal(data, &products); err != nil {
return nil, err return nil, err
} }
for _, product := range products { var product *Product
if product.Id == id { for _, p := range products {
return product, nil if p.Id == id {
product = p
break
} }
} }
if product == nil {
return nil, ErrProductNotFound return nil, ErrProductNotFound
}
res := &crm.Product{
Id: product.Id,
Article: product.Article,
Name: product.Name,
Uri: product.Uri,
Images: product.Images,
Description: product.Description,
GroupedProducts: nil,
Unit: product.Unit,
Inventory: product.Inventory,
Variants: product.Variants,
Characteristics: product.Characteristics,
Category: product.Category,
}
for _, p := range products {
if p.Group == product.Group {
image := ""
if len(product.Images) > 0 {
image = p.Images[0]
}
res.GroupedProducts = append(res.GroupedProducts, &crm.GroupedProduct{
Name: p.Name,
Uri: p.Uri,
Image: image,
})
}
}
return res, nil
} }
func (s *storageFile) GetBreadcrumbs(_ context.Context, id int64) ([]*crm.Category, error) { func (s *storageFile) GetBreadcrumbs(_ context.Context, id int64) ([]*crm.Category, error) {

View File

@ -12,9 +12,21 @@
}, },
{ {
"id": 2, "id": 2,
"name": ахлава", "name": еченье бисквитное",
"uri": "/categories/2", "uri": "/categories/2",
"children": [] "children": []
},
{
"id": 3,
"name": "Печенье песочное",
"uri": "/categories/3",
"children": []
},
{
"id": 4,
"name": "Восточные сладости",
"uri": "/categories/4",
"children": []
} }
] ]
} }

File diff suppressed because it is too large Load Diff