Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Zoisite - Jackie A. #126

wants to merge 6 commits into from

Conversation

japonte08
Copy link

No description provided.

Copy link
Collaborator

@yangashley yangashley left a 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):
Copy link
Collaborator

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.

Comment on lines +8 to +9
completed_at = db.Column(db.DateTime, nullable=True)
goal_id = db.Column(db.Integer, db.ForeignKey("goal.id"), nullable=True)
Copy link
Collaborator

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
Copy link
Collaborator

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

Copy link
Collaborator

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

Comment on lines +22 to +23
slack_url = "https://slack.com/api/chat.postMessage"
channel_id = "task-notifications"
Copy link
Collaborator

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
Copy link
Collaborator

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}
Copy link
Collaborator

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)
Copy link
Collaborator

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:
Copy link
Collaborator

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.

Comment on lines +105 to +107
task_dict = task.to_dict()
task_dict["goal_id"] = int(goal_id)
tasks_response.append(task_dict)
Copy link
Collaborator

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.

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