Skip to content

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Reginatam429
Copy link

No description provided.

@@ -4,3 +4,4 @@

class Goal(db.Model):
goal_id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String)
Copy link

@tgoslee tgoslee Jun 20, 2021

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)

Copy link

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

Comment on lines +34 to +35
# if request_body["completed_at"] is None:
# request_body["completed_at"] = false
Copy link

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

Comment on lines +51 to +85
@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"
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃🏽

Comment on lines +87 to +95
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)
Copy link

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!

Comment on lines +98 to +114
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
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃🏽

Comment on lines +116 to +128
@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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃🏽

Comment on lines +158 to +186
@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"
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃🏽

Comment on lines +158 to +186
@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"
})
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants