-
Notifications
You must be signed in to change notification settings - Fork 146
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
Marie Keefer Task List API #117
base: master
Are you sure you want to change the base?
Conversation
…asks with all Wave 1 tests passing
… routes, Waves 2 and 3 passing
…ne_goal, update_goal, delete_goal
…ses Wave 5 and 6 tests
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.
Heck yeah, Marie! I have to say, I didn't find a lot to give feedback on. I thought your code structuring was very beautiful, easy to read and understand.
I gave one or two suggestions to think about to improve readability or syntax, but that's about it! Great job!
title = db.Column(db.String) | ||
description = db.Column(db.String) |
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.
It turns out that nullable=True
is the default value for nullable. So all of the columns for Task here are currently marked as nullable. But should title or description be allowed to be NULL? (Does that make sense from a data standpoint?) Consider adding nullable=False
to those columns.
The way the project emphasized that completed_at
needs to accept NULL values may make it seem like we needed to explicitly call out that nullable should be True
, but it turns out this is the default for nullable. Instead, we should think about the other data in our model and consider whether it makes sense for any of it to be NULL. If not, we can have the database help us protect against that happening!
@@ -3,3 +3,18 @@ | |||
|
|||
class Goal(db.Model): | |||
goal_id = db.Column(db.Integer, primary_key=True) | |||
title = db.Column(db.String) |
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.
See the Task
model for more information about required attributes being given nullable=True
|
||
@classmethod | ||
def from_dict(cls, goal_data): | ||
new_goal = Goal(title=goal_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.
This works! But what if we changed the name of the model? Now this would continue creating Goal
which no longer exists, so let's take advantage of the cls
parameter. This will represent the current model, even if we change its name.
new_goal = cls(title=goal_data["title"])
|
||
@classmethod | ||
def from_dict(cls, task_data): | ||
new_task = Task(title=task_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.
new_task = cls(title=task_data["title"],
task.title = request_body["title"] | ||
task.description = request_body["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.
We could turn this into a helper method in Task
model
db.session.delete(task) | ||
db.session.commit() | ||
|
||
return make_response({"details":f"Task {task.task_id} \"{task.title}\" successfully deleted"}), 200 |
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 works! We could also do this:
return make_response({"details":f"Task {task.task_id} '{task.title}' successfully deleted"}), 200
We can take advantage of the two different sets of quotes
for task in goal.tasks: | ||
task_list.append(task.to_dict()) | ||
|
||
return make_response({"id": goal.goal_id, "title": goal.title, "tasks": task_list}) |
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.
whoops! forgot your status code!
return make_response({"id": goal.goal_id, "title": goal.title, "tasks": task_list}, 200)
db.session.delete(goal) | ||
db.session.commit() | ||
|
||
return make_response({"details":f"Goal {goal.goal_id} \"{goal.title}\" successfully deleted"}), 200 |
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 works! We could also do this:
return make_response({"details":f"Goal {goal.goal_id} '{goal.title}' successfully deleted"}), 200
We can take advantage of the two different sets of quotes
from dotenv import load_dotenv | ||
load_dotenv() |
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.
We can get rid of this since we aren't access the environmental variables in this file!
from dotenv import load_dotenv | |
load_dotenv() |
No description provided.