module Api class JurisprudencesController < BaseController include JurisprudenceSearch authorize_resource :jurisprudence, class: "Cdao::Jurisprudence", only: %i[index] def index search = jurisprudence_search(search_params) @jurisprudences = search.results respond_with @jurisprudences end def show respond_with @jurisprudence end def years authorize! :index, Cdao::Jurisprudence start_year = Cdao::Jurisprudence.order(year: :asc).first(10).map(&:year).compact.uniq.first || "1900" end_year = Cdao::Jurisprudence.order(year: :asc).last(10).map(&:year).compact.uniq.last || Time.zone.today.year @years = (start_year..end_year).entries.reverse respond_with @years end private def search_params params.permit(:reference_number, :title, :short_title, :year, :citation_finder, :q, :page, :per_page, exclude_ids: []) end end end