From 4b742206bd86d2cea6c5e723109294da911951fe Mon Sep 17 00:00:00 2001 From: Abiaina Date: Mon, 18 Jun 2018 13:33:28 -0700 Subject: [PATCH 1/5] did the db setup, seed content visible --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9f7601a8..22779079 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,7 +118,7 @@ GEM slop (~> 3.4) pry-rails (0.3.4) pry (>= 0.9.10) - puma (3.6.2) + puma (3.11.4) rack (2.0.1) rack-test (0.6.3) rack (>= 1.0) From 546ae8a4596b41a761c53991a2745ff8d65e8596 Mon Sep 17 00:00:00 2001 From: Abiaina Date: Wed, 20 Jun 2018 17:03:51 -0700 Subject: [PATCH 2/5] added post add_movie functionality --- app/controllers/movies_controller.rb | 26 +++++++++++++++++++++++++- config/routes.rb | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 362e2791..66ca33d3 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -17,8 +17,32 @@ def show json: @movie.as_json( only: [:title, :overview, :release_date, :inventory], methods: [:available_inventory] - ) ) + ) + end + + def add_movie + #pass in new_movie from params...somehow..its an object + @new_movie = params[:movie] + + if Movie.find_by(external_id: @new_movie.external_id) + render( + status: :bad_request, json: { errors: "already in movie library" } + ) + else + @new_movie = MovieWrapper.construct_movie(@new_movie) + if @new_movie.save + render( + status: :ok, + json: @new_movie.as_json( + # also can return external_id and then have the front end do an api call again + only: [:title, :overview] + ) + ) + else + render status: :bad_request, json: { errors: rental.errors.messages } + end + end end private diff --git a/config/routes.rb b/config/routes.rb index 54bf033e..5044ded0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,8 @@ resources :movies, only: [:index, :show], param: :title + post "/movies", to: "movies#add_movie", as: "add_movie" + 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" From e7728728bcfea29e9bd636770b136313707c5c76 Mon Sep 17 00:00:00 2001 From: Abiaina Date: Wed, 20 Jun 2018 22:37:35 -0700 Subject: [PATCH 3/5] updated routes to reflect route in front end --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 5044ded0..6ca674b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ resources :movies, only: [:index, :show], param: :title - post "/movies", to: "movies#add_movie", as: "add_movie" + post "/movies/addLibrary", to: "movies#add_movie", as: "add_movie" post "/rentals/:title/check-out", to: "rentals#check_out", as: "check_out" post "/rentals/:title/return", to: "rentals#check_in", as: "check_in" From 69616aec55cb717291611235c5e5e863b4f6717e Mon Sep 17 00:00:00 2001 From: Abiaina Date: Wed, 20 Jun 2018 22:53:07 -0700 Subject: [PATCH 4/5] changed the route again --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 6ca674b6..6e7d596c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ resources :movies, only: [:index, :show], param: :title - post "/movies/addLibrary", to: "movies#add_movie", as: "add_movie" + post "/addLibrary", to: "movies#add_movie", as: "add_movie" post "/rentals/:title/check-out", to: "rentals#check_out", as: "check_out" post "/rentals/:title/return", to: "rentals#check_in", as: "check_in" From f20c82b544ae4a4be48e5d61a1d4600d769dd1bf Mon Sep 17 00:00:00 2001 From: Abiaina Date: Wed, 20 Jun 2018 23:35:18 -0700 Subject: [PATCH 5/5] can make posts and add to library via postman --- app/controllers/movies_controller.rb | 10 +++++++--- config/routes.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 66ca33d3..1b3c2dc1 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -23,14 +23,18 @@ def show def add_movie #pass in new_movie from params...somehow..its an object - @new_movie = params[:movie] + @new_movie = Movie.new() + @new_movie.title = params[:title] + @new_movie.overview = params[:overview] + @new_movie.release_date = params[:release_date] + @new_movie.image_url = params[:image_url] + @new_movie.external_id = params[:external_id] - if Movie.find_by(external_id: @new_movie.external_id) + if Movie.find_by(external_id: params[:external_id]) render( status: :bad_request, json: { errors: "already in movie library" } ) else - @new_movie = MovieWrapper.construct_movie(@new_movie) if @new_movie.save render( status: :ok, diff --git a/config/routes.rb b/config/routes.rb index 6e7d596c..dab8b77d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ resources :movies, only: [:index, :show], param: :title - post "/addLibrary", to: "movies#add_movie", as: "add_movie" + post "/add_movie", to: "movies#add_movie", as: "add_movie" post "/rentals/:title/check-out", to: "rentals#check_out", as: "check_out" post "/rentals/:title/return", to: "rentals#check_in", as: "check_in"