-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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!
from .routes.task_routes import bp as task_bp | ||
from .routes.goal_routes import bp as goal_bp |
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
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:
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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
task = Task( | ||
title=data["title"], | ||
description=data["description"], | ||
completed_at=data["completed_at"], | ||
) | ||
|
||
return task |
There was a problem hiding this comment.
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:
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"]) |
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
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
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", |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
# "channel": "U07GC9C8Y4X", # My Slack account ID | ||
"username": "Task List app", |
There was a problem hiding this comment.
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
fixing notofocations in deployed BE fixing notofocations in deployed BE fixing notofocations in deployed BE fixing notofocations in deployed BE
No description provided.