Skip to content

Commit

Permalink
add description filter to the submissions endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Nov 29, 2023
1 parent 708be2c commit 9684c2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
27 changes: 17 additions & 10 deletions helpers/request_params_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/controllers/test_ontology_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9684c2b

Please sign in to comment.