Skip to content

Commit

Permalink
Merge pull request #239 from fga-eps-mds/60-local-view
Browse files Browse the repository at this point in the history
#60 - View local backend
  • Loading branch information
min-ia committed Oct 20, 2018
2 parents f11013a + 042f082 commit 1b7969f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions indicaAi/app/controllers/locals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ def show_rating
local = Local.find(params[:id_local])
json_response(locals: local, rating: rating)
end

# GET /local/:id
def show_place
unique_local = Local.find(params[:local_id])
json_response(unique_local)
end
end
3 changes: 2 additions & 1 deletion indicaAi/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Get Requests
get '/locals', to: 'locals#index'
get '/locals/name/:name', to: 'locals#search_locals'
get '/users', to: 'user_identifiers#index'
get 'local/:local_id', to: 'locals#show_place'
get '/local/favorites/:local_id', to: 'locals#list_favorites'
get '/users', to: 'user_identifiers#index'
get '/user/favorites/:user_id', to: 'user_identifiers#list_favorites'

# Post Requests
Expand Down
13 changes: 12 additions & 1 deletion indicaAi/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20181013160532) do
ActiveRecord::Schema.define(version: 20181015191753) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -27,9 +27,11 @@
create_table "local_ratings", force: :cascade do |t|
t.integer "value"
t.bigint "local_id"
t.bigint "user_identifier_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["local_id"], name: "index_local_ratings_on_local_id"
t.index ["user_identifier_id"], name: "index_local_ratings_on_user_identifier_id"
end

create_table "locals", force: :cascade do |t|
Expand All @@ -45,5 +47,14 @@
t.datetime "updated_at", null: false
end

create_table "user_rates", force: :cascade do |t|
t.integer "rating"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_foreign_key "favorite_locals", "locals"
add_foreign_key "favorite_locals", "user_identifiers"
add_foreign_key "local_ratings", "locals"
add_foreign_key "local_ratings", "user_identifiers"
end
13 changes: 13 additions & 0 deletions indicaAi/spec/controllers/locals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,17 @@
should route(:get, '/locals/name/x').to(action: :search_locals, name: 'x')
end
end

context 'GET #show_place' do
let!(:local) { create(:local, name: 'Some name') }
it 'Should route local/local_id to the corresponding action' do
get :show_place, params: { 'local_id' => local.id }
expect(response).to be_success
end
end

it 'Should return status 404' do
get :show_place, params: { 'local_id' => '45' }
expect(response.status).to eq(404)
end
end
20 changes: 19 additions & 1 deletion indicaAi/spec/requests/locals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,28 @@
describe 'GET /locals/name/:name' do
# make HTTP get request before each example
let!(:local) { create(:local, name: 'plaza') }
before { get '/locals/name/plaza' }
before { get "/locals/name/#{local.name}" }
it 'return local by name' do
expect(json).not_to be_empty
expect(json[0][0]['name']).to eq('plaza')
end
end
end

RSpec.describe 'Local API 2', type: :request do
describe 'GET /local/:id' do
# make HTTP get request before each example
let!(:local) { create(:local, name: 'plaza') }
before { get "/local/#{local.id}" }
it 'Should have status 200' do
expect(response).to have_http_status(200)
end
end

describe 'GET /local/:id' do
before { get '/local/1' }
it 'Should have status 404 when id does not exist' do
expect(response).to have_http_status(404)
end
end
end

0 comments on commit 1b7969f

Please sign in to comment.