Update paginated responses to include summary data
This commit is contained in:
@@ -3,11 +3,11 @@ class Api::V1::BaseController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def per_page
|
||||
(params[:per_page].presence || DEFAULT_PAGE_SIZE).to_i
|
||||
def pagination_limit
|
||||
(params[:limit].presence || DEFAULT_PAGE_SIZE).to_i
|
||||
end
|
||||
|
||||
def page
|
||||
(params[:page].presence || 1).to_i
|
||||
def pagination_offset
|
||||
(params[:offset].presence || 0).to_i
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,12 @@ module Api::V1::Parks
|
||||
before_action :set_park
|
||||
|
||||
def index
|
||||
render json: @park.alerts.limit(per_page).offset((page - 1) * per_page)
|
||||
render json: {
|
||||
total: @park.alerts.count,
|
||||
limit: pagination_limit,
|
||||
offset: pagination_offset,
|
||||
alerts: @park.alerts.limit(pagination_limit).offset(pagination_offset)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,12 @@ module Api::V1
|
||||
if params[:state].present?
|
||||
parks = parks.where("states like '%' || ? || '%'", params[:state])
|
||||
end
|
||||
render json: parks.limit(per_page).offset((page - 1) * per_page)
|
||||
render json: {
|
||||
total: parks.count,
|
||||
limit: pagination_limit,
|
||||
offset: pagination_offset,
|
||||
parks: parks.limit(pagination_limit).offset(pagination_offset)
|
||||
}
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
Reference in New Issue
Block a user