diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb index c9a2bb08..e0fcc9b1 100644 --- a/app/controllers/videos_controller.rb +++ b/app/controllers/videos_controller.rb @@ -21,6 +21,16 @@ def show ) end + def create + video = Video.new(video_params) + + if video.save + render json: video.as_json(only: [:id]), status: :created + else + render json: { errors: video.errors.messages }, status: :bad_request + end + end + private def require_video @@ -29,4 +39,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(:title, :overview, :release_date, :inventory, :available_inventory) + end end diff --git a/config/routes.rb b/config/routes.rb index 16fc2214..1111b4bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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"