96 lines
2.3 KiB
Go
96 lines
2.3 KiB
Go
|
package controllers
|
||
|
|
||
|
import (
|
||
|
"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.Get("/users", c.Getlistusers)
|
||
|
|
||
|
router.Patch("/users", c.Updatelistusers)
|
||
|
|
||
|
router.Delete("/account", c.Softdeleteaccount)
|
||
|
|
||
|
router.Get("/account", c.Getcurrentaccount)
|
||
|
|
||
|
router.Post("/account", c.Connectaccount)
|
||
|
|
||
|
}
|
||
|
|
||
|
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
|
||
|
|
||
|
err := c.AccountService.Updatelistusers(ctx.Context())
|
||
|
|
||
|
if err != nil {
|
||
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||
|
}
|
||
|
return ctx.SendStatus(fiber.StatusOK)
|
||
|
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
|
||
|
}
|