amocrm/internal/controllers/steps.go
skeris b554d9f475
All checks were successful
Deploy / CreateImage (push) Successful in 2m7s
Deploy / DeployService (push) Successful in 19s
ci gitea
2025-02-08 01:06:18 +03:00

59 lines
1.6 KiB
Go

package controllers
import (
"errors"
"github.com/gofiber/fiber/v2"
"gitea.pena/SQuiz/common/middleware"
"gitea.pena/SQuiz/common/pj_errors"
"strconv"
)
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 {
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")
}
//accountID := "654a8909725f47e926f0bebc"
err := c.service.UpdateListSteps(ctx.Context(), accountID)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}
return ctx.SendStatus(fiber.StatusOK)
}