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.
goeunpark
left a comment
There was a problem hiding this comment.
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.
Beautiful imports in your app init! 🎉
| @@ -1 +0,0 @@ | |||
| from flask import Blueprint No newline at end of file | |||
There was a problem hiding this comment.
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.
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" | ||
| } | ||
| } |
| db.session.add(new_goal) | ||
| db.session.commit() |
There was a problem hiding this comment.
Great job using db.session.<method-name>. Session gives us access to the following:
dbis our app’s instance of SQLAlchemy.sessionrepresents our active database connection.- By referencing
db.sessionwe 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! | | ||
| # |_____________| | ||
| # || | ||
| # (\__/)|| | ||
| # (•ㅅ•) || | ||
| # / >|| No newline at end of file |
There was a problem hiding this comment.
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.
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.
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 No newline at end of file |
| task.completed_at = datetime.utcnow() | ||
| db.session.commit() | ||
|
|
||
| slack_bot_message(f"Someone just completed the task {task.title}") |
No description provided.