-
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 - Jittania Smith #55
base: master
Are you sure you want to change the base?
Changes from all commits
6973a7c
85bd69c
af0d95d
7cdad2c
c2b6584
9a6f9ea
81b2989
8ae4a3b
583e9d5
ce69161
bb3eb09
1eb295b
150e67d
fd5ca7f
c731228
29a40f1
86d8571
2d3c5e5
f6b9fd8
70a0ebf
6c1880e
02e1a64
e2238c5
7ac2e98
371613e
ce158a7
4d0ba85
e824c9f
baa567f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn 'app:create_app()' |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,4 +3,20 @@ | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
class Goal(db.Model): | ||||||||||||||||||||||||||
goal_id = db.Column(db.Integer, primary_key=True) | ||||||||||||||||||||||||||
goal_id = db.Column(db.Integer, primary_key=True, autoincrement=True) | ||||||||||||||||||||||||||
title = db.Column(db.String) | ||||||||||||||||||||||||||
tasks = db.relationship('Task', backref='goal', lazy=True) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# This instance method returns a JSON dictionary of attribute values | ||||||||||||||||||||||||||
# with an optional argument if the goal has tasks assigned to it | ||||||||||||||||||||||||||
def convert_to_json(self, tasks_list=None): | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
response_body = { | ||||||||||||||||||||||||||
"id": self.goal_id, | ||||||||||||||||||||||||||
"title": self.title | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if tasks_list != None: | ||||||||||||||||||||||||||
response_body["tasks"] = tasks_list | ||||||||||||||||||||||||||
Comment on lines
+14
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By changing the code to make use of the tasks attribute you added to the Goal (line 8), you guarantee the list of tasks is always exactly what the database says it is, rather than allowing the caller of the function to specify whatever tasks they want to pass in.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I thought - but if I make this change, it causes my Wave 5/6 tests to fail? And I remember trying something like that initially and not being able to get it to work, which is why I went this route. I also had to use tasks = Task.query.filter_by(match_goal_id=goal_id) as opposed to just treating tasks like an attribute of a goal, which was not working. I'm guessing something else in my code needs to be changed as well, but I'm having trouble identifying where. In other words.....yes please, help me to understand!!!!! I'm confused on this one (also you'll probably notice I did a similar thing in my Video Store API because I was having the same issue) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're totally right! This suggestion is not enough on its own. Sorry for the confusion and thanks for the thorough response! As far as the other confusion about needing to query manually, I'm not sure. I just made a change in your code (I'll add another comment to talk about it) and it passed the tests just fine. For all of this though, I want to note that these are quite minor comments. The whole discussion we're having here can be fun and interesting to look into but none of it is very important or of high concern! |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return response_body |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,25 @@ | |
|
||
|
||
class Task(db.Model): | ||
task_id = db.Column(db.Integer, primary_key=True) | ||
task_id = db.Column(db.Integer, primary_key=True, autoincrement=True) | ||
title = db.Column(db.String) | ||
description = db.Column(db.String) | ||
completed_at = db.Column(db.DateTime, nullable=True) | ||
match_goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'),nullable=True) | ||
|
||
|
||
# This instance method checks if a task has been completed, and whether it | ||
# has a matching goal id, then returns a JSON dictionary of attribute values | ||
def convert_to_json(self): | ||
|
||
response_body = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love the helper methods! |
||
"id": self.task_id, | ||
"title": self.title, | ||
"description": self.description, | ||
"is_complete": bool(self.completed_at) | ||
} | ||
|
||
if self.match_goal_id: | ||
response_body["goal_id"] = self.match_goal_id | ||
|
||
return response_body |
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.
Love this thoughtful, handy optional param here! That said, you shouldn't actually need to ask the caller to pass these in because they are already attached to the goal. See my comment below.