Compare commits

..

No commits in common. "fe6d333e04bf11eeb609bc651bdc459884e2e287" and "4f6af5cae97607894154faee4b9e6826568f6734" have entirely different histories.

3 changed files with 13 additions and 26 deletions

View File

@ -1,13 +0,0 @@
# cake_crm
Генерация контракта
```shell
make generate
```
Запуск
```shell
make run
```

View File

@ -3,7 +3,7 @@ package main
import (
"cake_crm/internal/app"
"cake_crm/internal/models/storage/storage_file"
proto "cake_crm/proto"
crm "cake_crm/proto"
"context"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
@ -29,7 +29,7 @@ func main() {
// Create a gRPC server object
s := grpc.NewServer()
// Attach the Greeter service to the server
proto.RegisterCRMServer(s, app.NewServer(storage))
crm.RegisterCRMServer(s, app.NewServer(storage))
// Serve gRPC server
log.Println("Serving gRPC on 0.0.0.0:8080")
go func() {
@ -48,7 +48,7 @@ func main() {
gwmux := runtime.NewServeMux()
// Register Greeter
err = proto.RegisterCRMHandler(context.Background(), gwmux, conn)
err = crm.RegisterCRMHandler(context.Background(), gwmux, conn)
if err != nil {
log.Fatalln("Failed to register gateway:", err)
}

View File

@ -2,12 +2,12 @@ package app
import (
"cake_crm/internal/models/storage"
proto "cake_crm/proto"
crm "cake_crm/proto"
"context"
)
type Server struct {
proto.UnimplementedCRMServer
crm.UnimplementedCRMServer
storage storage.IStorage
}
@ -17,34 +17,34 @@ func NewServer(storage storage.IStorage) *Server {
}
}
func (s *Server) GetCatalog(ctx context.Context, _ *proto.GetCatalogReq) (*proto.CatalogRsp, error) {
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 &proto.CatalogRsp{Categories: categories}, nil
return &crm.CatalogRsp{Categories: categories}, nil
}
func (s *Server) GetPositions(ctx context.Context, req *proto.GetPositionsReq) (*proto.PositionsRsp, error) {
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 &proto.PositionsRsp{Products: products}, nil
return &crm.PositionsRsp{Products: products}, nil
}
func (s *Server) GetProduct(ctx context.Context, req *proto.GetProductReq) (*proto.ProductRsp, error) {
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 &proto.ProductRsp{Product: product}, nil
return &crm.ProductRsp{Product: product}, nil
}
func (s *Server) GetBreadcrumbs(ctx context.Context, req *proto.GetBreadcrumbsReq) (*proto.BreadcrumbsRsp, error) {
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 &proto.BreadcrumbsRsp{Categories: breadcrumbs}, nil
return &crm.BreadcrumbsRsp{Categories: breadcrumbs}, nil
}