2024-04-04 09:42:40 +00:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2024-04-08 08:20:10 +00:00
|
|
|
"amocrm/internal/models"
|
2024-04-04 09:42:40 +00:00
|
|
|
"amocrm/internal/service"
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccountController struct {
|
|
|
|
AccountService *service.AccountService
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAccountController(service *service.AccountService) *AccountController {
|
|
|
|
return &AccountController{
|
|
|
|
AccountService: service,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AccountController) Register(router fiber.Router) {
|
|
|
|
|
|
|
|
router.Patch("/users", c.Updatelistusers)
|
|
|
|
|
2024-04-08 08:20:10 +00:00
|
|
|
router.Get("/users", c.Gettinguserfromcash)
|
|
|
|
|
|
|
|
router.Delete("/utms", c.Deletinguserutm)
|
|
|
|
|
|
|
|
router.Post("/utms", c.Savinguserutm)
|
|
|
|
|
|
|
|
router.Get("/utms/{quizID}", c.Gettinguserutm)
|
|
|
|
|
2024-04-04 09:42:40 +00:00
|
|
|
router.Delete("/account", c.Softdeleteaccount)
|
|
|
|
|
|
|
|
router.Get("/account", c.Getcurrentaccount)
|
|
|
|
|
|
|
|
router.Post("/account", c.Connectaccount)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AccountController) Name() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2024-04-08 08:20:10 +00:00
|
|
|
func (c *AccountController) Updatelistusers(ctx *fiber.Ctx) error {
|
|
|
|
// Обработчик для метода Updatelistusers
|
2024-04-04 09:42:40 +00:00
|
|
|
|
2024-04-08 08:20:10 +00:00
|
|
|
err := c.AccountService.Updatelistusers(ctx.Context())
|
2024-04-04 09:42:40 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
|
|
}
|
|
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-04-08 08:20:10 +00:00
|
|
|
func (c *AccountController) Gettinguserfromcash(ctx *fiber.Ctx) error {
|
|
|
|
// Обработчик для метода Gettinguserfromcash
|
2024-04-04 09:42:40 +00:00
|
|
|
|
2024-04-08 08:20:10 +00:00
|
|
|
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)
|
2024-04-04 09:42:40 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
|
|
}
|
|
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-04-08 08:20:10 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-04-04 09:42:40 +00:00
|
|
|
func (c *AccountController) Softdeleteaccount(ctx *fiber.Ctx) error {
|
|
|
|
// Обработчик для метода Softdeleteaccount
|
|
|
|
|
|
|
|
err := c.AccountService.Softdeleteaccount(ctx.Context())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
|
|
}
|
|
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AccountController) Getcurrentaccount(ctx *fiber.Ctx) error {
|
|
|
|
// Обработчик для метода Getcurrentaccount
|
|
|
|
|
|
|
|
response, err := c.AccountService.Getcurrentaccount(ctx.Context())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
|
|
}
|
|
|
|
return ctx.Status(fiber.StatusOK).JSON(response)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AccountController) Connectaccount(ctx *fiber.Ctx) error {
|
|
|
|
// Обработчик для метода Connectaccount
|
|
|
|
|
|
|
|
response, err := c.AccountService.Connectaccount(ctx.Context())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
|
|
}
|
|
|
|
return ctx.Status(fiber.StatusOK).JSON(response)
|
|
|
|
|
|
|
|
}
|