add positions

This commit is contained in:
2024-05-18 12:36:31 +07:00
parent 0960f3e9dc
commit afd5536246
10 changed files with 1146 additions and 213 deletions
+8
View File
@@ -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
}
+2 -4
View File
@@ -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)
}
+18 -15
View File
@@ -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
}