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

Cedar - Maria O. #91

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

Cedar - Maria O. #91

wants to merge 9 commits into from

Conversation

mobregong
Copy link

No description provided.

Copy link

@beccaelenzil beccaelenzil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this complex Flask project! You've met the learning goals around writing tests and creating relationships with SQLAlchemy. Nice work implementing instance methods. I've left a few in-line comments on ways you may consider refactoring. Please let me know if you have any questions. Nice work!

Comment on lines +15 to +22
def to_dict(self):
return {
"id": self.task_id,
"title": self.title,
"description": self.description,
# "is_complete": True if self.completed_at == True else False
"is_complete": bool(self.completed_at)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider how you could refactor this to include the goal_id when self.goal_id is not null (None), then look below for one possible solution.

dict =  {
            "id": self.task_id,
            "title": self.title,
            "description": self.description,
            # "is_complete": True if self.completed_at == True else False
            "is_complete": bool(self.completed_at)
        }
if self.goal_id:
    dict["goal_id"] = self.goal_id

return dict

"is_complete": bool(self.completed_at)
}

def is_related_to_goal(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to goal! Note how the suggested refactor above negates the need for this check.

# relationship
tasks = db.relationship("Task", backref="goal", lazy=True)

def to_dict(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work making these instance methods

goals_bp = Blueprint('goals', __name__, url_prefix='/goals')

# # Helper functions
def valid_int(id):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you have this function in goal_routes and task_routes. Consider making a separate file with shared helper functions and importing them where you need them to DRY up your code.

@goals_bp.route("", methods=["POST"], strict_slashes=False)
def create_goal():
request_body = request.get_json()
valid_goal(request_body)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of a helper function. You might consider also including the creation of the goal in valid_goal such that the function either aborts because of Invalid data or returns the goal instance.

Comment on lines +48 to +49
for goal in goal_objects:
response_list.append(goal.to_dict())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a nice place to use a list comprehension.

task_ids_list = request_body["task_ids"]

for task_id in task_ids_list:
task = Task.query.get(task_id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably double check that the task ids in the request body actually correspond to existing tasks. We can do that with a get_or_404 or a check on whether the task is None.

Also note that add_tasks_to_goal_dict does the work of creating a list of task ids. That list has already been handed in as part of the request body, so this extra work is not necessary.

@tasks_bp.route("", methods=["POST"], strict_slashes=False)
def create_task():
request_body = request.get_json()
valid_task(request_body)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like with goal, consider using valid_task to return a task instance.

"title": "Updated Goal Title"
}
}
goal = Goal.query.get(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work querying the database to make sure the change was persisted there.

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