Conversation
jbieniosek
left a comment
There was a problem hiding this comment.
Fantastic work on this project Lia! I really liked your require_instance_or_404 decorator, it streamlined the code significantly. This project is green!
| "tasks": tasks | ||
| } | ||
|
|
||
| def update_from_dict(self, data): |
| "id": self.id, | ||
| "title": self.title, | ||
| "description": self.description, | ||
| "is_complete": self.check_if_completed() |
| @require_instance_or_404 | ||
| def get_task(task): | ||
| """Retrieve one stored task by id.""" | ||
| if task.goal_id: |
There was a problem hiding this comment.
This works but to simplify the code I would recommend pushing this check to the to_dict method and add the goal_id key-value pair if goal_id exists inside the to_dict function.
| mandatory_fields = ["title", "description", "completed_at"] | ||
| for field in mandatory_fields: | ||
| if field not in form_data: | ||
| return jsonify({"details": "Invalid data"}), 400 |
| from app.models.task import Task | ||
| from app.models.goal import Goal | ||
|
|
||
| def require_instance_or_404(endpoint): |
| return {"task": new_task.to_dict()}, 201 | ||
|
|
||
| @tasks_bp.route("/<task_id>", methods=["PUT"]) | ||
| @require_instance_or_404 |
There was a problem hiding this comment.
Nice work with this decorator! Setting up task as the parameter in the function makes the code in the function very streamlined!
|
|
||
| for task_id in form_data["task_ids"]: | ||
| query = Task.query.get(task_id) | ||
| if not query: |
There was a problem hiding this comment.
Very minor suggestion, query is a little confusing here as a variable name as the value being stored is a task not a query, I'd recommend something like task or current_task.
No description provided.