amocrm/internal/controllers/fields.go

48 lines
1.3 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"
)
2024-04-21 15:24:13 +00:00
func (c *Controller) GetFieldsWithPagination(ctx *fiber.Ctx) error {
accountID, ok := middleware.GetAccountId(ctx)
if !ok {
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
}
req, err := extractParams(ctx)
if err != nil {
return err
}
2024-04-21 15:24:13 +00:00
response, err := c.service.GetFieldsWithPagination(ctx.Context(), req, accountID)
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("fields 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) UpdateListCustom(ctx *fiber.Ctx) error {
accountID, ok := middleware.GetAccountId(ctx)
if !ok {
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
}
2024-05-05 12:22:54 +00:00
//accountID := "654a8909725f47e926f0bebc"
err := c.service.UpdateListCustom(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)
}