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

Ports - Laneia & Margaret #16

Open
wants to merge 2 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
27 changes: 23 additions & 4 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,41 @@ def index
render status: :ok, json: data
end

def create
movie = Movie.new(
title: params[:title],
overview: params[:overview],
release_date: params[:release_date],
image_url: params[:image_url],
)

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

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
5 changes: 2 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 25 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}