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

Branches - Brianna & Diana #7

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@ RUBY VERSION
ruby 2.5.5p157

BUNDLED WITH
1.17.3
2.0.2
22 changes: 16 additions & 6 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
class MoviesController < ApplicationController
before_action :require_movie, only: [:show]

def index
if params[:query]
data = MovieWrapper.search(params[:query])
else
data = Movie.all
end

render status: :ok, json: data
end

def show
render(
status: :ok,
json: @movie.as_json(
only: [:title, :overview, :release_date, :inventory],
methods: [:available_inventory]
)
)
)
end


def create
movie = MovieWrapper.construct_movie(params)

if movie.save
render status: :ok, json: {}
else
render status: :bad_request, json: {errors: movie.errors.messages}
end
end

private

def require_movie
@movie = Movie.find_by(title: params[:title])
unless @movie
Expand Down
12 changes: 6 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

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'

end