From e4f2f09ecde3b72fa0c09503557d75025e532d86 Mon Sep 17 00:00:00 2001 From: laneia Date: Thu, 27 Jun 2019 18:46:32 -0700 Subject: [PATCH 1/2] added movie create method for add movie to library --- app/controllers/movies_controller.rb | 26 +++++++++++++--- config/routes.rb | 5 ++-- package.json | 44 ++++++++++++++++------------ 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 362e2791..9f1fb5d5 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -11,14 +11,32 @@ def index render status: :ok, json: data end + def create + movie = Movie.new( + title: params[:title], + overview: params[:overview], + release_date: params[:release_date], + ) + + if !Movie.find_by(title: movie.title) + if movie.save! + render status: :ok, json: {} + else + render status: :bad_request, json: {errors: movie.errors.messages} + end + else + render status: :no_content, json: {message: "Movie already added."} + end + end + def show render( status: :ok, json: @movie.as_json( only: [:title, :overview, :release_date, :inventory], - methods: [:available_inventory] - ) - ) + methods: [:available_inventory], + ), + ) end private @@ -26,7 +44,7 @@ def show def require_movie @movie = Movie.find_by(title: params[:title]) unless @movie - render status: :not_found, json: { errors: { title: ["No movie with title #{params["title"]}"] } } + render status: :not_found, json: {errors: {title: ["No movie with title #{params["title"]}"]}} end end end diff --git a/config/routes.rb b/config/routes.rb index f4c99688..b72b7fe5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,12 +3,11 @@ resources :customers, only: [:index] - resources :movies, only: [:index, :show], param: :title + resources :movies, 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" get "/rentals/overdue", to: "rentals#overdue", as: "overdue" - root 'movies#index' - + root "movies#index" end diff --git a/package.json b/package.json index e5f1f022..f5bc0463 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,30 @@ { - "name": "video-store-api", - "version": "0.0.0", + "name": "video-store-consumer", + "version": "0.1.0", "private": true, - "scripts": { - "start": "nodemon ./bin/www", - "test": "clear; jasmine-node --verbose spec/" - }, "dependencies": { - "body-parser": "~1.13.2", - "cookie-parser": "~1.3.5", - "debug": "~2.6.9", - "express": "~4.13.1", - "jade": "~1.11.0", - "morgan": "~1.9.1", - "sequelize": "^5.1.0", - "serve-favicon": "~2.3.0" + "axios": "^0.19.0", + "react": "^16.8.6", + "react-dom": "^16.8.6", + "react-router-dom": "^5.0.1", + "react-scripts": "3.0.1" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test --env=jsdom", + "eject": "react-scripts eject" }, - "devDependencies": { - "jasmine-node": "^1.14.5", - "nodemon": "^1.9.2", - "request": "^2.72.0" + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] } -} +} \ No newline at end of file From 2b965cd6be758ad0b0dade12e64ba536c616f3b6 Mon Sep 17 00:00:00 2001 From: laneia Date: Fri, 28 Jun 2019 09:53:32 -0700 Subject: [PATCH 2/2] got images for adding new movies showing correctly --- app/controllers/movies_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 9f1fb5d5..49432954 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -16,6 +16,7 @@ def create title: params[:title], overview: params[:overview], release_date: params[:release_date], + image_url: params[:image_url], ) if !Movie.find_by(title: movie.title)