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

Alf & Reid - Spruce #56

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

Alf & Reid - Spruce #56

wants to merge 48 commits into from

Conversation

reidhowdy
Copy link

No description provided.

asliathman and others added 30 commits November 8, 2021 12:31
…y local computer, to overcome bug in test_update_customer
…ctionary rather than a nested dicitonary, now passing final wave 1 customer test
… guard clause rather than a try except to determine whether customer_id is a valid type
reidhowdy and others added 18 commits November 12, 2021 09:28
…items (a pagination attribute) to the for loop
…te resolves the error message we were getting earlier
…t that we can eventually use in our docstrings
…ate a specific response when ithere is missing data in the request body
Copy link

@audreyandoy audreyandoy 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 Alf and Reid! Y'all met all the learning goals for this project and passed all the tests.

I provided feedback on how y'all can refactor by omitting redundant logic and list comprehension.

Project grade: Green 🟢 !

Comment on lines +12 to +23
if "postal_code" not in request_body.keys():
response = {
"details": "Request body must include postal_code."
}
elif "name" not in request_body.keys():
response = {
"details": "Request body must include name."
}
elif "phone" not in request_body.keys():
response = {
"details": "Request body must include phone."
}

Choose a reason for hiding this comment

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

keys are the default iterator for dictionaries so we can actually omit the keys() method and this conditional will work the same way.

Suggested change
if "postal_code" not in request_body.keys():
response = {
"details": "Request body must include postal_code."
}
elif "name" not in request_body.keys():
response = {
"details": "Request body must include name."
}
elif "phone" not in request_body.keys():
response = {
"details": "Request body must include phone."
}
if "postal_code" not in request_body:
response = {
"details": "Request body must include postal_code."
}
elif "name" not in request_body:
response = {
"details": "Request body must include name."
}
elif "phone" not in request_body:
response = {
"details": "Request body must include phone."
}

Comment on lines +34 to +46
if customer_query == "name":
customers = Customer.query.order_by(Customer.name.asc()).paginate(page=page, per_page=num_per_page, error_out=False)
#when error out is false, page and per_page default to 1 and 20 respectively
#so we can paginate, and if no p and n parameters are passed in that's no problem because the defaults are passed in
else:
customers = Customer.query.order_by(Customer.customer_id.asc()).paginate(page=page, per_page=num_per_page, error_out=False)

response = [customer.to_dict() for customer in customers.items]
#because no matter what 'customers' is paginated (either with the parameters passed in or the default parameters)
#when we loop we can use pagination objects .items attribute to loop over the individual items themselves
#we use .items with no () because 'items' is an attribute of the pagination CLASS, not a method or a function

return jsonify(response), 200

Choose a reason for hiding this comment

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

Great use of pagination!

customers_bp = Blueprint("customers", __name__, url_prefix="/customers")

#HELPER FUNCTION
def find_specific_key_error(request_body):

Choose a reason for hiding this comment

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

Great helper function!

return jsonify(response), 400


@customers_bp.route("/<customer_id>", methods=["DELETE"])

Choose a reason for hiding this comment

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

👍

return jsonify(response), 200


@customers_bp.route("/<customer_id>/rentals", methods=["GET"])

Choose a reason for hiding this comment

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

👍

Comment on lines +32 to +43
if "title" not in request_body.keys():
response = {
"details" : "Request body must include title."
}
elif "release_date" not in request_body.keys():
response = {
"details" : "Request body must include release_date."
}
elif "total_inventory" not in request_body.keys():
response = {
"details" : "Request body must include total_inventory."
}

Choose a reason for hiding this comment

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

keys are the default iterator for dictionaries so we can actually omit the keys() method and this conditional will work the same way.


return jsonify(response), 400

@videos_bp.route("/<video_id>", methods=["GET"])

Choose a reason for hiding this comment

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

👍

Comment on lines +65 to +77
if not video:
return jsonify({"message" : f"Video {video_id} was not found"}), 404

else:
db.session.delete(video)
db.session.commit()
return jsonify(
{
"id": video.video_id, #this worked but video_id didnt??
'details': (f'Video {video.video_id} successfully deleted')
}

), 200

Choose a reason for hiding this comment

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

The else clause isn't necessary here, especially if we're following the guard clause pattern. We can think of if statements as if and only if this expression is true then execute this code, otherwise move on to the rest of the function body.

Suggested change
if not video:
return jsonify({"message" : f"Video {video_id} was not found"}), 404
else:
db.session.delete(video)
db.session.commit()
return jsonify(
{
"id": video.video_id, #this worked but video_id didnt??
'details': (f'Video {video.video_id} successfully deleted')
}
), 200
if not video:
return jsonify({"message" : f"Video {video_id} was not found"}), 404
db.session.delete(video)
db.session.commit()
return jsonify(
{
"id": video.video_id, #this worked but video_id didnt??
'details': (f'Video {video.video_id} successfully deleted')
}
), 200

Comment on lines +90 to +97
else:

video.title = request_body["title"]
video.release_date = request_body["release_date"]
video.total_inventory = request_body["total_inventory"]

db.session.commit()

Choose a reason for hiding this comment

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

See comment about else clauses above.

except KeyError:
return jsonify(None), 400

@videos_bp.route("/<video_id>/rentals", methods=["GET"])

Choose a reason for hiding this comment

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

👍

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