From f2574a883870199ecc7393a4d809527203afa421 Mon Sep 17 00:00:00 2001 From: vallyenfail Date: Tue, 20 Jan 2026 13:47:40 +0300 Subject: [PATCH] add service --- api/proto/request/request.proto | 9 ++- internal/grpc/request_handler.go | 24 ++++-- pkg/pb/request/request.pb.go | 126 +++++++++++++++++++++++++------ tests/full_flow_test.go | 10 +-- tests/ownership_test.go | 4 +- tests/request_handler_test.go | 6 +- 6 files changed, 135 insertions(+), 44 deletions(-) diff --git a/api/proto/request/request.proto b/api/proto/request/request.proto index 9ff809c..f2ebfef 100644 --- a/api/proto/request/request.proto +++ b/api/proto/request/request.proto @@ -57,7 +57,7 @@ message GetMailingListByIDRequest { } message GetMailingListByIDResponse { - MailingItem item = 1; + MailingDetail detail = 1; } message MailingItem { @@ -68,3 +68,10 @@ message MailingItem { google.protobuf.Timestamp created_at = 5; int32 suppliers_found = 6; } + +message MailingDetail { + string request_id = 1; + string title = 2; + string mail_text = 3; + repeated Supplier suppliers = 4; +} diff --git a/internal/grpc/request_handler.go b/internal/grpc/request_handler.go index 85eb1e6..287e48d 100644 --- a/internal/grpc/request_handler.go +++ b/internal/grpc/request_handler.go @@ -3,7 +3,6 @@ package grpc import ( "context" "strconv" - "time" "git.techease.ru/Smart-search/smart-search-back/pkg/errors" pb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request" @@ -91,14 +90,23 @@ func (h *RequestHandler) GetMailingListByID(ctx context.Context, req *pb.GetMail return nil, errors.ToGRPCError(err, h.logger, "RequestService.GetMailingListByID") } + suppliers := make([]*pb.Supplier, 0, len(detail.Suppliers)) + for _, s := range detail.Suppliers { + suppliers = append(suppliers, &pb.Supplier{ + Id: strconv.Itoa(s.CompanyID), + Name: s.CompanyName, + Email: s.Email, + Phone: s.Phone, + Url: s.URL, + }) + } + return &pb.GetMailingListByIDResponse{ - Item: &pb.MailingItem{ - RequestId: detail.RequestID.String(), - RequestTxt: detail.Title, - FinalTz: detail.MailText, - MailingStatus: "sent", - CreatedAt: timestamppb.New(time.Now()), - SuppliersFound: int32(len(detail.Suppliers)), + Detail: &pb.MailingDetail{ + RequestId: detail.RequestID.String(), + Title: detail.Title, + MailText: detail.MailText, + Suppliers: suppliers, }, }, nil } diff --git a/pkg/pb/request/request.pb.go b/pkg/pb/request/request.pb.go index f33940b..24ea162 100644 --- a/pkg/pb/request/request.pb.go +++ b/pkg/pb/request/request.pb.go @@ -480,7 +480,7 @@ func (x *GetMailingListByIDRequest) GetUserId() int64 { type GetMailingListByIDResponse struct { state protoimpl.MessageState `protogen:"open.v1"` - Item *MailingItem `protobuf:"bytes,1,opt,name=item,proto3" json:"item,omitempty"` + Detail *MailingDetail `protobuf:"bytes,1,opt,name=detail,proto3" json:"detail,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -515,9 +515,9 @@ func (*GetMailingListByIDResponse) Descriptor() ([]byte, []int) { return file_request_request_proto_rawDescGZIP(), []int{8} } -func (x *GetMailingListByIDResponse) GetItem() *MailingItem { +func (x *GetMailingListByIDResponse) GetDetail() *MailingDetail { if x != nil { - return x.Item + return x.Detail } return nil } @@ -606,6 +606,74 @@ func (x *MailingItem) GetSuppliersFound() int32 { return 0 } +type MailingDetail struct { + state protoimpl.MessageState `protogen:"open.v1"` + RequestId string `protobuf:"bytes,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` + Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` + MailText string `protobuf:"bytes,3,opt,name=mail_text,json=mailText,proto3" json:"mail_text,omitempty"` + Suppliers []*Supplier `protobuf:"bytes,4,rep,name=suppliers,proto3" json:"suppliers,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MailingDetail) Reset() { + *x = MailingDetail{} + mi := &file_request_request_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MailingDetail) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MailingDetail) ProtoMessage() {} + +func (x *MailingDetail) ProtoReflect() protoreflect.Message { + mi := &file_request_request_proto_msgTypes[10] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MailingDetail.ProtoReflect.Descriptor instead. +func (*MailingDetail) Descriptor() ([]byte, []int) { + return file_request_request_proto_rawDescGZIP(), []int{10} +} + +func (x *MailingDetail) GetRequestId() string { + if x != nil { + return x.RequestId + } + return "" +} + +func (x *MailingDetail) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *MailingDetail) GetMailText() string { + if x != nil { + return x.MailText + } + return "" +} + +func (x *MailingDetail) GetSuppliers() []*Supplier { + if x != nil { + return x.Suppliers + } + return nil +} + var File_request_request_proto protoreflect.FileDescriptor const file_request_request_proto_rawDesc = "" + @@ -644,9 +712,9 @@ const file_request_request_proto_rawDesc = "" + "\x19GetMailingListByIDRequest\x12\x1d\n" + "\n" + "request_id\x18\x01 \x01(\tR\trequestId\x12\x17\n" + - "\auser_id\x18\x02 \x01(\x03R\x06userId\"F\n" + - "\x1aGetMailingListByIDResponse\x12(\n" + - "\x04item\x18\x01 \x01(\v2\x14.request.MailingItemR\x04item\"\xf3\x01\n" + + "\auser_id\x18\x02 \x01(\x03R\x06userId\"L\n" + + "\x1aGetMailingListByIDResponse\x12.\n" + + "\x06detail\x18\x01 \x01(\v2\x16.request.MailingDetailR\x06detail\"\xf3\x01\n" + "\vMailingItem\x12\x1d\n" + "\n" + "request_id\x18\x01 \x01(\tR\trequestId\x12\x1f\n" + @@ -656,7 +724,13 @@ const file_request_request_proto_rawDesc = "" + "\x0emailing_status\x18\x04 \x01(\tR\rmailingStatus\x129\n" + "\n" + "created_at\x18\x05 \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\x12'\n" + - "\x0fsuppliers_found\x18\x06 \x01(\x05R\x0esuppliersFound2\xc7\x02\n" + + "\x0fsuppliers_found\x18\x06 \x01(\x05R\x0esuppliersFound\"\x92\x01\n" + + "\rMailingDetail\x12\x1d\n" + + "\n" + + "request_id\x18\x01 \x01(\tR\trequestId\x12\x14\n" + + "\x05title\x18\x02 \x01(\tR\x05title\x12\x1b\n" + + "\tmail_text\x18\x03 \x01(\tR\bmailText\x12/\n" + + "\tsuppliers\x18\x04 \x03(\v2\x11.request.SupplierR\tsuppliers2\xc7\x02\n" + "\x0eRequestService\x12?\n" + "\bCreateTZ\x12\x18.request.CreateTZRequest\x1a\x19.request.CreateTZResponse\x12B\n" + "\tApproveTZ\x12\x19.request.ApproveTZRequest\x1a\x1a.request.ApproveTZResponse\x12Q\n" + @@ -675,7 +749,7 @@ func file_request_request_proto_rawDescGZIP() []byte { return file_request_request_proto_rawDescData } -var file_request_request_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_request_request_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_request_request_proto_goTypes = []any{ (*CreateTZRequest)(nil), // 0: request.CreateTZRequest (*CreateTZResponse)(nil), // 1: request.CreateTZResponse @@ -687,26 +761,28 @@ var file_request_request_proto_goTypes = []any{ (*GetMailingListByIDRequest)(nil), // 7: request.GetMailingListByIDRequest (*GetMailingListByIDResponse)(nil), // 8: request.GetMailingListByIDResponse (*MailingItem)(nil), // 9: request.MailingItem - (*timestamppb.Timestamp)(nil), // 10: google.protobuf.Timestamp + (*MailingDetail)(nil), // 10: request.MailingDetail + (*timestamppb.Timestamp)(nil), // 11: google.protobuf.Timestamp } var file_request_request_proto_depIdxs = []int32{ 4, // 0: request.ApproveTZResponse.suppliers:type_name -> request.Supplier 9, // 1: request.GetMailingListResponse.items:type_name -> request.MailingItem - 9, // 2: request.GetMailingListByIDResponse.item:type_name -> request.MailingItem - 10, // 3: request.MailingItem.created_at:type_name -> google.protobuf.Timestamp - 0, // 4: request.RequestService.CreateTZ:input_type -> request.CreateTZRequest - 2, // 5: request.RequestService.ApproveTZ:input_type -> request.ApproveTZRequest - 5, // 6: request.RequestService.GetMailingList:input_type -> request.GetMailingListRequest - 7, // 7: request.RequestService.GetMailingListByID:input_type -> request.GetMailingListByIDRequest - 1, // 8: request.RequestService.CreateTZ:output_type -> request.CreateTZResponse - 3, // 9: request.RequestService.ApproveTZ:output_type -> request.ApproveTZResponse - 6, // 10: request.RequestService.GetMailingList:output_type -> request.GetMailingListResponse - 8, // 11: request.RequestService.GetMailingListByID:output_type -> request.GetMailingListByIDResponse - 8, // [8:12] is the sub-list for method output_type - 4, // [4:8] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 10, // 2: request.GetMailingListByIDResponse.detail:type_name -> request.MailingDetail + 11, // 3: request.MailingItem.created_at:type_name -> google.protobuf.Timestamp + 4, // 4: request.MailingDetail.suppliers:type_name -> request.Supplier + 0, // 5: request.RequestService.CreateTZ:input_type -> request.CreateTZRequest + 2, // 6: request.RequestService.ApproveTZ:input_type -> request.ApproveTZRequest + 5, // 7: request.RequestService.GetMailingList:input_type -> request.GetMailingListRequest + 7, // 8: request.RequestService.GetMailingListByID:input_type -> request.GetMailingListByIDRequest + 1, // 9: request.RequestService.CreateTZ:output_type -> request.CreateTZResponse + 3, // 10: request.RequestService.ApproveTZ:output_type -> request.ApproveTZResponse + 6, // 11: request.RequestService.GetMailingList:output_type -> request.GetMailingListResponse + 8, // 12: request.RequestService.GetMailingListByID:output_type -> request.GetMailingListByIDResponse + 9, // [9:13] is the sub-list for method output_type + 5, // [5:9] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_request_request_proto_init() } @@ -720,7 +796,7 @@ func file_request_request_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_request_request_proto_rawDesc), len(file_request_request_proto_rawDesc)), NumEnums: 0, - NumMessages: 10, + NumMessages: 11, NumExtensions: 0, NumServices: 1, }, diff --git a/tests/full_flow_test.go b/tests/full_flow_test.go index 7dbb15b..1a76c26 100644 --- a/tests/full_flow_test.go +++ b/tests/full_flow_test.go @@ -97,8 +97,8 @@ func (s *IntegrationSuite) TestFullFlow_CompleteRequestLifecycle() { s.T().Logf("GetMailingListByID failed: %v", err) return } - s.NotNil(mailingListByIDResp.Item) - s.Equal(requestID, mailingListByIDResp.Item.RequestId) + s.NotNil(mailingListByIDResp.Detail) + s.Equal(requestID, mailingListByIDResp.Detail.RequestId) exportExcelReq := &supplierpb.ExportExcelRequest{ RequestId: requestID, @@ -232,9 +232,9 @@ func (s *IntegrationSuite) TestFullFlow_CreateTZ_ApproveTZ_GetMailingListByID_Ex mailingListByIDResp, err := s.requestClient.GetMailingListByID(ctx, getMailingListByIDReq) s.NoError(err) - s.NotNil(mailingListByIDResp.Item) - s.Equal(requestID, mailingListByIDResp.Item.RequestId) - s.Greater(mailingListByIDResp.Item.SuppliersFound, int32(0)) + s.NotNil(mailingListByIDResp.Detail) + s.Equal(requestID, mailingListByIDResp.Detail.RequestId) + s.Greater(len(mailingListByIDResp.Detail.Suppliers), 0) exportExcelReq := &supplierpb.ExportExcelRequest{ RequestId: requestID, diff --git a/tests/ownership_test.go b/tests/ownership_test.go index 16e7a40..1f5260f 100644 --- a/tests/ownership_test.go +++ b/tests/ownership_test.go @@ -209,6 +209,6 @@ func (s *IntegrationSuite) TestOwnership_GetMailingListByID_OwnRequest_Success() resp, err := s.requestClient.GetMailingListByID(ctx, getMailingByIDReq) s.NoError(err) s.NotNil(resp) - s.NotNil(resp.Item) - s.Equal(requestID, resp.Item.RequestId) + s.NotNil(resp.Detail) + s.Equal(requestID, resp.Detail.RequestId) } diff --git a/tests/request_handler_test.go b/tests/request_handler_test.go index fac1d4d..150ecb1 100644 --- a/tests/request_handler_test.go +++ b/tests/request_handler_test.go @@ -262,7 +262,7 @@ func (s *IntegrationSuite) TestRequestHandler_GetMailingListByIDSuccess() { getByIDResp, err := s.requestClient.GetMailingListByID(ctx, getByIDReq) s.NoError(err) s.NotNil(getByIDResp) - s.NotNil(getByIDResp.Item) - s.Equal(requestID, getByIDResp.Item.RequestId) - s.Greater(getByIDResp.Item.SuppliersFound, int32(0)) + s.NotNil(getByIDResp.Detail) + s.Equal(requestID, getByIDResp.Detail.RequestId) + s.Greater(len(getByIDResp.Detail.Suppliers), 0) }