Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

mkeefer17
Copy link

No description provided.

Copy link

@spitsfire spitsfire left a 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!

Comment on lines +6 to +7
title = db.Column(db.String)
description = db.Column(db.String)

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)

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"])

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"],

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"],

Comment on lines +55 to +56
task.title = request_body["title"]
task.description = request_body["description"]

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

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})

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

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

Comment on lines +7 to +8
from dotenv import load_dotenv
load_dotenv()

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!

Suggested change
from dotenv import load_dotenv
load_dotenv()

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