-
Notifications
You must be signed in to change notification settings - Fork 128
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
Sapphire - Linh H. #127
base: main
Are you sure you want to change the base?
Sapphire - Linh H. #127
Conversation
… the task.py module.
… track migration versions.
… format HTTP responses into dictionaries.
…onse if title, description, or completed_at request is missing.
…routes.py module.
… defined within the app routes.py module.
… of is_complete record in response body.
…reference from_dict helper function.
…utes.py module) to include 'task' in response body.
…pletions in app model task.py module.
…per_functions.py module.
…s in which that function was called within the task_routes.py module.
…del helper funciton is called within the goal_routes.py module.
… within app dunder init module.
… the test_wave_05.py module.
…in the test_wave_05.py module.
…ion in test_wave_05.py module.
…ton in test_wave_05.py module.
…oal function in goal_routes.py module.
…tion in test_wave_06.py module.
…kip decorator commented out.
…nd task_routes.py modules.
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.
Wonderful work, Linh! 🎉
Your routes are RESTful and your model classes look efficient and clean! You seem to have a great understanding of HTTP codes and wrangling your response into the desired shape of the tests. Your one-to-many goals to tasks relationship is flawless, and I'm obsessed with the detail and frequency of your commit AND flask db migrate messages! Great job all around. ⭐
This project is a well-deserved Green. 🟢 Please let me know if you have any questions on the comments below.
from .task_routes import tasks_bp | ||
app.register_blueprint(tasks_bp) | ||
|
||
from .goal_routes import goals_bp | ||
app.register_blueprint(goals_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.
Beautiful imports in your app init! 🎉
@@ -1 +0,0 @@ | |||
from flask import Blueprint |
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.
Nice call creating two different routes files for our respective models -- it keeps both goal_routes.py
and task_routes.py
clean and short!
@@ -0,0 +1,30 @@ | |||
"""Added goal_id attribute to connect to goal table |
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.
Nice job remembering to add a message to your flask db migrate -m "message"
! ✨
def test_update_goal(client, one_goal): | ||
raise Exception("Complete test") | ||
#raise Exception("Complete test") | ||
|
||
# Act | ||
# ---- Complete Act Here ---- | ||
response = client.put("/goals/1", json={"title": "Updated Goal Title"}) | ||
response_body = response.get_json() | ||
|
||
# Assert | ||
# ---- Complete Assertions Here ---- | ||
# assertion 1 goes here | ||
assert response.status_code == 200 | ||
# assertion 2 goes here | ||
assert "goal" in response_body | ||
# assertion 3 goes here | ||
assert response_body == { | ||
"goal": { | ||
"id": 1, | ||
"title": "Updated Goal 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.
Awesome set of assertions! ❤️🔥
db.session.add(new_goal) | ||
db.session.commit() |
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 job using db.session.<method-name>.
Session gives us access to the following:
db
is our app’s instance of SQLAlchemy.session
represents our active database connection.- By referencing
db.session
we can use SQLAlchemy’s methods to perform tasks like committing a change to a model, storing a new record of a model, and deleting a record.
By referencing db.session.add()
you are able to use the SQLAlchemy method to store a new record of the Goal model. ⭐
# _______________ | ||
# | | | ||
# | Thank | | ||
# | you for | | ||
# | reviewing | | ||
# | my code! | | ||
# |_____________| | ||
# || | ||
# (\__/)|| | ||
# (•ㅅ•) || | ||
# / >|| |
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.
Wait, this is so cute 😭 TY for showing up!!
goal_id = db.Column(db.Integer, db.ForeignKey("goal.goal_id"), nullable=True) | ||
goal = db.relationship("Goal", back_populates="tasks") |
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.
Awesome! Beautiful sync up!
Fun fact: the default value for nullable is True
so we don't need to explicitly add it 😊
def to_dict(self): | ||
if self.completed_at: | ||
return dict( | ||
id=self.task_id, | ||
title=self.title, | ||
description=self.description, | ||
is_complete=True | ||
) | ||
|
||
if self.goal_id and not self.completed_at: | ||
return dict( | ||
id=self.task_id, | ||
goal_id=self.goal_id, | ||
title=self.title, | ||
description=self.description, | ||
is_complete=False | ||
) | ||
else: | ||
return dict( | ||
id=self.task_id, | ||
title=self.title, | ||
description=self.description, | ||
is_complete=False | ||
) |
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.
This is a great place to DRY our code! Remember that the pipe operator |
can merge two dictionaries together, so we could shorten the above to:
def to_dict(self):
base_goal_dict = {
"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": True
}
if self.completed_at:
return base_goal_dict
else:
base_goal_dict["is_complete"] = False
if self.goal_id:
return base_goal_dict | {"goal_id": self.goal_id, }
else:
return base_goal_dict
@classmethod | ||
def from_dict(cls, task_data): | ||
new_task = Task( | ||
title=task_data["title"], | ||
description=task_data["description"] | ||
) | ||
return new_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.
Awesome from_dict
instance method!
task.completed_at = datetime.utcnow() | ||
db.session.commit() | ||
|
||
slack_bot_message(f"Someone just completed the task {task.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.
So clean! So clear! Spectacular! 🌟
No description provided.