Skip to content

Commit

Permalink
added methods to model controller
Browse files Browse the repository at this point in the history
  • Loading branch information
aruna79 committed May 8, 2018
1 parent ea1454d commit b101950
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
class MoviesController < ApplicationController
def index
movies = Movie.all
render json: movies.as_json(only:[:id,:title,:release_date])
end

def show
@movie = Movie.find_by(id: params[:id])

if @movie

render json: @movie.as_json(only:[:title,:overview,:release_date,:inventory,:methods =>[:available_inventory]]),status: :ok
else
render json: {ok: false,errors:"movie not found"}, status: :not_found
end
end

def create
movie = Movie.create(movies_params)
if movie.valid?
render json: {id: movie.id}, status: :ok
else
render json: {ok: false,errors:movie.errors}, status: :bad_request
end

end
end

0 comments on commit b101950

Please sign in to comment.