From fc2f631b8bb10ebfb6a20badbc267379166a7328 Mon Sep 17 00:00:00 2001 From: Angel Aviel Domaoan Date: Fri, 4 Feb 2022 09:24:41 +0000 Subject: [PATCH] Add exclude_ids as search_params --- app/controllers/api/doctrines_controller.rb | 5 ++++- app/controllers/api/documents_controller.rb | 5 ++++- app/controllers/api/jurisprudences_controller.rb | 3 ++- app/controllers/concerns/jurisprudence_search.rb | 2 ++ app/controllers/subject_indexes_controller.rb | 4 +++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/doctrines_controller.rb b/app/controllers/api/doctrines_controller.rb index e79e0f8..7f53c92 100644 --- a/app/controllers/api/doctrines_controller.rb +++ b/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) 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 end @@ -39,7 +41,8 @@ module Api end 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 diff --git a/app/controllers/api/documents_controller.rb b/app/controllers/api/documents_controller.rb index ea5a377..162ba41 100644 --- a/app/controllers/api/documents_controller.rb +++ b/app/controllers/api/documents_controller.rb @@ -29,6 +29,8 @@ module Api 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 :year, :desc @@ -39,7 +41,8 @@ module Api end 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 diff --git a/app/controllers/api/jurisprudences_controller.rb b/app/controllers/api/jurisprudences_controller.rb index ff04a8e..370bd0a 100644 --- a/app/controllers/api/jurisprudences_controller.rb +++ b/app/controllers/api/jurisprudences_controller.rb @@ -27,7 +27,8 @@ module Api private 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 diff --git a/app/controllers/concerns/jurisprudence_search.rb b/app/controllers/concerns/jurisprudence_search.rb index 8619cb9..55393d4 100644 --- a/app/controllers/concerns/jurisprudence_search.rb +++ b/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? + without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present? + order_by :doc_date, :desc order_by :year, :desc diff --git a/app/controllers/subject_indexes_controller.rb b/app/controllers/subject_indexes_controller.rb index 8d1e47e..97bceec 100644 --- a/app/controllers/subject_indexes_controller.rb +++ b/app/controllers/subject_indexes_controller.rb @@ -77,6 +77,8 @@ class SubjectIndexesController < ApplicationController with :parent_id, nil end + without(:id).any_of(args[:exclude_ids]) if args[:exclude_ids].present? + order_by :name, :asc paginate page: args[:page] || 1, per_page: args[:per_page] || 20 @@ -88,6 +90,6 @@ class SubjectIndexesController < ApplicationController end def search_params - params.permit(:name, :parent_id, :state, doctrine_ids: []) + params.permit(:name, :parent_id, :state, doctrine_ids: [], exclude_ids: []) end end