-
Notifications
You must be signed in to change notification settings - Fork 128
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
Zoisite - Jackie A. #126
base: main
Are you sure you want to change the base?
Zoisite - Jackie A. #126
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.
Nice work on task-list-api! Let me know if you have questions about my review comments.
@@ -2,4 +2,19 @@ | |||
|
|||
|
|||
class Goal(db.Model): |
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.
👍 LGTM
Remember to make an empty init.py file in any package folder/subfolder. app and routes both have one, but we should have one here in the models folder as well.
completed_at = db.Column(db.DateTime, nullable=True) | ||
goal_id = db.Column(db.Integer, db.ForeignKey("goal.id"), nullable=True) |
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.
The default value for nullable
is True
so we don't need to explicitly add it
task_as_dict["id"] = self.id | ||
task_as_dict["title"] = self.title | ||
task_as_dict["description"] = self.description | ||
task_as_dict["is_complete"] = 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.
Instead of hardcoding is_complete
to False
, how could you use the value of self.completed_at
to derive the boolean value?
We could use a ternary operator like:
task_as_dict["is_complete"] = True if self.completed_at else 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.
👍 yep, every directory needs an __init__.py
file
slack_url = "https://slack.com/api/chat.postMessage" | ||
channel_id = "task-notifications" |
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 job putting this logic into a helper function!
Since slack_url and channel_id are constant variables, they should be spelled with all caps.
|
||
for task_id in task_ids: | ||
task = Task.query.get(task_id) | ||
task.goal_id = 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.
👍
|
||
db.session.commit() | ||
|
||
response_message = {"id": int(goal_id), "task_ids": task_ids} |
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.
The value referenced by task_ids comes from the request body that the client sent to your API. Instead of returning the values that the client sent in the response message, I'd prefer to get the task ids from the goal object that you validated and then associated tasks with instead.
goal = validate_model(Goal, goal_id) | ||
|
||
response_message = goal.to_dict() | ||
tasks = Task.query.filter_by(goal=goal) |
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.
We don't need to use Task.query.filter_by actually. Since a goal has associated tasks, we can access the goal's tasks
attribute (see goal.py line 7).
So this can be refactored to tasks = goal.tasks
tasks = Task.query.filter_by(goal=goal) | ||
tasks_response = [] | ||
|
||
if tasks: |
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 need for line 103. if tasks
is an empty list, then the for loop won't execute.
task_dict = task.to_dict() | ||
task_dict["goal_id"] = int(goal_id) | ||
tasks_response.append(task_dict) |
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 move the logic on line 106 into the to_dict() method then this for loop could be refactored to use list comprehension.
No description provided.