Get the list of the tables of a user

1.0
Fernando Blat 14 years ago
parent 8d1e75ea95
commit 5d4593264f

@ -1,6 +1,16 @@
class Api::Json::TablesController < ApplicationController
before_filter :login_required, :load_table
before_filter :login_required
before_filter :load_table, :except => [:index]
def index
@tables = Table.select(:id,:user_id,:name,:privacy).all
respond_to do |format|
format.json do
render :json => @tables.map{ |table| {:id => table.id, :name => table.name, :privacy => table_privacy_text(table)} }.to_json
end
end
end
def show
respond_to do |format|

@ -14,6 +14,7 @@ CartoDB::Application.routes.draw do
namespace :api do
namespace :json do
get 'tables' => 'tables#index', :format => :json
get 'table/:id' => 'tables#show', :format => :json
get 'table/:id/schema' => 'tables#schema', :format => :json
put 'table/:id/toggle_privacy' => 'tables#toggle_privacy', :format => :json

@ -110,4 +110,31 @@ feature "Tables JSON API" do
json_response.should == [["id", "integer"], ["name", "text"], ["location", "geometry"], ["description", "text"]]
end
scenario "Get a list of tables" do
user = create_user
authenticate_api user
get_json "/api/json/tables"
response.status.should == 200
JSON(response.body).should == []
table1 = create_table :user_id => user.id, :name => 'My table #1', :privacy => Table::PUBLIC
table2 = create_table :user_id => user.id, :name => 'My table #2', :privacy => Table::PRIVATE
get_json "/api/json/tables"
response.status.should == 200
response.body.should == [
{
"id" => table1.id,
"name" => "My table #1",
"privacy" => "PUBLIC"
},
{
"id" => table2.id,
"name" => "My table #2",
"privacy" => "PRIVATE"
}
].to_json
end
end

Loading…
Cancel
Save