-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: main
Are you sure you want to change the base?
Ocelots Anna Du #20
Conversation
rentals = db.relationship("Rental", back_populates="customer") | ||
|
||
|
||
def to_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.
looks good
check_out_status = db.Column(db.Boolean,default = True) | ||
available_inventory = db.Column(db.Integer) | ||
customer = db.relationship("Customer", back_populates="rentals") |
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.
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") |
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.
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)) |
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.
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() |
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.
This is another example where you might be able to make use of OOP-style SQLAlchemy interfaces, here :)
No description provided.