-
Notifications
You must be signed in to change notification settings - Fork 111
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
Shark - Thuytien Nguyen #114
base: master
Are you sure you want to change the base?
Conversation
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 job, Thuytien! One thing I noticed is that you kept your route return statements very consistent, and that's great! Predictability is key, and you did that well!
Some things to consider for the future:
- There was a lot of repeat code when turning a Task into a dictionary. We can turn that into a instance method. There were some other piece of code we could turn into methods as well.
- Some of the helper functions you made can be moved into a new file, like
helper.py
.
Other than some duplicate code, your logic was good and your return statements were very consistent!
# Use corresponding values to create the Task instance. | ||
post_dict = request.get_json() | ||
print(post_dict) |
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 you get rid of any print statements used for debugging before final submission
print(post_dict) |
description = post_dict['description'] | ||
|
||
task = Task(title=title, description=description, completed_at = 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 works just fine! we can also combine these lines, so that we aren't making new variables
title = post_dict['title'] | |
description = post_dict['description'] | |
task = Task(title=title, description=description, completed_at = completed_at) | |
task = Task( | |
title=post_dict['title'], | |
description=post_dict['description'], | |
completed_at = completed_at | |
) |
if completed_at == None: | ||
task_dict['is_complete'] = False | ||
else: | ||
task_dict['is_complete'] = True | ||
|
||
|
||
task_dict['id'] = task.id | ||
task_dict['title'] = task.title | ||
task_dict['description'] = task.description | ||
return_dict = {"task": task_dict} |
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 would make a great instance method in our Task model, like to_json
in Solar System or Flasky
for task in task_db: | ||
if task.completed_at == None: | ||
is_complete = False | ||
else: | ||
is_complete = True | ||
|
||
task_dict = {'id': task.id, | ||
'title': task.title, | ||
'description': task.description, | ||
'is_complete': is_complete} | ||
tasks_response.append(task_dict) |
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.
hmm where have we seen this before? we did it on lines 41-51 as well.
is_complete = False | ||
else: | ||
is_complete = True | ||
|
||
task_dict={} | ||
task_dict['id'] = task.id | ||
task_dict['title'] = task.title | ||
task_dict['description'] = task.description | ||
task_dict['is_complete'] = is_complete | ||
if not (task.goal_id == None): | ||
task_dict['goal_id'] = task.goal_id | ||
return_dict = {"task": task_dict} |
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.
we have the same code here again. we should definitely turn this into an instance method inside the Task model
#----------------------------------- | ||
@goals_bp.route("/<id>",methods = ["GET"]) | ||
def get_goal_by_id(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.
👍
|
||
#------------PUT Method - update goal by id--------- | ||
@goals_bp.route("/<id>", methods=["PUT"]) |
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.
👍
return jsonify(return_dict), 200 | ||
#------------remove goal by id------------ | ||
@goals_bp.route("/<id>", methods=["DELETE"]) |
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.
👍
#--------------------------------------------------- | ||
|
||
@goals_bp.route("/<goal_id>/tasks", methods=["POST"]) |
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.
👍
return jsonify(response_dict), 200 | ||
|
||
@goals_bp.route("/<goal_id>/tasks", methods=["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.
👍
Ready to submit