hybrid pagination
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
"tm/pkg/logger"
|
||||
orm "tm/pkg/mongo"
|
||||
"tm/pkg/response"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
@@ -20,7 +21,7 @@ type ContactRepository interface {
|
||||
GetByID(ctx context.Context, id string) (*Contact, error)
|
||||
|
||||
// Search searches contacts with filters and pagination
|
||||
Search(ctx context.Context, filters SearchContactsForm, pagination orm.Pagination) (*orm.PaginatedResult[Contact], error)
|
||||
Search(ctx context.Context, filters SearchContactsForm, pagination *response.Pagination) (*orm.PaginatedResult[Contact], error)
|
||||
|
||||
// UpdateStatus updates the status of a contact
|
||||
UpdateStatus(ctx context.Context, id string, status ContactStatus, adminNotes *string, resolvedBy *string) error
|
||||
@@ -87,20 +88,17 @@ func (r *contactRepository) GetByID(ctx context.Context, id string) (*Contact, e
|
||||
}
|
||||
|
||||
// Search searches contacts with filters and pagination
|
||||
func (r *contactRepository) Search(ctx context.Context, filters SearchContactsForm, pagination orm.Pagination) (*orm.PaginatedResult[Contact], error) {
|
||||
func (r *contactRepository) Search(ctx context.Context, filters SearchContactsForm, pagination *response.Pagination) (*orm.PaginatedResult[Contact], error) {
|
||||
filter := bson.M{}
|
||||
|
||||
// Apply text search if provided
|
||||
if filters.Search != nil && *filters.Search != "" {
|
||||
filter["$text"] = bson.M{"$search": *filters.Search}
|
||||
}
|
||||
|
||||
// Apply status filter
|
||||
if filters.Status != nil && *filters.Status != "" {
|
||||
filter["status"] = *filters.Status
|
||||
}
|
||||
|
||||
// Apply date range filters
|
||||
if filters.DateFrom != nil || filters.DateTo != nil {
|
||||
dateFilter := bson.M{}
|
||||
if filters.DateFrom != nil {
|
||||
@@ -112,7 +110,20 @@ func (r *contactRepository) Search(ctx context.Context, filters SearchContactsFo
|
||||
filter["created_at"] = dateFilter
|
||||
}
|
||||
|
||||
return r.repo.FindAll(ctx, filter, pagination)
|
||||
mongoPagination, err := orm.BuildListPagination(
|
||||
pagination.Limit,
|
||||
pagination.Offset,
|
||||
pagination.Cursor,
|
||||
pagination.SortBy,
|
||||
pagination.SortOrder,
|
||||
filter,
|
||||
orm.ListPaginationOptions{},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r.repo.FindAll(ctx, filter, mongoPagination)
|
||||
}
|
||||
|
||||
// UpdateStatus updates the status of a contact
|
||||
|
||||
Reference in New Issue
Block a user