Skip to content

Conversation

@eggoweggo
Copy link

No description provided.

Copy link

@tgoslee tgoslee left a comment

Choose a reason for hiding this comment

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

Great job Shannon! Your code was readable and organized. I left comments on a few things you can refactor! Let me know if you have any questions!

Comment on lines +33 to +37
from .task_routes import tasks_bp
app.register_blueprint(tasks_bp)

return app
from .goal_routes import goals_bp
app.register_blueprint(goals_bp)
Copy link

Choose a reason for hiding this comment

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

I like that you organized tasks and goals into two separate files. You can also move them to a directory called routes to make it even more organized.

goals_bp = Blueprint("goals_bp", __name__, url_prefix="/goals")

# helper functions
def validate_goal(goal_id):
Copy link

Choose a reason for hiding this comment

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

great validation and error handling. You can also move this function and other helper functions into a file helper_functions.py

def create_goal():
request_body = request.get_json()
if "title" not in request_body:
return make_response(jsonify({"details": "Invalid data"}), 400)
Copy link

Choose a reason for hiding this comment

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

you can add more specific details Invalid Data: the title is missing just like you did in your validate helper function

goal_id = db.Column(db.Integer, primary_key=True)
goal_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String)
tasks = db.relationship("Task", back_populates="goal", lazy=True)
Copy link

Choose a reason for hiding this comment

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

Because the default value for lazy is True you could technically leave it off. More info here https://docs.sqlalchemy.org/en/14/orm/loading_relationships.html

task_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String, nullable=False)
description = db.Column(db.String, nullable=False)
completed_at = db.Column(db.DateTime)
Copy link

Choose a reason for hiding this comment

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

you could add nullable=True here because completed_at doesn't have to exist

goal_id = db.Column(db.Integer, db.ForeignKey("goal.goal_id"))
goal = db.relationship("Goal", back_populates="tasks")

def make_dict(self):
Copy link

Choose a reason for hiding this comment

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

Because this is repetitive you could create a response dictionary to check for goal_id something like

response_dict = dict(
    id=self.task_id,
    title=self.title,
    description=self.description,
    is_complete= bool(self.completed_at)
)
        
if self.goal_id:
    response_dict["goal_id"] = self.goal_id
            
return response_dict

abort(make_response({"error":f"Task not found"}, 404))
return task

def slack_bot(task):
Copy link

Choose a reason for hiding this comment

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

🙌🏽

Comment on lines +43 to +51
if "completed_at" in request_body:
new_task = Task(
title=request_body["title"],
description=request_body["description"],
completed_at=request_body["completed_at"])
else:
new_task = Task(
title=request_body["title"],
description=request_body["description"])
Copy link

Choose a reason for hiding this comment

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

How could you use something like a ternary or conditional on line 47 instead of an if/else?

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