Compare commits
2 Commits
4f6af5cae9
...
fe6d333e04
Author | SHA1 | Date |
---|---|---|
Владимир Фёдоров | fe6d333e04 | |
Владимир Фёдоров | 05b10895d3 |
|
@ -0,0 +1,13 @@
|
||||||
|
# cake_crm
|
||||||
|
|
||||||
|
Генерация контракта
|
||||||
|
|
||||||
|
```shell
|
||||||
|
make generate
|
||||||
|
```
|
||||||
|
|
||||||
|
Запуск
|
||||||
|
|
||||||
|
```shell
|
||||||
|
make run
|
||||||
|
```
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"cake_crm/internal/app"
|
"cake_crm/internal/app"
|
||||||
"cake_crm/internal/models/storage/storage_file"
|
"cake_crm/internal/models/storage/storage_file"
|
||||||
crm "cake_crm/proto"
|
proto "cake_crm/proto"
|
||||||
"context"
|
"context"
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
@ -29,7 +29,7 @@ func main() {
|
||||||
// Create a gRPC server object
|
// Create a gRPC server object
|
||||||
s := grpc.NewServer()
|
s := grpc.NewServer()
|
||||||
// Attach the Greeter service to the server
|
// Attach the Greeter service to the server
|
||||||
crm.RegisterCRMServer(s, app.NewServer(storage))
|
proto.RegisterCRMServer(s, app.NewServer(storage))
|
||||||
// Serve gRPC server
|
// Serve gRPC server
|
||||||
log.Println("Serving gRPC on 0.0.0.0:8080")
|
log.Println("Serving gRPC on 0.0.0.0:8080")
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -48,7 +48,7 @@ func main() {
|
||||||
|
|
||||||
gwmux := runtime.NewServeMux()
|
gwmux := runtime.NewServeMux()
|
||||||
// Register Greeter
|
// Register Greeter
|
||||||
err = crm.RegisterCRMHandler(context.Background(), gwmux, conn)
|
err = proto.RegisterCRMHandler(context.Background(), gwmux, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Failed to register gateway:", err)
|
log.Fatalln("Failed to register gateway:", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cake_crm/internal/models/storage"
|
"cake_crm/internal/models/storage"
|
||||||
crm "cake_crm/proto"
|
proto "cake_crm/proto"
|
||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
crm.UnimplementedCRMServer
|
proto.UnimplementedCRMServer
|
||||||
storage storage.IStorage
|
storage storage.IStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,34 +17,34 @@ func NewServer(storage storage.IStorage) *Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GetCatalog(ctx context.Context, _ *crm.GetCatalogReq) (*crm.CatalogRsp, error) {
|
func (s *Server) GetCatalog(ctx context.Context, _ *proto.GetCatalogReq) (*proto.CatalogRsp, error) {
|
||||||
categories, err := s.storage.GetCatalog(ctx)
|
categories, err := s.storage.GetCatalog(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &crm.CatalogRsp{Categories: categories}, nil
|
return &proto.CatalogRsp{Categories: categories}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GetPositions(ctx context.Context, req *crm.GetPositionsReq) (*crm.PositionsRsp, error) {
|
func (s *Server) GetPositions(ctx context.Context, req *proto.GetPositionsReq) (*proto.PositionsRsp, error) {
|
||||||
products, err := s.storage.GetPositions(ctx, req.Id)
|
products, err := s.storage.GetPositions(ctx, req.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &crm.PositionsRsp{Products: products}, nil
|
return &proto.PositionsRsp{Products: products}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GetProduct(ctx context.Context, req *crm.GetProductReq) (*crm.ProductRsp, error) {
|
func (s *Server) GetProduct(ctx context.Context, req *proto.GetProductReq) (*proto.ProductRsp, error) {
|
||||||
product, err := s.storage.GetProduct(ctx, req.Id)
|
product, err := s.storage.GetProduct(ctx, req.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &crm.ProductRsp{Product: product}, nil
|
return &proto.ProductRsp{Product: product}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GetBreadcrumbs(ctx context.Context, req *crm.GetBreadcrumbsReq) (*crm.BreadcrumbsRsp, error) {
|
func (s *Server) GetBreadcrumbs(ctx context.Context, req *proto.GetBreadcrumbsReq) (*proto.BreadcrumbsRsp, error) {
|
||||||
breadcrumbs, err := s.storage.GetBreadcrumbs(ctx, req.Id)
|
breadcrumbs, err := s.storage.GetBreadcrumbs(ctx, req.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &crm.BreadcrumbsRsp{Categories: breadcrumbs}, nil
|
return &proto.BreadcrumbsRsp{Categories: breadcrumbs}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue