-
Notifications
You must be signed in to change notification settings - Fork 15
Accelerate - Andrea Valliere #4
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: master
Are you sure you want to change the base?
Conversation
…space each time a task is marked complete. Satisfies wave 4.
…als by id. Passes wave 5 tests.
Waves 6 and 7 incomplete. Have some uncommitted code I'll push up shortly |
@@ -4,3 +4,4 @@ | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after this line go ahead and add the db.relationship
for tasks
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add goal_id
adding a db.ForeignKey("goal.goal_id")
to connect it to the Goal class
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
@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) |
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.
💃🏽
@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) |
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 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) |
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.
💃🏽
} | ||
db.session.delete(goal) | ||
db.session.commit() | ||
return make_response(response, 200) |
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.
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.
No description provided.