Исправил модели данных

This commit is contained in:
Dmitry Dmitriev 2020-12-28 09:38:40 +03:00
parent ede7b6cbde
commit eb1ceef1e5
5 changed files with 109 additions and 12 deletions

View file

@ -3,7 +3,10 @@ package amo
import (
"fmt"
"github.com/qdimka/go-amo/api"
"github.com/qdimka/go-amo/models"
"github.com/qdimka/go-amo/models/companies"
"github.com/qdimka/go-amo/models/contacts"
"github.com/qdimka/go-amo/models/leads"
"github.com/qdimka/go-amo/models/users"
)
type AmoClient struct {
@ -21,8 +24,8 @@ func NewAmoClient(options *api.ClientOptions) (*AmoClient, error) {
}, nil
}
func (client *AmoClient) GetLead(leadId string, query string) (*models.Lead, error) {
deal := new(models.Lead)
func (client *AmoClient) GetLead(leadId string, query string) (*leads.Lead, error) {
deal := new(leads.Lead)
resource := fmt.Sprintf("/api/v4/leads/%s", leadId)
if len(query) != 0 {
resource = resource + "?" + query
@ -32,19 +35,19 @@ func (client *AmoClient) GetLead(leadId string, query string) (*models.Lead, err
return deal, err
}
func (client *AmoClient) GetUser(userId string) (*models.User, error) {
user := new(models.User)
func (client *AmoClient) GetUser(userId string) (*users.User, error) {
user := new(users.User)
err := client.api.Get(fmt.Sprintf("/api/v4/users/%s", userId), user)
return user, err
}
func (client *AmoClient) UpdateLead(lead *models.Lead) error {
func (client *AmoClient) UpdateLead(lead *leads.Lead) error {
err := client.api.Patch(fmt.Sprintf("/api/v4/leads/%d", lead.ID), lead, nil)
return err
}
func (client *AmoClient) GetCompany(companyId string, query string) (*models.Lead, error) {
deal := new(models.Lead)
func (client *AmoClient) GetCompany(companyId string, query string) (*companies.Company, error) {
deal := new(companies.Company)
resource := fmt.Sprintf("/api/v4/companies/%s", companyId)
if len(query) != 0 {
resource = resource + "?" + query
@ -54,8 +57,8 @@ func (client *AmoClient) GetCompany(companyId string, query string) (*models.Lea
return deal, err
}
func (client *AmoClient) GetContact(contactId string, query string) (*models.Lead, error) {
deal := new(models.Lead)
func (client *AmoClient) GetContact(contactId string, query string) (*contacts.Contact, error) {
deal := new(contacts.Contact)
resource := fmt.Sprintf("/api/v4/contacts/%s", contactId)
if len(query) != 0 {
resource = resource + "?" + query

View file

@ -0,0 +1,38 @@
package companies
type Company struct {
ID int `json:"id"`
Name string `json:"name"`
ResponsibleUserID int `json:"responsible_user_id"`
GroupID int `json:"group_id"`
CreatedBy int `json:"created_by"`
UpdatedBy int `json:"updated_by"`
CreatedAt int `json:"created_at"`
UpdatedAt int `json:"updated_at"`
ClosestTaskAt interface{} `json:"closest_task_at"`
CustomFieldsValues []CustomFieldsValues `json:"custom_fields_values"`
AccountID int `json:"account_id"`
Links Links `json:"_links"`
Embedded Embedded `json:"_embedded"`
}
type Values struct {
Value string `json:"value"`
EnumID int `json:"enum_id"`
Enum string `json:"enum"`
}
type CustomFieldsValues struct {
FieldID int `json:"field_id"`
FieldName string `json:"field_name"`
FieldCode string `json:"field_code"`
FieldType string `json:"field_type"`
Values []Values `json:"values"`
}
type Self struct {
Href string `json:"href"`
}
type Links struct {
Self Self `json:"self"`
}
type Embedded struct {
Tags []interface{} `json:"tags"`
}

View file

@ -0,0 +1,56 @@
package contacts
type Contact struct {
ID int `json:"id"`
Name string `json:"name"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
ResponsibleUserID int `json:"responsible_user_id"`
GroupID int `json:"group_id"`
CreatedBy int `json:"created_by"`
UpdatedBy int `json:"updated_by"`
CreatedAt int `json:"created_at"`
UpdatedAt int `json:"updated_at"`
ClosestTaskAt interface{} `json:"closest_task_at"`
CustomFieldsValues []CustomFieldsValues `json:"custom_fields_values"`
AccountID int `json:"account_id"`
Links Links `json:"_links"`
Embedded Embedded `json:"_embedded"`
}
type Values struct {
Value string `json:"value"`
EnumID int `json:"enum_id"`
Enum string `json:"enum"`
}
type CustomFieldsValues struct {
FieldID int `json:"field_id"`
FieldName string `json:"field_name"`
FieldCode string `json:"field_code"`
FieldType string `json:"field_type"`
Values []Values `json:"values"`
}
type Self struct {
Href string `json:"href"`
}
type Links struct {
Self Self `json:"self"`
}
type Leads struct {
ID int `json:"id"`
Links Links `json:"_links"`
}
type Customers struct {
ID int `json:"id"`
Links Links `json:"_links"`
}
type Companies struct {
ID int `json:"id"`
Links Links `json:"_links"`
}
type Embedded struct {
Tags []interface{} `json:"tags"`
Leads []Leads `json:"leads"`
Customers []Customers `json:"customers"`
CatalogElements []interface{} `json:"catalog_elements"`
Companies []Companies `json:"companies"`
}

View file

@ -1,4 +1,4 @@
package models
package leads
type Lead struct {
ID int `json:"id"`

View file

@ -1,4 +1,4 @@
package models
package users
type User struct {
ID int `json:"id"`