add service
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 1m40s

This commit is contained in:
vallyenfail
2026-01-20 12:21:27 +03:00
parent 8046ad9a5f
commit cac4035560
8 changed files with 196 additions and 81 deletions

View File

@@ -41,24 +41,23 @@ lint:
@echo "Running linter..."
golangci-lint run ./...
#Протник генерируем как показано в smart-search-gateway! Здесь это оставлено на всякий случай
#proto:
# @echo "Generating proto files..."
# @mkdir -p pkg/pb
# @cd api/proto && protoc --go_out=../../pkg/pb --go_opt=paths=source_relative \
# --go-grpc_out=../../pkg/pb --go-grpc_opt=paths=source_relative \
# auth/auth.proto \
# user/user.proto \
# invite/invite.proto \
# request/request.proto \
# supplier/supplier.proto
# @echo "Proto generation complete"
#
#clean:
# @echo "Cleaning build artifacts..."
# rm -rf bin/
# rm -rf pkg/pb/
# @echo "Clean complete"
proto:
@echo "Generating proto files..."
@mkdir -p pkg/pb
@cd api/proto && protoc --go_out=../../pkg/pb --go_opt=paths=source_relative \
--go-grpc_out=../../pkg/pb --go-grpc_opt=paths=source_relative \
auth/auth.proto \
user/user.proto \
invite/invite.proto \
request/request.proto \
supplier/supplier.proto
@echo "Proto generation complete"
clean:
@echo "Cleaning build artifacts..."
rm -rf bin/
rm -rf pkg/pb/
@echo "Clean complete"
.PHONY: generate-mock
generate-mock:

View File

@@ -30,8 +30,17 @@ message ApproveTZRequest {
}
message ApproveTZResponse {
bool success = 1;
string mailing_status = 2;
string request_id = 1;
repeated Supplier suppliers = 2;
}
message Supplier {
string id = 1;
string name = 2;
string email = 3;
string phone = 4;
string address = 5;
string url = 6;
}
message GetMailingListRequest {

View File

@@ -2,6 +2,7 @@ package grpc
import (
"context"
"strconv"
"time"
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
@@ -33,14 +34,26 @@ func (h *RequestHandler) ApproveTZ(ctx context.Context, req *pb.ApproveTZRequest
return nil, errors.ToGRPCError(err, h.logger, "RequestService.ApproveTZ")
}
_, err = h.requestService.ApproveTZ(ctx, requestID, req.FinalTz, int(req.UserId))
suppliers, err := h.requestService.ApproveTZ(ctx, requestID, req.FinalTz, int(req.UserId))
if err != nil {
return nil, errors.ToGRPCError(err, h.logger, "RequestService.ApproveTZ")
}
pbSuppliers := make([]*pb.Supplier, 0, len(suppliers))
for _, s := range suppliers {
pbSuppliers = append(pbSuppliers, &pb.Supplier{
Id: strconv.Itoa(s.ID),
Name: s.Name,
Email: s.Email,
Phone: s.Phone,
Address: s.Address,
Url: s.URL,
})
}
return &pb.ApproveTZResponse{
Success: true,
MailingStatus: "sent",
RequestId: req.RequestId,
Suppliers: pbSuppliers,
}, nil
}

View File

@@ -204,8 +204,8 @@ func (x *ApproveTZRequest) GetUserId() int64 {
type ApproveTZResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
MailingStatus string `protobuf:"bytes,2,opt,name=mailing_status,json=mailingStatus,proto3" json:"mailing_status,omitempty"`
RequestId string `protobuf:"bytes,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"`
Suppliers []*Supplier `protobuf:"bytes,2,rep,name=suppliers,proto3" json:"suppliers,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -240,16 +240,100 @@ func (*ApproveTZResponse) Descriptor() ([]byte, []int) {
return file_request_request_proto_rawDescGZIP(), []int{3}
}
func (x *ApproveTZResponse) GetSuccess() bool {
func (x *ApproveTZResponse) GetRequestId() string {
if x != nil {
return x.Success
return x.RequestId
}
return false
return ""
}
func (x *ApproveTZResponse) GetMailingStatus() string {
func (x *ApproveTZResponse) GetSuppliers() []*Supplier {
if x != nil {
return x.MailingStatus
return x.Suppliers
}
return nil
}
type Supplier struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
Phone string `protobuf:"bytes,4,opt,name=phone,proto3" json:"phone,omitempty"`
Address string `protobuf:"bytes,5,opt,name=address,proto3" json:"address,omitempty"`
Url string `protobuf:"bytes,6,opt,name=url,proto3" json:"url,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Supplier) Reset() {
*x = Supplier{}
mi := &file_request_request_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Supplier) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Supplier) ProtoMessage() {}
func (x *Supplier) ProtoReflect() protoreflect.Message {
mi := &file_request_request_proto_msgTypes[4]
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 Supplier.ProtoReflect.Descriptor instead.
func (*Supplier) Descriptor() ([]byte, []int) {
return file_request_request_proto_rawDescGZIP(), []int{4}
}
func (x *Supplier) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *Supplier) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Supplier) GetEmail() string {
if x != nil {
return x.Email
}
return ""
}
func (x *Supplier) GetPhone() string {
if x != nil {
return x.Phone
}
return ""
}
func (x *Supplier) GetAddress() string {
if x != nil {
return x.Address
}
return ""
}
func (x *Supplier) GetUrl() string {
if x != nil {
return x.Url
}
return ""
}
@@ -263,7 +347,7 @@ type GetMailingListRequest struct {
func (x *GetMailingListRequest) Reset() {
*x = GetMailingListRequest{}
mi := &file_request_request_proto_msgTypes[4]
mi := &file_request_request_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -275,7 +359,7 @@ func (x *GetMailingListRequest) String() string {
func (*GetMailingListRequest) ProtoMessage() {}
func (x *GetMailingListRequest) ProtoReflect() protoreflect.Message {
mi := &file_request_request_proto_msgTypes[4]
mi := &file_request_request_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -288,7 +372,7 @@ func (x *GetMailingListRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetMailingListRequest.ProtoReflect.Descriptor instead.
func (*GetMailingListRequest) Descriptor() ([]byte, []int) {
return file_request_request_proto_rawDescGZIP(), []int{4}
return file_request_request_proto_rawDescGZIP(), []int{5}
}
func (x *GetMailingListRequest) GetUserId() int64 {
@@ -307,7 +391,7 @@ type GetMailingListResponse struct {
func (x *GetMailingListResponse) Reset() {
*x = GetMailingListResponse{}
mi := &file_request_request_proto_msgTypes[5]
mi := &file_request_request_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -319,7 +403,7 @@ func (x *GetMailingListResponse) String() string {
func (*GetMailingListResponse) ProtoMessage() {}
func (x *GetMailingListResponse) ProtoReflect() protoreflect.Message {
mi := &file_request_request_proto_msgTypes[5]
mi := &file_request_request_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -332,7 +416,7 @@ func (x *GetMailingListResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetMailingListResponse.ProtoReflect.Descriptor instead.
func (*GetMailingListResponse) Descriptor() ([]byte, []int) {
return file_request_request_proto_rawDescGZIP(), []int{5}
return file_request_request_proto_rawDescGZIP(), []int{6}
}
func (x *GetMailingListResponse) GetItems() []*MailingItem {
@@ -352,7 +436,7 @@ type GetMailingListByIDRequest struct {
func (x *GetMailingListByIDRequest) Reset() {
*x = GetMailingListByIDRequest{}
mi := &file_request_request_proto_msgTypes[6]
mi := &file_request_request_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -364,7 +448,7 @@ func (x *GetMailingListByIDRequest) String() string {
func (*GetMailingListByIDRequest) ProtoMessage() {}
func (x *GetMailingListByIDRequest) ProtoReflect() protoreflect.Message {
mi := &file_request_request_proto_msgTypes[6]
mi := &file_request_request_proto_msgTypes[7]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -377,7 +461,7 @@ func (x *GetMailingListByIDRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetMailingListByIDRequest.ProtoReflect.Descriptor instead.
func (*GetMailingListByIDRequest) Descriptor() ([]byte, []int) {
return file_request_request_proto_rawDescGZIP(), []int{6}
return file_request_request_proto_rawDescGZIP(), []int{7}
}
func (x *GetMailingListByIDRequest) GetRequestId() string {
@@ -403,7 +487,7 @@ type GetMailingListByIDResponse struct {
func (x *GetMailingListByIDResponse) Reset() {
*x = GetMailingListByIDResponse{}
mi := &file_request_request_proto_msgTypes[7]
mi := &file_request_request_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -415,7 +499,7 @@ func (x *GetMailingListByIDResponse) String() string {
func (*GetMailingListByIDResponse) ProtoMessage() {}
func (x *GetMailingListByIDResponse) ProtoReflect() protoreflect.Message {
mi := &file_request_request_proto_msgTypes[7]
mi := &file_request_request_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -428,7 +512,7 @@ func (x *GetMailingListByIDResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetMailingListByIDResponse.ProtoReflect.Descriptor instead.
func (*GetMailingListByIDResponse) Descriptor() ([]byte, []int) {
return file_request_request_proto_rawDescGZIP(), []int{7}
return file_request_request_proto_rawDescGZIP(), []int{8}
}
func (x *GetMailingListByIDResponse) GetItem() *MailingItem {
@@ -452,7 +536,7 @@ type MailingItem struct {
func (x *MailingItem) Reset() {
*x = MailingItem{}
mi := &file_request_request_proto_msgTypes[8]
mi := &file_request_request_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -464,7 +548,7 @@ func (x *MailingItem) String() string {
func (*MailingItem) ProtoMessage() {}
func (x *MailingItem) ProtoReflect() protoreflect.Message {
mi := &file_request_request_proto_msgTypes[8]
mi := &file_request_request_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -477,7 +561,7 @@ func (x *MailingItem) ProtoReflect() protoreflect.Message {
// Deprecated: Use MailingItem.ProtoReflect.Descriptor instead.
func (*MailingItem) Descriptor() ([]byte, []int) {
return file_request_request_proto_rawDescGZIP(), []int{8}
return file_request_request_proto_rawDescGZIP(), []int{9}
}
func (x *MailingItem) GetRequestId() string {
@@ -541,10 +625,18 @@ const file_request_request_proto_rawDesc = "" +
"\n" +
"request_id\x18\x01 \x01(\tR\trequestId\x12\x19\n" +
"\bfinal_tz\x18\x02 \x01(\tR\afinalTz\x12\x17\n" +
"\auser_id\x18\x03 \x01(\x03R\x06userId\"T\n" +
"\x11ApproveTZResponse\x12\x18\n" +
"\asuccess\x18\x01 \x01(\bR\asuccess\x12%\n" +
"\x0emailing_status\x18\x02 \x01(\tR\rmailingStatus\"0\n" +
"\auser_id\x18\x03 \x01(\x03R\x06userId\"c\n" +
"\x11ApproveTZResponse\x12\x1d\n" +
"\n" +
"request_id\x18\x01 \x01(\tR\trequestId\x12/\n" +
"\tsuppliers\x18\x02 \x03(\v2\x11.request.SupplierR\tsuppliers\"\x86\x01\n" +
"\bSupplier\x12\x0e\n" +
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
"\x04name\x18\x02 \x01(\tR\x04name\x12\x14\n" +
"\x05email\x18\x03 \x01(\tR\x05email\x12\x14\n" +
"\x05phone\x18\x04 \x01(\tR\x05phone\x12\x18\n" +
"\aaddress\x18\x05 \x01(\tR\aaddress\x12\x10\n" +
"\x03url\x18\x06 \x01(\tR\x03url\"0\n" +
"\x15GetMailingListRequest\x12\x17\n" +
"\auser_id\x18\x01 \x01(\x03R\x06userId\"D\n" +
"\x16GetMailingListResponse\x12*\n" +
@@ -583,36 +675,38 @@ func file_request_request_proto_rawDescGZIP() []byte {
return file_request_request_proto_rawDescData
}
var file_request_request_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_request_request_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_request_request_proto_goTypes = []any{
(*CreateTZRequest)(nil), // 0: request.CreateTZRequest
(*CreateTZResponse)(nil), // 1: request.CreateTZResponse
(*ApproveTZRequest)(nil), // 2: request.ApproveTZRequest
(*ApproveTZResponse)(nil), // 3: request.ApproveTZResponse
(*GetMailingListRequest)(nil), // 4: request.GetMailingListRequest
(*GetMailingListResponse)(nil), // 5: request.GetMailingListResponse
(*GetMailingListByIDRequest)(nil), // 6: request.GetMailingListByIDRequest
(*GetMailingListByIDResponse)(nil), // 7: request.GetMailingListByIDResponse
(*MailingItem)(nil), // 8: request.MailingItem
(*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp
(*Supplier)(nil), // 4: request.Supplier
(*GetMailingListRequest)(nil), // 5: request.GetMailingListRequest
(*GetMailingListResponse)(nil), // 6: request.GetMailingListResponse
(*GetMailingListByIDRequest)(nil), // 7: request.GetMailingListByIDRequest
(*GetMailingListByIDResponse)(nil), // 8: request.GetMailingListByIDResponse
(*MailingItem)(nil), // 9: request.MailingItem
(*timestamppb.Timestamp)(nil), // 10: google.protobuf.Timestamp
}
var file_request_request_proto_depIdxs = []int32{
8, // 0: request.GetMailingListResponse.items:type_name -> request.MailingItem
8, // 1: request.GetMailingListByIDResponse.item:type_name -> request.MailingItem
9, // 2: request.MailingItem.created_at:type_name -> google.protobuf.Timestamp
0, // 3: request.RequestService.CreateTZ:input_type -> request.CreateTZRequest
2, // 4: request.RequestService.ApproveTZ:input_type -> request.ApproveTZRequest
4, // 5: request.RequestService.GetMailingList:input_type -> request.GetMailingListRequest
6, // 6: request.RequestService.GetMailingListByID:input_type -> request.GetMailingListByIDRequest
1, // 7: request.RequestService.CreateTZ:output_type -> request.CreateTZResponse
3, // 8: request.RequestService.ApproveTZ:output_type -> request.ApproveTZResponse
5, // 9: request.RequestService.GetMailingList:output_type -> request.GetMailingListResponse
7, // 10: request.RequestService.GetMailingListByID:output_type -> request.GetMailingListByIDResponse
7, // [7:11] is the sub-list for method output_type
3, // [3:7] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
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
}
func init() { file_request_request_proto_init() }
@@ -626,7 +720,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: 9,
NumMessages: 10,
NumExtensions: 0,
NumServices: 1,
},

View File

@@ -322,7 +322,7 @@ func (s *IntegrationSuite) TestEdgeCase_ApproveTZTwice() {
approveResp1, err := s.requestClient.ApproveTZ(ctx, approveReq1)
s.NoError(err)
s.True(approveResp1.Success)
s.NotEmpty(approveResp1.RequestId)
approveReq2 := &requestpb.ApproveTZRequest{
RequestId: requestID,
@@ -332,7 +332,7 @@ func (s *IntegrationSuite) TestEdgeCase_ApproveTZTwice() {
approveResp2, err := s.requestClient.ApproveTZ(ctx, approveReq2)
s.NoError(err)
s.True(approveResp2.Success)
s.NotEmpty(approveResp2.RequestId)
}
func (s *IntegrationSuite) TestEdgeCase_CreateTZWithVeryLongText() {
@@ -418,5 +418,5 @@ func (s *IntegrationSuite) TestEdgeCase_ApproveTZWithVeryLongFinalTZ() {
approveResp, err := s.requestClient.ApproveTZ(ctx, approveReq)
s.NoError(err)
s.True(approveResp.Success)
s.NotEmpty(approveResp.RequestId)
}

View File

@@ -76,7 +76,7 @@ func (s *IntegrationSuite) TestFullFlow_CompleteRequestLifecycle() {
s.T().Logf("ApproveTZ failed: %v", err)
return
}
s.True(approveTZResp.Success)
s.NotEmpty(approveTZResp.RequestId)
getMailingListReq := &requestpb.GetMailingListRequest{
UserId: userID,
@@ -223,7 +223,7 @@ func (s *IntegrationSuite) TestFullFlow_CreateTZ_ApproveTZ_GetMailingListByID_Ex
approveTZResp, err := s.requestClient.ApproveTZ(ctx, approveTZReq)
s.NoError(err)
s.True(approveTZResp.Success)
s.NotEmpty(approveTZResp.RequestId)
getMailingListByIDReq := &requestpb.GetMailingListByIDRequest{
RequestId: requestID,

View File

@@ -210,8 +210,8 @@ func (s *IntegrationSuite) TestRequestHandler_ApproveTZSuccess() {
approveResp, err := s.requestClient.ApproveTZ(ctx, approveReq)
s.NoError(err)
s.NotNil(approveResp)
s.True(approveResp.Success)
s.Equal("sent", approveResp.MailingStatus)
s.NotEmpty(approveResp.RequestId)
s.NotNil(approveResp.Suppliers)
}
func (s *IntegrationSuite) TestRequestHandler_GetMailingListByIDSuccess() {

View File

@@ -133,7 +133,7 @@ func (s *IntegrationSuite) TestSupplierHandler_ExportExcelWithSuppliers() {
approveResp, err := s.requestClient.ApproveTZ(ctx, approveReq)
s.NoError(err)
s.True(approveResp.Success)
s.NotEmpty(approveResp.RequestId)
exportReq := &supplierpb.ExportExcelRequest{
RequestId: requestID,