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

Maple: Faith & Kristina #38

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

Maple: Faith & Kristina #38

wants to merge 44 commits into from

Conversation

k0axaca
Copy link

@k0axaca k0axaca commented Nov 15, 2021

No description provided.

k0axaca and others added 30 commits November 9, 2021 11:25
Comment on lines +15 to +22
# backref is creating Customer.videos as well as Video.customers
# updated video and customer with cascade
# When the customer is deleted, all associated rentals are also deleted
# cascade allows us to "delete the ophans" associated with the customer id
# the videos that the customer has are accessed through the rental table
# the rental is the child of the customer
# orphan cascade is normally configured only on the "one" side of a one-to-many relationship, and not on the "many" side of a many-to-one or many-to-many relationship. To force this relationship to allow a particular "Video" object to be referred towards by only a single "Customer" object at a time via the Customer.videos relationship, which would allow delete-orphan cascade to take place in this direction, set the single_parent=True flag. (Background on this error at: http://sqlalche.me/e/13/bbf0)"
Copy link

Choose a reason for hiding this comment

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

Even though a bunch of comments is not necessarily a bad thing it could be moved to a ReadMe file to reference big blocks of comments for readability.

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String)
release_date = db.Column(db.DateTime) #should this be nullable?
Copy link

Choose a reason for hiding this comment

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

I don't think it should be nullable because every video has a release date

# When the video is deleted, all associated rentals are also deleted
# cascade allows us to "delete the ophans" associated with the video id
customers = db.relationship("Rental", backref='Video', cascade="all, delete-orphan", lazy="joined")
Copy link

Choose a reason for hiding this comment

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

the implementation of cascade and delete-orphan is great here

Comment on lines +19 to +21
available_inv = self.total_inventory - self.video_checked_out_count()
return available_inv
Copy link

Choose a reason for hiding this comment

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

You already have columns in your table for total inventory and available inventory. You do not need to create a function you can just add or subtract 1 inside of the route you need it would look like video.total_inventory += 1

Comment on lines +20 to +25
if 'title' not in request_body:
return make_response({"details": "Request body must include title."}, 400)
elif 'release_date' not in request_body:
return make_response({"details": "Request body must include release_date."}, 400)
elif 'total_inventory' not in request_body:
return make_response({"details": "Request body must include total_inventory."}, 400)
Copy link

Choose a reason for hiding this comment

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

you could create a function to handle these guard clauses dynamically and then use that function for customers and videos it could look something like:

def validate_parameters(request_body, parameters):
           for attribute in parameters:
                if attribute not in request_body:
                       jsonify({"details": f"Request body must include {attribute}."}, 400))

Comment on lines +35 to +38
return make_response({ "id": new_video.id,
"title": new_video.title,
"release_date": new_video.release_date,
"total_inventory": new_video.total_inventory}, 201)
Copy link

Choose a reason for hiding this comment

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

you can move this to a helper function like you did for customer dictionary

# begin endpoints/ functions for Customer Model
customers_bp = Blueprint("customers_bp", __name__, url_prefix="/customers")

def make_customer_dict(customer):
Copy link

Choose a reason for hiding this comment

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

Great helper function but it would be great practice to move this to your customer model.

@@ -0,0 +1,12 @@
def validate_request_body(request_body, list_of_attributes):
Copy link

Choose a reason for hiding this comment

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

I left a comment above about creating a function just like this!! Think about all of the other places you could've used this helper function 👀

@tgoslee
Copy link

tgoslee commented Nov 24, 2021

Great Job Faith and Kristina! I liked your added comments and some of the helper functions you created. I saw that you made a function to handle the customer dictionary. I left some comments on creating a dictionary for video and rentals as well. You could move those into their perspective models to clean up the routes.py. I also saw that you created a function to validate a request body. I added a comment to use that in any other places in your code. Let me know if you have any questions.

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