diff --git a/go.mod b/go.mod index db6901a..537e33e 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/twmb/franz-go v1.16.1 go.uber.org/zap v1.27.0 google.golang.org/protobuf v1.33.0 - penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240421140110-96a89cd0b56a + penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240421152238-836cb9fce7f1 penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af ) diff --git a/go.sum b/go.sum index 32fda44..4f9d978 100644 --- a/go.sum +++ b/go.sum @@ -153,5 +153,9 @@ penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3 penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM= penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240421140110-96a89cd0b56a h1:b9QF4TYZbfQ9wDZL+LnKNk7VzLLLvfHp+m+DbA4gzCc= penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240421140110-96a89cd0b56a/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240421152136-bba21decd33a h1:qP4qUVln7BXAYA8C983pa6a74arfbRJKbTGVHh+3zew= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240421152136-bba21decd33a/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240421152238-836cb9fce7f1 h1:jzhmhf7j+K6TVP5vY5/eHaA5405EqUsgfXDlHslDmBg= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240421152238-836cb9fce7f1/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64= penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo= penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I= diff --git a/internal/controllers/fields.go b/internal/controllers/fields.go index d4130de..dbba02a 100644 --- a/internal/controllers/fields.go +++ b/internal/controllers/fields.go @@ -5,13 +5,18 @@ import ( "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware" ) -func (c *Controller) GettingFieldsFromCash(ctx *fiber.Ctx) error { +func (c *Controller) GetFieldsWithPagination(ctx *fiber.Ctx) error { + accountID, ok := middleware.GetAccountId(ctx) + if !ok { + return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required") + } + req, err := extractParams(ctx) if err != nil { return err } - response, err := c.service.GetFieldsWithPagination(ctx.Context(), req) + response, err := c.service.GetFieldsWithPagination(ctx.Context(), req, accountID) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") } diff --git a/internal/controllers/initial.go b/internal/controllers/initial.go index 55bae3e..c13c076 100644 --- a/internal/controllers/initial.go +++ b/internal/controllers/initial.go @@ -25,26 +25,26 @@ func NewController(deps Deps) *Controller { func (c *Controller) Register(router fiber.Router) { router.Patch("/users", c.UpdateListUsers) - router.Get("/users", c.GettingUserFromCash) + router.Get("/users", c.GettingUserWithPagination) router.Delete("/utms/:quizID", c.DeletingUserUtm) router.Post("/utms/:quizID", c.SavingUserUtm) router.Get("/utms/:quizID", c.GettingUserUtm) router.Delete("/account", c.SoftDeleteAccount) router.Get("/account", c.GetCurrentAccount) router.Post("/account", c.ConnectAccount) - router.Get("/steps", c.GettingStepsFromCash) + router.Get("/steps", c.GetStepsWithPagination) router.Patch("/steps", c.UpdateListSteps) //todo поменять как было GET webhook/create router.Get("/", c.WebhookCreate) router.Get("/webhook/delete", c.WebhookDelete) router.Patch("/pipelines", c.UpdateListPipelines) - router.Get("/pipelines", c.GettingPipelinesFromCash) + router.Get("/pipelines", c.GetPipelinesWithPagination) router.Patch("/rules/:quizID", c.ChangeQuizSettings) router.Post("/rules/:quizID", c.SetQuizSettings) router.Get("/rules/:quizID", c.GettingQuizRules) router.Get("/tags", c.GettingTagsFromCash) router.Patch("/tags", c.UpdateListTags) - router.Get("/fields", c.GettingFieldsFromCash) + router.Get("/fields", c.GetFieldsWithPagination) router.Patch("/fields", c.UpdateListCustom) } diff --git a/internal/controllers/pipelines.go b/internal/controllers/pipelines.go index 33faeb0..8055ccc 100644 --- a/internal/controllers/pipelines.go +++ b/internal/controllers/pipelines.go @@ -21,13 +21,18 @@ func (c *Controller) UpdateListPipelines(ctx *fiber.Ctx) error { return ctx.SendStatus(fiber.StatusOK) } -func (c *Controller) GettingPipelinesFromCash(ctx *fiber.Ctx) error { +func (c *Controller) GetPipelinesWithPagination(ctx *fiber.Ctx) error { + accountID, ok := middleware.GetAccountId(ctx) + if !ok { + return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required") + } + req, err := extractParams(ctx) if err != nil { return err } - response, err := c.service.GetPipelinesWithPagination(ctx.Context(), req) + response, err := c.service.GetPipelinesWithPagination(ctx.Context(), req, accountID) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") } diff --git a/internal/controllers/steps.go b/internal/controllers/steps.go index 9622362..068d273 100644 --- a/internal/controllers/steps.go +++ b/internal/controllers/steps.go @@ -5,13 +5,18 @@ import ( "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware" ) -func (c *Controller) GettingStepsFromCash(ctx *fiber.Ctx) error { +func (c *Controller) GetStepsWithPagination(ctx *fiber.Ctx) error { + accountID, ok := middleware.GetAccountId(ctx) + if !ok { + return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required") + } + req, err := extractParams(ctx) if err != nil { return err } - response, err := c.service.GetStepsWithPagination(ctx.Context(), req) + response, err := c.service.GetStepsWithPagination(ctx.Context(), req, accountID) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") diff --git a/internal/controllers/tags.go b/internal/controllers/tags.go index 4b632da..e34a61b 100644 --- a/internal/controllers/tags.go +++ b/internal/controllers/tags.go @@ -6,12 +6,17 @@ import ( ) func (c *Controller) GettingTagsFromCash(ctx *fiber.Ctx) error { + accountID, ok := middleware.GetAccountId(ctx) + if !ok { + return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required") + } + req, err := extractParams(ctx) if err != nil { return err } - response, err := c.service.GetTagsWithPagination(ctx.Context(), req) + response, err := c.service.GetTagsWithPagination(ctx.Context(), req, accountID) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") } diff --git a/internal/controllers/user.go b/internal/controllers/user.go index 2a80eef..91709fd 100644 --- a/internal/controllers/user.go +++ b/internal/controllers/user.go @@ -24,13 +24,18 @@ func (c *Controller) UpdateListUsers(ctx *fiber.Ctx) error { return ctx.SendStatus(fiber.StatusOK) } -func (c *Controller) GettingUserFromCash(ctx *fiber.Ctx) error { +func (c *Controller) GettingUserWithPagination(ctx *fiber.Ctx) error { + accountID, ok := middleware.GetAccountId(ctx) + if !ok { + return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required") + } + req, err := extractParams(ctx) if err != nil { return err } - response, err := c.service.GettingUserWithPagination(ctx.Context(), req) + response, err := c.service.GettingUserWithPagination(ctx.Context(), req, accountID) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") } diff --git a/internal/controllers/utm.go b/internal/controllers/utm.go index bdf6b9f..2747808 100644 --- a/internal/controllers/utm.go +++ b/internal/controllers/utm.go @@ -8,7 +8,7 @@ import ( ) func (c *Controller) DeletingUserUtm(ctx *fiber.Ctx) error { - _, ok := middleware.GetAccountId(ctx) + accountID, ok := middleware.GetAccountId(ctx) if !ok { return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required") } @@ -18,7 +18,7 @@ func (c *Controller) DeletingUserUtm(ctx *fiber.Ctx) error { return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"}) } - err := c.service.DeletingUserUtm(ctx.Context(), &request) + err := c.service.DeletingUserUtm(ctx.Context(), &request, accountID) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") } diff --git a/internal/service/fields.go b/internal/service/fields.go index 18fd6f0..45661fa 100644 --- a/internal/service/fields.go +++ b/internal/service/fields.go @@ -7,8 +7,8 @@ import ( "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model" ) -func (s *Service) GetFieldsWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListFieldsResp, error) { - response, err := s.repository.AmoRepo.GetFieldsWithPagination(ctx, req) +func (s *Service) GetFieldsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListFieldsResp, error) { + response, err := s.repository.AmoRepo.GetFieldsWithPagination(ctx, req, accountID) if err != nil { s.logger.Error("error getting fields with pagination", zap.Error(err)) return nil, err diff --git a/internal/service/pipelines.go b/internal/service/pipelines.go index 2867b76..b2a809e 100644 --- a/internal/service/pipelines.go +++ b/internal/service/pipelines.go @@ -22,8 +22,8 @@ func (s *Service) UpdateListPipelines(ctx context.Context, accountID string) err return nil } -func (s *Service) GetPipelinesWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListPipelinesResp, error) { - response, err := s.repository.AmoRepo.GetPipelinesWithPagination(ctx, req) +func (s *Service) GetPipelinesWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListPipelinesResp, error) { + response, err := s.repository.AmoRepo.GetPipelinesWithPagination(ctx, req, accountID) if err != nil { s.logger.Error("error getting pipelines with pagination", zap.Error(err)) return nil, err diff --git a/internal/service/steps.go b/internal/service/steps.go index 7eb40b1..19e306e 100644 --- a/internal/service/steps.go +++ b/internal/service/steps.go @@ -7,8 +7,8 @@ import ( "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model" ) -func (s *Service) GetStepsWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListStepsResp, error) { - response, err := s.repository.AmoRepo.GetStepsWithPagination(ctx, req) +func (s *Service) GetStepsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListStepsResp, error) { + response, err := s.repository.AmoRepo.GetStepsWithPagination(ctx, req, accountID) if err != nil { s.logger.Error("error getting steps with pagination", zap.Error(err)) return nil, err diff --git a/internal/service/tags.go b/internal/service/tags.go index 3589766..2dd8fc0 100644 --- a/internal/service/tags.go +++ b/internal/service/tags.go @@ -7,8 +7,8 @@ import ( "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model" ) -func (s *Service) GetTagsWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListTagsResp, error) { - response, err := s.repository.AmoRepo.GetTagsWithPagination(ctx, req) +func (s *Service) GetTagsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListTagsResp, error) { + response, err := s.repository.AmoRepo.GetTagsWithPagination(ctx, req, accountID) if err != nil { s.logger.Error("error getting tags with pagination", zap.Error(err)) return nil, err diff --git a/internal/service/user.go b/internal/service/user.go index 5ef6ef8..7332605 100644 --- a/internal/service/user.go +++ b/internal/service/user.go @@ -22,8 +22,8 @@ func (s *Service) UpdateListUsers(ctx context.Context, accountID string) error { return nil } -func (s *Service) GettingUserWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListResp, error) { - response, err := s.repository.AmoRepo.GettingUserWithPagination(ctx, req) +func (s *Service) GettingUserWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListResp, error) { + response, err := s.repository.AmoRepo.GettingUserWithPagination(ctx, req, accountID) if err != nil { s.logger.Error("error getting users with pagination", zap.Error(err)) return nil, err diff --git a/internal/service/utm.go b/internal/service/utm.go index 4c96c95..facae13 100644 --- a/internal/service/utm.go +++ b/internal/service/utm.go @@ -6,8 +6,8 @@ import ( "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model" ) -func (s *Service) DeletingUserUtm(ctx context.Context, request *model.ListDeleteUTMIDsReq) error { - err := s.repository.AmoRepo.DeletingUserUtm(ctx, request) +func (s *Service) DeletingUserUtm(ctx context.Context, request *model.ListDeleteUTMIDsReq, accountID string) error { + err := s.repository.AmoRepo.DeletingUserUtm(ctx, request, accountID) if err != nil { s.logger.Error("error deleting user utm", zap.Error(err)) return err diff --git a/tests/repository/repository_test.go b/tests/repository/repository_test.go index 085be6e..e67300b 100644 --- a/tests/repository/repository_test.go +++ b/tests/repository/repository_test.go @@ -158,7 +158,7 @@ func gettingUserFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) er Size: int32(i), } - resp, err := repo.AmoRepo.GettingUserWithPagination(ctx, &req) + resp, err := repo.AmoRepo.GettingUserWithPagination(ctx, &req, "5") if err != nil { return err } @@ -206,7 +206,7 @@ func gettingPipelinesFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDa Size: int32(i), } - resp, err := repo.AmoRepo.GetPipelinesWithPagination(ctx, &req) + resp, err := repo.AmoRepo.GetPipelinesWithPagination(ctx, &req, "4") if err != nil { return err } @@ -254,7 +254,7 @@ func gettingStepsFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) e Size: int32(i), } - resp, err := repo.AmoRepo.GetStepsWithPagination(ctx, &req) + resp, err := repo.AmoRepo.GetStepsWithPagination(ctx, &req, "3") if err != nil { return err } @@ -366,7 +366,7 @@ func gettingTagsFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) er Size: int32(i), } - resp, err := repo.AmoRepo.GetTagsWithPagination(ctx, &req) + resp, err := repo.AmoRepo.GetTagsWithPagination(ctx, &req, "2") if err != nil { return err } @@ -480,7 +480,7 @@ func gettingFieldsFromCash(ctx context.Context, t *testing.T, repo *dal.AmoDal) Size: int32(i), } - resp, err := repo.AmoRepo.GetFieldsWithPagination(ctx, &req) + resp, err := repo.AmoRepo.GetFieldsWithPagination(ctx, &req, "1") if err != nil { return err }