-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entities #58
base: v2
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice start! i agree the Register/Unwrap might need some tweaking, but only usage will tell for sure
@@ -324,7 +325,7 @@ func tokenListHelper(lr tokenListRetriever, opts *ListOptions) error { | |||
func addListOptions(requrl string, opts *ListOptions) (string, error) { | |||
u, err := url.Parse(requrl) | |||
if err != nil { | |||
return "", nil | |||
return "", err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and a bugfix - hurrah!
client.go
Outdated
@@ -336,6 +337,7 @@ func addListOptions(requrl string, opts *ListOptions) (string, error) { | |||
q.Add("limit", strconv.Itoa(opts.Limit)) | |||
} | |||
if opts.PageToken != "" { | |||
// TODO: this is not compatible with the old parameter name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(
maybe the func could take another parameter if the new/old apis are the same in everything other than param name
customfield.go
Outdated
func (h Hours) CustomFieldTag() string { | ||
return CUSTOMFIELDTYPE_HOURS | ||
} | ||
|
||
type DailyTimes struct { | ||
DailyTimes string `json:"dailyTimes,omitempty"` | ||
Sunday string `json:"sunday,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this wrong all along or a change in Entities?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a change in Entities...I copied over the old struct. same thing happened for hours. will figure out how to distinguish between the two
customfield_service.go
Outdated
@@ -531,6 +531,7 @@ func ParseCustomFields(cfraw map[string]interface{}, cfs []*CustomField) (map[st | |||
return parsed, nil | |||
} | |||
|
|||
// TODO: Can we do this anymore? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not, and it probably doesn't make sense. it was just to prevent the "obvious" mistake of passing in a string vs id. now we probably won't know until we send to the API (unless we validate against the field schema, but that is probably a new exposed method, not an automagic thing)
customfield_service_test.go
Outdated
@@ -42,11 +42,11 @@ func runParseTest(t *testing.T, index int, c customFieldParseTest) { | |||
) | |||
|
|||
if cfType != expectType { | |||
t.Errorf("test #%d (%s) failed: expected type %s, got type %s", index, c.TypeName, expectType, cfType) | |||
t.Errorf("test #%d (%s) failed:\nexpected type %s\ngot type %s", index, c.TypeName, expectType, cfType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i really hate how hard it is to format things in test output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the tabbing in particular
entity_service.go
Outdated
return nil, fmt.Errorf("Unable to find entityType attribute in %v", metaByKey) | ||
} | ||
|
||
entityObj, err := e.LookupEntity(EntityType(entityType.(string))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should think about what we want to happen if a type is NOT registered. for example, what if the caller knew they didn't know the types ahead of time and wanted to just inspect them as JSON/map[string]interface{}? we might want to let that through and not error out in some cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the other hand, i can also see it useful to know if you weren't able to unwrap the type, but maybe we find that our during type assertion?
entity_service.go
Outdated
// Convert into struct of Entity Type | ||
entityJSON, err := json.Marshal(entityValsByKey) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error marshaling entity to JSON: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't include "error" in error message or capitalize first word
entity_service.go
Outdated
|
||
err = json.Unmarshal(entityJSON, &entityObj) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error unmarshaling entity JSON: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
entity_service.go
Outdated
return buf.Bytes(), nil | ||
} | ||
|
||
func (e *EntityService) toEntityTypes(entityInterfaces []interface{}) ([]Entity, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is throughout the PR, but the param names are stuttering with their type... prefer shortened values or descriptions of the content without the type:
toEntityTypes(entities []interface{})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah....i had a hard time because both the word type and interface you can't use in go, so i prefixed them a lot. I'll try to clean it up a bit
entity_service.go
Outdated
return entities, nil | ||
} | ||
|
||
func (e *EntityService) toEntityType(entityInterface interface{}) (Entity, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly, toEntityType(entity interface{})
or toEntityType(e interface{})
customfield_service.go
Outdated
@@ -531,7 +531,6 @@ func ParseCustomFields(cfraw map[string]interface{}, cfs []*CustomField) (map[st | |||
return parsed, nil | |||
} | |||
|
|||
// TODO: Can we do this anymore? | |||
func validateCustomFieldsKeys(cfs map[string]interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could rename this to validateLocationCustomFields or something to indicate it is legacy
registry.go
Outdated
|
||
func (r Registry) Register(key string, val interface{}) { | ||
//From: https://github.com/reggo/reggo/blob/master/common/common.go#L169 | ||
isPtr := reflect.ValueOf(val).Kind() == reflect.Ptr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var (..) for all these
@@ -0,0 +1,22 @@ | |||
package yext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, could embed to get Meta "for free" without need to duplicate. it would also be a good deser target if you didn't know what you were going to get from the API - for example, if you hit the generic entities endpoint to return any and all entities (assuming that exists?)?
entity_test.go
Outdated
} | ||
|
||
func (l *CustomLocationEntity) Type() EntityType { | ||
return ENTITYTYPE_LOCATION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you mean on create? If its pulled from the API, it would always be populated for you, right?
error.go
Outdated
return &Error{Type: typ, Code: codeInt, Message: message}, nil | ||
} | ||
|
||
func ErrorsFromString(errorStr string) ([]*Error, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whew!
event.go
Outdated
@@ -0,0 +1,34 @@ | |||
package yext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
@@ -0,0 +1,148 @@ | |||
package yext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is CFT Asset a different service? can this be part of a unified AssetService?
@@ -0,0 +1,152 @@ | |||
package yext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly, isn't this just asset.go?
@@ -1,20 +1,11 @@ | |||
package yext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High level feedback discussed with @upalsaha:
- Maintain AssetService but rename it to LegacyAssetService
- Name the new service (with registry, entity and CFT support) AssetService
- Add a switch in NewClient() that decides what service to create based on the Version date - leave the other service
nil
cc @cdworak
ASSETTYPE_COMPLEXVIDEO AssetType = "complexVideo" | ||
) | ||
|
||
type CFTAsset struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per above, this would just be Asset - the old thing would become LegacyAsset
cftasset.go
Outdated
} | ||
|
||
func (a *AssetUsage) Equal(b Comparable) bool { | ||
defer func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this necessary?
customfield.go
Outdated
HolidayHours []HolidayHours `json:"holidayHours,omitempty"` | ||
// HoursCustom is the Hours custom field format used by locations API | ||
// Entities API uses the Hours struct in location_entities.go (profile and custom hours are defined the same way for entities) | ||
type HoursCustom struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we follow the other pattern, maybe LegacyHours?
b.nilIsEmpty = val | ||
} | ||
|
||
type RawEntity map[string]interface{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option is to do:
struct RawEntity {
Meta Meta
fields: map[string]interface
}
and implement json.Unmarshaler on it. then you wouldn't need to parse meta by hand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i like this
event.go
Outdated
@@ -0,0 +1,34 @@ | |||
package yext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump on removal
location_diff.go
Outdated
@@ -148,7 +150,7 @@ func isZeroValue(v reflect.Value, interpretNilAsZeroValue bool) bool { | |||
return isZeroValue(v.Elem(), interpretNilAsZeroValue) | |||
case reflect.Struct: | |||
for i, n := 0, v.NumField(); i < n; i++ { | |||
if !isZeroValue(v.Field(i), interpretNilAsZeroValue) { | |||
if !isZeroValue(v.Field(i), true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a change we want in location_diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(vs entity_diff)
location_entity.go
Outdated
|
||
func (y LocationEntity) SetLabelIds(v []string) { | ||
l := UnorderedStrings(v) | ||
y.SetLabelIdsWithUnorderedStrings(l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you inline the UnorderedStrings wrapper?
location_entity.go
Outdated
if y.LabelIds != nil { | ||
v = *y.LabelIds | ||
func (y LocationEntity) GetLabels() (v UnorderedStrings) { | ||
if y.BaseEntity.Meta.Labels != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably also move these functions under BaseEntity
J=PC-40957 TEST=compile
* Add NewHoursClosedAllWeek static method
- newer API versions return custom fields differently. This change will give some backwards compatibility J=PC-219314 TEST=manual
#301) * migrate custom field endpoint to optionally use the configuration endpoint J=CR-3126 TEST=auto * refactor: respond to dev comments J=CR-3126
J=none TEST=manual Co-authored-by: sseverance <[email protected]>
J=PC-234251 TEST=auto
J=PC-220346
J=PC-237814 TEST=manual
- https://yexttest.atlassian.net/browse/PB-21550 J=PC-233325 TEST=manual
…310) J=PC-240725 TEST=manual
J=PC-240487 TEST=manual Co-authored-by: Lilian Wang <[email protected]>
J=PC-244952
J=PC-244921 TEST=manual
J=none|TEST=manual
…endpoint to account for newer A (#315) J=PC-254056 TEST=manual
J=none|TEST=manual Co-authored-by: Peter Oliveira Soens <[email protected]>
This reverts commit d840ea0.
Co-authored-by: Stephanie Severance <[email protected]>
this isn't even really a pull request because it's not done, just so hup can see