Skip to content

Conversation

@d3897
Copy link

@d3897 d3897 commented May 12, 2023

No description provided.

@d3897 d3897 changed the title Kunzite - Dianan Salazar Kunzite - Diana Salazar May 12, 2023
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.

Great job, Diana! Your routes stayed pretty consistent!

Things to consider:

  • There's some places I've marked that would make for good helper functions, which will let your routes breathe!

goals_bp = Blueprint("goal", __name__, url_prefix="/goals")


@goals_bp.route("", methods=["POST"])

Choose a reason for hiding this comment

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

👍 I like this organization here! Good guard clause, organized, helper functions. Looks great!

return make_response(jsonify(new_goal.to_dict()), 201)


@goals_bp.route("", methods=["GET"])

Choose a reason for hiding this comment

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

👍

return make_response(jsonify(goal_list), 200)


@goals_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.

👍

def update_goal(goal_id):
goal = Goal.validate_goal(goal_id)
request_body = request.get_json()
goal.title = request_body["title"]

Choose a reason for hiding this comment

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

There might be only one attribute, but for any model we could turn this into an instance method for updating!

return make_response(jsonify(goal.to_dict()), 200)


@goals_bp.route("/<goal_id>", methods=["DELETE"])

Choose a reason for hiding this comment

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

👍

return make_response(jsonify(task_list), 200)


@tasks_bp.route("/<task_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 +48 to +50
task.title = request_body["title"]
task.description = request_body["description"]
task.completed_at = request_body.get("completed_at", None)

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 an instance method in the Task class.

return make_response(jsonify(task.to_dict()), 200)


@tasks_bp.route("/<task_id>", methods=["DELETE"])

Choose a reason for hiding this comment

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

👍

Comment on lines +71 to +93
slack_token = os.environ.get("SLACK_TOKEN")
if slack_token:
channel = "#task-notifications"
message = f'Someone just completed the task "{task.title}."'
url = "https://slack.com/api/chat.postMessage"
headers = {
"Authorization": f"Bearer {slack_token}",
"Content-Type": "application/json"
}
payload = {
"channel":channel,
"text": message
}
custom_headers = request.headers.get("Custom-Headers")
if custom_headers is not None:
headers.update(custom_headers)
try:
response = requests.post(url, json=payload)
response.raise_for_status()
except requests.exceptions.RequestException as e:
abort(make_response(jsonify({"message": "Fail to send Slack message"}), 500))

response = requests.post(url, json=payload, headers=headers)

Choose a reason for hiding this comment

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

Let's turn this into a separate helper function!

return make_response(jsonify(task.to_dict()), 200)


@tasks_bp.route("/<task_id>/mark_incomplete", methods=["PATCH"])

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.

2 participants