Conversation
jbieniosek
left a comment
There was a problem hiding this comment.
Great work on this project Melinda! You hit all of the learning goals. My only recommendation is to look for additional places to use helper functions to DRY your code. This project is green!
| list = [] | ||
| for task in self.tasks: | ||
| list.append(task.to_dict) |
There was a problem hiding this comment.
I think there's a small bug here:
| list = [] | |
| for task in self.tasks: | |
| list.append(task.to_dict) | |
| list = [] | |
| for task in self.tasks: | |
| list.append(task.to_dict()) |
This loop is also a great candidate for a list comprehension similar to line 28:
| list = [] | |
| for task in self.tasks: | |
| list.append(task.to_dict) | |
| list = [task.to_dict() for task in self.tasks] |
|
|
||
| } | ||
|
|
||
| def check_for_complete_task(self): |
|
|
||
|
|
||
| tasks_bp = Blueprint("tasks_bp", __name__, url_prefix="/tasks") | ||
| def valid_int(number,parameter_type): |
| tasks_response.append( | ||
| { | ||
| "description": task.description, | ||
| "id": task.id, | ||
| "is_complete": False if has_complete == None else has_complete, | ||
| "title": task.title, | ||
| } | ||
| ) |
There was a problem hiding this comment.
This works, I recommend using the to_dict helper function to DRY this section:
| tasks_response.append( | |
| { | |
| "description": task.description, | |
| "id": task.id, | |
| "is_complete": False if has_complete == None else has_complete, | |
| "title": task.title, | |
| } | |
| ) | |
| tasks_response.append(task.to_dict()) |
| @tasks_bp.route("/<task_id>", methods=["GET", "PUT", "DELETE"]) | ||
| def handle_one_task(task_id): | ||
| valid_int(task_id,"task_id") | ||
| task = Task.query.get_or_404(task_id) |
| json_response = jsonify(response) | ||
| return make_response(json_response, 200) | ||
|
|
||
| def slack_bot(title): |
|
|
||
| #Wave 3 | ||
| @tasks_bp.route("/<task_id>/mark_complete", methods=["PATCH"]) | ||
| def handle_completed_task(task_id): |
There was a problem hiding this comment.
Great work, the use of helper functions and get_or_404 in this function really streamline the code!
| tasks = db.relationship("Task", backref="goal", lazy=True) | ||
|
|
||
| def to_dict(self): | ||
| if self.list_of_task_ids(): |
There was a problem hiding this comment.
Storing this result of function call here in a variable (ie task_ids = self.list_of_task_ids()) and then testing could create a slight optimization, because then the variable could be used on line 19 ("task_ids": task_ids) instead of calling the function again.
| goal.title = form_data["title"] | ||
|
|
||
| db.session.commit() | ||
| return jsonify({"goal":{"goal_id":goal.id, "title":goal.title}}),200 |
There was a problem hiding this comment.
| return jsonify({"goal":{"goal_id":goal.id, "title":goal.title}}),200 | |
| return jsonify({"goal":goal.to_dict()}),200 |
|
|
||
| #Wave # 6 | ||
| @goals_bp.route("/<goal_id>/tasks", methods=["POST"]) | ||
| def post_task_ids_to_goal(goal_id): |
No description provided.