feat: refactoring.
This commit is contained in:
parent
2c765d9bfd
commit
5410765b3b
8 changed files with 48 additions and 38 deletions
11
amocrm.go
11
amocrm.go
|
@ -23,7 +23,6 @@ type Client struct {
|
|||
Api *api.Client
|
||||
}
|
||||
|
||||
//goland:noinspection GoUnusedExportedFunction
|
||||
func NewAmoClient(options *api.ClientOptions) (*Client, error) {
|
||||
apiClient, err := api.NewClient(options)
|
||||
if err != nil {
|
||||
|
@ -40,9 +39,9 @@ func (client *Client) updateEntity(url string, id int, body interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (client *Client) GetUser(userId string) (*users.User, error) {
|
||||
func (client *Client) GetUser(userId int) (*users.User, error) {
|
||||
user := new(users.User)
|
||||
err := client.Api.Get(fmt.Sprintf("/api/v4/users/%s", userId), user)
|
||||
err := client.Api.Get(fmt.Sprintf("/api/v4/users/%d", userId), user)
|
||||
return user, err
|
||||
}
|
||||
|
||||
|
@ -58,7 +57,7 @@ func (client *Client) GetLead(leadId string, query string) (*leads.Lead, error)
|
|||
}
|
||||
|
||||
func (client *Client) UpdateLead(lead *leads.Lead) error {
|
||||
return client.updateEntity("/api/v4/leads", lead.ID, lead)
|
||||
return client.updateEntity("/api/v4/leads", lead.Id, lead)
|
||||
}
|
||||
|
||||
func (client *Client) GetCompany(companyId string, query string) (*companies.Company, error) {
|
||||
|
@ -73,7 +72,7 @@ func (client *Client) GetCompany(companyId string, query string) (*companies.Com
|
|||
}
|
||||
|
||||
func (client *Client) UpdateCompany(company *companies.Company) error {
|
||||
return client.updateEntity("/api/v4/companies", company.ID, company)
|
||||
return client.updateEntity("/api/v4/companies", company.Id, company)
|
||||
}
|
||||
|
||||
func (client *Client) GetContact(contactId string, query string) (*contacts.Contact, error) {
|
||||
|
@ -88,5 +87,5 @@ func (client *Client) GetContact(contactId string, query string) (*contacts.Cont
|
|||
}
|
||||
|
||||
func (client *Client) UpdateContact(contact *contacts.Contact) error {
|
||||
return client.updateEntity("/api/v4/contacts", contact.ID, contact)
|
||||
return client.updateEntity("/api/v4/contacts", contact.Id, contact)
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@ package companies
|
|||
import "vultras.su/core/amo/common"
|
||||
|
||||
type Company struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ResponsibleUserID int `json:"responsible_user_id,omitempty"`
|
||||
GroupID int `json:"group_id,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"`
|
||||
AccountId int `json:"account_id,omitempty"`
|
||||
Links Links `json:"_links,omitempty"`
|
||||
Embedded Embedded `json:"_embedded,omitempty"`
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ type Links struct {
|
|||
}
|
||||
|
||||
type Contacts struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
}
|
||||
|
||||
type Embedded struct {
|
||||
|
|
|
@ -3,25 +3,25 @@ package contacts
|
|||
import "vultras.su/core/amo/common"
|
||||
|
||||
type Contact struct {
|
||||
ID int `json:"id"`
|
||||
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"`
|
||||
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"`
|
||||
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"`
|
||||
EnumId int `json:"enum_id"`
|
||||
Enum string `json:"enum"`
|
||||
}
|
||||
|
||||
|
@ -34,17 +34,17 @@ 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"`
|
||||
}
|
||||
|
||||
|
|
10
go.mod
10
go.mod
|
@ -1,8 +1,14 @@
|
|||
module vultras.su/core/amo
|
||||
|
||||
go 1.15
|
||||
go 1.21.3
|
||||
|
||||
require (
|
||||
github.com/gorilla/schema v1.2.0
|
||||
github.com/stretchr/testify v1.6.1
|
||||
vultras.su/core/bond v0.0.0-20240114204709-a9c2c8810682
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,7 +1,5 @@
|
|||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
|
||||
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
@ -11,3 +9,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
|
|||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
vultras.su/core/bond v0.0.0-20240114204709-a9c2c8810682 h1:NiT5kAwzjTO+C4/y2EyRI6N8DOl5YFLuyZEUqrYwfFE=
|
||||
vultras.su/core/bond v0.0.0-20240114204709-a9c2c8810682/go.mod h1:d8O5wwQlZrVAeoV7qIwxXabB9RuqgopP7wEyRl3++Tc=
|
||||
|
|
5
id.go
Normal file
5
id.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package amo
|
||||
|
||||
// Should use it later as an ID
|
||||
// for type safety in compilation time.
|
||||
type Id[V any] int64
|
|
@ -3,15 +3,15 @@ package leads
|
|||
import "vultras.su/core/amo/common"
|
||||
|
||||
type Lead struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Price int `json:"price,omitempty"`
|
||||
ResponsibleUserID int `json:"responsible_user_id,omitempty"`
|
||||
GroupID int `json:"group_id,omitempty"`
|
||||
StatusID int `json:"status_id,omitempty"`
|
||||
PipelineID int `json:"pipeline_id,omitempty"`
|
||||
LossReasonID int `json:"loss_reason_id,omitempty"`
|
||||
SourceID interface{} `json:"source_id,omitempty"`
|
||||
ResponsibleUserId int `json:"responsible_user_id,omitempty"`
|
||||
GroupId int `json:"group_id,omitempty"`
|
||||
StatusId int `json:"status_id,omitempty"`
|
||||
PipelineId int `json:"pipeline_id,omitempty"`
|
||||
LossReasonId int `json:"loss_reason_id,omitempty"`
|
||||
SourceId interface{} `json:"source_id,omitempty"`
|
||||
CreatedBy int `json:"created_by,omitempty"`
|
||||
UpdatedBy int `json:"updated_by,omitempty"`
|
||||
CreatedAt int `json:"created_at,omitempty"`
|
||||
|
@ -21,7 +21,7 @@ type Lead struct {
|
|||
IsDeleted bool `json:"is_deleted,omitempty"`
|
||||
CustomFieldsValues []*common.CustomFieldsValue `json:"custom_fields_values,omitempty"`
|
||||
Score interface{} `json:"score,omitempty"`
|
||||
AccountID int `json:"account_id,omitempty"`
|
||||
AccountId int `json:"account_id,omitempty"`
|
||||
IsPriceModifiedByRobot bool `json:"is_price_modified_by_robot,omitempty"`
|
||||
Links Links `json:"_links,omitempty"`
|
||||
Embedded Embedded `json:"_embedded,omitempty"`
|
||||
|
@ -36,22 +36,22 @@ type Links struct {
|
|||
}
|
||||
|
||||
type Tags struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
Quantity int `json:"quantity"`
|
||||
CatalogID int `json:"catalog_id"`
|
||||
CatalogId int `json:"catalog_id"`
|
||||
}
|
||||
|
||||
type CatalogElements struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
Metadata Metadata `json:"metadata"`
|
||||
}
|
||||
|
||||
type LossReason struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Sort int `json:"sort"`
|
||||
CreatedAt int `json:"created_at"`
|
||||
|
@ -60,12 +60,12 @@ type LossReason struct {
|
|||
}
|
||||
|
||||
type Companies struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
Links Links `json:"_links"`
|
||||
}
|
||||
|
||||
type Contacts struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
IsMain bool `json:"is_main"`
|
||||
Links Links `json:"_links"`
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package users
|
||||
|
||||
type User struct {
|
||||
ID int `json:"id"`
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Lang string `json:"lang"`
|
||||
|
|
Loading…
Reference in a new issue