-
Notifications
You must be signed in to change notification settings - Fork 71
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
Lin - Rocks! #63
base: master
Are you sure you want to change the base?
Lin - Rocks! #63
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.
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): |
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.
👍 yay helper method!!
from app import db | ||
from flask import current_app | ||
from sqlalchemy import DateTime |
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.
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.
from sqlalchemy import DateTime |
goal_id = db.Column(db.Integer, db.ForeignKey( | ||
'goal.goal_id'), nullable=True) | ||
|
||
def is_complete(self): |
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.
👍
else: | ||
return False | ||
|
||
def to_json(self): |
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.
👍
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 | ||
} |
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 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] |
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 list comprehension
goal = Goal.query.get(goal_id) | ||
if goal is None: | ||
return make_response("", 404) |
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.
here we could use get_or_404()
, too!
goal = Goal.query.get(goal_id) | ||
if goal is None: | ||
return make_response("", 404) |
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.
here we could use get_or_404()
, too!
goal = Goal.query.get(goal_id) | ||
if goal is None: | ||
return make_response("", 404) |
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.
here we could use get_or_404()
, too!
goal = Goal.query.get(goal_id) | ||
if goal is None: | ||
return make_response("", 404) |
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.
here we could use get_or_404()
, too!
No description provided.