Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

accelerate - lilia #2

wants to merge 2 commits into from

Conversation

lilia-paz
Copy link

No description provided.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already imported this

Suggested change
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)
Copy link

@tgoslee tgoslee Jun 19, 2021

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

Comment on lines 5 to +9
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)
Copy link

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")

Copy link

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)
Copy link

@tgoslee tgoslee Jun 19, 2021

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"

Suggested change
"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:
Copy link

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"],
Copy link

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
Copy link

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

Suggested change
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"]
Copy link

@tgoslee tgoslee Jun 19, 2021

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

Suggested change
completed_at=request_body["completed_at"]

Comment on lines +26 to +29
if new_task.completed_at == None:
new_task.completed_at = False
else:
new_task.completed_at = True
Copy link

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:

Suggested change
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":
Copy link

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"]
Copy link

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)
Copy link

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

Comment on lines +68 to +72
elif request.method == "DELETE":
db.session.delete(task)
db.session.commit()

return {"details":f"Task {task.task_id} \"{task.title}\" successfully deleted"}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants