remove service errors, now use package from common
This commit is contained in:
parent
0a23c9ad66
commit
5ad4017cdb
@ -1,13 +1,13 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"amocrm/internal/service_errors"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
"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/model"
|
||||||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
|||||||
err = c.service.ChangeQuizSettings(ctx.Context(), &request, accountID, quizIDInt)
|
err = c.service.ChangeQuizSettings(ctx.Context(), &request, accountID, quizIDInt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, service_errors.ErrNotFound):
|
case errors.Is(err, pj_errors.ErrNotFound):
|
||||||
return ctx.Status(fiber.StatusNotFound).SendString("rule not found")
|
return ctx.Status(fiber.StatusNotFound).SendString("rule not found")
|
||||||
default:
|
default:
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
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))
|
return ctx.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("quiz settings already exist for accountID %s and quizID %d", accountID, quizIDInt))
|
||||||
}
|
}
|
||||||
switch {
|
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")
|
return ctx.Status(fiber.StatusNotFound).SendString("not found user for this rule")
|
||||||
default:
|
default:
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||||
@ -100,7 +100,7 @@ func (c *Controller) GettingQuizRules(ctx *fiber.Ctx) error {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, service_errors.ErrNotFound):
|
case errors.Is(err, pj_errors.ErrNotFound):
|
||||||
return ctx.Status(fiber.StatusNotFound).SendString("rule not found")
|
return ctx.Status(fiber.StatusNotFound).SendString("rule not found")
|
||||||
default:
|
default:
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"amocrm/internal/service_errors"
|
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/middleware"
|
"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)
|
response, err := c.service.GetCurrentAccount(ctx.Context(), accountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, service_errors.ErrNotFound):
|
case errors.Is(err, pj_errors.ErrNotFound):
|
||||||
return ctx.Status(fiber.StatusNotFound).SendString("user not found")
|
return ctx.Status(fiber.StatusNotFound).SendString("user not found")
|
||||||
default:
|
default:
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
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")
|
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//accountID := "64f2cd7a7047f28fdabf6d9e"
|
||||||
|
|
||||||
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
|
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error("error connect account", zap.Error(err))
|
c.logger.Error("error connect account", zap.Error(err))
|
||||||
|
@ -2,18 +2,18 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"amocrm/internal/models"
|
"amocrm/internal/models"
|
||||||
"amocrm/internal/service_errors"
|
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
"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 {
|
func (s *Service) ChangeQuizSettings(ctx context.Context, request *model.RulesReq, accountID string, quizID int) error {
|
||||||
err := s.repository.AmoRepo.ChangeQuizSettings(ctx, request, accountID, quizID)
|
err := s.repository.AmoRepo.ChangeQuizSettings(ctx, request, accountID, quizID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return service_errors.ErrNotFound
|
return pj_errors.ErrNotFound
|
||||||
}
|
}
|
||||||
s.logger.Error("error change quiz settings", zap.Error(err))
|
s.logger.Error("error change quiz settings", zap.Error(err))
|
||||||
return 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)
|
err := s.repository.AmoRepo.SetQuizSettings(ctx, request, accountID, quizID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return service_errors.ErrNotFound
|
return pj_errors.ErrNotFound
|
||||||
}
|
}
|
||||||
s.logger.Error("error setting quiz settings", zap.Error(err))
|
s.logger.Error("error setting quiz settings", zap.Error(err))
|
||||||
return 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)
|
rule, err := s.repository.AmoRepo.GettingQuizRules(ctx, quizID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, service_errors.ErrNotFound
|
return nil, pj_errors.ErrNotFound
|
||||||
}
|
}
|
||||||
s.logger.Error("error getting quiz settings", zap.Error(err))
|
s.logger.Error("error getting quiz settings", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -2,11 +2,11 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"amocrm/internal/models"
|
"amocrm/internal/models"
|
||||||
"amocrm/internal/service_errors"
|
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
"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 {
|
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)
|
user, err := s.repository.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
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))
|
s.logger.Error("error getting current account in getCurrentAccount service", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package service_errors
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
var ErrNotFound = errors.New("not found")
|
|
Loading…
Reference in New Issue
Block a user