Open
Conversation
…g order (wave 2).
spitsfire
reviewed
Jun 7, 2023
spitsfire
left a comment
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
👍 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"]) |
| return make_response(jsonify(goal_list), 200) | ||
|
|
||
|
|
||
| @goals_bp.route("/<goal_id>", methods=["GET"]) |
| def update_goal(goal_id): | ||
| goal = Goal.validate_goal(goal_id) | ||
| request_body = request.get_json() | ||
| goal.title = request_body["title"] |
There was a problem hiding this comment.
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"]) |
| return make_response(jsonify(task_list), 200) | ||
|
|
||
|
|
||
| @tasks_bp.route("/<task_id>", methods=["GET"]) |
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) |
There was a problem hiding this comment.
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"]) |
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) |
There was a problem hiding this comment.
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"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.