add pagination methods
This commit is contained in:
parent
4a952cb3e5
commit
8f3b0e5489
@ -8,7 +8,7 @@ func (c *Controller) GettingFieldsFromCash(ctx *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := c.service.GettingFieldsFromCash(ctx.Context())
|
response, err := c.service.GettingFieldsFromCash(ctx.Context(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,7 @@ func (c *Controller) GettingPipelinesFromCash(ctx *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := c.service.GettingPipelinesFromCash(ctx.Context())
|
response, err := c.service.GettingPipelinesFromCash(ctx.Context(), req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ func (c *Controller) GettingStepsFromCash(ctx *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := c.service.GettingStepsFromCash(ctx.Context())
|
response, err := c.service.GettingStepsFromCash(ctx.Context(), req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||||
|
@ -8,8 +8,7 @@ func (c *Controller) GettingTagsFromCash(ctx *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := c.service.GettingTagsFromCash(ctx.Context())
|
response, err := c.service.GettingTagsFromCash(ctx.Context(), req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ func (c *Controller) GettingUserFromCash(ctx *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := c.service.GettingUserFromCash(ctx.Context())
|
response, err := c.service.GettingUserFromCash(ctx.Context(), req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||||
}
|
}
|
||||||
|
@ -38,21 +38,21 @@ type ListSavedIDUTMResp struct {
|
|||||||
|
|
||||||
type UserListFieldsResp struct {
|
type UserListFieldsResp struct {
|
||||||
/* - общее количество кастомных полей, которые у нас закешированы для этого пользователя*/
|
/* - общее количество кастомных полей, которые у нас закешированы для этого пользователя*/
|
||||||
Count int `json:"count"`
|
Count int64 `json:"count"`
|
||||||
/* - список кастомных полей, которые были закешированы нашим сервисом*/
|
/* - список кастомных полей, которые были закешированы нашим сервисом*/
|
||||||
Items []Field `json:"items"`
|
Items []Field `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserListPipelinesResp struct {
|
type UserListPipelinesResp struct {
|
||||||
/* - общее количество воронок, которые у нас закешированы для этого пользователя*/
|
/* - общее количество воронок, которые у нас закешированы для этого пользователя*/
|
||||||
Count int `json:"count"`
|
Count int64 `json:"count"`
|
||||||
/* - список воронок, которые были закешированы нашим сервисом*/
|
/* - список воронок, которые были закешированы нашим сервисом*/
|
||||||
Items []Pipeline `json:"items"`
|
Items []Pipeline `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserListResp struct {
|
type UserListResp struct {
|
||||||
/* - общее количество юзеров, которые у нас закешированы для этого пользователя*/
|
/* - общее количество юзеров, которые у нас закешированы для этого пользователя*/
|
||||||
Count int `json:"count"`
|
Count int64 `json:"count"`
|
||||||
/* - список юзеров, которые были закешированы нашим сервисом*/
|
/* - список юзеров, которые были закешированы нашим сервисом*/
|
||||||
Items []User `json:"items"`
|
Items []User `json:"items"`
|
||||||
}
|
}
|
||||||
@ -61,12 +61,12 @@ type UserListStepsResp struct {
|
|||||||
/* - список шагов воронок, которые были закешированы нашим сервисом*/
|
/* - список шагов воронок, которые были закешированы нашим сервисом*/
|
||||||
Items []Step `json:"items"`
|
Items []Step `json:"items"`
|
||||||
/* - общее количество шагов воронок, которые у нас закешированы для этого пользователя*/
|
/* - общее количество шагов воронок, которые у нас закешированы для этого пользователя*/
|
||||||
Count int `json:"count"`
|
Count int64 `json:"count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserListTagsResp struct {
|
type UserListTagsResp struct {
|
||||||
/* - общее количество тегов, которые у нас закешированы для этого пользователя*/
|
/* - общее количество тегов, которые у нас закешированы для этого пользователя*/
|
||||||
Count int `json:"count"`
|
Count int64 `json:"count"`
|
||||||
/* - список тегов, которые были закешированы нашим сервисом*/
|
/* - список тегов, которые были закешированы нашим сервисом*/
|
||||||
Items []Tag `json:"items"`
|
Items []Tag `json:"items"`
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,43 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Repository) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
func (r *Repository) GettingFieldsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListFieldsResp, error) {
|
||||||
//TODO:IMPLEMENT ME
|
offset := (req.Page - 1) * req.Size
|
||||||
|
|
||||||
return &models.UserListFieldsResp{}, nil
|
totalFields, err := r.fields.CountDocuments(ctx, bson.M{"deleted": false})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var fields []models.Field
|
||||||
|
|
||||||
|
cursor, err := r.fields.Find(ctx, bson.M{"deleted": false}, options.Find().SetLimit(int64(req.Size)).SetSkip(int64(offset)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
|
for cursor.Next(ctx) {
|
||||||
|
var field models.Field
|
||||||
|
if err := cursor.Decode(&field); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fields = append(fields, field)
|
||||||
|
}
|
||||||
|
if err := cursor.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldListResp := &models.UserListFieldsResp{
|
||||||
|
Count: totalFields,
|
||||||
|
Items: fields,
|
||||||
|
}
|
||||||
|
|
||||||
|
return fieldListResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) UpdateListCustom(ctx context.Context) error {
|
func (r *Repository) UpdateListCustom(ctx context.Context) error {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,10 +17,39 @@ func (r *Repository) UpdateListPipelines(ctx context.Context) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
func (r *Repository) GettingPipelinesFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListPipelinesResp, error) {
|
||||||
//TODO:IMPLEMENT ME
|
offset := (req.Page - 1) * req.Size
|
||||||
|
|
||||||
return &models.UserListPipelinesResp{}, nil
|
totalPipelines, err := r.pipelines.CountDocuments(ctx, bson.M{"deleted": false})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pipelines []models.Pipeline
|
||||||
|
|
||||||
|
cursor, err := r.pipelines.Find(ctx, bson.M{"deleted": false}, options.Find().SetLimit(int64(req.Size)).SetSkip(int64(offset)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
|
for cursor.Next(ctx) {
|
||||||
|
var pipeline models.Pipeline
|
||||||
|
if err := cursor.Decode(&pipeline); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pipelines = append(pipelines, pipeline)
|
||||||
|
}
|
||||||
|
if err := cursor.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pipelineListResp := &models.UserListPipelinesResp{
|
||||||
|
Count: totalPipelines,
|
||||||
|
Items: pipelines,
|
||||||
|
}
|
||||||
|
|
||||||
|
return pipelineListResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) CheckPipelines(ctx context.Context, accountID string, pipelines []amo.Pipeline) error {
|
func (r *Repository) CheckPipelines(ctx context.Context, accountID string, pipelines []amo.Pipeline) error {
|
||||||
|
@ -6,13 +6,43 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Repository) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
func (r *Repository) GettingStepsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListStepsResp, error) {
|
||||||
//TODO:IMPLEMENT ME
|
offset := (req.Page - 1) * req.Size
|
||||||
|
|
||||||
return &models.UserListStepsResp{}, nil
|
totalSteps, err := r.steps.CountDocuments(ctx, bson.M{"deleted": false})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var steps []models.Step
|
||||||
|
|
||||||
|
cursor, err := r.steps.Find(ctx, bson.M{"deleted": false}, options.Find().SetLimit(int64(req.Size)).SetSkip(int64(offset)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
|
for cursor.Next(ctx) {
|
||||||
|
var step models.Step
|
||||||
|
if err := cursor.Decode(&step); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
steps = append(steps, step)
|
||||||
|
}
|
||||||
|
if err := cursor.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
stepListResp := &models.UserListStepsResp{
|
||||||
|
Count: totalSteps,
|
||||||
|
Items: steps,
|
||||||
|
}
|
||||||
|
|
||||||
|
return stepListResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) UpdateListSteps(ctx context.Context) error {
|
func (r *Repository) UpdateListSteps(ctx context.Context) error {
|
||||||
|
@ -6,13 +6,43 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Repository) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
func (r *Repository) GettingTagsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListTagsResp, error) {
|
||||||
//TODO:IMPLEMENT ME
|
offset := (req.Page - 1) * req.Size
|
||||||
|
|
||||||
return &models.UserListTagsResp{}, nil
|
totalTags, err := r.tags.CountDocuments(ctx, bson.M{"deleted": false})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tags []models.Tag
|
||||||
|
|
||||||
|
cursor, err := r.tags.Find(ctx, bson.M{"deleted": false}, options.Find().SetLimit(int64(req.Size)).SetSkip(int64(offset)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
|
for cursor.Next(ctx) {
|
||||||
|
var tag models.Tag
|
||||||
|
if err := cursor.Decode(&tag); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tags = append(tags, tag)
|
||||||
|
}
|
||||||
|
if err := cursor.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tagListResp := &models.UserListTagsResp{
|
||||||
|
Count: totalTags,
|
||||||
|
Items: tags,
|
||||||
|
}
|
||||||
|
|
||||||
|
return tagListResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) UpdateListTags(ctx context.Context) error {
|
func (r *Repository) UpdateListTags(ctx context.Context) error {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,10 +16,39 @@ func (r *Repository) UpdateListUsers(ctx context.Context) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
func (r *Repository) GettingUserFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListResp, error) {
|
||||||
//TODO:IMPLEMENT ME
|
offset := (req.Page - 1) * req.Size
|
||||||
|
|
||||||
return &models.UserListResp{}, nil
|
totalUsers, err := r.mdbUser.CountDocuments(ctx, bson.M{"Deleted": false})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var users []models.User
|
||||||
|
|
||||||
|
cursor, err := r.mdbUser.Find(ctx, bson.M{"Deleted": false}, options.Find().SetLimit(int64(req.Size)).SetSkip(int64(offset)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
|
for cursor.Next(ctx) {
|
||||||
|
var user models.User
|
||||||
|
if err := cursor.Decode(&user); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
users = append(users, user)
|
||||||
|
}
|
||||||
|
if err := cursor.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
userListResp := &models.UserListResp{
|
||||||
|
Count: totalUsers,
|
||||||
|
Items: users,
|
||||||
|
}
|
||||||
|
|
||||||
|
return userListResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) SoftDeleteAccount(ctx context.Context, accountID string) error {
|
func (r *Repository) SoftDeleteAccount(ctx context.Context, accountID string) error {
|
||||||
|
@ -3,12 +3,13 @@ package service
|
|||||||
import (
|
import (
|
||||||
"amocrm/internal/models"
|
"amocrm/internal/models"
|
||||||
"context"
|
"context"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
func (s *Service) GettingFieldsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListFieldsResp, error) {
|
||||||
|
response, err := s.repository.GettingFieldsFromCash(ctx, req)
|
||||||
response, err := s.repository.GettingFieldsFromCash(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.logger.Error("error getting fields with pagination", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"amocrm/internal/models"
|
"amocrm/internal/models"
|
||||||
"context"
|
"context"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) UpdateListPipelines(ctx context.Context) error {
|
func (s *Service) UpdateListPipelines(ctx context.Context) error {
|
||||||
@ -14,10 +15,10 @@ func (s *Service) UpdateListPipelines(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
func (s *Service) GettingPipelinesFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListPipelinesResp, error) {
|
||||||
|
response, err := s.repository.GettingPipelinesFromCash(ctx, req)
|
||||||
response, err := s.repository.GettingPipelinesFromCash(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.logger.Error("error getting pipelines with pagination", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -3,12 +3,13 @@ package service
|
|||||||
import (
|
import (
|
||||||
"amocrm/internal/models"
|
"amocrm/internal/models"
|
||||||
"context"
|
"context"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
func (s *Service) GettingStepsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListStepsResp, error) {
|
||||||
|
response, err := s.repository.GettingStepsFromCash(ctx, req)
|
||||||
response, err := s.repository.GettingStepsFromCash(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.logger.Error("error getting steps with pagination", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -3,12 +3,13 @@ package service
|
|||||||
import (
|
import (
|
||||||
"amocrm/internal/models"
|
"amocrm/internal/models"
|
||||||
"context"
|
"context"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
func (s *Service) GettingTagsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListTagsResp, error) {
|
||||||
|
response, err := s.repository.GettingTagsFromCash(ctx, req)
|
||||||
response, err := s.repository.GettingTagsFromCash(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.logger.Error("error getting tags with pagination", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
|
@ -15,10 +15,10 @@ func (s *Service) UpdateListUsers(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
func (s *Service) GettingUserFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListResp, error) {
|
||||||
|
response, err := s.repository.GettingUserFromCash(ctx, req)
|
||||||
response, err := s.repository.GettingUserFromCash(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.logger.Error("error getting users with pagination", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user