add positions
This commit is contained in:
@@ -14,29 +14,32 @@ func NewStorageFile() storage.IStorage {
|
||||
return &storageFile{}
|
||||
}
|
||||
|
||||
func (s *storageFile) GetCatalog(_ context.Context) ([]*crm.CatalogRsp_Category, error) {
|
||||
func (s *storageFile) GetCatalog(_ context.Context) ([]*crm.Category, error) {
|
||||
data, err := os.ReadFile("resources/catalog.json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var res []*crm.CatalogRsp_Category
|
||||
var res []*crm.Category
|
||||
if err := json.Unmarshal(data, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *storageFile) GetAllProducts(ctx context.Context) ([]storage.Product, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *storageFile) GetProductByID(ctx context.Context, id int) (storage.Product, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (s *storageFile) GetBreadcrumbs(ctx context.Context, id int) ([]storage.Breadcrumb, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
func (s *storageFile) GetPositions(_ context.Context, id int64) ([]*crm.Product, error) {
|
||||
data, err := os.ReadFile("resources/products.json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var products []*crm.Product
|
||||
if err := json.Unmarshal(data, &products); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make([]*crm.Product, 0, len(products))
|
||||
for _, product := range products {
|
||||
if id == 0 || product.Category == id {
|
||||
res = append(res, product)
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user