Skip to content
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

Open
wants to merge 290 commits into
base: v2
Choose a base branch
from
Open

Entities #58

wants to merge 290 commits into from

Conversation

cdworak
Copy link
Contributor

@cdworak cdworak commented Jul 18, 2018

this isn't even really a pull request because it's not done, just so hup can see

Copy link
Member

@mhupman mhupman left a 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
Copy link
Member

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
Copy link
Member

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"`
Copy link
Member

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?

Copy link
Contributor Author

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

@@ -531,6 +531,7 @@ func ParseCustomFields(cfraw map[string]interface{}, cfs []*CustomField) (map[st
return parsed, nil
}

// TODO: Can we do this anymore?
Copy link
Member

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)

@@ -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)
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tabbing in particular

return nil, fmt.Errorf("Unable to find entityType attribute in %v", metaByKey)
}

entityObj, err := e.LookupEntity(EntityType(entityType.(string)))
Copy link
Member

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?

Copy link
Member

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?

// 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)
Copy link
Member

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


err = json.Unmarshal(entityJSON, &entityObj)
if err != nil {
return nil, fmt.Errorf("Error unmarshaling entity JSON: %s", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

return buf.Bytes(), nil
}

func (e *EntityService) toEntityTypes(entityInterfaces []interface{}) ([]Entity, error) {
Copy link
Member

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{})

Copy link
Contributor Author

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

return entities, nil
}

func (e *EntityService) toEntityType(entityInterface interface{}) (Entity, error) {
Copy link
Member

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{})

@@ -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 {
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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() {
Copy link
Member

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 {
Copy link
Member

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{}
Copy link
Member

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

Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(vs entity_diff)


func (y LocationEntity) SetLabelIds(v []string) {
l := UnorderedStrings(v)
y.SetLabelIdsWithUnorderedStrings(l)
Copy link
Member

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?

if y.LabelIds != nil {
v = *y.LabelIds
func (y LocationEntity) GetLabels() (v UnorderedStrings) {
if y.BaseEntity.Meta.Labels != nil {
Copy link
Contributor Author

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

nirmalpatel94 and others added 30 commits July 18, 2023 14:31
- 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
…endpoint to account for newer A (#315)

J=PC-254056
TEST=manual
J=none|TEST=manual

Co-authored-by: Peter Oliveira Soens <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.