From ffd9f52bbdad716a72f6adf6f6301826ef2a67d0 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 1 Jul 2024 16:41:00 +0300 Subject: [PATCH] init methods delete and get all accounts --- service/account_svc.go | 1 - service/telegram_svc.go | 22 ++++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/service/account_svc.go b/service/account_svc.go index 434eba0..8affe78 100644 --- a/service/account_svc.go +++ b/service/account_svc.go @@ -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) diff --git a/service/telegram_svc.go b/service/telegram_svc.go index 14d25c5..b3cc56b 100644 --- a/service/telegram_svc.go +++ b/service/telegram_svc.go @@ -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) }