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

Cedar - Ana S. & Maria O. #37

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

Conversation

mobregong
Copy link

We are not passing all of the tests on wave 3 because we did not have time to implement all of the optional enhancements.

Anagabsoares and others added 30 commits November 8, 2021 10:57
Create video Model and /videos endpoints
er' of https://github.com/mob 
regong/retro-video-store
Co-authored-by: mobregong <[email protected]>
Copy link

@beccaelenzil-teach beccaelenzil-teach left a comment

Choose a reason for hiding this comment

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

Great work implementing this complex Flask project. You made great use of helper functions and stretched yourself to write tests for optional features. I've left some in-line comments focused on ways that you could use instance methods and class methods to DRY up your code and simplify the logic in the route functions. Please let me know if you have any questions. Nice work!

Comment on lines +11 to +12
videos_checked_out_count = db.Column(db.Integer, nullable=True)

Choose a reason for hiding this comment

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

Consider calculating available inventory based of the number of rentals a video currently has. For instance something like, for the video model: available_inventory = len([rental for rental in self.rentals if not rental.check_in_date])

This method requires that with have a rentals relationships column on our video: rentals = db.relationship('Rental', back_populates='customer', lazy=True)

This method of dynamically computing available_inventory rather than storing it in an instance variable makes it so there isn’t information stored in multiple places that could potentially conflict. Also something to note is that available_inventory is more of an attribute of a video rather than rental

due_date = db.Column(db.DateTime(timezone=True),nullable=True)
available_inventory = db.Column(db.Integer, nullable=False)
videos_checked_out_count = db.Column(db.Integer, nullable=True)

Choose a reason for hiding this comment

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

Similar to available_inventory, consider how you can dynamically calculate videos_checked_out_count for each customer by checking the length of the rentals attribute for a customer instance.

total_inventory = db.Column(db.Integer(), nullable=False)
# relationship
customers = db.relationship("Customer", secondary="rental", backref="video",lazy=True)

Choose a reason for hiding this comment

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

Nice work creating this secondary relationship column!

Comment on lines +15 to +17
response_list = []
for customer in customer_objects:
response_list.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 could be a nice place to use a list comprehension

Comment on lines +62 to +73
if "name" in request_body:
selected_customer.name = request_body["name"]
else:
abort(make_response({"error": "Invalid input"},400))
if "phone" in request_body:
selected_customer.phone = request_body["phone"]
else:
abort(make_response({"error": "Invalid input"},400))
if "postal_code" in request_body:
selected_customer.postal_code = request_body["postal_code"]
else:
abort(make_response({"error": "Invalid input"},400))

Choose a reason for hiding this comment

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

Note the similarities between this code and the code on lines 30-38. Consider how you could use a helper function to DFRY up your code.

response_body = rentals.to_dict()
return make_response(response_body, 200)

@rentals_bp.route("/overdue", methods=["GET"], strict_slashes=False)

Choose a reason for hiding this comment

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

Great work implementing this route!

app/routes/videos.py Outdated Show resolved Hide resolved
@video_bp.route("/<video_id>", methods=["DELETE"])
def delete_video(video_id):
video = get_video_by_id(video_id)
rentals = Rental.query.filter_by(video_id=video_id).all()

Choose a reason for hiding this comment

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

In a previous comment, I mentioned you could make a rentals relationship column for the video. This is a place it could be helpful.

Comment on lines +111 to +114
response_body.append({"due_date": rental.due_date,
"name": customer.name,
"phone": customer.phone,
"postal_code":customer.postal_code})

Choose a reason for hiding this comment

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

Consider using an instance method to create this dictionary.

@@ -0,0 +1,102 @@
from app.models.video import Video

Choose a reason for hiding this comment

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

Great work implementing these tests. You mentioned that they're not all passing yet. It is a great practice to write tests before you implement the feature. Bravo!

Anagabsoares and others added 2 commits November 18, 2021 17:54
Co-authored-by: beccaelenzil-teach <[email protected]>
Co-authored-by: beccaelenzil-teach <[email protected]>
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