Skip to content
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

Scissors - Melissa Nguyen #62

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

Conversation

melissa-nguyen
Copy link

No description provided.

… two endpoints, the first endpoint creates a task and retrieves all tasks, the second endpoint creates, modifies and deletes a specific task
…ask titles by ascending, descending or default sort based on sort query param
…s_complete depending on whether or not the task has been completed
… task list api. Slack message bot helper function identifies and returns which tasks have been completed
…etrieves all goals in database. Second endpoint gets, puts and deletes a singular goal
…st. Endpoint retrives list of tasks associated with a specific goal and posts tasks associated with a specific goal
Copy link

@beccaelenzil beccaelenzil left a comment

Choose a reason for hiding this comment

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

Good work on your first Flask project. Your code is clear and logical. I've left some inline comments on ways you could consider refactoring. My comments are mainly focused on places where you could write instance methods to DRY up your code, and ways to enhance readability. Please let me know if you have any questions. Keep up the hard work.

Comment on lines +27 to +32
"task": {
"id": new_task.task_id,
"title": new_task.title,
"description": new_task.description,
"is_complete": new_task.task_completed()
}

Choose a reason for hiding this comment

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

Notice that this code is repeated many places throughout your routes.py. Consider moving the logic to build a json response into a instance method on the task model that you could then call here with something like new_task.to_json().

db.session.commit()
return jsonify({"details": f'Task {task.task_id} "{task.title}" successfully deleted'}), 200

def slack_message_bot(task):

Choose a reason for hiding this comment

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

Great work making a helper function.

Comment on lines +151 to +158
return jsonify({
"task": {
"id": task.task_id,
"title": task.title,
"description": task.description,
"is_complete": task.task_completed()
}
}), 200

Choose a reason for hiding this comment

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

Sometimes your code uses make_response and sometimes it doesn't. Consistently using it (or not) can add readability to your code.

Comment on lines +173 to +188
return make_response({
"goal": {
"id": new_goal.goal_id,
"title": new_goal.title,
}
}, 201)

elif request.method == "GET":
goals = Goal.query.all()
goals_response = []

for goal in goals:
goals_response.append({
"id": goal.goal_id,
"title": goal.title
})

Choose a reason for hiding this comment

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

Just as with the task response body, note that the goal response body is used a few times. Consider moving this logic to an instance method on the goal model that returns the needed dictionary, and then calling it where needed with something like goal.to_json()

Comment on lines +145 to +146
if task == None:
return make_response(), 404

Choose a reason for hiding this comment

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

You have this code 3 places. Consider making a helper function, or even using get_or_404 https://flask-sqlalchemy.palletsprojects.com/en/2.x/api/#flask_sqlalchemy.BaseQuery.get_or_404.

Also, this is a very minor note, but I just learned this cohort that the python-y way to say if task == None is if not task

Comment on lines +167 to +171
else:
new_goal = Goal(title=request_body["title"])

db.session.add(new_goal)
db.session.commit()

Choose a reason for hiding this comment

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

Minor note: this does not need to be nested in an else. Reducing indentation can increase readability.

Comment on lines +236 to +238
for task_id in request_body["task_ids"]:
task = Task.query.get(task_id)
task.goal_id = goal.goal_id

Choose a reason for hiding this comment

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

Nice work writing this logic to make the relationship between goals and tasks.

completed_at = db.Column(db.DateTime, nullable=True)
goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'), nullable=True)

def task_completed(self):

Choose a reason for hiding this comment

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

Nice work using this helper function.

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