diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 362e2791..ce82c1c4 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -21,6 +21,32 @@ def show ) end + def create + movie = Movie.new( + title: params['title'], + overview: params['overview'], + release_date: params['release_date'], + pic_url: params['pic_url'], + external_id: params['external_id'] + ) + + + puts movie.image_url + + if movie.save + render status: :ok, json: { + id: movie.id, + title: movie.title, + overview: movie.overview, + release_date: movie.release_date, + pic_url: movie.pic_url, + external_id: movie.external_id + } + else + render status: :bad_request, json: { errors: rental.errors.messages } + end + end + private def require_movie diff --git a/app/models/movie.rb b/app/models/movie.rb index 0016080b..b670a663 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -7,7 +7,7 @@ def available_inventory end def image_url - orig_value = read_attribute :image_url + orig_value = read_attribute :pic_url if !orig_value MovieWrapper::DEFAULT_IMG_URL elsif external_id diff --git a/config/routes.rb b/config/routes.rb index f4c99688..76715f9a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ resources :customers, only: [:index] - resources :movies, only: [:index, :show], param: :title + resources :movies, only: [:index, :show, :create], 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" diff --git a/db/migrate/20181218230013_change_movie_image_ur_lto_pic_url.rb b/db/migrate/20181218230013_change_movie_image_ur_lto_pic_url.rb new file mode 100644 index 00000000..f00d9574 --- /dev/null +++ b/db/migrate/20181218230013_change_movie_image_ur_lto_pic_url.rb @@ -0,0 +1,5 @@ +class ChangeMovieImageUrLtoPicUrl < ActiveRecord::Migration[5.2] + def change + rename_column :movies, :image_url, :pic_url + end +end diff --git a/db/schema.rb b/db/schema.rb index ffb28f7e..6fe8a4ab 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,40 +10,43 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180618042754) do +ActiveRecord::Schema.define(version: 2018_12_18_230013) do - create_table "customers", force: :cascade do |t| - t.string "name" + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "customers", id: :serial, force: :cascade do |t| + t.string "name" t.datetime "registered_at" - t.string "address" - t.string "city" - t.string "state" - t.string "postal_code" - t.string "phone" - t.float "account_credit" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "address" + t.string "city" + t.string "state" + t.string "postal_code" + t.string "phone" + t.float "account_credit" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "movies", force: :cascade do |t| - t.string "title" - t.text "overview" - t.date "release_date" - t.integer "inventory" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "image_url" - t.integer "external_id" + create_table "movies", id: :serial, force: :cascade do |t| + t.string "title" + t.text "overview" + t.date "release_date" + t.integer "inventory" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "pic_url" + t.integer "external_id" end - create_table "rentals", force: :cascade do |t| - t.integer "customer_id" - t.integer "movie_id" - t.date "checkout_date" - t.date "due_date" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "returned" + create_table "rentals", id: :serial, force: :cascade do |t| + t.integer "customer_id" + t.integer "movie_id" + t.date "checkout_date" + t.date "due_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "returned" t.index ["customer_id"], name: "index_rentals_on_customer_id" t.index ["movie_id"], name: "index_rentals_on_movie_id" end diff --git a/lib/movie_wrapper.rb b/lib/movie_wrapper.rb index c51d05ee..b0b20e24 100644 --- a/lib/movie_wrapper.rb +++ b/lib/movie_wrapper.rb @@ -1,7 +1,7 @@ class MovieWrapper BASE_URL = "https://api.themoviedb.org/3/" - KEY = ENV["MOVIEDB_KEY"] + KEY = ENV["API_KEY"] BASE_IMG_URL = "https://image.tmdb.org/t/p/" DEFAULT_IMG_SIZE = "w185" @@ -30,7 +30,7 @@ def self.construct_movie(api_result) title: api_result["title"], overview: api_result["overview"], release_date: api_result["release_date"], - image_url: api_result["poster_path"], #(api_result["poster_path"] ? self.construct_image_url(api_result["poster_path"]) : nil), + pic_url: api_result["poster_path"], #(api_result["poster_path"] ? self.construct_image_url(api_result["poster_path"]) : nil), external_id: api_result["id"]) end