From 4bd82a34a17f37eddaa200b7cc80db77dcef2287 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Thu, 23 May 2024 01:40:59 +0700 Subject: [PATCH 1/3] add book order --- .gitignore | 3 + api/main.proto | 23 ++ cmd/cake_crm/main.go | 18 +- go.mod | 2 +- go.sum | 4 +- internal/app/server.go | 118 +++++- internal/models/messenger/interface.go | 5 + .../models/messenger/telegram/messenger.go | 30 ++ internal/services/server_web/interface.go | 8 - internal/services/server_web/server.go | 43 --- proto/main.pb.go | 360 ++++++++++++++++-- proto/main.pb.gw.go | 95 +++++ proto/main_grpc.pb.go | 37 ++ resources/main.swagger.json | 72 ++++ 14 files changed, 717 insertions(+), 101 deletions(-) create mode 100644 internal/models/messenger/interface.go create mode 100644 internal/models/messenger/telegram/messenger.go delete mode 100644 internal/services/server_web/interface.go delete mode 100644 internal/services/server_web/server.go diff --git a/.gitignore b/.gitignore index 3aa5afa..e6b48dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .idea bin + +resources/order_bot_token.txt +resources/telegram_order_chat_id.txt diff --git a/api/main.proto b/api/main.proto index f0ff120..e19abfc 100644 --- a/api/main.proto +++ b/api/main.proto @@ -30,6 +30,12 @@ service CRM { get: "/breadcrumbs/{id}" }; } + rpc Order(OrderReq) returns (OrderRsp) { + option (google.api.http) = { + post: "/orders" + body: "order" + }; + } } message GetCatalogReq {} @@ -104,3 +110,20 @@ message GetBreadcrumbsReq { message BreadcrumbsRsp { repeated Category categories = 1; } + +message OrderReq { + Order order = 1; + string name = 2; + string phone = 3; +} + +message OrderRsp {} + +message Order { + repeated OrderItem items = 1; +} + +message OrderItem { + int64 product_id = 1; + int64 count = 2; +} diff --git a/cmd/cake_crm/main.go b/cmd/cake_crm/main.go index 521ed30..cefd17a 100644 --- a/cmd/cake_crm/main.go +++ b/cmd/cake_crm/main.go @@ -2,6 +2,7 @@ package main import ( "cake_crm/internal/app" + "cake_crm/internal/models/messenger/telegram" "cake_crm/internal/models/storage/storage_file" proto "cake_crm/proto" "context" @@ -12,11 +13,26 @@ import ( "net" "net/http" "os" + "strconv" ) func main() { storage := storage_file.NewStorageFile() + tokenData, err := os.ReadFile("resources/order_bot_token.txt") + if err != nil { + panic(err) + } + token := string(tokenData) + + chatIdData, err := os.ReadFile("resources/telegram_order_chat_id.txt") + if err != nil { + panic(err) + } + chatID, err := strconv.ParseInt(string(chatIdData), 10, 64) + + messenger, err := telegram.NewMessenger(chatID, token) + // Create a listener on TCP port lis, err := net.Listen("tcp", ":8080") if err != nil { @@ -26,7 +42,7 @@ func main() { // Create a gRPC server object s := grpc.NewServer() // Attach the Greeter service to the server - proto.RegisterCRMServer(s, app.NewServer(storage)) + proto.RegisterCRMServer(s, app.NewServer(storage, messenger)) // Serve gRPC server log.Println("Serving gRPC on 0.0.0.0:8080") go func() { diff --git a/go.mod b/go.mod index 43b10e9..0f5cc65 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module cake_crm go 1.22 require ( - github.com/go-pkgz/routegroup v1.1.1 + github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 google.golang.org/grpc v1.64.0 diff --git a/go.sum b/go.sum index a8f1e04..0d5590b 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/go-pkgz/routegroup v1.1.1 h1:Dm5IBiEmUbQT+3rliBimhX0SifnZp/uRF/WOu3XPmms= -github.com/go-pkgz/routegroup v1.1.1/go.mod h1:kDDPDRLRiRY1vnENrZJw1jQAzQX7fvsbsHGRQFNQfKc= +github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc= +github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= diff --git a/internal/app/server.go b/internal/app/server.go index 5c5b5ee..a56c12d 100644 --- a/internal/app/server.go +++ b/internal/app/server.go @@ -1,19 +1,34 @@ package app import ( + "bytes" + "cake_crm/internal/models/messenger" "cake_crm/internal/models/storage" proto "cake_crm/proto" "context" + "errors" + "fmt" + "strconv" ) -type Server struct { - proto.UnimplementedCRMServer - storage storage.IStorage +type orderItem struct { + product *proto.Product + count int64 } -func NewServer(storage storage.IStorage) *Server { +type Server struct { + proto.UnsafeCRMServer + storage storage.IStorage + messenger messenger.IMessenger +} + +func NewServer( + storage storage.IStorage, + messenger messenger.IMessenger, +) proto.CRMServer { return &Server{ - storage: storage, + storage: storage, + messenger: messenger, } } @@ -48,3 +63,96 @@ func (s *Server) GetBreadcrumbs(ctx context.Context, req *proto.GetBreadcrumbsRe } return &proto.BreadcrumbsRsp{Categories: breadcrumbs}, nil } + +func (s *Server) Order(ctx context.Context, req *proto.OrderReq) (*proto.OrderRsp, error) { + items := make([]*orderItem, 0, len(req.Order.Items)) + for _, item := range req.Order.Items { + product, err := s.storage.GetProduct(ctx, item.ProductId) + if err != nil { + return nil, err + } + items = append( + items, + &orderItem{ + product: product, + count: item.Count, + }, + ) + } + text, err := createOrderText(req, items) + if err != nil { + return nil, err + } + return &proto.OrderRsp{}, s.messenger.SendMessage(text) +} + +func createOrderText(req *proto.OrderReq, items []*orderItem) (string, error) { + buffer := bytes.Buffer{} + orderAmount := 0.0 + buffer.WriteString(fmt.Sprintf("Заказ от:\n%s\n%s\n", req.Name, req.Phone)) + buffer.WriteString("\n") + for _, item := range items { + buffer.WriteString(item.product.Name) + buffer.WriteString("\n") + unit, err := unitToText(item.product.Unit) + if err != nil { + return "", err + } + buffer.WriteString(fmt.Sprintf("Количество: %d%s\n", item.count, unit)) + amount, err := calcItemAmount(item) + if err != nil { + return "", err + } + orderAmount += amount + buffer.WriteString(fmt.Sprintf("Сумма: %.00fр\n", amount)) + buffer.WriteString("\n") + } + buffer.WriteString("\n") + buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", orderAmount)) + return buffer.String(), nil +} + +func calcItemAmount(item *orderItem) (float64, error) { + var variant *proto.Variant + for _, v := range item.product.Variants { + check := true + for _, property := range v.Properties { + if property.Name == "min" { + minBorder, err := strconv.ParseInt(property.Value, 10, 64) + if err != nil { + return 0, err + } + if item.count < minBorder { + check = false + } + } + if property.Name == "max" { + maxBorder, err := strconv.ParseInt(property.Value, 10, 64) + if err != nil { + return 0, err + } + if item.count > maxBorder { + check = false + } + } + if check { + variant = v + break + } + } + } + if variant == nil { + return 0, errors.New("variant not found") + } + return float64(variant.Price) * float64(item.count) / 100, nil +} + +func unitToText(unit string) (string, error) { + switch unit { + case "kg": + return "кг", nil + case "piece": + return "шт", nil + } + return "", errors.New("unit not found") +} diff --git a/internal/models/messenger/interface.go b/internal/models/messenger/interface.go new file mode 100644 index 0000000..529fd6b --- /dev/null +++ b/internal/models/messenger/interface.go @@ -0,0 +1,5 @@ +package messenger + +type IMessenger interface { + SendMessage(message string) error +} diff --git a/internal/models/messenger/telegram/messenger.go b/internal/models/messenger/telegram/messenger.go new file mode 100644 index 0000000..5004e76 --- /dev/null +++ b/internal/models/messenger/telegram/messenger.go @@ -0,0 +1,30 @@ +package telegram + +import ( + "cake_crm/internal/models/messenger" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" +) + +type messengerTelegram struct { + chatID int64 + bot *tgbotapi.BotAPI +} + +func NewMessenger( + chatID int64, + token string, +) (messenger.IMessenger, error) { + bot, err := tgbotapi.NewBotAPI(token) + if err != nil { + return nil, err + } + return &messengerTelegram{ + chatID: chatID, + bot: bot, + }, nil +} + +func (m *messengerTelegram) SendMessage(message string) error { + _, err := m.bot.Send(tgbotapi.NewMessage(m.chatID, message)) + return err +} diff --git a/internal/services/server_web/interface.go b/internal/services/server_web/interface.go deleted file mode 100644 index b3a74d3..0000000 --- a/internal/services/server_web/interface.go +++ /dev/null @@ -1,8 +0,0 @@ -package server_web - -import "context" - -type IServer interface { - Run(ctx context.Context) error - Stop(ctx context.Context) error -} diff --git a/internal/services/server_web/server.go b/internal/services/server_web/server.go deleted file mode 100644 index 0d38c31..0000000 --- a/internal/services/server_web/server.go +++ /dev/null @@ -1,43 +0,0 @@ -package server_web - -import ( - "cake_crm/internal/models/storage" - "context" - "fmt" - "github.com/go-pkgz/routegroup" - "net/http" -) - -type server struct { - storage storage.IStorage - port int -} - -func NewServer( - storage storage.IStorage, - port int, -) IServer { - return &server{ - storage: storage, - port: port, - } -} - -func (s *server) Run(ctx context.Context) error { - router := routegroup.New(http.NewServeMux()) - router.HandleFunc("GET /products", s.getAllProductsHandler) - router.HandleFunc("GET /products/:id", s.getProductById) - router.HandleFunc("GET /category/:id/breadcrumbs", s.getBreadcrumbsByCategoryId) - return http.ListenAndServe(fmt.Sprintf(":%d", s.port), router) -} - -func (s *server) Stop(ctx context.Context) error { - //TODO implement me - panic("implement me") -} - -func (s *server) getAllProductsHandler(w http.ResponseWriter, r *http.Request) {} - -func (s *server) getProductById(w http.ResponseWriter, r *http.Request) {} - -func (s *server) getBreadcrumbsByCategoryId(w http.ResponseWriter, r *http.Request) {} diff --git a/proto/main.pb.go b/proto/main.pb.go index 25292c5..d5fd570 100644 --- a/proto/main.pb.go +++ b/proto/main.pb.go @@ -823,6 +823,209 @@ func (x *BreadcrumbsRsp) GetCategories() []*Category { return nil } +type OrderReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Order *Order `protobuf:"bytes,1,opt,name=order,proto3" json:"order,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Phone string `protobuf:"bytes,3,opt,name=phone,proto3" json:"phone,omitempty"` +} + +func (x *OrderReq) Reset() { + *x = OrderReq{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderReq) ProtoMessage() {} + +func (x *OrderReq) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[14] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderReq.ProtoReflect.Descriptor instead. +func (*OrderReq) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{14} +} + +func (x *OrderReq) GetOrder() *Order { + if x != nil { + return x.Order + } + return nil +} + +func (x *OrderReq) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *OrderReq) GetPhone() string { + if x != nil { + return x.Phone + } + return "" +} + +type OrderRsp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *OrderRsp) Reset() { + *x = OrderRsp{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderRsp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderRsp) ProtoMessage() {} + +func (x *OrderRsp) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[15] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderRsp.ProtoReflect.Descriptor instead. +func (*OrderRsp) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{15} +} + +type Order struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Items []*OrderItem `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` +} + +func (x *Order) Reset() { + *x = Order{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Order) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Order) ProtoMessage() {} + +func (x *Order) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[16] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Order.ProtoReflect.Descriptor instead. +func (*Order) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{16} +} + +func (x *Order) GetItems() []*OrderItem { + if x != nil { + return x.Items + } + return nil +} + +type OrderItem struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ProductId int64 `protobuf:"varint,1,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Count int64 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` +} + +func (x *OrderItem) Reset() { + *x = OrderItem{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderItem) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderItem) ProtoMessage() {} + +func (x *OrderItem) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[17] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderItem.ProtoReflect.Descriptor instead. +func (*OrderItem) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{17} +} + +func (x *OrderItem) GetProductId() int64 { + if x != nil { + return x.ProductId + } + return 0 +} + +func (x *OrderItem) GetCount() int64 { + if x != nil { + return x.Count + } + return 0 +} + var File_main_proto protoreflect.FileDescriptor var file_main_proto_rawDesc = []byte{ @@ -906,32 +1109,51 @@ var file_main_proto_rawDesc = []byte{ 0x72, 0x75, 0x6d, 0x62, 0x73, 0x52, 0x73, 0x70, 0x12, 0x33, 0x0a, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, - 0x79, 0x52, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x32, 0xf1, 0x02, - 0x0a, 0x03, 0x43, 0x52, 0x4d, 0x12, 0x4f, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x61, - 0x6c, 0x6f, 0x67, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, - 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, - 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, - 0x67, 0x52, 0x73, 0x70, 0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x2f, 0x63, - 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x5c, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x50, 0x6f, 0x73, - 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, - 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, - 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x50, - 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x73, 0x70, 0x22, 0x17, 0x82, 0xd3, 0xe4, - 0x93, 0x02, 0x11, 0x12, 0x0f, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, - 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x55, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, - 0x63, 0x74, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, - 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x63, - 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, - 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x70, 0x72, - 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x64, 0x0a, 0x0e, 0x47, - 0x65, 0x74, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x12, 0x1c, 0x2e, - 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x72, 0x65, - 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x19, 0x2e, 0x63, 0x72, - 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, - 0x6d, 0x62, 0x73, 0x52, 0x73, 0x70, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, - 0x2f, 0x62, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x2f, 0x7b, 0x69, 0x64, - 0x7d, 0x42, 0x0e, 0x92, 0x41, 0x00, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x79, 0x52, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x22, 0x5c, 0x0a, + 0x08, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x05, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, + 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x05, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x22, 0x0a, 0x0a, 0x08, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x33, 0x0a, 0x05, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x12, 0x2a, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x14, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x40, 0x0a, 0x09, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0xbc, + 0x03, 0x0a, 0x03, 0x43, 0x52, 0x4d, 0x12, 0x4f, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, + 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, + 0x2e, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x15, + 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x74, 0x61, 0x6c, + 0x6f, 0x67, 0x52, 0x73, 0x70, 0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x2f, + 0x63, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x5c, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x50, 0x6f, + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, + 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, + 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x73, 0x70, 0x22, 0x17, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x11, 0x12, 0x0f, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x55, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, + 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, + 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, + 0x74, 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x70, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x64, 0x0a, 0x0e, + 0x47, 0x65, 0x74, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x12, 0x1c, + 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x72, + 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x19, 0x2e, 0x63, + 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, + 0x75, 0x6d, 0x62, 0x73, 0x52, 0x73, 0x70, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, + 0x11, 0x2f, 0x62, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x2f, 0x7b, 0x69, + 0x64, 0x7d, 0x12, 0x49, 0x0a, 0x05, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x13, 0x2e, 0x63, 0x72, + 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x1a, 0x13, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x05, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x22, 0x07, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x42, 0x0e, 0x92, + 0x41, 0x00, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -946,7 +1168,7 @@ func file_main_proto_rawDescGZIP() []byte { return file_main_proto_rawDescData } -var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 14) +var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 18) var file_main_proto_goTypes = []interface{}{ (*GetCatalogReq)(nil), // 0: crabs.crm.GetCatalogReq (*CatalogRsp)(nil), // 1: crabs.crm.CatalogRsp @@ -962,6 +1184,10 @@ var file_main_proto_goTypes = []interface{}{ (*ProductRsp)(nil), // 11: crabs.crm.ProductRsp (*GetBreadcrumbsReq)(nil), // 12: crabs.crm.GetBreadcrumbsReq (*BreadcrumbsRsp)(nil), // 13: crabs.crm.BreadcrumbsRsp + (*OrderReq)(nil), // 14: crabs.crm.OrderReq + (*OrderRsp)(nil), // 15: crabs.crm.OrderRsp + (*Order)(nil), // 16: crabs.crm.Order + (*OrderItem)(nil), // 17: crabs.crm.OrderItem } var file_main_proto_depIdxs = []int32{ 2, // 0: crabs.crm.CatalogRsp.categories:type_name -> crabs.crm.Category @@ -973,19 +1199,23 @@ var file_main_proto_depIdxs = []int32{ 8, // 6: crabs.crm.Variant.properties:type_name -> crabs.crm.Property 5, // 7: crabs.crm.ProductRsp.product:type_name -> crabs.crm.Product 2, // 8: crabs.crm.BreadcrumbsRsp.categories:type_name -> crabs.crm.Category - 0, // 9: crabs.crm.CRM.GetCatalog:input_type -> crabs.crm.GetCatalogReq - 3, // 10: crabs.crm.CRM.GetPositions:input_type -> crabs.crm.GetPositionsReq - 10, // 11: crabs.crm.CRM.GetProduct:input_type -> crabs.crm.GetProductReq - 12, // 12: crabs.crm.CRM.GetBreadcrumbs:input_type -> crabs.crm.GetBreadcrumbsReq - 1, // 13: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp - 4, // 14: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp - 11, // 15: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp - 13, // 16: crabs.crm.CRM.GetBreadcrumbs:output_type -> crabs.crm.BreadcrumbsRsp - 13, // [13:17] is the sub-list for method output_type - 9, // [9:13] is the sub-list for method input_type - 9, // [9:9] is the sub-list for extension type_name - 9, // [9:9] is the sub-list for extension extendee - 0, // [0:9] is the sub-list for field type_name + 16, // 9: crabs.crm.OrderReq.order:type_name -> crabs.crm.Order + 17, // 10: crabs.crm.Order.items:type_name -> crabs.crm.OrderItem + 0, // 11: crabs.crm.CRM.GetCatalog:input_type -> crabs.crm.GetCatalogReq + 3, // 12: crabs.crm.CRM.GetPositions:input_type -> crabs.crm.GetPositionsReq + 10, // 13: crabs.crm.CRM.GetProduct:input_type -> crabs.crm.GetProductReq + 12, // 14: crabs.crm.CRM.GetBreadcrumbs:input_type -> crabs.crm.GetBreadcrumbsReq + 14, // 15: crabs.crm.CRM.Order:input_type -> crabs.crm.OrderReq + 1, // 16: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp + 4, // 17: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp + 11, // 18: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp + 13, // 19: crabs.crm.CRM.GetBreadcrumbs:output_type -> crabs.crm.BreadcrumbsRsp + 15, // 20: crabs.crm.CRM.Order:output_type -> crabs.crm.OrderRsp + 16, // [16:21] is the sub-list for method output_type + 11, // [11:16] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name } func init() { file_main_proto_init() } @@ -1162,6 +1392,54 @@ func file_main_proto_init() { return nil } } + file_main_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrderReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_main_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrderRsp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_main_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Order); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_main_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrderItem); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1169,7 +1447,7 @@ func file_main_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_main_proto_rawDesc, NumEnums: 0, - NumMessages: 14, + NumMessages: 18, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/main.pb.gw.go b/proto/main.pb.gw.go index c9388a9..ab99863 100644 --- a/proto/main.pb.gw.go +++ b/proto/main.pb.gw.go @@ -205,6 +205,50 @@ func local_request_CRM_GetBreadcrumbs_0(ctx context.Context, marshaler runtime.M } +var ( + filter_CRM_Order_0 = &utilities.DoubleArray{Encoding: map[string]int{"order": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_CRM_Order_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq OrderReq + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Order); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CRM_Order_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Order(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_CRM_Order_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq OrderReq + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Order); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CRM_Order_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Order(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterCRMHandlerServer registers the http handlers for service CRM to "mux". // UnaryRPC :call CRMServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -311,6 +355,31 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server }) + mux.Handle("POST", pattern_CRM_Order_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.crm.CRM/Order", runtime.WithHTTPPathPattern("/orders")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_CRM_Order_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_CRM_Order_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -440,6 +509,28 @@ func RegisterCRMHandlerClient(ctx context.Context, mux *runtime.ServeMux, client }) + mux.Handle("POST", pattern_CRM_Order_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.crm.CRM/Order", runtime.WithHTTPPathPattern("/orders")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_CRM_Order_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_CRM_Order_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -451,6 +542,8 @@ var ( pattern_CRM_GetProduct_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"products", "id"}, "")) pattern_CRM_GetBreadcrumbs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"breadcrumbs", "id"}, "")) + + pattern_CRM_Order_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"orders"}, "")) ) var ( @@ -461,4 +554,6 @@ var ( forward_CRM_GetProduct_0 = runtime.ForwardResponseMessage forward_CRM_GetBreadcrumbs_0 = runtime.ForwardResponseMessage + + forward_CRM_Order_0 = runtime.ForwardResponseMessage ) diff --git a/proto/main_grpc.pb.go b/proto/main_grpc.pb.go index f375c25..6f14d70 100644 --- a/proto/main_grpc.pb.go +++ b/proto/main_grpc.pb.go @@ -23,6 +23,7 @@ const ( CRM_GetPositions_FullMethodName = "/crabs.crm.CRM/GetPositions" CRM_GetProduct_FullMethodName = "/crabs.crm.CRM/GetProduct" CRM_GetBreadcrumbs_FullMethodName = "/crabs.crm.CRM/GetBreadcrumbs" + CRM_Order_FullMethodName = "/crabs.crm.CRM/Order" ) // CRMClient is the client API for CRM service. @@ -33,6 +34,7 @@ type CRMClient interface { GetPositions(ctx context.Context, in *GetPositionsReq, opts ...grpc.CallOption) (*PositionsRsp, error) GetProduct(ctx context.Context, in *GetProductReq, opts ...grpc.CallOption) (*ProductRsp, error) GetBreadcrumbs(ctx context.Context, in *GetBreadcrumbsReq, opts ...grpc.CallOption) (*BreadcrumbsRsp, error) + Order(ctx context.Context, in *OrderReq, opts ...grpc.CallOption) (*OrderRsp, error) } type cRMClient struct { @@ -79,6 +81,15 @@ func (c *cRMClient) GetBreadcrumbs(ctx context.Context, in *GetBreadcrumbsReq, o return out, nil } +func (c *cRMClient) Order(ctx context.Context, in *OrderReq, opts ...grpc.CallOption) (*OrderRsp, error) { + out := new(OrderRsp) + err := c.cc.Invoke(ctx, CRM_Order_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // CRMServer is the server API for CRM service. // All implementations must embed UnimplementedCRMServer // for forward compatibility @@ -87,6 +98,7 @@ type CRMServer interface { GetPositions(context.Context, *GetPositionsReq) (*PositionsRsp, error) GetProduct(context.Context, *GetProductReq) (*ProductRsp, error) GetBreadcrumbs(context.Context, *GetBreadcrumbsReq) (*BreadcrumbsRsp, error) + Order(context.Context, *OrderReq) (*OrderRsp, error) mustEmbedUnimplementedCRMServer() } @@ -106,6 +118,9 @@ func (UnimplementedCRMServer) GetProduct(context.Context, *GetProductReq) (*Prod func (UnimplementedCRMServer) GetBreadcrumbs(context.Context, *GetBreadcrumbsReq) (*BreadcrumbsRsp, error) { return nil, status.Errorf(codes.Unimplemented, "method GetBreadcrumbs not implemented") } +func (UnimplementedCRMServer) Order(context.Context, *OrderReq) (*OrderRsp, error) { + return nil, status.Errorf(codes.Unimplemented, "method Order not implemented") +} func (UnimplementedCRMServer) mustEmbedUnimplementedCRMServer() {} // UnsafeCRMServer may be embedded to opt out of forward compatibility for this service. @@ -191,6 +206,24 @@ func _CRM_GetBreadcrumbs_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _CRM_Order_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OrderReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CRMServer).Order(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: CRM_Order_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CRMServer).Order(ctx, req.(*OrderReq)) + } + return interceptor(ctx, in, info, handler) +} + // CRM_ServiceDesc is the grpc.ServiceDesc for CRM service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -214,6 +247,10 @@ var CRM_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetBreadcrumbs", Handler: _CRM_GetBreadcrumbs_Handler, }, + { + MethodName: "Order", + Handler: _CRM_Order_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "main.proto", diff --git a/resources/main.swagger.json b/resources/main.swagger.json index 6d479d1..33606b9 100644 --- a/resources/main.swagger.json +++ b/resources/main.swagger.json @@ -69,6 +69,50 @@ ] } }, + "/orders": { + "post": { + "operationId": "CRM_Order", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/crmOrderRsp" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "order", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/crabscrmOrder" + } + }, + { + "name": "name", + "in": "query", + "required": false, + "type": "string" + }, + { + "name": "phone", + "in": "query", + "required": false, + "type": "string" + } + ], + "tags": [ + "CRM" + ] + } + }, "/positions/{id}": { "get": { "operationId": "CRM_GetPositions", @@ -133,6 +177,18 @@ } }, "definitions": { + "crabscrmOrder": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/crmOrderItem" + } + } + } + }, "crmBreadcrumbsRsp": { "type": "object", "properties": { @@ -204,6 +260,22 @@ } } }, + "crmOrderItem": { + "type": "object", + "properties": { + "productId": { + "type": "string", + "format": "int64" + }, + "count": { + "type": "string", + "format": "int64" + } + } + }, + "crmOrderRsp": { + "type": "object" + }, "crmPositionsRsp": { "type": "object", "properties": { -- 2.40.1 From 8fbeae6fc11b43ccd0371afb01c7981e8e7e8c75 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Fri, 24 May 2024 01:10:31 +0700 Subject: [PATCH 2/3] add get card method --- api/main.proto | 26 ++ cmd/cake_crm/main.go | 9 +- internal/app/server.go | 107 ++--- .../messenger/interface.go | 0 .../messenger/telegram/messenger.go | 2 +- .../{models => modules}/storage/interface.go | 0 .../storage/storage_file/storage.go | 2 +- internal/services/card/card.go | 93 +++++ proto/main.pb.go | 382 +++++++++++++++--- proto/main.pb.gw.go | 77 ++++ proto/main_grpc.pb.go | 37 ++ resources/main.swagger.json | 87 ++++ 12 files changed, 685 insertions(+), 137 deletions(-) rename internal/{models => modules}/messenger/interface.go (100%) rename internal/{models => modules}/messenger/telegram/messenger.go (93%) rename internal/{models => modules}/storage/interface.go (100%) rename internal/{models => modules}/storage/storage_file/storage.go (98%) create mode 100644 internal/services/card/card.go diff --git a/api/main.proto b/api/main.proto index e19abfc..22b4e8a 100644 --- a/api/main.proto +++ b/api/main.proto @@ -36,6 +36,12 @@ service CRM { body: "order" }; } + rpc GetCard(CardReq) returns (CardRsp) { + option (google.api.http) = { + post: "/card" + body: "items" + }; + } } message GetCatalogReq {} @@ -127,3 +133,23 @@ message OrderItem { int64 product_id = 1; int64 count = 2; } + +message CardItem { + int64 id = 1; + string article = 2; + string name = 3; + string uri = 4; + repeated string images = 5; + string unit = 8; + double inventory = 9; + int64 count = 10; + int64 amount = 11; +} + +message CardReq { + repeated OrderItem items = 1; +} + +message CardRsp { + repeated CardItem items = 1; +} diff --git a/cmd/cake_crm/main.go b/cmd/cake_crm/main.go index cefd17a..ef21a2f 100644 --- a/cmd/cake_crm/main.go +++ b/cmd/cake_crm/main.go @@ -2,8 +2,9 @@ package main import ( "cake_crm/internal/app" - "cake_crm/internal/models/messenger/telegram" - "cake_crm/internal/models/storage/storage_file" + "cake_crm/internal/modules/messenger/telegram" + "cake_crm/internal/modules/storage/storage_file" + "cake_crm/internal/services/card" proto "cake_crm/proto" "context" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" @@ -19,6 +20,8 @@ import ( func main() { storage := storage_file.NewStorageFile() + cardService := card.NewService(storage) + tokenData, err := os.ReadFile("resources/order_bot_token.txt") if err != nil { panic(err) @@ -42,7 +45,7 @@ func main() { // Create a gRPC server object s := grpc.NewServer() // Attach the Greeter service to the server - proto.RegisterCRMServer(s, app.NewServer(storage, messenger)) + proto.RegisterCRMServer(s, app.NewServer(storage, messenger, cardService)) // Serve gRPC server log.Println("Serving gRPC on 0.0.0.0:8080") go func() { diff --git a/internal/app/server.go b/internal/app/server.go index a56c12d..ac1f713 100644 --- a/internal/app/server.go +++ b/internal/app/server.go @@ -2,33 +2,27 @@ package app import ( "bytes" - "cake_crm/internal/models/messenger" - "cake_crm/internal/models/storage" + "cake_crm/internal/modules/messenger" + "cake_crm/internal/modules/storage" + "cake_crm/internal/services/card" proto "cake_crm/proto" "context" "errors" "fmt" - "strconv" ) -type orderItem struct { - product *proto.Product - count int64 -} - type Server struct { proto.UnsafeCRMServer - storage storage.IStorage - messenger messenger.IMessenger + storage storage.IStorage + messenger messenger.IMessenger + cardService *card.Service } -func NewServer( - storage storage.IStorage, - messenger messenger.IMessenger, -) proto.CRMServer { +func NewServer(storage storage.IStorage, messenger messenger.IMessenger, cardService *card.Service) proto.CRMServer { return &Server{ - storage: storage, - messenger: messenger, + storage: storage, + messenger: messenger, + cardService: cardService, } } @@ -65,88 +59,39 @@ func (s *Server) GetBreadcrumbs(ctx context.Context, req *proto.GetBreadcrumbsRe } func (s *Server) Order(ctx context.Context, req *proto.OrderReq) (*proto.OrderRsp, error) { - items := make([]*orderItem, 0, len(req.Order.Items)) - for _, item := range req.Order.Items { - product, err := s.storage.GetProduct(ctx, item.ProductId) - if err != nil { - return nil, err - } - items = append( - items, - &orderItem{ - product: product, - count: item.Count, - }, - ) + enrichItems, err := s.cardService.GetCard(ctx, req.Order.Items) + if err != nil { + return nil, err } - text, err := createOrderText(req, items) + text, err := createOrderText(req, enrichItems) if err != nil { return nil, err } return &proto.OrderRsp{}, s.messenger.SendMessage(text) } -func createOrderText(req *proto.OrderReq, items []*orderItem) (string, error) { +func createOrderText(req *proto.OrderReq, items []*proto.CardItem) (string, error) { buffer := bytes.Buffer{} - orderAmount := 0.0 + var orderAmount int64 buffer.WriteString(fmt.Sprintf("Заказ от:\n%s\n%s\n", req.Name, req.Phone)) buffer.WriteString("\n") for _, item := range items { - buffer.WriteString(item.product.Name) + buffer.WriteString(item.Name) buffer.WriteString("\n") - unit, err := unitToText(item.product.Unit) + unit, err := unitToText(item.Unit) if err != nil { return "", err } - buffer.WriteString(fmt.Sprintf("Количество: %d%s\n", item.count, unit)) - amount, err := calcItemAmount(item) - if err != nil { - return "", err - } - orderAmount += amount - buffer.WriteString(fmt.Sprintf("Сумма: %.00fр\n", amount)) + buffer.WriteString(fmt.Sprintf("Количество: %d%s\n", item.Count, unit)) + orderAmount += item.Amount + buffer.WriteString(fmt.Sprintf("Сумма: %.00fр\n", float64(item.Amount)/100)) buffer.WriteString("\n") } buffer.WriteString("\n") - buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", orderAmount)) + buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", float64(orderAmount)/100)) return buffer.String(), nil } -func calcItemAmount(item *orderItem) (float64, error) { - var variant *proto.Variant - for _, v := range item.product.Variants { - check := true - for _, property := range v.Properties { - if property.Name == "min" { - minBorder, err := strconv.ParseInt(property.Value, 10, 64) - if err != nil { - return 0, err - } - if item.count < minBorder { - check = false - } - } - if property.Name == "max" { - maxBorder, err := strconv.ParseInt(property.Value, 10, 64) - if err != nil { - return 0, err - } - if item.count > maxBorder { - check = false - } - } - if check { - variant = v - break - } - } - } - if variant == nil { - return 0, errors.New("variant not found") - } - return float64(variant.Price) * float64(item.count) / 100, nil -} - func unitToText(unit string) (string, error) { switch unit { case "kg": @@ -156,3 +101,11 @@ func unitToText(unit string) (string, error) { } return "", errors.New("unit not found") } + +func (s *Server) GetCard(ctx context.Context, req *proto.CardReq) (*proto.CardRsp, error) { + enrichItems, err := s.cardService.GetCard(ctx, req.Items) + if err != nil { + return nil, err + } + return &proto.CardRsp{Items: enrichItems}, nil +} diff --git a/internal/models/messenger/interface.go b/internal/modules/messenger/interface.go similarity index 100% rename from internal/models/messenger/interface.go rename to internal/modules/messenger/interface.go diff --git a/internal/models/messenger/telegram/messenger.go b/internal/modules/messenger/telegram/messenger.go similarity index 93% rename from internal/models/messenger/telegram/messenger.go rename to internal/modules/messenger/telegram/messenger.go index 5004e76..08a19ff 100644 --- a/internal/models/messenger/telegram/messenger.go +++ b/internal/modules/messenger/telegram/messenger.go @@ -1,7 +1,7 @@ package telegram import ( - "cake_crm/internal/models/messenger" + "cake_crm/internal/modules/messenger" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) diff --git a/internal/models/storage/interface.go b/internal/modules/storage/interface.go similarity index 100% rename from internal/models/storage/interface.go rename to internal/modules/storage/interface.go diff --git a/internal/models/storage/storage_file/storage.go b/internal/modules/storage/storage_file/storage.go similarity index 98% rename from internal/models/storage/storage_file/storage.go rename to internal/modules/storage/storage_file/storage.go index 7afa895..d6e8d50 100644 --- a/internal/models/storage/storage_file/storage.go +++ b/internal/modules/storage/storage_file/storage.go @@ -1,7 +1,7 @@ package storage_file import ( - "cake_crm/internal/models/storage" + "cake_crm/internal/modules/storage" crm "cake_crm/proto" "context" "encoding/json" diff --git a/internal/services/card/card.go b/internal/services/card/card.go new file mode 100644 index 0000000..4bfdc97 --- /dev/null +++ b/internal/services/card/card.go @@ -0,0 +1,93 @@ +package card + +import ( + "cake_crm/internal/modules/storage" + "cake_crm/proto" + "context" + "errors" + "strconv" +) + +type ProductAndCount struct { + product *proto.Product + count int64 +} + +type Service struct { + storage storage.IStorage +} + +func NewService(storage storage.IStorage) *Service { + return &Service{ + storage: storage, + } +} + +func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*proto.CardItem, error) { + res := make([]*proto.CardItem, 0, len(items)) + for _, item := range items { + product, err := s.storage.GetProduct(ctx, item.ProductId) + if err != nil { + return nil, err + } + amount, err := calcItemAmount( + &ProductAndCount{ + product: product, + count: item.Count, + }, + ) + if err != nil { + return nil, err + } + res = append( + res, + &proto.CardItem{ + Id: product.Id, + Article: product.Article, + Name: product.Name, + Uri: product.Uri, + Images: product.Images, + Unit: product.Unit, + Inventory: product.Inventory, + Count: item.Count, + Amount: amount, + }, + ) + } + return res, nil +} + +func calcItemAmount(item *ProductAndCount) (int64, error) { + var variant *proto.Variant + for _, v := range item.product.Variants { + check := true + for _, property := range v.Properties { + if property.Name == "min" { + minBorder, err := strconv.ParseInt(property.Value, 10, 64) + if err != nil { + return 0, err + } + if item.count < minBorder { + check = false + } + } + if property.Name == "max" { + maxBorder, err := strconv.ParseInt(property.Value, 10, 64) + if err != nil { + return 0, err + } + if item.count > maxBorder { + check = false + } + } + if check { + variant = v + break + } + } + } + if variant == nil { + return 0, errors.New("variant not found") + } + return variant.Price * item.count, nil +} diff --git a/proto/main.pb.go b/proto/main.pb.go index d5fd570..a30e2be 100644 --- a/proto/main.pb.go +++ b/proto/main.pb.go @@ -318,7 +318,7 @@ func (x *Product) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Product.ProtoReflect.Descriptor instead. +// Deprecated: Use product.ProtoReflect.Descriptor instead. func (*Product) Descriptor() ([]byte, []int) { return file_main_proto_rawDescGZIP(), []int{5} } @@ -1026,6 +1026,211 @@ func (x *OrderItem) GetCount() int64 { return 0 } +type CardItem struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Article string `protobuf:"bytes,2,opt,name=article,proto3" json:"article,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + Uri string `protobuf:"bytes,4,opt,name=uri,proto3" json:"uri,omitempty"` + Images []string `protobuf:"bytes,5,rep,name=images,proto3" json:"images,omitempty"` + Unit string `protobuf:"bytes,8,opt,name=unit,proto3" json:"unit,omitempty"` + Inventory float64 `protobuf:"fixed64,9,opt,name=inventory,proto3" json:"inventory,omitempty"` + Count int64 `protobuf:"varint,10,opt,name=count,proto3" json:"count,omitempty"` + Amount int64 `protobuf:"varint,11,opt,name=amount,proto3" json:"amount,omitempty"` +} + +func (x *CardItem) Reset() { + *x = CardItem{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CardItem) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CardItem) ProtoMessage() {} + +func (x *CardItem) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[18] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CardItem.ProtoReflect.Descriptor instead. +func (*CardItem) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{18} +} + +func (x *CardItem) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *CardItem) GetArticle() string { + if x != nil { + return x.Article + } + return "" +} + +func (x *CardItem) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *CardItem) GetUri() string { + if x != nil { + return x.Uri + } + return "" +} + +func (x *CardItem) GetImages() []string { + if x != nil { + return x.Images + } + return nil +} + +func (x *CardItem) GetUnit() string { + if x != nil { + return x.Unit + } + return "" +} + +func (x *CardItem) GetInventory() float64 { + if x != nil { + return x.Inventory + } + return 0 +} + +func (x *CardItem) GetCount() int64 { + if x != nil { + return x.Count + } + return 0 +} + +func (x *CardItem) GetAmount() int64 { + if x != nil { + return x.Amount + } + return 0 +} + +type CardReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Items []*OrderItem `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` +} + +func (x *CardReq) Reset() { + *x = CardReq{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CardReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CardReq) ProtoMessage() {} + +func (x *CardReq) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[19] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CardReq.ProtoReflect.Descriptor instead. +func (*CardReq) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{19} +} + +func (x *CardReq) GetItems() []*OrderItem { + if x != nil { + return x.Items + } + return nil +} + +type CardRsp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Items []*CardItem `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` +} + +func (x *CardRsp) Reset() { + *x = CardRsp{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CardRsp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CardRsp) ProtoMessage() {} + +func (x *CardRsp) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[20] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CardRsp.ProtoReflect.Descriptor instead. +func (*CardRsp) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{20} +} + +func (x *CardRsp) GetItems() []*CardItem { + if x != nil { + return x.Items + } + return nil +} + var File_main_proto protoreflect.FileDescriptor var file_main_proto_rawDesc = []byte{ @@ -1123,37 +1328,61 @@ var file_main_proto_rawDesc = []byte{ 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0xbc, - 0x03, 0x0a, 0x03, 0x43, 0x52, 0x4d, 0x12, 0x4f, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, - 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, - 0x2e, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x15, - 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x74, 0x61, 0x6c, - 0x6f, 0x67, 0x52, 0x73, 0x70, 0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x2f, - 0x63, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x5c, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x50, 0x6f, - 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, - 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, - 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x73, 0x70, 0x22, 0x17, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x11, 0x12, 0x0f, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x55, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, - 0x75, 0x63, 0x74, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, - 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, - 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, - 0x74, 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x70, - 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x64, 0x0a, 0x0e, - 0x47, 0x65, 0x74, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x12, 0x1c, - 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x72, - 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x19, 0x2e, 0x63, - 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, - 0x75, 0x6d, 0x62, 0x73, 0x52, 0x73, 0x70, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, - 0x11, 0x2f, 0x62, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x2f, 0x7b, 0x69, - 0x64, 0x7d, 0x12, 0x49, 0x0a, 0x05, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x13, 0x2e, 0x63, 0x72, - 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, - 0x1a, 0x13, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, 0x72, 0x64, - 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x05, 0x6f, - 0x72, 0x64, 0x65, 0x72, 0x22, 0x07, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x42, 0x0e, 0x92, - 0x41, 0x00, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xd2, + 0x01, 0x0a, 0x08, 0x43, 0x61, 0x72, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, + 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x72, + 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x69, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x69, 0x12, 0x16, 0x0a, 0x06, 0x69, + 0x6d, 0x61, 0x67, 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x69, 0x6d, 0x61, + 0x67, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x6e, 0x76, 0x65, 0x6e, + 0x74, 0x6f, 0x72, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28, 0x01, 0x52, 0x09, 0x69, 0x6e, 0x76, 0x65, + 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x0a, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x61, + 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x61, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x35, 0x0a, 0x07, 0x43, 0x61, 0x72, 0x64, 0x52, 0x65, 0x71, 0x12, 0x2a, + 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, + 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x74, 0x65, 0x6d, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x34, 0x0a, 0x07, 0x43, 0x61, + 0x72, 0x64, 0x52, 0x73, 0x70, 0x12, 0x29, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, + 0x2e, 0x43, 0x61, 0x72, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, + 0x32, 0x85, 0x04, 0x0a, 0x03, 0x43, 0x52, 0x4d, 0x12, 0x4f, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x43, + 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, + 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x71, + 0x1a, 0x15, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x74, + 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x73, 0x70, 0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x12, + 0x08, 0x2f, 0x63, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x5c, 0x0a, 0x0c, 0x47, 0x65, 0x74, + 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x2e, 0x63, 0x72, 0x61, 0x62, + 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, + 0x6d, 0x2e, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x73, 0x70, 0x22, 0x17, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11, 0x12, 0x0f, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x55, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, + 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x1a, + 0x15, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x50, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, + 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x64, + 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, + 0x12, 0x1c, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, + 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x19, + 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x42, 0x72, 0x65, 0x61, 0x64, + 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x52, 0x73, 0x70, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x13, 0x12, 0x11, 0x2f, 0x62, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x2f, + 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x49, 0x0a, 0x05, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x13, 0x2e, + 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x1a, 0x13, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, + 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x07, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x12, + 0x47, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x43, 0x61, 0x72, 0x64, 0x12, 0x12, 0x2e, 0x63, 0x72, 0x61, + 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x72, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x12, + 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x72, 0x64, 0x52, + 0x73, 0x70, 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x3a, 0x05, 0x69, 0x74, 0x65, 0x6d, + 0x73, 0x22, 0x05, 0x2f, 0x63, 0x61, 0x72, 0x64, 0x42, 0x0e, 0x92, 0x41, 0x00, 0x5a, 0x09, 0x70, + 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1168,14 +1397,14 @@ func file_main_proto_rawDescGZIP() []byte { return file_main_proto_rawDescData } -var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 18) +var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 21) var file_main_proto_goTypes = []interface{}{ (*GetCatalogReq)(nil), // 0: crabs.crm.GetCatalogReq (*CatalogRsp)(nil), // 1: crabs.crm.CatalogRsp (*Category)(nil), // 2: crabs.crm.Category (*GetPositionsReq)(nil), // 3: crabs.crm.GetPositionsReq (*PositionsRsp)(nil), // 4: crabs.crm.PositionsRsp - (*Product)(nil), // 5: crabs.crm.Product + (*Product)(nil), // 5: crabs.crm.product (*GroupedProduct)(nil), // 6: crabs.crm.GroupedProduct (*Variant)(nil), // 7: crabs.crm.Variant (*Property)(nil), // 8: crabs.crm.Property @@ -1188,34 +1417,41 @@ var file_main_proto_goTypes = []interface{}{ (*OrderRsp)(nil), // 15: crabs.crm.OrderRsp (*Order)(nil), // 16: crabs.crm.Order (*OrderItem)(nil), // 17: crabs.crm.OrderItem + (*CardItem)(nil), // 18: crabs.crm.CardItem + (*CardReq)(nil), // 19: crabs.crm.CardReq + (*CardRsp)(nil), // 20: crabs.crm.CardRsp } var file_main_proto_depIdxs = []int32{ 2, // 0: crabs.crm.CatalogRsp.categories:type_name -> crabs.crm.Category 2, // 1: crabs.crm.Category.children:type_name -> crabs.crm.Category - 5, // 2: crabs.crm.PositionsRsp.products:type_name -> crabs.crm.Product - 6, // 3: crabs.crm.Product.grouped_products:type_name -> crabs.crm.GroupedProduct - 7, // 4: crabs.crm.Product.variants:type_name -> crabs.crm.Variant - 9, // 5: crabs.crm.Product.characteristics:type_name -> crabs.crm.Characteristic + 5, // 2: crabs.crm.PositionsRsp.products:type_name -> crabs.crm.product + 6, // 3: crabs.crm.product.grouped_products:type_name -> crabs.crm.GroupedProduct + 7, // 4: crabs.crm.product.variants:type_name -> crabs.crm.Variant + 9, // 5: crabs.crm.product.characteristics:type_name -> crabs.crm.Characteristic 8, // 6: crabs.crm.Variant.properties:type_name -> crabs.crm.Property - 5, // 7: crabs.crm.ProductRsp.product:type_name -> crabs.crm.Product + 5, // 7: crabs.crm.ProductRsp.product:type_name -> crabs.crm.product 2, // 8: crabs.crm.BreadcrumbsRsp.categories:type_name -> crabs.crm.Category 16, // 9: crabs.crm.OrderReq.order:type_name -> crabs.crm.Order 17, // 10: crabs.crm.Order.items:type_name -> crabs.crm.OrderItem - 0, // 11: crabs.crm.CRM.GetCatalog:input_type -> crabs.crm.GetCatalogReq - 3, // 12: crabs.crm.CRM.GetPositions:input_type -> crabs.crm.GetPositionsReq - 10, // 13: crabs.crm.CRM.GetProduct:input_type -> crabs.crm.GetProductReq - 12, // 14: crabs.crm.CRM.GetBreadcrumbs:input_type -> crabs.crm.GetBreadcrumbsReq - 14, // 15: crabs.crm.CRM.Order:input_type -> crabs.crm.OrderReq - 1, // 16: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp - 4, // 17: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp - 11, // 18: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp - 13, // 19: crabs.crm.CRM.GetBreadcrumbs:output_type -> crabs.crm.BreadcrumbsRsp - 15, // 20: crabs.crm.CRM.Order:output_type -> crabs.crm.OrderRsp - 16, // [16:21] is the sub-list for method output_type - 11, // [11:16] is the sub-list for method input_type - 11, // [11:11] is the sub-list for extension type_name - 11, // [11:11] is the sub-list for extension extendee - 0, // [0:11] is the sub-list for field type_name + 17, // 11: crabs.crm.CardReq.items:type_name -> crabs.crm.OrderItem + 18, // 12: crabs.crm.CardRsp.items:type_name -> crabs.crm.CardItem + 0, // 13: crabs.crm.CRM.GetCatalog:input_type -> crabs.crm.GetCatalogReq + 3, // 14: crabs.crm.CRM.GetPositions:input_type -> crabs.crm.GetPositionsReq + 10, // 15: crabs.crm.CRM.GetProduct:input_type -> crabs.crm.GetProductReq + 12, // 16: crabs.crm.CRM.GetBreadcrumbs:input_type -> crabs.crm.GetBreadcrumbsReq + 14, // 17: crabs.crm.CRM.Order:input_type -> crabs.crm.OrderReq + 19, // 18: crabs.crm.CRM.GetCard:input_type -> crabs.crm.CardReq + 1, // 19: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp + 4, // 20: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp + 11, // 21: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp + 13, // 22: crabs.crm.CRM.GetBreadcrumbs:output_type -> crabs.crm.BreadcrumbsRsp + 15, // 23: crabs.crm.CRM.Order:output_type -> crabs.crm.OrderRsp + 20, // 24: crabs.crm.CRM.GetCard:output_type -> crabs.crm.CardRsp + 19, // [19:25] is the sub-list for method output_type + 13, // [13:19] is the sub-list for method input_type + 13, // [13:13] is the sub-list for extension type_name + 13, // [13:13] is the sub-list for extension extendee + 0, // [0:13] is the sub-list for field type_name } func init() { file_main_proto_init() } @@ -1440,6 +1676,42 @@ func file_main_proto_init() { return nil } } + file_main_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CardItem); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_main_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CardReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_main_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CardRsp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1447,7 +1719,7 @@ func file_main_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_main_proto_rawDesc, NumEnums: 0, - NumMessages: 18, + NumMessages: 21, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/main.pb.gw.go b/proto/main.pb.gw.go index ab99863..e16326b 100644 --- a/proto/main.pb.gw.go +++ b/proto/main.pb.gw.go @@ -249,6 +249,32 @@ func local_request_CRM_Order_0(ctx context.Context, marshaler runtime.Marshaler, } +func request_CRM_GetCard_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CardReq + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Items); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GetCard(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_CRM_GetCard_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CardReq + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Items); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GetCard(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterCRMHandlerServer registers the http handlers for service CRM to "mux". // UnaryRPC :call CRMServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -380,6 +406,31 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server }) + mux.Handle("POST", pattern_CRM_GetCard_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.crm.CRM/GetCard", runtime.WithHTTPPathPattern("/card")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_CRM_GetCard_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_CRM_GetCard_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -531,6 +582,28 @@ func RegisterCRMHandlerClient(ctx context.Context, mux *runtime.ServeMux, client }) + mux.Handle("POST", pattern_CRM_GetCard_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.crm.CRM/GetCard", runtime.WithHTTPPathPattern("/card")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_CRM_GetCard_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_CRM_GetCard_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -544,6 +617,8 @@ var ( pattern_CRM_GetBreadcrumbs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"breadcrumbs", "id"}, "")) pattern_CRM_Order_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"orders"}, "")) + + pattern_CRM_GetCard_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"card"}, "")) ) var ( @@ -556,4 +631,6 @@ var ( forward_CRM_GetBreadcrumbs_0 = runtime.ForwardResponseMessage forward_CRM_Order_0 = runtime.ForwardResponseMessage + + forward_CRM_GetCard_0 = runtime.ForwardResponseMessage ) diff --git a/proto/main_grpc.pb.go b/proto/main_grpc.pb.go index 6f14d70..fcb3abd 100644 --- a/proto/main_grpc.pb.go +++ b/proto/main_grpc.pb.go @@ -24,6 +24,7 @@ const ( CRM_GetProduct_FullMethodName = "/crabs.crm.CRM/GetProduct" CRM_GetBreadcrumbs_FullMethodName = "/crabs.crm.CRM/GetBreadcrumbs" CRM_Order_FullMethodName = "/crabs.crm.CRM/Order" + CRM_GetCard_FullMethodName = "/crabs.crm.CRM/GetCard" ) // CRMClient is the client API for CRM service. @@ -35,6 +36,7 @@ type CRMClient interface { GetProduct(ctx context.Context, in *GetProductReq, opts ...grpc.CallOption) (*ProductRsp, error) GetBreadcrumbs(ctx context.Context, in *GetBreadcrumbsReq, opts ...grpc.CallOption) (*BreadcrumbsRsp, error) Order(ctx context.Context, in *OrderReq, opts ...grpc.CallOption) (*OrderRsp, error) + GetCard(ctx context.Context, in *CardReq, opts ...grpc.CallOption) (*CardRsp, error) } type cRMClient struct { @@ -90,6 +92,15 @@ func (c *cRMClient) Order(ctx context.Context, in *OrderReq, opts ...grpc.CallOp return out, nil } +func (c *cRMClient) GetCard(ctx context.Context, in *CardReq, opts ...grpc.CallOption) (*CardRsp, error) { + out := new(CardRsp) + err := c.cc.Invoke(ctx, CRM_GetCard_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // CRMServer is the server API for CRM service. // All implementations must embed UnimplementedCRMServer // for forward compatibility @@ -99,6 +110,7 @@ type CRMServer interface { GetProduct(context.Context, *GetProductReq) (*ProductRsp, error) GetBreadcrumbs(context.Context, *GetBreadcrumbsReq) (*BreadcrumbsRsp, error) Order(context.Context, *OrderReq) (*OrderRsp, error) + GetCard(context.Context, *CardReq) (*CardRsp, error) mustEmbedUnimplementedCRMServer() } @@ -121,6 +133,9 @@ func (UnimplementedCRMServer) GetBreadcrumbs(context.Context, *GetBreadcrumbsReq func (UnimplementedCRMServer) Order(context.Context, *OrderReq) (*OrderRsp, error) { return nil, status.Errorf(codes.Unimplemented, "method Order not implemented") } +func (UnimplementedCRMServer) GetCard(context.Context, *CardReq) (*CardRsp, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCard not implemented") +} func (UnimplementedCRMServer) mustEmbedUnimplementedCRMServer() {} // UnsafeCRMServer may be embedded to opt out of forward compatibility for this service. @@ -224,6 +239,24 @@ func _CRM_Order_Handler(srv interface{}, ctx context.Context, dec func(interface return interceptor(ctx, in, info, handler) } +func _CRM_GetCard_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CardReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CRMServer).GetCard(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: CRM_GetCard_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CRMServer).GetCard(ctx, req.(*CardReq)) + } + return interceptor(ctx, in, info, handler) +} + // CRM_ServiceDesc is the grpc.ServiceDesc for CRM service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -251,6 +284,10 @@ var CRM_ServiceDesc = grpc.ServiceDesc{ MethodName: "Order", Handler: _CRM_Order_Handler, }, + { + MethodName: "GetCard", + Handler: _CRM_GetCard_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "main.proto", diff --git a/resources/main.swagger.json b/resources/main.swagger.json index 33606b9..940b1d5 100644 --- a/resources/main.swagger.json +++ b/resources/main.swagger.json @@ -47,6 +47,42 @@ ] } }, + "/card": { + "post": { + "operationId": "CRM_GetCard", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/crmCardRsp" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "items", + "in": "body", + "required": true, + "schema": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/crmOrderItem" + } + } + } + ], + "tags": [ + "CRM" + ] + } + }, "/catalog": { "get": { "operationId": "CRM_GetCatalog", @@ -201,6 +237,57 @@ } } }, + "crmCardItem": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "int64" + }, + "article": { + "type": "string" + }, + "name": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "images": { + "type": "array", + "items": { + "type": "string" + } + }, + "unit": { + "type": "string" + }, + "inventory": { + "type": "number", + "format": "double" + }, + "count": { + "type": "string", + "format": "int64" + }, + "amount": { + "type": "string", + "format": "int64" + } + } + }, + "crmCardRsp": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/crmCardItem" + } + } + } + }, "crmCatalogRsp": { "type": "object", "properties": { -- 2.40.1 From d49b4e9037581f1cf9bb9d83e8554bac46d2bb79 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Fri, 24 May 2024 01:18:23 +0700 Subject: [PATCH 3/3] add empty line to drone.yml --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index 3a6b1f4..f746938 100644 --- a/.drone.yml +++ b/.drone.yml @@ -52,3 +52,4 @@ steps: trigger: event: - push + -- 2.40.1