2024-09-07 19:14:29 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-09-07 21:18:36 +03:00
|
|
|
parentCategories, err := a.GetParentCategories()
|
2024-09-07 19:14:29 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-09-07 21:18:36 +03:00
|
|
|
for _, category := range parentCategories {
|
2024-09-07 19:14:29 +03:00
|
|
|
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
|
|
|
|
}
|