Created
July 31, 2020 21:40
-
-
Save ericraio/82ce51bf37657e8ddcaaaa5932734ff9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lineitem | |
import ( | |
"errors" | |
"github.com/ezoic/go-dfpapi/generated/lineitemservice" | |
) | |
type LineItemModel struct { | |
Attributes *lineitemservice.LineItem | |
} | |
func (lim *LineItemModel) GetCustomTargetingValuesFromKeyID(targetID int64) ([]*int64, error) { | |
var values []*int64 | |
targetingPtr := lim.Attributes.Targeting | |
if targetingPtr == nil { | |
return values, errors.New("Targeting is missing") | |
} | |
targeting := *targetingPtr | |
customTargetingPtr := targeting.CustomTargeting | |
if customTargetingPtr == nil { | |
return values, errors.New("Custom targeting is missing") | |
} | |
customTargeting := *customTargetingPtr | |
children := customTargeting.Children | |
var childPtr *lineitemservice.CustomCriteriaNode | |
if len(children) > 1 { | |
for _, target := range children { | |
if target == nil { | |
continue | |
} | |
customCriteriaPtr := target.CustomCriteria | |
if customCriteriaPtr == nil { | |
continue | |
} | |
customCriteria := *customCriteriaPtr | |
keyIdPtr := customCriteria.KeyId | |
if keyIdPtr == nil { | |
continue | |
} | |
keyID := *keyIdPtr | |
if keyID == targetID { | |
childPtr = target | |
break | |
} | |
} | |
} else { | |
childPtr = children[0] | |
} | |
if childPtr == nil { | |
return values, errors.New("Missing child values") | |
} | |
child := *childPtr | |
criteriaPtr := child.CustomCriteria | |
if criteriaPtr == nil { | |
return values, errors.New("Missing custom criteria") | |
} | |
criteria := *criteriaPtr | |
return criteria.ValueIds, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment