These custom endpoints are best served with a Rental
model. You will need to determine the columns for the Rental
table and establish the following relationships between the tables using SQLAlchemy.
Fig. ERD Diagram of the finished database.
Checks out a video to a customer, and updates the data in the database as such.
When successful, this request should:
- increase the customer's
videos_checked_out_count
by one - decrease the video's
available_inventory
by one - create a due date. The rental's due date is the seven days from the current date.
Request Body Param | Type | Details |
---|---|---|
customer_id |
integer | ID of the customer attempting to check out this video |
video_id |
integer | ID of the video to be checked out |
Typical success response:
Status: 200
{
"customer_id": 122581016,
"video_id": 235040983,
"due_date": "2020-06-31",
"videos_checked_out_count": 2,
"available_inventory": 5
}
- The API should return back detailed errors and a status
404: Not Found
if the customer does not exist - The API should return back detailed errors and a status
404: Not Found
if the video does not exist - The API should return back detailed errors and a status
400: Bad Request
if the video does not have any available inventory before check out
Checks in a video to a customer, and updates the data in the database as such.
When successful, this request should:
- decrease the customer's
videos_checked_out_count
by one - increase the video's
available_inventory
by one
Request Body Param | Type | Details |
---|---|---|
customer_id |
integer | ID of the customer attempting to check out this video |
video_id |
integer | ID of the video to be checked out |
Typical success response:
Status: 200
{
"customer_id": 122581016,
"video_id": 277419103,
"videos_checked_out_count": 1,
"available_inventory": 6
}
- The API should return back detailed errors and a status
404: Not Found
if the customer does not exist - The API should return back detailed errors and a status
404: Not Found
if the video does not exist - The API should return back detailed errors and a status
400: Bad Request
if the video and customer do not match a current rental
List the videos a customer currently has checked out
Arg | Type | Details |
---|---|---|
id |
integer | The id of the customer |
Typical success response is a list of videos with the due date:
Status: 200
[
{
"release_date": "Wed, 01 Jan 1958 00:00:00 GMT",
"title": "Vertigo",
"due_date": "Thu, 13 May 2021 19:27:47 GMT",
},
{
"release_date": "Wed, 01 Jan 1941 00:00:00 GMT",
"title": "Citizen Kane",
"due_date": "Thu, 13 May 2021 19:28:00 GMT",
}
]
- The API should return back detailed errors and a status
404: Not Found
if the customer does not exist - The API should return an empty list if the customer does not have any videos checked out.
List the customers who currently have the video checked out
Arg | Type | Details |
---|---|---|
id |
integer | The id of the video |
Typical success response is a list of customers with the due date:
Status: 200
[
{
"due_date": "Thu, 13 May 2021 21:36:38 GMT",
"name": "Edith Wong",
"phone": "(555) 555-5555",
"postal_code": "99999",
},
{
"due_date": "Thu, 13 May 2021 21:36:47 GMT",
"name": "Ricarda Mowery",
"phone": "(555) 555-5555",
"postal_code": "99999",
}
]
- The API should return back detailed errors and a status
404: Not Found
if the video does not exist - The API should return an empty list if the video is not checked out to any customers.