Skip to content

Possum - Geetha#34

Open
geethavs88 wants to merge 3 commits intoAda-C24:mainfrom
geethavs88:main
Open

Possum - Geetha#34
geethavs88 wants to merge 3 commits intoAda-C24:mainfrom
geethavs88:main

Conversation

@geethavs88
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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!

Comment thread app/models/goal.py
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")
Copy link
Copy Markdown

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!

Comment thread app/models/goal.py
return {
"id": self.id,
"title" : self.title
#"tasks" : [task.to_dict() for task in self.tasks]
Copy link
Copy Markdown

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

Comment thread app/models/goal.py
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"]]
Copy link
Copy Markdown

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?

Comment thread app/routes/task_routes.py
@@ -1 +1,70 @@
from flask import Blueprint No newline at end of file
from flask import Blueprint, request, Response, abort, make_response
Copy link
Copy Markdown

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.

Comment thread app/models/task.py
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"))
Copy link
Copy Markdown

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.

Comment thread app/routes/task_routes.py
task.completed_at = datetime.now()
task.title="My Beautiful Task"
db.session.commit()
slack_url = "https://slack.com/api/chat.postMessage"
Copy link
Copy Markdown

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 thread app/routes/task_routes.py
Comment on lines +52 to +53
slack_request_body = {
"channel": "#task-notifications",
Copy link
Copy Markdown

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,

Comment thread app/routes/task_routes.py
def mark_task_complete(task_id):
task = validate_model(Task, task_id)
task.completed_at = datetime.now()
task.title="My Beautiful Task"
Copy link
Copy Markdown

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"

Comment thread tests/test_wave_01.py
Copy link
Copy Markdown

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.

Comment thread tests/test_wave_07.py

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

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