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 (31 loc) · 869 Bytes
/
rentals_controller.rb
File metadata and controls
37 lines (31 loc) · 869 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
# TODO: To make this happen automatically
def checkout
@rental = Rental.new(rental_params)
@rental.check_date
if @rental.save
@rental.build_rental
render json: rental_params, status: :ok
else
#failure
render json: {errors: @rental.errors.messages }, status: :bad_request
end
end
def check_in
@rental = Rental.find_by(customer_id: params[:customer_id], movie_id: params[:movie_id])
if @rental.nil?
render json: {
"errors": {
"id": ["No rental with id #{params[:id]}"]
}
}, status: :not_found
else
@rental.build_return
render(json: @rental.as_json(only: [:customer_id, :movie_id]), status: :ok)
end
end
private
def rental_params
params.permit(:customer_id, :movie_id)
end
end