-
Notifications
You must be signed in to change notification settings - Fork 97
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
Maple-FaithKauwe #81
base: master
Are you sure you want to change the base?
Maple-FaithKauwe #81
Conversation
Great job Faith! I added some comments on refactoring your code. Think about using helper functions or moving code to your models to clean up the |
Co-authored-by: Trenisha Goslee <[email protected]>
description = db.Column(db.String) | ||
completed_at = db.Column(db.DateTime, nullable = True) | ||
goal_id = db.Column(db.Integer, db.ForeignKey("goal.goal_id"), nullable = True) | ||
#goal =db.relationship("Goal", back_populates ="task") |
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.
you can remove this now that you are not using it
return make_response({"task": {"id": new_task.task_id, | ||
"title": new_task.title, | ||
"description": new_task.description, | ||
"is_complete": 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 is code is repeated multiple times in this file ... think about creating a helper function to put this information. You could also move this to your task model and create an instance method you can use in routes.py
if title_query: | ||
# filter_by returns a list of objects/ records that match the query params | ||
|
||
tasks = Task.query.filter_by(title = title_query) | ||
# what part of the Task.query is actually accessing the DB? | ||
elif order_by_query == 'asc': | ||
# getting all tasks fr the db | ||
tasks = Task.query.order_by(Task.title).all() | ||
# query_all return list of objects. loop through objects and add to empt list, task_response | ||
# as requested formatted JSON objects | ||
elif order_by_query == 'desc': | ||
tasks = Task.query.order_by(desc(Task.title)).all() | ||
# this else covers any search for all tasks, without any query params | ||
else: | ||
tasks = Task.query.order_by(Task.title).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.
💃🏽 great way to combine filtering by title and sorting
task = Task.query.get(task_id) #either get Task back or None | ||
if task is None: | ||
# couldn't figure out another way to return no response body, researched abort | ||
abort(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.
you could do something like return make_response(jsonify(None), 404)
try: | ||
query_params = {"channel": "slack-api-test-channel", | ||
"text": f"Someone just completed the task {task.title}"} | ||
header_param = {"Authorization": "Bearer "+ os.environ.get("slack_oauth_token")} | ||
slack_post_body = requests.post(slack_path, params=query_params, headers= header_param) | ||
except TypeError: | ||
pass |
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.
like the use of try/except here
if task is None: | ||
abort(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.
another suggestion instead of abort could be
if task is None: | |
abort(404) | |
if not task: | |
return "", 404 |
return make_response({"goal": {"id": new_goal.goal_id, | ||
"title": new_goal.title}}, 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.
same comment from tasks. You can make a helper function to handle the dict for goals or you could move it to the goal model and create an instance method.
No description provided.