remove service errors, now use package from common

This commit is contained in:
Pavel 2024-06-05 11:47:37 +03:00
parent 0a23c9ad66
commit 5ad4017cdb
5 changed files with 14 additions and 17 deletions

@ -1,13 +1,13 @@
package controllers
import (
"amocrm/internal/service_errors"
"errors"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/lib/pq"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
"strconv"
)
@ -37,7 +37,7 @@ func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
err = c.service.ChangeQuizSettings(ctx.Context(), &request, accountID, quizIDInt)
if err != nil {
switch {
case errors.Is(err, service_errors.ErrNotFound):
case errors.Is(err, pj_errors.ErrNotFound):
return ctx.Status(fiber.StatusNotFound).SendString("rule not found")
default:
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
@ -76,7 +76,7 @@ func (c *Controller) SetQuizSettings(ctx *fiber.Ctx) error {
return ctx.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("quiz settings already exist for accountID %s and quizID %d", accountID, quizIDInt))
}
switch {
case errors.Is(err, service_errors.ErrNotFound):
case errors.Is(err, pj_errors.ErrNotFound):
return ctx.Status(fiber.StatusNotFound).SendString("not found user for this rule")
default:
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
@ -100,7 +100,7 @@ func (c *Controller) GettingQuizRules(ctx *fiber.Ctx) error {
if err != nil {
switch {
case errors.Is(err, service_errors.ErrNotFound):
case errors.Is(err, pj_errors.ErrNotFound):
return ctx.Status(fiber.StatusNotFound).SendString("rule not found")
default:
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")

@ -1,10 +1,10 @@
package controllers
import (
"amocrm/internal/service_errors"
"errors"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/middleware"
)
@ -66,7 +66,7 @@ func (c *Controller) GetCurrentAccount(ctx *fiber.Ctx) error {
response, err := c.service.GetCurrentAccount(ctx.Context(), accountID)
if err != nil {
switch {
case errors.Is(err, service_errors.ErrNotFound):
case errors.Is(err, pj_errors.ErrNotFound):
return ctx.Status(fiber.StatusNotFound).SendString("user not found")
default:
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
@ -81,6 +81,8 @@ func (c *Controller) ConnectAccount(ctx *fiber.Ctx) error {
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
}
//accountID := "64f2cd7a7047f28fdabf6d9e"
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
if err != nil {
c.logger.Error("error connect account", zap.Error(err))

@ -2,18 +2,18 @@ package service
import (
"amocrm/internal/models"
"amocrm/internal/service_errors"
"context"
"database/sql"
"go.uber.org/zap"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
)
func (s *Service) ChangeQuizSettings(ctx context.Context, request *model.RulesReq, accountID string, quizID int) error {
err := s.repository.AmoRepo.ChangeQuizSettings(ctx, request, accountID, quizID)
if err != nil {
if err == sql.ErrNoRows {
return service_errors.ErrNotFound
return pj_errors.ErrNotFound
}
s.logger.Error("error change quiz settings", zap.Error(err))
return err
@ -46,7 +46,7 @@ func (s *Service) SetQuizSettings(ctx context.Context, request *model.RulesReq,
err := s.repository.AmoRepo.SetQuizSettings(ctx, request, accountID, quizID)
if err != nil {
if err == sql.ErrNoRows {
return service_errors.ErrNotFound
return pj_errors.ErrNotFound
}
s.logger.Error("error setting quiz settings", zap.Error(err))
return err
@ -79,7 +79,7 @@ func (s *Service) GettingQuizRules(ctx context.Context, quizID int) (*model.Rule
rule, err := s.repository.AmoRepo.GettingQuizRules(ctx, quizID)
if err != nil {
if err == sql.ErrNoRows {
return nil, service_errors.ErrNotFound
return nil, pj_errors.ErrNotFound
}
s.logger.Error("error getting quiz settings", zap.Error(err))
return nil, err

@ -2,11 +2,11 @@ package service
import (
"amocrm/internal/models"
"amocrm/internal/service_errors"
"context"
"database/sql"
"go.uber.org/zap"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
)
func (s *Service) UpdateListUsers(ctx context.Context, accountID string) error {
@ -46,7 +46,7 @@ func (s *Service) GetCurrentAccount(ctx context.Context, accountID string) (*mod
user, err := s.repository.AmoRepo.GetCurrentAccount(ctx, accountID)
if err != nil {
if err == sql.ErrNoRows {
return nil, service_errors.ErrNotFound
return nil, pj_errors.ErrNotFound
}
s.logger.Error("error getting current account in getCurrentAccount service", zap.Error(err))
return nil, err

@ -1,5 +0,0 @@
package service_errors
import "errors"
var ErrNotFound = errors.New("not found")