Conversation
Wave 1 tests passing
Wave 2 tests passing
Wave 3 tests passing
added Slack bot functionality
Wave 5 tests passed
yangashley
left a comment
There was a problem hiding this comment.
Great work on Task List, Morgan! 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 or make response so that you properly return JSON to the client.
I added a few comments about using list comprehension, where you could use a helper function, and using nullable=False.
Let me know if you have any questions!
|
|
||
| class Goal(db.Model): | ||
| goal_id = db.Column(db.Integer, primary_key=True) | ||
| title = db.Column(db.String) |
There was a problem hiding this comment.
Consider adding nullable=False to ensure every goal requires a title.
|
|
||
| class Task(db.Model): | ||
| task_id = db.Column(db.Integer, primary_key=True) | ||
| title = db.Column(db.String) |
There was a problem hiding this comment.
Consider adding nullable=False to ensure every task requires a title.
| "is_complete": True if self.completed_at else False | ||
| } | ||
|
|
||
| if self.goal: | ||
| task_dict["goal_id"] = self.goal_id | ||
|
|
||
| return task_dict |
| from app.models.goal import Goal | ||
| from .helpers import validate_goal, validate_task | ||
|
|
||
| goals_bp = Blueprint("goals", __name__, url_prefix="/goals") |
There was a problem hiding this comment.
Nice work creating two separate route files for each model and adding them to a routes directory
| if request_body.get("title"): | ||
| new_goal = Goal.create(request_body) | ||
| else: | ||
| abort(make_response({"details": "Invalid data"}, 400)) |
| for goal in goals: | ||
| goal_response_body.append(goal.to_json()) |
There was a problem hiding this comment.
This works well and is readable, but if you'd like to incorporate list comprehensions into your code, you could write it like this:
goals_response = [goal.to_json() for goal in goals]
| if request_body.get("title"): | ||
| goal.update(request_body) | ||
| else: | ||
| abort(make_response({"details": "Invalid data"}, 400)) |
There was a problem hiding this comment.
👍 we can't assume that the client will always pass us a correctly formatted request so good job adding error handling here too
| tasks.append(task.to_json()) | ||
|
|
||
| goal_response = goal.to_json() | ||
| goal_response["tasks"] = tasks |
There was a problem hiding this comment.
Wonder if you could refactor to_json() so that the logic on line 88 gets moved into the method
| if not already_completed: | ||
| key = os.environ.get("SLACK_API") | ||
| payload = { | ||
| "channel": "task-notifications", | ||
| "text": f"Someone just completed the task {task.title}" | ||
| } | ||
| header = {"Authorization": f"Bearer {key}"} | ||
| requests.post("https://slack.com/api/chat.postMessage", params=payload, | ||
| headers=header) |
There was a problem hiding this comment.
Consider putting this in a helper function and calling it here to make mark_complete() a bit more concise.
No description provided.