mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-12-04 18:56:08 +03:00
add new order field DialogID and fix custom fields marshaling
This commit is contained in:
parent
076ce77bdb
commit
0ed90e8351
@ -58,6 +58,30 @@ func (l *StringMap) UnmarshalJSON(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *CustomFieldMap) UnmarshalJSON(data []byte) error {
|
||||||
|
var i interface{}
|
||||||
|
var m CustomFieldMap
|
||||||
|
if err := json.Unmarshal(data, &i); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch e := i.(type) {
|
||||||
|
case map[string]interface{}:
|
||||||
|
m = make(CustomFieldMap, len(e))
|
||||||
|
for idx, val := range e {
|
||||||
|
m[idx] = val
|
||||||
|
}
|
||||||
|
case []interface{}:
|
||||||
|
m = make(CustomFieldMap, len(e))
|
||||||
|
for idx, val := range e {
|
||||||
|
m[strconv.Itoa(idx)] = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*l = m
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *OrderPayments) UnmarshalJSON(data []byte) error {
|
func (p *OrderPayments) UnmarshalJSON(data []byte) error {
|
||||||
var i interface{}
|
var i interface{}
|
||||||
var m OrderPayments
|
var m OrderPayments
|
||||||
|
@ -44,7 +44,7 @@ func TestAPIErrorsList_UnmarshalJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCustomFieldsList_UnmarshalJSON(t *testing.T) {
|
func TestCustomFieldsList_UnmarshalJSON(t *testing.T) {
|
||||||
var list StringMap
|
var list CustomFieldMap
|
||||||
|
|
||||||
require.NoError(t, json.Unmarshal([]byte(`["first", "second"]`), &list))
|
require.NoError(t, json.Unmarshal([]byte(`["first", "second"]`), &list))
|
||||||
assert.Len(t, list, 2)
|
assert.Len(t, list, 2)
|
||||||
@ -56,6 +56,13 @@ func TestCustomFieldsList_UnmarshalJSON(t *testing.T) {
|
|||||||
assert.Equal(t, list["a"], "first")
|
assert.Equal(t, list["a"], "first")
|
||||||
assert.Equal(t, list["b"], "second")
|
assert.Equal(t, list["b"], "second")
|
||||||
|
|
||||||
|
require.NoError(t, json.Unmarshal([]byte(`{"a": ["first", "second"], "b": "second"}`), &list))
|
||||||
|
assert.Len(t, list, 2)
|
||||||
|
assert.Len(t, list["a"].([]interface{}), 2)
|
||||||
|
assert.Equal(t, list["a"].([]interface{})[0], "first")
|
||||||
|
assert.Equal(t, list["a"].([]interface{})[1], "second")
|
||||||
|
assert.Equal(t, list["b"], "second")
|
||||||
|
|
||||||
require.NoError(t, json.Unmarshal([]byte(`[]`), &list))
|
require.NoError(t, json.Unmarshal([]byte(`[]`), &list))
|
||||||
assert.Len(t, list, 0)
|
assert.Len(t, list, 0)
|
||||||
}
|
}
|
||||||
|
12
types.go
12
types.go
@ -155,7 +155,7 @@ type Customer struct {
|
|||||||
BrowserID string `json:"browserId,omitempty"`
|
BrowserID string `json:"browserId,omitempty"`
|
||||||
MgCustomerID string `json:"mgCustomerId,omitempty"`
|
MgCustomerID string `json:"mgCustomerId,omitempty"`
|
||||||
PhotoURL string `json:"photoUrl,omitempty"`
|
PhotoURL string `json:"photoUrl,omitempty"`
|
||||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||||
Tags []Tag `json:"tags,omitempty"`
|
Tags []Tag `json:"tags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ type CorporateCustomer struct {
|
|||||||
CreatedAt string `json:"createdAt,omitempty"`
|
CreatedAt string `json:"createdAt,omitempty"`
|
||||||
Vip bool `json:"vip,omitempty"`
|
Vip bool `json:"vip,omitempty"`
|
||||||
Bad bool `json:"bad,omitempty"`
|
Bad bool `json:"bad,omitempty"`
|
||||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||||
PersonalDiscount float32 `json:"personalDiscount,omitempty"`
|
PersonalDiscount float32 `json:"personalDiscount,omitempty"`
|
||||||
DiscountCardNumber string `json:"discountCardNumber,omitempty"`
|
DiscountCardNumber string `json:"discountCardNumber,omitempty"`
|
||||||
ManagerID int `json:"managerId,omitempty"`
|
ManagerID int `json:"managerId,omitempty"`
|
||||||
@ -228,7 +228,7 @@ type Company struct {
|
|||||||
CreatedAt string `json:"createdAt,omitempty"`
|
CreatedAt string `json:"createdAt,omitempty"`
|
||||||
Contragent *Contragent `json:"contragent,omitempty"`
|
Contragent *Contragent `json:"contragent,omitempty"`
|
||||||
Address *IdentifiersPair `json:"address,omitempty"`
|
Address *IdentifiersPair `json:"address,omitempty"`
|
||||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CorporateCustomerNote type.
|
// CorporateCustomerNote type.
|
||||||
@ -287,6 +287,7 @@ Order related types
|
|||||||
|
|
||||||
type OrderPayments map[string]OrderPayment
|
type OrderPayments map[string]OrderPayment
|
||||||
type StringMap map[string]string
|
type StringMap map[string]string
|
||||||
|
type CustomFieldMap map[string]interface{}
|
||||||
type Properties map[string]Property
|
type Properties map[string]Property
|
||||||
|
|
||||||
// Order type.
|
// Order type.
|
||||||
@ -338,10 +339,11 @@ type Order struct {
|
|||||||
Delivery *OrderDelivery `json:"delivery,omitempty"`
|
Delivery *OrderDelivery `json:"delivery,omitempty"`
|
||||||
Marketplace *OrderMarketplace `json:"marketplace,omitempty"`
|
Marketplace *OrderMarketplace `json:"marketplace,omitempty"`
|
||||||
Items []OrderItem `json:"items,omitempty"`
|
Items []OrderItem `json:"items,omitempty"`
|
||||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||||
Payments OrderPayments `json:"payments,omitempty"`
|
Payments OrderPayments `json:"payments,omitempty"`
|
||||||
ApplyRound *bool `json:"applyRound,omitempty"`
|
ApplyRound *bool `json:"applyRound,omitempty"`
|
||||||
PrivilegeType string `json:"privilegeType,omitempty"`
|
PrivilegeType string `json:"privilegeType,omitempty"`
|
||||||
|
DialogID int `json:"dialogId,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrdersStatus type.
|
// OrdersStatus type.
|
||||||
@ -1342,7 +1344,7 @@ type LoyaltyAccount struct {
|
|||||||
ActivatedAt string `json:"activatedAt,omitempty"`
|
ActivatedAt string `json:"activatedAt,omitempty"`
|
||||||
ConfirmedPhoneAt string `json:"confirmedPhoneAt,omitempty"`
|
ConfirmedPhoneAt string `json:"confirmedPhoneAt,omitempty"`
|
||||||
LastCheckID int `json:"lastCheckId,omitempty"`
|
LastCheckID int `json:"lastCheckId,omitempty"`
|
||||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||||
Loyalty Loyalty `json:"loyalty,omitempty"`
|
Loyalty Loyalty `json:"loyalty,omitempty"`
|
||||||
Customer Customer `json:"customer,omitempty"`
|
Customer Customer `json:"customer,omitempty"`
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
|
Loading…
Reference in New Issue
Block a user