3 changed files with 53 additions and 0 deletions
@ -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 |
||||||
|
|
||||||
@ -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 |
||||||
Loading…
Reference in new issue