mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Deal with Api::OrdersController and SearchOrders service
This commit is contained in:
@@ -15,9 +15,11 @@ module Api
|
||||
|
||||
orders = SearchOrders.new(params, current_api_user).orders
|
||||
|
||||
pagy, paged_orders = pagy(orders, items: params[:per_page] || default_per_page)
|
||||
|
||||
render json: {
|
||||
orders: serialized_orders(orders),
|
||||
pagination: pagination_data(orders)
|
||||
orders: serialized_orders(paged_orders),
|
||||
pagination: pagination_data(pagy)
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ class SearchOrders
|
||||
includes(:payments, :subscription, :shipments, :bill_address, :distributor, :order_cycle).
|
||||
ransack(params[:q])
|
||||
|
||||
return paginated_results if using_pagination?
|
||||
|
||||
@search.result(distinct: true)
|
||||
end
|
||||
|
||||
@@ -35,14 +33,4 @@ class SearchOrders
|
||||
shipping_method_id: params[:shipping_method_id]
|
||||
})
|
||||
end
|
||||
|
||||
def paginated_results
|
||||
@search.result(distinct: true)
|
||||
.page(params[:page])
|
||||
.per(params[:per_page])
|
||||
end
|
||||
|
||||
def using_pagination?
|
||||
params[:page]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user