some update and add base logic for webhook
This commit is contained in:
parent
3d88dcad04
commit
46447ecdc9
4
go.mod
4
go.mod
@ -8,11 +8,14 @@ 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/core.git v0.0.0-20240219174804-d78fd38511af
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.17.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
@ -32,5 +35,4 @@ require (
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.17.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240408182839-4495237cb30d // indirect
|
||||
)
|
||||
|
24
go.sum
24
go.sum
@ -6,15 +6,15 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
|
||||
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
|
||||
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
|
||||
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
@ -56,8 +56,7 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
@ -74,8 +73,7 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@ -89,11 +87,9 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
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-20240408182839-4495237cb30d h1:zMmE6uS7nG329zQP8GoWhELK+PkthB7QVhLArSpjzHo=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240408182839-4495237cb30d/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=
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/internal/server/http"
|
||||
"amocrm/internal/service"
|
||||
amoClient2 "amocrm/pkg/amoClient"
|
||||
"amocrm/pkg/closer"
|
||||
pena_social_auth "amocrm/pkg/pena-social-auth"
|
||||
"context"
|
||||
@ -41,14 +42,25 @@ func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) erro
|
||||
ReturnURL: config.ReturnURL,
|
||||
})
|
||||
|
||||
amoClient := amoClient2.NewAmoClient(amoClient2.AmoDeps{
|
||||
BaseApiURL: config.ApiURL,
|
||||
Logger: logger,
|
||||
RedirectionURL: config.ReturnURL,
|
||||
IntegrationID: config.IntegrationID,
|
||||
IntegrationSecret: config.IntegrationSecret,
|
||||
})
|
||||
|
||||
repo := repository.NewRepository(repository.Deps{
|
||||
MdbUser: mdb.Collection("amoUsers"),
|
||||
Tokens: mdb.Collection("tokens"),
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
svc := service.NewService(service.Deps{
|
||||
Repository: repo,
|
||||
Logger: logger,
|
||||
SocialAuthClient: socialAithClient,
|
||||
AmoClient: amoClient,
|
||||
})
|
||||
|
||||
controller := controllers.NewController(controllers.Deps{
|
||||
|
@ -1,331 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/middleware"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Service *service.Service
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
service *service.Service
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewController(deps Deps) *Controller {
|
||||
return &Controller{
|
||||
service: deps.Service,
|
||||
logger: deps.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) Register(router fiber.Router) {
|
||||
router.Patch("/users", c.UpdateListUsers)
|
||||
router.Get("/users", c.GettingUserFromCash)
|
||||
router.Delete("/utms/:quizID", c.DeletingUserUtm)
|
||||
router.Post("/utms/:quizID", c.SavingUserUtm)
|
||||
router.Get("/utms/:quizID", c.GettingUserUtm)
|
||||
router.Delete("/account", c.SoftDeleteAccount)
|
||||
router.Get("/account", c.GetCurrentAccount)
|
||||
router.Post("/account", c.ConnectAccount)
|
||||
router.Get("/steps", c.GettingStepsFromCash)
|
||||
router.Patch("/steps", c.UpdateListSteps)
|
||||
router.Get("/webhook/create", c.WebhookCreate)
|
||||
router.Get("/webhook/delete", c.WebhookDelete)
|
||||
router.Patch("/pipelines", c.UpdateListPipelines)
|
||||
router.Get("/pipelines", c.GettingPipelinesFromCash)
|
||||
router.Patch("/rules/:quizID", c.ChangeQuizSettings)
|
||||
router.Post("/rules/:quizID", c.SetQuizSettings)
|
||||
router.Get("/rules/:quizID", c.GettingQuizRules)
|
||||
router.Get("/tags", c.GettingTagsFromCash)
|
||||
router.Patch("/tags", c.UpdateListTags)
|
||||
router.Get("/fields", c.GettingFieldsFromCash)
|
||||
router.Patch("/fields", c.UpdateListCustom)
|
||||
}
|
||||
|
||||
func (c *Controller) Name() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListUsers(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListUsers(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingUserFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingUserFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) DeletingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.ListDeleteUTMIDsReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.DeletingUserUtm(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) SavingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.SaveUserListUTMReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
response, err := c.service.SavingUserUtm(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingUserUtm(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) SoftDeleteAccount(ctx *fiber.Ctx) error {
|
||||
err := c.service.SoftDeleteAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GetCurrentAccount(ctx *fiber.Ctx) error {
|
||||
response, err := c.service.GetCurrentAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
// при запросе на этот контроллер приходит только токен из которого получаем id аккаунта в ис
|
||||
// отдает ссылку на подключение к amocrm и создает модель в монге имеющую связь с аккаунтом
|
||||
// в постгресе по accountid
|
||||
// ссылку составляет сервис соц авторизации
|
||||
func (c *Controller) ConnectAccount(ctx *fiber.Ctx) error {
|
||||
accountID, ok := middleware.GetAccountId(ctx)
|
||||
if !ok {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
c.logger.Error("error connect account", zap.Error(err))
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingStepsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingStepsFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListSteps(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListSteps(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) WebhookCreate(ctx *fiber.Ctx) error {
|
||||
err := c.service.WebhookCreate(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) WebhookDelete(ctx *fiber.Ctx) error {
|
||||
err := c.service.WebhookDelete(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListPipelines(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListPipelines(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingPipelinesFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingPipelinesFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.ChangeQuizSettings(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) SetQuizSettings(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.SetQuizSettings(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingQuizRules(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
response, err := c.service.GettingQuizRules(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingTagsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingTagsFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListTags(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListTags(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingFieldsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingFieldsFromCash(ctx.Context())
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListCustom(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListCustom(ctx.Context())
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
24
internal/controllers/fields.go
Normal file
24
internal/controllers/fields.go
Normal file
@ -0,0 +1,24 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func (c *Controller) GettingFieldsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingFieldsFromCash(ctx.Context())
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListCustom(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListCustom(ctx.Context())
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
52
internal/controllers/initial.go
Normal file
52
internal/controllers/initial.go
Normal file
@ -0,0 +1,52 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Service *service.Service
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
service *service.Service
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewController(deps Deps) *Controller {
|
||||
return &Controller{
|
||||
service: deps.Service,
|
||||
logger: deps.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) Register(router fiber.Router) {
|
||||
router.Patch("/users", c.UpdateListUsers)
|
||||
router.Get("/users", c.GettingUserFromCash)
|
||||
router.Delete("/utms/:quizID", c.DeletingUserUtm)
|
||||
router.Post("/utms/:quizID", c.SavingUserUtm)
|
||||
router.Get("/utms/:quizID", c.GettingUserUtm)
|
||||
router.Delete("/account", c.SoftDeleteAccount)
|
||||
router.Get("/account", c.GetCurrentAccount)
|
||||
router.Post("/account", c.ConnectAccount)
|
||||
router.Get("/steps", c.GettingStepsFromCash)
|
||||
router.Patch("/steps", c.UpdateListSteps)
|
||||
router.Get("/webhook/create", c.WebhookCreate)
|
||||
router.Get("/webhook/delete", c.WebhookDelete)
|
||||
router.Patch("/pipelines", c.UpdateListPipelines)
|
||||
router.Get("/pipelines", c.GettingPipelinesFromCash)
|
||||
router.Patch("/rules/:quizID", c.ChangeQuizSettings)
|
||||
router.Post("/rules/:quizID", c.SetQuizSettings)
|
||||
router.Get("/rules/:quizID", c.GettingQuizRules)
|
||||
router.Get("/tags", c.GettingTagsFromCash)
|
||||
router.Patch("/tags", c.UpdateListTags)
|
||||
router.Get("/fields", c.GettingFieldsFromCash)
|
||||
router.Patch("/fields", c.UpdateListCustom)
|
||||
}
|
||||
|
||||
func (c *Controller) Name() string {
|
||||
return ""
|
||||
}
|
26
internal/controllers/pipelines.go
Normal file
26
internal/controllers/pipelines.go
Normal file
@ -0,0 +1,26 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func (c *Controller) UpdateListPipelines(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListPipelines(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingPipelinesFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingPipelinesFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
58
internal/controllers/rules.go
Normal file
58
internal/controllers/rules.go
Normal file
@ -0,0 +1,58 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.ChangeQuizSettings(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) SetQuizSettings(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.SetQuizSettings(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingQuizRules(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
response, err := c.service.GettingQuizRules(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
26
internal/controllers/steps.go
Normal file
26
internal/controllers/steps.go
Normal file
@ -0,0 +1,26 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func (c *Controller) GettingStepsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingStepsFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListSteps(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListSteps(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
26
internal/controllers/tags.go
Normal file
26
internal/controllers/tags.go
Normal file
@ -0,0 +1,26 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func (c *Controller) GettingTagsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingTagsFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListTags(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListTags(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
67
internal/controllers/user.go
Normal file
67
internal/controllers/user.go
Normal file
@ -0,0 +1,67 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/middleware"
|
||||
)
|
||||
|
||||
func (c *Controller) UpdateListUsers(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListUsers(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingUserFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingUserFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) SoftDeleteAccount(ctx *fiber.Ctx) error {
|
||||
err := c.service.SoftDeleteAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GetCurrentAccount(ctx *fiber.Ctx) error {
|
||||
response, err := c.service.GetCurrentAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
// при запросе на этот контроллер приходит только токен из которого получаем id аккаунта в ис
|
||||
// отдает ссылку на подключение к amocrm и создает модель в монге имеющую связь с аккаунтом
|
||||
// в постгресе по accountid
|
||||
// ссылку составляет сервис соц авторизации
|
||||
func (c *Controller) ConnectAccount(ctx *fiber.Ctx) error {
|
||||
accountID, ok := middleware.GetAccountId(ctx)
|
||||
if !ok {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
c.logger.Error("error connect account", zap.Error(err))
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
63
internal/controllers/utm.go
Normal file
63
internal/controllers/utm.go
Normal file
@ -0,0 +1,63 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (c *Controller) DeletingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.ListDeleteUTMIDsReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.DeletingUserUtm(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) SavingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.SaveUserListUTMReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
response, err := c.service.SavingUserUtm(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingUserUtm(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
47
internal/controllers/webhook.go
Normal file
47
internal/controllers/webhook.go
Normal file
@ -0,0 +1,47 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// контроллер на который редиректятся ответы по авторизации в амо
|
||||
func (c *Controller) WebhookCreate(ctx *fiber.Ctx) error {
|
||||
code := ctx.Query("code") // Authorization 20 минут
|
||||
referer := ctx.Query("referer") // адрес аккаунта пользователя
|
||||
state := ctx.Query("state") // строка которая передавалась в соц аус сервисе
|
||||
fromWidget := ctx.Query("from_widget")
|
||||
platform := ctx.Query("platform") // ru/global 1/2
|
||||
noAccess := ctx.Query("error")
|
||||
|
||||
if noAccess != "" {
|
||||
return ctx.Status(http.StatusForbidden).SendString("Access denied")
|
||||
}
|
||||
|
||||
req := service.ParamsWebhookCreate{
|
||||
Code: code,
|
||||
Referer: referer,
|
||||
State: state,
|
||||
FromWidget: fromWidget,
|
||||
Platform: platform,
|
||||
}
|
||||
|
||||
err := c.service.WebhookCreate(ctx.Context(), req)
|
||||
if err != nil {
|
||||
c.logger.Error("error create webhook", zap.Error(err))
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) WebhookDelete(ctx *fiber.Ctx) error {
|
||||
err := c.service.WebhookDelete(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
@ -12,6 +12,11 @@ type Config struct {
|
||||
MongoAuth string `env:"MONGO_AUTH" envDefault:"admin"`
|
||||
// урл в соц аус сервисе для генерации ссылки для авторизации в амо
|
||||
PenaSocialAuthURL string `env:"PENA_SOCIAL_AUTH_URL"`
|
||||
// урл на который будет возвращен пользователь после авторизации
|
||||
// урл на который будет возвращен пользователь после авторизации это webhook/create get
|
||||
ReturnURL string `env:"RETURN_URL"`
|
||||
ApiURL string `env:"API_URL" envDefault:"https://example.amocrm.ru"`
|
||||
// id интеграции
|
||||
IntegrationID string `env:"INTEGRATION_ID"`
|
||||
// секрет интеграции
|
||||
IntegrationSecret string `env:"INTEGRATION_SECRET"`
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ type CreateWebHookReq struct {
|
||||
|
||||
type CreateWebHookResp struct {
|
||||
TokenType string `json:"token_type"` // Тип токена
|
||||
ExpiresIn int `json:"expires_in"` // ttl в секундах
|
||||
ExpiresIn int64 `json:"expires_in"` // ttl в секундах
|
||||
AccessToken string `json:"access_token"` // Access Token в формате JWT
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
@ -24,49 +24,49 @@ type UpdateWebHookReq struct {
|
||||
}
|
||||
|
||||
type WebHookRequest interface {
|
||||
GetClientID() string
|
||||
GetClientSecret() string
|
||||
SetClientID(str string)
|
||||
SetClientSecret(str string)
|
||||
GetGrantType() string
|
||||
GetRedirectURL() string
|
||||
SetRedirectURL(str string)
|
||||
GetToken() string
|
||||
}
|
||||
|
||||
func (req CreateWebHookReq) GetClientID() string {
|
||||
return req.ClientID
|
||||
func (req *CreateWebHookReq) SetClientID(str string) {
|
||||
req.ClientID = str
|
||||
}
|
||||
|
||||
func (req CreateWebHookReq) GetClientSecret() string {
|
||||
return req.ClientSecret
|
||||
func (req *CreateWebHookReq) SetClientSecret(str string) {
|
||||
req.ClientSecret = str
|
||||
}
|
||||
|
||||
func (req CreateWebHookReq) GetGrantType() string {
|
||||
func (req *CreateWebHookReq) GetGrantType() string {
|
||||
return req.GrantType
|
||||
}
|
||||
|
||||
func (req CreateWebHookReq) GetRedirectURL() string {
|
||||
return req.RedirectUrl
|
||||
func (req *CreateWebHookReq) SetRedirectURL(str string) {
|
||||
req.RedirectUrl = str
|
||||
}
|
||||
|
||||
func (req CreateWebHookReq) GetToken() string {
|
||||
func (req *CreateWebHookReq) GetToken() string {
|
||||
return req.Code
|
||||
}
|
||||
|
||||
func (req UpdateWebHookReq) GetClientID() string {
|
||||
return req.ClientID
|
||||
func (req *UpdateWebHookReq) SetClientID(str string) {
|
||||
req.ClientID = str
|
||||
}
|
||||
|
||||
func (req UpdateWebHookReq) GetClientSecret() string {
|
||||
return req.ClientSecret
|
||||
func (req *UpdateWebHookReq) SetClientSecret(str string) {
|
||||
req.ClientSecret = str
|
||||
}
|
||||
|
||||
func (req UpdateWebHookReq) GetGrantType() string {
|
||||
func (req *UpdateWebHookReq) GetGrantType() string {
|
||||
return req.GrantType
|
||||
}
|
||||
|
||||
func (req UpdateWebHookReq) GetRedirectURL() string {
|
||||
return req.RedirectUrl
|
||||
func (req *UpdateWebHookReq) SetRedirectURL(str string) {
|
||||
req.RedirectUrl = str
|
||||
}
|
||||
|
||||
func (req UpdateWebHookReq) GetToken() string {
|
||||
func (req *UpdateWebHookReq) GetToken() string {
|
||||
return req.RefreshToken
|
||||
}
|
||||
|
12
internal/models/token.go
Normal file
12
internal/models/token.go
Normal file
@ -0,0 +1,12 @@
|
||||
package models
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
type Token struct {
|
||||
ObjID primitive.ObjectID `json:"ObjID" bson:"_id"`
|
||||
AccountID string `json:"account_id" bson:"AccountID"` // id в квизе
|
||||
RefreshToken string `json:"refresh_token" bson:"RefreshToken"` // 80 дней
|
||||
AccessToken string `json:"access_token" bson:"AccessToken"` // 20 минут
|
||||
AuthCode string `json:"auth_code" bson:"AuthCode"`
|
||||
Expiration int64 `json:"expiration" bson:"Expiration"` // таймшамп времени когда кончится AccessToken
|
||||
}
|
19
internal/repository/fields.go
Normal file
19
internal/repository/fields.go
Normal file
@ -0,0 +1,19 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (r *Repository) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListFieldsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListCustom(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
19
internal/repository/pipelines.go
Normal file
19
internal/repository/pipelines.go
Normal file
@ -0,0 +1,19 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (r *Repository) UpdateListPipelines(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListPipelinesResp{}, nil
|
||||
}
|
@ -1,169 +1,26 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
MdbUser *mongo.Collection
|
||||
Tokens *mongo.Collection
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
mdbUser *mongo.Collection
|
||||
tokens *mongo.Collection
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewRepository(deps Deps) *Repository {
|
||||
return &Repository{
|
||||
mdbUser: deps.MdbUser,
|
||||
tokens: deps.Tokens,
|
||||
logger: deps.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListUsers(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.ListSavedIDUTMResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) GettingUserUtm(ctx context.Context) (*models.GetListUserUTMResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetListUserUTMResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) SoftDeleteAccount(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetCurrentAccountResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) CreateAccount(ctx context.Context, accountID string) error {
|
||||
userData := models.User{}
|
||||
userData.ObjID = primitive.NewObjectID()
|
||||
userData.Accountid = accountID
|
||||
_, err := r.mdbUser.InsertOne(ctx, userData)
|
||||
if err != nil {
|
||||
r.logger.Error("error createAccount in mongodb")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListStepsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListSteps(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) WebhookCreate(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) WebhookDelete(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListPipelines(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListPipelinesResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.Rule{}, nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListTagsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListTags(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListFieldsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListCustom(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
27
internal/repository/rules.go
Normal file
27
internal/repository/rules.go
Normal file
@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (r *Repository) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.Rule{}, nil
|
||||
|
||||
}
|
19
internal/repository/steps.go
Normal file
19
internal/repository/steps.go
Normal file
@ -0,0 +1,19 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (r *Repository) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListStepsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListSteps(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
19
internal/repository/tags.go
Normal file
19
internal/repository/tags.go
Normal file
@ -0,0 +1,19 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (r *Repository) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListTagsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListTags(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
45
internal/repository/user.go
Normal file
45
internal/repository/user.go
Normal file
@ -0,0 +1,45 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func (r *Repository) UpdateListUsers(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) SoftDeleteAccount(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetCurrentAccountResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) CreateAccount(ctx context.Context, accountID string) error {
|
||||
userData := models.User{}
|
||||
userData.ObjID = primitive.NewObjectID()
|
||||
userData.Accountid = accountID
|
||||
_, err := r.mdbUser.InsertOne(ctx, userData)
|
||||
if err != nil {
|
||||
r.logger.Error("error createAccount in mongodb")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
24
internal/repository/utm.go
Normal file
24
internal/repository/utm.go
Normal file
@ -0,0 +1,24 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (r *Repository) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.ListSavedIDUTMResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) GettingUserUtm(ctx context.Context) (*models.GetListUserUTMResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetListUserUTMResp{}, nil
|
||||
}
|
19
internal/repository/webhook.go
Normal file
19
internal/repository/webhook.go
Normal file
@ -0,0 +1,19 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (r *Repository) WebhookCreate(ctx context.Context, tokens models.Token) error {
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) WebhookDelete(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
24
internal/service/fields.go
Normal file
24
internal/service/fields.go
Normal file
@ -0,0 +1,24 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *Service) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingFieldsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListCustom(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListCustom(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
31
internal/service/initial.go
Normal file
31
internal/service/initial.go
Normal file
@ -0,0 +1,31 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/pkg/amoClient"
|
||||
pena_social_auth "amocrm/pkg/pena-social-auth"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Repository *repository.Repository
|
||||
Logger *zap.Logger
|
||||
SocialAuthClient *pena_social_auth.Client
|
||||
AmoClient *amoClient.Amo
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
repository *repository.Repository
|
||||
logger *zap.Logger
|
||||
socialAuthClient *pena_social_auth.Client
|
||||
amoClient *amoClient.Amo
|
||||
}
|
||||
|
||||
func NewService(deps Deps) *Service {
|
||||
return &Service{
|
||||
repository: deps.Repository,
|
||||
logger: deps.Logger,
|
||||
socialAuthClient: deps.SocialAuthClient,
|
||||
amoClient: deps.AmoClient,
|
||||
}
|
||||
}
|
24
internal/service/pipelines.go
Normal file
24
internal/service/pipelines.go
Normal file
@ -0,0 +1,24 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *Service) UpdateListPipelines(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListPipelines(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
||||
|
||||
response, err := s.repository.GettingPipelinesFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
33
internal/service/rules.go
Normal file
33
internal/service/rules.go
Normal file
@ -0,0 +1,33 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *Service) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
|
||||
err := s.repository.ChangeQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
|
||||
err := s.repository.SetQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
|
||||
response, err := s.repository.GettingQuizRules(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
@ -1,228 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/repository"
|
||||
pena_social_auth "amocrm/pkg/pena-social-auth"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Repository *repository.Repository
|
||||
Logger *zap.Logger
|
||||
SocialAuthClient *pena_social_auth.Client
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
repository *repository.Repository
|
||||
logger *zap.Logger
|
||||
socialAuthClient *pena_social_auth.Client
|
||||
}
|
||||
|
||||
func NewService(deps Deps) *Service {
|
||||
return &Service{
|
||||
repository: deps.Repository,
|
||||
logger: deps.Logger,
|
||||
socialAuthClient: deps.SocialAuthClient,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListUsers(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListUsers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
||||
|
||||
response, err := s.repository.GettingUserFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
|
||||
err := s.repository.DeletingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) {
|
||||
|
||||
response, err := s.repository.SavingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingUserUtm(ctx context.Context) (*models.GetListUserUTMResp, error) {
|
||||
|
||||
response, err := s.repository.GettingUserUtm(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) SoftDeleteAccount(ctx context.Context) error {
|
||||
|
||||
err := s.repository.SoftDeleteAccount(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
|
||||
response, err := s.repository.GetCurrentAccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*models.ConnectAccountResp, error) {
|
||||
err := s.repository.CreateAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
s.logger.Error("error create account in connectAccount service", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
link, err := s.socialAuthClient.GenerateAmocrmAuthURL()
|
||||
if err != nil {
|
||||
s.logger.Error("error sending request to pena social auth service:", zap.Error(err))
|
||||
}
|
||||
|
||||
response := models.ConnectAccountResp{
|
||||
Link: link,
|
||||
}
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingStepsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListSteps(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListSteps(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) WebhookCreate(ctx context.Context) error {
|
||||
|
||||
err := s.repository.WebhookCreate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) WebhookDelete(ctx context.Context) error {
|
||||
|
||||
err := s.repository.WebhookDelete(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListPipelines(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListPipelines(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
||||
|
||||
response, err := s.repository.GettingPipelinesFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
|
||||
err := s.repository.ChangeQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
|
||||
err := s.repository.SetQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
|
||||
response, err := s.repository.GettingQuizRules(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingTagsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListTags(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListTags(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingFieldsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListCustom(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListCustom(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
24
internal/service/steps.go
Normal file
24
internal/service/steps.go
Normal file
@ -0,0 +1,24 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *Service) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingStepsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListSteps(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListSteps(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
24
internal/service/tags.go
Normal file
24
internal/service/tags.go
Normal file
@ -0,0 +1,24 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *Service) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingTagsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListTags(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListTags(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
62
internal/service/user.go
Normal file
62
internal/service/user.go
Normal file
@ -0,0 +1,62 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (s *Service) UpdateListUsers(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListUsers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
||||
|
||||
response, err := s.repository.GettingUserFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) SoftDeleteAccount(ctx context.Context) error {
|
||||
|
||||
err := s.repository.SoftDeleteAccount(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
|
||||
response, err := s.repository.GetCurrentAccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*models.ConnectAccountResp, error) {
|
||||
err := s.repository.CreateAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
s.logger.Error("error create account in connectAccount service", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
link, err := s.socialAuthClient.GenerateAmocrmAuthURL()
|
||||
if err != nil {
|
||||
s.logger.Error("error sending request to pena social auth service:", zap.Error(err))
|
||||
}
|
||||
|
||||
response := models.ConnectAccountResp{
|
||||
Link: link,
|
||||
}
|
||||
|
||||
return &response, nil
|
||||
}
|
33
internal/service/utm.go
Normal file
33
internal/service/utm.go
Normal file
@ -0,0 +1,33 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *Service) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
|
||||
err := s.repository.DeletingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) {
|
||||
|
||||
response, err := s.repository.SavingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingUserUtm(ctx context.Context) (*models.GetListUserUTMResp, error) {
|
||||
|
||||
response, err := s.repository.GettingUserUtm(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
56
internal/service/webhook.go
Normal file
56
internal/service/webhook.go
Normal file
@ -0,0 +1,56 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/models/amo"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ParamsWebhookCreate struct {
|
||||
Code string // Authorization 20 минут
|
||||
Referer string // адрес аккаунта пользователя
|
||||
State string // строка которая передавалась в соц аус сервисе
|
||||
FromWidget string
|
||||
Platform string // ru/global 1/2
|
||||
}
|
||||
|
||||
// todo надо понять как понимать какому юзеру принадлежит токен
|
||||
func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) error {
|
||||
// получаем аксес и рефреш токены по коду авторизации
|
||||
forGetTokens := amo.CreateWebHookReq{
|
||||
GrantType: "authorization_code",
|
||||
Code: req.Code,
|
||||
}
|
||||
|
||||
tokens, err := s.amoClient.CreateWebHook(&forGetTokens)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting webhook in Service:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.repository.WebhookCreate(ctx, models.Token{
|
||||
ObjID: primitive.NewObjectID(),
|
||||
RefreshToken: tokens.RefreshToken,
|
||||
AccessToken: tokens.AccessToken,
|
||||
AccountID: "todo",
|
||||
AuthCode: req.Code,
|
||||
Expiration: time.Now().Unix() + tokens.ExpiresIn,
|
||||
})
|
||||
if err != nil {
|
||||
s.logger.Error("error adding tokens to mongo on service WebhookCreate", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) WebhookDelete(ctx context.Context) error {
|
||||
|
||||
err := s.repository.WebhookDelete(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
@ -11,21 +11,21 @@ import (
|
||||
)
|
||||
|
||||
type Amo struct {
|
||||
urlUserList string
|
||||
urlCreateWebHook string
|
||||
urlDeleteWebHook string
|
||||
baseApiURL string
|
||||
fiberClient *fiber.Client
|
||||
logger *zap.Logger
|
||||
baseApiURL string
|
||||
fiberClient *fiber.Client
|
||||
logger *zap.Logger
|
||||
redirectionURL string
|
||||
integrationID string
|
||||
integrationSecret string
|
||||
}
|
||||
|
||||
type AmoDeps struct {
|
||||
UrlUserList string
|
||||
UrlCreateWebHook string
|
||||
UrlDeleteWebHook string
|
||||
BaseApiURL string
|
||||
FiberClient *fiber.Client
|
||||
Logger *zap.Logger
|
||||
BaseApiURL string
|
||||
FiberClient *fiber.Client
|
||||
Logger *zap.Logger
|
||||
RedirectionURL string
|
||||
IntegrationID string
|
||||
IntegrationSecret string
|
||||
}
|
||||
|
||||
func NewAmoClient(deps AmoDeps) *Amo {
|
||||
@ -33,12 +33,12 @@ func NewAmoClient(deps AmoDeps) *Amo {
|
||||
deps.FiberClient = fiber.AcquireClient()
|
||||
}
|
||||
return &Amo{
|
||||
urlUserList: deps.UrlUserList,
|
||||
urlCreateWebHook: deps.UrlCreateWebHook,
|
||||
urlDeleteWebHook: deps.UrlDeleteWebHook,
|
||||
baseApiURL: deps.BaseApiURL,
|
||||
fiberClient: deps.FiberClient,
|
||||
logger: deps.Logger,
|
||||
baseApiURL: deps.BaseApiURL,
|
||||
fiberClient: deps.FiberClient,
|
||||
logger: deps.Logger,
|
||||
redirectionURL: deps.RedirectionURL,
|
||||
integrationSecret: deps.IntegrationSecret,
|
||||
integrationID: deps.IntegrationID,
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ func NewAmoClient(deps AmoDeps) *Amo {
|
||||
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/users-api#users-list
|
||||
func (a *Amo) GetUserList(req amo2.RequestGetListUsers) (*amo2.ResponseGetListUsers, error) {
|
||||
uri := fmt.Sprintf("%s?page=%d&limit=%d&with=%s", a.urlUserList, req.Page, req.Limit, req.With)
|
||||
uri := fmt.Sprintf("%s/api/v4/users?page=%d&limit=%d&with=%s", a.baseApiURL, req.Page, req.Limit, req.With)
|
||||
|
||||
agent := a.fiberClient.Get(uri)
|
||||
|
||||
@ -89,13 +89,18 @@ func (a *Amo) GetUserList(req amo2.RequestGetListUsers) (*amo2.ResponseGetListUs
|
||||
// POST /oauth2/access_token
|
||||
// тут и создание по коду и обновление по рефрешу в этом клиенте
|
||||
func (a *Amo) CreateWebHook(req amo2.WebHookRequest) (*amo2.CreateWebHookResp, error) {
|
||||
req.SetClientID(a.integrationID)
|
||||
req.SetClientSecret(a.integrationSecret)
|
||||
req.SetRedirectURL(a.redirectionURL)
|
||||
bodyBytes, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
a.logger.Error("error marshal req in CreateWebHook:", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
agent := a.fiberClient.Post(a.urlCreateWebHook)
|
||||
fmt.Println(string(bodyBytes))
|
||||
|
||||
agent := a.fiberClient.Post(a.baseApiURL + "/oauth2/access_token")
|
||||
agent.Set("Content-Type", "application/json").Body(bodyBytes)
|
||||
|
||||
statusCode, resBody, errs := agent.Bytes()
|
||||
@ -196,7 +201,7 @@ func (a *Amo) GetListFields(req amo2.GetListFieldsReq, url string) (*amo2.Respon
|
||||
// https://www.amocrm.ru/developers/content/crm_platform/tags-api#%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA-%D1%82%D0%B5%D0%B3%D0%BE%D0%B2-%D0%B4%D0%BB%D1%8F-%D1%81%D1%83%D1%89%D0%BD%D0%BE%D1%81%D1%82%D0%B8
|
||||
// GET /api/v4/{entity_type:leads|contacts|companies|customers}/tags
|
||||
func (a *Amo) GetListTags(req amo2.GetListTagsReq) (*amo2.ResponseGetListTags, error) {
|
||||
fullURL := fmt.Sprintf("%s/%s/tags?", a.baseApiURL, req.EntityType)
|
||||
fullURL := fmt.Sprintf("%s/api/v4/%s/tags?", a.baseApiURL, req.EntityType)
|
||||
|
||||
if req.Filter.Name != "" {
|
||||
fullURL += "&filter[name]=" + url.QueryEscape(req.Filter.Name)
|
||||
|
39
pkg/amoClient/amo_test.go
Normal file
39
pkg/amoClient/amo_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package amoClient
|
||||
|
||||
import (
|
||||
"amocrm/internal/models/amo"
|
||||
"fmt"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_CreateWebhook(t *testing.T) {
|
||||
cfgLogger := zap.NewDevelopmentConfig()
|
||||
cfgLogger.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
cfgLogger.EncoderConfig.ConsoleSeparator = " "
|
||||
|
||||
logger, err := cfgLogger.Build()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
amoclient := NewAmoClient(AmoDeps{
|
||||
BaseApiURL: "BaseApiURL",
|
||||
Logger: logger,
|
||||
RedirectionURL: "RedirectionURL",
|
||||
IntegrationID: "IntegrationID",
|
||||
IntegrationSecret: "IntegrationSecret",
|
||||
})
|
||||
|
||||
req1 := amo.UpdateWebHookReq{
|
||||
GrantType: "refresh_token",
|
||||
RefreshToken: "refresh_token",
|
||||
}
|
||||
req2 := amo.CreateWebHookReq{
|
||||
GrantType: "authorization_code",
|
||||
Code: "Code",
|
||||
}
|
||||
_, _ = amoclient.CreateWebHook(&req1)
|
||||
_, _ = amoclient.CreateWebHook(&req2)
|
||||
}
|
Loading…
Reference in New Issue
Block a user