Merge pull request 'feat(products): sort by' (#26) from staging into main
Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
@@ -112,7 +112,9 @@ func (r *ProductRepositoryImpl) List(ctx context.Context, filters map[string]int
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := query.Limit(limit).Offset(offset).Find(&products).Error
|
// id is a tie-breaker so LIMIT/OFFSET paging stays stable when several products
|
||||||
|
// share the same created_at.
|
||||||
|
err := query.Order("created_at DESC, id DESC").Limit(limit).Offset(offset).Find(&products).Error
|
||||||
return products, total, err
|
return products, total, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,6 +267,8 @@ func (r *ProductRepositoryImpl) ListWithOutletPrice(ctx context.Context, filters
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := query.Limit(limit).Offset(offset).Find(&products).Error
|
// Columns are qualified because the outlet join brings a second created_at/id
|
||||||
|
// into scope. id is a tie-breaker for stable LIMIT/OFFSET paging.
|
||||||
|
err := query.Order("products.created_at DESC, products.id DESC").Limit(limit).Offset(offset).Find(&products).Error
|
||||||
return products, total, err
|
return products, total, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user