From 47e70b5e1299094c7dba34a5b597807c2670bc55 Mon Sep 17 00:00:00 2001 From: gatorjuice Date: Sat, 21 Jul 2018 20:41:37 -0500 Subject: [PATCH 1/7] created partners controller --- app/controllers/api/v1/partners_controller.rb | 2 ++ .../api/v1/partners_controller_spec.rb | 5 +++++ spec/helpers/api/v1/partners_helper_spec.rb | 15 +++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 app/controllers/api/v1/partners_controller.rb create mode 100644 spec/controllers/api/v1/partners_controller_spec.rb create mode 100644 spec/helpers/api/v1/partners_helper_spec.rb diff --git a/app/controllers/api/v1/partners_controller.rb b/app/controllers/api/v1/partners_controller.rb new file mode 100644 index 0000000..36a8883 --- /dev/null +++ b/app/controllers/api/v1/partners_controller.rb @@ -0,0 +1,2 @@ +class Api::V1::PartnersController < ApplicationController +end diff --git a/spec/controllers/api/v1/partners_controller_spec.rb b/spec/controllers/api/v1/partners_controller_spec.rb new file mode 100644 index 0000000..3ca17f3 --- /dev/null +++ b/spec/controllers/api/v1/partners_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::PartnersController, type: :controller do + +end diff --git a/spec/helpers/api/v1/partners_helper_spec.rb b/spec/helpers/api/v1/partners_helper_spec.rb new file mode 100644 index 0000000..3b58d8e --- /dev/null +++ b/spec/helpers/api/v1/partners_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::V1::PartnersHelper. For example: +# +# describe Api::V1::PartnersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::V1::PartnersHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From 2c97c5b3afd56020d08106c3d2f68a3a7d714738 Mon Sep 17 00:00:00 2001 From: gatorjuice Date: Sat, 21 Jul 2018 21:46:02 -0500 Subject: [PATCH 2/7] created a new route to retrieve the partners --- config/routes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index d05e1be..b1b8ac2 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' From 0ff666ee47a957193635a7ce707143b9bf63f2e8 Mon Sep 17 00:00:00 2001 From: gatorjuice Date: Sat, 21 Jul 2018 21:46:30 -0500 Subject: [PATCH 3/7] added a new controller and index method --- app/controllers/api/v1/partners_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/partners_controller.rb b/app/controllers/api/v1/partners_controller.rb index 36a8883..c166026 100644 --- a/app/controllers/api/v1/partners_controller.rb +++ b/app/controllers/api/v1/partners_controller.rb @@ -1,2 +1,9 @@ -class Api::V1::PartnersController < ApplicationController +module Api + module V1 + class PartnersController < ApiController + def index + render json: Partner.all + end + end + end end From 26da901d858b3d4bb8ac5775c436ace1d1a21af0 Mon Sep 17 00:00:00 2001 From: gatorjuice Date: Sat, 21 Jul 2018 21:47:21 -0500 Subject: [PATCH 4/7] created partner model --- app/models/partner.rb | 2 ++ db/migrate/20180722014457_create_partners.rb | 13 +++++++++++++ db/schema.rb | 20 +++++++++++--------- spec/models/partner_spec.rb | 5 +++++ 4 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 app/models/partner.rb create mode 100644 db/migrate/20180722014457_create_partners.rb create mode 100644 spec/models/partner_spec.rb diff --git a/app/models/partner.rb b/app/models/partner.rb new file mode 100644 index 0000000..6a58e97 --- /dev/null +++ b/app/models/partner.rb @@ -0,0 +1,2 @@ +class Partner < ActiveRecord::Base +end diff --git a/db/migrate/20180722014457_create_partners.rb b/db/migrate/20180722014457_create_partners.rb new file mode 100644 index 0000000..0cdf290 --- /dev/null +++ b/db/migrate/20180722014457_create_partners.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 053b3b2..9d87f7c 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -112,15 +112,11 @@ t.string "slug" t.string "order" t.string "description" - t.integer "upload_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "uploader_id" t.string "name" end - add_index "indicator_properties", ["uploader_id"], name: "index_indicator_properties_on_uploader_id", using: :btree - create_table "indicators", force: :cascade do |t| t.string "name" t.integer "sub_category_id" @@ -157,11 +153,18 @@ t.string "purple_binder_url", default: "" t.string "program_url", default: "" t.integer "community_area_id" - t.integer "geography_id" t.string "community_area_name" end - 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" @@ -198,6 +201,7 @@ t.string "url" t.string "report_url" t.string "report_name" + t.text "geometry" t.text "areas" t.string "area_type" t.text "area_alt" @@ -314,9 +318,7 @@ add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_foreign_key "hc_indicators", "uploaders" - add_foreign_key "indicator_properties", "uploaders" add_foreign_key "indicators", "sub_categories" - add_foreign_key "intervention_locations", "geographies" add_foreign_key "resources", "category_groups" add_foreign_key "resources", "demo_groups" add_foreign_key "resources", "geo_groups" diff --git a/spec/models/partner_spec.rb b/spec/models/partner_spec.rb new file mode 100644 index 0000000..06cff9d --- /dev/null +++ b/spec/models/partner_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Partner, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From d350d52b1a182adb884c26ce94dbeba28a77888f Mon Sep 17 00:00:00 2001 From: gatorjuice Date: Sat, 21 Jul 2018 22:00:16 -0500 Subject: [PATCH 5/7] fixed some auto mmodified schema entries --- db/schema.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 9d87f7c..05dade5 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -112,11 +112,15 @@ t.string "slug" t.string "order" t.string "description" + t.integer "upload_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "uploader_id" t.string "name" end + add_index "indicator_properties", ["uploader_id"], name: "index_indicator_properties_on_uploader_id", using: :btree + create_table "indicators", force: :cascade do |t| t.string "name" t.integer "sub_category_id" @@ -153,9 +157,12 @@ t.string "purple_binder_url", default: "" t.string "program_url", default: "" t.integer "community_area_id" + t.integer "geography_id" t.string "community_area_name" end + 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" @@ -201,7 +208,6 @@ t.string "url" t.string "report_url" t.string "report_name" - t.text "geometry" t.text "areas" t.string "area_type" t.text "area_alt" @@ -318,7 +324,9 @@ add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_foreign_key "hc_indicators", "uploaders" + add_foreign_key "indicator_properties", "uploaders" add_foreign_key "indicators", "sub_categories" + add_foreign_key "intervention_locations", "geographies" add_foreign_key "resources", "category_groups" add_foreign_key "resources", "demo_groups" add_foreign_key "resources", "geo_groups" From 49829ed49eb6676272de8d128d2c888030dfce06 Mon Sep 17 00:00:00 2001 From: gatorjuice Date: Sat, 28 Jul 2018 14:11:44 -0500 Subject: [PATCH 6/7] removed helper file --- spec/helpers/api/v1/partners_helper_spec.rb | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 spec/helpers/api/v1/partners_helper_spec.rb diff --git a/spec/helpers/api/v1/partners_helper_spec.rb b/spec/helpers/api/v1/partners_helper_spec.rb deleted file mode 100644 index 3b58d8e..0000000 --- a/spec/helpers/api/v1/partners_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the Api::V1::PartnersHelper. For example: -# -# describe Api::V1::PartnersHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe Api::V1::PartnersHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end From d56541bf05c32902026c31de3144edec44f29a4d Mon Sep 17 00:00:00 2001 From: gatorjuice Date: Sun, 29 Jul 2018 11:33:23 -0500 Subject: [PATCH 7/7] added rest of crud methods to controller --- app/controllers/api/v1/partners_controller.rb | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/controllers/api/v1/partners_controller.rb b/app/controllers/api/v1/partners_controller.rb index c166026..5a43505 100644 --- a/app/controllers/api/v1/partners_controller.rb +++ b/app/controllers/api/v1/partners_controller.rb @@ -4,6 +4,39 @@ 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