-
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
Amethyst - Mazzy #119
base: main
Are you sure you want to change the base?
Amethyst - Mazzy #119
Conversation
def to_dict(self): | ||
goal_as_dict = {} | ||
goal_as_dict["id"] = self.goal_id | ||
goal_as_dict["title"] = self.title | ||
|
||
|
||
return goal_as_dict |
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.
Nice helper method function! ⭐️
description = task_data["description"] | ||
) | ||
|
||
return new_task |
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.
✨
try: | ||
new_goal = Goal(title=request_body["title"]) | ||
|
||
except: | ||
abort(make_response({ | ||
"details": "Invalid data" |
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.
Like we validated models, could we also make a general function that validates request bodies? Here's an example:
def validate_request_body(request_body, keys):
for key in keys:
if not request_body.get(key):
abort(make_response({
'Invalid Data': f'missing key: {key}'
}, 400))
return True
We can pass in the request_body
and a list of strings that are keys
and then check to see if those keys are present.
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.
Now we can have error handling and request body validation across all our routes more easily.
for goal in goals: | ||
goals_response.append( | ||
goal.to_dict() | ||
) |
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.
Nice utilization of your .to_dict()
helper method! ⭐️
for task in request_body["task_ids"]: | ||
task = validate_model(Task, task) | ||
tasks_list.append(task) | ||
task.goal_id = 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.
⭐️
for task in goal.tasks: | ||
tasks_list.append({ | ||
"id" : task.task_id, | ||
"goal_id" : task.goal_id, | ||
"title" : task.title, | ||
"description" : task.description, | ||
"is_complete" : False | ||
}) |
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.
Well done! I have a question for you, do you think that this loop and the logic within could be moved to into the Goal
class?
if sort_query == "asc": | ||
tasks = Task.query.order_by(Task.title.asc()).all() | ||
elif sort_query == "desc": | ||
tasks = Task.query.order_by(Task.title.desc()).all() | ||
else: | ||
tasks = Task.query.all() |
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.
Awesome! 💫
|
||
return jsonify(tasks_response) | ||
|
||
def validate_model(cls, model_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.
Make sure your helper functions are in a place that's easy to find
|
||
task = validate_model(Task, task_id) | ||
|
||
send_slack_message(task.title) |
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.
So, right now your route sends a message to slack saying that the task has been completed, before the task is marked complete. But what happens if your can't actually commit the change, your code will send out a false positive. You typically will want to send alerts like this after all your other logic has ran.
|
||
return make_response({ | ||
"details": f'{Task.__name__} {task_id} "{task.title}" successfully deleted' | ||
}), 200 |
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.
Well done on this project Maz, I didn't have much to comment on and that is a good thing! Keep up the good work! Really looking forward to what you create in the frontend! Please feel free to reach out if you have any questions about the feedback that I left! ✨💫🤭
No description provided.