Skip to content

Conversation

@geethavs88
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.

Nice job on task-list-api!

class Goal(db.Model):
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
title: Mapped[str]
tasks: Mapped[list["Task"]] = relationship(back_populates="goal")

Choose a reason for hiding this comment

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

👍 A goal has many tasks!

return {
"id": self.id,
"title" : self.title
#"tasks" : [task.to_dict() for task in self.tasks]

Choose a reason for hiding this comment

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

It would be nice to conditionally return tasks if a goal has them.

You could create a goal dictionary and then add the tasks if necessary.

goal =  {
    "id": self.id,
    "title" : self.title
}

if self.tasks:
    goal["tasks"] = [task.to_dict() for task in self.tasks]

return goal

def from_dict(cls, goal_data):
return cls(
title = goal_data["title"]
#tasks = [Task.from_dict(task_data) for task_data in goal_data["tasks"]]

Choose a reason for hiding this comment

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

Same as my comment above. How could you conditionally pass tasks if you needed to?

@@ -1 +1,70 @@
from flask import Blueprint
from flask import Blueprint, request, Response, abort, make_response

Choose a reason for hiding this comment

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

Suggested change
from flask import Blueprint, request, Response, abort, make_response
from flask import Blueprint, request, Response

abort and make_response are imported but not accessed so they should be removed.

title: Mapped[str]
description: Mapped[str]
completed_at: Mapped[datetime | None] = mapped_column(nullable=True)
goal_id: Mapped[Optional[int]] = mapped_column(ForeignKey("goal.id"))

Choose a reason for hiding this comment

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

👍 The foreign key goes on the model that represents the 'many' side of the one-to-many relationship. Since a goal has many tasks, the goal's id should be the foreign key for a task.

task.completed_at = datetime.now()
task.title="My Beautiful Task"
db.session.commit()
slack_url = "https://slack.com/api/chat.postMessage"

Choose a reason for hiding this comment

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

Constant variables should be named with all caps

Suggested change
slack_url = "https://slack.com/api/chat.postMessage"
SLACK_URL = "https://slack.com/api/chat.postMessage"

Comment on lines +52 to +53
slack_request_body = {
"channel": "#task-notifications",

Choose a reason for hiding this comment

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

Prefer the channel name to be referenced by a constant variable too.

Suggested change
slack_request_body = {
"channel": "#task-notifications",
SLACK_CHANNEL = "#task-notifications"
slack_request_body = {
"channel": SLACK_CHANNEL,

def mark_task_complete(task_id):
task = validate_model(Task, task_id)
task.completed_at = datetime.now()
task.title="My Beautiful Task"

Choose a reason for hiding this comment

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

The task title shouldn't be hardcoded to "My Beautiful Task" like we showed in an example. The task.title should just be whatever the task's current title.

Suggested change
task.title="My Beautiful Task"

Choose a reason for hiding this comment

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

👍 Your added assertions for this test file look good to me.


# Assert
assert response.status_code == 400
assert "details" in response_body

Choose a reason for hiding this comment

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

Suggested change
assert "details" in response_body

We can remove this assertion because you check the shape of response_body below on line 168-170, which includes the key "details".

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