Simplify cases where pagination is conditional and pagination data may or may not be used

This commit is contained in:
Matt-Yorkley
2021-06-29 12:02:25 +01:00
parent e5afa3a26e
commit 41f9f07a80
5 changed files with 14 additions and 14 deletions

View File

@@ -73,8 +73,9 @@ module Api
end
def render_paginated_products
pagy, results = nil, products
pagy, results = pagy(results, items: params[:per_page] || DEFAULT_PER_PAGE) if pagination_required?
results = products
@pagy, results = pagy(results, items: params[:per_page] || DEFAULT_PER_PAGE) if pagination_required?
serialized_products = ActiveModel::ArraySerializer.new(
results,
@@ -84,7 +85,7 @@ module Api
render json: {
products: serialized_products,
pagination: pagination_data(pagy)
pagination: pagination_data
}
end

View File

@@ -15,11 +15,11 @@ module Api
orders = SearchOrders.new(params, current_api_user).orders
pagy, paged_orders = pagy(orders, items: params[:per_page] || default_per_page)
@pagy, paged_orders = pagy(orders, items: params[:per_page] || default_per_page)
render json: {
orders: serialized_orders(paged_orders),
pagination: pagination_data(pagy)
pagination: pagination_data
}
end

View File

@@ -132,7 +132,7 @@ module Api
end
def render_paged_products(products, product_serializer = ::Api::Admin::ProductSerializer)
pagy, products = pagy(products, items: params[:per_page] || DEFAULT_PER_PAGE)
@pagy, products = pagy(products, items: params[:per_page] || DEFAULT_PER_PAGE)
serialized_products = ActiveModel::ArraySerializer.new(
products,
@@ -141,7 +141,7 @@ module Api
render json: {
products: serialized_products,
pagination: pagination_data(pagy)
pagination: pagination_data
}
end