Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Maple-FaithKauwe #81

wants to merge 10 commits into from

Conversation

FaithKauwe
Copy link

No description provided.

app/__init__.py Outdated Show resolved Hide resolved
@tgoslee
Copy link

tgoslee commented Nov 9, 2021

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 routes.py

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")
Copy link

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

Comment on lines +38 to +41
return make_response({"task": {"id": new_task.task_id,
"title": new_task.title,
"description": new_task.description,
"is_complete": is_complete}}, 201)
Copy link

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

Comment on lines +47 to +61
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()
Copy link

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)
Copy link

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)

Comment on lines +143 to +149
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
Copy link

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

Comment on lines +159 to +160
if task is None:
abort(404)
Copy link

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

Suggested change
if task is None:
abort(404)
if not task:
return "", 404

Comment on lines +180 to +181
return make_response({"goal": {"id": new_goal.goal_id,
"title": new_goal.title}}, 201)
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants