From ab6d5fb1183873e4a8c95d8acfbfa8020cc39e87 Mon Sep 17 00:00:00 2001 From: surdeus Date: Thu, 30 May 2024 17:42:47 +0500 Subject: [PATCH] feat: added the GetValuesByID for CustomFieldsValues. --- common/common.go | 16 +++++++++++++- companies/companies.go | 2 +- contacts/contacts.go | 50 +++++++++++++++++++++--------------------- leads/leads.go | 2 +- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/common/common.go b/common/common.go index d56192e..2140659 100644 --- a/common/common.go +++ b/common/common.go @@ -1,7 +1,7 @@ package common type Values struct { - Value interface{} `json:"value,omitempty"` + Value any `json:"value,omitempty"` EnumID int `json:"enum_id,omitempty"` Enum string `json:"enum,omitempty"` } @@ -12,3 +12,17 @@ type CustomFieldsValue struct { FieldType string `json:"field_type,omitempty"` Values []Values `json:"values"` } + +type CustomFieldsValues []CustomFieldsValue + +func (vs CustomFieldsValues) GetValuesByID( + id int, +) ([]Values, bool) { + for _, v := range vs { + if v.FieldID == id { + return v.Values, true + } + } + return nil, false +} + diff --git a/companies/companies.go b/companies/companies.go index 688c158..72fbe14 100644 --- a/companies/companies.go +++ b/companies/companies.go @@ -12,7 +12,7 @@ type Company struct { CreatedAt int `json:"created_at,omitempty"` UpdatedAt int `json:"updated_at,omitempty"` ClosestTaskAt interface{} `json:"closest_task_at,omitempty"` - CustomFieldsValues []common.CustomFieldsValue `json:"custom_fields_values,omitempty"` + CustomFieldsValues common.CustomFieldsValues `json:"custom_fields_values,omitempty"` AccountID int `json:"account_id,omitempty"` Links Links `json:"_links,omitempty"` Embedded Embedded `json:"_embedded,omitempty"` diff --git a/contacts/contacts.go b/contacts/contacts.go index bdea6eb..ef7424d 100644 --- a/contacts/contacts.go +++ b/contacts/contacts.go @@ -3,26 +3,26 @@ package contacts import "surdeus.su/core/amo/common" type Contact struct { - Id int `json:"id"` - Name string `json:"name,omitempty"` - FirstName string `json:"first_name,omitempty"` - LastName string `json:"last_name,omitempty"` - ResponsibleUserId int `json:"responsible_user_id,omitempty"` - GroupId int `json:"group_id,omitempty"` - CreatedBy int `json:"created_by,omitempty"` - UpdatedBy int `json:"updated_by,omitempty"` - CreatedAt int `json:"created_at,omitempty"` - UpdatedAt int `json:"updated_at,omitempty"` - ClosestTaskAt interface{} `json:"closest_task_at,omitempty"` - CustomFieldsValues []common.CustomFieldsValue `json:"custom_fields_values,omitempty"` - AccountId int `json:"account_id,omitempty"` - Links Links `json:"_links,omitempty"` - Embedded Embedded `json:"_embedded,omitempty"` + Id int `json:"id"` + Name string `json:"name,omitempty"` + FirstName string `json:"first_name,omitempty"` + LastName string `json:"last_name,omitempty"` + ResponsibleUserId int `json:"responsible_user_id,omitempty"` + GroupId int `json:"group_id,omitempty"` + CreatedBy int `json:"created_by,omitempty"` + UpdatedBy int `json:"updated_by,omitempty"` + CreatedAt int `json:"created_at,omitempty"` + UpdatedAt int `json:"updated_at,omitempty"` + ClosestTaskAt interface{} `json:"closest_task_at,omitempty"` + CustomFieldsValues common.CustomFieldsValues `json:"custom_fields_values,omitempty"` + AccountId int `json:"account_id,omitempty"` + Links Links `json:"_links,omitempty"` + Embedded Embedded `json:"_embedded,omitempty"` } type Values struct { - Value string `json:"value"` - EnumId int `json:"enum_id"` - Enum string `json:"enum"` + Value string `json:"value"` + EnumId int `json:"enum_id"` + Enum string `json:"enum"` } type Self struct { @@ -34,24 +34,24 @@ type Links struct { } type Leads struct { - Id int `json:"id"` + Id int `json:"id"` Links Links `json:"_links"` } type Customers struct { - Id int `json:"id"` + Id int `json:"id"` Links Links `json:"_links"` } type Companies struct { - Id int `json:"id"` + Id int `json:"id"` Links Links `json:"_links"` } type Embedded struct { - Tags []interface{} `json:"tags"` - Leads []Leads `json:"leads"` - Customers []Customers `json:"customers"` + Tags []interface{} `json:"tags"` + Leads []Leads `json:"leads"` + Customers []Customers `json:"customers"` CatalogElements []interface{} `json:"catalog_elements"` - Companies []Companies `json:"companies"` + Companies []Companies `json:"companies"` } diff --git a/leads/leads.go b/leads/leads.go index 345986c..236cffc 100644 --- a/leads/leads.go +++ b/leads/leads.go @@ -19,7 +19,7 @@ type Lead struct { ClosedAt int `json:"closed_at,omitempty"` ClosestTaskAt interface{} `json:"closest_task_at,omitempty"` IsDeleted bool `json:"is_deleted,omitempty"` - CustomFieldsValues []common.CustomFieldsValue `json:"custom_fields_values,omitempty"` + CustomFieldsValues common.CustomFieldsValues `json:"custom_fields_values,omitempty"` Score interface{} `json:"score,omitempty"` AccountID int `json:"account_id,omitempty"` IsPriceModifiedByRobot bool `json:"is_price_modified_by_robot,omitempty"`