Open
Conversation
… case, passed all tests.
…and passed all tests
…s and passed tests
…te if its not None.
…te if its not None.
CheezItMan
reviewed
Dec 3, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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 |
Comment on lines
+93
to
+99
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
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 | ||
| } |
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() |
|
|
||
| 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 |
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 |
| }}), 200 | ||
|
|
||
| #UPDATE Routes (Wave 3: PATCH Routes) | ||
| @tasks_bp.route("/<task_id>/<mark>", methods=["PATCH"]) |
There was a problem hiding this comment.
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.