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

task list pull request #67

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

task list pull request #67

wants to merge 5 commits into from

Conversation

chanbzz
Copy link

@chanbzz chanbzz commented May 13, 2021

No description provided.

Copy link

@audreyandoy audreyandoy left a comment

Choose a reason for hiding this comment

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

Awesome job Chan 🔥 You hit all the learning goals for this project and I can tell you took a lot of care with this project. Overall, your was neat and easy to read. You've got some clean functions that can be reduced even further using the .get_or_404() method. I'm glad you're seeing the value of helper methods/functions and are having fun with list comprehension and classes!

I added a few comments about how you could refactor and/or other ways of writing code.

Overall, great job and keep up the hard work 🔥 👍 ✨

@@ -1,6 +1,21 @@
from flask import current_app
from app import db
from sqlalchemy.orm import relationship

Choose a reason for hiding this comment

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

hmm.. I don't think you need this import from sqlalchemy as you're already importing and initializing it as db in __init__.py.
This means relationship is coming from db rather than sqlalhemy.orm in this file.

"id": self.goal_id,
"title": self.title
}

Choose a reason for hiding this comment

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

Good job in setting up the one to many relationship here and using a helper method! 👍

Comment on lines +4 to +5
from sqlalchemy.orm import relationship
from sqlalchemy import ForeignKey

Choose a reason for hiding this comment

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

See comment about imports in goal.py

Comment on lines +18 to +30
def to_json(self):

task_dict = {
"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": False if self.completed_at is None else True
}

if self.goal_id:
task_dict["goal_id"] = self.goal_id

return task_dict

Choose a reason for hiding this comment

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

Nice helper method here. This is a good way to adding in a goal_id only IF a non-null value is detected. The ternary here looks great as well. Another way you can write that is using:

Suggested change
def to_json(self):
task_dict = {
"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": False if self.completed_at is None else True
}
if self.goal_id:
task_dict["goal_id"] = self.goal_id
return task_dict
def to_json(self):
task_dict = {
"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": self.completed_at != None
}
if self.goal_id:
task_dict["goal_id"] = self.goal_id
return task_dict

Comment on lines +59 to +62
task = Task.query.get(task_id)

if task == None:
return("", 404)

Choose a reason for hiding this comment

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

Nice!! You can also reduce these lines of code by using Flask's get_or_404() method

Suggested change
task = Task.query.get(task_id)
if task == None:
return("", 404)
task = Task.query.get_or_404(task_id)

Choose a reason for hiding this comment

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

This method can be used pretty much anywhere you're grabbing an id.

else:
task.completed_at = datetime.now()
db.session.commit()
slack_app.slack_bot_message(task)

Choose a reason for hiding this comment

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

Nice use of a helper method here!

if request.method == "GET":

tasks = Task.query.filter_by(goal_id=goal_id)
response_body = [task.to_json() for task in tasks]

Choose a reason for hiding this comment

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

Great use of a list comprehension here!

@@ -0,0 +1,25 @@
from app.models import task

Choose a reason for hiding this comment

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

Great use of a class here Chan 🔥


if request.method == "GET":

tasks = Task.query.filter_by(goal_id=goal_id)

Choose a reason for hiding this comment

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

Ooo interesting how you didn't need to use a join here, only a filter by.

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