Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api for cities #27

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
/config/master.key
# /config/database.yml
coverage/*
.env
10 changes: 10 additions & 0 deletions app/controllers/api/v1/cities_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Api
module V1
class CitiesController < ApplicationController
skip_before_action :validate_token, only: [:index]
def index
render json: City.all.order(:name).as_json
end
end
end
end
1 change: 0 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ development:

# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public

# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
get "/city_sport_levels", to: "levels#all_levels"
resources :levels
post "/level_sports", to: "level_sports#create"
resources :cities, only: [:index]
end
end
end
17 changes: 4 additions & 13 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,14 @@
create_table "users", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.string "contact_number"
t.boolean "is_admin"
t.integer "contact_number"
t.boolean "role"
t.string "email"
t.string "password"
t.bigint "city_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.index ["city_id"], name: "index_users_on_city_id"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

add_foreign_key "user_city_sports", "level_city_sports", column: "level_city_sports_id"
Expand Down
11 changes: 11 additions & 0 deletions spec/requests/get_cities_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "rails_helper"

describe "get all cities", type: :request do
before do
get "/api/v1/cities"
end

it "returns http success" do
expect(response).to have_http_status(:success)
end
end