add positions
This commit is contained in:
@@ -24,3 +24,11 @@ func (s *Server) GetCatalog(ctx context.Context, _ *crm.GetCatalogReq) (*crm.Cat
|
||||
}
|
||||
return &crm.CatalogRsp{Categories: categories}, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetPositions(ctx context.Context, req *crm.GetPositionsReq) (*crm.PositionsRsp, error) {
|
||||
products, err := s.storage.GetPositions(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &crm.PositionsRsp{Products: products}, nil
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ type Breadcrumb struct {
|
||||
}
|
||||
|
||||
type IStorage interface {
|
||||
GetAllProducts(ctx context.Context) ([]Product, error)
|
||||
GetProductByID(ctx context.Context, id int) (Product, error)
|
||||
GetBreadcrumbs(ctx context.Context, id int) ([]Breadcrumb, error)
|
||||
GetCatalog(ctx context.Context) ([]*crm.CatalogRsp_Category, error)
|
||||
GetCatalog(ctx context.Context) ([]*crm.Category, error)
|
||||
GetPositions(ctx context.Context, id int64) ([]*crm.Product, error)
|
||||
}
|
||||
|
||||
@@ -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