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

Scissors - Araceli #68

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

Conversation

aracelim1234
Copy link

No description provided.

Comment on lines +9 to +13
def to_json(self):
return {
"id": self.goal_id,
"title": self.title,
}

Choose a reason for hiding this comment

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

This is a great helper function, but I suspect it wasn't working as you expected because the tab level is outside of the class.

Comment on lines +14 to +29
def to_dict(self):
return {
"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": bool(self.completed_at)
}

def to_dict_goal(self):
return {
"id": self.task_id,
"goal_id": self.goal_id,
"title": self.title,
"description": self.description,
"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.

Same issue as Goal, but these are great helper functions!


return jsonify(response), 400

else:

Choose a reason for hiding this comment

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

It's not necessary to include this else statement. If the if statement passes, the function will return and the code after this point will not run.

Comment on lines +44 to +51
if sort_query == "asc":
tasks = Task.query.order_by(Task.title.asc())

elif sort_query == "desc":
tasks = Task.query.order_by(Task.title.desc())

else:
tasks = Task.query.all()

Choose a reason for hiding this comment

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

Nice!

return jsonify(tasks_response), 200


@tasks_bp.route("/<task_id>", methods=["GET", "PUT", "DELETE"], strict_slashes=False)

Choose a reason for hiding this comment

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

In the "" route above (lines 17 & 37), the methods are split into separate functions, while here they're combined into the same method. Both ways are fine, but for readability, I recommend following the same patterns throughout your code.


if request.method == "GET":
if task is None:
return make_response(f"404 Not Found", 404)

Choose a reason for hiding this comment

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

Having an error message is great, but I would suggest having a more meaningful error message, something like 'Task with ID X not found'. Also this test is something you are doing for all of the methods - it could be moved up before the checks for the type of method so it only needs to be done once.

else:
one_task = to_dict(task)

return {"task": one_task}

Choose a reason for hiding this comment

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

For readability I recommend using the same format to create your responses throughout your project. Lines 56, 66 and 71 all use a different format. Flask handles all of these formats gracefully, but having multiple formats can make it seem that different things are happening when in fact they are all more or less the same. Also, I recommend explicitly setting a status code everywhere so that you can accurately predict what your API will do in each situation.

Comment on lines +82 to +87
updated_task = {
"id": task.task_id,
"title": task.title,
"description": task.description,
"is_complete": bool(task.completed_at)
}

Choose a reason for hiding this comment

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

This would be a great place to use use the to_dict helper function.

return make_response(f"404 Not Found", 404)

else:
one_task = to_dict(task)

Choose a reason for hiding this comment

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

Here is where the last test fails - if the task has a valid goal_id, it should include the goal_id in the json output. One way to handle this is:

if task.goal_id:
    one_task = to_dict_goal(task)
else:
    one_task = to_dict(task)

# for task in tasks:
# tasks_list.append(to_dict_goal(task))

task_list = [to_dict_goal(task) for task in tasks]

Choose a reason for hiding this comment

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

Nice list comprehension!

@jbieniosek
Copy link

Great work on this project, you hit all the learning goals. Nice work with your to_json & to_dict helper functions!

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