cake_crm/internal/app/server.go

51 lines
1.3 KiB
Go
Raw Normal View History

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