bpiek/api/products.go

32 lines
614 B
Go
Raw Normal View History

package api
import "gitea.24example.ru/spavelit/bpiek/model"
var products []model.Product
func (a *Api) GetProducts() ([]model.Product, error) {
if len(products) > 0 {
return products, nil
}
parentCategories, err := a.GetParentCategories()
if err != nil {
return nil, err
}
for _, category := range parentCategories {
categoriesAndProduct, err := a.GetCategoriesAndProductsBySlugParentCategory(category.Slug)
if err != nil {
return nil, err
}
if len(categoriesAndProduct.Products) != 0 {
products = append(products, categoriesAndProduct.Products...)
}
}
return products, nil
}