mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-24 05:38:52 +00:00
apply pagination data concern to orders controller
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
module Api
|
||||
class OrdersController < Api::BaseController
|
||||
include PaginationData
|
||||
|
||||
def show
|
||||
authorize! :read, order
|
||||
render json: order, serializer: Api::OrderDetailedSerializer, current_order: order
|
||||
@@ -10,9 +12,11 @@ module Api
|
||||
|
||||
search_results = SearchOrders.new(params, current_api_user)
|
||||
|
||||
orders = search_results.orders
|
||||
|
||||
render json: {
|
||||
orders: serialized_orders(search_results.orders),
|
||||
pagination: search_results.pagination_data
|
||||
orders: orders,
|
||||
pagination: pagination_required? ? pagination_data(orders) : nil
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -8,17 +8,6 @@ class SearchOrders
|
||||
@orders = fetch_orders
|
||||
end
|
||||
|
||||
def pagination_data
|
||||
return unless using_pagination?
|
||||
|
||||
{
|
||||
results: @orders.total_count,
|
||||
pages: @orders.num_pages,
|
||||
page: params[:page].to_i,
|
||||
per_page: params[:per_page].to_i
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :params, :current_user
|
||||
@@ -50,6 +39,6 @@ class SearchOrders
|
||||
end
|
||||
|
||||
def using_pagination?
|
||||
params[:per_page]
|
||||
params[:page]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user