Conversation
…ls from app.models
…el in task.py and defines Goal model in goal.py.
…ask and Goal instances.
…te a one to many relationship between the two models.
…e method to Task model that generates a JSON with goal_id included in response body, adds response that posts a message to Slack task-notification channel on the task-list-api workspace when user completes a task and sends a patch request to tasks/<task_id> in routes.py.
…py and goal.py and refactors code in routes.py to use from_json instance methods in goal and task endpoints for PUT request.
…search queries by id and sorting requests.
…plete(task_id) funcion in routes.py.
… in def mark_complete function in routes.py.
CheezItMan
left a comment
There was a problem hiding this comment.
Overall nice work Ruthie. I left a few comments, mostly minor things that you seem to have changed just prior to submitting (which caused tests to fail). Let me know what questions you have and I'm happy to go over them.
| def from_json(request_dict): | ||
| # Converts JSON into a new instance of Task | ||
| new_goal = Goal( | ||
| title = request_dict["title"] | ||
| ) | ||
|
|
||
| return new_goal No newline at end of file |
There was a problem hiding this comment.
Since this method creates a new Goal, I suggest making it a class method
| def from_json(request_dict): | |
| # Converts JSON into a new instance of Task | |
| new_goal = Goal( | |
| title = request_dict["title"] | |
| ) | |
| return new_goal | |
| @classmethod | |
| def from_json(cls, request_dict): | |
| # Converts JSON into a new instance of Task | |
| new_goal = Goal( | |
| title = request_dict["title"] | |
| ) | |
| return new_goal |
| 'is_complete' : completed | ||
| } | ||
|
|
||
| def create_json_with_goal_id(self): |
There was a problem hiding this comment.
You could make this helper a part of the above create_json function using an if statement to include goal if the goal field exists.
| 'is_complete' : completed | ||
| } | ||
|
|
||
| def from_json(request_dict): |
There was a problem hiding this comment.
similarly I suggest making it a class method. This way you don't have to make an instance of Task before getting a new instance.
task = Task.from_json({ "title": "blah", "description": "...", "is_complete": True })
| def from_json(request_dict): | |
| @classmethod | |
| def from_json(cls, request_dict): |
| SLACK_TOKEN = os.environ["SLACK_API_TOKEN"] | ||
| slack_channel = "task-notifications" | ||
| slack_icon_url = "https://slack.com/api/chat.postMessage" | ||
| text = f"Someone just completed the task {task.title}" | ||
|
|
||
| response = requests.post('https://slack.com/api/chat.postMessage', { | ||
| 'token': slack_token, | ||
| 'channel': slack_channel, | ||
| 'text': text, | ||
| 'icon_url': slack_icon_url | ||
| }).json() |
There was a problem hiding this comment.
Just a note that this would make a great helper function.
|
|
||
| response = requests.post('https://slack.com/api/chat.postMessage', { | ||
| 'token': slack_token, | ||
| 'channel': slack_channel, |
There was a problem hiding this comment.
You forgot to capitalize this. So some tests are failing.
| 'channel': slack_channel, | |
| 'channel': SLACK_TOKEN, |
| @@ -0,0 +1,37 @@ | |||
|
|
|||
There was a problem hiding this comment.
I like the idea of a separate file for utility functions, but since you're not using it, take it out of git.
| #This fixture gets called in tests for returning goals sorted by title | ||
| @pytest.fixture | ||
| def three_goals(app): |
There was a problem hiding this comment.
You should probably also have a fixture for 3 tasks.
It's great however that you added your own fixture.
| @@ -0,0 +1,69 @@ | |||
| # #test to get tasks sorted by id | |||
There was a problem hiding this comment.
I just want to note that after I uncommented this code, the tests passed...
|
|
||
| ordered_query = Task.query.order_by(Task.title.desc()) | ||
|
|
||
| elif sort_query == "id": |
No description provided.