-
Notifications
You must be signed in to change notification settings - Fork 111
c17 sea turtles - jae #111
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
base: master
Are you sure you want to change the base?
Changes from all commits
e2a223a
bfb2572
ec31f83
5e79d2b
edeab94
318e5c6
446479a
f6decf5
6ac0d3b
98c7a54
0361a75
65ddc75
e4148b2
aafed42
48292b6
b4dce2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn 'app:create_app()' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
from flask import jsonify, abort, make_response | ||
|
||
def error_message(message, status_code): | ||
abort(make_response(jsonify(dict(details=message)), status_code)) | ||
|
||
|
||
|
||
|
||
# validate record | ||
# pass in the actual class in our function, to use for both models ! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,72 @@ | ||
from app import db | ||
|
||
|
||
class Task(db.Model): | ||
task_id = db.Column(db.Integer, primary_key=True) | ||
id = db.Column(db.Integer, primary_key=True) | ||
title = db.Column(db.String, nullable=False) | ||
description = db.Column(db.String, nullable=False) | ||
is_complete = db.Column(db.Boolean, default=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider not making an actual |
||
completed_at = db.Column(db.DateTime, default=None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For nullable columns, their default value is NULL ( |
||
goal_id = db.Column(db.Integer, db.ForeignKey('goal.id')) | ||
# goal = db.relationship ("Goal", backref='tasks') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, we don't need this relationship since we have the |
||
|
||
|
||
|
||
def to_dict(self): | ||
task_dict = dict( | ||
# goal_id=self.goal_id | ||
id=self.id, | ||
title=self.title, | ||
description=self.description, | ||
is_complete= self.is_complete | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The line you commented out would be a big help here! is_complete= True if self.completed_at else False would allow us to get rid of the column, and the later |
||
) | ||
|
||
# True if self.completed_at else False | ||
|
||
if self.completed_at: | ||
task_dict['is_complete'] = True | ||
|
||
if self.goal_id: | ||
task_dict['goal_id'] = self.goal_id | ||
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice way to add the goal id for tasks that are part of a goal. |
||
|
||
return task_dict | ||
|
||
|
||
|
||
|
||
@classmethod | ||
def from_dict(cls, data_dict): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 But try to clean up the code that's not being used. |
||
|
||
return cls( | ||
title=data_dict["title"], | ||
description=data_dict["description"] | ||
# is_complete=data_dict["is_complete"], | ||
# completed_at=data_dict["completed_at"] | ||
# is_complete=data_dict["is_complete"], | ||
|
||
) | ||
|
||
def replace_details(self, data_dict): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Nice helper to update the task details, including the optional Also consider leaving off the call to convert the task to a dictionary. There's no real relationship between updating a task, and converting it to a dictionary. One is business logic, and the other is for sending a result back to the an API caller. |
||
self.title=data_dict["title"] | ||
self.description=data_dict["description"] | ||
|
||
if "completed_at" in data_dict: | ||
self.completed_at=data_dict["completed_at"] | ||
self.is_complete= True | ||
|
||
return self.to_dict() | ||
|
||
|
||
|
||
# completed_at : default null (none) | ||
|
||
# is_complete(db.relationship) | ||
|
||
|
||
# when we care a new task, completed_att should be NULL (NONE) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
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.
👍
For the name of this file, the file doesn't contain routes for something called a helper, it contains helpers for routes, so I would name this
route_helpers.py