Skip to content

Paper-Glenda#50

Open
GClenda wants to merge 9 commits intoAda-C15:masterfrom
GClenda:master
Open

Paper-Glenda#50
GClenda wants to merge 9 commits intoAda-C15:masterfrom
GClenda:master

Conversation

@GClenda
Copy link
Copy Markdown

@GClenda GClenda commented May 13, 2021

No description provided.

Copy link
Copy Markdown

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Really nice work Glenda, you hit all the learning goals here. Well done. I made a few minor suggestions, but this is great work.

One minor additional suggestion, it might help readability to break up the long route functions you define into smaller functions which simply handle one task. You can make a route function which handles a specific path/method combination rather than one function which handles all the methods for a specific path.

"title": self.title
}

def to_json_three(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why three?

Comment on lines +11 to +16
def to_json(self):

return {
"id": self.goal_id,
"title": self.title
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 I like these helper methods

goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'), nullable=True)

# created a helper function to convert completed_at to is_complete.
def to_json(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

import os
from app.models.goal import Goal

path = "https://slack.com/api/chat.postMessage"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Make variables you want to stay stuck to a specific value, in all capital letters. We normally make constants in all caps. Also change the name to specify which path you want.

Suggested change
path = "https://slack.com/api/chat.postMessage"
SLACK_PATH = "https://slack.com/api/chat.postMessage"

Comment on lines +103 to +115
key = os.environ.get("AUTHORIZATION")

query_params = {
"text": f"Someone just completed the task {task.title}",
"channel": "task-notifications"

}

query_headers = {
"authorization": f"Bearer {key}"
}
response = requests.post(path, params=query_params, headers=query_headers )
response_body = response.json()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just a note: This would make a great helper function.

Comment on lines +116 to +119

print(response)


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
print(response)

print(response)


db.session.commit()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would also send the slack message, after you have successfully saved the task to the database.

return jsonify({"task": task.to_json()}),200


goals_bp = Blueprint("goals", __name__, url_prefix="/goals")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I suggest you define the Blueprints together at the top, just to make it easier to review all the blueprints available.

Comment on lines +217 to +218
@goals_bp.route("/<goal_id>/tasks", methods=["GET"], strict_slashes=False)
def get_goals_task(goal_id):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Small suggestion, add a blank line between route definitions

Suggested change
@goals_bp.route("/<goal_id>/tasks", methods=["GET"], strict_slashes=False)
def get_goals_task(goal_id):
@goals_bp.route("/<goal_id>/tasks", methods=["GET"], strict_slashes=False)
def get_goals_task(goal_id):

Comment on lines +17 to +18
@tasks_bp.route("", methods=["POST", "GET"], strict_slashes=False)
def tasks():
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Small readability suggestion, it could be good to break up these large functions into smaller functions. So one function to handle the GET request and the other handles the POST request.

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