Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
19 changes: 19 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/movie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ test:

production:
<<: *default
database: <APPLICATION_NAME>_production
username: <APPLICATION_NAME>
password: <%= ENV['<APPLICATION_NAME>_DATABASE_PASSWORD'] %>

database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down