diff --git a/internal/repository/product_repository.go b/internal/repository/product_repository.go index 5fa64e5..09862ea 100644 --- a/internal/repository/product_repository.go +++ b/internal/repository/product_repository.go @@ -112,7 +112,9 @@ func (r *ProductRepositoryImpl) List(ctx context.Context, filters map[string]int 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 } @@ -265,6 +267,8 @@ func (r *ProductRepositoryImpl) ListWithOutletPrice(ctx context.Context, filters 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 }