Conversation
spitsfire
left a comment
There was a problem hiding this comment.
This looks very nice, Brittany! Some things you could consider for a future project is that functions should only do one thing. That means we could separate out each request method into its own route decorator and function, too.
Also, keep blank lines to a minimum. Sometimes spacing out chunks of code will help, but doing it too much can make it hard to read!
| from dotenv import load_dotenv | ||
| import datetime |
There was a problem hiding this comment.
since you aren't using datetime in this file, we don't need to import it. also, are you calling load_dotenv anywhere? were your environment variables able to load without it?
| from dotenv import load_dotenv | |
| import datetime | |
| from dotenv import load_dotenv | |
| load_dotenv() |
| @@ -1,6 +1,33 @@ | |||
| from types import new_class | |||
There was a problem hiding this comment.
is this being used?
| from types import new_class |
| from types import new_class | ||
| from flask import current_app | ||
| from app import db | ||
| from app.models.task import Task |
There was a problem hiding this comment.
| from app.models.task import Task |
| "title": self.title | ||
| } | ||
|
|
||
| def goal_json_object_with_tasks(self): |
| from flask import current_app | ||
| from app import db | ||
|
|
||
| from datetime import datetime |
There was a problem hiding this comment.
| from datetime import datetime |
| task = Task.query.get(task_id) | ||
|
|
||
| if task is None: | ||
| return jsonify(None), 404 |
There was a problem hiding this comment.
here we could use get_or_404() method, too!
|
|
||
| if request.method == "PATCH": | ||
|
|
||
| task = Task.query.get(task_id) | ||
|
|
||
| if task is None: | ||
| return jsonify(None), 404 | ||
|
|
||
| task.completed_at = None | ||
|
|
||
| return jsonify({"task":task.json_object()}),200 | ||
|
|
||
|
|
There was a problem hiding this comment.
careful with adding too many blank lines! it can make code harder to read
| if request.method == "PATCH": | |
| task = Task.query.get(task_id) | |
| if task is None: | |
| return jsonify(None), 404 | |
| task.completed_at = None | |
| return jsonify({"task":task.json_object()}),200 | |
| if request.method == "PATCH": | |
| task = Task.query.get(task_id) | |
| if task is None: | |
| return jsonify(None), 404 | |
| task.completed_at = None | |
| return jsonify({"task":task.json_object()}),200 |
| goal = Goal.query.get(goal_id) | ||
|
|
||
| if goal is None: | ||
| return jsonify(None), 404 |
There was a problem hiding this comment.
here we could use get_or_404() method, too!
| def goals_task(goal_id): | ||
|
|
||
| form_data = request.get_json() | ||
|
|
||
| for task_id in form_data["task_ids"]: | ||
|
|
||
| task = Task.query.get(task_id) | ||
|
|
||
| task.goal_id = goal_id | ||
|
|
||
| db.session.commit() | ||
|
|
||
| return make_response({"id": int(goal_id),"task_ids":form_data["task_ids"]}), 200 |
| goal = Goal.query.get(goal_id) | ||
| if goal is None: | ||
| return make_response("", 404) |
There was a problem hiding this comment.
here we could use get_or_404() method, too!
No description provided.