-
Notifications
You must be signed in to change notification settings - Fork 111
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
Project complete and deployed #105
base: master
Are you sure you want to change the base?
Conversation
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.
Great work on Task List, Huma! You earned a 🟢 on this project. Really nice to see you making frequent commits too.
From your code, I can see that you've got a nice handle on Flask and SqlAlchemy. Good to see you consistently using jsonify and I'd encourage you to reuse your instance method to_json() in your Goal and Task classes.
I added a few comments about using list comprehension and some refactors to help keep your routes concise.
Let me know if you have any questions!
from app.models.task import Task | ||
# datetime.datetime.utcnow() | ||
|
||
goal_bp = Blueprint("goal_bp", __name__, url_prefix = "/goals") |
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 keep your project organized, you can create a routes directory under the app directory. In the routes directory, you can add goal_routes.py and you can rename routes.py to task_routes.py
from flask import request | ||
from datetime import datetime | ||
from app.models.task import Task | ||
# datetime.datetime.utcnow() |
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.
Deleting comments like this can keep your code clean
goal_bp = Blueprint("goal_bp", __name__, url_prefix = "/goals") | ||
|
||
|
||
def validate_goal(id_): |
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.
Curious about id_
, is the underscore intentional here after id?
try: | ||
new_goal = Goal.create(request_body) | ||
|
||
except KeyError: | ||
return abort(make_response({"details": "Invalid data"}, 400)) |
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.
Nice error handling here! We can't assume that clients will send valid requests to our API so we have to anticipate a scenario where the req doesn't have the keys your method will need to access.
for goal in goals: | ||
goals_response.append( | ||
{ | ||
"id": goal.id, | ||
"title": goal.title | ||
} | ||
) |
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.
If you use a to_json() method on each goal, then you could use list comprehension here to keep your route method concise. Something like:
goals_response = [goal.to_json() for goal in goals]
|
||
query_params = { | ||
"channel": "test-channel", | ||
"text": f"Someone just completed the task {task.title}" | ||
} | ||
|
||
headers = {"Authorization": os.environ.get("SLACK_BOT_KEY")} | ||
|
||
response_bot = requests.post(SLACK_BOT_POST_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.
Consider putting this into a helper method and then calling it here to keep the route concise. Using a helper method would also apply the SRP (single responsibility principle) to the route function.
tasks = Task.query.order_by(Task.title.desc()).all() | ||
else: | ||
# tasks = Task.query.all() | ||
tasks = Task.query.order_by(Task.title.asc()).all() |
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.
with order_by() you don't need to use chain .all() to the end of this statement.
task_response_body.append(task.to_json()) |
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.
You can use list comprehension here if you'd like.
request_body = request.get_json() | ||
|
||
task.update(request_body) |
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.
Consider adding some error handling here if request_body doesn't have "title" or "description"
# Act | ||
# ---- Complete Act Here ---- | ||
|
||
response = client.put("/goals/1", json={ |
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.
👍
No description provided.