198 lines
5.8 KiB
Go
198 lines
5.8 KiB
Go
package controllers
|
|
|
|
import (
|
|
"amocrm/internal/models"
|
|
"amocrm/internal/service"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type DifferentController struct {
|
|
DifferentService *service.DifferentService
|
|
}
|
|
|
|
func NewDifferentController(service *service.DifferentService) *DifferentController {
|
|
return &DifferentController{
|
|
DifferentService: service,
|
|
}
|
|
}
|
|
|
|
func (c *DifferentController) Register(router fiber.Router) {
|
|
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 *DifferentController) Name() string {
|
|
return ""
|
|
}
|
|
|
|
func (c *DifferentController) GettingStepsFromCash(ctx *fiber.Ctx) error {
|
|
req, err := extractParams(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
response, err := c.DifferentService.GettingStepsFromCash(ctx.Context())
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.Status(fiber.StatusOK).JSON(response)
|
|
}
|
|
|
|
func (c *DifferentController) UpdateListSteps(ctx *fiber.Ctx) error {
|
|
err := c.DifferentService.UpdateListSteps(ctx.Context())
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
}
|
|
|
|
func (c *DifferentController) WebhookCreate(ctx *fiber.Ctx) error {
|
|
err := c.DifferentService.WebhookCreate(ctx.Context())
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
}
|
|
|
|
func (c *DifferentController) WebhookDelete(ctx *fiber.Ctx) error {
|
|
err := c.DifferentService.WebhookDelete(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 {
|
|
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) GettingPipelinesFromCash(ctx *fiber.Ctx) error {
|
|
req, err := extractParams(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
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 {
|
|
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.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 {
|
|
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.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 {
|
|
quizID := ctx.Params("quizID")
|
|
if quizID == "" {
|
|
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
|
}
|
|
|
|
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 {
|
|
req, err := extractParams(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
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 {
|
|
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 {
|
|
req, err := extractParams(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
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 {
|
|
err := c.DifferentService.UpdateListCustom(ctx.Context())
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
}
|