add search
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Владимир Фёдоров 2024-05-30 04:17:13 +07:00
parent 073a7e6d8c
commit 8be5d0b831
9 changed files with 320 additions and 53 deletions

View File

@ -48,6 +48,11 @@ service CRM {
get: "/images/{name}"
};
}
rpc Search(SearchReq) returns (PositionsRsp) {
option (google.api.http) = {
get: "/search"
};
}
}
message GetCatalogReq {}
@ -174,3 +179,7 @@ message CartRsp {
message GetImageReq {
string name = 1;
}
message SearchReq {
string text = 1;
}

View File

@ -31,3 +31,7 @@ content-type: application/json
}
]
}
###
GET http://localhost:8090/search?text=Лимон

View File

@ -96,3 +96,11 @@ func (s *Server) GetImage(_ context.Context, req *proto.GetImageReq) (*httpbody.
Data: data,
}, nil
}
func (s *Server) Search(ctx context.Context, req *proto.SearchReq) (*proto.PositionsRsp, error) {
products, err := s.storage.GetPositionsByText(ctx, req.Text)
if err != nil {
return nil, err
}
return &proto.PositionsRsp{Products: products}, nil
}

View File

@ -10,4 +10,5 @@ type IStorage interface {
GetPositions(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)
GetPositionsByText(ctx context.Context, text string) ([]*crm.Product, error)
}

View File

@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"os"
"strings"
)
type Product struct {
@ -160,3 +161,24 @@ func getBreadcrumbs(categories []*crm.Category, id int64) []*crm.Category {
}
return nil
}
func (s *storageFile) GetPositionsByText(_ context.Context, text string) ([]*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
}
res := make([]*crm.Product, 0, len(products))
searchText := strings.TrimSpace(strings.ToLower(text))
for _, product := range products {
name := strings.ToLower(product.Name)
if strings.Contains(name, searchText) {
s.enrichedProduct(product)
res = append(res, product)
}
}
return res, nil
}

View File

@ -1382,6 +1382,53 @@ func (x *GetImageReq) GetName() string {
return ""
}
type SearchReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"`
}
func (x *SearchReq) Reset() {
*x = SearchReq{}
if protoimpl.UnsafeEnabled {
mi := &file_main_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SearchReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SearchReq) ProtoMessage() {}
func (x *SearchReq) ProtoReflect() protoreflect.Message {
mi := &file_main_proto_msgTypes[23]
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 SearchReq.ProtoReflect.Descriptor instead.
func (*SearchReq) Descriptor() ([]byte, []int) {
return file_main_proto_rawDescGZIP(), []int{23}
}
func (x *SearchReq) GetText() string {
if x != nil {
return x.Text
}
return ""
}
var File_main_proto protoreflect.FileDescriptor
var file_main_proto_rawDesc = []byte{
@ -1520,47 +1567,54 @@ var file_main_proto_rawDesc = []byte{
0x6f, 0x75, 0x6e, 0x74, 0x4f, 0x6c, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x61,
0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x4f, 0x6c, 0x64, 0x22, 0x21, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x49,
0x6d, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x32, 0xe0, 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, 0x6d, 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, 0x22, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1c, 0x12, 0x1a, 0x2f, 0x70,
0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x2f, 0x62, 0x72, 0x65,
0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 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, 0x74, 0x12, 0x12,
0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x72, 0x74, 0x52,
0x65, 0x71, 0x1a, 0x12, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43,
0x61, 0x72, 0x74, 0x52, 0x73, 0x70, 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x3a, 0x05,
0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x05, 0x2f, 0x63, 0x61, 0x72, 0x74, 0x12, 0x50, 0x0a, 0x08,
0x47, 0x65, 0x74, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x16, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73,
0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71,
0x1a, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74,
0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e,
0x2f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 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,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x1f, 0x0a, 0x09, 0x53,
0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x32, 0xaa, 0x05, 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, 0x6d, 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, 0x22, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1c, 0x12, 0x1a, 0x2f,
0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x2f, 0x62, 0x72,
0x65, 0x61, 0x64, 0x63, 0x72, 0x75, 0x6d, 0x62, 0x73, 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, 0x74, 0x12,
0x12, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x43, 0x61, 0x72, 0x74,
0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e,
0x43, 0x61, 0x72, 0x74, 0x52, 0x73, 0x70, 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x3a,
0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x05, 0x2f, 0x63, 0x61, 0x72, 0x74, 0x12, 0x50, 0x0a,
0x08, 0x47, 0x65, 0x74, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x16, 0x2e, 0x63, 0x72, 0x61, 0x62,
0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x52, 0x65,
0x71, 0x1a, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48,
0x74, 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12,
0x0e, 0x2f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x12,
0x48, 0x0a, 0x06, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x12, 0x14, 0x2e, 0x63, 0x72, 0x61, 0x62,
0x73, 0x2e, 0x63, 0x72, 0x6d, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 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, 0x0f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x09,
0x12, 0x07, 0x2f, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 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 (
@ -1575,7 +1629,7 @@ func file_main_proto_rawDescGZIP() []byte {
return file_main_proto_rawDescData
}
var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 23)
var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 24)
var file_main_proto_goTypes = []interface{}{
(*GetCatalogReq)(nil), // 0: crabs.crm.GetCatalogReq
(*CatalogRsp)(nil), // 1: crabs.crm.CatalogRsp
@ -1600,7 +1654,8 @@ var file_main_proto_goTypes = []interface{}{
(*CartReq)(nil), // 20: crabs.crm.CartReq
(*CartRsp)(nil), // 21: crabs.crm.CartRsp
(*GetImageReq)(nil), // 22: crabs.crm.GetImageReq
(*httpbody.HttpBody)(nil), // 23: google.api.HttpBody
(*SearchReq)(nil), // 23: crabs.crm.SearchReq
(*httpbody.HttpBody)(nil), // 24: google.api.HttpBody
}
var file_main_proto_depIdxs = []int32{
2, // 0: crabs.crm.CatalogRsp.categories:type_name -> crabs.crm.Category
@ -1626,15 +1681,17 @@ var file_main_proto_depIdxs = []int32{
15, // 20: crabs.crm.CRM.Order:input_type -> crabs.crm.OrderReq
20, // 21: crabs.crm.CRM.GetCart:input_type -> crabs.crm.CartReq
22, // 22: crabs.crm.CRM.GetImage:input_type -> crabs.crm.GetImageReq
1, // 23: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp
4, // 24: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp
12, // 25: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp
14, // 26: crabs.crm.CRM.GetBreadcrumbs:output_type -> crabs.crm.BreadcrumbsRsp
16, // 27: crabs.crm.CRM.Order:output_type -> crabs.crm.OrderRsp
21, // 28: crabs.crm.CRM.GetCart:output_type -> crabs.crm.CartRsp
23, // 29: crabs.crm.CRM.GetImage:output_type -> google.api.HttpBody
23, // [23:30] is the sub-list for method output_type
16, // [16:23] is the sub-list for method input_type
23, // 23: crabs.crm.CRM.Search:input_type -> crabs.crm.SearchReq
1, // 24: crabs.crm.CRM.GetCatalog:output_type -> crabs.crm.CatalogRsp
4, // 25: crabs.crm.CRM.GetPositions:output_type -> crabs.crm.PositionsRsp
12, // 26: crabs.crm.CRM.GetProduct:output_type -> crabs.crm.ProductRsp
14, // 27: crabs.crm.CRM.GetBreadcrumbs:output_type -> crabs.crm.BreadcrumbsRsp
16, // 28: crabs.crm.CRM.Order:output_type -> crabs.crm.OrderRsp
21, // 29: crabs.crm.CRM.GetCart:output_type -> crabs.crm.CartRsp
24, // 30: crabs.crm.CRM.GetImage:output_type -> google.api.HttpBody
4, // 31: crabs.crm.CRM.Search:output_type -> crabs.crm.PositionsRsp
24, // [24:32] is the sub-list for method output_type
16, // [16:24] is the sub-list for method input_type
16, // [16:16] is the sub-list for extension type_name
16, // [16:16] is the sub-list for extension extendee
0, // [0:16] is the sub-list for field type_name
@ -1922,6 +1979,18 @@ func file_main_proto_init() {
return nil
}
}
file_main_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SearchReq); 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{
@ -1929,7 +1998,7 @@ func file_main_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_main_proto_rawDesc,
NumEnums: 0,
NumMessages: 23,
NumMessages: 24,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -309,6 +309,42 @@ func local_request_CRM_GetImage_0(ctx context.Context, marshaler runtime.Marshal
}
var (
filter_CRM_Search_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_CRM_Search_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq SearchReq
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CRM_Search_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Search(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_CRM_Search_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq SearchReq
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CRM_Search_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Search(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.
@ -490,6 +526,31 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server
})
mux.Handle("GET", pattern_CRM_Search_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/Search", runtime.WithHTTPPathPattern("/search"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_CRM_Search_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_Search_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -685,6 +746,28 @@ func RegisterCRMHandlerClient(ctx context.Context, mux *runtime.ServeMux, client
})
mux.Handle("GET", pattern_CRM_Search_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/Search", runtime.WithHTTPPathPattern("/search"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_CRM_Search_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_Search_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -702,6 +785,8 @@ var (
pattern_CRM_GetCart_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"cart"}, ""))
pattern_CRM_GetImage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"images", "name"}, ""))
pattern_CRM_Search_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"search"}, ""))
)
var (
@ -718,4 +803,6 @@ var (
forward_CRM_GetCart_0 = runtime.ForwardResponseMessage
forward_CRM_GetImage_0 = runtime.ForwardResponseMessage
forward_CRM_Search_0 = runtime.ForwardResponseMessage
)

View File

@ -27,6 +27,7 @@ const (
CRM_Order_FullMethodName = "/crabs.crm.CRM/Order"
CRM_GetCart_FullMethodName = "/crabs.crm.CRM/GetCart"
CRM_GetImage_FullMethodName = "/crabs.crm.CRM/GetImage"
CRM_Search_FullMethodName = "/crabs.crm.CRM/Search"
)
// CRMClient is the client API for CRM service.
@ -40,6 +41,7 @@ type CRMClient interface {
Order(ctx context.Context, in *OrderReq, opts ...grpc.CallOption) (*OrderRsp, error)
GetCart(ctx context.Context, in *CartReq, opts ...grpc.CallOption) (*CartRsp, error)
GetImage(ctx context.Context, in *GetImageReq, opts ...grpc.CallOption) (*httpbody.HttpBody, error)
Search(ctx context.Context, in *SearchReq, opts ...grpc.CallOption) (*PositionsRsp, error)
}
type cRMClient struct {
@ -113,6 +115,15 @@ func (c *cRMClient) GetImage(ctx context.Context, in *GetImageReq, opts ...grpc.
return out, nil
}
func (c *cRMClient) Search(ctx context.Context, in *SearchReq, opts ...grpc.CallOption) (*PositionsRsp, error) {
out := new(PositionsRsp)
err := c.cc.Invoke(ctx, CRM_Search_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
@ -124,6 +135,7 @@ type CRMServer interface {
Order(context.Context, *OrderReq) (*OrderRsp, error)
GetCart(context.Context, *CartReq) (*CartRsp, error)
GetImage(context.Context, *GetImageReq) (*httpbody.HttpBody, error)
Search(context.Context, *SearchReq) (*PositionsRsp, error)
mustEmbedUnimplementedCRMServer()
}
@ -152,6 +164,9 @@ func (UnimplementedCRMServer) GetCart(context.Context, *CartReq) (*CartRsp, erro
func (UnimplementedCRMServer) GetImage(context.Context, *GetImageReq) (*httpbody.HttpBody, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetImage not implemented")
}
func (UnimplementedCRMServer) Search(context.Context, *SearchReq) (*PositionsRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Search not implemented")
}
func (UnimplementedCRMServer) mustEmbedUnimplementedCRMServer() {}
// UnsafeCRMServer may be embedded to opt out of forward compatibility for this service.
@ -291,6 +306,24 @@ func _CRM_GetImage_Handler(srv interface{}, ctx context.Context, dec func(interf
return interceptor(ctx, in, info, handler)
}
func _CRM_Search_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CRMServer).Search(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CRM_Search_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CRMServer).Search(ctx, req.(*SearchReq))
}
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)
@ -326,6 +359,10 @@ var CRM_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetImage",
Handler: _CRM_GetImage_Handler,
},
{
MethodName: "Search",
Handler: _CRM_Search_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "main.proto",

View File

@ -228,6 +228,36 @@
"CRM"
]
}
},
"/search": {
"get": {
"operationId": "CRM_Search",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/crmPositionsRsp"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "text",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"CRM"
]
}
}
},
"definitions": {