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

Maple :: Tiffany & Ro #47

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

starseed2021
Copy link

No description provided.



def get_cust_dict(self):
Copy link

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):
Copy link

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

Comment on lines +21 to +26
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
Copy link

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")
Copy link

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

Comment on lines +67 to +68
if not video_id.isnumeric():
return jsonify(None), 400
Copy link

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

Suggested change
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
Copy link

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
Copy link

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

@tgoslee
Copy link

tgoslee commented Nov 24, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants