Skip to content

Conversation

@lzhang39
Copy link

No description provided.

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

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

Lin, this is very nice! My only suggestion for you is think about consistency in return statements. it helps with readability, comprehension, predictability for other programmers and any tests someone might make. Here's an example:

`return jsonify({"goal": new_goal.to_dict()}), 201`
`return make_response({"details": "Invalid data"}, 400)`

to make these consistent, one of these needs to be changed: return jsonify({"details": "Invalid data"}), 400

# 'Task' looks at class in python and loads multiple of those (this is like a pseudo column)
tasks = db.relationship('Task', backref='goal', lazy=True)

def to_dict(self):

Choose a reason for hiding this comment

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

👍 yay helper method!!

from flask import current_app
from app import db
from flask import current_app
from sqlalchemy import DateTime

Choose a reason for hiding this comment

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

since we are already importing db, we don't need to import DateTime separately. It already comes in db, like db.String, db.Column, etc.

Suggested change
from sqlalchemy import DateTime

goal_id = db.Column(db.Integer, db.ForeignKey(
'goal.goal_id'), nullable=True)

def is_complete(self):

Choose a reason for hiding this comment

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

👍

else:
return False

def to_json(self):

Choose a reason for hiding this comment

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

👍

Comment on lines +30 to +37
def with_goal(self):
return {
"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": self.is_complete(),
"goal_id": self.goal_id
}

Choose a reason for hiding this comment

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

we could use an if statement to combine with_goal() and to_json()

@goals_bp.route("", methods=["GET"], strict_slashes=False)
def goal_index():
goals = Goal.query.all()
goals_response = [(goal.to_dict()) for goal in goals]

Choose a reason for hiding this comment

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

👍 nice list comprehension

Comment on lines +162 to +164
goal = Goal.query.get(goal_id)
if goal is None:
return make_response("", 404)

Choose a reason for hiding this comment

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

here we could use get_or_404(), too!

Comment on lines +170 to +172
goal = Goal.query.get(goal_id)
if goal is None:
return make_response("", 404)

Choose a reason for hiding this comment

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

here we could use get_or_404(), too!

Comment on lines +182 to +184
goal = Goal.query.get(goal_id)
if goal is None:
return make_response("", 404)

Choose a reason for hiding this comment

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

here we could use get_or_404(), too!

Comment on lines +211 to +213
goal = Goal.query.get(goal_id)
if goal is None:
return make_response("", 404)

Choose a reason for hiding this comment

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

here we could use get_or_404(), too!

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