update get breadcrumbs method
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-05-30 02:47:24 +07:00
parent ccaaddf938
commit 59e60c4be1
5 changed files with 66 additions and 57 deletions
@@ -113,7 +113,11 @@ func (s *storageFile) GetProduct(_ context.Context, id int64) (*crm.Product, err
return res, nil
}
func (s *storageFile) GetBreadcrumbs(_ context.Context, id int64) ([]*crm.Category, error) {
func (s *storageFile) GetBreadcrumbs(ctx context.Context, id int64) ([]*crm.Category, error) {
product, err := s.GetProduct(ctx, id)
if err != nil {
return nil, err
}
data, err := os.ReadFile("resources/catalog.json")
if err != nil {
return nil, err
@@ -122,7 +126,11 @@ func (s *storageFile) GetBreadcrumbs(_ context.Context, id int64) ([]*crm.Catego
if err := json.Unmarshal(data, &categories); err != nil {
return nil, err
}
return getBreadcrumbs(categories, id), nil
breadcrumbs := getBreadcrumbs(categories, product.Id)
breadcrumbs = append(breadcrumbs, &crm.Category{
Name: product.Name,
})
return breadcrumbs, nil
}
func getBreadcrumbs(categories []*crm.Category, id int64) []*crm.Category {