Skip to content

Cedar-Rebeca Muniz#80

Open
rebecamuniz wants to merge 9 commits intoAda-C16:masterfrom
rebecamuniz:master
Open

Cedar-Rebeca Muniz#80
rebecamuniz wants to merge 9 commits intoAda-C16:masterfrom
rebecamuniz:master

Conversation

@rebecamuniz
Copy link

No description provided.

Comment on lines +107 to +108
slack_url = os.environ.get("SLACK_URL")
channel_id = os.environ.get("CHANNEL_ID")

Choose a reason for hiding this comment

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

CHANNEL_ID and SLACK_URL do not need to be secret. Consider saving them as a constant rather than in the .env

Comment on lines +106 to +110
slack_key = os.environ.get("SLACK_KEY")
slack_url = os.environ.get("SLACK_URL")
channel_id = os.environ.get("CHANNEL_ID")
requests.post(slack_url, headers= {'Authorization': f"Bearer {slack_key}"}, \
data= {'channel' : f"{channel_id}", 'text' : f"Someone just completed the task My Beautiful Task"})

Choose a reason for hiding this comment

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

Great work implementing this functionality. Consider encapsulating in a helper function to enhance readability and flexibility (You may want to use this function when someone updates a task, for instance).

Comment on lines +88 to +90
task = Task.query.get(task_id)
if task is None:
return jsonify(None), 404

Choose a reason for hiding this comment

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

Here is another place you can use the helper function get_task_from_id

Copy link

@beccaelenzil beccaelenzil 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 complex Flask project. You've made good use of helper function and instance methods. I've left a few inline comments on small ways to consider refactoring. Please let me know if you have any questions. Nice work!

"title": self.title,
}

def task_list(self):

Choose a reason for hiding this comment

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

Nice work encapsulating this functionality in an instance method.

Comment on lines +18 to +20
def get_task_from_id(task_id):
valid_int(task_id, "task_id")
return Task.query.get_or_404(task_id, description="{task not found}")

Choose a reason for hiding this comment

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

Consider implementing a similar method for goals

Comment on lines +26 to +30
if "title" not in request_body or "description" not in request_body\
or "completed_at" not in request_body:
return jsonify({"details": "Invalid data"}), 400

new_task = Task(title=request_body["title"],

Choose a reason for hiding this comment

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

Consider encapsulating this functionality in a helper method that either aborts for invalid data or returns the new_task if the request body is valid

Comment on lines +44 to +47
task = Task.query.get(task_id)

if task is None:
return jsonify(None), 404

Choose a reason for hiding this comment

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

To DRY up your code, you could use the get_task_from_id helper function here.

elif sort == "desc":
query = query.order_by(Task.title.desc())

query = query.all() # Final query

Choose a reason for hiding this comment

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

Consider naming query tasks to enhance readability.

Suggested change
query = query.all() # Final query
tasks = query.all() # Final query
Suggested change
query = query.all() # Final query
query = query.all() # Final query

title = db.Column(db.String)
description = db.Column(db.String)
completed_at = db.Column(db.DateTime, nullable =True)
is_complete = db.Column(db.Boolean)

Choose a reason for hiding this comment

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

is_complete should not be a separate attribute. is_complete us False when completed_at is None and True when completed_at has a value as you calculated below on line 20 (nice work there!). The danger in adding is_complete as another attribute on the task model is that we could store data that is inconsistent

return {
"id": goal.goal_id,
"title": goal.title,
"tasks": goal.task_list()

Choose a reason for hiding this comment

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

Great use of an instance method!

"title": "Updated Goal Title"
}
}
goal = Goal.query.get(1)

Choose a reason for hiding this comment

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

Nice work including the test that queries the database an make sure the change has been persisted.

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