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

Ruby - Rediet Medhane #14

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Ruby - Rediet Medhane #14

wants to merge 22 commits into from

Conversation

red-med
Copy link

@red-med red-med commented May 10, 2023

No description provided.

Copy link

@nancy-harris nancy-harris left a 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!

Comment on lines +34 to +36
from .routes import task_bp, goal_bp
app.register_blueprint(task_bp)
app.register_blueprint(goal_bp)

Choose a reason for hiding this comment

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

Excellent!

Comment on lines +9 to +22
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
}

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.

Comment on lines +13 to +36
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
}

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

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

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):

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):

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):

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

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):

Choose a reason for hiding this comment

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

Excellent!

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