Browse Source

Add exclude_ids as search_params

pull/17/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
fc2f631b8b
  1. 5
      app/controllers/api/doctrines_controller.rb
  2. 5
      app/controllers/api/documents_controller.rb
  3. 3
      app/controllers/api/jurisprudences_controller.rb
  4. 2
      app/controllers/concerns/jurisprudence_search.rb
  5. 4
      app/controllers/subject_indexes_controller.rb

5
app/controllers/api/doctrines_controller.rb

@ -32,6 +32,8 @@ module Api
with(:created_at).between(Date.parse(search_params[:created_at])..Time.zone.today.to_date) with(:created_at).between(Date.parse(search_params[:created_at])..Time.zone.today.to_date)
end end
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20 paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20
end end
@ -39,7 +41,8 @@ module Api
end end
def search_params def search_params
params.permit(:created_at, :q, :page, :per_page, subject_ids: [], user_ids: []) params.permit(:created_at, :q, :page, :per_page,
exclude_ids: [], subject_ids: [], user_ids: [])
end end
end end
end end

5
app/controllers/api/documents_controller.rb

@ -29,6 +29,8 @@ module Api
with(:year, search_params[:year].to_i) if search_params[:year].present? with(:year, search_params[:year].to_i) if search_params[:year].present?
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
order_by :doc_date, :desc order_by :doc_date, :desc
order_by :year, :desc order_by :year, :desc
@ -39,7 +41,8 @@ module Api
end end
def search_params def search_params
params.permit(:reference_number, :title, :short_title, :year, :q, :page, :per_page) params.permit(:reference_number, :title, :short_title, :year, :q, :page, :per_page,
exclude_ids: [])
end end
end end
end end

3
app/controllers/api/jurisprudences_controller.rb

@ -27,7 +27,8 @@ module Api
private private
def search_params def search_params
params.permit(:reference_number, :title, :short_title, :q, :page, :per_page) params.permit(:reference_number, :title, :short_title, :year, :q, :page, :per_page,
exclude_ids: [])
end end
end end
end end

2
app/controllers/concerns/jurisprudence_search.rb

@ -13,6 +13,8 @@ module JurisprudenceSearch
with(:subject_ids).any_of(search_params[:subject_ids].split(",").map(&:strip).map(&:to_i)) if search_params[:subject_ids].present? with(:subject_ids).any_of(search_params[:subject_ids].split(",").map(&:strip).map(&:to_i)) if search_params[:subject_ids].present?
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
order_by :doc_date, :desc order_by :doc_date, :desc
order_by :year, :desc order_by :year, :desc

4
app/controllers/subject_indexes_controller.rb

@ -77,6 +77,8 @@ class SubjectIndexesController < ApplicationController
with :parent_id, nil with :parent_id, nil
end end
without(:id).any_of(args[:exclude_ids]) if args[:exclude_ids].present?
order_by :name, :asc order_by :name, :asc
paginate page: args[:page] || 1, per_page: args[:per_page] || 20 paginate page: args[:page] || 1, per_page: args[:per_page] || 20
@ -88,6 +90,6 @@ class SubjectIndexesController < ApplicationController
end end
def search_params def search_params
params.permit(:name, :parent_id, :state, doctrine_ids: []) params.permit(:name, :parent_id, :state, doctrine_ids: [], exclude_ids: [])
end end
end end

Loading…
Cancel
Save