-
Notifications
You must be signed in to change notification settings - Fork 124
Kunzite - Diana Salazar #107
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
base: main
Are you sure you want to change the base?
Conversation
…g order (wave 2).
spitsfire
left a comment
There was a problem hiding this 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"]) |
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| 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.
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"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| 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.
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"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
No description provided.