Skip to content

TaskListProject_Cheetahs_Tapasya#118

Open
takhat wants to merge 19 commits intoAda-C18:masterfrom
takhat:master
Open

TaskListProject_Cheetahs_Tapasya#118
takhat wants to merge 19 commits intoAda-C18:masterfrom
takhat:master

Conversation

@takhat
Copy link
Copy Markdown

@takhat takhat commented Nov 10, 2022

No description provided.

Copy link
Copy Markdown

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Nice work Tapasya! You hit the learning goals here. I especially like your tests for query params. Well done. I left some minor comments, but this is a solid solution. Well done.

Comment on lines +18 to +21
try:
new_goal = Goal.from_dict(request_body)
except KeyError:
return jsonify ({"details": "Invalid data"}), 400
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work with try-except, but it would be good to provide the user information about what data is invalid.

def get_all_goals():
all_goals = Goal.query.all()

result = [item.to_dict() for item in all_goals]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice use of a list comprehension & helper method.

Comment on lines +49 to +52
try:
update_goal.title = request_body["title"]
except KeyError:
return jsonify({"msg": "Missing needed data"}), 400
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Another similar try-except block.

Comment on lines +93 to +99







Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change

Comment on lines +14 to +27
def to_dict(self):
return {
"id": self.goal_id,
"title": self.title
}

def to_dict_incl_tasks(self):
tasks = self.get_task_items()

return {
"id": self.goal_id,
"title": self.title,
"tasks": tasks
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These seem redundant

Comment on lines +36 to +41
if "sort"in request.args or "SORT" in request.args:
sort_query_val = request.args.get("sort") if "sort"in request.args else \
request.args.get("SORT")

if sort_query_val.lower() == "asc":
tasks = Task.query.order_by(Task.title).all()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work with query params.


elif sort_query_val.lower() == "desc":
tasks = Task.query.order_by(Task.title.desc()).all()
# Source: https://stackoverflow.com/questions/4186062/sqlalchemy-order-by-descending
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice documentation!

Comment on lines +61 to +79
def read_task_by_id(task_id):
task = validate_model(Task, task_id)
if task.goal_id is None:
return jsonify({"task":task.to_dict()}), 200
return jsonify({"task":task.to_dict_incl_goal_id()}), 200

#Helper function for use in READ route: read_task_by_id and UPDATE route: update_task
def validate_model(cls, id):
try:
model_id = int(id)
except:
abort(make_response(jsonify({"msg":f"invalid id: {model_id}"}), 400))

chosen_object = cls.query.get(model_id)

if not chosen_object:
abort(make_response(jsonify({"msg": f"No {cls.__name__.lower()} found with given id: {model_id}"}), 404))

return chosen_object
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great helper functions

}}), 200

#UPDATE Routes (Wave 3: PATCH Routes)
@tasks_bp.route("/<task_id>/<mark>", methods=["PATCH"])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like how you worked the "mark" into the route.

"is_complete": False}
]
#@pytest.mark.skip(reason="No way to test this feature yet")
def test_get_tasks_sorted_asc_ignore_case_SORT(client, three_tasks):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice test!

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