Pavel Sinitsin
e14d4b188b
This commit introduces new API and client modules that provide functionality for managing categories and products. It includes the creation of `.gitignore`, necessary data models, API endpoints, and client authentication using go-resty. This forms the foundation for further enhancements to the category and product management features.
32 lines
612 B
Go
32 lines
612 B
Go
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
|
|
}
|
|
|
|
parentCategoris, err := a.GetParentCategories()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, category := range parentCategoris {
|
|
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
|
|
}
|