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

C19 Kunzite Shay, Amber #110

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

C19 Kunzite Shay, Amber #110

wants to merge 29 commits into from

Conversation

Maashad
Copy link

@Maashad Maashad commented May 12, 2023

No description provided.

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

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

Nicely done, Amber! Perhaps during a break week, you can finish up Wave 6.

Things to consider:

  • Keep your responses as consistent and predictable as possible. If you start with jsonify, then use it all the way through (where possible).
  • Don't forget your status codes. Several of them are missing form your responses.
  • There are some places we could pull out code into helper functions in order to keep routes shorter.

Comment on lines +28 to +29
is_valid_goal = "title" in request_body
if not is_valid_goal:

Choose a reason for hiding this comment

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

This works, but it is more Pythonic to combine this:

    if "title" not in request_body:

request_body = request.get_json()
is_valid_goal = "title" in request_body
if not is_valid_goal:
abort(make_response({"details": "Invalid data"}, 400))

Choose a reason for hiding this comment

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

How could we make this error message more descriptive for the user to understand what is missing? Maybe we can say that title is missing or something!

goals = Goal.query.all()

goals_response = [goal.goal_to_dict() for goal in goals]
return jsonify(goals_response)

Choose a reason for hiding this comment

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

Oops, don't forget your status code! Technically, it will add one by default, but consider being explicit and always adding the status code.

goals_response = [goal.goal_to_dict() for goal in goals]
return jsonify(goals_response)

@goal_bp.route("/<goal_id>", methods=["GET"])

Choose a reason for hiding this comment

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

👍

response_body = {
"goal": goal.goal_to_dict()
}
return response_body

Choose a reason for hiding this comment

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

Careful here! While this does work, it is very different form the previous routes you've done. Try to keep them as consistent as possible. If you used jsonfy in a previous route response, do it for all of them (with the few exceptions that there may be)

"task": task.task_to_dict()
}
return response_body

Choose a reason for hiding this comment

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

Try to keep your responses as consistent as possible. Since you've used jsonify previously, continue using it throughout.

return jsonify(response_body), 200

"task": task.task_to_dict()
}
return jsonify(response_body)

Choose a reason for hiding this comment

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

Oops, you forgot your status code! It will implicitly return a status code, but we should add it ourselves to be in control of what is returned

Comment on lines +110 to +122
my_headers = {
"Authorization": f"Bearer {SLACK_BOT_TOKEN}"
}

data_payload = {
"channel": "task-notifications",
"text": f"Someone just completed the task {task.title}"
}

requests.post("https://slack.com/api/chat.postMessage",
headers=my_headers,
data=data_payload)

Choose a reason for hiding this comment

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

This would be a good candidate for a helper function



# ~~Below is the the code I would have used given Slack documentation for calling their API~~

Choose a reason for hiding this comment

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

Good job working with the documentation to find a solution! 👍

Comment on lines +153 to +154
return response_body

Choose a reason for hiding this comment

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

I believe abort has an implicit return, so we can combine these two lines together:

        abort(make_response({"message": f"{task_id} not found"}, 404))

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