Make api element index paths resourceful

This commit is contained in:
Anton Khorev 2025-02-01 13:00:39 +03:00
parent 0a4442781c
commit 35d5276587
4 changed files with 19 additions and 18 deletions

View file

@ -39,7 +39,6 @@ OpenStreetMap::Application.routes.draw do
get "node/:id" => "nodes#show", :as => :api_node, :id => /\d+/
put "node/:id" => "nodes#update", :id => /\d+/
delete "node/:id" => "nodes#delete", :id => /\d+/
get "nodes" => "nodes#index"
put "way/create" => "ways#create"
get "way/:id/history" => "old_ways#history", :as => :api_way_history, :id => /\d+/
@ -50,7 +49,6 @@ OpenStreetMap::Application.routes.draw do
get "way/:id" => "ways#show", :as => :api_way, :id => /\d+/
put "way/:id" => "ways#update", :id => /\d+/
delete "way/:id" => "ways#delete", :id => /\d+/
get "ways" => "ways#index"
put "relation/create" => "relations#create"
get "relation/:id/relations" => "relations#relations_for_relation", :as => :relation_relations, :id => /\d+/
@ -61,10 +59,13 @@ OpenStreetMap::Application.routes.draw do
get "relation/:id" => "relations#show", :as => :api_relation, :id => /\d+/
put "relation/:id" => "relations#update", :id => /\d+/
delete "relation/:id" => "relations#delete", :id => /\d+/
get "relations" => "relations#index"
end
namespace :api, :path => "api/0.6" do
resources :nodes, :only => :index
resources :ways, :only => :index
resources :relations, :only => :index
resource :map, :only => :show
resources :tracepoints, :path => "trackpoints", :only => :index

View file

@ -434,15 +434,15 @@ module Api
node5 = create(:node, :deleted, :with_history, :version => 2)
# check error when no parameter provided
get nodes_path
get api_nodes_path
assert_response :bad_request
# check error when no parameter value provided
get nodes_path(:nodes => "")
get api_nodes_path(:nodes => "")
assert_response :bad_request
# test a working call
get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}")
get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}")
assert_response :success
assert_select "osm" do
assert_select "node", :count => 5
@ -454,7 +454,7 @@ module Api
end
# test a working call with json format
get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json")
get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json")
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
@ -467,7 +467,7 @@ module Api
assert_equal 1, (js["elements"].count { |a| a["id"] == node5.id && a["visible"] == false })
# check error when a non-existent node is included
get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0")
get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0")
assert_response :not_found
end

View file

@ -174,15 +174,15 @@ module Api
relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
# check error when no parameter provided
get relations_path
get api_relations_path
assert_response :bad_request
# check error when no parameter value provided
get relations_path(:relations => "")
get api_relations_path(:relations => "")
assert_response :bad_request
# test a working call
get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}")
get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}")
assert_response :success
assert_select "osm" do
assert_select "relation", :count => 4
@ -193,7 +193,7 @@ module Api
end
# test a working call with json format
get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json")
get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json")
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
@ -205,7 +205,7 @@ module Api
assert_equal 1, (js["elements"].count { |a| a["id"] == relation4.id && a["visible"].nil? })
# check error when a non-existent relation is included
get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0")
get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0")
assert_response :not_found
end

View file

@ -98,15 +98,15 @@ module Api
way4 = create(:way)
# check error when no parameter provided
get ways_path
get api_ways_path
assert_response :bad_request
# check error when no parameter value provided
get ways_path(:ways => "")
get api_ways_path(:ways => "")
assert_response :bad_request
# test a working call
get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}")
get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}")
assert_response :success
assert_select "osm" do
assert_select "way", :count => 4
@ -117,7 +117,7 @@ module Api
end
# test a working call with json format
get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json")
get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json")
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
@ -129,7 +129,7 @@ module Api
assert_equal 1, (js["elements"].count { |a| a["id"] == way4.id && a["visible"].nil? })
# check error when a non-existent way is included
get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0")
get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0")
assert_response :not_found
end