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 - Detroit and Monica #55

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

Conversation

mcatcruz
Copy link

No description provided.

mcatcruz and others added 30 commits November 8, 2021 17:10
phone = db.Column(db.String)
registered_at = db.Column(db.DateTime, nullable=True)
# videos_checked_out_count = db.Column(db.Integer, default=0, nullable=False)
Copy link

Choose a reason for hiding this comment

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

I would actually add this column here! You could use it to calculate inventory after someone checks in and checks out a video


def get_videos_checked_out_count(self):
from app.models.rental import Rental
Copy link

Choose a reason for hiding this comment

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

best practice to have imports at the top of your file. I would move it there

customers = db.relationship('Customer', secondary='rentals', backref='video')

def calculate_available_inventory(self):
Copy link

Choose a reason for hiding this comment

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

If you add videos_checkout_count to your customer model then you could do something like

customer.videos_checkout_count += 1
self.total_inventory -= 1

Comment on lines +28 to +33
if 'title' not in request_body.keys():
return make_response({"details": "Request body must include title." }, 400)
elif 'release_date' not in request_body.keys():
return make_response({"details":"Request body must include release_date."}, 400)
elif 'total_inventory' not in request_body.keys():
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:
                       abort(make_response({"details": f"Request body must include {attribute}."}, 400))

Comment on lines +51 to +56
# The try/except clause coerces the typed argument to be an int. If it is a non-numeric value, then a ValueError will be raised.
# Alternatively, can also use isnumeric(). This will return a boolean, so no need for try/except. An if/else clause will suffice.
try:
id = int(video_id)
except ValueError:
return jsonify({"details": "Invalid data"}), 400
Copy link

Choose a reason for hiding this comment

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

yass! 💃🏽

Comment on lines +80 to +83
return make_response({"id": video.id,
"title": video.title,
"release_date": video.release_date,
"total_inventory":video.total_inventory})
Copy link

Choose a reason for hiding this comment

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

this repeated code could be moved to your Video Model as an instance method or moved to a helper function. It could look something like after the instance method is created

Suggested change
return make_response({"id": video.id,
"title": video.title,
"release_date": video.release_date,
"total_inventory":video.total_inventory})
return make_response({
video.video_to_dict()
})

Comment on lines +128 to +129
# elif 'registered_at' not in request_body.keys():
# return make_response({"details": "Request body must include registered_at."}, 400)
Copy link

Choose a reason for hiding this comment

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

remove unused code

Comment on lines +293 to +302
# new_rental = Rental(video_id=request_body["video_id"],
# customer_id=request_body["customer_id"])
# updated_videos_checked_out = Customer.query.filter_by(id=request_body['customer_id']).first().videos_checked_out_count +1
# Customer.query.filter_by(id=request_body['customer_id']).first().videos_checked_out_count



# return make_response({"customer_id": request_body["customer_id"] ,
# "video_id": request_body["video_id"]})

Copy link

Choose a reason for hiding this comment

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

remove unused code when pushing final code. If you want to keep this code, I would move it to a readME file.

@tgoslee
Copy link

tgoslee commented Nov 28, 2021

Great Job Monica and Detroit! Your code was readable and passes all tests. I added some comments on refactoring to use helper functions and/or instance methods to your models. Also, it's best practice to remove unused code and to put your import statements at the top of your file. 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