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

Project complete and deployed #105

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

Conversation

hhameed1
Copy link

No description provided.

Copy link

@yangashley yangashley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on Task List, Huma! You earned a 🟢 on this project. Really nice to see you making frequent commits too.

From your code, I can see that you've got a nice handle on Flask and SqlAlchemy. Good to see you consistently using jsonify and I'd encourage you to reuse your instance method to_json() in your Goal and Task classes.

I added a few comments about using list comprehension and some refactors to help keep your routes concise.

Let me know if you have any questions!

from app.models.task import Task
# datetime.datetime.utcnow()

goal_bp = Blueprint("goal_bp", __name__, url_prefix = "/goals")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep your project organized, you can create a routes directory under the app directory. In the routes directory, you can add goal_routes.py and you can rename routes.py to task_routes.py

from flask import request
from datetime import datetime
from app.models.task import Task
# datetime.datetime.utcnow()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting comments like this can keep your code clean

goal_bp = Blueprint("goal_bp", __name__, url_prefix = "/goals")


def validate_goal(id_):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about id_, is the underscore intentional here after id?

Comment on lines +33 to +37
try:
new_goal = Goal.create(request_body)

except KeyError:
return abort(make_response({"details": "Invalid data"}, 400))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice error handling here! We can't assume that clients will send valid requests to our API so we have to anticipate a scenario where the req doesn't have the keys your method will need to access.

Comment on lines +51 to +57
for goal in goals:
goals_response.append(
{
"id": goal.id,
"title": goal.title
}
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use a to_json() method on each goal, then you could use list comprehension here to keep your route method concise. Something like:

goals_response = [goal.to_json() for goal in goals]

Comment on lines +66 to +75

query_params = {
"channel": "test-channel",
"text": f"Someone just completed the task {task.title}"
}

headers = {"Authorization": os.environ.get("SLACK_BOT_KEY")}

response_bot = requests.post(SLACK_BOT_POST_PATH, params=query_params, headers=headers)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting this into a helper method and then calling it here to keep the route concise. Using a helper method would also apply the SRP (single responsibility principle) to the route function.

Comment on lines +103 to +107
tasks = Task.query.order_by(Task.title.desc()).all()
else:
# tasks = Task.query.all()
tasks = Task.query.order_by(Task.title.asc()).all()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with order_by() you don't need to use chain .all() to the end of this statement.

Comment on lines +111 to +112
task_response_body.append(task.to_json())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use list comprehension here if you'd like.

request_body = request.get_json()

task.update(request_body)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding some error handling here if request_body doesn't have "title" or "description"

# Act
# ---- Complete Act Here ----

response = client.put("/goals/1", json={

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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