Skip to content

Olga_Karaivanska_task_list_api #41

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

Conversation

lioliadoc
Copy link

No description provided.

Copy link

@mikellewade mikellewade left a comment

Choose a reason for hiding this comment

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

Nice work over all, Ogla! The comments I left are mainly about refactors. There are a few places where you could have DRY'd up your code. Refactoring is a big part of this project because it helps train your eye for seeing similarities in your codebase as well as practicing maintainability and scalability.

app/__init__.py Outdated
Comment on lines 4 to 5
from .routes.task_routes import tasks_bp
from .routes.goal_routes import goal_bp

Choose a reason for hiding this comment

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

Don't forget that the convention for naming blueprints is to name them bp. With each blueprint being named the same thing we will need to import them under an alias like so:

from .routes.task_routes import bp as tasks_bp

id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
title: Mapped[str] = mapped_column(nullable=False)

Choose a reason for hiding this comment

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

If we want a column to be nullable then we would want to use Optional like you did like how you did in the Task model. Without Optional we don't need nullable=False.

Comment on lines +11 to +15
title: Mapped[str]
description: Mapped[str]
completed_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True )
goal_id: Mapped[Optional[int]] = mapped_column(ForeignKey("goal.id"))
goal: Mapped[Optional["Goal"]] = relationship(back_populates="tasks")

Choose a reason for hiding this comment

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

Nice work on getting these columns made!

"id": self.id,
"title": self.title,
"description": self.description,
"is_complete": self.completed_at is not None

Choose a reason for hiding this comment

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

⭐️

Comment on lines +12 to +15
return {"details": "Invalid data"}, 400

goal_data = {"title": request_body.get("title")}

Choose a reason for hiding this comment

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

This logic could go inside of our create_model function, we would just have modify the logic here and in model methods to check if check if request was a bad one.

Comment on lines +20 to +22
"description": request_body.get("description"),
"completed_at": request_body.get("completed_at")}

Choose a reason for hiding this comment

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

We don't necessarily need to do this part, we could pass in the request body since it has the keys and the accompanying values we need for our model construction.

Comment on lines 30 to 36

query = db.select(Task)
if sort_order == "asc":
query = query.order_by(Task.title.asc())
elif sort_order == "desc":
query = query.order_by(Task.title.desc())

Choose a reason for hiding this comment

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

Could this logic maybe be add to our get_model_with_filters function?


if task.goal_id is not None:
response["task"]["goal_id"] = task.goal_id

Choose a reason for hiding this comment

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

I would put this as None that way there isn't confusion where people might think you are adding a goal_id even though there isn't one.

Comment on lines +83 to +92
url = "https://slack.com/api/chat.postMessage"
headers = {"Authorization": f"Bearer {slack_token}"}
request_body = {
"channel": "task-notifications",
"text": f"Someone just completed the task '{task.title}'"
}
requests.post(url, json=request_body, headers=headers)

return{"task": task.to_dict()}, 200

Choose a reason for hiding this comment

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

I would move this logic into a helper function and then that helper function into our utilities file to help with separation of concerns and readability.

Comment on lines +80 to +92
response = client.put("/goals/1", json={
"title": "Build a habit of going outside daily"
})
response_body = response.get_json()
assert response.status_code == 200
assert "goal" in response_body
assert response_body == {
"goal": {
"id": 1,
"title": "Build a habit of going outside daily",

}
}

Choose a reason for hiding this comment

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

⭐️

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