feat: update protobuf message structure for product tariffs; change Offers to Offer and adjust related conversions

This commit is contained in:
2025-08-17 10:47:52 +03:00
parent abbcc0a81a
commit 593fbc88fa
7 changed files with 76 additions and 66 deletions

View File

@@ -25,7 +25,7 @@ type CalculateProductTariffsRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
MarketplaceId int64 `protobuf:"varint,1,opt,name=marketplace_id,json=marketplaceId,proto3" json:"marketplace_id,omitempty"` MarketplaceId int64 `protobuf:"varint,1,opt,name=marketplace_id,json=marketplaceId,proto3" json:"marketplace_id,omitempty"`
Parameters *CalculateProductTariffsRequest_Parameters `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` Parameters *CalculateProductTariffsRequest_Parameters `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"`
Offers []*CalculateProductTariffsRequest_Offers `protobuf:"bytes,3,rep,name=offers,proto3" json:"offers,omitempty"` Offers []*CalculateProductTariffsRequest_Offer `protobuf:"bytes,3,rep,name=offers,proto3" json:"offers,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@@ -74,7 +74,7 @@ func (x *CalculateProductTariffsRequest) GetParameters() *CalculateProductTariff
return nil return nil
} }
func (x *CalculateProductTariffsRequest) GetOffers() []*CalculateProductTariffsRequest_Offers { func (x *CalculateProductTariffsRequest) GetOffers() []*CalculateProductTariffsRequest_Offer {
if x != nil { if x != nil {
return x.Offers return x.Offers
} }
@@ -221,33 +221,33 @@ func (x *GetProductsResponse) GetOffers() []*GetProductsResponse_Offer {
return nil return nil
} }
type CalculateProductTariffsRequest_Offers struct { type CalculateProductTariffsRequest_Offer struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
CategoryId int64 `protobuf:"varint,1,opt,name=category_id,json=categoryId,proto3" json:"category_id,omitempty"` CategoryId int64 `protobuf:"varint,1,opt,name=category_id,json=categoryId,proto3" json:"category_id,omitempty"`
Price int64 `protobuf:"varint,2,opt,name=price,proto3" json:"price,omitempty"` Price float32 `protobuf:"fixed32,2,opt,name=price,proto3" json:"price,omitempty"`
Length int64 `protobuf:"varint,3,opt,name=length,proto3" json:"length,omitempty"` Length float32 `protobuf:"fixed32,3,opt,name=length,proto3" json:"length,omitempty"`
Width int64 `protobuf:"varint,4,opt,name=width,proto3" json:"width,omitempty"` Width float32 `protobuf:"fixed32,4,opt,name=width,proto3" json:"width,omitempty"`
Height int64 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"` Height float32 `protobuf:"fixed32,5,opt,name=height,proto3" json:"height,omitempty"`
Weight int64 `protobuf:"varint,6,opt,name=weight,proto3" json:"weight,omitempty"` Weight float32 `protobuf:"fixed32,6,opt,name=weight,proto3" json:"weight,omitempty"`
Quantity int64 `protobuf:"varint,7,opt,name=quantity,proto3" json:"quantity,omitempty"` Quantity int64 `protobuf:"varint,7,opt,name=quantity,proto3" json:"quantity,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
func (x *CalculateProductTariffsRequest_Offers) Reset() { func (x *CalculateProductTariffsRequest_Offer) Reset() {
*x = CalculateProductTariffsRequest_Offers{} *x = CalculateProductTariffsRequest_Offer{}
mi := &file_yandexmarket_products_proto_msgTypes[4] mi := &file_yandexmarket_products_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
func (x *CalculateProductTariffsRequest_Offers) String() string { func (x *CalculateProductTariffsRequest_Offer) String() string {
return protoimpl.X.MessageStringOf(x) return protoimpl.X.MessageStringOf(x)
} }
func (*CalculateProductTariffsRequest_Offers) ProtoMessage() {} func (*CalculateProductTariffsRequest_Offer) ProtoMessage() {}
func (x *CalculateProductTariffsRequest_Offers) ProtoReflect() protoreflect.Message { func (x *CalculateProductTariffsRequest_Offer) ProtoReflect() protoreflect.Message {
mi := &file_yandexmarket_products_proto_msgTypes[4] mi := &file_yandexmarket_products_proto_msgTypes[4]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -259,54 +259,54 @@ func (x *CalculateProductTariffsRequest_Offers) ProtoReflect() protoreflect.Mess
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use CalculateProductTariffsRequest_Offers.ProtoReflect.Descriptor instead. // Deprecated: Use CalculateProductTariffsRequest_Offer.ProtoReflect.Descriptor instead.
func (*CalculateProductTariffsRequest_Offers) Descriptor() ([]byte, []int) { func (*CalculateProductTariffsRequest_Offer) Descriptor() ([]byte, []int) {
return file_yandexmarket_products_proto_rawDescGZIP(), []int{0, 0} return file_yandexmarket_products_proto_rawDescGZIP(), []int{0, 0}
} }
func (x *CalculateProductTariffsRequest_Offers) GetCategoryId() int64 { func (x *CalculateProductTariffsRequest_Offer) GetCategoryId() int64 {
if x != nil { if x != nil {
return x.CategoryId return x.CategoryId
} }
return 0 return 0
} }
func (x *CalculateProductTariffsRequest_Offers) GetPrice() int64 { func (x *CalculateProductTariffsRequest_Offer) GetPrice() float32 {
if x != nil { if x != nil {
return x.Price return x.Price
} }
return 0 return 0
} }
func (x *CalculateProductTariffsRequest_Offers) GetLength() int64 { func (x *CalculateProductTariffsRequest_Offer) GetLength() float32 {
if x != nil { if x != nil {
return x.Length return x.Length
} }
return 0 return 0
} }
func (x *CalculateProductTariffsRequest_Offers) GetWidth() int64 { func (x *CalculateProductTariffsRequest_Offer) GetWidth() float32 {
if x != nil { if x != nil {
return x.Width return x.Width
} }
return 0 return 0
} }
func (x *CalculateProductTariffsRequest_Offers) GetHeight() int64 { func (x *CalculateProductTariffsRequest_Offer) GetHeight() float32 {
if x != nil { if x != nil {
return x.Height return x.Height
} }
return 0 return 0
} }
func (x *CalculateProductTariffsRequest_Offers) GetWeight() int64 { func (x *CalculateProductTariffsRequest_Offer) GetWeight() float32 {
if x != nil { if x != nil {
return x.Weight return x.Weight
} }
return 0 return 0
} }
func (x *CalculateProductTariffsRequest_Offers) GetQuantity() int64 { func (x *CalculateProductTariffsRequest_Offer) GetQuantity() int64 {
if x != nil { if x != nil {
return x.Quantity return x.Quantity
} }
@@ -384,11 +384,11 @@ func (x *CalculateProductTariffsRequest_Parameters) GetCurrency() string {
type CalculateProductTariffsResponse_Offer struct { type CalculateProductTariffsResponse_Offer struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
CategoryId int64 `protobuf:"varint,1,opt,name=category_id,json=categoryId,proto3" json:"category_id,omitempty"` CategoryId int64 `protobuf:"varint,1,opt,name=category_id,json=categoryId,proto3" json:"category_id,omitempty"`
Price int64 `protobuf:"varint,2,opt,name=price,proto3" json:"price,omitempty"` Price float32 `protobuf:"fixed32,2,opt,name=price,proto3" json:"price,omitempty"`
Length int64 `protobuf:"varint,3,opt,name=length,proto3" json:"length,omitempty"` Length float32 `protobuf:"fixed32,3,opt,name=length,proto3" json:"length,omitempty"`
Width int64 `protobuf:"varint,4,opt,name=width,proto3" json:"width,omitempty"` Width float32 `protobuf:"fixed32,4,opt,name=width,proto3" json:"width,omitempty"`
Height int64 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"` Height float32 `protobuf:"fixed32,5,opt,name=height,proto3" json:"height,omitempty"`
Weight int64 `protobuf:"varint,6,opt,name=weight,proto3" json:"weight,omitempty"` Weight float32 `protobuf:"fixed32,6,opt,name=weight,proto3" json:"weight,omitempty"`
Quantity int64 `protobuf:"varint,7,opt,name=quantity,proto3" json:"quantity,omitempty"` Quantity int64 `protobuf:"varint,7,opt,name=quantity,proto3" json:"quantity,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -431,35 +431,35 @@ func (x *CalculateProductTariffsResponse_Offer) GetCategoryId() int64 {
return 0 return 0
} }
func (x *CalculateProductTariffsResponse_Offer) GetPrice() int64 { func (x *CalculateProductTariffsResponse_Offer) GetPrice() float32 {
if x != nil { if x != nil {
return x.Price return x.Price
} }
return 0 return 0
} }
func (x *CalculateProductTariffsResponse_Offer) GetLength() int64 { func (x *CalculateProductTariffsResponse_Offer) GetLength() float32 {
if x != nil { if x != nil {
return x.Length return x.Length
} }
return 0 return 0
} }
func (x *CalculateProductTariffsResponse_Offer) GetWidth() int64 { func (x *CalculateProductTariffsResponse_Offer) GetWidth() float32 {
if x != nil { if x != nil {
return x.Width return x.Width
} }
return 0 return 0
} }
func (x *CalculateProductTariffsResponse_Offer) GetHeight() int64 { func (x *CalculateProductTariffsResponse_Offer) GetHeight() float32 {
if x != nil { if x != nil {
return x.Height return x.Height
} }
return 0 return 0
} }
func (x *CalculateProductTariffsResponse_Offer) GetWeight() int64 { func (x *CalculateProductTariffsResponse_Offer) GetWeight() float32 {
if x != nil { if x != nil {
return x.Weight return x.Weight
} }
@@ -829,21 +829,21 @@ var File_yandexmarket_products_proto protoreflect.FileDescriptor
const file_yandexmarket_products_proto_rawDesc = "" + const file_yandexmarket_products_proto_rawDesc = "" +
"\n" + "\n" +
"\x1byandexmarket/products.proto\x12\x15yandexmarket.products\"\xce\x04\n" + "\x1byandexmarket/products.proto\x12\x15yandexmarket.products\"\xcc\x04\n" +
"\x1eCalculateProductTariffsRequest\x12%\n" + "\x1eCalculateProductTariffsRequest\x12%\n" +
"\x0emarketplace_id\x18\x01 \x01(\x03R\rmarketplaceId\x12`\n" + "\x0emarketplace_id\x18\x01 \x01(\x03R\rmarketplaceId\x12`\n" +
"\n" + "\n" +
"parameters\x18\x02 \x01(\v2@.yandexmarket.products.CalculateProductTariffsRequest.ParametersR\n" + "parameters\x18\x02 \x01(\v2@.yandexmarket.products.CalculateProductTariffsRequest.ParametersR\n" +
"parameters\x12T\n" + "parameters\x12S\n" +
"\x06offers\x18\x03 \x03(\v2<.yandexmarket.products.CalculateProductTariffsRequest.OffersR\x06offers\x1a\xb9\x01\n" + "\x06offers\x18\x03 \x03(\v2;.yandexmarket.products.CalculateProductTariffsRequest.OfferR\x06offers\x1a\xb8\x01\n" +
"\x06Offers\x12\x1f\n" + "\x05Offer\x12\x1f\n" +
"\vcategory_id\x18\x01 \x01(\x03R\n" + "\vcategory_id\x18\x01 \x01(\x03R\n" +
"categoryId\x12\x14\n" + "categoryId\x12\x14\n" +
"\x05price\x18\x02 \x01(\x03R\x05price\x12\x16\n" + "\x05price\x18\x02 \x01(\x02R\x05price\x12\x16\n" +
"\x06length\x18\x03 \x01(\x03R\x06length\x12\x14\n" + "\x06length\x18\x03 \x01(\x02R\x06length\x12\x14\n" +
"\x05width\x18\x04 \x01(\x03R\x05width\x12\x16\n" + "\x05width\x18\x04 \x01(\x02R\x05width\x12\x16\n" +
"\x06height\x18\x05 \x01(\x03R\x06height\x12\x16\n" + "\x06height\x18\x05 \x01(\x02R\x06height\x12\x16\n" +
"\x06weight\x18\x06 \x01(\x03R\x06weight\x12\x1a\n" + "\x06weight\x18\x06 \x01(\x02R\x06weight\x12\x1a\n" +
"\bquantity\x18\a \x01(\x03R\bquantity\x1a\x90\x01\n" + "\bquantity\x18\a \x01(\x03R\bquantity\x1a\x90\x01\n" +
"\n" + "\n" +
"Parameters\x12\x1f\n" + "Parameters\x12\x1f\n" +
@@ -857,11 +857,11 @@ const file_yandexmarket_products_proto_rawDesc = "" +
"\x05Offer\x12\x1f\n" + "\x05Offer\x12\x1f\n" +
"\vcategory_id\x18\x01 \x01(\x03R\n" + "\vcategory_id\x18\x01 \x01(\x03R\n" +
"categoryId\x12\x14\n" + "categoryId\x12\x14\n" +
"\x05price\x18\x02 \x01(\x03R\x05price\x12\x16\n" + "\x05price\x18\x02 \x01(\x02R\x05price\x12\x16\n" +
"\x06length\x18\x03 \x01(\x03R\x06length\x12\x14\n" + "\x06length\x18\x03 \x01(\x02R\x06length\x12\x14\n" +
"\x05width\x18\x04 \x01(\x03R\x05width\x12\x16\n" + "\x05width\x18\x04 \x01(\x02R\x05width\x12\x16\n" +
"\x06height\x18\x05 \x01(\x03R\x06height\x12\x16\n" + "\x06height\x18\x05 \x01(\x02R\x06height\x12\x16\n" +
"\x06weight\x18\x06 \x01(\x03R\x06weight\x12\x1a\n" + "\x06weight\x18\x06 \x01(\x02R\x06weight\x12\x1a\n" +
"\bquantity\x18\a \x01(\x03R\bquantity\x1a5\n" + "\bquantity\x18\a \x01(\x03R\bquantity\x1a5\n" +
"\tParameter\x12\x12\n" + "\tParameter\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" +
@@ -917,7 +917,7 @@ var file_yandexmarket_products_proto_goTypes = []any{
(*CalculateProductTariffsResponse)(nil), // 1: yandexmarket.products.CalculateProductTariffsResponse (*CalculateProductTariffsResponse)(nil), // 1: yandexmarket.products.CalculateProductTariffsResponse
(*GetProductsRequest)(nil), // 2: yandexmarket.products.GetProductsRequest (*GetProductsRequest)(nil), // 2: yandexmarket.products.GetProductsRequest
(*GetProductsResponse)(nil), // 3: yandexmarket.products.GetProductsResponse (*GetProductsResponse)(nil), // 3: yandexmarket.products.GetProductsResponse
(*CalculateProductTariffsRequest_Offers)(nil), // 4: yandexmarket.products.CalculateProductTariffsRequest.Offers (*CalculateProductTariffsRequest_Offer)(nil), // 4: yandexmarket.products.CalculateProductTariffsRequest.Offer
(*CalculateProductTariffsRequest_Parameters)(nil), // 5: yandexmarket.products.CalculateProductTariffsRequest.Parameters (*CalculateProductTariffsRequest_Parameters)(nil), // 5: yandexmarket.products.CalculateProductTariffsRequest.Parameters
(*CalculateProductTariffsResponse_Offer)(nil), // 6: yandexmarket.products.CalculateProductTariffsResponse.Offer (*CalculateProductTariffsResponse_Offer)(nil), // 6: yandexmarket.products.CalculateProductTariffsResponse.Offer
(*CalculateProductTariffsResponse_Parameter)(nil), // 7: yandexmarket.products.CalculateProductTariffsResponse.Parameter (*CalculateProductTariffsResponse_Parameter)(nil), // 7: yandexmarket.products.CalculateProductTariffsResponse.Parameter
@@ -929,7 +929,7 @@ var file_yandexmarket_products_proto_goTypes = []any{
} }
var file_yandexmarket_products_proto_depIdxs = []int32{ var file_yandexmarket_products_proto_depIdxs = []int32{
5, // 0: yandexmarket.products.CalculateProductTariffsRequest.parameters:type_name -> yandexmarket.products.CalculateProductTariffsRequest.Parameters 5, // 0: yandexmarket.products.CalculateProductTariffsRequest.parameters:type_name -> yandexmarket.products.CalculateProductTariffsRequest.Parameters
4, // 1: yandexmarket.products.CalculateProductTariffsRequest.offers:type_name -> yandexmarket.products.CalculateProductTariffsRequest.Offers 4, // 1: yandexmarket.products.CalculateProductTariffsRequest.offers:type_name -> yandexmarket.products.CalculateProductTariffsRequest.Offer
9, // 2: yandexmarket.products.CalculateProductTariffsResponse.offers:type_name -> yandexmarket.products.CalculateProductTariffsResponse.Offers 9, // 2: yandexmarket.products.CalculateProductTariffsResponse.offers:type_name -> yandexmarket.products.CalculateProductTariffsResponse.Offers
10, // 3: yandexmarket.products.GetProductsResponse.offers:type_name -> yandexmarket.products.GetProductsResponse.Offer 10, // 3: yandexmarket.products.GetProductsResponse.offers:type_name -> yandexmarket.products.GetProductsResponse.Offer
7, // 4: yandexmarket.products.CalculateProductTariffsResponse.Tariff.parameters:type_name -> yandexmarket.products.CalculateProductTariffsResponse.Parameter 7, // 4: yandexmarket.products.CalculateProductTariffsResponse.Tariff.parameters:type_name -> yandexmarket.products.CalculateProductTariffsResponse.Parameter

View File

@@ -16,6 +16,7 @@ import (
"github.com/jackc/pgx/v5/pgxpool" "github.com/jackc/pgx/v5/pgxpool"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"google.golang.org/grpc" "google.golang.org/grpc"
_ "google.golang.org/grpc/encoding/gzip"
) )
func logMessage(level string, format string, a ...interface{}) { func logMessage(level string, format string, a ...interface{}) {

View File

@@ -6,7 +6,7 @@ import (
type PbCalculateProductTariffsRequest = pb.CalculateProductTariffsRequest type PbCalculateProductTariffsRequest = pb.CalculateProductTariffsRequest
type PbCalculateProductTariffsResponse = pb.CalculateProductTariffsResponse type PbCalculateProductTariffsResponse = pb.CalculateProductTariffsResponse
type PbOffer = pb.CalculateProductTariffsRequest_Offers type PbOffer = pb.CalculateProductTariffsRequest_Offer
type PbResponseOffer = pb.CalculateProductTariffsResponse_Offers type PbResponseOffer = pb.CalculateProductTariffsResponse_Offers
type PbParameters = pb.CalculateProductTariffsRequest_Parameters type PbParameters = pb.CalculateProductTariffsRequest_Parameters
type PbGetProductsOffer = pb.GetProductsResponse_Offer type PbGetProductsOffer = pb.GetProductsResponse_Offer

View File

@@ -1,8 +1,9 @@
package mapping package mapping
import ( import (
"git.denco.store/fakz9/yandex-go-client"
proto "sipro-mps/api/generated/v1/yandexmarket/products" proto "sipro-mps/api/generated/v1/yandexmarket/products"
"git.denco.store/fakz9/yandex-go-client"
) )
//go:generate go run github.com/jmattheis/goverter/cmd/goverter gen . //go:generate go run github.com/jmattheis/goverter/cmd/goverter gen .
@@ -16,7 +17,7 @@ import (
// goverter:useZeroValueOnPointerInconsistency yes // goverter:useZeroValueOnPointerInconsistency yes
// goverter:extend Int64ToFloat32 Int64ToInt32 Float32ToInt64 Int32ToInt64 PointerInt32ToInt64 // goverter:extend Int64ToFloat32 Int64ToInt32 Float32ToInt64 Int32ToInt64 PointerInt32ToInt64
type Converter interface { type Converter interface {
ProtoOfferToYmOffer(details *proto.CalculateProductTariffsRequest_Offers) *ymclient.CalculateTariffsOfferDTO ProtoOfferToYmOffer(details *proto.CalculateProductTariffsRequest_Offer) *ymclient.CalculateTariffsOfferDTO
ProtoParametersToYmParameters(details *proto.CalculateProductTariffsRequest_Parameters) *ymclient.CalculateTariffsParametersDTO ProtoParametersToYmParameters(details *proto.CalculateProductTariffsRequest_Parameters) *ymclient.CalculateTariffsParametersDTO
// Response converters // Response converters

View File

@@ -11,16 +11,16 @@ import (
type ConverterImpl struct{} type ConverterImpl struct{}
func (c *ConverterImpl) ProtoOfferToYmOffer(source *products.CalculateProductTariffsRequest_Offers) *yandexgoclient.CalculateTariffsOfferDTO { func (c *ConverterImpl) ProtoOfferToYmOffer(source *products.CalculateProductTariffsRequest_Offer) *yandexgoclient.CalculateTariffsOfferDTO {
var pYmclientCalculateTariffsOfferDTO *yandexgoclient.CalculateTariffsOfferDTO var pYmclientCalculateTariffsOfferDTO *yandexgoclient.CalculateTariffsOfferDTO
if source != nil { if source != nil {
var ymclientCalculateTariffsOfferDTO yandexgoclient.CalculateTariffsOfferDTO var ymclientCalculateTariffsOfferDTO yandexgoclient.CalculateTariffsOfferDTO
ymclientCalculateTariffsOfferDTO.CategoryId = (*source).CategoryId ymclientCalculateTariffsOfferDTO.CategoryId = (*source).CategoryId
ymclientCalculateTariffsOfferDTO.Price = mapping.Int64ToFloat32((*source).Price) ymclientCalculateTariffsOfferDTO.Price = (*source).Price
ymclientCalculateTariffsOfferDTO.Length = mapping.Int64ToFloat32((*source).Length) ymclientCalculateTariffsOfferDTO.Length = (*source).Length
ymclientCalculateTariffsOfferDTO.Width = mapping.Int64ToFloat32((*source).Width) ymclientCalculateTariffsOfferDTO.Width = (*source).Width
ymclientCalculateTariffsOfferDTO.Height = mapping.Int64ToFloat32((*source).Height) ymclientCalculateTariffsOfferDTO.Height = (*source).Height
ymclientCalculateTariffsOfferDTO.Weight = mapping.Int64ToFloat32((*source).Weight) ymclientCalculateTariffsOfferDTO.Weight = (*source).Weight
pInt32 := mapping.Int64ToInt32((*source).Quantity) pInt32 := mapping.Int64ToInt32((*source).Quantity)
ymclientCalculateTariffsOfferDTO.Quantity = &pInt32 ymclientCalculateTariffsOfferDTO.Quantity = &pInt32
pYmclientCalculateTariffsOfferDTO = &ymclientCalculateTariffsOfferDTO pYmclientCalculateTariffsOfferDTO = &ymclientCalculateTariffsOfferDTO
@@ -117,11 +117,11 @@ func (c *ConverterImpl) pYmclientOfferWeightDimensionsDTOToPProductsGetProductsR
func (c *ConverterImpl) ymclientCalculateTariffsOfferDTOToPProductsCalculateProductTariffsResponse_Offer(source yandexgoclient.CalculateTariffsOfferDTO) *products.CalculateProductTariffsResponse_Offer { func (c *ConverterImpl) ymclientCalculateTariffsOfferDTOToPProductsCalculateProductTariffsResponse_Offer(source yandexgoclient.CalculateTariffsOfferDTO) *products.CalculateProductTariffsResponse_Offer {
var productsCalculateProductTariffsResponse_Offer products.CalculateProductTariffsResponse_Offer var productsCalculateProductTariffsResponse_Offer products.CalculateProductTariffsResponse_Offer
productsCalculateProductTariffsResponse_Offer.CategoryId = source.CategoryId productsCalculateProductTariffsResponse_Offer.CategoryId = source.CategoryId
productsCalculateProductTariffsResponse_Offer.Price = mapping.Float32ToInt64(source.Price) productsCalculateProductTariffsResponse_Offer.Price = source.Price
productsCalculateProductTariffsResponse_Offer.Length = mapping.Float32ToInt64(source.Length) productsCalculateProductTariffsResponse_Offer.Length = source.Length
productsCalculateProductTariffsResponse_Offer.Width = mapping.Float32ToInt64(source.Width) productsCalculateProductTariffsResponse_Offer.Width = source.Width
productsCalculateProductTariffsResponse_Offer.Height = mapping.Float32ToInt64(source.Height) productsCalculateProductTariffsResponse_Offer.Height = source.Height
productsCalculateProductTariffsResponse_Offer.Weight = mapping.Float32ToInt64(source.Weight) productsCalculateProductTariffsResponse_Offer.Weight = source.Weight
if source.Quantity != nil { if source.Quantity != nil {
productsCalculateProductTariffsResponse_Offer.Quantity = mapping.Int32ToInt64(*source.Quantity) productsCalculateProductTariffsResponse_Offer.Quantity = mapping.Int32ToInt64(*source.Quantity)
} }

View File

@@ -184,6 +184,7 @@ func (r *apiRepository) processOfferMappings(offerMappings []ymclient.GetOfferMa
resultOffers = append(resultOffers, &pb.GetProductsResponse_Offer{}) resultOffers = append(resultOffers, &pb.GetProductsResponse_Offer{})
continue continue
} }
protoOffer.MarketCategoryId = *offerMapping.Mapping.MarketCategoryId
resultOffers = append(resultOffers, protoOffer) resultOffers = append(resultOffers, protoOffer)
} }
@@ -233,15 +234,22 @@ func (r *apiRepository) setTariffsRateLimit() {
} }
// processTariffChunk processes a single chunk of offers for tariff calculation // processTariffChunk processes a single chunk of offers for tariff calculation
func (r *apiRepository) processTariffChunk(ctx context.Context, client *ymclient.APIClient, ymParameters *ymclient.CalculateTariffsParametersDTO, offerChunk []*pb.CalculateProductTariffsRequest_Offers, chunkIndex int) (*pb.CalculateProductTariffsResponse, error) { func (r *apiRepository) processTariffChunk(ctx context.Context, client *ymclient.APIClient, ymParameters *ymclient.CalculateTariffsParametersDTO, offerChunk []*pb.CalculateProductTariffsRequest_Offer, chunkIndex int) (*pb.CalculateProductTariffsResponse, error) {
ymOffers := r.convertOffersToYM(offerChunk) ymOffers := r.convertOffersToYM(offerChunk)
if len(ymOffers) == 0 { if len(ymOffers) == 0 {
fmt.Printf("Skipping chunk %d: no valid offers\n", chunkIndex+1) fmt.Printf("Skipping chunk %d: no valid offers\n", chunkIndex+1)
return nil, nil return nil, nil
} }
ymRequest := ymclient.NewCalculateTariffsRequest(*ymParameters, ymOffers) if ymParameters.CampaignId != nil && *ymParameters.CampaignId > 0 {
ymParameters.SellingProgram = nil
ymParameters.Frequency = nil
ymParameters.Currency = nil
} else {
ymParameters.CampaignId = nil
}
ymRequest := ymclient.NewCalculateTariffsRequest(*ymParameters, ymOffers)
response, httpResp, err := client.TariffsAPI.CalculateTariffs(ctx). response, httpResp, err := client.TariffsAPI.CalculateTariffs(ctx).
CalculateTariffsRequest(*ymRequest). CalculateTariffsRequest(*ymRequest).
Execute() Execute()
@@ -263,7 +271,7 @@ func (r *apiRepository) processTariffChunk(ctx context.Context, client *ymclient
} }
// convertOffersToYM converts protobuf offers to Yandex Market format // convertOffersToYM converts protobuf offers to Yandex Market format
func (r *apiRepository) convertOffersToYM(offers []*pb.CalculateProductTariffsRequest_Offers) []ymclient.CalculateTariffsOfferDTO { func (r *apiRepository) convertOffersToYM(offers []*pb.CalculateProductTariffsRequest_Offer) []ymclient.CalculateTariffsOfferDTO {
var ymOffers []ymclient.CalculateTariffsOfferDTO var ymOffers []ymclient.CalculateTariffsOfferDTO
for _, offer := range offers { for _, offer := range offers {
ymOffer := r.converter.ProtoOfferToYmOffer(offer) ymOffer := r.converter.ProtoOfferToYmOffer(offer)