Conversation
spitsfire
left a comment
There was a problem hiding this comment.
good job, Bahareh! One thing to consider is staying consistent as you can with your route responses. Sometimes you send through just a dictionary, sometimes you jsonify the dictionary, sometimes the status code isn't there, etc.
Double check your routes so that they are formatted consistently and that they have predictable behavior.
| def to_json(self): | ||
| if self.completed_at: | ||
| is_completed=True | ||
| else: | ||
| is_completed=False | ||
| task_dict= { | ||
| "id": self.task_id, | ||
| "title": self.title, | ||
| "description": self.description, | ||
| "is_complete": is_completed, | ||
| } | ||
| if self.goal_id: | ||
| task_dict["goal_id"] = self.goal_id | ||
| return task_dict | ||
|
|
||
| def to_json_without_des(self): | ||
| if self.completed_at: | ||
| is_completed=True | ||
| else: | ||
| is_completed=False | ||
| return { | ||
| "id": self.task_id, | ||
| "title": self.title, | ||
| "description": "", | ||
| "is_complete": is_completed, | ||
| } |
There was a problem hiding this comment.
👍 ohhh cool! Interesting way to separate out which tasks need which attributes! I wonder if we could combine these two methods back together with an if statement, though. Something to think about!
| task_list_bp = Blueprint("task_list", __name__,url_prefix="/tasks") | ||
| goal_list_bp = Blueprint("goal_list", __name__,url_prefix="/goals") |
There was a problem hiding this comment.
one thing we could do to help with too much in one file is by separating these two blueprints out into their own files. This can help bigger teams work on different tasks in a project without stepping on each other's toes.
| def validate_task(task_id): | ||
| try: | ||
| task_id = int(task_id) | ||
| except: | ||
| abort(make_response({"message":f"task {task_id} invalid"}, 400)) | ||
|
|
||
| task = Task.query.get(task_id) | ||
|
|
||
| if not task: | ||
| abort(make_response({"message":f"task {task_id} not found"}, 404)) | ||
|
|
||
| return task |
There was a problem hiding this comment.
we could put this in a separate file to keep our routes file tidier
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
be careful with too much blank lines! it can make code harder to read
|
|
||
|
|
||
|
|
| new_goal = Goal(title=request_body["title"], | ||
| ) |
There was a problem hiding this comment.
| new_goal = Goal(title=request_body["title"], | |
| ) | |
| new_goal = Goal(title=request_body["title"]) |
| return{"goal": { | ||
| "id": goal.goal_id, | ||
| "title": goal.title, | ||
| }} |
| task_list = [] | ||
|
|
||
| for task in tasks: | ||
| task_list.append(task.to_json()) | ||
| return make_response(jsonify({ | ||
| "id": goal.goal_id, | ||
| "title": goal.title, | ||
| "tasks": task_list |
There was a problem hiding this comment.
just as we made a to_json method for tasks, we could do the same for goals
|
|
||
|
|
||
|
|
|
|
||
|
|
||
| #Post tasks to a goal | ||
| @goal_list_bp.route("/<goal_id>/tasks", methods=["POST"]) |
No description provided.