From 7583137585f53c50ab211786ecd2e79dbb6e20ca Mon Sep 17 00:00:00 2001 From: surdeus Date: Fri, 31 May 2024 16:06:01 +0500 Subject: [PATCH] feat: leads: added GetMain(). --- leads/leads.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/leads/leads.go b/leads/leads.go index 236cffc..8969850 100644 --- a/leads/leads.go +++ b/leads/leads.go @@ -64,16 +64,27 @@ type Companies struct { Links Links `json:"_links"` } -type Contacts struct { + +type Contact struct { ID int `json:"id"` IsMain bool `json:"is_main"` Links Links `json:"_links"` } +type Contacts []Contact + +func (cs Contacts) GetMain() (Contact, bool) { + for _, contact := range cs { + if contact.IsMain { + return contact, true + } + } + return Contact{}, false +} type Embedded struct { Tags []*Tags `json:"tags"` CatalogElements []*CatalogElements `json:"catalog_elements"` LossReason []*LossReason `json:"loss_reason"` Companies []*Companies `json:"companies"` - Contacts []*Contacts `json:"contacts"` + Contacts Contacts `json:"contacts"` }