diff --git a/api/main.proto b/api/main.proto index cf2bad5..4ca71ea 100644 --- a/api/main.proto +++ b/api/main.proto @@ -17,6 +17,11 @@ service CRM { get: "/positions/{id}" }; } + rpc GetProduct(GetProductReq) returns (ProductRsp) { + option (google.api.http) = { + get: "/products/{id}" + }; + } } message GetCatalogReq {} @@ -75,3 +80,11 @@ message Characteristic { string name = 1; string value = 2; } + +message GetProductReq{ + int64 id = 1; +} + +message ProductRsp { + Product product = 1; +} diff --git a/internal/app/server.go b/internal/app/server.go index 5f2ee83..d71a903 100644 --- a/internal/app/server.go +++ b/internal/app/server.go @@ -32,3 +32,11 @@ func (s *Server) GetPositions(ctx context.Context, req *crm.GetPositionsReq) (*c } return &crm.PositionsRsp{Products: products}, nil } + +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 +} diff --git a/internal/models/storage/interface.go b/internal/models/storage/interface.go index d8ab976..06282cc 100644 --- a/internal/models/storage/interface.go +++ b/internal/models/storage/interface.go @@ -19,4 +19,5 @@ type Breadcrumb struct { type IStorage interface { GetCatalog(ctx context.Context) ([]*crm.Category, error) GetPositions(ctx context.Context, id int64) ([]*crm.Product, error) + GetProduct(ctx context.Context, id int64) (*crm.Product, error) } diff --git a/internal/models/storage/storage_file/storage.go b/internal/models/storage/storage_file/storage.go index f820251..21c0e26 100644 --- a/internal/models/storage/storage_file/storage.go +++ b/internal/models/storage/storage_file/storage.go @@ -5,9 +5,14 @@ import ( crm "cake_crm/proto" "context" "encoding/json" + "errors" "os" ) +var ( + ErrProductNotFound = errors.New("product not found") +) + type storageFile struct{} func NewStorageFile() storage.IStorage { @@ -43,3 +48,20 @@ func (s *storageFile) GetPositions(_ context.Context, id int64) ([]*crm.Product, } return res, nil } + +func (s *storageFile) GetProduct(_ context.Context, id int64) (*crm.Product, error) { + data, err := os.ReadFile("resources/products.json") + if err != nil { + return nil, err + } + var products []*crm.Product + if err := json.Unmarshal(data, &products); err != nil { + return nil, err + } + for _, product := range products { + if product.Id == id { + return product, nil + } + } + return nil, ErrProductNotFound +} diff --git a/proto/main.pb.go b/proto/main.pb.go index 32386cb..cac985d 100644 --- a/proto/main.pb.go +++ b/proto/main.pb.go @@ -634,6 +634,100 @@ func (x *Characteristic) GetValue() string { return "" } +type GetProductReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetProductReq) Reset() { + *x = GetProductReq{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetProductReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetProductReq) ProtoMessage() {} + +func (x *GetProductReq) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[10] + 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 GetProductReq.ProtoReflect.Descriptor instead. +func (*GetProductReq) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{10} +} + +func (x *GetProductReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type ProductRsp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Product *Product `protobuf:"bytes,1,opt,name=product,proto3" json:"product,omitempty"` +} + +func (x *ProductRsp) Reset() { + *x = ProductRsp{} + if protoimpl.UnsafeEnabled { + mi := &file_main_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ProductRsp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ProductRsp) ProtoMessage() {} + +func (x *ProductRsp) ProtoReflect() protoreflect.Message { + mi := &file_main_proto_msgTypes[11] + 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 ProductRsp.ProtoReflect.Descriptor instead. +func (*ProductRsp) Descriptor() ([]byte, []int) { + return file_main_proto_rawDescGZIP(), []int{11} +} + +func (x *ProductRsp) GetProduct() *Product { + if x != nil { + return x.Product + } + return nil +} + var File_main_proto protoreflect.FileDescriptor var file_main_proto_rawDesc = []byte{ @@ -702,19 +796,31 @@ var file_main_proto_rawDesc = []byte{ 0x61, 0x63, 0x74, 0x65, 0x72, 0x69, 0x73, 0x74, 0x69, 0x63, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x32, 0xb4, 0x01, 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, 0x42, 0x09, 0x5a, 0x07, 0x70, - 0x6b, 0x67, 0x2f, 0x63, 0x72, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x6c, 0x75, 0x65, 0x22, 0x1f, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x3a, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x52, 0x73, 0x70, 0x12, 0x2c, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, + 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, + 0x74, 0x32, 0x8b, 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, 0x42, + 0x09, 0x5a, 0x07, 0x70, 0x6b, 0x67, 0x2f, 0x63, 0x72, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -729,7 +835,7 @@ func file_main_proto_rawDescGZIP() []byte { return file_main_proto_rawDescData } -var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_main_proto_goTypes = []interface{}{ (*GetCatalogReq)(nil), // 0: crabs.crm.GetCatalogReq (*CatalogRsp)(nil), // 1: crabs.crm.CatalogRsp @@ -741,24 +847,29 @@ var file_main_proto_goTypes = []interface{}{ (*Variant)(nil), // 7: crabs.crm.Variant (*Property)(nil), // 8: crabs.crm.Property (*Characteristic)(nil), // 9: crabs.crm.Characteristic + (*GetProductReq)(nil), // 10: crabs.crm.GetProductReq + (*ProductRsp)(nil), // 11: crabs.crm.ProductRsp } 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 - 8, // 6: crabs.crm.Variant.properties:type_name -> crabs.crm.Property - 0, // 7: crabs.crm.CRM.GetCatalog:input_type -> crabs.crm.GetCatalogReq - 3, // 8: crabs.crm.CRM.GetPositions:input_type -> crabs.crm.GetPositionsReq - 1, // 9: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp - 4, // 10: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp - 9, // [9:11] is the sub-list for method output_type - 7, // [7:9] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 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 + 8, // 6: crabs.crm.Variant.properties:type_name -> crabs.crm.Property + 5, // 7: crabs.crm.ProductRsp.product:type_name -> crabs.crm.Product + 0, // 8: crabs.crm.CRM.GetCatalog:input_type -> crabs.crm.GetCatalogReq + 3, // 9: crabs.crm.CRM.GetPositions:input_type -> crabs.crm.GetPositionsReq + 10, // 10: crabs.crm.CRM.GetProduct:input_type -> crabs.crm.GetProductReq + 1, // 11: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp + 4, // 12: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp + 11, // 13: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp + 11, // [11:14] is the sub-list for method output_type + 8, // [8:11] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_main_proto_init() } @@ -887,6 +998,30 @@ func file_main_proto_init() { return nil } } + file_main_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetProductReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_main_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ProductRsp); 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{ @@ -894,7 +1029,7 @@ func file_main_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_main_proto_rawDesc, NumEnums: 0, - NumMessages: 10, + NumMessages: 12, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/main.pb.gw.go b/proto/main.pb.gw.go index 83c6849..789ae4f 100644 --- a/proto/main.pb.gw.go +++ b/proto/main.pb.gw.go @@ -101,6 +101,58 @@ func local_request_CRM_GetPositions_0(ctx context.Context, marshaler runtime.Mar } +func request_CRM_GetProduct_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetProductReq + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.Int64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := client.GetProduct(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_CRM_GetProduct_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetProductReq + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.Int64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := server.GetProduct(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. @@ -157,6 +209,31 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server }) + mux.Handle("GET", pattern_CRM_GetProduct_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/GetProduct", runtime.WithHTTPPathPattern("/products/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_CRM_GetProduct_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_GetProduct_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -242,6 +319,28 @@ func RegisterCRMHandlerClient(ctx context.Context, mux *runtime.ServeMux, client }) + mux.Handle("GET", pattern_CRM_GetProduct_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/GetProduct", runtime.WithHTTPPathPattern("/products/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_CRM_GetProduct_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_GetProduct_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -249,10 +348,14 @@ var ( pattern_CRM_GetCatalog_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"catalog"}, "")) pattern_CRM_GetPositions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"positions", "id"}, "")) + + pattern_CRM_GetProduct_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"products", "id"}, "")) ) var ( forward_CRM_GetCatalog_0 = runtime.ForwardResponseMessage forward_CRM_GetPositions_0 = runtime.ForwardResponseMessage + + forward_CRM_GetProduct_0 = runtime.ForwardResponseMessage ) diff --git a/proto/main.swagger.json b/proto/main.swagger.json index f637377..f7d4e6d 100644 --- a/proto/main.swagger.json +++ b/proto/main.swagger.json @@ -63,6 +63,37 @@ "CRM" ] } + }, + "/products/{id}": { + "get": { + "operationId": "CRM_GetProduct", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/crmProductRsp" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/runtimeError" + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "type": "string", + "format": "int64" + } + ], + "tags": [ + "CRM" + ] + } } }, "definitions": { @@ -190,6 +221,14 @@ } } }, + "crmProductRsp": { + "type": "object", + "properties": { + "product": { + "$ref": "#/definitions/crmProduct" + } + } + }, "crmProperty": { "type": "object", "properties": { diff --git a/proto/main_grpc.pb.go b/proto/main_grpc.pb.go index 53fa210..598dc8f 100644 --- a/proto/main_grpc.pb.go +++ b/proto/main_grpc.pb.go @@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion7 const ( CRM_GetCatalog_FullMethodName = "/crabs.crm.CRM/GetCatalog" CRM_GetPositions_FullMethodName = "/crabs.crm.CRM/GetPositions" + CRM_GetProduct_FullMethodName = "/crabs.crm.CRM/GetProduct" ) // CRMClient is the client API for CRM service. @@ -29,6 +30,7 @@ const ( type CRMClient interface { GetCatalog(ctx context.Context, in *GetCatalogReq, opts ...grpc.CallOption) (*CatalogRsp, error) GetPositions(ctx context.Context, in *GetPositionsReq, opts ...grpc.CallOption) (*PositionsRsp, error) + GetProduct(ctx context.Context, in *GetProductReq, opts ...grpc.CallOption) (*ProductRsp, error) } type cRMClient struct { @@ -57,12 +59,22 @@ func (c *cRMClient) GetPositions(ctx context.Context, in *GetPositionsReq, opts return out, nil } +func (c *cRMClient) GetProduct(ctx context.Context, in *GetProductReq, opts ...grpc.CallOption) (*ProductRsp, error) { + out := new(ProductRsp) + err := c.cc.Invoke(ctx, CRM_GetProduct_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 type CRMServer interface { GetCatalog(context.Context, *GetCatalogReq) (*CatalogRsp, error) GetPositions(context.Context, *GetPositionsReq) (*PositionsRsp, error) + GetProduct(context.Context, *GetProductReq) (*ProductRsp, error) mustEmbedUnimplementedCRMServer() } @@ -76,6 +88,9 @@ func (UnimplementedCRMServer) GetCatalog(context.Context, *GetCatalogReq) (*Cata func (UnimplementedCRMServer) GetPositions(context.Context, *GetPositionsReq) (*PositionsRsp, error) { return nil, status.Errorf(codes.Unimplemented, "method GetPositions not implemented") } +func (UnimplementedCRMServer) GetProduct(context.Context, *GetProductReq) (*ProductRsp, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") +} func (UnimplementedCRMServer) mustEmbedUnimplementedCRMServer() {} // UnsafeCRMServer may be embedded to opt out of forward compatibility for this service. @@ -125,6 +140,24 @@ func _CRM_GetPositions_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _CRM_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetProductReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CRMServer).GetProduct(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: CRM_GetProduct_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CRMServer).GetProduct(ctx, req.(*GetProductReq)) + } + 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) @@ -140,6 +173,10 @@ var CRM_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetPositions", Handler: _CRM_GetPositions_Handler, }, + { + MethodName: "GetProduct", + Handler: _CRM_GetProduct_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "main.proto",