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 - Araceli #60

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

Scissors - Araceli #60

wants to merge 11 commits into from

Conversation

aracelim1234
Copy link

No description provided.


if "name" not in request_body.keys() or "postal_code" not in request_body.keys() or "phone" not in request_body.keys():

return jsonify({"Error": "Enter info for all fields"}), 400
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines +18 to +19
if customers is None:
return 404
Copy link
Contributor

Choose a reason for hiding this comment

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

If there are no customers, query.all() will return an empty list, unlike query.get() which does return None. This check will always fail, if you want to return an error message in the case of no customers, the conditional needs to check for an empty list or falsey.

"id": self.id,
"title": self.title,
"release_date": self.release_date,
"total_inventory": self.total_inventory
Copy link
Contributor

Choose a reason for hiding this comment

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

Small bug here, "available_inventory" should be part of the json output for a video.

return jsonify({"id": customer.id}), 200

else:
return jsonify({"Error": f"Customer {customer_id} does not exist"}), 404
Copy link
Contributor

Choose a reason for hiding this comment

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

Line 49 and this line are doing the same work, but the error messages are different. Consider pulling this out into a helper function to make it easier to create consistent error messages. 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 +105 to +108
results = db.session.query(Customer, Video, Rental)\
.join(Customer, Customer.id==Rental.customer_id)\
.join(Video, Video.id==Rental.video_id)\
.filter(Customer.id==id).all()
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

video = Video.query.get(rental.video_id)

# if customer and video exist
if customer:
Copy link
Contributor

Choose a reason for hiding this comment

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

This only checks to see if the customer exists. If the video does not exist, line 41 will raise an exception.

video = Video.query.get(rental.video_id)

# if customer exists and is valid
if customer and customer.videos_checked_out >= 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking for customer.videos_checked_out >= 0 will allow customer.videos_checked_out to be set to -1.


# add it to database and commit
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.

How are you recording that the rental has ended? Consider this sequence (customer has 0 videos, video1 has inventory 1, video 2 has inventory 1:

  1. A customer checks out 2 videos (customer.videos_checked_out = 2, video1.total_inventory = 0, video2.total_inventory = 0)
  2. Check in with customer & video1 (customer.videos_checked_out = 1, video1.total_inventory = 1)
  3. Check in with customer & video1: This should return 400 as this customer does not have this video checked out anymore. However, it does not - customer.videos_checked_out will be set to 0 and video1.total_inventory will be set to 2, and the API will return a status of 200. This will set up a situation in the DB where the total inventory has gone up, and the customer has 0 videos checked out, both of which are incorrect.

customer.videos_checked_out += 1

# decrease videos.total_inventory by 1
if video.total_inventory > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

The column total_inventory not change when doing rentals, as this is how many copies the video store owns. There are two ways to check to see if a rental is possible - either use the available_inventory column from models/video.py line 11, or calculate it based on how many rentals have this video id.

__tablename__ = "customer"
id = db.Column(db.Integer, primary_key=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).

@jbieniosek
Copy link
Contributor

Great work on this project! The code is very clean and readable. There are some bugs with rentals, but the rest of the functionality is solid. 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