-
Notifications
You must be signed in to change notification settings - Fork 15
C15 Accelerate - Regina Tam #12
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
@@ -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.
add tasks
to the Goal model with db.relationship
this will set up the connection between goal and task.
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
here with db.ForeignKey
to connect it to goal.goal_id
# if request_body["completed_at"] is None: | ||
# request_body["completed_at"] = false |
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.
go ahead and remove commented code
@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("Not Found", 404) | ||
elif request.method == "GET": | ||
return { "task":{ | ||
"id": task.task_id, | ||
"title": task.title, | ||
"description": task.description, | ||
"is_complete": bool(task.completed_at) | ||
}} | ||
elif request.method == "PUT": | ||
form_data = request.get_json() | ||
|
||
task.title = form_data["title"] | ||
task.description = form_data["description"] | ||
task.completed_at = form_data["completed_at"] | ||
|
||
db.session.commit() | ||
|
||
return { | ||
"task":{ | ||
"id": task.task_id, | ||
"title": task.title, | ||
"description": task.description, | ||
"is_complete": bool(task.completed_at) | ||
}} | ||
elif request.method == "DELETE": | ||
db.session.delete(task) | ||
db.session.commit() | ||
return make_response({ | ||
"details":f"Task {task.task_id} \"{task.title}\" successfully deleted" | ||
}) |
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 post_to_slack(slack_message): | ||
SLACK_TOKEN = os.environ.get('SLACK_ACCESS_TOKEN') | ||
slack_path = "https://slack.com/api/chat.postMessage" | ||
query_params ={ | ||
'channel': 'task-notifications', | ||
'text': slack_message | ||
} | ||
headers = {'Authorization': f"Bearer {SLACK_TOKEN}"} | ||
requests.post(slack_path, params=query_params, 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.
I like that you created a different method for slack!
def handle_task_completion(task_id): | ||
task = Task.query.get(task_id) | ||
if task is None: | ||
return make_response("Not Found", 404) | ||
elif request.method == "PATCH": | ||
if bool(task.completed_at) == False: | ||
task.completed_at = datetime.datetime.now() | ||
slack_message = f"Someone just completed the task {task.title}" | ||
post_to_slack(slack_message) | ||
return ( | ||
{ "task":{ | ||
"id": task.task_id, | ||
"title": task.title, | ||
"description": task.description, | ||
"is_complete": bool(task.completed_at) | ||
}}, 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_incomplete", methods=["PATCH"]) | ||
def handle_task_not_completion(task_id): | ||
task = Task.query.get(task_id) | ||
if task is None: | ||
return make_response("Not Found", 404) | ||
elif request.method == "PATCH": | ||
task.completed_at = None | ||
return ({ "task":{ | ||
"id": task.task_id, | ||
"title": task.title, | ||
"description": task.description, | ||
"is_complete": False | ||
}}, 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.
💃🏽
@goals_bp.route("/<goal_id>", methods=["GET", "PUT", "DELETE"]) | ||
def handle_goal(goal_id): | ||
goal = Goal.query.get(goal_id) | ||
|
||
if goal is None: | ||
return make_response("Not Found", 404) | ||
elif request.method == "GET": | ||
return { "goal":{ | ||
"id": goal.goal_id, | ||
"title": goal.title, | ||
}} | ||
elif request.method == "PUT": | ||
form_data = request.get_json() | ||
|
||
goal.title = form_data["title"] | ||
|
||
db.session.commit() | ||
|
||
return { | ||
"goal":{ | ||
"id": goal.goal_id, | ||
"title": goal.title | ||
}} | ||
elif request.method == "DELETE": | ||
db.session.delete(goal) | ||
db.session.commit() | ||
return make_response({ | ||
"details":f"Goal {goal.goal_id} \"{goal.title}\" successfully deleted" | ||
}) |
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.
💃🏽
@goals_bp.route("/<goal_id>", methods=["GET", "PUT", "DELETE"]) | ||
def handle_goal(goal_id): | ||
goal = Goal.query.get(goal_id) | ||
|
||
if goal is None: | ||
return make_response("Not Found", 404) | ||
elif request.method == "GET": | ||
return { "goal":{ | ||
"id": goal.goal_id, | ||
"title": goal.title, | ||
}} | ||
elif request.method == "PUT": | ||
form_data = request.get_json() | ||
|
||
goal.title = form_data["title"] | ||
|
||
db.session.commit() | ||
|
||
return { | ||
"goal":{ | ||
"id": goal.goal_id, | ||
"title": goal.title | ||
}} | ||
elif request.method == "DELETE": | ||
db.session.delete(goal) | ||
db.session.commit() | ||
return make_response({ | ||
"details":f"Goal {goal.goal_id} \"{goal.title}\" successfully deleted" | ||
}) |
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 six passing go ahead and follow what you've been doing!
Set up the route @goal_bp.route("/<goal_id>/tasks", methods=["GET", "POST"])
and implement what I put in the comments for the Models.
No description provided.