From 2b1de3b6d9af220678b44ba006a622fea275baae Mon Sep 17 00:00:00 2001 From: Jamila Date: Wed, 20 Jun 2018 12:30:36 -0700 Subject: [PATCH 1/3] working on adding to library --- Gemfile | 1 + Gemfile.lock | 4 +++- app/controllers/movies_controller.rb | 15 +++++++++++++++ config/application.rb | 10 ++++++---- config/routes.rb | 3 ++- lib/movie_wrapper.rb | 10 ++++++++++ 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 009415af..e54f60b1 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby +gem 'rack-cors', require: 'rack/cors' # Use jquery as the JavaScript library gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 9f7601a8..fcb76c2a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,8 +118,9 @@ GEM slop (~> 3.4) pry-rails (0.3.4) pry (>= 0.9.10) - puma (3.6.2) + puma (3.11.4) rack (2.0.1) + rack-cors (1.0.2) rack-test (0.6.3) rack (>= 1.0) rails (5.0.1) @@ -210,6 +211,7 @@ DEPENDENCIES minitest-spec-rails pry-rails puma (~> 3.0) + rack-cors rails (~> 5.0.1) sass-rails (~> 5.0) spring diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 362e2791..ff7b198f 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -21,8 +21,23 @@ def show ) end + def create + puts "We made it" + puts params.inspect + + puts movie_params + + @movie = Movie.new(movie_params) + + end + private + def movie_params + return params.require(:title, :overview, :release_date, :image_url ).permit(:external_id) + + end + def require_movie @movie = Movie.find_by(title: params[:title]) unless @movie diff --git a/config/application.rb b/config/application.rb index cc803322..0e371183 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,9 +15,11 @@ class Application < Rails::Application #this loads everything in the lib folder automatically config.eager_load_paths << Rails.root.join('lib') - config.action_dispatch.default_headers = { - 'Access-Control-Allow-Origin' => '*', - 'Access-Control-Request-Method' => %w{GET POST OPTIONS}.join(",") - } + config.middleware.insert_before 0, Rack::Cors do + allow do + origins '*' + resource '*', headers: :any, methods: [:get, :post, :options] + end + end end end diff --git a/config/routes.rb b/config/routes.rb index 54bf033e..61500c6d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,11 +3,12 @@ resources :customers, only: [:index] - resources :movies, only: [:index, :show], param: :title + resources :movies, only: [:index, :show,], param: :title post "/rentals/:title/check-out", to: "rentals#check_out", as: "check_out" post "/rentals/:title/return", to: "rentals#check_in", as: "check_in" get "/rentals/overdue", to: "rentals#overdue", as: "overdue" + post "/movies", to: "movies#create", as: "create" end diff --git a/lib/movie_wrapper.rb b/lib/movie_wrapper.rb index 7bd05c0e..c2aa3390 100644 --- a/lib/movie_wrapper.rb +++ b/lib/movie_wrapper.rb @@ -20,6 +20,16 @@ def self.search(query) end end + # def self.details(title) + # puts "here we are" + # url = BASE_URL + "search/movie?api_key=" + KEY + "&query=" + title + # response = HTTParty.get(url) + # puts response + # + # return response + # + # end + private def self.construct_movie(api_result) From 54c717a70a1c7e0ccb2395ab243db1bd8c9c884a Mon Sep 17 00:00:00 2001 From: Brandy Austin Date: Wed, 20 Jun 2018 14:45:57 -0700 Subject: [PATCH 2/3] can add item to rental library --- app/controllers/movies_controller.rb | 17 +++++++++-------- config/routes.rb | 3 +-- notes.md | 9 +++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 notes.md diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index ff7b198f..277e2df5 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -22,21 +22,22 @@ def show end def create - puts "We made it" - puts params.inspect + puts "we made it" + puts "params below" - puts movie_params + movie = Movie.new(title: params["title"], overview: params["overview"], release_date: params["release_date"], image_url: params["image_url"]) + movie.save - @movie = Movie.new(movie_params) + puts "movie" + puts movie.inspect end private - def movie_params - return params.require(:title, :overview, :release_date, :image_url ).permit(:external_id) - - end + # def movie_params + # return params.permit(title: params["title"], overview: params["overview"], release_date: params["release_date"], image_url: params["image_url"]) + # end def require_movie @movie = Movie.find_by(title: params[:title]) diff --git a/config/routes.rb b/config/routes.rb index 61500c6d..8aac8bc9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,6 @@ post "/rentals/:title/check-out", to: "rentals#check_out", as: "check_out" post "/rentals/:title/return", to: "rentals#check_in", as: "check_in" get "/rentals/overdue", to: "rentals#overdue", as: "overdue" - post "/movies", to: "movies#create", as: "create" - + post "/movies", to: "movies#create", as: "create" end diff --git a/notes.md b/notes.md new file mode 100644 index 00000000..0da3d17c --- /dev/null +++ b/notes.md @@ -0,0 +1,9 @@ +- only one change to the API...it needs to add movies to the rental library (which is in its local database, not the external API) when the user clicks the "add to library" button on the search results page + +- the search results page queries the external api after going through a route that is in our api wrapper...only some of the possible movies are currently in the rental library as the seeds file does not add everything + +- the seeds file creates the rental library with the help of the external api, the title is the only item that is used from the movies.json file, the inventory is not involved anywhere...it is meaningless...we can assume there is endless inventory + +- only functionality of the app is that you can search for a movie, view the rental library, select movie and customer which is info that's stored until a controlled form is submitted + +- the controlled form sends a post request to our api wrapper which records the checkout though there is no get request for this so the information can't be viewed anywhere From b40c5e2adaa523aa7e6a9677187d721bfddb3775 Mon Sep 17 00:00:00 2001 From: Brandy Austin Date: Fri, 22 Jun 2018 14:02:28 -0700 Subject: [PATCH 3/3] final touches --- app/controllers/movies_controller.rb | 8 +------- db/migrate/20180620223521_add_inlibary_flag.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20180620223521_add_inlibary_flag.rb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 277e2df5..296e0d94 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -22,15 +22,9 @@ def show end def create - puts "we made it" - puts "params below" - movie = Movie.new(title: params["title"], overview: params["overview"], release_date: params["release_date"], image_url: params["image_url"]) + movie.save - - puts "movie" - puts movie.inspect - end private diff --git a/db/migrate/20180620223521_add_inlibary_flag.rb b/db/migrate/20180620223521_add_inlibary_flag.rb new file mode 100644 index 00000000..25bdf61c --- /dev/null +++ b/db/migrate/20180620223521_add_inlibary_flag.rb @@ -0,0 +1,5 @@ +class AddInlibaryFlag < ActiveRecord::Migration[5.0] + def change + add_column :movies, :in_library, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index ffb28f7e..0c0e4102 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180618042754) do +ActiveRecord::Schema.define(version: 20180620223521) do create_table "customers", force: :cascade do |t| t.string "name" @@ -34,6 +34,7 @@ t.datetime "updated_at", null: false t.string "image_url" t.integer "external_id" + t.boolean "in_library" end create_table "rentals", force: :cascade do |t|