cake_crm/internal/app/server.go

51 lines
1.2 KiB
Go
Raw Normal View History

2024-05-18 05:12:00 +00:00
package app
import (
"cake_crm/internal/models/storage"
crm "cake_crm/proto"
"context"
)
type Server struct {
crm.UnimplementedCRMServer
storage storage.IStorage
}
func NewServer(storage storage.IStorage) *Server {
return &Server{
storage: storage,
}
}
func (s *Server) GetCatalog(ctx context.Context, _ *crm.GetCatalogReq) (*crm.CatalogRsp, error) {
categories, err := s.storage.GetCatalog(ctx)
if err != nil {
return nil, err
}
return &crm.CatalogRsp{Categories: categories}, nil
}
2024-05-18 05:36:31 +00:00
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
}
2024-05-18 05:58:50 +00:00
func (s *Server) GetProduct(ctx context.Context, req *crm.GetProductReq) (*crm.ProductRsp, error) {
product, err := s.storage.GetProduct(ctx, req.Id)
if err != nil {
return nil, err
}
return &crm.ProductRsp{Product: product}, nil
}
2024-05-18 06:16:57 +00:00
func (s *Server) GetBreadcrumbs(ctx context.Context, req *crm.GetBreadcrumbsReq) (*crm.BreadcrumbsRsp, error) {
breadcrumbs, err := s.storage.GetBreadcrumbs(ctx, req.Id)
if err != nil {
return nil, err
}
return &crm.BreadcrumbsRsp{Categories: breadcrumbs}, nil
}