From 9684c2b74045fc2d03d3313cd2c9465f5a4d26e1 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Wed, 29 Nov 2023 18:02:08 +0100 Subject: [PATCH] add description filter to the submissions endpoint --- helpers/request_params_helper.rb | 27 ++++++++++++------- .../test_ontology_submissions_controller.rb | 5 ++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/helpers/request_params_helper.rb b/helpers/request_params_helper.rb index f1b8268c..59adeba7 100644 --- a/helpers/request_params_helper.rb +++ b/helpers/request_params_helper.rb @@ -122,17 +122,24 @@ def add_inverse_filters(inverse_filters, query) end def add_acronym_name_filters(query) - if params[:acronym] - filter = Goo::Filter.new(extract_attr(:ontology_acronym)).regex(params[:acronym]) - if params[:name] - filter.or(Goo::Filter.new(extract_attr(:ontology_name)).regex(params[:name])) - end - query = query.filter(filter) - elsif params[:name] - filter = Goo::Filter.new(extract_attr(:ontology_name)).regex(params[:name]) - query = query.filter(filter) + filters = { + acronym: :ontology_acronym, + name: :ontology_name, + description: :description + }.map do |key, attr| + (params[key].nil? || params[key].empty?) ? nil : [extract_attr(attr), params[key]] + end.compact + + return query if filters.empty? + + key, val = filters.first + filter = Goo::Filter.new(key).regex(val) + + filters.drop(1).each do |k, v| + filter = filter.or(Goo::Filter.new(k).regex(v)) end - query + + query.filter(filter) end def add_order_by_patterns(query) diff --git a/test/controllers/test_ontology_submissions_controller.rb b/test/controllers/test_ontology_submissions_controller.rb index 147b9c12..095d0339 100644 --- a/test/controllers/test_ontology_submissions_controller.rb +++ b/test/controllers/test_ontology_submissions_controller.rb @@ -314,6 +314,7 @@ def test_submissions_pagination_filter ontologies.first.save sub = ontologies.first.latest_submission(status: :any).bring_remaining sub.status = 'retired' + sub.description = "234" sub.creationDate = DateTime.yesterday.to_datetime sub.hasOntologyLanguage = LinkedData::Models::OntologyFormat.find('SKOS').first sub.save @@ -363,6 +364,10 @@ def test_submissions_pagination_filter submissions = MultiJson.load(last_response.body) refute_empty submissions["collection"] assert_equal ontologies.size - 1 , submissions["collection"].size + get "/submissions?page=1&pagesize=100&description=234&acronym=234&name=234" + assert last_response.ok? + submissions = MultiJson.load(last_response.body) + assert_equal 1 , submissions["collection"].size end def test_submissions_default_includes