Conversation
yangashley
left a comment
There was a problem hiding this comment.
Nice work, Gricelda!
I left some comments about how you could refactor your code to use list comprehension and return dictionaries directly without building them up beforehand which can help make your code more concise.
Your routes look good! I added a couple of comments where you can add error handling for the PUT requests in case clients send incorrect req bodies.
For now your Task List API is a 🟡 ! If you choose to refactor and add in Waves 4 and 7 then let me know and I can re-review your project.
| new_goal = cls( | ||
| title = request_body['title'] | ||
|
|
||
| ) | ||
| return new_goal |
There was a problem hiding this comment.
I think line 31 and the paren on line 33 needs to be tabbed over to the right one more time to match the opening bracket on line 30.
You can also return the class without instantiating it and saving it to a variable like:
return cls(
title = request_body['title']
)| if not self.completed_at: | ||
| is_complete = False | ||
| else: | ||
| is_complete = True |
There was a problem hiding this comment.
Another way you could write this is within the task_dict after line 23, like:
"is_complete": True if self.completed_at else False| new_task = cls( | ||
| title = request_body['title'], | ||
| description = request_body['description'], | ||
| completed_at = request_body.get('completed_at', None) | ||
|
|
||
| ) |
There was a problem hiding this comment.
Lines 47 -51 needs to be indented one level deeper.
|
|
||
| from flask import jsonify, abort, make_response | ||
|
|
||
| class Goal(db.Model): |
|
|
||
| from flask import jsonify, abort, make_response | ||
|
|
||
| class Task(db.Model): |
| @@ -0,0 +1,104 @@ | |||
| from datetime import date | |||
| from urllib import response | |||
| @task_bp.route("", methods=["GET"]) | ||
| def get_all_tasks(): | ||
| task_response_body = [] | ||
| # tasks = Task.query.all() |
There was a problem hiding this comment.
Remove unused code so it doesn't accidentally get uncommented and execute when we don't expect it to.
| @task_bp.route("", methods=["POST"]) | ||
| def create_task(): | ||
| request_body = request.get_json() | ||
| print(request_body) |
There was a problem hiding this comment.
Remove debugging print statements when you're done with them
| one_task = Task.validate(id) | ||
| response_body = {} | ||
| response_body["task"] = one_task.to_json() | ||
|
|
||
| return jsonify(response_body), 200 |
There was a problem hiding this comment.
To make this a 2 line method, you could write the code like this too:
one_task = Task.validate(id)
return jsonify({"task": one_task.to_json()}), 200| one_task = Task.validate(id) | ||
| request_body = request.get_json() | ||
|
|
||
| one_task.update(request_body) |
There was a problem hiding this comment.
We should add error handling here in case the client sends an incorrect request body so that we can handle a potential KeyError, like you did in your POST request on lines 33-36
No description provided.