-
Notifications
You must be signed in to change notification settings - Fork 15
accelerate - lilia #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
from app.models.task import Task | ||
from app.models.goal import Goal | ||
|
||
db.init_app(app) | ||
migrate.init_app(app, db) | ||
from app.models.task import Task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you already imported this
from app.models.task import Task |
from app.models.task import Task | ||
from app.models.goal import Goal | ||
|
||
db.init_app(app) | ||
migrate.init_app(app, db) | ||
from app.models.task import Task | ||
from .routes import tasks_bp | ||
app.register_blueprint(tasks_bp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure to also import and register goals_bp
class Task(db.Model): | ||
task_id = db.Column(db.Integer, primary_key=True) | ||
task_id = db.Column(db.Integer, primary_key=True, autoincrement=True) | ||
title = db.Column(db.String) | ||
description = db.Column(db.String) | ||
completed_at = db.Column(db.DateTime, nullable=True, default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good for task.py
go ahead and do the same for goal.py
|
||
tasks_bp = Blueprint("tasks", __name__, url_prefix="/tasks") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the same for goals_bp
"id": task.task_id, | ||
"title": task.title, | ||
"description": task.description, | ||
"completed_at": bool(task.completed_at) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be "is_complete"
"completed_at": bool(task.completed_at) | |
"is_complete": bool(task.completed_at) |
def handle_tasks(): | ||
if request.method == "POST": | ||
request_body = request.get_json() | ||
if "title" not in request_body or "description" not in request_body or "completed_at" not in request_body: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good check
|
||
new_task = Task( | ||
id=request_body["id"], | ||
title=request_body["title"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need id here because it is created for you
new_task.completed_at = False | ||
else: | ||
new_task.completed_at = True | ||
return jsonify(new_task), 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this response, you want to make sure you are adding "task" before the response. So it should look like
return jsonify(new_task), 200 | |
return jsonify({"task":new_task)}, 200 |
id=request_body["id"], | ||
title=request_body["title"], | ||
description=request_body["description"], | ||
completed_at=request_body["completed_at"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove completed at here and do your check then add it
completed_at=request_body["completed_at"] | |
if new_task.completed_at == None: | ||
new_task.completed_at = False | ||
else: | ||
new_task.completed_at = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this above line 23 and edit it to add to the Task call. For example:
if new_task.completed_at == None: | |
new_task.completed_at = False | |
else: | |
new_task.completed_at = True | |
if "completed_at" in request_body: | |
new_task.completed_at = request_body["completed_at"] | |
if task is None: | ||
return make_response("", 404) | ||
|
||
if request.method == "GET": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
elif request.method == "PUT": | ||
form_data = request.get_json() | ||
task.title = form_data["title"] | ||
task.description = form_data["description"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to add the same for task.completed_at
task.title = form_data["title"] | ||
task.description = form_data["description"] | ||
db.session.commit() | ||
return make_response(f"Task #{task.task_id} has been updated.", 201) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return. Similar for the return for GET method
elif request.method == "DELETE": | ||
db.session.delete(task) | ||
db.session.commit() | ||
|
||
return {"details":f"Task {task.task_id} \"{task.title}\" successfully deleted"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
No description provided.