amocrm/internal/controllers/steps.go

59 lines
1.6 KiB
Go
Raw Normal View History

package controllers
import (
2024-06-05 13:27:14 +00:00
"errors"
"github.com/gofiber/fiber/v2"
2025-02-07 13:42:57 +00:00
"gitea.pena/SQuiz/common/middleware"
"gitea.pena/SQuiz/common/pj_errors"
"strconv"
)
2024-04-21 15:24:13 +00:00
func (c *Controller) GetStepsWithPagination(ctx *fiber.Ctx) error {
accountID, ok := middleware.GetAccountId(ctx)
if !ok {
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
}
pipelineIDStr := ctx.Query("pipelineID")
if pipelineIDStr == "" {
return ctx.Status(fiber.StatusBadRequest).SendString("pipeline id is required")
}
pipelineID, err := strconv.Atoi(pipelineIDStr)
if err != nil {
return ctx.Status(fiber.StatusBadRequest).SendString("invalid pipeline id parameter")
}
req, err := extractParams(ctx)
if err != nil {
return err
}
response, err := c.service.GetStepsWithPagination(ctx.Context(), req, accountID, pipelineID)
if err != nil {
2024-06-05 13:27:14 +00:00
switch {
case errors.Is(err, pj_errors.ErrNotFound):
return ctx.Status(fiber.StatusNotFound).SendString("steps for this user not found")
default:
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}
}
return ctx.Status(fiber.StatusOK).JSON(response)
}
func (c *Controller) UpdateListSteps(ctx *fiber.Ctx) error {
accountID, ok := middleware.GetAccountId(ctx)
if !ok {
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
}
2024-05-07 18:46:14 +00:00
//accountID := "654a8909725f47e926f0bebc"
err := c.service.UpdateListSteps(ctx.Context(), accountID)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}
2024-06-05 13:27:14 +00:00
return ctx.SendStatus(fiber.StatusOK)
}