-
Notifications
You must be signed in to change notification settings - Fork 128
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
Ruby - Rediet Medhane #14
base: main
Are you sure you want to change the base?
Conversation
…ate_task helper function
…invalid data post requests
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.
Excellent job! There are some comments below on places to make the code cleaner/simpler. Great job!
from .routes import task_bp, goal_bp | ||
app.register_blueprint(task_bp) | ||
app.register_blueprint(goal_bp) |
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.
Excellent!
def to_dict(self): | ||
#tasks = [task.to_dict() for task in self.tasks] | ||
return { | ||
"id" : self.goal_id, | ||
"title" : self.title | ||
|
||
} | ||
def to_dict_with_tasks(self): | ||
tasks = [task.to_dict_with_goal() for task in self.tasks] | ||
return { | ||
"id" : self.goal_id, | ||
"title" : self.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.
Yay, helper methods! However, these two are very, very similar. For the one with tasks, you can call the regular to_dict
and then just add the lists of tasks to the dictionary that's returned.
def to_dict(self): | ||
if self.completed_at: | ||
is_complete = True | ||
else: | ||
is_complete = False | ||
return { | ||
"id" : self.task_id, | ||
"title" : self.title, | ||
"description" : self.description, | ||
"is_complete" : is_complete | ||
} | ||
|
||
def to_dict_with_goal(self): | ||
if self.completed_at: | ||
is_complete = True | ||
else: | ||
is_complete = False | ||
return { | ||
"id" : self.task_id, | ||
"title" : self.title, | ||
"description" : self.description, | ||
"is_complete" : is_complete, | ||
"goal_id": self.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.
Yay, helper methods! Again, these are very, very similar. Only one is needed. The to_dict
method can check to see if the task has a goal_id. If it does, add it to the dictionary.
def test_get_task_not_found(client): | ||
# Act | ||
response = client.get("/tasks/1") | ||
response_body = response.get_json() | ||
|
||
# Assert | ||
assert response.status_code == 404 | ||
assert not 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.
Excellent!
@@ -130,14 +126,10 @@ def test_update_task_not_found(client): | |||
|
|||
# Assert | |||
assert response.status_code == 404 | |||
assert not 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.
Excellent!
|
||
@goal_bp.route("/<goal_id>", methods = ["GET"]) | ||
def get_goal_by_id(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.
Excellent!
|
||
@goal_bp.route("/<goal_id>", methods = ["PUT"]) | ||
def update_one_goal(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.
Excellent!
|
||
@goal_bp.route("/<goal_id>", methods = ["DELETE"]) | ||
def delete_one_goal(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.
Excellent!
tasks.append(validate_item(Task, task_id)) | ||
|
||
goal.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.
If the goal already had tasks attached to it, this would get rid of them. It would be better to append the tasks.
|
||
@goal_bp.route("/<goal_id>/tasks", methods = ["GET"]) | ||
def get_tasks_of_one_goal(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.
Excellent!
No description provided.