-
Notifications
You must be signed in to change notification settings - Fork 55
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
Maple :: Tiffany & Ro #47
base: master
Are you sure you want to change the base?
Conversation
|
||
|
||
def get_cust_dict(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great use of an instance method here
|
||
# Return response body | ||
def get_video_dict(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great use of an instance method
if "title" not in video_request_body: | ||
return jsonify({"details": "Request body must include title."}), 400 | ||
elif "release_date" not in video_request_body: | ||
return jsonify({"details": "Request body must include release_date."}), 400 | ||
elif "total_inventory" not in video_request_body: | ||
return jsonify({"details": "Request body must include total_inventory."}), 400 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could create a function to handle these guard clauses dynamically and then use that function for customers and videos it could look something like
def validate_parameters(request_body, parameters):
for attribute in parameters:
if attribute not in request_body:
abort(make_response({"details": f"Request body must include {attribute}."}, 400))
|
||
#OPTIONAL ENHANCEMENT (Query Params) | ||
# --------------------------------- | ||
sort_query = request.args.get("sort") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of sorting by id or by title
if not video_id.isnumeric(): | ||
return jsonify(None), 400 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another suggestion is to do a try/except to handle if the video id is not an integer
if not video_id.isnumeric(): | |
return jsonify(None), 400 | |
try: | |
video_id = int(video_id) | |
except ValueError: | |
return f"Invalid video id '{video_id}'",400 |
|
||
video_delete_response = video.get_video_dict() | ||
|
||
print("********", video_delete_response), 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove print after troubleshooting and pushing your final code
|
||
videos_checked_out = Rental.query.filter(Rental.video_id == rentals_request_body["video_id"], Rental.checked_out == True).count() | ||
|
||
avail_inventory = video.total_inventory - videos_checked_out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could add videos_checkout_count to your model then subtract from the count by doingrental.videos_checkout_count +=1
and add total inventory would be video.total_inventory -=1
Great job Tiffany and Ro! Your code was clean and readable. I like that you added helper functions for the responses. I added a few suggestions on refactoring your guard clauses to be a function and a few minor things. Let me know if you have questions. |
No description provided.