Skip to content

C22_Marjana_Khatun #22

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

C22_Marjana_Khatun #22

wants to merge 14 commits into from

Conversation

marjanak
Copy link

@marjanak marjanak commented Nov 8, 2024

No description provided.

Copy link
Collaborator

@kelsey-steven-ada kelsey-steven-ada 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 Marjana! Let me know if you have questions on any of my feedback =]

@@ -1,6 +1,9 @@
from flask import Flask
from .db import db, migrate
from .models import task, goal
from .routes.task_routes import tasks_bp
from .routes.goal_routes import bp as goals_bp
from .models import goal
Copy link
Collaborator

Choose a reason for hiding this comment

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

We're importing goal on line 4 and line 6; this import should be removed to keep our file tidy.

Comment on lines +13 to +14
)
@classmethod
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should leave a blank line between these functions to create visual space for readers - it makes it easier to quickly scan through a file when the functions are very clear from each other.

goal : Mapped[Optional["Goal"]] = relationship(back_populates="tasks")

def to_dict(self):
is_complete_task= False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
is_complete_task= False
is_complete_task = False

Comment on lines +20 to +28
task_dict = dict(
id=self.id,
title=self.title,
description=self.description,
is_complete=is_complete_task,

)
if self.goal:
task_dict["goal_id"] = self.goal.id
Copy link
Collaborator

Choose a reason for hiding this comment

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

The spacing is a little weird here, I recommend removing the blank line inside the dict declaration and adding a blank line after to separate the creation from the goal check:

        task_dict = dict(
            id=self.id,
            title=self.title,
            description=self.description,
            is_complete=is_complete_task,
        )

        if self.goal:
            task_dict["goal_id"] = self.goal.id

Comment on lines +1 to +13
from sqlalchemy.orm import Mapped, mapped_column , relationship
from sqlalchemy import ForeignKey
from ..db import db
from datetime import datetime
from typing import Optional

class Task(db.Model):
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
title : Mapped[str]
description : Mapped [str]
completed_at: Mapped[Optional[datetime]]
goal_id: Mapped[Optional[int]] = mapped_column(ForeignKey("goal.id"))
goal : Mapped[Optional["Goal"]] = relationship(back_populates="tasks")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Really nice set up work for both your model classes! 🙌🏻

task = validate_model(Task, task_id)

task.completed_at = date.today()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This works, but the datetime module also has a method .now() which can optionally accept a timezone parameter. In the Python documentation now is noted as preferred over today (documentation)


@bp.post("/<goal_id>/tasks")
def create_task_with_goal_id(goal_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function will look up existing tasks and associate them with an existing goal. Since we don't create any new tasks, how could we rename this route function to better reflect the actions it is taking?

Comment on lines +96 to +98
for task in goal.tasks:
all_tasks.append(task.to_dict())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be a great place for a list comprehension:

all_tasks = [task.to_dict() for task in goal.tasks]

@@ -77,7 +77,7 @@ def three_tasks(app):
def completed_task(app):
new_task = Task(title="Go on my daily walk 🏞",
description="Notice something new every day",
completed_at=datetime.utcnow())
completed_at=datetime.now())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch that this should be updated to now since utcnow is deprecated!

Comment on lines +45 to +55
#@pytest.mark.skip(reason="No way to test this feature yet")
def test_get_tasks_for_specific_goal_no_goal(client):
# Act
response = client.get("/goals/1/tasks")
response_body = response.get_json()

# Assert
assert response.status_code == 404
assert response_body == {"message" : "Goal 1 not found"}

raise Exception("Complete test with assertion about response body")
#raise Exception("Complete test with assertion about response body")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Updates look great across the tests!

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