diff --git a/.gitignore b/.gitignore index 4a494a75..58456ca4 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,8 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +# Elastic Beanstalk Files +.elasticbeanstalk/* +!.elasticbeanstalk/*.cfg.yml +!.elasticbeanstalk/*.global.yml diff --git a/Gemfile.lock b/Gemfile.lock index a0a07df1..94bb57b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -196,7 +196,7 @@ DEPENDENCIES will_paginate RUBY VERSION - ruby 2.5.1p57 + ruby 2.5.3p105 BUNDLED WITH 1.16.6 diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 362e2791..7ae0c873 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -21,8 +21,25 @@ def show ) end + def create + # binding.pry + movie = Movie.new(movie_params) + # movie.available_inventory = movie.inventory + # binding.pry + if movie.save + # render json: { id: movie.id }, status: :ok + render json: movie.as_json(only: [:title, :overview, :release_date, :image_url, :external_id]), status: :ok + else + render_error(:bad_request, movie.errors.messages) + end + end + private + def movie_params + params.permit(:title, :overview, :release_date, :image_url, :external_id) + end + def require_movie @movie = Movie.find_by(title: params[:title]) unless @movie diff --git a/app/controllers/rentals_controller.rb b/app/controllers/rentals_controller.rb index 67e77073..8e4b6833 100644 --- a/app/controllers/rentals_controller.rb +++ b/app/controllers/rentals_controller.rb @@ -4,7 +4,7 @@ class RentalsController < ApplicationController # TODO: make sure that wave 2 works all the way def check_out - rental = Rental.new(movie: @movie, customer: @customer, due_date: params[:due_date]) + rental = Rental.new(movie: @movie, customer: @customer, due_date: DateTime.now + 7) if rental.save render status: :ok, json: {} diff --git a/app/models/movie.rb b/app/models/movie.rb index 0016080b..34b08223 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -10,7 +10,7 @@ def image_url orig_value = read_attribute :image_url if !orig_value MovieWrapper::DEFAULT_IMG_URL - elsif external_id + elsif orig_value !~ %r{\Ahttps?://} MovieWrapper.construct_image_url(orig_value) else orig_value diff --git a/config/database.yml b/config/database.yml index 50748d61..3b9343e6 100644 --- a/config/database.yml +++ b/config/database.yml @@ -21,7 +21,8 @@ test: production: <<: *default - database: _production - username: - password: <%= ENV['_DATABASE_PASSWORD'] %> - + database: <%= ENV['RDS_DB_NAME'] %> + username: <%= ENV['RDS_USERNAME'] %> + password: <%= ENV['RDS_PASSWORD'] %> + host: <%= ENV['RDS_HOSTNAME'] %> + port: <%= ENV['RDS_PORT'] %> 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/schema.rb b/db/schema.rb index ffb28f7e..c7cb7c0a 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_06_18_042754) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" create_table "customers", force: :cascade do |t| - t.string "name" + 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" + 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" 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" + 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