-
Notifications
You must be signed in to change notification settings - Fork 15
Accelerate - Cloudy Lopez #3
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 sqlalchemy import ForeignKey, update | ||
from sqlalchemy.orm import relationship |
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 can remove these imports
from sqlalchemy import ForeignKey, update | |
from sqlalchemy.orm import relationship |
@@ -1,6 +1,11 @@ | |||
from flask import current_app | |||
from sqlalchemy.orm import backref |
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 can remove this import
from sqlalchemy.orm import backref |
from sqlalchemy import ForeignKey, update | ||
from sqlalchemy.orm import relationship |
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 can remove these imports
from sqlalchemy import ForeignKey, update | |
from sqlalchemy.orm import relationship |
|
||
@goals_bp.route("/<goal_id>", methods=["GET", "PUT", "DELETE"]) | ||
def handle_goal(goal_id): | ||
goal = Goal.query.get_or_404(goal_id) |
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 use of get_or_404
tasks = [] | ||
|
||
for item in goal.tasks: | ||
tasks.append(item) |
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 do not need to have this here. You are handling goals and tasks in the function you created handle_goal_tasks
tasks = [] | |
for item in goal.tasks: | |
tasks.append(item) | |
tasks = [] | |
selected_goal = {"goal": | ||
{"id": goal.goal_id, | ||
"title": goal.title, | ||
"tasks": 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.
remove this line
"tasks": tasks | |
elif request.method == "PUT": | ||
form_data = request.get_json() | ||
goal.title = form_data["title"] | ||
|
||
db.session.commit() | ||
|
||
committed_goal = {"goal": | ||
{"id": goal.goal_id, | ||
"title": goal.title, | ||
}} | ||
return jsonify(committed_goal), 200 | ||
|
||
elif request.method == "DELETE": | ||
db.session.delete(goal) | ||
db.session.commit() | ||
goal_response_body = { | ||
"details": | ||
f'Goal {goal.goal_id} successfully deleted' | ||
} | ||
return jsonify(goal_response_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.
💃🏽
"task": { | ||
"id": new_task.task_id, | ||
"title": new_task.title, | ||
"description": new_task.description, | ||
"is_complete": completed_at | ||
}}, 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.
Just like we talked about in the review session, how could you create a helper function instead of having to write this every time?
if not sort: | ||
tasks = Task.query.all() |
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 handled by the else line in your conditional, so you wouldn't need this check here
task = Task.query.get(task_id) | ||
if task is None: | ||
return make_response("No matching task found", 404) |
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.
use your get or 404 here that you used for goals!
wave one - passing some tests - not complete