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

Scissors: Mai Truong #55

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Scissors: Mai Truong #55

wants to merge 6 commits into from

Conversation

truongmt89
Copy link

No description provided.

__tablename__ = "customer"
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String)
postal_code = db.Column(db.Integer)
Copy link
Contributor

Choose a reason for hiding this comment

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

This solution is fine but it causes the code to fail 2 smoke tests (there was inconsistency around the postal_code in the tests).

Comment on lines +40 to +41
if customer == None:
return jsonify({"details": "customer not found"}), 404
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is the same as lines 30 & 31 - consider pulling them out into a helper function. The Flask abort function might be useful in this case, it makes it possible to return a response directly from a helper function.

Comment on lines +44 to +50
errors = ""
information = ["name", "postal_code", "phone"]
for info in information:
if info not in request_body:
errors = errors + info
if errors != "":
return jsonify({"details": errors}), 400
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! This is a great candidate for a helper function, and could be used for error checking on video as well if the list of fields is passed as a variable to the function.

postal_code = db.Column(db.Integer)
phone_number = db.Column(db.String)
registered_at = db.Column(db.DateTime, nullable=True)
videos_checked_out_count = db.Column(db.Integer, default=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you pull videos_checked_out_count from the rental table rather than storing it directly in the customer table?

title = db.Column(db.String)
release_date = db.Column(db.DateTime, nullable=True)
total_inventory = db.Column(db.Integer)
available_inventory = db.Column(db.Integer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you pull available_inventory from the rental table rather than storing it directly in this table?

Comment on lines +192 to +205
customer_id = request_body.get("customer_id")
video_id = request_body.get("video_id")

if type(customer_id) != int or type(video_id) != int:
return jsonify({"details": "Invalid data"}), 400

customer = Customer.query.get(customer_id)
video = Video.query.get(video_id)

if customer is None and video is None:
return jsonify({"details": "id's do not exist"}), 404

if video.available_inventory < 1:
return jsonify({"details": "2Invalid data"}), 400
Copy link
Contributor

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 +239 to +244
for rental in customer.video:
if rental.video_id == video_id:
customer.videos_checked_out_count -= 1
video.available_inventory += 1
db.session.delete(rental)
db.session.commit()
Copy link
Contributor

Choose a reason for hiding this comment

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

This will work, but it is also possible to pull the rental from the database directly. This query Rental.query.filter_by(customer_id = customer_id, video_id=video_id).all() is a place to start.

@jbieniosek
Copy link
Contributor

Fantastic work on this project! All of the functionality is solid. The majority of my comments focus on ways you can DRY up your code. This project is green, you hit all of the learning goals.

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