-
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
Zoisite - Jessica #111
base: main
Are you sure you want to change the base?
Zoisite - Jessica #111
Conversation
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 talked a bit about your project, Jessica and I continue to be impressed by everything you have done here! You should be very proud of what you've accomplished! I added a few comments here or there but overall it's so strong!
"title": self.title, | ||
} | ||
if tasks: | ||
goal_dict["tasks"] = [task.to_json() for task in self.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.
Great use of a list comprehension here!
class Goal(db.Model): | ||
goal_id = db.Column(db.Integer, primary_key=True) | ||
__tablename__ = 'goals' |
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.
Just a reminder that we should have an empty init.py within our model directory as well!
title = db.Column(db.String, nullable=False) | ||
description = db.Column(db.Text, nullable=False) | ||
completed_at = db.Column(db.DateTime(timezone=True), nullable=True) | ||
goal_id = db.Column(db.Integer, db.ForeignKey("goals.goal_id"), nullable=True) |
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.
the default for nullable is True, so we do not need to specify that here!
"id": self.task_id, | ||
"title": self.title, | ||
"description": self.description, | ||
"is_complete": self.completed_at is not None |
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 converting the completed_at attribute to a conditional!
@@ -0,0 +1,42 @@ | |||
from .helper_functions import create_instance, get_all_instances, get_one_instance, get_one_instance, delete_instance, update_instance, add_tasks_to_model |
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 separating out your helper functions! And great job with creating the helper functions themselves! It truly helps streamline the routes!
instance = cls.from_json(instance_info) | ||
except KeyError as err: | ||
error_message = {"details": f"KeyError invalid {cls.__name__} data, missing key: {err}"} | ||
return make_response(error_message, HTTPStatus.BAD_REQUEST) |
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 error handling!
return make_response({cls_type: instance}, status_code) | ||
|
||
|
||
def generate_error_message(cls, id): |
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.
My one concern about this method is that it only describes one potential error. This particular method generates a message that always says the id is not found, which doesn't describe every error that could potentially pop up (Invalid input, missing information, etc). With that in mind, it might be better to simply create the error message in the moment as opposed to in a helper method.
elif sort_order == "description_desc": | ||
instances = instances.order_by(desc(cls.description)) | ||
|
||
instance = [instance.to_json() for instance in instances] |
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 list comprehension!
|
||
db.session.commit() | ||
|
||
return make_response({"id": goal_id, "task_ids": task_ids}, HTTPStatus.OK) |
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.
All in all, these are some very sleek helper functions here!
|
||
@tasks_bp.route("/<task_id>/mark_incomplete", methods=['PATCH']) | ||
def mark_task_incomplete(task_id): | ||
return make_instance_incomplete(Task, task_id) |
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.
👍
No description provided.