Conversation
mhupman
left a comment
There was a problem hiding this comment.
nice start! i agree the Register/Unwrap might need some tweaking, but only usage will tell for sure
| u, err := url.Parse(requrl) | ||
| if err != nil { | ||
| return "", nil | ||
| return "", err |
client.go
Outdated
| 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.
:(
maybe the func could take another parameter if the new/old apis are the same in everything other than param name
customfield.go
Outdated
|
|
||
| type DailyTimes struct { | ||
| DailyTimes string `json:"dailyTimes,omitempty"` | ||
| Sunday string `json:"sunday,omitempty"` |
There was a problem hiding this comment.
was this wrong all along or a change in Entities?
There was a problem hiding this comment.
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
| return parsed, nil | ||
| } | ||
|
|
||
| // TODO: Can we do this anymore? |
There was a problem hiding this comment.
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
|
|
||
| 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.
i really hate how hard it is to format things in test output
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.
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.
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.
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) |
entity_service.go
Outdated
| return buf.Bytes(), nil | ||
| } | ||
|
|
||
| func (e *EntityService) toEntityTypes(entityInterfaces []interface{}) ([]Entity, error) { |
There was a problem hiding this comment.
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.
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.
similarly, toEntityType(entity interface{}) or toEntityType(e interface{})
customfield_service.go
Outdated
| } | ||
|
|
||
| // TODO: Can we do this anymore? | ||
| func validateCustomFieldsKeys(cfs map[string]interface{}) error { |
There was a problem hiding this comment.
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 |
| @@ -0,0 +1,22 @@ | |||
| package yext | |||
There was a problem hiding this comment.
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.
Oh, you mean on create? If its pulled from the API, it would always be populated for you, right?
| return &Error{Type: typ, Code: codeInt, Message: message}, nil | ||
| } | ||
|
|
||
| func ErrorsFromString(errorStr string) ([]*Error, error) { |
event.go
Outdated
| @@ -0,0 +1,34 @@ | |||
| package yext | |||
| @@ -0,0 +1,148 @@ | |||
| package yext | |||
There was a problem hiding this comment.
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.
similarly, isn't this just asset.go?
| @@ -1,20 +1,11 @@ | |||
| package yext | |||
There was a problem hiding this comment.
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.
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() { |
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.
if we follow the other pattern, maybe LegacyHours?
| b.nilIsEmpty = val | ||
| } | ||
|
|
||
| type RawEntity map[string]interface{} |
There was a problem hiding this comment.
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
event.go
Outdated
| @@ -0,0 +1,34 @@ | |||
| package yext | |||
location_diff.go
Outdated
| 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.
is this a change we want in location_diff
location_entity.go
Outdated
|
|
||
| func (y LocationEntity) SetLabelIds(v []string) { | ||
| l := UnorderedStrings(v) | ||
| y.SetLabelIdsWithUnorderedStrings(l) |
There was a problem hiding this comment.
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.
we should probably also move these functions under BaseEntity
* Add NewHoursClosedAllWeek static method
J=none TEST=manual Co-authored-by: sseverance <sseverance@yext.com>
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 <lwang@yext.com>
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 <poliveirasoens@yext.com>
This reverts commit d840ea0.
Co-authored-by: Stephanie Severance <sseverance@yext.com>
…s to set the type correctly (#329) J=PC-270239 TEST=manual
fix command
this isn't even really a pull request because it's not done, just so hup can see