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

Sapphire - Monica L. #15

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

Sapphire - Monica L. #15

wants to merge 13 commits into from

Conversation

monicadjl
Copy link

No description provided.

Copy link

@tildeee tildeee left a comment

Choose a reason for hiding this comment

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

Great work on this project Monica! I'm really really really sorry this review is coming so late. I hope it's still helpful somehow.

Overall, your project implementation is great! All of the features I was expecting and looking for look good here. Your tests look good, too. Most of my feedback is around small nitpicks around code style. In addition, I encourage you to use more descriptive git commit messages-- naming which bug is being fixed is crucial!

Besides that, this is a solid API implementation and a solid project submission! You did great work here, I'm so sorry this review is so late, and please let me know any comments and questions you have.

Comment on lines +3 to +14
def validate_object(cls, object_id):
# handle invalid object id, return 400
try:
object_id = int(object_id)
except:
abort(make_response({"msg": f"{cls.__name__} {object_id} is invalid."}, 400))

obj = cls.query.get(object_id)
if obj is None:
abort(make_response({"msg": f"{cls.__name__} not found."}, 404))

return obj
Copy link

Choose a reason for hiding this comment

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

Excellent helper function!

Comment on lines +20 to +25
def tasks_to_dict(self):
return {
"id": int(self.goal_id),
"title": self.title,
"tasks": [task.to_dict() for task in self.tasks]
}
Copy link

Choose a reason for hiding this comment

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

Wonderful :D ! I think this is a really smart helper method to make, and you did it in a very neat and concise way.

Comment on lines +24 to +27
new_task = Task(title=task_data["title"],
description=task_data["description"],
completed_at=task_data["completed at"])
return task_data
Copy link

Choose a reason for hiding this comment

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

In this case, it seems like new_task isn't being used, and you're returning the input task_data... It seems like it hasn't caused any bugs so far, but if there are any bugs in the future I might check into this method.

Comment on lines +12 to +24
def validate_model_by_id(model, id):
#handle invalid task id, return 400
try:
id = int(id)
except:
abort(make_response(jsonify({"msg": f"{model.__name__}{id} is invalid."}), 400))

model_object = model.query.get(id)

if model_object is None:
abort(make_response(jsonify({"msg": "task not found"}), 404))

return model_object
Copy link

Choose a reason for hiding this comment

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

It seems like you have a more generic implementation of the same logic in helper_routes.py named validate_object, which your goal_routes file uses. I think it'd work out if this validate_model_by_id method was deleted, and instead you usedyour generic validate_object, to help keep your code DRY.

Comment on lines +51 to +56
if sorting_query == "asc":
tasks=Task.query.order_by(Task.title.asc())
elif sorting_query=="desc":
tasks=Task.query.order_by(Task.title.desc())
else:
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.

Nitpick: Consistency with spacing!

    if sorting_query == "asc":
        tasks = Task.query.order_by(Task.title.asc())
    elif sorting_query == "desc":
        tasks = Task.query.order_by(Task.title.desc())
    else:
        tasks = Task.query.all()

Comment on lines +73 to +74
get_task = Task.query.get(task_id)
task = validate_model_by_id(Task, task_id)
Copy link

Choose a reason for hiding this comment

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

In this case, you're getting the correct instance of Task that you need with task = validate_model_by_id ..., so you probably don't need get_task = ...

Comment on lines +111 to +131
print("1111111111111111111111111")
task = validate_model_by_id(Task, task_id)
print("222222222222222222222")
if task.completed_at is not None:
# The task is already complete, no need to update it
return {"task": task.to_dict()}, 200

task.completed_at = datetime.utcnow()
print("3**************************")
db.session.commit()

print("4**************************")
#integrate slack
slack_token= os.environ["SLACK_TOKEN"]
client = WebClient(token=slack_token)
result = client.chat_postMessage(channel="task-notifications",
text=f"Someone just completed the task {task.title}")
print("5**************************")

return {"task": task.to_dict()}, 200
############
Copy link

Choose a reason for hiding this comment

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

Nitpick: Feel free to delete your print statements before submission!

nullable=True)

def to_dict(self):
dictionary = { "id": self.task_id,
Copy link

Choose a reason for hiding this comment

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

Nitpick: instead of dictionary as a variable name, I think that something like task would be better.

print("4**************************")
#integrate slack
slack_token= os.environ["SLACK_TOKEN"]
client = WebClient(token=slack_token)
Copy link

Choose a reason for hiding this comment

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

Nice work using the slack_sdk!

# Assert
assert response.status_code == 200
assert "details" in response_body
assert response_body == {
"details": 'Goal 1 "Build a habit of going outside daily" successfully deleted'
"details": 'goal 1 "Build a habit of going outside daily" successfully deleted'
Copy link

Choose a reason for hiding this comment

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

I'm surprised that you changed the test to lowercase instead of changing your implementation 🤔

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