diff --git a/app/controllers/api/doctrines_controller.rb b/app/controllers/api/doctrines_controller.rb new file mode 100644 index 0000000..758d77d --- /dev/null +++ b/app/controllers/api/doctrines_controller.rb @@ -0,0 +1,36 @@ + +module Api + class DoctrinesController < BaseController + authorize_resource :doctrine, class: "Doctrine", only: %i[index] + + def index + search = doctrine_search(search_params) + + @doctrines = search.results + + respond_with @doctrines + end + + private + + def doctrine_search(search_params) + search = Sunspot.search(Doctrine) do + + with(:subject_ids).any_of(search_params[:subject_ids]) if search_params[:subject_ids].present? + + with(:user_ids).any_of(search_params[:user_ids]) if search_params[:user_ids].present? + + if search_params[:created_at].present? + with(:created_at).between(Date.parse(search_params[:created_at]..Time.zone.today.to_date) + end + end + + search + end + + def search_params + params.permit(subject_ids: [], user_ids: [], :created_at) + end + end +end + \ No newline at end of file diff --git a/app/controllers/api/documents_controller.rb b/app/controllers/api/documents_controller.rb new file mode 100644 index 0000000..1c2e635 --- /dev/null +++ b/app/controllers/api/documents_controller.rb @@ -0,0 +1,15 @@ +module Api + class DocumentsController < BaseController + include JurisprudenceSearch + + authorize_resource :document, class: "Cdao::Document", only: %i[index] + + def index + search = jurisprudence_search(search_params) + + @jurisprudences = search.results + + respond_with @jurisprudences + end + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1b89883..9f02c85 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,8 @@ class ApplicationController < ActionController::Base before_action :authenticate_user! + before_action :set_paper_trail_whodunnit + rescue_from CanCan::AccessDenied do |exception| redirect_to root_url, notice: "You are not authorized to access this page." end