84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
|
"strconv"
|
|
)
|
|
|
|
func (c *Controller) DeletingUserUtm(ctx *fiber.Ctx) error {
|
|
_, ok := middleware.GetAccountId(ctx)
|
|
if !ok {
|
|
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
|
}
|
|
|
|
var request model.ListDeleteUTMIDsReq
|
|
if err := ctx.BodyParser(&request); err != nil {
|
|
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
|
}
|
|
|
|
err := c.service.DeletingUserUtm(ctx.Context(), &request)
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
}
|
|
|
|
func (c *Controller) SavingUserUtm(ctx *fiber.Ctx) error {
|
|
accountID, ok := middleware.GetAccountId(ctx)
|
|
if !ok {
|
|
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
|
}
|
|
quizID := ctx.Params("quizID")
|
|
if quizID == "" {
|
|
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
|
}
|
|
|
|
quizIDInt, err := strconv.Atoi(quizID)
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusBadRequest).SendString("failed convert quizID to int")
|
|
}
|
|
|
|
var request model.SaveUserListUTMReq
|
|
if err := ctx.BodyParser(&request); err != nil {
|
|
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
|
}
|
|
|
|
response, err := c.service.SavingUserUtm(ctx.Context(), &request, accountID, quizIDInt)
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.Status(fiber.StatusOK).JSON(response)
|
|
}
|
|
|
|
func (c *Controller) GettingUserUtm(ctx *fiber.Ctx) error {
|
|
accountID, ok := middleware.GetAccountId(ctx)
|
|
if !ok {
|
|
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
|
}
|
|
|
|
quizID := ctx.Params("quizID")
|
|
if quizID == "" {
|
|
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
|
}
|
|
|
|
quizIDInt, err := strconv.Atoi(quizID)
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusBadRequest).SendString("failed convert quizID to int")
|
|
}
|
|
|
|
req, err := extractParams(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
response, err := c.service.GettingUserUtm(ctx.Context(), req, accountID, quizIDInt)
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.Status(fiber.StatusOK).JSON(response)
|
|
}
|