Skip to content

Phoenix (C22)- Jenny M #24

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

jennymassari
Copy link

No description provided.

Copy link

@apradoada apradoada left a comment

Choose a reason for hiding this comment

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

GREEN

Well done, Jenny! Overall this looks good and works well and passes all the tests. The biggest thing that I would focus on is modifying your task's to_dict function to include a conditional that adds the goal id if it exists but doesn't include it if it doesn't. There are so many places where you could have used it, but didn't because it doesn't quite work correctly.

All in all, if you have time, make sure you are going back over your code to see where and how you can refactor effectively!

Comment on lines +4 to +7
from .routes.task_routes import tasks_bp
import os
from dotenv import load_dotenv
from .routes.goal_routes import goals_bp

Choose a reason for hiding this comment

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

Feel free to get in the habit of naming all our blueprints bp within their routes and aliasing them within the init.py

Comment on lines +9 to +10
load_dotenv()
SLACKBOT_TOKEN = os.environ.get("SLACKBOT_TOKEN")

Choose a reason for hiding this comment

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

Because we aren't using the Slackbot token in this file, we don't need to bring it in here!

class Goal(db.Model):
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
title: Mapped[str]

Choose a reason for hiding this comment

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

Just make sure to remove unnecessary empty lines like this in the PR!


class Task(db.Model):

__tablename__ = 'tasks'

Choose a reason for hiding this comment

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

It doesn't seem as though you are using tablename anywhere else so we don't need to include this!

Comment on lines +26 to +32
def to_dict(self):
return dict(
id=self.id,
goal_id=self.goal_id,
title=self.title,
description=self.description,
is_complete=check_complete(self.completed_at)

Choose a reason for hiding this comment

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

While it feels very complete to return the dictionary in its entirety here, the goal_id is an optional attribute. When you have an optional attribute, you should only add it to the returned dictionary if it exists! This is a simple conditional that we can build in here!

Also, I see where you are coming from with the check_complete helper function. My one concern is that this is coming from the routes utilities in the routes directory. While it is not forbidden to use helper methods from the tasks in your models, it can get confusing. You could use a ternary instead to ascertain the truthiness of is_complete.

Comment on lines +68 to +75
{
"id": task.id,
"title": task.title,
"description": task.description,
"is_complete": check_complete(task.completed_at)

}

Choose a reason for hiding this comment

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

This is another place where the modified to_dict could definitely come in handy!

Comment on lines +86 to +99
return {
"task": task.to_dict()

}
else:
return {
"task": {
"id": task.id,
"title": task.title,
"description": task.description,
"is_complete": check_complete(task.completed_at)
}
}

Choose a reason for hiding this comment

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

A similar conditional in the task's to_dict would allow much more flexibility in its use!

Comment on lines +136 to +151
# def task_mark_complete(task_id):
# task = validate_task(task_id)

# task.completed_at = datetime.now()

# db.session.commit()

# return {
# "task": {
# "id": task.id,
# "title": task.title,
# "description": task.description,
# "is_complete": check_complete(task.completed_at)
# }
# }

Choose a reason for hiding this comment

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

Make sure to remove unused code from the PR!

Comment on lines +177 to +189
"channel": "task-notifications",
"text": f"Someone just completed the task {task.title}"

}

# Send the Slack message
headers = {"Authorization": f"Bearer {SLACKBOT_TOKEN}"}
slack_response = requests.post(
"https://slack.com/api/chat.postMessage",
json=slack_message,
headers=headers
)

Choose a reason for hiding this comment

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

This looks good! In order to elevate your code further, I would say this is a great candidate for a helper function!

Comment on lines +192 to +193
return jsonify({"message": "Failed to send Slack notification"}), 500

Choose a reason for hiding this comment

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

You're the only person I've seen who makes this check and I think it's a great idea!

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