postgres prepare
This commit is contained in:
parent
29222e8f23
commit
37cd008dab
2
go.mod
2
go.mod
@ -10,7 +10,7 @@ require (
|
||||
go.mongodb.org/mongo-driver v1.14.0
|
||||
go.uber.org/zap v1.27.0
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240409160049-5136009e944d
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240417121939-5bc95d6c6160
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af
|
||||
)
|
||||
|
||||
|
6
go.sum
6
go.sum
@ -112,5 +112,11 @@ penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240409160049-5136009e944d h1:oSUk1641wEUviO6w1/5h6OxJOAo+N4aT/jMvoYr7+vo=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240409160049-5136009e944d/go.mod h1:/DcyAjBh41IbomuDu5QzhL9flZW6lWO3ZAEbUXKobk0=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240417093019-b73bae196662 h1:VHtXkmKQx4xo7qyVICcMYB+2Ssw6Qw74WTDEi1SdjgA=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240417093019-b73bae196662/go.mod h1:/DcyAjBh41IbomuDu5QzhL9flZW6lWO3ZAEbUXKobk0=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240417120101-7e817cf088ee h1:oZKOn1wtgVdUqFarcIHQyWC4oYGpHv8WgcU/S/stjFk=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240417120101-7e817cf088ee/go.mod h1:/DcyAjBh41IbomuDu5QzhL9flZW6lWO3ZAEbUXKobk0=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240417121939-5bc95d6c6160 h1:R1m7D8AuzHUH9vMmGrD12PqPx+A8qnD0OScTJDRSDdc=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240417121939-5bc95d6c6160/go.mod h1:/DcyAjBh41IbomuDu5QzhL9flZW6lWO3ZAEbUXKobk0=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=
|
||||
|
@ -3,7 +3,6 @@ package app
|
||||
import (
|
||||
"amocrm/internal/controllers"
|
||||
"amocrm/internal/initialize"
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/internal/server/http"
|
||||
"amocrm/internal/service"
|
||||
"amocrm/internal/workers/data_updater"
|
||||
@ -13,6 +12,7 @@ import (
|
||||
pena_social_auth "amocrm/pkg/pena-social-auth"
|
||||
"context"
|
||||
"errors"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
|
||||
"time"
|
||||
|
||||
@ -33,9 +33,9 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro
|
||||
|
||||
shutdownGroup := closer.NewCloserGroup()
|
||||
|
||||
mdb, err := initialize.MongoDB(ctx, config)
|
||||
amoRepo, err := dal.NewAmoDal(ctx, config.PostgresCredentials)
|
||||
if err != nil {
|
||||
logger.Error("failed initialize mongo")
|
||||
logger.Error("error init amo repo in common repo", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -60,19 +60,8 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro
|
||||
RateLimiter: rateLimiter,
|
||||
})
|
||||
|
||||
repo := repository.NewRepository(repository.Deps{
|
||||
MdbUser: mdb.Collection("amoUsers"),
|
||||
Tokens: mdb.Collection("tokens"),
|
||||
Pipelines: mdb.Collection("pipelines"),
|
||||
Steps: mdb.Collection("steps"),
|
||||
Tags: mdb.Collection("tags"),
|
||||
Fields: mdb.Collection("fields"),
|
||||
UTMs: mdb.Collection("utms"),
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
svc := service.NewService(service.Deps{
|
||||
Repository: repo,
|
||||
Repository: amoRepo,
|
||||
Logger: logger,
|
||||
SocialAuthClient: socialAithClient,
|
||||
AmoClient: amoClient,
|
||||
@ -85,13 +74,13 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro
|
||||
})
|
||||
|
||||
tokenUpdater := tokens.NewRefreshWC(tokens.Deps{
|
||||
Repo: repo,
|
||||
Repo: amoRepo,
|
||||
AmoClient: amoClient,
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
dataUpdater := data_updater.NewDataUpdaterWC(data_updater.Deps{
|
||||
Repo: repo,
|
||||
Repo: amoRepo,
|
||||
AmoClient: amoClient,
|
||||
Logger: logger,
|
||||
})
|
||||
@ -115,7 +104,7 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro
|
||||
server.ListRoutes()
|
||||
|
||||
shutdownGroup.Add(closer.CloserFunc(server.Shutdown))
|
||||
shutdownGroup.Add(closer.CloserFunc(mdb.Client().Disconnect))
|
||||
shutdownGroup.Add(closer.CloserFunc(amoRepo.Close))
|
||||
shutdownGroup.Add(closer.CloserFunc(rateLimiter.Stop))
|
||||
shutdownGroup.Add(closer.CloserFunc(tokenUpdater.Stop))
|
||||
shutdownGroup.Add(closer.CloserFunc(dataUpdater.Stop))
|
||||
|
@ -1,12 +1,12 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func extractParams(ctx *fiber.Ctx) (*models.PaginationReq, error) {
|
||||
func extractParams(ctx *fiber.Ctx) (*model.PaginationReq, error) {
|
||||
pageStr := ctx.Query("page")
|
||||
sizeStr := ctx.Query("size")
|
||||
|
||||
@ -20,7 +20,7 @@ func extractParams(ctx *fiber.Ctx) (*models.PaginationReq, error) {
|
||||
return nil, ctx.Status(fiber.StatusBadRequest).SendString("Invalid size parameter")
|
||||
}
|
||||
|
||||
req := models.PaginationReq{
|
||||
req := model.PaginationReq{
|
||||
Page: page,
|
||||
Size: size,
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
||||
@ -11,7 +11,7 @@ func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
var request model.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
@ -30,7 +30,7 @@ func (c *Controller) SetQuizSettings(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
var request model.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -13,7 +13,7 @@ func (c *Controller) DeletingUserUtm(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
var request models.ListDeleteUTMIDsReq
|
||||
var request model.ListDeleteUTMIDsReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
@ -40,7 +40,7 @@ func (c *Controller) SavingUserUtm(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("failed convert quizID to int")
|
||||
}
|
||||
|
||||
var request models.SaveUserListUTMReq
|
||||
var request model.SaveUserListUTMReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
@ -1,17 +1,12 @@
|
||||
package initialize
|
||||
|
||||
type Config struct {
|
||||
AppName string `env:"APP_NAME" envDefault:"amocrm"`
|
||||
HTTPHost string `env:"HTTP_HOST" envDefault:"localhost"`
|
||||
HTTPPort string `env:"HTTP_PORT" envDefault:"3000"`
|
||||
MongoHost string `env:"MONGO_HOST" envDefault:"127.0.0.1"`
|
||||
MongoPort string `env:"MONGO_PORT" envDefault:"27020"`
|
||||
MongoUser string `env:"MONGO_USER" envDefault:"test"`
|
||||
MongoPassword string `env:"MONGO_PASSWORD" envDefault:"test"`
|
||||
MongoDatabase string `env:"MONGO_DB" envDefault:"admin"`
|
||||
MongoAuth string `env:"MONGO_AUTH" envDefault:"admin"`
|
||||
PubKey string `env:"PUBLIC_KEY"`
|
||||
PrivKey string `env:"PRIVATE_KEY"`
|
||||
AppName string `env:"APP_NAME" envDefault:"amocrm"`
|
||||
HTTPHost string `env:"HTTP_HOST" envDefault:"localhost"`
|
||||
HTTPPort string `env:"HTTP_PORT" envDefault:"3000"`
|
||||
PostgresCredentials string `env:"PG_CRED" envDefault:"host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
PubKey string `env:"PUBLIC_KEY"`
|
||||
PrivKey string `env:"PRIVATE_KEY"`
|
||||
// урл в соц аус сервисе для генерации ссылки для авторизации в амо
|
||||
PenaSocialAuthURL string `env:"PENA_SOCIAL_AUTH_URL"`
|
||||
// урл на который будет возвращен пользователь после авторизации это webhook/create get
|
||||
|
@ -1,39 +0,0 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
mdb "penahub.gitlab.yandexcloud.net/backend/penahub_common/mongo"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MongoDB(ctx context.Context, cfg Config) (*mongo.Database, error) {
|
||||
dbConfig := &mdb.Configuration{
|
||||
Host: cfg.MongoHost,
|
||||
Port: cfg.MongoPort,
|
||||
User: cfg.MongoUser,
|
||||
Password: cfg.MongoPassword,
|
||||
DatabaseName: cfg.MongoDatabase,
|
||||
Auth: cfg.MongoAuth,
|
||||
}
|
||||
|
||||
newCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
mongoDeps := &mdb.ConnectDeps{
|
||||
Configuration: dbConfig,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
db, err := mdb.Connect(newCtx, mongoDeps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = db.Client().Ping(newCtx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package amo
|
||||
package models
|
||||
|
||||
type CreateWebHookReq struct {
|
||||
ClientID string `json:"client_id"` // id интеграции
|
@ -1,26 +0,0 @@
|
||||
package models
|
||||
|
||||
import "amocrm/internal/models/amo"
|
||||
|
||||
type Field struct {
|
||||
/* - айдишник в нашей системе Primary Key*/
|
||||
ID int `json:"ID"`
|
||||
/* - айдишник кастомного поля в амо*/
|
||||
Amoid int `json:"AmoID"`
|
||||
/* - кодовое слово в амо*/
|
||||
Code string `json:"Code"`
|
||||
/* - связь с аккаунтом в интеграции амо id аккаунта в амо*/
|
||||
Accountid int `json:"AccountID"`
|
||||
/* - название воронки в амо*/
|
||||
Name string `json:"Name"`
|
||||
/* - тип сущности в амо, для которой это кастомное поле*/
|
||||
Entity amo.EntityType `json:"Entity"`
|
||||
/* - тип поля https://www.amocrm.ru/developers/content/crm_platform/custom-fields#%D0%94%D0%BE%D1%81%D1%82%D1%83%D0%BF%D0%BD%D1%8B%D0%B5-%D1%82%D0%B8%D0%BF%D1%8B-%D0%BF%D0%BE%D0%BB%D0%B5%D0%B9*/
|
||||
Type string `json:"Type"`
|
||||
/* - флаг мягкого удаления*/
|
||||
Deleted bool `json:"Deleted"`
|
||||
/* - таймштамп создания воронки в нашей системе*/
|
||||
Createdat int64 `json:"CreatedAt"`
|
||||
// время обновления
|
||||
UpdateAt int64 `json:"UpdateAt"`
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package models
|
||||
|
||||
type FieldRule struct {
|
||||
/* - сопоставление айдишника вопроса полю, которое будет заполняться ответом. соответственно QuestionID это айдишник вопроса. это я так мэпу пытался записать*/
|
||||
Questionid map[int]int `json:"QuestionID"` // ключ id вопроса значение id астомного поля
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
package amo
|
||||
package models
|
||||
|
||||
import (
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
type GetListFieldsReq struct {
|
||||
Page int `json:"page"`
|
||||
Limit int `json:"limit"`
|
||||
//Filter []string `json:"filter"` // пока не понял что это может быть
|
||||
EntityType EntityType `json:"entityType"`
|
||||
EntityType model.EntityType `json:"entityType"`
|
||||
}
|
||||
|
||||
type ResponseGetListFields struct {
|
@ -1,4 +1,4 @@
|
||||
package amo
|
||||
package models
|
||||
|
||||
type PipelineResponse struct {
|
||||
TotalItems int `json:"_total_items"`
|
@ -1,4 +1,4 @@
|
||||
package amo
|
||||
package models
|
||||
|
||||
type ResponseGetListSteps struct {
|
||||
TotalItems int `json:"_total_items"`
|
@ -1,10 +1,14 @@
|
||||
package amo
|
||||
package models
|
||||
|
||||
import (
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
type GetListTagsReq struct {
|
||||
Page int `json:"page"`
|
||||
Limit int `json:"limit"`
|
||||
Filter Filter `json:"filter"`
|
||||
EntityType EntityType `json:"entityType"`
|
||||
Page int `json:"page"`
|
||||
Limit int `json:"limit"`
|
||||
Filter Filter `json:"filter"`
|
||||
EntityType model.EntityType `json:"entityType"`
|
||||
}
|
||||
|
||||
type Filter struct {
|
||||
@ -13,15 +17,6 @@ type Filter struct {
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
type EntityType string
|
||||
|
||||
const (
|
||||
LeadsTags EntityType = "leads"
|
||||
ContactsTags EntityType = "contacts"
|
||||
CompaniesTags EntityType = "companies"
|
||||
CustomersTags EntityType = "customers"
|
||||
)
|
||||
|
||||
type ResponseGetListTags struct {
|
||||
Page int `json:"_page"`
|
||||
Links Links `json:"_links"`
|
@ -1,4 +1,4 @@
|
||||
package amo
|
||||
package models
|
||||
|
||||
type RequestGetListUsers struct {
|
||||
Page int
|
@ -1,20 +0,0 @@
|
||||
package models
|
||||
|
||||
type Pipeline struct {
|
||||
// айдишник в нашей системе Primary Key
|
||||
ID int `json:"ID"`
|
||||
/* - айдишник воронки в амо*/
|
||||
Amoid int `json:"AmoID"`
|
||||
/* - связь с аккаунтом в интеграции амо id аккаунта в амо*/
|
||||
AccountID int `json:"AccountID"`
|
||||
/* - название воронки в амо*/
|
||||
Name string `json:"Name"`
|
||||
/* - флаг архивной воронки в амо*/
|
||||
Isarchive bool `json:"IsArchive"`
|
||||
/* - флаг мягкого удаления*/
|
||||
Deleted bool `json:"Deleted"`
|
||||
/* - таймштамп создания воронки в нашей системе*/
|
||||
Createdat int64 `json:"CreatedAt"`
|
||||
// время обновления
|
||||
UpdateAt int64 `json:"UpdateAt"`
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package models
|
||||
|
||||
type ListDeleteUTMIDsReq struct {
|
||||
/* - список айдишников utm которые удалить*/
|
||||
Utms []string `json:"utms"`
|
||||
}
|
||||
|
||||
type PaginationReq struct {
|
||||
/* - указание страницы пагинации. Если страница не указана, применять 0*/
|
||||
Page int `json:"page"`
|
||||
/* - указание размера страницы пагинации. По умолчанию применять 25*/
|
||||
Size int `json:"size"`
|
||||
}
|
||||
|
||||
type RulesReq struct {
|
||||
/* - ID квиза*/
|
||||
ID string `json:"ID"`
|
||||
}
|
||||
|
||||
type SaveUserListUTMReq struct {
|
||||
/* - список utm для сохранения. сохранять только те, которых в этом аккаунте ещё нет*/
|
||||
Utms []UTM `json:"utms"`
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package models
|
||||
|
||||
type ConnectAccountResp struct {
|
||||
/* - ссылка для авторизации в амо*/
|
||||
Link string `json:"link"`
|
||||
}
|
||||
|
||||
type GetCurrentAccountResp struct {
|
||||
/* - айдишник в нашей системе Primary Key*/
|
||||
ID int `json:"ID"`
|
||||
/* - имя аккаунта в амо*/
|
||||
Name string `json:"Name"`
|
||||
/* - поддомен организации в амо*/
|
||||
Subdomain string `json:"Subdomain"`
|
||||
/* - id пользователя из токена в нашей системе*/
|
||||
Accountid string `json:"AccountID"`
|
||||
/* - айдишник пользвателя, который подключал интеграцию*/
|
||||
Amouserid int `json:"AmoUserID"`
|
||||
/* - связь с аккаунтом в амо*/
|
||||
Amocrmid int `json:"AmocrmID"`
|
||||
/* - страна указанная в настройках амо*/
|
||||
Country string `json:"Country"`
|
||||
/* - таймштамп создания аккаунта*/
|
||||
Createdat int64 `json:"CreatedAt"`
|
||||
}
|
||||
|
||||
type GetListUserUTMResp struct {
|
||||
/* - общее количество юзеров, которые у нас закешированы для этого пользователя*/
|
||||
Count int `json:"count"`
|
||||
/* - список юзеров, которые были закешированы нашим сервисом*/
|
||||
Items []UTM `json:"items"`
|
||||
}
|
||||
|
||||
type ListSavedIDUTMResp struct {
|
||||
/* - список айдишников сохранённых меток*/
|
||||
Ids []string `json:"IDs"`
|
||||
}
|
||||
|
||||
type UserListFieldsResp struct {
|
||||
/* - общее количество кастомных полей, которые у нас закешированы для этого пользователя*/
|
||||
Count int `json:"count"`
|
||||
/* - список кастомных полей, которые были закешированы нашим сервисом*/
|
||||
Items []Field `json:"items"`
|
||||
}
|
||||
|
||||
type UserListPipelinesResp struct {
|
||||
/* - общее количество воронок, которые у нас закешированы для этого пользователя*/
|
||||
Count int `json:"count"`
|
||||
/* - список воронок, которые были закешированы нашим сервисом*/
|
||||
Items []Pipeline `json:"items"`
|
||||
}
|
||||
|
||||
type UserListResp struct {
|
||||
/* - общее количество юзеров, которые у нас закешированы для этого пользователя*/
|
||||
Count int `json:"count"`
|
||||
/* - список юзеров, которые были закешированы нашим сервисом*/
|
||||
Items []User `json:"items"`
|
||||
}
|
||||
|
||||
type UserListStepsResp struct {
|
||||
/* - список шагов воронок, которые были закешированы нашим сервисом*/
|
||||
Items []Step `json:"items"`
|
||||
/* - общее количество шагов воронок, которые у нас закешированы для этого пользователя*/
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type UserListTagsResp struct {
|
||||
/* - общее количество тегов, которые у нас закешированы для этого пользователя*/
|
||||
Count int64 `json:"count"`
|
||||
/* - список тегов, которые были закешированы нашим сервисом*/
|
||||
Items []Tag `json:"items"`
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package models
|
||||
|
||||
type Rule struct {
|
||||
/* - айдишник в нашей системе*/
|
||||
ID int `json:"ID"`
|
||||
/* - связь с аккаунтом в интеграции амо id в амо*/
|
||||
Accountid int `json:"AccountID"`
|
||||
/* - айдишник опроса*/
|
||||
Quizid int `json:"QuizID"`
|
||||
/* - айдишник ответственного за сделку*/
|
||||
Performerid int `json:"PerformerID"`
|
||||
/* - айдишник воронки*/
|
||||
Pipelineid int `json:"PipelineID"`
|
||||
/* - айдишник этапа*/
|
||||
Stepid int `json:"StepID"`
|
||||
/* - список UTM для этого опроса*/
|
||||
Utms []int `json:"UTMs"`
|
||||
/* - правила заполнения полей сущностей в амо*/
|
||||
Fieldsrule Fieldsrule `json:"FieldsRule"`
|
||||
/* - флаг мягкого удаления*/
|
||||
Deleted bool `json:"Deleted"`
|
||||
/* - таймштамп создания воронки в нашей системе*/
|
||||
Createdat int `json:"CreatedAt"`
|
||||
}
|
||||
|
||||
type Fieldsrule struct {
|
||||
Lead []FieldRule `json:"Lead"`
|
||||
Contact []FieldRule `json:"Contact"`
|
||||
Company []FieldRule `json:"Company"`
|
||||
Customer []FieldRule `json:"Customer"`
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package models
|
||||
|
||||
type Step struct {
|
||||
/* - айдишник в нашей системе Primary Key*/
|
||||
ID int `json:"ID"`
|
||||
/* - айдишник шага воронки в амо*/
|
||||
Amoid int `json:"AmoID"`
|
||||
/* - айдишник воронки в амо*/
|
||||
Pipelineid int `json:"PipelineID"`
|
||||
/* - связь с аккаунтом в интеграции амо id в амо*/
|
||||
Accountid int `json:"AccountID"`
|
||||
/* - название воронки в амо*/
|
||||
Name string `json:"Name"`
|
||||
/* - цвет шага в амо*/
|
||||
Color string `json:"Color"`
|
||||
/* - флаг мягкого удаления*/
|
||||
Deleted bool `json:"Deleted"`
|
||||
/* - таймштамп создания воронки в нашей системе*/
|
||||
Createdat int64 `json:"CreatedAt"`
|
||||
// время обновления
|
||||
UpdateAt int64 `json:"UpdateAt"`
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package models
|
||||
|
||||
import "amocrm/internal/models/amo"
|
||||
|
||||
type Tag struct {
|
||||
/* - айдишник в нашей системе Primary Key*/
|
||||
ID int `json:"ID"`
|
||||
/* - айдишник тега в амо*/
|
||||
Amoid int `json:"AmoID"`
|
||||
/* - связь с аккаунтом в интеграции амо id аккаунта в амо*/
|
||||
Accountid int `json:"AccountID"`
|
||||
/* - сущность, к которой принадлежит этот тег. Наверное, стоит сделать через enum в базе*/
|
||||
Entity amo.EntityType `json:"Entity"`
|
||||
/* - название тега в амо*/
|
||||
Name string `json:"Name"`
|
||||
/* - цвет тега в амо*/
|
||||
Color *string `json:"Color"`
|
||||
/* - флаг мягкого удаления*/
|
||||
Deleted bool `json:"Deleted"`
|
||||
/* - таймштамп создания тега в нашей системе*/
|
||||
Createdat int64 `json:"CreatedAt"`
|
||||
// время обновления
|
||||
UpdateAt int64 `json:"UpdateAt"`
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package models
|
||||
|
||||
type Token struct {
|
||||
AccountID string `json:"account_id"` // id в квизе
|
||||
RefreshToken string `json:"refresh_token"` // 80 дней
|
||||
AccessToken string `json:"access_token"` // 20 минут
|
||||
AuthCode string `json:"auth_code"`
|
||||
Expiration int64 `json:"expiration"` // таймшамп времени когда кончится AccessToken
|
||||
CreatedAt int64 `json:"created_at"` // таймшамп времени создания, нужен для отслеживания 80 дней
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package models
|
||||
|
||||
type User struct {
|
||||
/* - айдишник в нашей системе Primary Key*/
|
||||
ID int `json:"ID"`
|
||||
/* - id пользователя из токена в нашей системе*/
|
||||
Accountid string `json:"AccountID"`
|
||||
/* - айдишник пользователя в амо*/
|
||||
AmoID int `json:"AmocrmID"`
|
||||
/* - имя аккаунта в амо*/
|
||||
Name string `json:"Name"`
|
||||
/* - почта пользователя из амо*/
|
||||
Email string `json:"Email"`
|
||||
/* - роль пользователя в амо*/
|
||||
Role string `json:"Role"`
|
||||
/* - группы пользователя в амо*/
|
||||
Group []UserGroups `json:"Group"`
|
||||
/* - флаг мягкого удаления*/
|
||||
Deleted bool `json:"Deleted"`
|
||||
/* - таймштамп создания аккаунта*/
|
||||
Createdat int64 `json:"CreatedAt"`
|
||||
/* - поддомен организации в амо*/
|
||||
Subdomain string `json:"Subdomain"`
|
||||
/* - айдишник пользвателя, который подключал интеграцию*/
|
||||
Amouserid int `json:"AmoUserID"`
|
||||
/* - страна указанная в настройках амо*/
|
||||
Country string `json:"Country"`
|
||||
}
|
||||
|
||||
type UserGroups struct {
|
||||
ID int `json:"id" bson:"id"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
UUID interface{} `json:"uuid" bson:"uuid"`
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package amo
|
||||
package models
|
||||
|
||||
type AmocrmUserInformation struct {
|
||||
//ID аккаунта
|
||||
ID int64 `json:"id" bson:"id"`
|
||||
ID int `json:"id" bson:"id"`
|
||||
//Название аккаунта
|
||||
Name string `json:"name" bson:"name"`
|
||||
//Субдомен аккаунта
|
@ -1,18 +0,0 @@
|
||||
package models
|
||||
|
||||
type UTM struct {
|
||||
/* - айдишник в нашей системе Primary Key*/
|
||||
ID int `json:"ID" bson:"ID"`
|
||||
/* - айдишник кастомного поля в амо*/
|
||||
Amofieldid int `json:"AmoFieldID"`
|
||||
/* - айдишник квиза*/
|
||||
Quizid int `json:"QuizID"`
|
||||
/* - связь с аккаунтом в интеграции амо id амо*/
|
||||
Accountid int `json:"AccountID"`
|
||||
/* - название тега в амо*/
|
||||
Name string `json:"Name"`
|
||||
/* - флаг мягкого удаления*/
|
||||
Deleted bool `json:"Deleted"`
|
||||
/* - таймштамп создания тега в нашей системе*/
|
||||
Createdat int64 `json:"CreatedAt"`
|
||||
}
|
@ -55,7 +55,7 @@ func (r *Repository) UpdateListCustom(ctx context.Context) error {
|
||||
type CheckFieldsDeps struct {
|
||||
AccountID string // id quiz
|
||||
ID int // id amo
|
||||
EntityType amo.EntityType
|
||||
EntityType models.EntityType
|
||||
Fields []amo.CustomField
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func (r *Repository) CheckFields(ctx context.Context, deps CheckFieldsDeps) erro
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) GetFieldByID(ctx context.Context, accountID string, amoid int, entity amo.EntityType) (*models.Field, error) {
|
||||
func (r *Repository) GetFieldByID(ctx context.Context, accountID string, amoid int, entity models.EntityType) (*models.Field, error) {
|
||||
var field models.Field
|
||||
filter := bson.M{"id": accountID, "amoid": amoid, "entity": entity}
|
||||
err := r.fields.FindOne(ctx, filter).Decode(&field)
|
||||
|
@ -56,7 +56,7 @@ func (r *Repository) UpdateListTags(ctx context.Context) error {
|
||||
type CheckTagsDeps struct {
|
||||
AccountID string // id quiz
|
||||
ID int // id amo
|
||||
EntityType amo.EntityType
|
||||
EntityType models.EntityType
|
||||
Tags []amo.Tag
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ func (r *Repository) CheckTags(ctx context.Context, deps CheckTagsDeps) error {
|
||||
}
|
||||
|
||||
// test +
|
||||
func (r *Repository) GetTagByID(ctx context.Context, accountID string, amoid int, entity amo.EntityType) (*models.Tag, error) {
|
||||
func (r *Repository) GetTagByID(ctx context.Context, accountID string, amoid int, entity models.EntityType) (*models.Tag, error) {
|
||||
var tag models.Tag
|
||||
filter := bson.M{"id": accountID, "amoid": amoid, "entity": entity}
|
||||
err := r.tags.FindOne(ctx, filter).Decode(&tag)
|
||||
|
@ -1,13 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (s *Service) GettingFieldsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListFieldsResp, error) {
|
||||
response, err := s.repository.GettingFieldsFromCash(ctx, req)
|
||||
func (s *Service) GettingFieldsFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListFieldsResp, error) {
|
||||
response, err := s.repository.AmoRepo.GettingFieldsFromCash(ctx, req)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting fields with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
@ -17,7 +17,7 @@ func (s *Service) GettingFieldsFromCash(ctx context.Context, req *models.Paginat
|
||||
|
||||
func (s *Service) UpdateListCustom(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListCustom(ctx)
|
||||
err := s.repository.AmoRepo.UpdateListCustom(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/pkg/amoClient"
|
||||
pena_social_auth "amocrm/pkg/pena-social-auth"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Repository *repository.Repository
|
||||
Repository *dal.AmoDal
|
||||
Logger *zap.Logger
|
||||
SocialAuthClient *pena_social_auth.Client
|
||||
AmoClient *amoClient.Amo
|
||||
@ -17,7 +17,7 @@ type Deps struct {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
repository *repository.Repository
|
||||
repository *dal.AmoDal
|
||||
logger *zap.Logger
|
||||
socialAuthClient *pena_social_auth.Client
|
||||
amoClient *amoClient.Amo
|
||||
|
@ -1,22 +1,22 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (s *Service) UpdateListPipelines(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListPipelines(ctx)
|
||||
err := s.repository.AmoRepo.UpdateListPipelines(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingPipelinesFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListPipelinesResp, error) {
|
||||
response, err := s.repository.GettingPipelinesFromCash(ctx, req)
|
||||
func (s *Service) GettingPipelinesFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListPipelinesResp, error) {
|
||||
response, err := s.repository.AmoRepo.GettingPipelinesFromCash(ctx, req)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting pipelines with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
|
@ -1,31 +1,31 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (s *Service) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
func (s *Service) ChangeQuizSettings(ctx context.Context, request *model.RulesReq) error {
|
||||
|
||||
err := s.repository.ChangeQuizSettings(ctx, request)
|
||||
err := s.repository.AmoRepo.ChangeQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
func (s *Service) SetQuizSettings(ctx context.Context, request *model.RulesReq) error {
|
||||
|
||||
err := s.repository.SetQuizSettings(ctx, request)
|
||||
err := s.repository.AmoRepo.SetQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
func (s *Service) GettingQuizRules(ctx context.Context) (*model.Rule, error) {
|
||||
|
||||
response, err := s.repository.GettingQuizRules(ctx)
|
||||
response, err := s.repository.AmoRepo.GettingQuizRules(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (s *Service) GettingStepsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListStepsResp, error) {
|
||||
response, err := s.repository.GettingStepsFromCash(ctx, req)
|
||||
func (s *Service) GettingStepsFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListStepsResp, error) {
|
||||
response, err := s.repository.AmoRepo.GettingStepsFromCash(ctx, req)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting steps with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
@ -17,7 +17,7 @@ func (s *Service) GettingStepsFromCash(ctx context.Context, req *models.Paginati
|
||||
|
||||
func (s *Service) UpdateListSteps(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListSteps(ctx)
|
||||
err := s.repository.AmoRepo.UpdateListSteps(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (s *Service) GettingTagsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListTagsResp, error) {
|
||||
response, err := s.repository.GettingTagsFromCash(ctx, req)
|
||||
func (s *Service) GettingTagsFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListTagsResp, error) {
|
||||
response, err := s.repository.AmoRepo.GettingTagsFromCash(ctx, req)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting tags with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
@ -17,7 +17,7 @@ func (s *Service) GettingTagsFromCash(ctx context.Context, req *models.Paginatio
|
||||
|
||||
func (s *Service) UpdateListTags(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListTags(ctx)
|
||||
err := s.repository.AmoRepo.UpdateListTags(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (s *Service) UpdateListUsers(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListUsers(ctx)
|
||||
err := s.repository.AmoRepo.UpdateListUsers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingUserFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListResp, error) {
|
||||
response, err := s.repository.GettingUserFromCash(ctx, req)
|
||||
func (s *Service) GettingUserFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListResp, error) {
|
||||
response, err := s.repository.AmoRepo.GettingUserFromCash(ctx, req)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting users with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
@ -25,7 +25,7 @@ func (s *Service) GettingUserFromCash(ctx context.Context, req *models.Paginatio
|
||||
}
|
||||
|
||||
func (s *Service) SoftDeleteAccount(ctx context.Context, accountID string) error {
|
||||
err := s.repository.SoftDeleteAccount(ctx, accountID)
|
||||
err := s.repository.AmoRepo.SoftDeleteAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
s.logger.Error("error soft delete current account in softDeleteAccount service", zap.Error(err))
|
||||
return err
|
||||
@ -33,20 +33,20 @@ func (s *Service) SoftDeleteAccount(ctx context.Context, accountID string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GetCurrentAccount(ctx context.Context, accountID string) (*models.GetCurrentAccountResp, error) {
|
||||
user, err := s.repository.GetCurrentAccount(ctx, accountID)
|
||||
func (s *Service) GetCurrentAccount(ctx context.Context, accountID string) (*model.GetCurrentAccountResp, error) {
|
||||
user, err := s.repository.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting current account in getCurrentAccount service", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := models.GetCurrentAccountResp{
|
||||
response := model.GetCurrentAccountResp{
|
||||
ID: user.ID,
|
||||
Name: user.Name,
|
||||
Subdomain: user.Subdomain,
|
||||
Accountid: user.Accountid,
|
||||
Amouserid: user.Amouserid,
|
||||
Amocrmid: user.Amocrmid,
|
||||
Amocrmid: user.AmoID,
|
||||
Country: user.Country,
|
||||
Createdat: user.Createdat,
|
||||
}
|
||||
@ -54,8 +54,8 @@ func (s *Service) GetCurrentAccount(ctx context.Context, accountID string) (*mod
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*models.ConnectAccountResp, error) {
|
||||
err := s.repository.CreateAccount(ctx, accountID)
|
||||
func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*model.ConnectAccountResp, error) {
|
||||
err := s.repository.AmoRepo.CreateAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
s.logger.Error("error create account in connectAccount service", zap.Error(err))
|
||||
return nil, err
|
||||
@ -72,7 +72,7 @@ func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*models
|
||||
s.logger.Error("error sending request to pena social auth service:", zap.Error(err))
|
||||
}
|
||||
|
||||
response := models.ConnectAccountResp{
|
||||
response := model.ConnectAccountResp{
|
||||
Link: link,
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (s *Service) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
err := s.repository.DeletingUserUtm(ctx, request)
|
||||
func (s *Service) DeletingUserUtm(ctx context.Context, request *model.ListDeleteUTMIDsReq) error {
|
||||
err := s.repository.AmoRepo.DeletingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
s.logger.Error("error deleting user utm", zap.Error(err))
|
||||
return err
|
||||
@ -15,8 +15,8 @@ func (s *Service) DeletingUserUtm(ctx context.Context, request *models.ListDelet
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq, accountID string, quizID int) (*models.ListSavedIDUTMResp, error) {
|
||||
response, err := s.repository.SavingUserUtm(ctx, request, accountID, quizID)
|
||||
func (s *Service) SavingUserUtm(ctx context.Context, request *model.SaveUserListUTMReq, accountID string, quizID int) (*model.ListSavedIDUTMResp, error) {
|
||||
response, err := s.repository.AmoRepo.SavingUserUtm(ctx, request, accountID, quizID)
|
||||
if err != nil {
|
||||
s.logger.Error("error saving user utm", zap.Error(err))
|
||||
return nil, err
|
||||
@ -24,8 +24,8 @@ func (s *Service) SavingUserUtm(ctx context.Context, request *models.SaveUserLis
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingUserUtm(ctx context.Context, request *models.PaginationReq, accountID string, quizID int) (*models.GetListUserUTMResp, error) {
|
||||
response, err := s.repository.GettingUserUtm(ctx, request, accountID, quizID)
|
||||
func (s *Service) GettingUserUtm(ctx context.Context, request *model.PaginationReq, accountID string, quizID int) (*model.GetListUserUTMResp, error) {
|
||||
response, err := s.repository.AmoRepo.GettingUserUtm(ctx, request, accountID, quizID)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting user utm with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
|
@ -2,10 +2,10 @@ package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/models/amo"
|
||||
"amocrm/internal/tools"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -25,7 +25,7 @@ func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) er
|
||||
}
|
||||
|
||||
// получаем аксес и рефреш токены по коду авторизации
|
||||
forGetTokens := amo.CreateWebHookReq{
|
||||
forGetTokens := models.CreateWebHookReq{
|
||||
GrantType: "authorization_code",
|
||||
Code: req.Code,
|
||||
}
|
||||
@ -43,31 +43,31 @@ func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) er
|
||||
return err
|
||||
}
|
||||
|
||||
userInfoByID, err := s.amoClient.GetUserByID(userInfo.CurrentUserID)
|
||||
userInfoByID, err := s.amoClient.GetUserByID(userInfo.ID)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting GetUserByID in Service:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
toUpdate := models.User{
|
||||
ID: *userInfoByID.UUID,
|
||||
toUpdate := model.User{
|
||||
Name: userInfoByID.Name,
|
||||
Subdomain: userInfo.Subdomain,
|
||||
Amocrmid: userInfo.ID,
|
||||
Amouserid: userInfoByID.ID,
|
||||
AmoID: userInfo.ID,
|
||||
// todo понять какой пользователь считается подключившим
|
||||
Amouserid: userInfo.ID,
|
||||
Email: userInfoByID.Email,
|
||||
Group: tools.ConvertUserGroups(userInfo),
|
||||
Country: userInfo.Country,
|
||||
Role: *userInfoByID.Role,
|
||||
}
|
||||
|
||||
err = s.repository.UpdateAccount(ctx, accountID, toUpdate)
|
||||
err = s.repository.AmoRepo.UpdateAccount(ctx, accountID, toUpdate)
|
||||
if err != nil {
|
||||
s.logger.Error("error update account in mongo on service WebhookCreate", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.repository.WebhookCreate(ctx, models.Token{
|
||||
err = s.repository.AmoRepo.WebhookCreate(ctx, model.Token{
|
||||
RefreshToken: tokens.RefreshToken,
|
||||
AccessToken: tokens.AccessToken,
|
||||
AccountID: accountID,
|
||||
@ -84,7 +84,7 @@ func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) er
|
||||
|
||||
func (s *Service) WebhookDelete(ctx context.Context) error {
|
||||
|
||||
err := s.repository.WebhookDelete(ctx)
|
||||
err := s.repository.AmoRepo.WebhookDelete(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
67
internal/tools/construct.go
Normal file
67
internal/tools/construct.go
Normal file
@ -0,0 +1,67 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func ToPipeline(amoPipelines []models.Pipeline) []model.Pipeline {
|
||||
var pipelines []model.Pipeline
|
||||
for _, p := range amoPipelines {
|
||||
pipeline := model.Pipeline{
|
||||
Amoid: p.ID,
|
||||
Name: p.Name,
|
||||
Isarchive: p.IsArchive,
|
||||
AccountID: p.AccountID,
|
||||
}
|
||||
pipelines = append(pipelines, pipeline)
|
||||
}
|
||||
return pipelines
|
||||
}
|
||||
|
||||
func ToStep(amoStatuses []models.Statuses) []model.Step {
|
||||
var steps []model.Step
|
||||
for _, s := range amoStatuses {
|
||||
step := model.Step{
|
||||
Amoid: s.ID,
|
||||
Name: s.Name,
|
||||
Pipelineid: s.PipelineID,
|
||||
Color: s.Color,
|
||||
Accountid: s.AccountID,
|
||||
}
|
||||
steps = append(steps, step)
|
||||
}
|
||||
return steps
|
||||
}
|
||||
|
||||
func ToTag(amoTag []models.Tag, entity model.EntityType, accountID int) []model.Tag {
|
||||
var tags []model.Tag
|
||||
for _, t := range amoTag {
|
||||
tag := model.Tag{
|
||||
Amoid: t.ID,
|
||||
Accountid: accountID,
|
||||
Entity: entity,
|
||||
Name: t.Name,
|
||||
Color: t.Color,
|
||||
}
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
func ToField(amoField []models.CustomField, entity model.EntityType, accountID int) []model.Field {
|
||||
var fields []model.Field
|
||||
for _, f := range amoField {
|
||||
field := model.Field{
|
||||
Amoid: f.ID,
|
||||
Code: f.Code,
|
||||
Accountid: accountID,
|
||||
Name: f.Name,
|
||||
Entity: entity,
|
||||
Type: f.Type,
|
||||
}
|
||||
fields = append(fields, field)
|
||||
}
|
||||
|
||||
return fields
|
||||
}
|
@ -2,13 +2,13 @@ package tools
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/models/amo"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func ConvertUserGroups(groups *amo.AmocrmUserInformation) []models.UserGroups {
|
||||
var userGroups []models.UserGroups
|
||||
func ConvertUserGroups(groups *models.AmocrmUserInformation) []model.UserGroups {
|
||||
var userGroups []model.UserGroups
|
||||
for _, group := range groups.Embedded.UsersGroups {
|
||||
userGroups = append(userGroups, models.UserGroups{
|
||||
userGroups = append(userGroups, model.UserGroups{
|
||||
ID: group.ID,
|
||||
Name: group.Name,
|
||||
UUID: group.UUID,
|
||||
@ -17,10 +17,10 @@ func ConvertUserGroups(groups *amo.AmocrmUserInformation) []models.UserGroups {
|
||||
return userGroups
|
||||
}
|
||||
|
||||
func ConvertGroups(groups amo.Users) []models.UserGroups {
|
||||
var userGroups []models.UserGroups
|
||||
func ConvertGroups(groups models.Users) []model.UserGroups {
|
||||
var userGroups []model.UserGroups
|
||||
for _, group := range groups.Embedded.Groups {
|
||||
userGroups = append(userGroups, models.UserGroups{
|
||||
userGroups = append(userGroups, model.UserGroups{
|
||||
ID: group.ID,
|
||||
Name: group.Name,
|
||||
})
|
||||
|
@ -2,24 +2,24 @@ package data_updater
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/models/amo"
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/internal/tools"
|
||||
"amocrm/pkg/amoClient"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
AmoClient *amoClient.Amo
|
||||
Repo *repository.Repository
|
||||
Repo *dal.AmoDal
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type DataUpdater struct {
|
||||
amoClient *amoClient.Amo
|
||||
repo *repository.Repository
|
||||
repo *dal.AmoDal
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
wc.logger.Error("some error from UserUpdater", zap.Error(err))
|
||||
}
|
||||
// сначала получаем список токенов
|
||||
allTokens, err := wc.repo.GetAllTokens(ctx)
|
||||
allTokens, err := wc.repo.AmoRepo.GetAllTokens(ctx)
|
||||
if err != nil {
|
||||
wc.logger.Error("error fetch all tokens from mongo:", zap.Error(err))
|
||||
return
|
||||
@ -67,7 +67,7 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
if err != nil {
|
||||
wc.logger.Error("error getting list pipelines:", zap.Error(err))
|
||||
}
|
||||
err = wc.repo.CheckPipelines(ctx, token.AccountID, pipelines.Embedded.Pipelines)
|
||||
err = wc.repo.AmoRepo.CheckPipelines(ctx, token.AccountID, tools.ToPipeline(pipelines.Embedded.Pipelines))
|
||||
if err != nil {
|
||||
wc.logger.Error("error update pipelines in mongo:", zap.Error(err))
|
||||
}
|
||||
@ -81,25 +81,25 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
|
||||
err = wc.repo.CheckSteps(ctx, token.AccountID, steps.Embedded.Statuses)
|
||||
err = wc.repo.AmoRepo.CheckSteps(ctx, token.AccountID, tools.ToStep(steps.Embedded.Statuses))
|
||||
if err != nil {
|
||||
wc.logger.Error("error update pipeline steps in mongo:", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
// tags
|
||||
var leadsTags []amo.Tag
|
||||
var contactsTags []amo.Tag
|
||||
var companiesTags []amo.Tag
|
||||
var customersTags []amo.Tag
|
||||
var leadsTags []models.Tag
|
||||
var contactsTags []models.Tag
|
||||
var companiesTags []models.Tag
|
||||
var customersTags []models.Tag
|
||||
|
||||
entityTypes := []amo.EntityType{amo.LeadsTags, amo.ContactsTags, amo.CompaniesTags, amo.CustomersTags}
|
||||
entityTypes := []model.EntityType{model.LeadsTags, model.ContactsTags, model.CompaniesTags, model.CustomersTags}
|
||||
for _, entityType := range entityTypes {
|
||||
page := 1
|
||||
limit := 250
|
||||
|
||||
for {
|
||||
req := amo.GetListTagsReq{
|
||||
req := models.GetListTagsReq{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
EntityType: entityType,
|
||||
@ -115,13 +115,13 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
}
|
||||
|
||||
switch entityType {
|
||||
case amo.LeadsTags:
|
||||
case model.LeadsTags:
|
||||
leadsTags = append(leadsTags, tags.Embedded.Tags...)
|
||||
case amo.ContactsTags:
|
||||
case model.ContactsTags:
|
||||
contactsTags = append(contactsTags, tags.Embedded.Tags...)
|
||||
case amo.CompaniesTags:
|
||||
case model.CompaniesTags:
|
||||
companiesTags = append(companiesTags, tags.Embedded.Tags...)
|
||||
case amo.CustomersTags:
|
||||
case model.CustomersTags:
|
||||
customersTags = append(customersTags, tags.Embedded.Tags...)
|
||||
}
|
||||
|
||||
@ -131,46 +131,26 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
|
||||
for _, entityType := range entityTypes {
|
||||
switch entityType {
|
||||
case amo.LeadsTags:
|
||||
err := wc.repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
Tags: leadsTags,
|
||||
AccountID: token.AccountID,
|
||||
ID: accountID,
|
||||
EntityType: entityType,
|
||||
})
|
||||
case model.LeadsTags:
|
||||
err := wc.repo.AmoRepo.CheckTags(ctx, tools.ToTag(leadsTags, entityType, accountID), token.AccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error update leads tags")
|
||||
continue
|
||||
}
|
||||
case amo.ContactsTags:
|
||||
err := wc.repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
Tags: contactsTags,
|
||||
AccountID: token.AccountID,
|
||||
ID: accountID,
|
||||
EntityType: entityType,
|
||||
})
|
||||
case model.ContactsTags:
|
||||
err := wc.repo.AmoRepo.CheckTags(ctx, tools.ToTag(contactsTags, entityType, accountID), token.AccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error update contacts tags")
|
||||
continue
|
||||
}
|
||||
case amo.CompaniesTags:
|
||||
err := wc.repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
Tags: companiesTags,
|
||||
AccountID: token.AccountID,
|
||||
ID: accountID,
|
||||
EntityType: entityType,
|
||||
})
|
||||
case model.CompaniesTags:
|
||||
err := wc.repo.AmoRepo.CheckTags(ctx, tools.ToTag(companiesTags, entityType, accountID), token.AccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error update companies tags")
|
||||
continue
|
||||
}
|
||||
case amo.CustomersTags:
|
||||
err := wc.repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
Tags: customersTags,
|
||||
AccountID: token.AccountID,
|
||||
ID: accountID,
|
||||
EntityType: entityType,
|
||||
})
|
||||
case model.CustomersTags:
|
||||
err := wc.repo.AmoRepo.CheckTags(ctx, tools.ToTag(customersTags, entityType, accountID), token.AccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error update customer tags")
|
||||
continue
|
||||
@ -179,16 +159,16 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
}
|
||||
|
||||
// fields
|
||||
var leadsFields []amo.CustomField
|
||||
var contactsFields []amo.CustomField
|
||||
var companiesFields []amo.CustomField
|
||||
var customersFields []amo.CustomField
|
||||
var leadsFields []models.CustomField
|
||||
var contactsFields []models.CustomField
|
||||
var companiesFields []models.CustomField
|
||||
var customersFields []models.CustomField
|
||||
for _, entityType := range entityTypes {
|
||||
page := 1
|
||||
limit := 50
|
||||
|
||||
for {
|
||||
req := amo.GetListFieldsReq{
|
||||
req := models.GetListFieldsReq{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
EntityType: entityType,
|
||||
@ -204,13 +184,13 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
}
|
||||
|
||||
switch entityType {
|
||||
case amo.LeadsTags:
|
||||
case model.LeadsTags:
|
||||
leadsFields = append(leadsFields, fields.Embedded.CustomFields...)
|
||||
case amo.ContactsTags:
|
||||
case model.ContactsTags:
|
||||
contactsFields = append(contactsFields, fields.Embedded.CustomFields...)
|
||||
case amo.CompaniesTags:
|
||||
case model.CompaniesTags:
|
||||
companiesFields = append(companiesFields, fields.Embedded.CustomFields...)
|
||||
case amo.CustomersTags:
|
||||
case model.CustomersTags:
|
||||
customersFields = append(customersFields, fields.Embedded.CustomFields...)
|
||||
}
|
||||
|
||||
@ -220,46 +200,26 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
|
||||
for _, entityType := range entityTypes {
|
||||
switch entityType {
|
||||
case amo.LeadsTags:
|
||||
err := wc.repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
Fields: leadsFields,
|
||||
AccountID: token.AccountID,
|
||||
ID: accountID,
|
||||
EntityType: entityType,
|
||||
})
|
||||
case model.LeadsTags:
|
||||
err := wc.repo.AmoRepo.CheckFields(ctx, tools.ToField(leadsFields, entityType, accountID), token.AccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error update leads fields")
|
||||
continue
|
||||
}
|
||||
case amo.ContactsTags:
|
||||
err := wc.repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
Fields: contactsFields,
|
||||
AccountID: token.AccountID,
|
||||
ID: accountID,
|
||||
EntityType: entityType,
|
||||
})
|
||||
case model.ContactsTags:
|
||||
err := wc.repo.AmoRepo.CheckFields(ctx, tools.ToField(contactsFields, entityType, accountID), token.AccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error update contacts fields")
|
||||
continue
|
||||
}
|
||||
case amo.CompaniesTags:
|
||||
err := wc.repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
Fields: companiesFields,
|
||||
AccountID: token.AccountID,
|
||||
ID: accountID,
|
||||
EntityType: entityType,
|
||||
})
|
||||
case model.CompaniesTags:
|
||||
err := wc.repo.AmoRepo.CheckFields(ctx, tools.ToField(companiesFields, entityType, accountID), token.AccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error update companies fields")
|
||||
continue
|
||||
}
|
||||
case amo.CustomersTags:
|
||||
err := wc.repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
Fields: companiesFields,
|
||||
AccountID: token.AccountID,
|
||||
ID: accountID,
|
||||
EntityType: entityType,
|
||||
})
|
||||
case model.CustomersTags:
|
||||
err := wc.repo.AmoRepo.CheckFields(ctx, tools.ToField(companiesFields, entityType, accountID), token.AccountID)
|
||||
if err != nil {
|
||||
wc.logger.Error("error update customer fields")
|
||||
continue
|
||||
@ -270,11 +230,11 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (wc *DataUpdater) UserUpdater(ctx context.Context) error {
|
||||
var listUser []amo.Users
|
||||
var listUser []models.Users
|
||||
page := 1
|
||||
limit := 250
|
||||
for {
|
||||
userData, err := wc.amoClient.GetUserList(amo.RequestGetListUsers{
|
||||
userData, err := wc.amoClient.GetUserList(models.RequestGetListUsers{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
})
|
||||
@ -298,7 +258,7 @@ func (wc *DataUpdater) UserUpdater(ctx context.Context) error {
|
||||
wc.logger.Error("error getting user by id", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
err = wc.repo.CheckUsers(ctx, user.ID, models.User{
|
||||
err = wc.repo.AmoRepo.CheckUsers(ctx, user.ID, model.User{
|
||||
Name: onlyOneUser.Name,
|
||||
Group: tools.ConvertGroups(user),
|
||||
Role: *onlyOneUser.Role,
|
||||
|
@ -2,23 +2,23 @@ package tokens
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/models/amo"
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/pkg/amoClient"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
AmoClient *amoClient.Amo
|
||||
Repo *repository.Repository
|
||||
Repo *dal.AmoDal
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
amoClient *amoClient.Amo
|
||||
repo *repository.Repository
|
||||
repo *dal.AmoDal
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
@ -46,13 +46,13 @@ func (wc *Token) Start(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (wc *Token) processTasks(ctx context.Context) {
|
||||
tokens, err := wc.repo.CheckExpired(ctx)
|
||||
tokens, err := wc.repo.AmoRepo.CheckExpired(ctx)
|
||||
if err != nil {
|
||||
wc.logger.Error("error fetch expired tokens in mongo", zap.Error(err))
|
||||
return
|
||||
}
|
||||
for _, token := range tokens {
|
||||
req := amo.UpdateWebHookReq{
|
||||
req := models.UpdateWebHookReq{
|
||||
GrantType: "refresh_token",
|
||||
RefreshToken: token.RefreshToken,
|
||||
}
|
||||
@ -61,7 +61,7 @@ func (wc *Token) processTasks(ctx context.Context) {
|
||||
wc.logger.Error("error create webhook for update tokens", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
err = wc.repo.WebhookUpdate(ctx, models.Token{
|
||||
err = wc.repo.AmoRepo.WebhookUpdate(ctx, model.Token{
|
||||
AccountID: token.AccountID,
|
||||
RefreshToken: newTokens.RefreshToken,
|
||||
AccessToken: newTokens.AccessToken,
|
||||
|
@ -1,7 +1,7 @@
|
||||
package amoClient
|
||||
|
||||
import (
|
||||
"amocrm/internal/models/amo"
|
||||
"amocrm/internal/models"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
@ -54,7 +54,7 @@ func NewAmoClient(deps AmoDeps) *Amo {
|
||||
|
||||
// токен должен быть с правами администратора
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/users-api#users-list
|
||||
func (a *Amo) GetUserList(req amo.RequestGetListUsers) (*amo.ResponseGetListUsers, error) {
|
||||
func (a *Amo) GetUserList(req models.RequestGetListUsers) (*models.ResponseGetListUsers, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/users?page=%d&limit=%d&with=role,group,uuid", a.baseApiURL, req.Page, req.Limit)
|
||||
@ -87,7 +87,7 @@ func (a *Amo) GetUserList(req amo.RequestGetListUsers) (*amo.ResponseGetListUser
|
||||
}
|
||||
}
|
||||
|
||||
var userListResponse amo.ResponseGetListUsers
|
||||
var userListResponse models.ResponseGetListUsers
|
||||
err := json.Unmarshal(resBody, &userListResponse)
|
||||
if err != nil {
|
||||
a.logger.Error("error unmarshal ResponseGetListUsers:", zap.Error(err))
|
||||
@ -103,7 +103,7 @@ func (a *Amo) GetUserList(req amo.RequestGetListUsers) (*amo.ResponseGetListUser
|
||||
// https://www.amocrm.ru/developers/content/oauth/step-by-step
|
||||
// POST /oauth2/access_token
|
||||
// тут и создание по коду и обновление по рефрешу в этом клиенте
|
||||
func (a *Amo) CreateWebHook(req amo.WebHookRequest) (*amo.CreateWebHookResp, error) {
|
||||
func (a *Amo) CreateWebHook(req models.WebHookRequest) (*models.CreateWebHookResp, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
req.SetClientID(a.integrationID)
|
||||
@ -132,7 +132,7 @@ func (a *Amo) CreateWebHook(req amo.WebHookRequest) (*amo.CreateWebHookResp, err
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var tokens amo.CreateWebHookResp
|
||||
var tokens models.CreateWebHookResp
|
||||
err = json.Unmarshal(resBody, &tokens)
|
||||
if err != nil {
|
||||
a.logger.Error("error unmarshal CreateWebHookResp:", zap.Error(err))
|
||||
@ -158,7 +158,7 @@ func (a *Amo) DeleteWebHook() {
|
||||
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA-%D1%81%D1%82%D0%B0%D1%82%D1%83%D1%81%D0%BE%D0%B2-%D0%B2%D0%BE%D1%80%D0%BE%D0%BD%D0%BA%D0%B8-%D1%81%D0%B4%D0%B5%D0%BB%D0%BE%D0%BA
|
||||
// GET /api/v4/leads/pipelines/{pipeline_id}/statuses
|
||||
func (a *Amo) GetListSteps(pipelineID int, accessToken string) (*amo.ResponseGetListSteps, error) {
|
||||
func (a *Amo) GetListSteps(pipelineID int, accessToken string) (*models.ResponseGetListSteps, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/leads/pipelines/%d/statuses", a.baseApiURL, pipelineID)
|
||||
@ -178,7 +178,7 @@ func (a *Amo) GetListSteps(pipelineID int, accessToken string) (*amo.ResponseGet
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var listSteps amo.ResponseGetListSteps
|
||||
var listSteps models.ResponseGetListSteps
|
||||
err := json.Unmarshal(resBody, &listSteps)
|
||||
if err != nil {
|
||||
a.logger.Error("error unmarshal ResponseGetListSteps:", zap.Error(err))
|
||||
@ -201,7 +201,7 @@ func (a *Amo) GetListSteps(pipelineID int, accessToken string) (*amo.ResponseGet
|
||||
// GET /api/v4/customers/segments/custom_fields
|
||||
// GET /api/v4/catalogs/{catalog_id}/custom_fields
|
||||
// эти методы все относятся к одному и тому же, поэтому на вход будет урл и рек стуктура, выход у них один и тот же
|
||||
func (a *Amo) GetListFields(req amo.GetListFieldsReq, accessToken string) (*amo.ResponseGetListFields, error) {
|
||||
func (a *Amo) GetListFields(req models.GetListFieldsReq, accessToken string) (*models.ResponseGetListFields, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
fullURL := fmt.Sprintf("%s/api/v4/%s/custom_fields?limit=%d&page=%d", a.baseApiURL, req.EntityType, req.Limit, req.Page)
|
||||
@ -221,7 +221,7 @@ func (a *Amo) GetListFields(req amo.GetListFieldsReq, accessToken string) (*amo.
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var listFields amo.ResponseGetListFields
|
||||
var listFields models.ResponseGetListFields
|
||||
err := json.Unmarshal(resBody, &listFields)
|
||||
if err != nil {
|
||||
a.logger.Error("error unmarshal ResponseGetListFields:", zap.Error(err))
|
||||
@ -236,7 +236,7 @@ func (a *Amo) GetListFields(req amo.GetListFieldsReq, accessToken string) (*amo.
|
||||
|
||||
// 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
|
||||
func (a *Amo) GetListTags(req amo.GetListTagsReq, accessToken string) (*amo.ResponseGetListTags, error) {
|
||||
func (a *Amo) GetListTags(req models.GetListTagsReq, accessToken string) (*models.ResponseGetListTags, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
fullURL := fmt.Sprintf("%s/api/v4/%s/tags?", a.baseApiURL, req.EntityType)
|
||||
@ -271,7 +271,7 @@ func (a *Amo) GetListTags(req amo.GetListTagsReq, accessToken string) (*amo.Resp
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var listTags amo.ResponseGetListTags
|
||||
var listTags models.ResponseGetListTags
|
||||
err := json.Unmarshal(resBody, &listTags)
|
||||
if err != nil {
|
||||
a.logger.Error("error unmarshal ResponseGetListTags:", zap.Error(err))
|
||||
@ -286,7 +286,7 @@ func (a *Amo) GetListTags(req amo.GetListTagsReq, accessToken string) (*amo.Resp
|
||||
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/account-info
|
||||
// GET /api/v4/account
|
||||
func (a *Amo) GetUserInfo(accessToken string) (*amo.AmocrmUserInformation, error) {
|
||||
func (a *Amo) GetUserInfo(accessToken string) (*models.AmocrmUserInformation, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
agent := a.fiberClient.Get(a.userInfoURL)
|
||||
@ -305,7 +305,7 @@ func (a *Amo) GetUserInfo(accessToken string) (*amo.AmocrmUserInformation, error
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var userInfo amo.AmocrmUserInformation
|
||||
var userInfo models.AmocrmUserInformation
|
||||
err := json.Unmarshal(resBody, &userInfo)
|
||||
if err != nil {
|
||||
a.logger.Error("error unmarshal AmocrmUserInformation:", zap.Error(err))
|
||||
@ -321,7 +321,7 @@ func (a *Amo) GetUserInfo(accessToken string) (*amo.AmocrmUserInformation, error
|
||||
// токен должен быть с правами администратора
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/users-api#user-detail
|
||||
// GET /api/v4/users/{id
|
||||
func (a *Amo) GetUserByID(id int) (*amo.OneUserInfo, error) {
|
||||
func (a *Amo) GetUserByID(id int) (*models.OneUserInfo, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/users/%d?with=role,uuid", a.baseApiURL, id)
|
||||
@ -341,7 +341,7 @@ func (a *Amo) GetUserByID(id int) (*amo.OneUserInfo, error) {
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var userInfo amo.OneUserInfo
|
||||
var userInfo models.OneUserInfo
|
||||
err := json.Unmarshal(resBody, &userInfo)
|
||||
if err != nil {
|
||||
a.logger.Error("error unmarshal OneUserInfo:", zap.Error(err))
|
||||
@ -356,7 +356,7 @@ func (a *Amo) GetUserByID(id int) (*amo.OneUserInfo, error) {
|
||||
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines#%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA-%D0%B2%D0%BE%D1%80%D0%BE%D0%BD%D0%BE%D0%BA-%D1%81%D0%B4%D0%B5%D0%BB%D0%BE%D0%BA
|
||||
// GET /api/v4/leads/pipelines
|
||||
func (a *Amo) GetListPipelines(accessToken string) (*amo.PipelineResponse, error) {
|
||||
func (a *Amo) GetListPipelines(accessToken string) (*models.PipelineResponse, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/leads/pipelines", a.baseApiURL)
|
||||
@ -376,7 +376,7 @@ func (a *Amo) GetListPipelines(accessToken string) (*amo.PipelineResponse, error
|
||||
return nil, fmt.Errorf(errorMessage)
|
||||
}
|
||||
|
||||
var userInfo amo.PipelineResponse
|
||||
var userInfo models.PipelineResponse
|
||||
err := json.Unmarshal(resBody, &userInfo)
|
||||
if err != nil {
|
||||
a.logger.Error("error unmarshal PipelineResponse:", zap.Error(err))
|
||||
|
@ -1,7 +1,7 @@
|
||||
package amoClient
|
||||
|
||||
import (
|
||||
"amocrm/internal/models/amo"
|
||||
"amocrm/internal/models"
|
||||
"fmt"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
@ -26,11 +26,11 @@ func Test_CreateWebhook(t *testing.T) {
|
||||
IntegrationSecret: "IntegrationSecret",
|
||||
})
|
||||
|
||||
req1 := amo.UpdateWebHookReq{
|
||||
req1 := models.UpdateWebHookReq{
|
||||
GrantType: "refresh_token",
|
||||
RefreshToken: "refresh_token",
|
||||
}
|
||||
req2 := amo.CreateWebHookReq{
|
||||
req2 := models.CreateWebHookReq{
|
||||
GrantType: "authorization_code",
|
||||
Code: "Code",
|
||||
}
|
||||
|
@ -1,59 +1,29 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"amocrm/internal/initialize"
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/models/amo"
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/internal/tools"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pioz/faker"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_Repository(t *testing.T) {
|
||||
cfgLogger := zap.NewDevelopmentConfig()
|
||||
cfgLogger.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
cfgLogger.EncoderConfig.ConsoleSeparator = " "
|
||||
|
||||
logger, err := cfgLogger.Build()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
mdb, err := initialize.MongoDB(ctx, initialize.Config{
|
||||
MongoHost: "localhost",
|
||||
MongoPort: "27020",
|
||||
MongoDatabase: "admin",
|
||||
MongoAuth: "admin",
|
||||
MongoPassword: "test",
|
||||
MongoUser: "test",
|
||||
})
|
||||
repo, err := dal.NewAmoDal(ctx, "host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("err init mongo")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
repo := repository.NewRepository(repository.Deps{
|
||||
MdbUser: mdb.Collection("amoUsers"),
|
||||
Tokens: mdb.Collection("tokens"),
|
||||
Pipelines: mdb.Collection("pipelines"),
|
||||
Steps: mdb.Collection("steps"),
|
||||
Tags: mdb.Collection("tags"),
|
||||
Fields: mdb.Collection("fields"),
|
||||
UTMs: mdb.Collection("utms"),
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
err = webhookCreate(ctx, repo)
|
||||
assert.NoError(t, err)
|
||||
err = webhookUpdate(ctx, repo)
|
||||
@ -107,10 +77,10 @@ func Test_Repository(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func createUser(ctx context.Context, repo *repository.Repository) error {
|
||||
func createUser(ctx context.Context, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err := repo.CreateAccount(ctx, accID)
|
||||
err := repo.AmoRepo.CreateAccount(ctx, accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -118,18 +88,18 @@ func createUser(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateUser(ctx context.Context, repo *repository.Repository) error {
|
||||
var testUserInfo amo.AmocrmUserInformation
|
||||
func updateUser(ctx context.Context, repo *dal.AmoDal) error {
|
||||
var testUserInfo models.AmocrmUserInformation
|
||||
err := json.Unmarshal([]byte(jsonUserInfo), &testUserInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 1; i < 10; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
info := models.User{
|
||||
info := model.User{
|
||||
Name: faker.String(),
|
||||
Subdomain: "pena",
|
||||
Amocrmid: 666,
|
||||
AmoID: 666,
|
||||
Amouserid: i,
|
||||
Email: faker.Email(),
|
||||
Group: tools.ConvertUserGroups(&testUserInfo),
|
||||
@ -140,12 +110,10 @@ func updateUser(ctx context.Context, repo *repository.Repository) error {
|
||||
role := faker.String()
|
||||
role2 := &role
|
||||
info.Role = *role2
|
||||
uuid := faker.UUID()
|
||||
uuid2 := &uuid
|
||||
info.ID = *uuid2
|
||||
info.ID = faker.Int()
|
||||
}
|
||||
|
||||
err = repo.UpdateAccount(ctx, accID, info)
|
||||
err = repo.AmoRepo.UpdateAccount(ctx, accID, info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -154,15 +122,15 @@ func updateUser(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkUsers(ctx context.Context, repo *repository.Repository) error {
|
||||
var testUserInfo amo.AmocrmUserInformation
|
||||
func checkUsers(ctx context.Context, repo *dal.AmoDal) error {
|
||||
var testUserInfo models.AmocrmUserInformation
|
||||
err := json.Unmarshal([]byte(jsonUserInfo), &testUserInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 1; i < 10; i++ {
|
||||
if i%2 != 0 {
|
||||
info := models.User{
|
||||
info := model.User{
|
||||
Name: faker.String(),
|
||||
Email: faker.Email(),
|
||||
Group: tools.ConvertUserGroups(&testUserInfo),
|
||||
@ -171,7 +139,7 @@ func checkUsers(ctx context.Context, repo *repository.Repository) error {
|
||||
role2 := &role
|
||||
info.Role = *role2
|
||||
|
||||
err = repo.CheckUsers(ctx, i, info)
|
||||
err = repo.AmoRepo.CheckUsers(ctx, i, info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -180,14 +148,14 @@ func checkUsers(ctx context.Context, repo *repository.Repository) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func gettingUserFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
func gettingUserFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
req := models.PaginationReq{
|
||||
req := model.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingUserFromCash(ctx, &req)
|
||||
resp, err := repo.AmoRepo.GettingUserFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -198,14 +166,14 @@ func gettingUserFromCash(ctx context.Context, t *testing.T, repo *repository.Rep
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkPipelines(ctx context.Context, repo *repository.Repository) error {
|
||||
var testPipeline1 amo.PipelineResponse
|
||||
func checkPipelines(ctx context.Context, repo *dal.AmoDal) error {
|
||||
var testPipeline1 models.PipelineResponse
|
||||
err := json.Unmarshal([]byte(jsonPipelines), &testPipeline1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testPipeline2 amo.PipelineResponse
|
||||
var testPipeline2 models.PipelineResponse
|
||||
err = json.Unmarshal([]byte(jsonPipelines2), &testPipeline2)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -213,7 +181,7 @@ func checkPipelines(ctx context.Context, repo *repository.Repository) error {
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckPipelines(ctx, accID, testPipeline1.Embedded.Pipelines)
|
||||
err = repo.AmoRepo.CheckPipelines(ctx, accID, tools.ToPipeline(testPipeline1.Embedded.Pipelines))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -221,7 +189,7 @@ func checkPipelines(ctx context.Context, repo *repository.Repository) error {
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckPipelines(ctx, accID, testPipeline2.Embedded.Pipelines)
|
||||
err = repo.AmoRepo.CheckPipelines(ctx, accID, tools.ToPipeline(testPipeline2.Embedded.Pipelines))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -230,14 +198,14 @@ func checkPipelines(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingPipelinesFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
func gettingPipelinesFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 28; i++ {
|
||||
req := models.PaginationReq{
|
||||
req := model.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingPipelinesFromCash(ctx, &req)
|
||||
resp, err := repo.AmoRepo.GettingPipelinesFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -249,14 +217,14 @@ func gettingPipelinesFromCash(ctx context.Context, t *testing.T, repo *repositor
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkSteps(ctx context.Context, repo *repository.Repository) error {
|
||||
var testStep1 amo.ResponseGetListSteps
|
||||
func checkSteps(ctx context.Context, repo *dal.AmoDal) error {
|
||||
var testStep1 models.ResponseGetListSteps
|
||||
err := json.Unmarshal([]byte(jsonStep1), &testStep1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testStep2 amo.ResponseGetListSteps
|
||||
var testStep2 models.ResponseGetListSteps
|
||||
err = json.Unmarshal([]byte(jsonStep2), &testStep2)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -264,7 +232,7 @@ func checkSteps(ctx context.Context, repo *repository.Repository) error {
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckSteps(ctx, accID, testStep1.Embedded.Statuses)
|
||||
err = repo.AmoRepo.CheckSteps(ctx, accID, tools.ToStep(testStep1.Embedded.Statuses))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -272,7 +240,7 @@ func checkSteps(ctx context.Context, repo *repository.Repository) error {
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckSteps(ctx, accID, testStep2.Embedded.Statuses)
|
||||
err = repo.AmoRepo.CheckSteps(ctx, accID, tools.ToStep(testStep2.Embedded.Statuses))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -281,14 +249,14 @@ func checkSteps(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingStepsFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
func gettingStepsFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 46; i++ {
|
||||
req := models.PaginationReq{
|
||||
req := model.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingStepsFromCash(ctx, &req)
|
||||
resp, err := repo.AmoRepo.GettingStepsFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -300,50 +268,50 @@ func gettingStepsFromCash(ctx context.Context, t *testing.T, repo *repository.Re
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkTags(ctx context.Context, repo *repository.Repository) error {
|
||||
var testLeadsTags amo.ResponseGetListTags
|
||||
func checkTags(ctx context.Context, repo *dal.AmoDal) error {
|
||||
var testLeadsTags models.ResponseGetListTags
|
||||
err := json.Unmarshal([]byte(jsonLeadsTags), &testLeadsTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testLeadsTags2 amo.ResponseGetListTags
|
||||
var testLeadsTags2 models.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonLeadsTags2), &testLeadsTags2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testContactsTags amo.ResponseGetListTags
|
||||
var testContactsTags models.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonContactsTags), &testContactsTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testContactsTags2 amo.ResponseGetListTags
|
||||
var testContactsTags2 models.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonContactsTags2), &testContactsTags2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCompaniesTags amo.ResponseGetListTags
|
||||
var testCompaniesTags models.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonCompaniesTags), &testCompaniesTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCompaniesTags2 amo.ResponseGetListTags
|
||||
var testCompaniesTags2 models.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonCompaniesTags2), &testCompaniesTags2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCustomersTags amo.ResponseGetListTags
|
||||
var testCustomersTags models.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonCustomersTags), &testCustomersTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCustomersTags2 amo.ResponseGetListTags
|
||||
var testCustomersTags2 models.ResponseGetListTags
|
||||
err = json.Unmarshal([]byte(jsonCustomersTags2), &testCustomersTags2)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -351,39 +319,19 @@ func checkTags(ctx context.Context, repo *repository.Repository) error {
|
||||
id := 666666
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.LeadsTags,
|
||||
Tags: testLeadsTags.Embedded.Tags,
|
||||
})
|
||||
err = repo.AmoRepo.CheckTags(ctx, tools.ToTag(testLeadsTags.Embedded.Tags, model.LeadsTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CompaniesTags,
|
||||
Tags: testCompaniesTags.Embedded.Tags,
|
||||
})
|
||||
err = repo.AmoRepo.CheckTags(ctx, tools.ToTag(testCompaniesTags.Embedded.Tags, model.CompaniesTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CustomersTags,
|
||||
Tags: testCustomersTags.Embedded.Tags,
|
||||
})
|
||||
err = repo.AmoRepo.CheckTags(ctx, tools.ToTag(testCustomersTags.Embedded.Tags, model.CustomersTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.ContactsTags,
|
||||
Tags: testContactsTags.Embedded.Tags,
|
||||
})
|
||||
err = repo.AmoRepo.CheckTags(ctx, tools.ToTag(testContactsTags.Embedded.Tags, model.ContactsTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -391,39 +339,22 @@ func checkTags(ctx context.Context, repo *repository.Repository) error {
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.LeadsTags,
|
||||
Tags: testLeadsTags2.Embedded.Tags,
|
||||
})
|
||||
err = repo.AmoRepo.CheckTags(ctx, tools.ToTag(testLeadsTags2.Embedded.Tags, model.LeadsTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CompaniesTags,
|
||||
Tags: testCompaniesTags2.Embedded.Tags,
|
||||
})
|
||||
err = repo.AmoRepo.CheckTags(ctx, tools.ToTag(testCompaniesTags2.Embedded.Tags, model.CompaniesTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CustomersTags,
|
||||
Tags: testCustomersTags2.Embedded.Tags,
|
||||
})
|
||||
err = repo.AmoRepo.CheckTags(ctx, tools.ToTag(testCustomersTags2.Embedded.Tags, model.CustomersTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.AmoRepo.CheckTags(ctx, tools.ToTag(testContactsTags2.Embedded.Tags, model.ContactsTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckTags(ctx, repository.CheckTagsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.ContactsTags,
|
||||
Tags: testContactsTags2.Embedded.Tags,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -432,14 +363,14 @@ func checkTags(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingTagsFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
func gettingTagsFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 73; i++ {
|
||||
req := models.PaginationReq{
|
||||
req := model.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingTagsFromCash(ctx, &req)
|
||||
resp, err := repo.AmoRepo.GettingTagsFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -451,50 +382,50 @@ func gettingTagsFromCash(ctx context.Context, t *testing.T, repo *repository.Rep
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkFields(ctx context.Context, repo *repository.Repository) error {
|
||||
var testLeadsFields amo.ResponseGetListFields
|
||||
func checkFields(ctx context.Context, repo *dal.AmoDal) error {
|
||||
var testLeadsFields models.ResponseGetListFields
|
||||
err := json.Unmarshal([]byte(jsonLeadsFields), &testLeadsFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testLeadsFields2 amo.ResponseGetListFields
|
||||
var testLeadsFields2 models.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonLeadsFields2), &testLeadsFields2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testContactsFields amo.ResponseGetListFields
|
||||
var testContactsFields models.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonContactsFields), &testContactsFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testContactsFields2 amo.ResponseGetListFields
|
||||
var testContactsFields2 models.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonContactsFields2), &testContactsFields2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCompaniesFields amo.ResponseGetListFields
|
||||
var testCompaniesFields models.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonCompaniesFields), &testCompaniesFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCompaniesFields2 amo.ResponseGetListFields
|
||||
var testCompaniesFields2 models.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonCompaniesFields2), &testCompaniesFields2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCustomersFields amo.ResponseGetListFields
|
||||
var testCustomersFields models.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonCustomersFields), &testCustomersFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var testCustomersFields2 amo.ResponseGetListFields
|
||||
var testCustomersFields2 models.ResponseGetListFields
|
||||
err = json.Unmarshal([]byte(jsonCustomersFields2), &testCustomersFields2)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -503,39 +434,19 @@ func checkFields(ctx context.Context, repo *repository.Repository) error {
|
||||
id := 666666
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.LeadsTags,
|
||||
Fields: testLeadsFields.Embedded.CustomFields,
|
||||
})
|
||||
err = repo.AmoRepo.CheckFields(ctx, tools.ToField(testLeadsFields.Embedded.CustomFields, model.LeadsTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CompaniesTags,
|
||||
Fields: testCompaniesFields.Embedded.CustomFields,
|
||||
})
|
||||
err = repo.AmoRepo.CheckFields(ctx, tools.ToField(testCompaniesFields.Embedded.CustomFields, model.CompaniesTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CustomersTags,
|
||||
Fields: testCustomersFields.Embedded.CustomFields,
|
||||
})
|
||||
err = repo.AmoRepo.CheckFields(ctx, tools.ToField(testCustomersFields.Embedded.CustomFields, model.CustomersTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.ContactsTags,
|
||||
Fields: testContactsFields.Embedded.CustomFields,
|
||||
})
|
||||
err = repo.AmoRepo.CheckFields(ctx, tools.ToField(testContactsFields.Embedded.CustomFields, model.ContactsTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -543,39 +454,22 @@ func checkFields(ctx context.Context, repo *repository.Repository) error {
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.LeadsTags,
|
||||
Fields: testLeadsFields2.Embedded.CustomFields,
|
||||
})
|
||||
err = repo.AmoRepo.CheckFields(ctx, tools.ToField(testLeadsFields2.Embedded.CustomFields, model.LeadsTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CompaniesTags,
|
||||
Fields: testCompaniesFields2.Embedded.CustomFields,
|
||||
})
|
||||
err = repo.AmoRepo.CheckFields(ctx, tools.ToField(testCompaniesFields2.Embedded.CustomFields, model.CompaniesTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.CustomersTags,
|
||||
Fields: testCustomersFields2.Embedded.CustomFields,
|
||||
})
|
||||
err = repo.AmoRepo.CheckFields(ctx, tools.ToField(testCustomersFields2.Embedded.CustomFields, model.CustomersTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.AmoRepo.CheckFields(ctx, tools.ToField(testContactsFields2.Embedded.CustomFields, model.ContactsTags, id), accID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repo.CheckFields(ctx, repository.CheckFieldsDeps{
|
||||
AccountID: accID,
|
||||
ID: id,
|
||||
EntityType: amo.ContactsTags,
|
||||
Fields: testContactsFields2.Embedded.CustomFields,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -584,14 +478,14 @@ func checkFields(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingFieldsFromCash(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
func gettingFieldsFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 73; i++ {
|
||||
req := models.PaginationReq{
|
||||
req := model.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingFieldsFromCash(ctx, &req)
|
||||
resp, err := repo.AmoRepo.GettingFieldsFromCash(ctx, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -603,10 +497,10 @@ func gettingFieldsFromCash(ctx context.Context, t *testing.T, repo *repository.R
|
||||
return nil
|
||||
}
|
||||
|
||||
func webhookCreate(ctx context.Context, repo *repository.Repository) error {
|
||||
func webhookCreate(ctx context.Context, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err := repo.WebhookCreate(ctx, models.Token{
|
||||
err := repo.AmoRepo.WebhookCreate(ctx, model.Token{
|
||||
RefreshToken: faker.UUID(),
|
||||
AccessToken: faker.UUID(),
|
||||
AccountID: accID,
|
||||
@ -621,10 +515,10 @@ func webhookCreate(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func webhookUpdate(ctx context.Context, repo *repository.Repository) error {
|
||||
func webhookUpdate(ctx context.Context, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
accID := strconv.Itoa(i)
|
||||
err := repo.WebhookUpdate(ctx, models.Token{
|
||||
err := repo.AmoRepo.WebhookUpdate(ctx, model.Token{
|
||||
RefreshToken: faker.UUID(),
|
||||
AccessToken: faker.UUID(),
|
||||
AccountID: accID,
|
||||
@ -638,8 +532,8 @@ func webhookUpdate(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkExpired(ctx context.Context, repo *repository.Repository) ([]models.Token, error) {
|
||||
tokens, err := repo.CheckExpired(ctx)
|
||||
func checkExpired(ctx context.Context, repo *dal.AmoDal) ([]model.Token, error) {
|
||||
tokens, err := repo.AmoRepo.CheckExpired(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -647,8 +541,8 @@ func checkExpired(ctx context.Context, repo *repository.Repository) ([]models.To
|
||||
return tokens, nil
|
||||
}
|
||||
|
||||
func getAllTokens(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
tokens, err := repo.GetAllTokens(ctx)
|
||||
func getAllTokens(ctx context.Context, t *testing.T, repo *dal.AmoDal) error {
|
||||
tokens, err := repo.AmoRepo.GetAllTokens(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -657,22 +551,22 @@ func getAllTokens(ctx context.Context, t *testing.T, repo *repository.Repository
|
||||
return nil
|
||||
}
|
||||
|
||||
func saveUtms(ctx context.Context, repo *repository.Repository) error {
|
||||
func saveUtms(ctx context.Context, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 10; i++ {
|
||||
var utms []models.UTM
|
||||
var utms []model.UTM
|
||||
quizId := i
|
||||
for j := 1; j < 50; j++ {
|
||||
utm := models.UTM{
|
||||
utm := model.UTM{
|
||||
Name: strconv.Itoa(i),
|
||||
Quizid: j,
|
||||
Accountid: faker.Int(),
|
||||
Amofieldid: j,
|
||||
Createdat: time.Now().Unix(),
|
||||
ID: strconv.Itoa(i),
|
||||
ID: i,
|
||||
}
|
||||
utms = append(utms, utm)
|
||||
}
|
||||
resp, err := repo.SavingUserUtm(ctx, &models.SaveUserListUTMReq{
|
||||
resp, err := repo.AmoRepo.SavingUserUtm(ctx, &model.SaveUserListUTMReq{
|
||||
Utms: utms,
|
||||
}, strconv.Itoa(i), quizId)
|
||||
if err != nil {
|
||||
@ -684,14 +578,14 @@ func saveUtms(ctx context.Context, repo *repository.Repository) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func gettingUserUtm(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
func gettingUserUtm(ctx context.Context, t *testing.T, repo *dal.AmoDal) error {
|
||||
for i := 1; i < 50; i++ {
|
||||
req := models.PaginationReq{
|
||||
req := model.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingUserUtm(ctx, &req, "1", 1)
|
||||
resp, err := repo.AmoRepo.GettingUserUtm(ctx, &req, "1", 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -703,35 +597,35 @@ func gettingUserUtm(ctx context.Context, t *testing.T, repo *repository.Reposito
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteUserUTM(ctx context.Context, t *testing.T, repo *repository.Repository) error {
|
||||
req := models.PaginationReq{
|
||||
func deleteUserUTM(ctx context.Context, t *testing.T, repo *dal.AmoDal) error {
|
||||
req := model.PaginationReq{
|
||||
Page: 1,
|
||||
Size: 50,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingUserUtm(ctx, &req, "5", 5)
|
||||
resp, err := repo.AmoRepo.GettingUserUtm(ctx, &req, "5", 5)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var fordetete []string
|
||||
var fordetete []int
|
||||
for _, r := range resp.Items {
|
||||
fordetete = append(fordetete, r.ObjId)
|
||||
fordetete = append(fordetete, r.ID)
|
||||
}
|
||||
err = repo.DeletingUserUtm(ctx, &models.ListDeleteUTMIDsReq{
|
||||
err = repo.AmoRepo.DeletingUserUtm(ctx, &model.ListDeleteUTMIDsReq{
|
||||
fordetete,
|
||||
}, 5)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 1; i < 50; i++ {
|
||||
req := models.PaginationReq{
|
||||
req := model.PaginationReq{
|
||||
Page: 1,
|
||||
Size: i,
|
||||
}
|
||||
|
||||
resp, err := repo.GettingUserUtm(ctx, &req, "5", 5)
|
||||
resp, err := repo.AmoRepo.GettingUserUtm(ctx, &req, "5", 5)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user