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

Mary and Abinnet #15

Open
wants to merge 5 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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 29 additions & 1 deletion app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,36 @@ 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 = 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: params[:external_id])
render(
status: :bad_request, json: { errors: "already in movie library" }
)
else
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
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

resources :movies, only: [:index, :show], param: :title

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"
get "/rentals/overdue", to: "rentals#overdue", as: "overdue"
Expand Down