48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package controllers
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/gofiber/fiber/v2"
|
|
"gitea.pena/SQuiz/common/middleware"
|
|
"gitea.pena/SQuiz/common/pj_errors"
|
|
)
|
|
|
|
func (c *Controller) UpdateListPipelines(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.UpdateListPipelines(ctx.Context(), accountID)
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
}
|
|
|
|
func (c *Controller) GetPipelinesWithPagination(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
|
|
}
|
|
|
|
response, err := c.service.GetPipelinesWithPagination(ctx.Context(), req, accountID)
|
|
if err != nil {
|
|
switch {
|
|
case errors.Is(err, pj_errors.ErrNotFound):
|
|
return ctx.Status(fiber.StatusNotFound).SendString("pipelines for this user not found")
|
|
default:
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
}
|
|
return ctx.Status(fiber.StatusOK).JSON(response)
|
|
}
|