add breadcrumbs

This commit is contained in:
Владимир Фёдоров 2024-05-18 13:16:57 +07:00
parent 6b3306bb96
commit db4419dc81
9 changed files with 421 additions and 59 deletions

View File

@ -8,3 +8,6 @@ generate:
--grpc-gateway_out ./proto --grpc-gateway_opt paths=source_relative \ --grpc-gateway_out ./proto --grpc-gateway_opt paths=source_relative \
--swagger_out=allow_merge=true,merge_file_name=main:./proto \ --swagger_out=allow_merge=true,merge_file_name=main:./proto \
./api/main.proto ./api/main.proto
run:
go run ./cmd/cake_crm/main.go

View File

@ -22,6 +22,11 @@ service CRM {
get: "/products/{id}" get: "/products/{id}"
}; };
} }
rpc GetBreadcrumbs(GetBreadcrumbsReq) returns (BreadcrumbsRsp) {
option (google.api.http) = {
get: "/breadcrumbs/{id}"
};
}
} }
message GetCatalogReq {} message GetCatalogReq {}
@ -88,3 +93,11 @@ message GetProductReq{
message ProductRsp { message ProductRsp {
Product product = 1; Product product = 1;
} }
message GetBreadcrumbsReq {
int64 id = 1;
}
message BreadcrumbsRsp {
repeated Category categories = 1;
}

View File

@ -40,3 +40,11 @@ func (s *Server) GetProduct(ctx context.Context, req *crm.GetProductReq) (*crm.P
} }
return &crm.ProductRsp{Product: product}, nil return &crm.ProductRsp{Product: product}, nil
} }
func (s *Server) GetBreadcrumbs(ctx context.Context, req *crm.GetBreadcrumbsReq) (*crm.BreadcrumbsRsp, error) {
breadcrumbs, err := s.storage.GetBreadcrumbs(ctx, req.Id)
if err != nil {
return nil, err
}
return &crm.BreadcrumbsRsp{Categories: breadcrumbs}, nil
}

View File

@ -5,19 +5,9 @@ import (
"context" "context"
) )
type Product struct {
ID int `json:"id"`
Name string `json:"name"`
// todo
}
type Breadcrumb struct {
Name string `json:"name"`
URL string `json:"url"`
}
type IStorage interface { type IStorage interface {
GetCatalog(ctx context.Context) ([]*crm.Category, error) GetCatalog(ctx context.Context) ([]*crm.Category, error)
GetPositions(ctx context.Context, id int64) ([]*crm.Product, error) GetPositions(ctx context.Context, id int64) ([]*crm.Product, error)
GetProduct(ctx context.Context, id int64) (*crm.Product, error) GetProduct(ctx context.Context, id int64) (*crm.Product, error)
GetBreadcrumbs(ctx context.Context, id int64) ([]*crm.Category, error)
} }

View File

@ -65,3 +65,33 @@ func (s *storageFile) GetProduct(_ context.Context, id int64) (*crm.Product, err
} }
return nil, ErrProductNotFound return nil, ErrProductNotFound
} }
func (s *storageFile) GetBreadcrumbs(_ context.Context, id int64) ([]*crm.Category, error) {
data, err := os.ReadFile("resources/catalog.json")
if err != nil {
return nil, err
}
var categories []*crm.Category
if err := json.Unmarshal(data, &categories); err != nil {
return nil, err
}
return getBreadcrumbs(categories, id), nil
}
func getBreadcrumbs(categories []*crm.Category, id int64) []*crm.Category {
for _, category := range categories {
if category.Id == id {
category.Children = nil
return []*crm.Category{category}
}
breadcrumbs := getBreadcrumbs(category.Children, id)
if len(breadcrumbs) != 0 {
res := make([]*crm.Category, 0, len(breadcrumbs)+1)
category.Children = nil
res = append(res, category)
res = append(res, breadcrumbs...)
return res
}
}
return nil
}

View File

@ -728,6 +728,100 @@ func (x *ProductRsp) GetProduct() *Product {
return nil return nil
} }
type GetBreadcrumbsReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *GetBreadcrumbsReq) Reset() {
*x = GetBreadcrumbsReq{}
if protoimpl.UnsafeEnabled {
mi := &file_main_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetBreadcrumbsReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetBreadcrumbsReq) ProtoMessage() {}
func (x *GetBreadcrumbsReq) ProtoReflect() protoreflect.Message {
mi := &file_main_proto_msgTypes[12]
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 GetBreadcrumbsReq.ProtoReflect.Descriptor instead.
func (*GetBreadcrumbsReq) Descriptor() ([]byte, []int) {
return file_main_proto_rawDescGZIP(), []int{12}
}
func (x *GetBreadcrumbsReq) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
type BreadcrumbsRsp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Categories []*Category `protobuf:"bytes,1,rep,name=categories,proto3" json:"categories,omitempty"`
}
func (x *BreadcrumbsRsp) Reset() {
*x = BreadcrumbsRsp{}
if protoimpl.UnsafeEnabled {
mi := &file_main_proto_msgTypes[13]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *BreadcrumbsRsp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BreadcrumbsRsp) ProtoMessage() {}
func (x *BreadcrumbsRsp) ProtoReflect() protoreflect.Message {
mi := &file_main_proto_msgTypes[13]
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 BreadcrumbsRsp.ProtoReflect.Descriptor instead.
func (*BreadcrumbsRsp) Descriptor() ([]byte, []int) {
return file_main_proto_rawDescGZIP(), []int{13}
}
func (x *BreadcrumbsRsp) GetCategories() []*Category {
if x != nil {
return x.Categories
}
return nil
}
var File_main_proto protoreflect.FileDescriptor var File_main_proto protoreflect.FileDescriptor
var file_main_proto_rawDesc = []byte{ var file_main_proto_rawDesc = []byte{
@ -802,25 +896,38 @@ var file_main_proto_rawDesc = []byte{
0x52, 0x73, 0x70, 0x12, 0x2c, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x18, 0x01, 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, 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, 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, 0x74, 0x22, 0x23, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63, 0x72, 0x75,
0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x6d, 0x62, 0x73, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x45, 0x0a, 0x0e, 0x42, 0x72, 0x65, 0x61, 0x64, 0x63,
0x71, 0x1a, 0x15, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x72, 0x75, 0x6d, 0x62, 0x73, 0x52, 0x73, 0x70, 0x12, 0x33, 0x0a, 0x0a, 0x63, 0x61, 0x74, 0x65,
0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x73, 0x70, 0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x63,
0x12, 0x08, 0x2f, 0x63, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x5c, 0x0a, 0x0c, 0x47, 0x65, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72,
0x74, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x2e, 0x63, 0x72, 0x61, 0x79, 0x52, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x32, 0xf1, 0x02,
0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x0a, 0x03, 0x43, 0x52, 0x4d, 0x12, 0x4f, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x61,
0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x6c, 0x6f, 0x67, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e,
0x72, 0x6d, 0x2e, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x73, 0x70, 0x22, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e,
0x17, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11, 0x12, 0x0f, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f,
0x6f, 0x6e, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x55, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, 0x67, 0x52, 0x73, 0x70, 0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x2f, 0x63,
0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x12, 0x5c, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x50, 0x6f, 0x73,
0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63,
0x1a, 0x15, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x50, 0x72, 0x6f, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52,
0x64, 0x75, 0x63, 0x74, 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x50,
0x0e, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x42, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x73, 0x70, 0x22, 0x17, 0x82, 0xd3, 0xe4,
0x09, 0x5a, 0x07, 0x70, 0x6b, 0x67, 0x2f, 0x63, 0x72, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x93, 0x02, 0x11, 0x12, 0x0f, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f,
0x6f, 0x33, 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, 0x09, 0x5a, 0x07, 0x70, 0x6b, 0x67, 0x2f, 0x63, 0x72, 0x6d, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -835,7 +942,7 @@ func file_main_proto_rawDescGZIP() []byte {
return file_main_proto_rawDescData return file_main_proto_rawDescData
} }
var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 14)
var file_main_proto_goTypes = []interface{}{ var file_main_proto_goTypes = []interface{}{
(*GetCatalogReq)(nil), // 0: crabs.crm.GetCatalogReq (*GetCatalogReq)(nil), // 0: crabs.crm.GetCatalogReq
(*CatalogRsp)(nil), // 1: crabs.crm.CatalogRsp (*CatalogRsp)(nil), // 1: crabs.crm.CatalogRsp
@ -849,6 +956,8 @@ var file_main_proto_goTypes = []interface{}{
(*Characteristic)(nil), // 9: crabs.crm.Characteristic (*Characteristic)(nil), // 9: crabs.crm.Characteristic
(*GetProductReq)(nil), // 10: crabs.crm.GetProductReq (*GetProductReq)(nil), // 10: crabs.crm.GetProductReq
(*ProductRsp)(nil), // 11: crabs.crm.ProductRsp (*ProductRsp)(nil), // 11: crabs.crm.ProductRsp
(*GetBreadcrumbsReq)(nil), // 12: crabs.crm.GetBreadcrumbsReq
(*BreadcrumbsRsp)(nil), // 13: crabs.crm.BreadcrumbsRsp
} }
var file_main_proto_depIdxs = []int32{ var file_main_proto_depIdxs = []int32{
2, // 0: crabs.crm.CatalogRsp.categories:type_name -> crabs.crm.Category 2, // 0: crabs.crm.CatalogRsp.categories:type_name -> crabs.crm.Category
@ -859,17 +968,20 @@ var file_main_proto_depIdxs = []int32{
9, // 5: crabs.crm.Product.characteristics:type_name -> crabs.crm.Characteristic 9, // 5: crabs.crm.Product.characteristics:type_name -> crabs.crm.Characteristic
8, // 6: crabs.crm.Variant.properties:type_name -> crabs.crm.Property 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
0, // 8: crabs.crm.CRM.GetCatalog:input_type -> crabs.crm.GetCatalogReq 2, // 8: crabs.crm.BreadcrumbsRsp.categories:type_name -> crabs.crm.Category
3, // 9: crabs.crm.CRM.GetPositions:input_type -> crabs.crm.GetPositionsReq 0, // 9: crabs.crm.CRM.GetCatalog:input_type -> crabs.crm.GetCatalogReq
10, // 10: crabs.crm.CRM.GetProduct:input_type -> crabs.crm.GetProductReq 3, // 10: crabs.crm.CRM.GetPositions:input_type -> crabs.crm.GetPositionsReq
1, // 11: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp 10, // 11: crabs.crm.CRM.GetProduct:input_type -> crabs.crm.GetProductReq
4, // 12: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp 12, // 12: crabs.crm.CRM.GetBreadcrumbs:input_type -> crabs.crm.GetBreadcrumbsReq
11, // 13: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp 1, // 13: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp
11, // [11:14] is the sub-list for method output_type 4, // 14: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp
8, // [8:11] is the sub-list for method input_type 11, // 15: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp
8, // [8:8] is the sub-list for extension type_name 13, // 16: crabs.crm.CRM.GetBreadcrumbs:output_type -> crabs.crm.BreadcrumbsRsp
8, // [8:8] is the sub-list for extension extendee 13, // [13:17] is the sub-list for method output_type
0, // [0:8] is the sub-list for field type_name 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
} }
func init() { file_main_proto_init() } func init() { file_main_proto_init() }
@ -1022,6 +1134,30 @@ func file_main_proto_init() {
return nil return nil
} }
} }
file_main_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetBreadcrumbsReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_main_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BreadcrumbsRsp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@ -1029,7 +1165,7 @@ func file_main_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_main_proto_rawDesc, RawDescriptor: file_main_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 12, NumMessages: 14,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@ -153,6 +153,58 @@ func local_request_CRM_GetProduct_0(ctx context.Context, marshaler runtime.Marsh
} }
func request_CRM_GetBreadcrumbs_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetBreadcrumbsReq
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.GetBreadcrumbs(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_CRM_GetBreadcrumbs_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetBreadcrumbsReq
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.GetBreadcrumbs(ctx, &protoReq)
return msg, metadata, err
}
// RegisterCRMHandlerServer registers the http handlers for service CRM to "mux". // RegisterCRMHandlerServer registers the http handlers for service CRM to "mux".
// UnaryRPC :call CRMServer directly. // UnaryRPC :call CRMServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@ -234,6 +286,31 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server
}) })
mux.Handle("GET", pattern_CRM_GetBreadcrumbs_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/GetBreadcrumbs", runtime.WithHTTPPathPattern("/breadcrumbs/{id}"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_CRM_GetBreadcrumbs_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_GetBreadcrumbs_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil return nil
} }
@ -341,6 +418,28 @@ func RegisterCRMHandlerClient(ctx context.Context, mux *runtime.ServeMux, client
}) })
mux.Handle("GET", pattern_CRM_GetBreadcrumbs_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/GetBreadcrumbs", runtime.WithHTTPPathPattern("/breadcrumbs/{id}"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_CRM_GetBreadcrumbs_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_GetBreadcrumbs_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil return nil
} }
@ -350,6 +449,8 @@ var (
pattern_CRM_GetPositions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"positions", "id"}, "")) 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"}, "")) 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"}, ""))
) )
var ( var (
@ -358,4 +459,6 @@ var (
forward_CRM_GetPositions_0 = runtime.ForwardResponseMessage forward_CRM_GetPositions_0 = runtime.ForwardResponseMessage
forward_CRM_GetProduct_0 = runtime.ForwardResponseMessage forward_CRM_GetProduct_0 = runtime.ForwardResponseMessage
forward_CRM_GetBreadcrumbs_0 = runtime.ForwardResponseMessage
) )

View File

@ -11,6 +11,37 @@
"application/json" "application/json"
], ],
"paths": { "paths": {
"/breadcrumbs/{id}": {
"get": {
"operationId": "CRM_GetBreadcrumbs",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/crmBreadcrumbsRsp"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/runtimeError"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string",
"format": "int64"
}
],
"tags": [
"CRM"
]
}
},
"/catalog": { "/catalog": {
"get": { "get": {
"operationId": "CRM_GetCatalog", "operationId": "CRM_GetCatalog",
@ -97,6 +128,17 @@
} }
}, },
"definitions": { "definitions": {
"crmBreadcrumbsRsp": {
"type": "object",
"properties": {
"categories": {
"type": "array",
"items": {
"$ref": "#/definitions/crmCategory"
}
}
}
},
"crmCatalogRsp": { "crmCatalogRsp": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -22,6 +22,7 @@ const (
CRM_GetCatalog_FullMethodName = "/crabs.crm.CRM/GetCatalog" CRM_GetCatalog_FullMethodName = "/crabs.crm.CRM/GetCatalog"
CRM_GetPositions_FullMethodName = "/crabs.crm.CRM/GetPositions" CRM_GetPositions_FullMethodName = "/crabs.crm.CRM/GetPositions"
CRM_GetProduct_FullMethodName = "/crabs.crm.CRM/GetProduct" CRM_GetProduct_FullMethodName = "/crabs.crm.CRM/GetProduct"
CRM_GetBreadcrumbs_FullMethodName = "/crabs.crm.CRM/GetBreadcrumbs"
) )
// CRMClient is the client API for CRM service. // CRMClient is the client API for CRM service.
@ -31,6 +32,7 @@ type CRMClient interface {
GetCatalog(ctx context.Context, in *GetCatalogReq, opts ...grpc.CallOption) (*CatalogRsp, error) GetCatalog(ctx context.Context, in *GetCatalogReq, opts ...grpc.CallOption) (*CatalogRsp, error)
GetPositions(ctx context.Context, in *GetPositionsReq, opts ...grpc.CallOption) (*PositionsRsp, error) GetPositions(ctx context.Context, in *GetPositionsReq, opts ...grpc.CallOption) (*PositionsRsp, error)
GetProduct(ctx context.Context, in *GetProductReq, opts ...grpc.CallOption) (*ProductRsp, error) GetProduct(ctx context.Context, in *GetProductReq, opts ...grpc.CallOption) (*ProductRsp, error)
GetBreadcrumbs(ctx context.Context, in *GetBreadcrumbsReq, opts ...grpc.CallOption) (*BreadcrumbsRsp, error)
} }
type cRMClient struct { type cRMClient struct {
@ -68,6 +70,15 @@ func (c *cRMClient) GetProduct(ctx context.Context, in *GetProductReq, opts ...g
return out, nil return out, nil
} }
func (c *cRMClient) GetBreadcrumbs(ctx context.Context, in *GetBreadcrumbsReq, opts ...grpc.CallOption) (*BreadcrumbsRsp, error) {
out := new(BreadcrumbsRsp)
err := c.cc.Invoke(ctx, CRM_GetBreadcrumbs_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// CRMServer is the server API for CRM service. // CRMServer is the server API for CRM service.
// All implementations must embed UnimplementedCRMServer // All implementations must embed UnimplementedCRMServer
// for forward compatibility // for forward compatibility
@ -75,6 +86,7 @@ type CRMServer interface {
GetCatalog(context.Context, *GetCatalogReq) (*CatalogRsp, error) GetCatalog(context.Context, *GetCatalogReq) (*CatalogRsp, error)
GetPositions(context.Context, *GetPositionsReq) (*PositionsRsp, error) GetPositions(context.Context, *GetPositionsReq) (*PositionsRsp, error)
GetProduct(context.Context, *GetProductReq) (*ProductRsp, error) GetProduct(context.Context, *GetProductReq) (*ProductRsp, error)
GetBreadcrumbs(context.Context, *GetBreadcrumbsReq) (*BreadcrumbsRsp, error)
mustEmbedUnimplementedCRMServer() mustEmbedUnimplementedCRMServer()
} }
@ -91,6 +103,9 @@ func (UnimplementedCRMServer) GetPositions(context.Context, *GetPositionsReq) (*
func (UnimplementedCRMServer) GetProduct(context.Context, *GetProductReq) (*ProductRsp, error) { func (UnimplementedCRMServer) GetProduct(context.Context, *GetProductReq) (*ProductRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented")
} }
func (UnimplementedCRMServer) GetBreadcrumbs(context.Context, *GetBreadcrumbsReq) (*BreadcrumbsRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetBreadcrumbs not implemented")
}
func (UnimplementedCRMServer) mustEmbedUnimplementedCRMServer() {} func (UnimplementedCRMServer) mustEmbedUnimplementedCRMServer() {}
// UnsafeCRMServer may be embedded to opt out of forward compatibility for this service. // UnsafeCRMServer may be embedded to opt out of forward compatibility for this service.
@ -158,6 +173,24 @@ func _CRM_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(inte
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _CRM_GetBreadcrumbs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetBreadcrumbsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CRMServer).GetBreadcrumbs(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CRM_GetBreadcrumbs_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CRMServer).GetBreadcrumbs(ctx, req.(*GetBreadcrumbsReq))
}
return interceptor(ctx, in, info, handler)
}
// CRM_ServiceDesc is the grpc.ServiceDesc for CRM service. // CRM_ServiceDesc is the grpc.ServiceDesc for CRM service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -177,6 +210,10 @@ var CRM_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetProduct", MethodName: "GetProduct",
Handler: _CRM_GetProduct_Handler, Handler: _CRM_GetProduct_Handler,
}, },
{
MethodName: "GetBreadcrumbs",
Handler: _CRM_GetBreadcrumbs_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "main.proto", Metadata: "main.proto",