add pagination methods

This commit is contained in:
Pavel 2024-04-12 19:39:51 +03:00
parent 4a952cb3e5
commit 8f3b0e5489
16 changed files with 194 additions and 43 deletions

@ -8,7 +8,7 @@ func (c *Controller) GettingFieldsFromCash(ctx *fiber.Ctx) error {
return err
}
response, err := c.service.GettingFieldsFromCash(ctx.Context())
response, err := c.service.GettingFieldsFromCash(ctx.Context(), req)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}

@ -17,8 +17,7 @@ func (c *Controller) GettingPipelinesFromCash(ctx *fiber.Ctx) error {
return err
}
response, err := c.service.GettingPipelinesFromCash(ctx.Context())
response, err := c.service.GettingPipelinesFromCash(ctx.Context(), req)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}

@ -8,7 +8,7 @@ func (c *Controller) GettingStepsFromCash(ctx *fiber.Ctx) error {
return err
}
response, err := c.service.GettingStepsFromCash(ctx.Context())
response, err := c.service.GettingStepsFromCash(ctx.Context(), req)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")

@ -8,8 +8,7 @@ func (c *Controller) GettingTagsFromCash(ctx *fiber.Ctx) error {
return err
}
response, err := c.service.GettingTagsFromCash(ctx.Context())
response, err := c.service.GettingTagsFromCash(ctx.Context(), req)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}

@ -23,8 +23,7 @@ func (c *Controller) GettingUserFromCash(ctx *fiber.Ctx) error {
return err
}
response, err := c.service.GettingUserFromCash(ctx.Context())
response, err := c.service.GettingUserFromCash(ctx.Context(), req)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}

@ -38,21 +38,21 @@ type ListSavedIDUTMResp struct {
type UserListFieldsResp struct {
/* - общее количество кастомных полей, которые у нас закешированы для этого пользователя*/
Count int `json:"count"`
Count int64 `json:"count"`
/* - список кастомных полей, которые были закешированы нашим сервисом*/
Items []Field `json:"items"`
}
type UserListPipelinesResp struct {
/* - общее количество воронок, которые у нас закешированы для этого пользователя*/
Count int `json:"count"`
Count int64 `json:"count"`
/* - список воронок, которые были закешированы нашим сервисом*/
Items []Pipeline `json:"items"`
}
type UserListResp struct {
/* - общее количество юзеров, которые у нас закешированы для этого пользователя*/
Count int `json:"count"`
Count int64 `json:"count"`
/* - список юзеров, которые были закешированы нашим сервисом*/
Items []User `json:"items"`
}
@ -61,12 +61,12 @@ type UserListStepsResp struct {
/* - список шагов воронок, которые были закешированы нашим сервисом*/
Items []Step `json:"items"`
/* - общее количество шагов воронок, которые у нас закешированы для этого пользователя*/
Count int `json:"count"`
Count int64 `json:"count"`
}
type UserListTagsResp struct {
/* - общее количество тегов, которые у нас закешированы для этого пользователя*/
Count int `json:"count"`
Count int64 `json:"count"`
/* - список тегов, которые были закешированы нашим сервисом*/
Items []Tag `json:"items"`
}

@ -6,13 +6,43 @@ import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"time"
)
func (r *Repository) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
//TODO:IMPLEMENT ME
func (r *Repository) GettingFieldsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListFieldsResp, error) {
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 {

@ -6,6 +6,7 @@ import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"time"
)
@ -16,10 +17,39 @@ func (r *Repository) UpdateListPipelines(ctx context.Context) error {
}
func (r *Repository) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
//TODO:IMPLEMENT ME
func (r *Repository) GettingPipelinesFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListPipelinesResp, error) {
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 {

@ -6,13 +6,43 @@ import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"time"
)
func (r *Repository) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
//TODO:IMPLEMENT ME
func (r *Repository) GettingStepsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListStepsResp, error) {
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 {

@ -6,13 +6,43 @@ import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"time"
)
func (r *Repository) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
//TODO:IMPLEMENT ME
func (r *Repository) GettingTagsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListTagsResp, error) {
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 {

@ -5,6 +5,7 @@ import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"time"
)
@ -15,10 +16,39 @@ func (r *Repository) UpdateListUsers(ctx context.Context) error {
}
func (r *Repository) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
//TODO:IMPLEMENT ME
func (r *Repository) GettingUserFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListResp, error) {
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 {

@ -3,12 +3,13 @@ package service
import (
"amocrm/internal/models"
"context"
"go.uber.org/zap"
)
func (s *Service) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
response, err := s.repository.GettingFieldsFromCash(ctx)
func (s *Service) GettingFieldsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListFieldsResp, error) {
response, err := s.repository.GettingFieldsFromCash(ctx, req)
if err != nil {
s.logger.Error("error getting fields with pagination", zap.Error(err))
return nil, err
}
return response, nil

@ -3,6 +3,7 @@ package service
import (
"amocrm/internal/models"
"context"
"go.uber.org/zap"
)
func (s *Service) UpdateListPipelines(ctx context.Context) error {
@ -14,10 +15,10 @@ func (s *Service) UpdateListPipelines(ctx context.Context) error {
return nil
}
func (s *Service) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
response, err := s.repository.GettingPipelinesFromCash(ctx)
func (s *Service) GettingPipelinesFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListPipelinesResp, error) {
response, err := s.repository.GettingPipelinesFromCash(ctx, req)
if err != nil {
s.logger.Error("error getting pipelines with pagination", zap.Error(err))
return nil, err
}
return response, nil

@ -3,12 +3,13 @@ package service
import (
"amocrm/internal/models"
"context"
"go.uber.org/zap"
)
func (s *Service) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
response, err := s.repository.GettingStepsFromCash(ctx)
func (s *Service) GettingStepsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListStepsResp, error) {
response, err := s.repository.GettingStepsFromCash(ctx, req)
if err != nil {
s.logger.Error("error getting steps with pagination", zap.Error(err))
return nil, err
}
return response, nil

@ -3,12 +3,13 @@ package service
import (
"amocrm/internal/models"
"context"
"go.uber.org/zap"
)
func (s *Service) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
response, err := s.repository.GettingTagsFromCash(ctx)
func (s *Service) GettingTagsFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListTagsResp, error) {
response, err := s.repository.GettingTagsFromCash(ctx, req)
if err != nil {
s.logger.Error("error getting tags with pagination", zap.Error(err))
return nil, err
}
return response, nil

@ -15,10 +15,10 @@ func (s *Service) UpdateListUsers(ctx context.Context) error {
return nil
}
func (s *Service) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
response, err := s.repository.GettingUserFromCash(ctx)
func (s *Service) GettingUserFromCash(ctx context.Context, req *models.PaginationReq) (*models.UserListResp, error) {
response, err := s.repository.GettingUserFromCash(ctx, req)
if err != nil {
s.logger.Error("error getting users with pagination", zap.Error(err))
return nil, err
}
return response, nil