forked from AdaGold/video-store-api
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrentals_controller.rb
More file actions
37 lines (30 loc) · 897 Bytes
/
rentals_controller.rb
File metadata and controls
37 lines (30 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class RentalsController < ApplicationController
def check_out
rental = Rental.new(rental_params)
rental.due_date = Date.today + 7
if rental.save
rental = Rental.update_movie_and_customer(rental)
render json: rental.as_json(except: [:updated_at], status: :ok)
else
render json: { errors: rental.errors.messages}, status: :bad_request
end
end
def check_in
rental = Rental.find_checked_out_movie(params[:movie_id], params[:customer_id])
if rental
rental.update(check_in_date: Date.today)
rental = Rental.update_movie_and_customer(rental)
render json: rental.as_json(except: [:updated_at], status: :ok)
else
render json: {
errors: {
rental: ["No rental found"]
}
}, status: :not_found
end
end
private
def rental_params
params.permit(:movie_id, :customer_id)
end
end