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

Panthers - Kallie and Billie resubmission #140

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

Conversation

lbbetts
Copy link

@lbbetts lbbetts commented Dec 1, 2022

No description provided.

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 Kallie and Billie! Your code was very clean due to helper functions and instance/class methods!

Y'all have earned a 🟢 green grade for this project.

In this PR, you'll find comments focused on compliments and suggestions for refactoring. With internship in a few months, I'd like you to submit PRs as if a manager is reviewing your code. So in this case, removing unneeded whitespace, unused code, and unused imports are all things that should be removed prior to submitting a PR to be reviewed. Let's practice that in future projects!

Keep up the great work! 🐈‍⬛ ✨

Comment on lines +9 to +20
def validate_goal(goal_id):
try:
goal_id = int(goal_id)
except:
abort(make_response({"message":f"Goal {goal_id} invalid"}, 400))

goal = Goal.query.get(goal_id)

if not goal:
abort(make_response({"message":f"Goal {goal_id} not found"}, 404))

return goal

Choose a reason for hiding this comment

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

👍 Great helper function!

Comment on lines +22 to +34
@goals_bp.route("", methods=["POST"])
def create_goal():
request_body = request.get_json()

if "title" not in request_body:
return make_response({"details": "Invalid data"}, 400)

new_goal = Goal(title = request_body["title"])

db.session.add(new_goal)
db.session.commit()

return make_response({"goal":new_goal.to_dict()}, 201)
Copy link

@audreyandoy audreyandoy Dec 7, 2022

Choose a reason for hiding this comment

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

👍 Great work using to_dict() here! Because we're returning a dictionary, we can take advantage of Flask's default behavior of turning dictionaries into JSON format as according to their documentation:

If you return a dict from a view, it will be converted to a JSON response.

https://flask.palletsprojects.com/en/1.1.x/quickstart/#apis-with-json

We can apply this same comment to the rest of this project.

Comment on lines +36 to +48
@goals_bp.route("", methods=["GET"])
def get_goals():
goal_query = Goal.query
goals = goal_query.all()

goals_response = []
for goal in goals:
goals_response.append({
"id": goal.goal_id,
"title": goal.title,
})

return make_response(jsonify(goals_response), 200)

Choose a reason for hiding this comment

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

👍 Nice work! We can use list comprehension to build goal_response and use to_dict like so:

goals_response = [goal.to_dict() for goal in goals]
return jsonify(goals_response), 200

Comment on lines +49 to +54
@goals_bp.route(GOAL_ID_PREFIX, methods=["GET"])
def get_one_goal(goal_id):
goal = validate_goal(goal_id)
goal = Goal.query.get(goal_id)

return {"goal": goal.to_dict()}

Choose a reason for hiding this comment

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

👍

Comment on lines +56 to +68
@goals_bp.route(GOAL_ID_PREFIX,methods=['PUT'])
def update_task(goal_id):
request_body = request.get_json()
if "title" not in request_body:
return make_response("Invalid Request, Goal Must Have Title", 400)

goal = validate_goal(goal_id)
goal = Goal.query.get(goal_id)

goal.title = request_body["title"]

db.session.commit()
return make_response({"goal":goal.to_dict()}, 200)

Choose a reason for hiding this comment

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

👍

Comment on lines +58 to +59
assert response.status_code == 404
assert response_body == {"message":f"Goal 1 not found"}

Choose a reason for hiding this comment

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

👍

Comment on lines +88 to +97
assert response.status_code == 200
assert "goal" in response_body
assert response_body == {
"goal": {
"id": 1,
"title": "My Updated New Goal"
}
}
goal = Goal.query.get(1)
assert goal.title == "My Updated New Goal"

Choose a reason for hiding this comment

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

👍

Comment on lines +103 to +110
response = client.put("/goals/1", json={
"title": "Updated Task Title"
})
response_body = response.get_json()

# Assert
# ---- Complete Assertions Here ----
# assertion 1 goes here
# assertion 2 goes here
# ---- Complete Assertions Here ----
assert response.status_code == 404
assert response_body == {"message":f"Goal 1 not found"}

Choose a reason for hiding this comment

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

👍

Comment on lines +133 to +140
response = client.delete("/goals/1")
response_body = response.get_json()

# Assert
# ---- Complete Assertions Here ----
# assertion 1 goes here
# assertion 2 goes here
# ---- Complete Assertions Here ----
assert response.status_code == 404
assert response_body == {"message":f"Goal 1 not found"}

assert Goal.query.all() == []

Choose a reason for hiding this comment

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

👍

# *****************************************************************
# **Complete test with assertion about response body***************
# *****************************************************************
assert response_body == {"message":f"Goal 1 not found"}

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