-
Notifications
You must be signed in to change notification settings - Fork 71
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
Scissors- Marisa M #70
base: master
Are you sure you want to change the base?
Conversation
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.
Great work on your first Flask project. Your code is clear and logical. Your consistent spacing and indentation made it a pleasure to read. Good use of instance methods on the Task and Goal model to DRY up your code. I've left a few inline comments on ways you could consider refactoring. Please let me know if you have any questions.
return self.completed_at != None | ||
|
||
|
||
def make_json(self): |
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.
Good use of a helper method. Consider DRYing up your code by building the dictionary
json =
{"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": self.is_complete()}
and conditionally adding the goal_id
like this:
if self.goal_id:
json["goal_id] = self.goal_id
and then returning {"task": json}
"id": task.task_id, | ||
"title": task.title, | ||
"description": task.description, | ||
"is_complete": task.is_complete() |
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.
We could use the task instance method here task.make_json
to DRY up the code and reduce room for errors.
}) | ||
return jsonify(tasks_response) | ||
|
||
elif request.method == "POST": |
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.
With regards to the point in separating out the functions for each route (that you noted in Learn), this way of organizing your code can increase readability by reducing indentation and making meaningful function names. For instance, if we separate out GET and POST, we might call one function def all_tasks()
and the other def create_task()
.
task = Task.query.get(task_id) | ||
|
||
if task is None: | ||
return make_response("", 404) |
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.
We could use get_or_404()
method here
https://flask-sqlalchemy.palletsprojects.com/en/2.x/api/#flask_sqlalchemy.BaseQuery.get_or_404
API_KEY = os.environ.get("API_KEY") | ||
PATH = "https://slack.com/api/chat.postMessage" | ||
query_params = { | ||
"channel": "task-notifications", | ||
"text": f"Someone just completed the task {task.title}." | ||
} | ||
task.completed_at = datetime.utcnow() | ||
db.session.commit() | ||
requests.post(PATH, data=query_params, headers={"Authorization":API_KEY}) |
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.
Consider moving this functionality into a helper function increase readability and changeability.
No description provided.