Open
Conversation
…space each time a task is marked complete. Satisfies wave 4.
…als by id. Passes wave 5 tests.
Author
|
Waves 6 and 7 incomplete. Have some uncommitted code I'll push up shortly |
tgoslee
reviewed
Jun 20, 2021
|
|
||
| class Goal(db.Model): | ||
| goal_id = db.Column(db.Integer, primary_key=True) | ||
| title = db.Column(db.String) |
There was a problem hiding this comment.
after this line go ahead and add the db.relationship for tasks
tgoslee
reviewed
Jun 20, 2021
| task_id = db.Column(db.Integer, primary_key=True, autoincrement=True) | ||
| title = db.Column(db.String) | ||
| description = db.Column(db.String) | ||
| completed_at = db.Column(db.DateTime, nullable=True, default=None) |
There was a problem hiding this comment.
add goal_id adding a db.ForeignKey("goal.goal_id") to connect it to the Goal class
tgoslee
reviewed
Jun 20, 2021
Comment on lines
+20
to
+28
| title = request_body.get("title") | ||
| description = request_body.get("description") | ||
|
|
||
| if not title or not description or "completed_at" not in request_body: | ||
| return jsonify({"details": "Invalid data"}), 400 | ||
|
|
||
| new_task = Task(title=request_body["title"], | ||
| description=request_body["description"], | ||
| completed_at=request_body["completed_at"]) |
There was a problem hiding this comment.
Because you defined title and description on lines 20/21 you can just use title and description on lines 26/27
For example: Task(title = title)
tgoslee
reviewed
Jun 20, 2021
Comment on lines
+60
to
+103
| @tasks_bp.route("/<task_id>", methods=["GET", "PUT", "DELETE"]) | ||
| def handle_task(task_id): | ||
| task = Task.query.get(task_id) | ||
| if task is None: | ||
| return make_response("", 404) | ||
|
|
||
| if request.method == "GET": | ||
| selected_task = { | ||
| "task": { | ||
| "id": task.task_id, | ||
| "title": task.title, | ||
| "description": task.description, | ||
| "is_complete": bool(task.completed_at) | ||
| } | ||
| } | ||
| return selected_task | ||
|
|
||
| elif request.method == "PUT": | ||
| request_body = request.get_json() | ||
|
|
||
| task.title = request_body["title"] | ||
| task.description = request_body["description"] | ||
| task.completed_at = request_body["completed_at"] | ||
|
|
||
| updated_task = { | ||
| "task": { | ||
| "id": task.task_id, | ||
| "title": task.title, | ||
| "description": task.description, | ||
| "is_complete": bool(task.completed_at) | ||
| } | ||
| } | ||
|
|
||
| db.session.commit() | ||
| return make_response(updated_task, 200) | ||
|
|
||
| elif request.method == "DELETE": | ||
| response = { | ||
| "details": | ||
| f'Task {task.task_id} "{task.title}" successfully deleted' | ||
| } | ||
| db.session.delete(task) | ||
| db.session.commit() | ||
| return make_response(response, 200) |
tgoslee
reviewed
Jun 20, 2021
Comment on lines
+105
to
+151
| @tasks_bp.route("/<task_id>/mark_complete", methods=["PATCH"]) | ||
| def handle_complete_task(task_id): | ||
| task = Task.query.get(task_id) | ||
| if task is None: | ||
| return make_response("", 404) | ||
|
|
||
| task.completed_at = date.today() | ||
| db.session.commit() | ||
| response = { | ||
| "task": { | ||
| "id": task.task_id, | ||
| "title": task.title, | ||
| "description": task.description, | ||
| "is_complete": True | ||
| } | ||
| } | ||
|
|
||
| slack_path = "https://slack.com/api/chat.postMessage" | ||
| slack_token = os.environ.get("SLACK_API_TOKEN") | ||
| slack_headers = { | ||
| "Authorization": f"Bearer {slack_token}" | ||
| } | ||
| slack_query_params = { | ||
| "channel": "task-list-bot", | ||
| "text": f"Someone just completed the task {task.title}." | ||
| } | ||
| requests.post(slack_path, params=slack_query_params, headers=slack_headers) | ||
|
|
||
| return make_response(response, 200) | ||
|
|
||
| @tasks_bp.route("/<task_id>/mark_incomplete", methods=["PATCH"]) | ||
| def handle_incomplete_task(task_id): | ||
| task = Task.query.get(task_id) | ||
| if task is None: | ||
| return make_response("", 404) | ||
|
|
||
| task.completed_at = None | ||
| db.session.commit() | ||
| response = { | ||
| "task": { | ||
| "id": task.task_id, | ||
| "title": task.title, | ||
| "description": task.description, | ||
| "is_complete": False | ||
| } | ||
| } | ||
| return make_response(response, 200) |
tgoslee
reviewed
Jun 20, 2021
Comment on lines
+158
to
+187
| def handle_goals(): | ||
| if request.method == "POST": | ||
| request_body = request.get_json() | ||
| title = request_body.get("title") | ||
|
|
||
| if not title: | ||
| response_body = {"details": "Invalid data"} | ||
| return make_response(response_body, 400) | ||
|
|
||
| new_goal = Goal(title=title) | ||
| db.session.add(new_goal) | ||
| db.session.commit() | ||
| db_goal = { | ||
| "goal": { | ||
| "id": new_goal.goal_id, | ||
| "title": new_goal.title | ||
| } | ||
| } | ||
| return db_goal, 201 | ||
| elif request.method == "GET": | ||
| goals = Goal.query.all() | ||
|
|
||
| goals_response = [] | ||
| for goal in goals: | ||
| goals_response.append({ | ||
| "id": goal.goal_id, | ||
| "title": goal.title | ||
| }) | ||
| goals_json_response = jsonify(goals_response) | ||
| return make_response(goals_json_response, 200) |
tgoslee
reviewed
Jun 20, 2021
| } | ||
| db.session.delete(goal) | ||
| db.session.commit() | ||
| return make_response(response, 200) No newline at end of file |
There was a problem hiding this comment.
To get Wave 6 passing start with:
- setting up the route after this line
@goal_bp.route("/<goal_id>/tasks", methods=["GET", "POST"]) - make sure to implement the database relationship and goal_id in Models.py
- you've done a great job with the previous methods. Follow what you've been doing and the ReadME to get it implemented.
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.