add base logic for getting lists tags need mongo method update insert
This commit is contained in:
parent
b36a3e67b4
commit
fa11f63432
@ -1,10 +1,10 @@
|
|||||||
package data_updater
|
package data_updater
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"amocrm/internal/models/amo"
|
||||||
"amocrm/internal/repository"
|
"amocrm/internal/repository"
|
||||||
"amocrm/pkg/amoClient"
|
"amocrm/pkg/amoClient"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -75,16 +75,50 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
|||||||
wc.logger.Error("error update pipeline steps in mongo:", zap.Error(err))
|
wc.logger.Error("error update pipeline steps in mongo:", zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user, err := wc.repo.GetCurrentAccount(ctx, token.AccountID)
|
|
||||||
if err != nil {
|
var leadsTags []amo.Tag
|
||||||
wc.logger.Error("error getting user data from mongo")
|
var contactsTags []amo.Tag
|
||||||
}
|
var companiesTags []amo.Tag
|
||||||
userInfo, err := wc.amoClient.GetUserByID(token.AccessToken, user.Amocrmid)
|
var customersTags []amo.Tag
|
||||||
for _, tipe := range userInfo.Rights.StatusRights {
|
|
||||||
// todo понимать как когда нужно какой тип
|
entityTypes := []amo.EntityType{amo.LeadsTags, amo.ContactsTags, amo.CompaniesTags, amo.CustomersTags}
|
||||||
fmt.Println(tipe)
|
for _, entityType := range entityTypes {
|
||||||
|
page := 1
|
||||||
|
limit := 250
|
||||||
|
|
||||||
|
for {
|
||||||
|
req := amo.GetListTagsReq{
|
||||||
|
Page: page,
|
||||||
|
Limit: limit,
|
||||||
|
EntityType: entityType,
|
||||||
|
}
|
||||||
|
tags, err := wc.amoClient.GetListTags(req, token.AccessToken)
|
||||||
|
if err != nil {
|
||||||
|
wc.logger.Error("error getting list of tags", zap.Error(err))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
switch entityType {
|
||||||
|
case amo.LeadsTags:
|
||||||
|
leadsTags = append(leadsTags, tags.Embedded.Tags...)
|
||||||
|
case amo.ContactsTags:
|
||||||
|
contactsTags = append(contactsTags, tags.Embedded.Tags...)
|
||||||
|
case amo.CompaniesTags:
|
||||||
|
companiesTags = append(companiesTags, tags.Embedded.Tags...)
|
||||||
|
case amo.CustomersTags:
|
||||||
|
customersTags = append(customersTags, tags.Embedded.Tags...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tags.Embedded.Tags) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
page++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo вставка списков в монгу то есть апдейт
|
||||||
|
|
||||||
// todo fields
|
// todo fields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ func (a *Amo) GetListFields(req amo2.GetListFieldsReq, url string) (*amo2.Respon
|
|||||||
|
|
||||||
// https://www.amocrm.ru/developers/content/crm_platform/tags-api#%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA-%D1%82%D0%B5%D0%B3%D0%BE%D0%B2-%D0%B4%D0%BB%D1%8F-%D1%81%D1%83%D1%89%D0%BD%D0%BE%D1%81%D1%82%D0%B8
|
// https://www.amocrm.ru/developers/content/crm_platform/tags-api#%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA-%D1%82%D0%B5%D0%B3%D0%BE%D0%B2-%D0%B4%D0%BB%D1%8F-%D1%81%D1%83%D1%89%D0%BD%D0%BE%D1%81%D1%82%D0%B8
|
||||||
// GET /api/v4/{entity_type:leads|contacts|companies|customers}/tags
|
// GET /api/v4/{entity_type:leads|contacts|companies|customers}/tags
|
||||||
func (a *Amo) GetListTags(req amo2.GetListTagsReq) (*amo2.ResponseGetListTags, error) {
|
func (a *Amo) GetListTags(req amo2.GetListTagsReq, accessToken string) (*amo2.ResponseGetListTags, error) {
|
||||||
for {
|
for {
|
||||||
if a.rateLimiter.Check() {
|
if a.rateLimiter.Check() {
|
||||||
fullURL := fmt.Sprintf("%s/api/v4/%s/tags?", a.baseApiURL, req.EntityType)
|
fullURL := fmt.Sprintf("%s/api/v4/%s/tags?", a.baseApiURL, req.EntityType)
|
||||||
@ -251,6 +251,7 @@ func (a *Amo) GetListTags(req amo2.GetListTagsReq) (*amo2.ResponseGetListTags, e
|
|||||||
fullURL += fmt.Sprintf("&page=%d&limit=%d", req.Page, req.Limit)
|
fullURL += fmt.Sprintf("&page=%d&limit=%d", req.Page, req.Limit)
|
||||||
|
|
||||||
agent := a.fiberClient.Get(fullURL)
|
agent := a.fiberClient.Get(fullURL)
|
||||||
|
agent.Set("Authorization", "Bearer "+accessToken)
|
||||||
statusCode, resBody, errs := agent.Bytes()
|
statusCode, resBody, errs := agent.Bytes()
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
|
Loading…
Reference in New Issue
Block a user