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

Partners api #387

Open
wants to merge 7 commits into
base: master
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
42 changes: 42 additions & 0 deletions app/controllers/api/v1/partners_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Api
module V1
class PartnersController < ApiController
def index
render json: Partner.all
end

def create
partner = Partner.new(partner_params)
if partner.save
render json: status: 200
else
render json: status: 500
end
end

def update
partner = Partner.find(params[:id])
if partner.update(partner_params)
render json: status: 200
else
render json: status: 500
end
end

def destroy
partner = Partner.find(params[:id])
if partner.delete
render json: status: 200
else
render json: status: 500
end
end

private

def partner_params
params.require(:partner).permit()
end
end
end
end
2 changes: 2 additions & 0 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Partner < ActiveRecord::Base
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
resources :indicators, only: [:index, :show] do
end

resources :partners

get '/places', to: 'geographies#index', as: 'community_areas'
get '/place/:geo_slug', to: 'geographies#show', as: 'community_area'
get '/place/:geo_slug/resources(/:dataset_slug)', to: 'geographies#resources_json', as: 'community_area_resources'
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20180722014457_create_partners.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreatePartners < ActiveRecord::Migration
def change
create_table :partners do |t|
t.string :title
t.string :description
t.string :img_src_url
t.string :img_alt
t.string :image_url

t.timestamps null: false
end
end
end
12 changes: 11 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170915190057) do
ActiveRecord::Schema.define(version: 20180722014457) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -163,6 +163,16 @@

add_index "intervention_locations", ["geography_id"], name: "index_intervention_locations_on_geography_id", using: :btree

create_table "partners", force: :cascade do |t|
t.string "title"
t.string "description"
t.string "img_src_url"
t.string "img_alt"
t.string "image_url"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "provider_stats", force: :cascade do |t|
t.integer "provider_id"
t.string "stat_type"
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/api/v1/partners_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Api::V1::PartnersController, type: :controller do

end
5 changes: 5 additions & 0 deletions spec/models/partner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Partner, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end