Skip to content

C22 - Sphinx - Tatiana Trofimova #38

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 80 commits into
base: main
Choose a base branch
from

Conversation

Nerpassevera
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-api!

Comment on lines +2 to +3
from .routes.task_routes import bp as task_bp
from .routes.goal_routes import bp as goal_bp

Choose a reason for hiding this comment

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

👍


@classmethod
def from_dict(cls, data):
return Goal(title=data["title"])

Choose a reason for hiding this comment

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

While we can explicitly use Goal here, we can also use the cls keyword, like:

Suggested change
return Goal(title=data["title"])
return cls(title=data["title"])

from ..db import db

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

Choose a reason for hiding this comment

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

Consider whether the this column for Goal should be nullable. It feels odd to allow someone to create a goal that gets saved to the DB without a title.

from ..db import db

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

Choose a reason for hiding this comment

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

As with Goal, consider which of the columns for Task should be nullable and which should not be.

Comment on lines +32 to +38
task = Task(
title=data["title"],
description=data["description"],
completed_at=data["completed_at"],
)

return task

Choose a reason for hiding this comment

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

Since you don't reference the variable task after you initialize it and before you return it, you can just directly return the instance of task without making a variable:

Suggested change
task = Task(
title=data["title"],
description=data["description"],
completed_at=data["completed_at"],
)
return task
return cls(
title=data["title"],
description=data["description"],
completed_at=data["completed_at"],
)

@bp.post("/", strict_slashes=False)
def create_goal():
return create_class_instance(Goal, request, ["title"])

Choose a reason for hiding this comment

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

The logic in create_class_instance doesn't access the list of required fields so I think ["title"] should be removed since we don't need to pass it to the helper function

@bp.post("/", strict_slashes=False)
def create_task():
return create_class_instance(Task, request, ["title", "description"])

Choose a reason for hiding this comment

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

Same comment as in goal_routes.py: looks like create_class_instance never accesses the last param required_fields so it should be removed

Suggested change
return create_class_instance(Task, request, ["title", "description"])
return create_class_instance(Task, request)

}
message_status = requests.post(
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.

Prefer the URL to be referenced by a constant variable instead of having a string literal here.

URL = "https://slack.com/api/chat.postMessage" 
        url=URL, 

headers={
"Authorization": environ.get('SLACK_API_KEY'),
"Content-Type": "application/json"

Choose a reason for hiding this comment

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

When you pass your payload as json, like you do on line 63, Flask will auto set the Contnet-Type to JSON so you don't need to

Comment on lines +56 to +58
# "channel": "U07GC9C8Y4X", # My Slack account ID
"username": "Task List app",

Choose a reason for hiding this comment

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

Prefer the string literals on lines 56 and 58 be referenced with constant variables like CHANNEL_NAME and USERNAME

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