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
18 changes: 18 additions & 0 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ def show
)
end

def create
new_video = Video.new(external_id: video_params[:external_id], title: video_params[:title],overview: video_params[:overview], release_date: video_params[:release_date], image_url: video_params[:image_url], inventory: 7 )

if new_video.external_id != nil && !Video.find_by(external_id: new_video.external_id)
if new_video.save
render status: :created, json: {}
else
render status: :bad_request, json: { errors: video.errors.messages }
end
else
render status: :bad_request, json: { errors: "Video already in database" }
end
end

private

def require_video
Expand All @@ -29,4 +43,8 @@ def require_video
render status: :not_found, json: { errors: { title: ["No video with title #{params["title"]}"] } }
end
end

def video_params
return params.permit(:external_id, :title, :inventory, :overview, :release_date, :image_url)
end
end
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</head>

<body>
<h1>Hello World!</h1>
<%= yield %>
</body>
</html>
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 :videos, only: [:index, :show], param: :title
resources :videos, only: [:index, :create, :show], 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