hybrid pagination
This commit is contained in:
@@ -177,23 +177,22 @@ func (s *categoryService) Delete(ctx context.Context, id string) error {
|
||||
// SearchCategories searches categories with filters
|
||||
func (s *categoryService) SearchCategories(ctx context.Context, form *SearchForm, pagination *response.Pagination) (*CategoryListResponse, error) {
|
||||
// Get categories using search
|
||||
categories, 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 categories", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return nil, errors.New("failed to search categories")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Convert to responses
|
||||
var categoryResponses []*CategoryResponse
|
||||
for _, category := range categories {
|
||||
for _, category := range page.Items {
|
||||
categoryResponses = append(categoryResponses, category.ToResponse())
|
||||
}
|
||||
|
||||
return &CategoryListResponse{
|
||||
Categories: categoryResponses,
|
||||
Meta: pagination.Response(total),
|
||||
Meta: pagination.ListMeta(page.TotalCount, page.NextCursor, page.HasMore, page.PageOffset),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user