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

Sierra and Melinda - Pine #60

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

Conversation

heysierra
Copy link

No description provided.

Copy link

@jbieniosek jbieniosek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work on this project Sierra and Melinda! I like the way you are generating the available inventory dynamically by pulling data from the rental table. My recommendation would be to think about ways to create helper functions to break up some of the longer functions and pull out some of the chunks of similar code. The functionality on this project is very solid and you hit all of the learning goals. This project is green!


def rental_dict(self, id):
video = Video.query.get(id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The db.relationships is already doing this work for you. It looks like the relationships are set up correctly so self.video should be a Video model where the Video.id == self.video_id.

Comment on lines +23 to +26
customers_response = []

for customer in customers:
customers_response.append(customer.to_dict())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well and is very readable, but if you'd like to start incorporating list comprehensions into your code, a loop like this that builds a list is a great place to start:

Suggested change
customers_response = []
for customer in customers:
customers_response.append(customer.to_dict())
customers_response = [customer.to_dict() for customer in customers]

Comment on lines +76 to +81
if customer is None:
return make_response({"message": f"Customer {customer_id} was not found"}, 404)
elif "name" not in request_body or "postal_code" not in request_body or "phone" not in request_body:
return make_response({"details": "Invalid data"}, 400)
else:
response_body = request.get_json()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great error checking!

Comment on lines +126 to +130
@videos_bp.route("", methods=["GET"])
def get_all_videos():
videos = Video.query.all()
response_body = [video.to_dict() for video in videos]
return jsonify(response_body), 200

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't getting called. This is the same route as line 92 and I suspect what is happening here is that the first route is the one that is called and this one is ignored.

Comment on lines +140 to +141
if video is None:
return make_response({"message": f"Video {video_id} was not found"}, 404)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is the same for all methods, I recommend bumping this up out of the if/elif structure to right after line 136 to DRY the code slightly.

Comment on lines +198 to +199
if video.total_inventory - len(video.rentals) == 0:
abort(make_response({"message": "Could not perform checkout"}, 400))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small logical bug here. The list of rentals associated with a video will include all of the rentals where that have a foreign key video_id that matches the id of this video. The check-in logic sets the checked-out variable of the rental to False, but does not delete the rental. This list will then contain all of the current and past rentals. One way to fix this is to go through the list of rentals and count the ones that are active:

Suggested change
if video.total_inventory - len(video.rentals) == 0:
abort(make_response({"message": "Could not perform checkout"}, 400))
active_rentals = 0
for rental in video.rentals:
if rental.checked_out:
active_rentals += 1
if video.total_inventory - active_rentals == 0:
abort(make_response({"message": "Could not perform checkout"}, 400))

Comment on lines +244 to +246
num_currently_checked_out = Rental.query.filter_by(video_id=video.id, checked_out=True).count()
available_inventory = video.total_inventory - num_currently_checked_out
videos_customer_checked_out = Rental.query.filter_by(customer_id=customer.id, checked_out=True).count()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 The query on line 244 could also be used to fix the logical bug in the check out method.

Comment on lines +78 to +79
elif "name" not in request_body or "postal_code" not in request_body or "phone" not in request_body:
return make_response({"details": "Invalid data"}, 400)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is very similar to the validation in the POST route in the handle_customers() function. I recommend thinking about ways to pull these sections out into helper functions to DRY the code.

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.

3 participants