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 b/Gemfile index 2d53ba9c..d963ecfa 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '2.5.1' +ruby '~> 2.5' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 362e2791..6d77f60f 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -21,8 +21,27 @@ def show ) end + def create + movie = Movie.new(movie_params) + + if movie.save + render( + status: :ok, + json: movie.as_json( + only: [:id, :title], + ) + ) + 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/models/movie.rb b/app/models/movie.rb index 0016080b..4ed867f4 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -2,6 +2,7 @@ class Movie < ApplicationRecord has_many :rentals has_many :customers, through: :rentals + def available_inventory self.inventory - Rental.where(movie: self, returned: false).length end @@ -10,7 +11,7 @@ def image_url orig_value = read_attribute :image_url if !orig_value MovieWrapper::DEFAULT_IMG_URL - elsif external_id + elsif orig_value.length == 62 || orig_value.length == 32 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"