правки
This commit is contained in:
@@ -2193,14 +2193,9 @@ func (s *PurchaseOptionalDetails) createPurchase(b *bot.Bot, jwt string) {
|
||||
return
|
||||
}
|
||||
|
||||
placementDetails := s.buildPlacementDetails(placementType)
|
||||
if placementDetails != nil && s.isPlacementDetailsEmpty(placementDetails) {
|
||||
placementDetails = nil
|
||||
}
|
||||
|
||||
apiChannels := make([]backend.CreatePlacementChannelInput, 0, len(s.Channels))
|
||||
for _, ch := range s.Channels {
|
||||
channelDetails := s.buildChannelDetails(channelKey(ch))
|
||||
channelDetails := s.buildChannelDetails(channelKey(ch), placementType)
|
||||
if channelDetails != nil && s.isChannelDetailsEmpty(channelDetails) {
|
||||
channelDetails = nil
|
||||
}
|
||||
@@ -2214,7 +2209,6 @@ func (s *PurchaseOptionalDetails) createPurchase(b *bot.Bot, jwt string) {
|
||||
input := backend.CreatePlacementsInput{
|
||||
CreativeID: &s.CreativeID,
|
||||
Channels: apiChannels,
|
||||
Details: placementDetails,
|
||||
}
|
||||
|
||||
placements, err := b.Backend.CreatePlacements(context.Background(), jwt, b.Session.WorkspaceID, s.ProjectID, input)
|
||||
@@ -2247,102 +2241,82 @@ func (s *PurchaseOptionalDetails) createPurchase(b *bot.Bot, jwt string) {
|
||||
}, bot.NewMessage)
|
||||
}
|
||||
|
||||
func (s *PurchaseOptionalDetails) buildPlacementDetails(placementType *string) *backend.PlacementDetails {
|
||||
func (s *PurchaseOptionalDetails) buildChannelDetails(channelKey string, placementType *string) *backend.PlacementDetails {
|
||||
details := &backend.PlacementDetails{}
|
||||
|
||||
if s.PlacementMode != "per_channel" || len(s.Channels) <= 1 {
|
||||
if s.PlacementDateTime != nil {
|
||||
formatted := s.PlacementDateTime.Format(time.RFC3339)
|
||||
details.PlacementAt = &formatted
|
||||
}
|
||||
}
|
||||
if s.PaymentDateMode != "per_channel" || len(s.Channels) <= 1 {
|
||||
if s.PaymentDate != nil {
|
||||
formatted := s.PaymentDate.Format(time.RFC3339)
|
||||
details.PaymentAt = &formatted
|
||||
}
|
||||
}
|
||||
if s.CostMode != "per_channel" || len(s.Channels) <= 1 {
|
||||
details.Cost = s.buildCostInfo(s.CostType, s.CostValue)
|
||||
}
|
||||
if s.CostBeforeMode != "per_channel" || len(s.Channels) <= 1 {
|
||||
if s.CostBeforeBargain != nil && s.CostBeforeBargain.Value != nil {
|
||||
details.CostBeforeBargain = s.buildCostInfo(s.CostBeforeBargain.Type, s.CostBeforeBargain.Value)
|
||||
}
|
||||
}
|
||||
if s.PurchaseTypeMode != "per_channel" || len(s.Channels) <= 1 {
|
||||
if s.PurchaseType != "" {
|
||||
details.PlacementType = &s.PurchaseType
|
||||
}
|
||||
}
|
||||
if s.CommentMode != "per_channel" || len(s.Channels) <= 1 {
|
||||
if s.Comment != "" {
|
||||
details.Comment = &s.Comment
|
||||
}
|
||||
}
|
||||
if s.FormatMode != "per_channel" || len(s.Channels) <= 1 {
|
||||
if s.Format != "" {
|
||||
details.Format = &s.Format
|
||||
}
|
||||
}
|
||||
if s.InviteLinkTypeMode != "per_channel" || len(s.Channels) <= 1 {
|
||||
if s.InviteLinkType != "" {
|
||||
details.InviteLinkType = &s.InviteLinkType
|
||||
}
|
||||
}
|
||||
if placementType != nil && (s.PurchaseTypeMode == "per_channel" || len(s.Channels) <= 1) {
|
||||
details.PlacementType = placementType
|
||||
}
|
||||
|
||||
return details
|
||||
}
|
||||
|
||||
func (s *PurchaseOptionalDetails) buildChannelDetails(channelKey string) *backend.PlacementDetails {
|
||||
if len(s.Channels) <= 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
details := &backend.PlacementDetails{}
|
||||
if s.PlacementMode == "per_channel" {
|
||||
// Placement date
|
||||
if s.PlacementMode == "per_channel" && len(s.Channels) > 1 {
|
||||
if value, ok := s.PlacementByChannel[channelKey]; ok && value != nil {
|
||||
formatted := value.Format(time.RFC3339)
|
||||
details.PlacementAt = &formatted
|
||||
}
|
||||
} else if s.PlacementDateTime != nil {
|
||||
formatted := s.PlacementDateTime.Format(time.RFC3339)
|
||||
details.PlacementAt = &formatted
|
||||
}
|
||||
if s.PaymentDateMode == "per_channel" {
|
||||
|
||||
// Payment date
|
||||
if s.PaymentDateMode == "per_channel" && len(s.Channels) > 1 {
|
||||
if value, ok := s.PaymentDateByChannel[channelKey]; ok && value != nil {
|
||||
formatted := value.Format(time.RFC3339)
|
||||
details.PaymentAt = &formatted
|
||||
}
|
||||
} else if s.PaymentDate != nil {
|
||||
formatted := s.PaymentDate.Format(time.RFC3339)
|
||||
details.PaymentAt = &formatted
|
||||
}
|
||||
if s.CostMode == "per_channel" {
|
||||
|
||||
// Cost
|
||||
if s.CostMode == "per_channel" && len(s.Channels) > 1 {
|
||||
entry := s.CostByChannel[channelKey]
|
||||
details.Cost = s.buildCostInfo(entry.Type, entry.Value)
|
||||
} else {
|
||||
details.Cost = s.buildCostInfo(s.CostType, s.CostValue)
|
||||
}
|
||||
if s.CostBeforeMode == "per_channel" {
|
||||
|
||||
// Cost before bargain
|
||||
if s.CostBeforeMode == "per_channel" && len(s.Channels) > 1 {
|
||||
if entry, ok := s.CostBeforeByChannel[channelKey]; ok && entry.Value != nil {
|
||||
details.CostBeforeBargain = s.buildCostInfo(entry.Type, entry.Value)
|
||||
}
|
||||
} else if s.CostBeforeBargain != nil && s.CostBeforeBargain.Value != nil {
|
||||
details.CostBeforeBargain = s.buildCostInfo(s.CostBeforeBargain.Type, s.CostBeforeBargain.Value)
|
||||
}
|
||||
if s.PurchaseTypeMode == "per_channel" {
|
||||
|
||||
// Placement type
|
||||
if s.PurchaseTypeMode == "per_channel" && len(s.Channels) > 1 {
|
||||
if value, ok := s.PurchaseTypeByChannel[channelKey]; ok && value != "" {
|
||||
details.PlacementType = &value
|
||||
}
|
||||
} else if placementType != nil {
|
||||
details.PlacementType = placementType
|
||||
}
|
||||
if s.CommentMode == "per_channel" {
|
||||
|
||||
// Comment
|
||||
if s.CommentMode == "per_channel" && len(s.Channels) > 1 {
|
||||
if value, ok := s.CommentByChannel[channelKey]; ok && value != "" {
|
||||
details.Comment = &value
|
||||
}
|
||||
} else if s.Comment != "" {
|
||||
details.Comment = &s.Comment
|
||||
}
|
||||
if s.FormatMode == "per_channel" {
|
||||
|
||||
// Format
|
||||
if s.FormatMode == "per_channel" && len(s.Channels) > 1 {
|
||||
if value, ok := s.FormatByChannel[channelKey]; ok && value != "" {
|
||||
details.Format = &value
|
||||
}
|
||||
} else if s.Format != "" {
|
||||
details.Format = &s.Format
|
||||
}
|
||||
if s.InviteLinkTypeMode == "per_channel" {
|
||||
|
||||
// Invite link type
|
||||
if s.InviteLinkTypeMode == "per_channel" && len(s.Channels) > 1 {
|
||||
if value, ok := s.InviteLinkTypeByChannel[channelKey]; ok && value != "" {
|
||||
details.InviteLinkType = &value
|
||||
}
|
||||
} else if s.InviteLinkType != "" {
|
||||
details.InviteLinkType = &s.InviteLinkType
|
||||
}
|
||||
|
||||
return details
|
||||
@@ -2362,21 +2336,15 @@ func (s *PurchaseOptionalDetails) buildCostInfo(costType string, value *float64)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PurchaseOptionalDetails) isPlacementDetailsEmpty(details *backend.PlacementDetails) bool {
|
||||
func (s *PurchaseOptionalDetails) isChannelDetailsEmpty(details *backend.PlacementDetails) bool {
|
||||
return details.PlacementAt == nil &&
|
||||
details.PaymentAt == nil &&
|
||||
details.Cost == nil &&
|
||||
details.CostBeforeBargain == nil &&
|
||||
details.PlacementType == nil &&
|
||||
details.Format == nil &&
|
||||
details.Comment == nil
|
||||
}
|
||||
|
||||
func (s *PurchaseOptionalDetails) isChannelDetailsEmpty(details *backend.PlacementDetails) bool {
|
||||
return details.PlacementAt == nil &&
|
||||
details.Cost == nil &&
|
||||
details.CostBeforeBargain == nil &&
|
||||
details.Format == nil
|
||||
details.Comment == nil &&
|
||||
details.InviteLinkType == nil
|
||||
}
|
||||
|
||||
func (s *PurchaseOptionalDetails) normalizePurchaseType() (*string, bool) {
|
||||
|
||||
Reference in New Issue
Block a user