Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addy & lindsay - video store api #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
27 changes: 27 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ def show
)
end

def create
movie = Movie.new(
title: params['title'],
overview: params['overview'],
release_date: params['release_date'],
image_url: params['image_url'],
external_id: params['external_id']
)

if movie.save
render status: :ok, json: {
id: movie.id,
title: movie.title,
overview: movie.overview,
release_date: movie.release_date,
image_url: movie.image_url,
external_id: movie.external_id
}
else
render status: :bad_request, json: { errors: movie.errors.messages }
end
end





private

def require_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 @@ -7,10 +7,11 @@ def available_inventory
end

def image_url
pattern = /^((?!http).)*$/
orig_value = read_attribute :image_url
if !orig_value
MovieWrapper::DEFAULT_IMG_URL
elsif external_id
elsif external_id && pattern.match?(orig_value)
MovieWrapper.construct_image_url(orig_value)
else
orig_value
Expand Down
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
1 change: 1 addition & 0 deletions node_modules/.bin/loose-envify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading