merge domain to fixPagination
This commit is contained in:
commit
d7fd0c002c
3
go.mod
3
go.mod
@ -13,8 +13,7 @@ require (
|
||||
github.com/twmb/franz-go v1.16.1
|
||||
go.uber.org/zap v1.27.0
|
||||
google.golang.org/protobuf v1.33.0
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240605174203-7b3d9e21ed2b
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608115230-da2584a374f6
|
||||
)
|
||||
|
||||
require (
|
||||
|
10
go.sum
10
go.sum
@ -132,11 +132,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA=
|
||||
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-20240604155436-38f4528609d7 h1:rwocr+GsnkSYV/lif9Li+yc7rEqlciEBGkM2wc8lsNw=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240604155436-38f4528609d7/go.mod h1:G1ZAWaQq6WW1wG9Shy57K4ZIezuhaBckQgsqQ+lhe94=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240604224009-95703fcd61a5 h1:l4icPXyhkCCp9ivRUkir34fsqiWzMDhs1rGUb9lQa7U=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240604224009-95703fcd61a5/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240605174203-7b3d9e21ed2b h1:z9tCPsW39/PMwBsqOc0uDS32ccs5z5wf4JRbbmYl/AA=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240605174203-7b3d9e21ed2b/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
|
||||
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=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608115230-da2584a374f6 h1:IKvZcF5A5lXwVH2nW8GR/pvH5sCR0iPmzDglBaQzO9k=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240608115230-da2584a374f6/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
|
||||
|
@ -71,7 +71,6 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro
|
||||
rateLimiter := limiter.NewRateLimiter(ctx, 6, 1500*time.Millisecond)
|
||||
|
||||
amoClient := amoClient.NewAmoClient(amoClient.AmoDeps{
|
||||
BaseApiURL: config.ApiURL,
|
||||
Logger: logger,
|
||||
RedirectionURL: config.ReturnURL,
|
||||
IntegrationID: config.IntegrationID,
|
||||
|
@ -1,8 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (c *Controller) GetFieldsWithPagination(ctx *fiber.Ctx) error {
|
||||
@ -18,7 +20,12 @@ func (c *Controller) GetFieldsWithPagination(ctx *fiber.Ctx) error {
|
||||
|
||||
response, err := c.service.GetFieldsWithPagination(ctx.Context(), req, accountID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
switch {
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("fields for this user not found")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
@ -35,5 +42,6 @@ func (c *Controller) UpdateListCustom(ctx *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (c *Controller) UpdateListPipelines(ctx *fiber.Ctx) error {
|
||||
@ -14,10 +16,10 @@ func (c *Controller) UpdateListPipelines(ctx *fiber.Ctx) error {
|
||||
//accountID := "654a8909725f47e926f0bebc"
|
||||
|
||||
err := c.service.UpdateListPipelines(ctx.Context(), accountID)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
@ -34,7 +36,12 @@ func (c *Controller) GetPipelinesWithPagination(ctx *fiber.Ctx) error {
|
||||
|
||||
response, err := c.service.GetPipelinesWithPagination(ctx.Context(), req, accountID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
switch {
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("pipelines for this user not found")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/service_errors"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lib/pq"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -37,7 +37,7 @@ func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
||||
err = c.service.ChangeQuizSettings(ctx.Context(), &request, accountID, quizIDInt)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, service_errors.ErrNotFound):
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("rule not found")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
@ -76,7 +76,7 @@ func (c *Controller) SetQuizSettings(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("quiz settings already exist for accountID %s and quizID %d", accountID, quizIDInt))
|
||||
}
|
||||
switch {
|
||||
case errors.Is(err, service_errors.ErrNotFound):
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("not found user for this rule")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
@ -100,7 +100,7 @@ func (c *Controller) GettingQuizRules(ctx *fiber.Ctx) error {
|
||||
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, service_errors.ErrNotFound):
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("rule not found")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
|
@ -1,8 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -28,9 +30,13 @@ func (c *Controller) GetStepsWithPagination(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
response, err := c.service.GetStepsWithPagination(ctx.Context(), req, accountID, pipelineID)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
switch {
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("steps for this user not found")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
@ -44,9 +50,9 @@ func (c *Controller) UpdateListSteps(ctx *fiber.Ctx) error {
|
||||
//accountID := "654a8909725f47e926f0bebc"
|
||||
|
||||
err := c.service.UpdateListSteps(ctx.Context(), accountID)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (c *Controller) GetTagsWithPagination(ctx *fiber.Ctx) error {
|
||||
@ -18,7 +20,12 @@ func (c *Controller) GetTagsWithPagination(ctx *fiber.Ctx) error {
|
||||
|
||||
response, err := c.service.GetTagsWithPagination(ctx.Context(), req, accountID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
switch {
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("tags for this user not found")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
@ -32,9 +39,9 @@ func (c *Controller) UpdateListTags(ctx *fiber.Ctx) error {
|
||||
//accountID := "654a8909725f47e926f0bebc"
|
||||
|
||||
err := c.service.UpdateListTags(ctx.Context(), accountID)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/service_errors"
|
||||
"errors"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (c *Controller) UpdateListUsers(ctx *fiber.Ctx) error {
|
||||
@ -17,10 +17,10 @@ func (c *Controller) UpdateListUsers(ctx *fiber.Ctx) error {
|
||||
//accountID := "654a8909725f47e926f0bebc"
|
||||
|
||||
err := c.service.UpdateListUsers(ctx.Context(), accountID)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ func (c *Controller) GetCurrentAccount(ctx *fiber.Ctx) error {
|
||||
response, err := c.service.GetCurrentAccount(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, service_errors.ErrNotFound):
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("user not found")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
@ -81,6 +81,8 @@ func (c *Controller) ConnectAccount(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
//accountID := "64f2cd7a7047f28fdabf6d9e"
|
||||
|
||||
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
c.logger.Error("error connect account", zap.Error(err))
|
||||
|
@ -29,9 +29,9 @@ func (c *WebhookController) WebhookCreate(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
if accountID == "" {
|
||||
c.logger.Error("error account id do not be nil", zap.Error(err))
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("nil account id")
|
||||
if accountID == "" || code == "" || referer == "" {
|
||||
c.logger.Error("error required fields do not be nil", zap.Error(err))
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("nil required fields")
|
||||
}
|
||||
|
||||
req := service.ParamsWebhookCreate{
|
||||
|
@ -21,7 +21,6 @@ type Config struct {
|
||||
PenaSocialAuthURL string `env:"PENA_SOCIAL_AUTH_URL" envDefault:"http://localhost:8000/amocrm/auth"`
|
||||
// урл на который будет возвращен пользователь после авторизации это webhook/create get
|
||||
ReturnURL string `env:"RETURN_URL" envDefault:"https://squiz.pena.digital/squiz/amocrm/oauth"`
|
||||
ApiURL string `env:"API_URL" envDefault:"https://penadigitaltech.amocrm.ru"`
|
||||
// id интеграции
|
||||
IntegrationID string `env:"INTEGRATION_ID" envDefault:"2dbd6329-9be6-41f2-aa5f-964b9e723e49"`
|
||||
// секрет интеграции
|
||||
|
@ -4,12 +4,14 @@ type SaveDeal struct {
|
||||
AnswerID int64
|
||||
DealID int32
|
||||
AccessToken string
|
||||
SubDomain string
|
||||
}
|
||||
|
||||
type MappingDealsData struct {
|
||||
AnswerID int64
|
||||
DealID int32
|
||||
LeadFields []FieldsValues
|
||||
SubDomain string
|
||||
}
|
||||
|
||||
type ForRestoringData struct {
|
||||
|
@ -3,10 +3,11 @@ package models
|
||||
import "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
|
||||
type KafkaMessage struct {
|
||||
AccountID string
|
||||
AuthCode *string
|
||||
Type MessageType
|
||||
Rule KafkaRule
|
||||
AccountID string
|
||||
AuthCode string
|
||||
RefererURL string
|
||||
Type MessageType
|
||||
Rule KafkaRule
|
||||
}
|
||||
|
||||
type KafkaRule struct {
|
||||
|
@ -121,6 +121,7 @@ func (r *Repository) FetchingDeals(ctx context.Context) (map[string][]models.Map
|
||||
AnswerID: saveDeal.AnswerID,
|
||||
DealID: saveDeal.DealID,
|
||||
LeadFields: leadFields,
|
||||
SubDomain: saveDeal.SubDomain,
|
||||
})
|
||||
|
||||
forRestoringMap[saveDeal.DealID] = models.ForRestoringData{
|
||||
|
@ -3,13 +3,18 @@ package service
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"database/sql"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (s *Service) GetFieldsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListFieldsResp, error) {
|
||||
response, err := s.repository.AmoRepo.GetFieldsWithPagination(ctx, req, accountID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error getting fields with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,8 +3,10 @@ package service
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"database/sql"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (s *Service) UpdateListPipelines(ctx context.Context, accountID string) error {
|
||||
@ -25,6 +27,9 @@ func (s *Service) UpdateListPipelines(ctx context.Context, accountID string) err
|
||||
func (s *Service) GetPipelinesWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListPipelinesResp, error) {
|
||||
response, err := s.repository.AmoRepo.GetPipelinesWithPagination(ctx, req, accountID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error getting pipelines with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,18 +2,18 @@ package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/service_errors"
|
||||
"context"
|
||||
"database/sql"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (s *Service) ChangeQuizSettings(ctx context.Context, request *model.RulesReq, accountID string, quizID int) error {
|
||||
err := s.repository.AmoRepo.ChangeQuizSettings(ctx, request, accountID, quizID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return service_errors.ErrNotFound
|
||||
return pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error change quiz settings", zap.Error(err))
|
||||
return err
|
||||
@ -46,7 +46,7 @@ func (s *Service) SetQuizSettings(ctx context.Context, request *model.RulesReq,
|
||||
err := s.repository.AmoRepo.SetQuizSettings(ctx, request, accountID, quizID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return service_errors.ErrNotFound
|
||||
return pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error setting quiz settings", zap.Error(err))
|
||||
return err
|
||||
@ -79,7 +79,7 @@ func (s *Service) GettingQuizRules(ctx context.Context, quizID int) (*model.Rule
|
||||
rule, err := s.repository.AmoRepo.GettingQuizRules(ctx, quizID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, service_errors.ErrNotFound
|
||||
return nil, pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error getting quiz settings", zap.Error(err))
|
||||
return nil, err
|
||||
|
@ -3,13 +3,18 @@ package service
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"database/sql"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (s *Service) GetStepsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string, pipelineID int) (*model.UserListStepsResp, error) {
|
||||
response, err := s.repository.AmoRepo.GetStepsWithPagination(ctx, req, accountID, int32(pipelineID))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error getting steps with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,13 +3,18 @@ package service
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"database/sql"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (s *Service) GetTagsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListTagsResp, error) {
|
||||
response, err := s.repository.AmoRepo.GetTagsWithPagination(ctx, req, accountID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error getting tags with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,11 +2,11 @@ package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/service_errors"
|
||||
"context"
|
||||
"database/sql"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (s *Service) UpdateListUsers(ctx context.Context, accountID string) error {
|
||||
@ -46,7 +46,7 @@ func (s *Service) GetCurrentAccount(ctx context.Context, accountID string) (*mod
|
||||
user, err := s.repository.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, service_errors.ErrNotFound
|
||||
return nil, pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error getting current account in getCurrentAccount service", zap.Error(err))
|
||||
return nil, err
|
||||
|
@ -16,9 +16,10 @@ type ParamsWebhookCreate struct {
|
||||
|
||||
func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) error {
|
||||
message := models.KafkaMessage{
|
||||
AccountID: req.AccountID,
|
||||
AuthCode: &req.Code,
|
||||
Type: models.UserCreate,
|
||||
AccountID: req.AccountID,
|
||||
AuthCode: req.Code,
|
||||
RefererURL: req.Referer,
|
||||
Type: models.UserCreate,
|
||||
}
|
||||
|
||||
err := s.producer.ToKafkaUpdate(ctx, message)
|
||||
|
@ -1,5 +0,0 @@
|
||||
package service_errors
|
||||
|
||||
import "errors"
|
||||
|
||||
var ErrNotFound = errors.New("not found")
|
@ -63,6 +63,7 @@ func (wc *PostDeals) startFetching(ctx context.Context) {
|
||||
}
|
||||
|
||||
mapDealReq := make(map[string][]models.DealReq)
|
||||
mapTokenDomain := make(map[string]string)
|
||||
|
||||
for _, result := range results {
|
||||
allAnswers, err := wc.amoRepo.AnswerRepo.GetAllAnswersByQuizID(ctx, result.Session)
|
||||
@ -102,7 +103,7 @@ func (wc *PostDeals) startFetching(ctx context.Context) {
|
||||
|
||||
utmFields := tools.ConstructUTMFields(result.UTMs, currentFields)
|
||||
|
||||
_, err = wc.amoClient.CreatingCustomer(customerToCreate, result.AccessToken)
|
||||
_, err = wc.amoClient.CreatingCustomer(customerToCreate, result.AccessToken, result.SubDomain)
|
||||
if err != nil {
|
||||
wc.logger.Error("error sending requests for create customer", zap.Error(err))
|
||||
return
|
||||
@ -120,7 +121,7 @@ func (wc *PostDeals) startFetching(ctx context.Context) {
|
||||
|
||||
if len(mapDealReq[result.AccessToken]) >= 49 {
|
||||
wc.logger.Info("reached maximum number of deals for access token", zap.String("access_token", result.AccessToken))
|
||||
err = wc.sendingDealsReq(ctx, mapDealReq)
|
||||
err = wc.sendingDealsReq(ctx, mapDealReq, mapTokenDomain)
|
||||
if err != nil {
|
||||
wc.logger.Error("error sending requests for create deals", zap.Error(err))
|
||||
return
|
||||
@ -129,24 +130,26 @@ func (wc *PostDeals) startFetching(ctx context.Context) {
|
||||
}
|
||||
|
||||
mapDealReq[result.AccessToken] = append(mapDealReq[result.AccessToken], deal)
|
||||
mapTokenDomain[result.AccessToken] = result.SubDomain
|
||||
}
|
||||
|
||||
err = wc.sendingDealsReq(ctx, mapDealReq)
|
||||
err = wc.sendingDealsReq(ctx, mapDealReq, mapTokenDomain)
|
||||
if err != nil {
|
||||
wc.logger.Error("error send requests for create deals", zap.Error(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (wc *PostDeals) sendingDealsReq(ctx context.Context, mapDealReq map[string][]models.DealReq) error {
|
||||
func (wc *PostDeals) sendingDealsReq(ctx context.Context, mapDealReq map[string][]models.DealReq, mapTokenDomain map[string]string) error {
|
||||
for accessToken, deal := range mapDealReq {
|
||||
resp, err := wc.amoClient.CreatingDeal(deal, accessToken)
|
||||
subDomain := mapTokenDomain[accessToken]
|
||||
resp, err := wc.amoClient.CreatingDeal(deal, accessToken, subDomain)
|
||||
if err != nil {
|
||||
// todo логирование в тг
|
||||
wc.logger.Error("error creating deal in amo", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
err = wc.saveDealToDB(ctx, resp, accessToken)
|
||||
err = wc.saveDealToDB(ctx, resp, accessToken, subDomain)
|
||||
if err != nil {
|
||||
wc.logger.Error("error saving resp data to db", zap.Error(err))
|
||||
return err
|
||||
@ -155,7 +158,7 @@ func (wc *PostDeals) sendingDealsReq(ctx context.Context, mapDealReq map[string]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wc *PostDeals) saveDealToDB(ctx context.Context, resp []models.DealResp, accessToken string) error {
|
||||
func (wc *PostDeals) saveDealToDB(ctx context.Context, resp []models.DealResp, accessToken string, subDomain string) error {
|
||||
status := "pending"
|
||||
for _, dealResp := range resp {
|
||||
requestID := strings.Join(dealResp.RequestID, ",")
|
||||
@ -175,6 +178,7 @@ func (wc *PostDeals) saveDealToDB(ctx context.Context, resp []models.DealResp, a
|
||||
AnswerID: answerID,
|
||||
DealID: dealResp.DealID,
|
||||
AccessToken: accessToken,
|
||||
SubDomain: subDomain,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -80,8 +80,10 @@ func (wc *PostFields) processTask(ctx context.Context) {
|
||||
|
||||
func (wc *PostFields) sendForUpdate(ctx context.Context, token string, dealsData []models.MappingDealsData) (map[int32]struct{}, error) {
|
||||
errorCheckerMap := make(map[int32]struct{})
|
||||
var subDomain string
|
||||
var reqToUpdate []models.UpdateDealReq
|
||||
for _, data := range dealsData {
|
||||
subDomain = data.SubDomain
|
||||
req := models.UpdateDealReq{
|
||||
DealID: data.DealID,
|
||||
CustomFieldsValues: data.LeadFields,
|
||||
@ -89,7 +91,7 @@ func (wc *PostFields) sendForUpdate(ctx context.Context, token string, dealsData
|
||||
reqToUpdate = append(reqToUpdate, req)
|
||||
}
|
||||
|
||||
resp, errResp := wc.amoClient.UpdatingDeal(reqToUpdate, token)
|
||||
resp, errResp := wc.amoClient.UpdatingDeal(reqToUpdate, token, subDomain)
|
||||
if errResp != nil {
|
||||
// todo также логирование ошибки в тг
|
||||
wc.logger.Error("error sendig request for update deal fields", zap.Error(errResp))
|
||||
|
@ -129,13 +129,10 @@ func (wc *QueueUpdater) processMessages(ctx context.Context, message models.Kafk
|
||||
}
|
||||
|
||||
case models.UserCreate:
|
||||
if message.AuthCode == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
token, err := wc.methods.CreateUserFromWebHook(ctx, message.AccountID, *message.AuthCode)
|
||||
token, err := wc.methods.CreateUserFromWebHook(ctx, message)
|
||||
if err != nil {
|
||||
wc.logger.Error("error creating user from webhook request", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if token == nil {
|
||||
@ -215,7 +212,7 @@ func (wc *QueueUpdater) processMessages(ctx context.Context, message models.Kafk
|
||||
return err
|
||||
}
|
||||
|
||||
err = wc.methods.CheckFieldRule(ctx, token.AccessToken, message.AccountID, message.Rule)
|
||||
err = wc.methods.CheckFieldRule(ctx, token.AccessToken, message)
|
||||
if err != nil {
|
||||
wc.logger.Error("error check field rules for fields rules", zap.Error(err))
|
||||
return err
|
||||
|
@ -41,12 +41,17 @@ func (m *Methods) UpdateTokens(ctx context.Context) ([]model.Token, error) {
|
||||
}
|
||||
|
||||
for _, oldToken := range allTokens {
|
||||
user, err := m.repo.AmoRepo.GetCurrentAccount(ctx, oldToken.AccountID)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting account by id in UpdateTokens", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
req := models.UpdateWebHookReq{
|
||||
GrantType: "refresh_token",
|
||||
RefreshToken: oldToken.RefreshToken,
|
||||
}
|
||||
|
||||
resp, err := m.amoClient.CreateWebHook(&req)
|
||||
resp, err := m.amoClient.CreateWebHook(&req, user.Subdomain)
|
||||
if err != nil {
|
||||
m.logger.Error("error create webhook in UpdateTokens", zap.Error(err))
|
||||
continue
|
||||
@ -79,12 +84,18 @@ func (m *Methods) UpdateTokens(ctx context.Context) ([]model.Token, error) {
|
||||
func (m *Methods) CheckUsers(ctx context.Context, allTokens []model.Token) error {
|
||||
listUser := make(map[string][]models.Users)
|
||||
for _, token := range allTokens {
|
||||
user, err := m.repo.AmoRepo.GetCurrentAccount(ctx, token.AccountID)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting account by id in CheckUsers", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
page := 1
|
||||
limit := 250
|
||||
userData, err := m.amoClient.GetUserList(models.RequestGetListUsers{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
}, token.AccessToken)
|
||||
}, token.AccessToken, user.Subdomain)
|
||||
if err != nil {
|
||||
m.logger.Error("error fetching list users", zap.Error(err))
|
||||
break
|
||||
@ -177,7 +188,7 @@ func (m *Methods) CheckPipelinesAndSteps(ctx context.Context, tokens []model.Tok
|
||||
|
||||
var receivedSteps []model.Step
|
||||
|
||||
pipelines, err := m.amoClient.GetListPipelines(token.AccessToken)
|
||||
pipelines, err := m.amoClient.GetListPipelines(token.AccessToken, user.Subdomain)
|
||||
if err != nil {
|
||||
m.logger.Error("error fetching list pipelines from amo", zap.Error(err))
|
||||
continue
|
||||
@ -191,7 +202,7 @@ func (m *Methods) CheckPipelinesAndSteps(ctx context.Context, tokens []model.Tok
|
||||
}
|
||||
|
||||
for _, pipeline := range pipelines.Embedded.Pipelines {
|
||||
steps, err := m.amoClient.GetListSteps(pipeline.ID, token.AccessToken)
|
||||
steps, err := m.amoClient.GetListSteps(pipeline.ID, token.AccessToken, user.Subdomain)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting list steps pipeline:", zap.Error(err))
|
||||
continue
|
||||
@ -286,7 +297,7 @@ func (m *Methods) CheckTags(ctx context.Context, tokens []model.Token) error {
|
||||
Limit: limit,
|
||||
EntityType: entityType,
|
||||
}
|
||||
tags, err := m.amoClient.GetListTags(req, token.AccessToken)
|
||||
tags, err := m.amoClient.GetListTags(req, token.AccessToken, user.Subdomain)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting list of tags", zap.Error(err))
|
||||
return
|
||||
@ -396,7 +407,7 @@ func (m *Methods) CheckFields(ctx context.Context, tokens []model.Token) error {
|
||||
Limit: limit,
|
||||
EntityType: entityType,
|
||||
}
|
||||
fields, err := m.amoClient.GetListFields(req, token.AccessToken)
|
||||
fields, err := m.amoClient.GetListFields(req, token.AccessToken, user.Subdomain)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting list of fields", zap.Error(err))
|
||||
return
|
||||
@ -486,21 +497,21 @@ func (m *Methods) GetTokenByID(ctx context.Context, accountID string) (*model.To
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (m *Methods) CreateUserFromWebHook(ctx context.Context, accountID string, authCode string) (*model.Token, error) {
|
||||
func (m *Methods) CreateUserFromWebHook(ctx context.Context, msg models.KafkaMessage) (*model.Token, error) {
|
||||
// получаем аксес и рефреш токены по коду авторизации
|
||||
forGetTokens := models.CreateWebHookReq{
|
||||
GrantType: "authorization_code",
|
||||
Code: authCode,
|
||||
Code: msg.AuthCode,
|
||||
}
|
||||
|
||||
tokens, err := m.amoClient.CreateWebHook(&forGetTokens)
|
||||
tokens, err := m.amoClient.CreateWebHook(&forGetTokens, msg.RefererURL)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting webhook in CreateUserFromWebHook:", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// получаем информацию о пользователе по аксес токену
|
||||
userInfo, err := m.amoClient.GetUserInfo(tokens.AccessToken)
|
||||
userInfo, err := m.amoClient.GetUserInfo(tokens.AccessToken, msg.RefererURL)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting UserInfo in CreateUserFromWebHook:", zap.Error(err))
|
||||
return nil, err
|
||||
@ -508,13 +519,13 @@ func (m *Methods) CreateUserFromWebHook(ctx context.Context, accountID string, a
|
||||
|
||||
toCreate := model.User{
|
||||
Name: userInfo.Name,
|
||||
Subdomain: userInfo.Subdomain,
|
||||
Subdomain: msg.RefererURL,
|
||||
AmoID: userInfo.ID,
|
||||
Amouserid: userInfo.ID,
|
||||
Country: userInfo.Country,
|
||||
}
|
||||
|
||||
err = m.repo.AmoRepo.CreateAccount(ctx, accountID, toCreate)
|
||||
err = m.repo.AmoRepo.CreateAccount(ctx, msg.AccountID, toCreate)
|
||||
if err != nil {
|
||||
m.logger.Error("error create account in db in CreateUserFromWebHook", zap.Error(err))
|
||||
return nil, err
|
||||
@ -523,8 +534,8 @@ func (m *Methods) CreateUserFromWebHook(ctx context.Context, accountID string, a
|
||||
err = m.repo.AmoRepo.WebhookCreate(ctx, model.Token{
|
||||
RefreshToken: tokens.RefreshToken,
|
||||
AccessToken: tokens.AccessToken,
|
||||
AccountID: accountID,
|
||||
AuthCode: authCode,
|
||||
AccountID: msg.AccountID,
|
||||
AuthCode: msg.AuthCode,
|
||||
Expiration: time.Now().Unix() + tokens.ExpiresIn,
|
||||
CreatedAt: time.Now().Unix(),
|
||||
})
|
||||
@ -534,85 +545,24 @@ func (m *Methods) CreateUserFromWebHook(ctx context.Context, accountID string, a
|
||||
}
|
||||
|
||||
return &model.Token{
|
||||
AccountID: accountID,
|
||||
AccountID: msg.AccountID,
|
||||
RefreshToken: tokens.RefreshToken,
|
||||
AccessToken: tokens.AccessToken,
|
||||
}, nil
|
||||
}
|
||||
|
||||
//func (m *Methods) CheckUTMs(ctx context.Context, token, accountID string, ids []int32) ([]model.Field, error) {
|
||||
// utms, err := m.repo.AmoRepo.GetUtmsByID(ctx, ids)
|
||||
// if err != nil {
|
||||
// m.logger.Error("error getting user UTM byList IDs", zap.Error(err))
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// user, err := m.repo.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||
// if err != nil {
|
||||
// m.logger.Error("error getting user data by account id in check utms wc method", zap.Error(err))
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// fields, err := m.repo.AmoRepo.GetUserFieldsByID(ctx, user.AmoID)
|
||||
// if err != nil {
|
||||
// m.logger.Error("error getting user fields by amo account id", zap.Error(err))
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// if len(utms) < 0 {
|
||||
// return fields, nil
|
||||
// }
|
||||
//
|
||||
// toCreated, toUpdate := tools.ToCreatedUpdate(utms, fields)
|
||||
//
|
||||
// if len(toUpdate) > 0 {
|
||||
// err = m.repo.AmoRepo.UpdateUtmsFields(ctx, toUpdate)
|
||||
// if err != nil {
|
||||
// m.logger.Error("error update utms fields in db", zap.Error(err))
|
||||
// return nil, err
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if len(toCreated) > 0 {
|
||||
// createdFields, err := m.amoClient.AddFields(toCreated, model.LeadsType, token)
|
||||
// if err != nil {
|
||||
// m.logger.Error("error created amo fields", zap.Error(err))
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// newFields := tools.ToField(createdFields.Embedded.CustomFields, model.LeadsType)
|
||||
//
|
||||
// err = m.repo.AmoRepo.CheckFields(ctx, newFields, accountID)
|
||||
// if err != nil {
|
||||
// m.logger.Error("error created amo fields in db", zap.Error(err))
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// forUpdate := tools.MatchingUTMs(utms, createdFields.Embedded.CustomFields)
|
||||
// err = m.repo.AmoRepo.UpdateUTMs(ctx, forUpdate)
|
||||
// if err != nil {
|
||||
// m.logger.Error("error update utms in db", zap.Error(err))
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// fields = append(fields, newFields...)
|
||||
// }
|
||||
//
|
||||
// return fields, nil
|
||||
//}
|
||||
|
||||
func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID string, req models.KafkaRule) error {
|
||||
func (m *Methods) CheckFieldRule(ctx context.Context, token string, msg models.KafkaMessage) error {
|
||||
var (
|
||||
leadIDs, companyIDs, customerIDs []int32
|
||||
leadQuestions, companyQuestions, customerQuestions []model.Question
|
||||
questionsTypeMap = make(map[model.EntityType][]model.Question)
|
||||
newFields []model.Field
|
||||
lead, company, customer []model.FieldRule
|
||||
currentFieldsRule = req.Fieldsrule
|
||||
currentFieldsRule = msg.Rule.Fieldsrule
|
||||
err error
|
||||
)
|
||||
|
||||
user, err := m.repo.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||
user, err := m.repo.AmoRepo.GetCurrentAccount(ctx, msg.AccountID)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting user data by account id in check utms wc method", zap.Error(err))
|
||||
return err
|
||||
@ -624,7 +574,7 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID st
|
||||
return err
|
||||
}
|
||||
|
||||
quiz, err := m.repo.QuizRepo.GetQuizById(ctx, accountID, uint64(req.QuizID))
|
||||
quiz, err := m.repo.QuizRepo.GetQuizById(ctx, msg.AccountID, uint64(msg.Rule.QuizID))
|
||||
if err != nil {
|
||||
m.logger.Error("error getting quiz by quizID and accountID", zap.Error(err))
|
||||
return err
|
||||
@ -637,9 +587,9 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID st
|
||||
return err
|
||||
}
|
||||
|
||||
leadIDs = tools.ToQuestionIDs(req.Fieldsrule.Lead)
|
||||
customerIDs = tools.ToQuestionIDs(req.Fieldsrule.Customer)
|
||||
companyIDs = tools.ToQuestionIDs(req.Fieldsrule.Company)
|
||||
leadIDs = tools.ToQuestionIDs(msg.Rule.Fieldsrule.Lead)
|
||||
customerIDs = tools.ToQuestionIDs(msg.Rule.Fieldsrule.Customer)
|
||||
companyIDs = tools.ToQuestionIDs(msg.Rule.Fieldsrule.Company)
|
||||
|
||||
getQuestions := func(questionIDs []int32, questions *[]model.Question) {
|
||||
if len(questionIDs) > 0 {
|
||||
@ -667,7 +617,7 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID st
|
||||
continue
|
||||
}
|
||||
|
||||
createdFields, err := m.amoClient.AddFields(fields, entity, token)
|
||||
createdFields, err := m.amoClient.AddFields(fields, entity, token, user.Subdomain)
|
||||
if err != nil {
|
||||
m.logger.Error("error adding fields to amo", zap.Any("type", entity), zap.Error(err))
|
||||
continue
|
||||
@ -676,7 +626,7 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID st
|
||||
}
|
||||
|
||||
if len(contactFieldsToCreate) > 0 {
|
||||
createdFields, err := m.amoClient.AddFields(contactFieldsToCreate, model.ContactsType, token)
|
||||
createdFields, err := m.amoClient.AddFields(contactFieldsToCreate, model.ContactsType, token, user.Subdomain)
|
||||
if err != nil {
|
||||
m.logger.Error("error adding fields to amo", zap.Any("type", model.ContactsType), zap.Error(err))
|
||||
}
|
||||
@ -693,7 +643,7 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID st
|
||||
}
|
||||
|
||||
if len(newFields) > 0 {
|
||||
err = m.repo.AmoRepo.CheckFields(ctx, newFields, accountID)
|
||||
err = m.repo.AmoRepo.CheckFields(ctx, newFields, msg.AccountID)
|
||||
if err != nil {
|
||||
m.logger.Error("error updating fields rule in db Check Fields", zap.Error(err))
|
||||
return err
|
||||
@ -733,7 +683,7 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, accountID st
|
||||
Customer: customer,
|
||||
Company: company,
|
||||
Contact: model.ContactRules{ContactRuleMap: forAdding},
|
||||
}, accountID, req.QuizID)
|
||||
}, msg.AccountID, msg.Rule.QuizID)
|
||||
|
||||
if err != nil {
|
||||
m.logger.Error("error updating fields rule in db", zap.Error(err))
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
)
|
||||
|
||||
type Amo struct {
|
||||
baseApiURL string
|
||||
fiberClient *fiber.Client
|
||||
logger *zap.Logger
|
||||
redirectionURL string
|
||||
@ -32,7 +31,6 @@ type Amo struct {
|
||||
}
|
||||
|
||||
type AmoDeps struct {
|
||||
BaseApiURL string
|
||||
FiberClient *fiber.Client
|
||||
Logger *zap.Logger
|
||||
RedirectionURL string
|
||||
@ -47,7 +45,6 @@ func NewAmoClient(deps AmoDeps) *Amo {
|
||||
deps.FiberClient = fiber.AcquireClient()
|
||||
}
|
||||
return &Amo{
|
||||
baseApiURL: deps.BaseApiURL,
|
||||
fiberClient: deps.FiberClient,
|
||||
logger: deps.Logger,
|
||||
redirectionURL: deps.RedirectionURL,
|
||||
@ -60,10 +57,10 @@ func NewAmoClient(deps AmoDeps) *Amo {
|
||||
|
||||
// токен должен быть с правами администратора
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/users-api#users-list
|
||||
func (a *Amo) GetUserList(req models.RequestGetListUsers, accesToken string) (*models.ResponseGetListUsers, error) {
|
||||
func (a *Amo) GetUserList(req models.RequestGetListUsers, accesToken string, domain string) (*models.ResponseGetListUsers, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("https://penadigitaltech.amocrm.ru/ajax/v3/users?with=rights&page=%d&limit=%d", req.Page, req.Limit)
|
||||
uri := fmt.Sprintf("https://%s/ajax/v3/users?with=rights&page=%d&limit=%d", domain, req.Page, req.Limit)
|
||||
|
||||
agent := a.fiberClient.Get(uri)
|
||||
agent.Set("Authorization", "Bearer "+accesToken)
|
||||
@ -109,7 +106,7 @@ func (a *Amo) GetUserList(req models.RequestGetListUsers, accesToken string) (*m
|
||||
// https://www.amocrm.ru/developers/content/oauth/step-by-step
|
||||
// POST /oauth2/access_token
|
||||
// тут и создание по коду и обновление по рефрешу в этом клиенте
|
||||
func (a *Amo) CreateWebHook(req models.WebHookRequest) (*models.CreateWebHookResp, error) {
|
||||
func (a *Amo) CreateWebHook(req models.WebHookRequest, domain string) (*models.CreateWebHookResp, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
req.SetClientID(a.integrationID)
|
||||
@ -120,8 +117,7 @@ func (a *Amo) CreateWebHook(req models.WebHookRequest) (*models.CreateWebHookRes
|
||||
a.logger.Error("error marshal req in CreateWebHook:", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
agent := a.fiberClient.Post(a.baseApiURL + "/oauth2/access_token")
|
||||
agent := a.fiberClient.Post("https://" + domain + "/oauth2/access_token")
|
||||
agent.Set("Content-Type", "application/json").Body(bodyBytes)
|
||||
|
||||
statusCode, resBody, errs := agent.Bytes()
|
||||
@ -153,10 +149,10 @@ func (a *Amo) CreateWebHook(req models.WebHookRequest) (*models.CreateWebHookRes
|
||||
|
||||
// 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) (*models.ResponseGetListSteps, error) {
|
||||
func (a *Amo) GetListSteps(pipelineID int, accessToken string, domain string) (*models.ResponseGetListSteps, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/leads/pipelines/%d/statuses", a.baseApiURL, pipelineID)
|
||||
uri := fmt.Sprintf("https://%s/api/v4/leads/pipelines/%d/statuses", domain, pipelineID)
|
||||
agent := a.fiberClient.Get(uri)
|
||||
agent.Set("Authorization", "Bearer "+accessToken)
|
||||
statusCode, resBody, errs := agent.Bytes()
|
||||
@ -196,10 +192,10 @@ func (a *Amo) GetListSteps(pipelineID int, accessToken string) (*models.Response
|
||||
// GET /api/v4/customers/segments/custom_fields
|
||||
// GET /api/v4/catalogs/{catalog_id}/custom_fields
|
||||
// эти методы все относятся к одному и тому же, поэтому на вход будет урл и рек стуктура, выход у них один и тот же
|
||||
func (a *Amo) GetListFields(req models.GetListFieldsReq, accessToken string) (*models.ResponseGetListFields, error) {
|
||||
func (a *Amo) GetListFields(req models.GetListFieldsReq, accessToken string, domain 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)
|
||||
fullURL := fmt.Sprintf("https://%s/api/v4/%s/custom_fields?limit=%d&page=%d", domain, req.EntityType, req.Limit, req.Page)
|
||||
agent := a.fiberClient.Get(fullURL)
|
||||
agent.Set("Authorization", "Bearer "+accessToken)
|
||||
statusCode, resBody, errs := agent.Bytes()
|
||||
@ -231,10 +227,10 @@ func (a *Amo) GetListFields(req models.GetListFieldsReq, accessToken string) (*m
|
||||
|
||||
// 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 models.GetListTagsReq, accessToken string) (*models.ResponseGetListTags, error) {
|
||||
func (a *Amo) GetListTags(req models.GetListTagsReq, accessToken string, domain string) (*models.ResponseGetListTags, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
fullURL := fmt.Sprintf("%s/api/v4/%s/tags?", a.baseApiURL, req.EntityType)
|
||||
fullURL := fmt.Sprintf("https://%s/api/v4/%s/tags?", domain, req.EntityType)
|
||||
|
||||
if req.Filter.Name != "" {
|
||||
fullURL += "&filter[name]=" + url.QueryEscape(req.Filter.Name)
|
||||
@ -281,10 +277,10 @@ func (a *Amo) GetListTags(req models.GetListTagsReq, accessToken string) (*model
|
||||
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/account-info
|
||||
// GET /api/v4/account
|
||||
func (a *Amo) GetUserInfo(accessToken string) (*models.AmocrmUserInformation, error) {
|
||||
func (a *Amo) GetUserInfo(accessToken string, domain string) (*models.AmocrmUserInformation, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
url := fmt.Sprintf("%s/api/v4/account", a.baseApiURL)
|
||||
url := fmt.Sprintf("https://%s/api/v4/account", domain)
|
||||
agent := a.fiberClient.Get(url)
|
||||
agent.Set("Authorization", "Bearer "+accessToken)
|
||||
statusCode, resBody, errs := agent.Bytes()
|
||||
@ -316,10 +312,10 @@ func (a *Amo) GetUserInfo(accessToken string) (*models.AmocrmUserInformation, er
|
||||
|
||||
// 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) (*models.PipelineResponse, error) {
|
||||
func (a *Amo) GetListPipelines(accessToken string, domain string) (*models.PipelineResponse, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/leads/pipelines", a.baseApiURL)
|
||||
uri := fmt.Sprintf("https://%s/api/v4/leads/pipelines", domain)
|
||||
agent := a.fiberClient.Get(uri)
|
||||
agent.Set("Authorization", "Bearer "+accessToken)
|
||||
statusCode, resBody, errs := agent.Bytes()
|
||||
@ -352,10 +348,10 @@ func (a *Amo) GetListPipelines(accessToken string) (*models.PipelineResponse, er
|
||||
// токен должен быть с правами администратора
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/users-api#user-detail
|
||||
// GET /api/v4/users/{id
|
||||
func (a *Amo) GetUserByID(id int32, accessToken string) (*models.OneUserInfo, error) {
|
||||
func (a *Amo) GetUserByID(id int32, accessToken string, domain string) (*models.OneUserInfo, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/users/%d?with=role,uuid", a.baseApiURL, id)
|
||||
uri := fmt.Sprintf("https://%s/api/v4/users/%d?with=role,uuid", domain, id)
|
||||
agent := a.fiberClient.Get(uri)
|
||||
agent.Set("Authorization", "Bearer "+accessToken)
|
||||
statusCode, resBody, errs := agent.Bytes()
|
||||
@ -385,10 +381,10 @@ func (a *Amo) GetUserByID(id int32, accessToken string) (*models.OneUserInfo, er
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Amo) AddFields(req []models.AddLeadsFields, entity model.EntityType, accessToken string) (*models.ResponseGetListFields, error) {
|
||||
func (a *Amo) AddFields(req []models.AddLeadsFields, entity model.EntityType, accessToken string, domain string) (*models.ResponseGetListFields, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/%s/custom_fields", a.baseApiURL, entity)
|
||||
uri := fmt.Sprintf("https://%s/api/v4/%s/custom_fields", domain, entity)
|
||||
bodyBytes, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
a.logger.Error("error marshal req in Add Fields:", zap.Error(err))
|
||||
@ -425,10 +421,10 @@ func (a *Amo) AddFields(req []models.AddLeadsFields, entity model.EntityType, ac
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Amo) CreatingDeal(req []models.DealReq, accessToken string) ([]models.DealResp, error) {
|
||||
func (a *Amo) CreatingDeal(req []models.DealReq, accessToken string, domain string) ([]models.DealResp, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/leads/complex", a.baseApiURL)
|
||||
uri := fmt.Sprintf("https://%s/api/v4/leads/complex", domain)
|
||||
bodyBytes, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
a.logger.Error("error marshal req in Creating Deal:", zap.Error(err))
|
||||
@ -466,10 +462,10 @@ func (a *Amo) CreatingDeal(req []models.DealReq, accessToken string) ([]models.D
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Amo) UpdatingDeal(req []models.UpdateDealReq, accessToken string) (*models.UpdateDealResp, error) {
|
||||
func (a *Amo) UpdatingDeal(req []models.UpdateDealReq, accessToken string, domain string) (*models.UpdateDealResp, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/leads", a.baseApiURL)
|
||||
uri := fmt.Sprintf("https://%s/api/v4/leads", domain)
|
||||
bodyBytes, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
a.logger.Error("error marshal req in Updating Deal:", zap.Error(err))
|
||||
@ -507,10 +503,10 @@ func (a *Amo) UpdatingDeal(req []models.UpdateDealReq, accessToken string) (*mod
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Amo) CreatingCustomer(req []models.Customer, accessToken string) (*models.CustomerResp, error) {
|
||||
func (a *Amo) CreatingCustomer(req []models.Customer, accessToken string, domain string) (*models.CustomerResp, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/customers", a.baseApiURL)
|
||||
uri := fmt.Sprintf("https://%s/api/v4/customers", domain)
|
||||
bodyBytes, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
a.logger.Error("error marshal req in Creating Customer:", zap.Error(err))
|
||||
@ -548,6 +544,7 @@ func (a *Amo) CreatingCustomer(req []models.Customer, accessToken string) (*mode
|
||||
}
|
||||
}
|
||||
|
||||
// todo подумать на счет хранилища в амо
|
||||
func (a *Amo) downloadFile(urlFile string) (*os.File, error) {
|
||||
var err error
|
||||
agent := a.fiberClient.Get(urlFile)
|
||||
|
Loading…
Reference in New Issue
Block a user