Преглед изворни кода

search entity by id now using search by attribute as its' underlinng support.

master
Patrick Peng Sun пре 8 година
родитељ
комит
0ac81c9920
2 измењених фајлова са 29 додато и 22 уклоњено
  1. +28
    -22
      crmEntity.go
  2. +1
    -0
      crmEntity_test.go

+ 28
- 22
crmEntity.go Прегледај датотеку

return return
} }


filters := []crmdSearchFilter{
{"id", "equals", id},
}
cs, err := crmSearchEntity(entityType, filters)
if err != nil || cs.Total < 1 {
return
}
total, list, err := crmFindEntityByAttr(entityType, "id", id)


if cs.Total > 1 {
log.Printf("ERROR: more than one(%d) %s associated with %s", cs.Total, entityType, id)
if total > 1 {
log.Printf("ERROR: more than one(%d) %s associated with %s", total, entityType, id)
} }


if err != nil {
return
}
switch entityType { switch entityType {
case "Lead": case "Lead":
e := []crmdLead{}
err = json.Unmarshal(*cs.List, &e)
if (err != nil) || (len(e) != cs.Total) {
e, ok := list.([]crmdLead)
if (!ok) || (len(e) != total) {
return return
} }
entity = e[0] entity = e[0]
case "Livecast": case "Livecast":
e := []crmdLiveCast{}
err = json.Unmarshal(*cs.List, &e)
if (err != nil) || (len(e) != cs.Total) {
e, ok := list.([]crmdLiveCast)
if (!ok) || (len(e) != total) {
return return
} }
entity = e[0] entity = e[0]
case "Meeting": case "Meeting":
e := []crmdMeeting{}
err = json.Unmarshal(*cs.List, &e)
if (err != nil) || (len(e) != cs.Total) {
e, ok := list.([]crmdMeeting)
if (!ok) || (len(e) != total) {
return return
} }
entity = e[0] entity = e[0]
if err != nil || cs.Total < 1 { if err != nil || cs.Total < 1 {
return return
} }
total = cs.Total
return cs.toEntityList(entityType)
}

func (m crmdSearchResult) toEntityList(entityType string) (total int, list interface{}, err error) {
total = m.Total
switch entityType { switch entityType {
case "Lead": case "Lead":
e := []crmdLead{} e := []crmdLead{}
err = json.Unmarshal(*cs.List, &e)
err = json.Unmarshal(*m.List, &e)
list = e
case "Livecast":
e := []crmdLiveCast{}
err = json.Unmarshal(*m.List, &e)
list = e list = e
case "Account":
return


case "Meeting":
e := []crmdMeeting{}
err = json.Unmarshal(*m.List, &e)
list = e
default:
err = errors.New("unknown entity type " + entityType)
} }
return return
} }

+ 1
- 0
crmEntity_test.go Прегледај датотеку

e.Status = "New" e.Status = "New"
e.EmailAddress = "abc@gmail.com" e.EmailAddress = "abc@gmail.com"
e.WechatHitxyID = "someopenid" e.WechatHitxyID = "someopenid"
e.ForceDuplicate = true
b, _ := json.Marshal(e) b, _ := json.Marshal(e)
entity, err := crmCreateEntity("Lead", b) entity, err := crmCreateEntity("Lead", b)
if err != nil { if err != nil {

Loading…
Откажи
Сачувај