From 1d4a20d8653b56c9b025ed3d01a17457db68b1ab Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 8 Apr 2024 11:20:10 +0300 Subject: [PATCH] generate with blueprint --- .gitignore | 162 ++++++++++++++++++- amoClients/amo.go | 3 +- cmd/main.go | 3 +- database.puml | 83 ++++++++++ internal/controllers/account.go | 81 ++++++++-- internal/controllers/different.go | 189 +++++++++++++++-------- internal/models/field.go | 22 +++ internal/models/fieldrule.go | 6 + internal/models/getcurrentaccountresp.go | 14 +- internal/models/getlistuserutmresp.go | 8 + internal/models/listdeleteutmidsreq.go | 6 + internal/models/listsavedidutmresp.go | 6 + internal/models/paginationreq.go | 8 + internal/models/pipeline.go | 18 +++ internal/models/rule.go | 24 +++ internal/models/rulesreq.go | 6 + internal/models/saveuserlistutmreq.go | 6 + internal/models/step.go | 20 +++ internal/models/tag.go | 20 +++ internal/models/user.go | 22 +++ internal/models/userlistfieldsresp.go | 8 + internal/models/userlistpipelinesresp.go | 8 + internal/models/userlistresp.go | 8 + internal/models/userliststepsresp.go | 8 + internal/models/userlisttagsresp.go | 8 + internal/models/utm.go | 18 +++ internal/repository/account.go | 25 ++- internal/repository/different.go | 86 +++++++---- internal/service/account.go | 50 ++++-- internal/service/different.go | 127 +++++++++------ openapi.yaml | 91 ++++++++++- 31 files changed, 960 insertions(+), 184 deletions(-) create mode 100644 internal/models/field.go create mode 100644 internal/models/fieldrule.go create mode 100644 internal/models/getlistuserutmresp.go create mode 100644 internal/models/listdeleteutmidsreq.go create mode 100644 internal/models/listsavedidutmresp.go create mode 100644 internal/models/paginationreq.go create mode 100644 internal/models/pipeline.go create mode 100644 internal/models/rule.go create mode 100644 internal/models/rulesreq.go create mode 100644 internal/models/saveuserlistutmreq.go create mode 100644 internal/models/step.go create mode 100644 internal/models/tag.go create mode 100644 internal/models/user.go create mode 100644 internal/models/userlistfieldsresp.go create mode 100644 internal/models/userlistpipelinesresp.go create mode 100644 internal/models/userlistresp.go create mode 100644 internal/models/userliststepsresp.go create mode 100644 internal/models/userlisttagsresp.go create mode 100644 internal/models/utm.go diff --git a/.gitignore b/.gitignore index 62c8935..2b70277 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,161 @@ -.idea/ \ No newline at end of file +# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,goland,go +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,goland,go + +### Go ### +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +### GoLand ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### GoLand Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### VisualStudioCode ### +.vscode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,goland,go diff --git a/amoClients/amo.go b/amoClients/amo.go index bc06c46..fd2b91b 100644 --- a/amoClients/amo.go +++ b/amoClients/amo.go @@ -4,9 +4,10 @@ import ( "amocrm/models/amo" "encoding/json" "fmt" + "net/url" + "github.com/gofiber/fiber/v2" "go.uber.org/zap" - "net/url" ) type Amo struct { diff --git a/cmd/main.go b/cmd/main.go index 71d211d..cca3517 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,11 +1,12 @@ package main import ( - "amocrm/internal/app" "context" "os/signal" "syscall" + "amocrm/internal/app" + "go.uber.org/zap" "go.uber.org/zap/zapcore" diff --git a/database.puml b/database.puml index d7e914b..70a6875 100644 --- a/database.puml +++ b/database.puml @@ -1,4 +1,87 @@ @startuml Database +map FieldRule { + QuestionID => **integer** +} + +map UTM { + CreatedAt => **integer** + Deleted => **boolean** + ID => **integer** + Name => **string** + QuizID => **integer** + AccountID => **string** + AmoFieldID => **integer** +} + +map Pipeline { + CreatedAt => **integer** + Deleted => **boolean** + ID => **integer** + IsArchive => **boolean** + Name => **string** + AccountID => **string** + AmoID => **integer** +} + +map Step { + Deleted => **boolean** + ID => **integer** + Name => **string** + PipelineID => **integer** + AccountID => **string** + AmoID => **integer** + Color => **string** + CreatedAt => **integer** +} + +map Tag { + AccountID => **string** + AmoID => **integer** + Color => **string** + CreatedAt => **integer** + Deleted => **boolean** + Entity => **string** + ID => **integer** + Name => **string** +} + +map Field { + CreatedAt => **integer** + Deleted => **boolean** + EntityType => **string** + ID => **integer** + Name => **string** + Type => **string** + AccountID => **string** + AmoID => **integer** + Code => **string** +} + +map User { + Role => **string** + AmoID => **integer** + Group => **string** + Name => **string** + Email => **string** + ID => **integer** + AccountID => **string** + CreatedAt => **integer** + Deleted => **boolean** +} + +map Rule { + CreatedAt => **integer** + Deleted => **boolean** + FieldsRule => **FieldsRule** + PipelineID => **integer** + QuizID => **integer** + StepID => **integer** + UTMs => **[]integer** + AccountID => **string** + PerformerID => **integer** + ID => **integer** +} + @enduml \ No newline at end of file diff --git a/internal/controllers/account.go b/internal/controllers/account.go index 800b6fb..5133c78 100644 --- a/internal/controllers/account.go +++ b/internal/controllers/account.go @@ -1,6 +1,7 @@ package controllers import ( + "amocrm/internal/models" "amocrm/internal/service" "github.com/gofiber/fiber/v2" @@ -18,10 +19,16 @@ func NewAccountController(service *service.AccountService) *AccountController { func (c *AccountController) Register(router fiber.Router) { - router.Get("/users", c.Getlistusers) - router.Patch("/users", c.Updatelistusers) + router.Get("/users", c.Gettinguserfromcash) + + router.Delete("/utms", c.Deletinguserutm) + + router.Post("/utms", c.Savinguserutm) + + router.Get("/utms/{quizID}", c.Gettinguserutm) + router.Delete("/account", c.Softdeleteaccount) router.Get("/account", c.Getcurrentaccount) @@ -34,18 +41,6 @@ func (c *AccountController) Name() string { return "" } -func (c *AccountController) Getlistusers(ctx *fiber.Ctx) error { - // Обработчик для метода Getlistusers - - err := c.AccountService.Getlistusers(ctx.Context()) - - if err != nil { - return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") - } - return ctx.SendStatus(fiber.StatusOK) - -} - func (c *AccountController) Updatelistusers(ctx *fiber.Ctx) error { // Обработчик для метода Updatelistusers @@ -58,6 +53,64 @@ func (c *AccountController) Updatelistusers(ctx *fiber.Ctx) error { } +func (c *AccountController) Gettinguserfromcash(ctx *fiber.Ctx) error { + // Обработчик для метода Gettinguserfromcash + + response, err := c.AccountService.Gettinguserfromcash(ctx.Context()) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.Status(fiber.StatusOK).JSON(response) + +} + +func (c *AccountController) Deletinguserutm(ctx *fiber.Ctx) error { + // Обработчик для метода Deletinguserutm + + 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.AccountService.Deletinguserutm(ctx.Context(), &request) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.SendStatus(fiber.StatusOK) + +} + +func (c *AccountController) Savinguserutm(ctx *fiber.Ctx) error { + // Обработчик для метода Savinguserutm + + 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.AccountService.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 *AccountController) Gettinguserutm(ctx *fiber.Ctx) error { + // Обработчик для метода Gettinguserutm + + response, err := c.AccountService.Gettinguserutm(ctx.Context()) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.Status(fiber.StatusOK).JSON(response) + +} + func (c *AccountController) Softdeleteaccount(ctx *fiber.Ctx) error { // Обработчик для метода Softdeleteaccount diff --git a/internal/controllers/different.go b/internal/controllers/different.go index 223e0a6..90d5c66 100644 --- a/internal/controllers/different.go +++ b/internal/controllers/different.go @@ -1,6 +1,7 @@ package controllers import ( + "amocrm/internal/models" "amocrm/internal/service" "github.com/gofiber/fiber/v2" @@ -18,25 +19,31 @@ func NewDifferentController(service *service.DifferentService) *DifferentControl func (c *DifferentController) Register(router fiber.Router) { - router.Get("/tags", c.Getlisttags) + router.Get("/steps", c.Gettingstepsfromcash) - router.Patch("/tags", c.Updatelisttags) + router.Patch("/steps", c.Updateliststeps) router.Get("/webhook/create", c.Webhookcreate) router.Get("/webhook/delete", c.Webhookdelete) - router.Get("/fields", c.Getlistcustom) - - router.Patch("/fields", c.Updatelistcustom) - - router.Get("/pipelines", c.Getlistpipelines) - router.Patch("/pipelines", c.Updatelistpipelines) - router.Get("/steps", c.Getliststeps) + router.Get("/pipelines", c.Gettingpipelinesfromcash) - router.Patch("/steps", c.Updateliststeps) + router.Patch("/rules", c.Changequizsettings) + + router.Post("/rules", 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) } @@ -44,22 +51,22 @@ func (c *DifferentController) Name() string { return "" } -func (c *DifferentController) Getlisttags(ctx *fiber.Ctx) error { - // Обработчик для метода Getlisttags +func (c *DifferentController) Gettingstepsfromcash(ctx *fiber.Ctx) error { + // Обработчик для метода Gettingstepsfromcash - err := c.DifferentService.Getlisttags(ctx.Context()) + response, err := c.DifferentService.Gettingstepsfromcash(ctx.Context()) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") } - return ctx.SendStatus(fiber.StatusOK) + return ctx.Status(fiber.StatusOK).JSON(response) } -func (c *DifferentController) Updatelisttags(ctx *fiber.Ctx) error { - // Обработчик для метода Updatelisttags +func (c *DifferentController) Updateliststeps(ctx *fiber.Ctx) error { + // Обработчик для метода Updateliststeps - err := c.DifferentService.Updatelisttags(ctx.Context()) + err := c.DifferentService.Updateliststeps(ctx.Context()) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") @@ -92,10 +99,10 @@ func (c *DifferentController) Webhookdelete(ctx *fiber.Ctx) error { } -func (c *DifferentController) Getlistcustom(ctx *fiber.Ctx) error { - // Обработчик для метода Getlistcustom +func (c *DifferentController) Updatelistpipelines(ctx *fiber.Ctx) error { + // Обработчик для метода Updatelistpipelines - err := c.DifferentService.Getlistcustom(ctx.Context()) + err := c.DifferentService.Updatelistpipelines(ctx.Context()) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") @@ -104,6 +111,100 @@ func (c *DifferentController) Getlistcustom(ctx *fiber.Ctx) error { } +func (c *DifferentController) Gettingpipelinesfromcash(ctx *fiber.Ctx) error { + // Обработчик для метода Gettingpipelinesfromcash + + response, err := c.DifferentService.Gettingpipelinesfromcash(ctx.Context()) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.Status(fiber.StatusOK).JSON(response) + +} + +func (c *DifferentController) Changequizsettings(ctx *fiber.Ctx) error { + // Обработчик для метода Changequizsettings + + 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.DifferentService.Changequizsettings(ctx.Context(), &request) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.SendStatus(fiber.StatusOK) + +} + +func (c *DifferentController) Setquizsettings(ctx *fiber.Ctx) error { + // Обработчик для метода Setquizsettings + + 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.DifferentService.Setquizsettings(ctx.Context(), &request) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.SendStatus(fiber.StatusOK) + +} + +func (c *DifferentController) Gettingquizrules(ctx *fiber.Ctx) error { + // Обработчик для метода Gettingquizrules + + response, err := c.DifferentService.Gettingquizrules(ctx.Context()) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.Status(fiber.StatusOK).JSON(response) + +} + +func (c *DifferentController) Gettingtagsfromcash(ctx *fiber.Ctx) error { + // Обработчик для метода Gettingtagsfromcash + + response, err := c.DifferentService.Gettingtagsfromcash(ctx.Context()) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.Status(fiber.StatusOK).JSON(response) + +} + +func (c *DifferentController) Updatelisttags(ctx *fiber.Ctx) error { + // Обработчик для метода Updatelisttags + + err := c.DifferentService.Updatelisttags(ctx.Context()) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.SendStatus(fiber.StatusOK) + +} + +func (c *DifferentController) Gettingfieldsfromcash(ctx *fiber.Ctx) error { + // Обработчик для метода Gettingfieldsfromcash + + response, err := c.DifferentService.Gettingfieldsfromcash(ctx.Context()) + + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + return ctx.Status(fiber.StatusOK).JSON(response) + +} + func (c *DifferentController) Updatelistcustom(ctx *fiber.Ctx) error { // Обработчик для метода Updatelistcustom @@ -115,51 +216,3 @@ func (c *DifferentController) Updatelistcustom(ctx *fiber.Ctx) error { return ctx.SendStatus(fiber.StatusOK) } - -func (c *DifferentController) Getlistpipelines(ctx *fiber.Ctx) error { - // Обработчик для метода Getlistpipelines - - err := c.DifferentService.Getlistpipelines(ctx.Context()) - - if err != nil { - return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") - } - return ctx.SendStatus(fiber.StatusOK) - -} - -func (c *DifferentController) Updatelistpipelines(ctx *fiber.Ctx) error { - // Обработчик для метода Updatelistpipelines - - err := c.DifferentService.Updatelistpipelines(ctx.Context()) - - if err != nil { - return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") - } - return ctx.SendStatus(fiber.StatusOK) - -} - -func (c *DifferentController) Getliststeps(ctx *fiber.Ctx) error { - // Обработчик для метода Getliststeps - - err := c.DifferentService.Getliststeps(ctx.Context()) - - if err != nil { - return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") - } - return ctx.SendStatus(fiber.StatusOK) - -} - -func (c *DifferentController) Updateliststeps(ctx *fiber.Ctx) error { - // Обработчик для метода Updateliststeps - - err := c.DifferentService.Updateliststeps(ctx.Context()) - - if err != nil { - return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") - } - return ctx.SendStatus(fiber.StatusOK) - -} diff --git a/internal/models/field.go b/internal/models/field.go new file mode 100644 index 0000000..b4f474f --- /dev/null +++ b/internal/models/field.go @@ -0,0 +1,22 @@ +package models + +type Field struct { + /* - таймштамп создания воронки в нашей системе*/ + Createdat int `json:"CreatedAt"` + /* - флаг мягкого удаления*/ + Deleted bool `json:"Deleted"` + /* - тип сущности в амо, для которой это кастомное поле*/ + Entitytype string `json:"EntityType"` + /* - айдишник в нашей системе*/ + ID int `json:"ID"` + /* - название воронки в амо*/ + Name string `json:"Name"` + /* - тип поля https://www.amocrm.ru/developers/content/crm_platform/custom-fields#%D0%94%D0%BE%D1%81%D1%82%D1%83%D0%BF%D0%BD%D1%8B%D0%B5-%D1%82%D0%B8%D0%BF%D1%8B-%D0%BF%D0%BE%D0%BB%D0%B5%D0%B9*/ + Type string `json:"Type"` + /* - связь с аккаунтом в интеграции амо*/ + Accountid string `json:"AccountID"` + /* - айдишник кастомного поля в амо*/ + Amoid int `json:"AmoID"` + /* - кодовое слово в амо*/ + Code string `json:"Code"` +} diff --git a/internal/models/fieldrule.go b/internal/models/fieldrule.go new file mode 100644 index 0000000..eaffbf7 --- /dev/null +++ b/internal/models/fieldrule.go @@ -0,0 +1,6 @@ +package models + +type FieldRule struct { + /* - сопоставление айдишника вопроса полю, которое будет заполняться ответом. соответственно QuestionID это айдишник вопроса. это я так мэпу пытался записать*/ + Questionid int `json:"QuestionID"` +} diff --git a/internal/models/getcurrentaccountresp.go b/internal/models/getcurrentaccountresp.go index 33b155b..72b4184 100644 --- a/internal/models/getcurrentaccountresp.go +++ b/internal/models/getcurrentaccountresp.go @@ -1,6 +1,12 @@ package models type GetCurrentAccountResp struct { + /* - uuid*/ + ID string `json:"ID"` + /* - имя аккаунта в амо*/ + Name string `json:"Name"` + /* - поддомен организации в амо*/ + Subdomain string `json:"Subdomain"` /* - связь с аккаунтом в квизе*/ Accountid string `json:"AccountID"` /* - айдишник пользвателя, который подключал интеграцию*/ @@ -9,10 +15,6 @@ type GetCurrentAccountResp struct { Amocrmid int `json:"AmocrmID"` /* - страна указанная в настройках амо*/ Country string `json:"Country"` - /* - uuid*/ - ID string `json:"ID"` - /* - имя аккаунта в амо*/ - Name string `json:"Name"` - /* - поддомен организации в амо*/ - Subdomain string `json:"Subdomain"` + /* - таймштамп создания аккаунта*/ + Createdat int `json:"CreatedAt"` } diff --git a/internal/models/getlistuserutmresp.go b/internal/models/getlistuserutmresp.go new file mode 100644 index 0000000..45aa4d7 --- /dev/null +++ b/internal/models/getlistuserutmresp.go @@ -0,0 +1,8 @@ +package models + +type GetListUserUTMResp struct { + /* - общее количество юзеров, которые у нас закешированы для этого пользователя*/ + Count int `json:"count"` + /* - список юзеров, которые были закешированы нашим сервисом*/ + Items []UTM `json:"items"` +} diff --git a/internal/models/listdeleteutmidsreq.go b/internal/models/listdeleteutmidsreq.go new file mode 100644 index 0000000..8fca03e --- /dev/null +++ b/internal/models/listdeleteutmidsreq.go @@ -0,0 +1,6 @@ +package models + +type ListDeleteUTMIDsReq struct { + /* - список айдишников utm которые удалить*/ + Utms []int `json:"utms"` +} diff --git a/internal/models/listsavedidutmresp.go b/internal/models/listsavedidutmresp.go new file mode 100644 index 0000000..7c7e99b --- /dev/null +++ b/internal/models/listsavedidutmresp.go @@ -0,0 +1,6 @@ +package models + +type ListSavedIDUTMResp struct { + /* - список айдишников сохранённых меток*/ + Ids []string `json:"IDs"` +} diff --git a/internal/models/paginationreq.go b/internal/models/paginationreq.go new file mode 100644 index 0000000..c4cc2b8 --- /dev/null +++ b/internal/models/paginationreq.go @@ -0,0 +1,8 @@ +package models + +type PaginationReq struct { + /* - указание страницы пагинации. Если страница не указана, применять 0*/ + Page int `json:"page"` + /* - указание размера страницы пагинации. По умолчанию применять 25*/ + Size int `json:"size"` +} diff --git a/internal/models/pipeline.go b/internal/models/pipeline.go new file mode 100644 index 0000000..39ce91b --- /dev/null +++ b/internal/models/pipeline.go @@ -0,0 +1,18 @@ +package models + +type Pipeline struct { + /* - таймштамп создания воронки в нашей системе*/ + Createdat int `json:"CreatedAt"` + /* - флаг мягкого удаления*/ + Deleted bool `json:"Deleted"` + /* - айдишник в нашей системе*/ + ID int `json:"ID"` + /* - флаг архивной воронки в амо*/ + Isarchive bool `json:"IsArchive"` + /* - название воронки в амо*/ + Name string `json:"Name"` + /* - связь с аккаунтом в интеграции амо*/ + Accountid string `json:"AccountID"` + /* - айдишник воронки в амо*/ + Amoid int `json:"AmoID"` +} diff --git a/internal/models/rule.go b/internal/models/rule.go new file mode 100644 index 0000000..25e4626 --- /dev/null +++ b/internal/models/rule.go @@ -0,0 +1,24 @@ +package models + +type Rule struct { + /* - айдишник воронки*/ + Pipelineid int `json:"PipelineID"` + /* - айдишник опроса*/ + Quizid int `json:"QuizID"` + /* - айдишник этапа*/ + Stepid int `json:"StepID"` + /* - список UTM для этого опроса*/ + Utms []int `json:"UTMs"` + /* - связь с аккаунтом в интеграции амо*/ + Accountid string `json:"AccountID"` + /* - таймштамп создания воронки в нашей системе*/ + Createdat int `json:"CreatedAt"` + /* - флаг мягкого удаления*/ + Deleted bool `json:"Deleted"` + /* - правила заполнения полей сущностей в амо*/ + Fieldsrule Fieldsrule `json:"FieldsRule"` + /* - айдишник в нашей системе*/ + ID int `json:"ID"` + /* - айдишник ответственного за сделку*/ + Performerid int `json:"PerformerID"` +} diff --git a/internal/models/rulesreq.go b/internal/models/rulesreq.go new file mode 100644 index 0000000..87163d5 --- /dev/null +++ b/internal/models/rulesreq.go @@ -0,0 +1,6 @@ +package models + +type RulesReq struct { + /* - ID квиза*/ + ID string `json:"ID"` +} diff --git a/internal/models/saveuserlistutmreq.go b/internal/models/saveuserlistutmreq.go new file mode 100644 index 0000000..cb08fa2 --- /dev/null +++ b/internal/models/saveuserlistutmreq.go @@ -0,0 +1,6 @@ +package models + +type SaveUserListUTMReq struct { + /* - список utm для сохранения. сохранять только те, которых в этом аккаунте ещё нет*/ + Utms []string `json:"utms"` +} diff --git a/internal/models/step.go b/internal/models/step.go new file mode 100644 index 0000000..b29b87e --- /dev/null +++ b/internal/models/step.go @@ -0,0 +1,20 @@ +package models + +type Step struct { + /* - айдишник воронки в амо*/ + Pipelineid int `json:"PipelineID"` + /* - связь с аккаунтом в интеграции амо*/ + Accountid string `json:"AccountID"` + /* - айдишник шага воронки в амо*/ + Amoid int `json:"AmoID"` + /* - цвет шага в амо*/ + Color string `json:"Color"` + /* - таймштамп создания воронки в нашей системе*/ + Createdat int `json:"CreatedAt"` + /* - флаг мягкого удаления*/ + Deleted bool `json:"Deleted"` + /* - айдишник в нашей системе*/ + ID int `json:"ID"` + /* - название воронки в амо*/ + Name string `json:"Name"` +} diff --git a/internal/models/tag.go b/internal/models/tag.go new file mode 100644 index 0000000..e256f70 --- /dev/null +++ b/internal/models/tag.go @@ -0,0 +1,20 @@ +package models + +type Tag struct { + /* - таймштамп создания тега в нашей системе*/ + Createdat int `json:"CreatedAt"` + /* - флаг мягкого удаления*/ + Deleted bool `json:"Deleted"` + /* - сущность, к которой принадлежит этот тег. Наверное, стоит сделать через enum в базе*/ + Entity string `json:"Entity"` + /* - айдишник в нашей системе*/ + ID int `json:"ID"` + /* - название тега в амо*/ + Name string `json:"Name"` + /* - связь с аккаунтом в интеграции амо*/ + Accountid string `json:"AccountID"` + /* - айдишник тега в амо*/ + Amoid int `json:"AmoID"` + /* - цвет тега в амо*/ + Color string `json:"Color"` +} diff --git a/internal/models/user.go b/internal/models/user.go new file mode 100644 index 0000000..b1056e5 --- /dev/null +++ b/internal/models/user.go @@ -0,0 +1,22 @@ +package models + +type User struct { + /* - связь с аккаунтом в интеграции амо*/ + Accountid string `json:"AccountID"` + /* - таймштамп создания тега в нашей системе*/ + Createdat int `json:"CreatedAt"` + /* - флаг мягкого удаления*/ + Deleted bool `json:"Deleted"` + /* - почта пользователя из амо*/ + Email string `json:"Email"` + /* - айдишник в нашей системе*/ + ID int `json:"ID"` + /* - айдишник пользователя в амо*/ + Amoid int `json:"AmoID"` + /* - руппа пользователя в амо*/ + Group string `json:"Group"` + /* - имя пользователя в амо*/ + Name string `json:"Name"` + /* - роль пользователя в амо*/ + Role string `json:"Role"` +} diff --git a/internal/models/userlistfieldsresp.go b/internal/models/userlistfieldsresp.go new file mode 100644 index 0000000..59f4a61 --- /dev/null +++ b/internal/models/userlistfieldsresp.go @@ -0,0 +1,8 @@ +package models + +type UserListFieldsResp struct { + /* - общее количество кастомных полей, которые у нас закешированы для этого пользователя*/ + Count int `json:"count"` + /* - список кастомных полей, которые были закешированы нашим сервисом*/ + Items []Field `json:"items"` +} diff --git a/internal/models/userlistpipelinesresp.go b/internal/models/userlistpipelinesresp.go new file mode 100644 index 0000000..869e655 --- /dev/null +++ b/internal/models/userlistpipelinesresp.go @@ -0,0 +1,8 @@ +package models + +type UserListPipelinesResp struct { + /* - общее количество воронок, которые у нас закешированы для этого пользователя*/ + Count int `json:"count"` + /* - список воронок, которые были закешированы нашим сервисом*/ + Items []Pipeline `json:"items"` +} diff --git a/internal/models/userlistresp.go b/internal/models/userlistresp.go new file mode 100644 index 0000000..c26d6f3 --- /dev/null +++ b/internal/models/userlistresp.go @@ -0,0 +1,8 @@ +package models + +type UserListResp struct { + /* - общее количество юзеров, которые у нас закешированы для этого пользователя*/ + Count int `json:"count"` + /* - список юзеров, которые были закешированы нашим сервисом*/ + Items []User `json:"items"` +} diff --git a/internal/models/userliststepsresp.go b/internal/models/userliststepsresp.go new file mode 100644 index 0000000..23e2d94 --- /dev/null +++ b/internal/models/userliststepsresp.go @@ -0,0 +1,8 @@ +package models + +type UserListStepsResp struct { + /* - список шагов воронок, которые были закешированы нашим сервисом*/ + Items []Step `json:"items"` + /* - общее количество шагов воронок, которые у нас закешированы для этого пользователя*/ + Count int `json:"count"` +} diff --git a/internal/models/userlisttagsresp.go b/internal/models/userlisttagsresp.go new file mode 100644 index 0000000..f2168b0 --- /dev/null +++ b/internal/models/userlisttagsresp.go @@ -0,0 +1,8 @@ +package models + +type UserListTagsResp struct { + /* - общее количество тегов, которые у нас закешированы для этого пользователя*/ + Count int `json:"count"` + /* - список тегов, которые были закешированы нашим сервисом*/ + Items []Tag `json:"items"` +} diff --git a/internal/models/utm.go b/internal/models/utm.go new file mode 100644 index 0000000..8f36716 --- /dev/null +++ b/internal/models/utm.go @@ -0,0 +1,18 @@ +package models + +type UTM struct { + /* - название тега в амо*/ + Name string `json:"Name"` + /* - айдишник квиза*/ + Quizid int `json:"QuizID"` + /* - связь с аккаунтом в интеграции амо*/ + Accountid string `json:"AccountID"` + /* - айдишник кастомного поля в амо*/ + Amofieldid int `json:"AmoFieldID"` + /* - таймштамп создания тега в нашей системе*/ + Createdat int `json:"CreatedAt"` + /* - флаг мягкого удаления*/ + Deleted bool `json:"Deleted"` + /* - айдишник в нашей системе*/ + ID int `json:"ID"` +} diff --git a/internal/repository/account.go b/internal/repository/account.go index 20703db..aa20a45 100644 --- a/internal/repository/account.go +++ b/internal/repository/account.go @@ -12,20 +12,41 @@ func NewAccountRepository() *AccountRepository { return &AccountRepository{} } -func (r *AccountRepository) Getlistusers(ctx context.Context) error { +func (r *AccountRepository) Updatelistusers(ctx context.Context) error { //TODO:IMPLEMENT ME return nil } -func (r *AccountRepository) Updatelistusers(ctx context.Context) error { +func (r *AccountRepository) Gettinguserfromcash(ctx context.Context) (*models.UserListResp, error) { + //TODO:IMPLEMENT ME + + return &models.UserListResp{}, nil + +} + +func (r *AccountRepository) Deletinguserutm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error { //TODO:IMPLEMENT ME return nil } +func (r *AccountRepository) Savinguserutm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) { + //TODO:IMPLEMENT ME + + return &models.ListSavedIDUTMResp{}, nil + +} + +func (r *AccountRepository) Gettinguserutm(ctx context.Context) (*models.GetListUserUTMResp, error) { + //TODO:IMPLEMENT ME + + return &models.GetListUserUTMResp{}, nil + +} + func (r *AccountRepository) Softdeleteaccount(ctx context.Context) error { //TODO:IMPLEMENT ME diff --git a/internal/repository/different.go b/internal/repository/different.go index bc53cd2..8b52132 100644 --- a/internal/repository/different.go +++ b/internal/repository/different.go @@ -1,6 +1,7 @@ package repository import ( + "amocrm/internal/models" "context" ) @@ -11,14 +12,14 @@ func NewDifferentRepository() *DifferentRepository { return &DifferentRepository{} } -func (r *DifferentRepository) Getlisttags(ctx context.Context) error { +func (r *DifferentRepository) Gettingstepsfromcash(ctx context.Context) (*models.UserListStepsResp, error) { //TODO:IMPLEMENT ME - return nil + return &models.UserListStepsResp{}, nil } -func (r *DifferentRepository) Updatelisttags(ctx context.Context) error { +func (r *DifferentRepository) Updateliststeps(ctx context.Context) error { //TODO:IMPLEMENT ME return nil @@ -39,44 +40,65 @@ func (r *DifferentRepository) Webhookdelete(ctx context.Context) error { } -func (r *DifferentRepository) Getlistcustom(ctx context.Context) error { +func (r *DifferentRepository) Updatelistpipelines(ctx context.Context) error { //TODO:IMPLEMENT ME return nil } +func (r *DifferentRepository) Gettingpipelinesfromcash(ctx context.Context) (*models.UserListPipelinesResp, error) { + //TODO:IMPLEMENT ME + + return &models.UserListPipelinesResp{}, nil + +} + +func (r *DifferentRepository) Changequizsettings(ctx context.Context, request *models.RulesReq) error { + //TODO:IMPLEMENT ME + + return nil + +} + +func (r *DifferentRepository) Setquizsettings(ctx context.Context, request *models.RulesReq) error { + //TODO:IMPLEMENT ME + + return nil + +} + +func (r *DifferentRepository) Gettingquizrules(ctx context.Context) (*models.Rule, error) { + //TODO:IMPLEMENT ME + + return &models.Rule{}, nil + +} + +func (r *DifferentRepository) Gettingtagsfromcash(ctx context.Context) (*models.UserListTagsResp, error) { + //TODO:IMPLEMENT ME + + return &models.UserListTagsResp{}, nil + +} + +func (r *DifferentRepository) Updatelisttags(ctx context.Context) error { + //TODO:IMPLEMENT ME + + return nil + +} + +func (r *DifferentRepository) Gettingfieldsfromcash(ctx context.Context) (*models.UserListFieldsResp, error) { + //TODO:IMPLEMENT ME + + return &models.UserListFieldsResp{}, nil + +} + func (r *DifferentRepository) Updatelistcustom(ctx context.Context) error { //TODO:IMPLEMENT ME return nil } - -func (r *DifferentRepository) Getlistpipelines(ctx context.Context) error { - //TODO:IMPLEMENT ME - - return nil - -} - -func (r *DifferentRepository) Updatelistpipelines(ctx context.Context) error { - //TODO:IMPLEMENT ME - - return nil - -} - -func (r *DifferentRepository) Getliststeps(ctx context.Context) error { - //TODO:IMPLEMENT ME - - return nil - -} - -func (r *DifferentRepository) Updateliststeps(ctx context.Context) error { - //TODO:IMPLEMENT ME - - return nil - -} diff --git a/internal/service/account.go b/internal/service/account.go index c81e073..9c6e09e 100644 --- a/internal/service/account.go +++ b/internal/service/account.go @@ -16,16 +16,6 @@ func NewAccountService(repository *repository.AccountRepository) *AccountService } } -func (s *AccountService) Getlistusers(ctx context.Context) error { - - err := s.AccountRepository.Getlistusers(ctx) - if err != nil { - return err - } - return nil - -} - func (s *AccountService) Updatelistusers(ctx context.Context) error { err := s.AccountRepository.Updatelistusers(ctx) @@ -36,6 +26,46 @@ func (s *AccountService) Updatelistusers(ctx context.Context) error { } +func (s *AccountService) Gettinguserfromcash(ctx context.Context) (*models.UserListResp, error) { + + response, err := s.AccountRepository.Gettinguserfromcash(ctx) + if err != nil { + return nil, err + } + return response, nil + +} + +func (s *AccountService) Deletinguserutm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error { + + err := s.AccountRepository.Deletinguserutm(ctx, request) + if err != nil { + return err + } + return nil + +} + +func (s *AccountService) Savinguserutm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) { + + response, err := s.AccountRepository.Savinguserutm(ctx, request) + if err != nil { + return nil, err + } + return response, nil + +} + +func (s *AccountService) Gettinguserutm(ctx context.Context) (*models.GetListUserUTMResp, error) { + + response, err := s.AccountRepository.Gettinguserutm(ctx) + if err != nil { + return nil, err + } + return response, nil + +} + func (s *AccountService) Softdeleteaccount(ctx context.Context) error { err := s.AccountRepository.Softdeleteaccount(ctx) diff --git a/internal/service/different.go b/internal/service/different.go index 2fb4fe7..a01f32f 100644 --- a/internal/service/different.go +++ b/internal/service/different.go @@ -1,6 +1,7 @@ package service import ( + "amocrm/internal/models" "amocrm/internal/repository" "context" ) @@ -15,19 +16,19 @@ func NewDifferentService(repository *repository.DifferentRepository) *DifferentS } } -func (s *DifferentService) Getlisttags(ctx context.Context) error { +func (s *DifferentService) Gettingstepsfromcash(ctx context.Context) (*models.UserListStepsResp, error) { - err := s.DifferentRepository.Getlisttags(ctx) + response, err := s.DifferentRepository.Gettingstepsfromcash(ctx) if err != nil { - return err + return nil, err } - return nil + return response, nil } -func (s *DifferentService) Updatelisttags(ctx context.Context) error { +func (s *DifferentService) Updateliststeps(ctx context.Context) error { - err := s.DifferentRepository.Updatelisttags(ctx) + err := s.DifferentRepository.Updateliststeps(ctx) if err != nil { return err } @@ -55,9 +56,9 @@ func (s *DifferentService) Webhookdelete(ctx context.Context) error { } -func (s *DifferentService) Getlistcustom(ctx context.Context) error { +func (s *DifferentService) Updatelistpipelines(ctx context.Context) error { - err := s.DifferentRepository.Getlistcustom(ctx) + err := s.DifferentRepository.Updatelistpipelines(ctx) if err != nil { return err } @@ -65,6 +66,76 @@ func (s *DifferentService) Getlistcustom(ctx context.Context) error { } +func (s *DifferentService) Gettingpipelinesfromcash(ctx context.Context) (*models.UserListPipelinesResp, error) { + + response, err := s.DifferentRepository.Gettingpipelinesfromcash(ctx) + if err != nil { + return nil, err + } + return response, nil + +} + +func (s *DifferentService) Changequizsettings(ctx context.Context, request *models.RulesReq) error { + + err := s.DifferentRepository.Changequizsettings(ctx, request) + if err != nil { + return err + } + return nil + +} + +func (s *DifferentService) Setquizsettings(ctx context.Context, request *models.RulesReq) error { + + err := s.DifferentRepository.Setquizsettings(ctx, request) + if err != nil { + return err + } + return nil + +} + +func (s *DifferentService) Gettingquizrules(ctx context.Context) (*models.Rule, error) { + + response, err := s.DifferentRepository.Gettingquizrules(ctx) + if err != nil { + return nil, err + } + return response, nil + +} + +func (s *DifferentService) Gettingtagsfromcash(ctx context.Context) (*models.UserListTagsResp, error) { + + response, err := s.DifferentRepository.Gettingtagsfromcash(ctx) + if err != nil { + return nil, err + } + return response, nil + +} + +func (s *DifferentService) Updatelisttags(ctx context.Context) error { + + err := s.DifferentRepository.Updatelisttags(ctx) + if err != nil { + return err + } + return nil + +} + +func (s *DifferentService) Gettingfieldsfromcash(ctx context.Context) (*models.UserListFieldsResp, error) { + + response, err := s.DifferentRepository.Gettingfieldsfromcash(ctx) + if err != nil { + return nil, err + } + return response, nil + +} + func (s *DifferentService) Updatelistcustom(ctx context.Context) error { err := s.DifferentRepository.Updatelistcustom(ctx) @@ -74,43 +145,3 @@ func (s *DifferentService) Updatelistcustom(ctx context.Context) error { return nil } - -func (s *DifferentService) Getlistpipelines(ctx context.Context) error { - - err := s.DifferentRepository.Getlistpipelines(ctx) - if err != nil { - return err - } - return nil - -} - -func (s *DifferentService) Updatelistpipelines(ctx context.Context) error { - - err := s.DifferentRepository.Updatelistpipelines(ctx) - if err != nil { - return err - } - return nil - -} - -func (s *DifferentService) Getliststeps(ctx context.Context) error { - - err := s.DifferentRepository.Getliststeps(ctx) - if err != nil { - return err - } - return nil - -} - -func (s *DifferentService) Updateliststeps(ctx context.Context) error { - - err := s.DifferentRepository.Updateliststeps(ctx) - if err != nil { - return err - } - return nil - -} diff --git a/openapi.yaml b/openapi.yaml index da5c748..f37b6c7 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -70,6 +70,12 @@ paths: - account description: получение списка заданных юзером utm меток. Это чисто наша сущность, в амо она представлена кастомными полями сделки parameters: + - in: path + name: quizID + required: true + schema: + type: string + description: Id квиза - in: query name: Pagination description: Параметры пагинации @@ -95,6 +101,7 @@ paths: 'application/json': schema: $ref: '#/components/schemas/GetListUserUTMResp' + /utms: post: operationId: SavingUserUTM tags: @@ -325,13 +332,20 @@ paths: responses: '200': description: Success -# блупринт с таким роутом не работает надо будет пересмотреть такие пути +# таких запросах для блупринта обязательно нужно указывать параметры /rules/{quizID}: get: operationId: GettingQuizRules tags: - different description: получение настроек интеграции для конкретного квиза + parameters: + - in: path + name: quizID + required: true + schema: + type: string + description: Id квиза responses: '200': description: успешное получение настройки интеграции @@ -339,11 +353,17 @@ paths: 'application/json': schema: $ref: "#/components/schemas/Rule" + /rules: post: operationId: SetQuizSettings description: создание настроек интеграции для конкретного квиза tags: - different + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/RulesReq" responses: '200': description: Success @@ -352,6 +372,11 @@ paths: description: изменение настроек интеграции для конкретного квиза tags: - different + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/RulesReq" responses: '200': description: Success @@ -718,3 +743,67 @@ components: size: type: integer description: указание размера страницы пагинации. По умолчанию применять 25 + RulesReq: + type: object + properties: + ID: + type: string + description: ID квиза + + responses: + '200': + description: Success + content: + application/json: + schema: + type: string + description: Success + '201': + description: Created + content: + application/json: + schema: + type: string + description: Created + '204': + description: No content + content: + application/json: + schema: + type: string + description: No content + '400': + description: Bad Request + content: + application/json: + schema: + type: string + description: Bad Request + '401': + description: Unauthorized + content: + application/json: + schema: + type: string + description: Unauthorized + '403': + description: Forbidden + content: + application/json: + schema: + type: string + description: Forbidden + '404': + description: Not Found + content: + application/json: + schema: + type: string + description: Not Found + '500': + description: Internal Server Error + content: + application/json: + schema: + type: string + description: Internal Server Error