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

Alice and Maha #9

Open
wants to merge 6 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Ignore Byebug command history file.
.byebug_history
.env
.idea

# Ignore master key for decrypting credentials and more.
/config/master.key
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,12 +21,32 @@ def show
)
end

def create
p params
video = Video.new(video_params)
if Video.find_by(external_id: params[:external_id])
render status: :bad_request, json: {errors: ['Video already exist'] }
else
if video.save
render status: :created, json: {}
else
render status: :bad_request, json: {errors: video.errors.messages}
end
end
end

private

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

def require_video
@video = Video.find_by(title: params[:title])
unless @video
render status: :not_found, json: { errors: { title: ["No video with title #{params["title"]}"] } }
end
end
end


1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

resources :videos, only: [:index, :show], param: :title

post "/videos", to: "videos#create", as: "add_videos"
post "/rentals/:title/check-out", to: "rentals#check_out", as: "check_out"
post "/rentals/:title/return", to: "rentals#check_in", as: "check_in"
get "/rentals/overdue", to: "rentals#overdue", as: "overdue"
Expand Down