Update pagination in Api::ExchangeProductsController

This commit is contained in:
Matt-Yorkley
2021-06-28 21:08:20 +01:00
parent 6fe68322da
commit 3213c30a37

View File

@@ -27,7 +27,7 @@ module Api
render_variant_count && return if params[:action_name] == "variant_count"
render_paginated_products paginated_products
render_paginated_products
end
private
@@ -51,14 +51,6 @@ module Api
new(@order_cycle, spree_current_user)
end
def paginated_products
return products unless pagination_required?
products.
page(params[:page]).
per(params[:per_page] || DEFAULT_PER_PAGE)
end
def load_data_from_exchange
exchange = Exchange.find_by(id: exchange_params[:exchange_id])
@@ -80,16 +72,19 @@ module Api
end
end
def render_paginated_products(paginated_products)
def render_paginated_products
pagy, results = nil, products
pagy, results = pagy(results, items: params[:per_page] || DEFAULT_PER_PAGE) if pagination_required?
serialized_products = ActiveModel::ArraySerializer.new(
paginated_products,
results,
each_serializer: Api::Admin::ForOrderCycle::SuppliedProductSerializer,
order_cycle: @order_cycle
)
render json: {
products: serialized_products,
pagination: pagination_data(paginated_products)
pagination: pagination_data(pagy)
}
end