-
Notifications
You must be signed in to change notification settings - Fork 146
Lions - Jessica Ambriz-Madrigal #127
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?
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.
Nice work Jessica, you hit the learning goals here. I left some minor comments in the code. If you have questions on them please let me know via Slack.
|
||
|
||
|
||
|
||
|
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.
if self.completed_at is None: | ||
if self.goal_id is None: | ||
task_dict = { | ||
"id":self.id, | ||
"title":self.title, | ||
"description":self.description, | ||
"is_complete": False | ||
} | ||
else: | ||
task_dict = { | ||
"id":self.id, | ||
"goal_id": self.goal_id, | ||
"title":self.title, | ||
"description":self.description, | ||
"is_complete": False | ||
} | ||
else: | ||
task_dict = { | ||
"id":self.id, | ||
"title":self.title, | ||
"description":self.description, | ||
"is_complete": True | ||
} | ||
return task_dict |
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.
This seems a little over-complicated. Could you do the basic dictionary in one block and then add key-value pairs based on an if-else?
task_bp = Blueprint("task_bp",__name__, url_prefix="/tasks") | ||
|
||
def get_one_task_or_abort(task_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.
Good helper function
"description" not in request_body: | ||
return jsonify({"details": "Invalid data"}), 400 |
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.
Good validation here. However I think you should also indicate what data is invalid.
"task":{ | ||
"id" : new_task.id, | ||
"title" : new_task.title, | ||
"description" : new_task.description, | ||
"is_complete" : new_task.is_complete | ||
} | ||
}, 201 |
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.
This return value might be useful as a helper function for reuse.
tasks = Task.query.all() | ||
|
||
if sort_param == "desc": | ||
tasks = Task.query.order_by(Task.title.desc()).all() | ||
|
||
if sort_param == "asc": | ||
tasks = Task.query.order_by(Task.title.asc()).all() |
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.
This might cause Task.query
to execute twice making this potentially twice as slow as it needs to be.
SLACK_BOT_TOKEN = os.environ.get("SLACK_BOT_TOKEN") | ||
|
||
headers = { | ||
"Authorization" : f"Bearer {SLACK_BOT_TOKEN}" | ||
} | ||
params = { | ||
"channel": "task-notifications", | ||
"text": f"Someone just completed the task {update_is_valid_id.title}" | ||
} | ||
|
||
requests.get(url=SLACK_PATH, headers=headers, params=params) |
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.
The Slack portion would make a good candidate for a helper function.
return jsonify({"details": "Invalid data"}), 400 |
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.
Again indicating what data is invalid would be useful.
No description provided.