hybrid pagination
This commit is contained in:
@@ -194,7 +194,7 @@ func (s *notificationService) GetNotifications(ctx context.Context, req *SearchF
|
||||
"offset": pagination.Offset,
|
||||
})
|
||||
|
||||
notifications, total, err := s.repository.GetByUserID(ctx, req.Recipient, req.Status, req.Seen, req.Priority, req.EventType, req.Type, pagination)
|
||||
page, err := s.repository.GetByUserID(ctx, req.Recipient, req.Status, req.Seen, req.Priority, req.EventType, req.Type, pagination)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get notifications", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
@@ -203,7 +203,7 @@ func (s *notificationService) GetNotifications(ctx context.Context, req *SearchF
|
||||
}
|
||||
|
||||
notificationsResponse := make([]*NotificationResponse, 0)
|
||||
for _, notification := range notifications {
|
||||
for _, notification := range page.Items {
|
||||
usr, _ := s.userService.GetUserByID(ctx, notification.UserID)
|
||||
cust, _ := s.customerService.GetByID(ctx, notification.UserID)
|
||||
|
||||
@@ -250,21 +250,9 @@ func (s *notificationService) GetNotifications(ctx context.Context, req *SearchF
|
||||
})
|
||||
}
|
||||
|
||||
// Calculate total pages
|
||||
totalPages := int(total) / pagination.Limit
|
||||
if int(total)%pagination.Limit > 0 {
|
||||
totalPages++
|
||||
}
|
||||
|
||||
return &NotificationListResponse{
|
||||
Notifications: notificationsResponse,
|
||||
Meta: &response.Meta{
|
||||
Total: int(total),
|
||||
Limit: pagination.Limit,
|
||||
Offset: pagination.Offset,
|
||||
Page: (pagination.Offset / pagination.Limit) + 1,
|
||||
Pages: totalPages,
|
||||
},
|
||||
Meta: pagination.ListMeta(page.TotalCount, page.NextCursor, page.HasMore, page.PageOffset),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user