bpiek/api/products.go
Pavel Sinitsin e14d4b188b
Add new API and client modules for category and product management
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.
2024-09-07 19:14:29 +03:00

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
}