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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

.generators
# Ignore bundler config.
/.bundle

Expand Down
20 changes: 20 additions & 0 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,28 @@ def show
)
end

def create
if Video.find_by(external_id: params[:external_id])
render status: :bad_request, json: { errors: "this film is already in your library" }
return
end

video = Video.new(video_params)
if video.save
render status: :ok, json: {}
return
else
render status: :bad_request, json: { errors: video.errors.messages }
return
end
end

private

def video_params
params.require(:video).permit(:title, :overview, :release_date, :inventory, :image_url, :external_id)
end

def require_video
@video = Video.find_by(title: params[:title])
unless @video
Expand Down
4 changes: 3 additions & 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 :videos, only: [:index, :show], param: :title
resources :videos, 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 All @@ -12,3 +12,5 @@
root 'videos#index'

end

# show index create new edit update delete
Loading