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

Ocelots Anna Du #20

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

Ocelots Anna Du #20

wants to merge 46 commits into from

Conversation

anjing0921
Copy link

No description provided.

rentals = db.relationship("Rental", back_populates="customer")


def to_dict(self):

Choose a reason for hiding this comment

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

looks good

check_out_status = db.Column(db.Boolean,default = True)
available_inventory = db.Column(db.Integer)
customer = db.relationship("Customer", back_populates="rentals")

Choose a reason for hiding this comment

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

Nice job setting up the rental relationships!

customer = validate_model(Customer, id)

video_query = Rental.query.filter_by(customer_id=customer.id).join(Video)
sort_query = request.args.get("sort")

Choose a reason for hiding this comment

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

Good use of joining tables!

I will add that thanks to the relationships you've set up, you could use the OOP-style SQLAlchemy to get some of this information. Such as customer.rentals :)


available_inventory = video.total_inventory - videos_checked_out
if available_inventory == 0:
abort(make_response({"message":f"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.

When I see repeated code, I think about added cost of maintenance. In this case, I would wonder if there's a way to extract repeated code. Maybe at least defining the error string as a variable, so you only have to make changes in one location. :)

customer = validate_model(Customer, request_body["customer_id"])
video = validate_model(Video, request_body["video_id"])

rental = db.session.query(Rental).filter_by(video_id=video.id, customer_id=customer.id).first()

Choose a reason for hiding this comment

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

This is another example where you might be able to make use of OOP-style SQLAlchemy interfaces, here :)

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