hybrid pagination
This commit is contained in:
@@ -218,16 +218,16 @@ func (s *customerService) GetByID(ctx context.Context, id string) (*CustomerResp
|
||||
|
||||
// Search searches for customers
|
||||
func (s *customerService) Search(ctx context.Context, form *SearchCustomersForm, pagination *response.Pagination) (*CustomerListResponse, error) {
|
||||
customers, total, err := s.repository.Search(ctx, form, pagination)
|
||||
page, err := s.repository.Search(ctx, form, pagination)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to search customers", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return nil, errors.New("failed to search customers")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var customerResponses []*CustomerResponse
|
||||
for _, customer := range customers {
|
||||
for _, customer := range page.Items {
|
||||
companies, err := s.loadCompaniesForCustomer(ctx, &customer)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to load companies for customer", map[string]interface{}{
|
||||
@@ -241,12 +241,12 @@ func (s *customerService) Search(ctx context.Context, form *SearchCustomersForm,
|
||||
|
||||
return &CustomerListResponse{
|
||||
Customers: customerResponses,
|
||||
Meta: pagination.Response(total),
|
||||
Meta: pagination.ListMeta(page.TotalCount, page.NextCursor, page.HasMore, page.PageOffset),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *customerService) SearchNotification(ctx context.Context, form *SearchCustomersForm, pagination *response.Pagination) ([]*CustomerNotificationResponse, error) {
|
||||
customers, _, err := s.repository.Search(ctx, form, pagination)
|
||||
page, err := s.repository.Search(ctx, form, pagination)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to search customers", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
@@ -255,7 +255,7 @@ func (s *customerService) SearchNotification(ctx context.Context, form *SearchCu
|
||||
}
|
||||
|
||||
var customerResponses []*CustomerNotificationResponse
|
||||
for _, customer := range customers {
|
||||
for _, customer := range page.Items {
|
||||
customerResponses = append(customerResponses, customer.ToNotificationResponse())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user