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..296e0d94 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -21,8 +21,18 @@ def show ) end + def create + movie = Movie.new(title: params["title"], overview: params["overview"], release_date: params["release_date"], image_url: params["image_url"]) + + movie.save + end + private + # 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]) 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..8aac8bc9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,11 +3,11 @@ 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/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| 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) 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