Conversation
spitsfire
left a comment
There was a problem hiding this comment.
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): |
| from flask import current_app | ||
| from app import db | ||
| from flask import current_app | ||
| from sqlalchemy import DateTime |
There was a problem hiding this comment.
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): |
| else: | ||
| return False | ||
|
|
||
| def to_json(self): |
| 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.
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] |
| goal = Goal.query.get(goal_id) | ||
| if goal is None: | ||
| return make_response("", 404) |
There was a problem hiding this comment.
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.
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.
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.
here we could use get_or_404(), too!
No description provided.