Skip to content

Commit

Permalink
Add note search by ids to api
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Aug 12, 2023
1 parent d8abf0d commit ea4f7c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/api/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ def search
# Get the initial set of notes
@notes = closed_condition(Note.all)

# Add ids filter
if params[:notes]
ids = params["notes"].split(",").collect(&:to_i)
raise OSM::APIBadUserInput, "No notes were given to search for" if ids.empty?
@notes = @notes.where(:id => ids)
end

# Add any user filter
if params[:display_name] || params[:user]
if params[:display_name]
Expand Down
24 changes: 24 additions & 0 deletions test/controllers/api/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,30 @@ def test_search_bad_params
assert_response :bad_request
end

def test_search_by_ids_success
note1 = create(:note, :created_at => "2020-01-01T00:00:00Z")
note2 = create(:note, :created_at => "2020-02-01T00:00:00Z")
note3 = create(:note, :created_at => "2020-03-01T00:00:00Z", :status => "hidden")
note4 = create(:note, :created_at => "2020-04-01T00:00:00Z")
note5 = create(:note, :created_at => "2020-05-01T00:00:00Z")

get search_api_notes_path(:notes => "#{note4.id},#{note2.id},#{note3.id},#{note1.id}", :format => "json")
assert_response :success
assert_equal "application/json", @response.media_type
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
assert_equal "FeatureCollection", js["type"]
assert_equal 3, js["features"].count
assert_equal note4.id, js["features"][0]["properties"]["id"]
assert_equal note2.id, js["features"][1]["properties"]["id"]
assert_equal note1.id, js["features"][2]["properties"]["id"]
end

def test_search_by_ids_bad_params
get search_api_notes_path, :params => { :notes => "" }
assert_response :bad_request
end

def test_feed_success
position = (1.1 * GeoRecord::SCALE).to_i
create(:note_with_comments, :latitude => position, :longitude => position)
Expand Down

0 comments on commit ea4f7c5

Please sign in to comment.