init methods delete and get all accounts

This commit is contained in:
Pavel 2024-07-01 16:41:00 +03:00
parent 456fbd3d2f
commit ffd9f52bbd
2 changed files with 20 additions and 3 deletions

@ -316,7 +316,6 @@ func (s *Service) GetLeadTarget(ctx *fiber.Ctx) error {
default:
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
}
return ctx.Status(fiber.StatusOK).JSON(result)

@ -10,6 +10,7 @@ import (
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
"penahub.gitlab.yandexcloud.net/backend/quiz/core/clients/telegram"
"penahub.gitlab.yandexcloud.net/backend/tdlib/client"
"strconv"
)
type Message struct {
@ -18,7 +19,16 @@ type Message struct {
}
func (s *Service) GetPoolTgAccounts(ctx *fiber.Ctx) error {
return nil
allAccounts, err := s.dal.TgRepo.GetAllTgAccounts(ctx.Context())
if err != nil {
switch {
case errors.Is(err, pj_errors.ErrNotFound):
return ctx.Status(fiber.StatusNotFound).SendString("not found")
default:
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
}
return ctx.Status(fiber.StatusOK).JSON(allAccounts)
}
func (s *Service) AddingTgAccount(ctx *fiber.Ctx) error {
@ -142,5 +152,13 @@ func (s *Service) SettingTgCode(ctx *fiber.Ctx) error {
}
func (s *Service) DeleteTgAccountByID(ctx *fiber.Ctx) error {
return nil
id, err := strconv.ParseInt(ctx.Params("id"), 10, 64)
if err != nil {
return ctx.Status(fiber.StatusBadRequest).SendString("invalid id format")
}
err = s.dal.TgRepo.SoftDeleteTgAccount(ctx.Context(), id)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
return ctx.SendStatus(fiber.StatusOK)
}