Skip to content

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

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

Accelerate - Cloudy Lopez #3

wants to merge 11 commits into from

Conversation

OhCloud
Copy link

@OhCloud OhCloud commented Jun 11, 2021

wave one - passing some tests - not complete

Comment on lines +4 to +5
from sqlalchemy import ForeignKey, update
from sqlalchemy.orm import relationship
Copy link

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

Suggested change
from sqlalchemy import ForeignKey, update
from sqlalchemy.orm import relationship

@@ -1,6 +1,11 @@
from flask import current_app
from sqlalchemy.orm import backref
Copy link

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

Suggested change
from sqlalchemy.orm import backref

Comment on lines +3 to +4
from sqlalchemy import ForeignKey, update
from sqlalchemy.orm import relationship
Copy link

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

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

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

Comment on lines +69 to +72
tasks = []

for item in goal.tasks:
tasks.append(item)
Copy link

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

Suggested change
tasks = []
for item in goal.tasks:
tasks.append(item)
tasks = []

selected_goal = {"goal":
{"id": goal.goal_id,
"title": goal.title,
"tasks": tasks
Copy link

Choose a reason for hiding this comment

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

remove this line

Suggested change
"tasks": tasks

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

Choose a reason for hiding this comment

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

💃🏽

Comment on lines +170 to +175
"task": {
"id": new_task.task_id,
"title": new_task.title,
"description": new_task.description,
"is_complete": completed_at
}}, 201)
Copy link

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?

Comment on lines +185 to +186
if not sort:
tasks = Task.query.all()
Copy link

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

Comment on lines +212 to +214
task = Task.query.get(task_id)
if task is None:
return make_response("No matching task found", 404)
Copy link

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!

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