Allow index meta param enrichment
This commit is contained in:
@@ -7,6 +7,7 @@ module Dunlop::Ember::ApiBaseController
|
|||||||
before_action :set_current_user
|
before_action :set_current_user
|
||||||
before_action :find_record, only: %i[show update destroy]
|
before_action :find_record, only: %i[show update destroy]
|
||||||
respond_to :json, :csv
|
respond_to :json, :csv
|
||||||
|
|
||||||
rescue_from CanCan::AccessDenied do
|
rescue_from CanCan::AccessDenied do
|
||||||
render json: {errors: [{status: 403, detail: 'unauthorized'}]}, status: 403
|
render json: {errors: [{status: 403, detail: 'unauthorized'}]}, status: 403
|
||||||
end
|
end
|
||||||
@@ -23,9 +24,9 @@ module Dunlop::Ember::ApiBaseController
|
|||||||
result = result.uniq if params[:uniq].present?
|
result = result.uniq if params[:uniq].present?
|
||||||
if index_pagination?
|
if index_pagination?
|
||||||
paginated = result.page(params[:page]).per(params[:per_page])
|
paginated = result.page(params[:page]).per(params[:per_page])
|
||||||
render json: paginated, meta: {total_pages: paginated.total_pages, total_count: paginated.total_count}
|
render json: paginated, meta: index_meta_params.merge(total_pages: paginated.total_pages, total_count: paginated.total_count)
|
||||||
else
|
else
|
||||||
render json: result
|
render json: result, meta: index_meta_params
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -167,6 +168,12 @@ module Dunlop::Ember::ApiBaseController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This method can be overloaded by the including controller to enrich the meta information of the collection
|
||||||
|
# with other meta-data
|
||||||
|
def index_meta_params
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
# /(_eq|_eq_any|_eq_all|_not_eq|_not_eq_any|_not_eq_all|_matches|_matches_any|_matches_all|
|
# /(_eq|_eq_any|_eq_all|_not_eq|_not_eq_any|_not_eq_all|_matches|_matches_any|_matches_all|
|
||||||
# _does_not_match|_does_not_match_any|_does_not_match_all|_lt|_lt_any|_lt_all|_lteq|_lteq_any|
|
# _does_not_match|_does_not_match_any|_does_not_match_all|_lt|_lt_any|_lt_all|_lteq|_lteq_any|
|
||||||
# _lteq_all|_gt|_gt_any|_gt_all|_gteq|_gteq_any|_gteq_all|_in|_in_any|_in_all|_not_in|_not_in_any|
|
# _lteq_all|_gt|_gt_any|_gt_all|_gteq|_gteq_any|_gteq_all|_in|_in_any|_in_all|_not_in|_not_in_any|
|
||||||
|
|||||||
Reference in New Issue
Block a user