You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ada-project-docs/wave_05.md
+19-33Lines changed: 19 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,22 +3,21 @@
3
3
## Goal
4
4
5
5
Our task list API should be able to work with an entity called `Goal`.
6
+
-`Goal`s are entities that describe a task a user wants to complete.
7
+
- They contain a title to name the goal.
6
8
7
-
Goals are entities that describe a task a user wants to complete.
8
-
9
-
They contain a title to name the goal.
10
-
11
-
Our goal for this wave is to be able to create, read, update, and delete different goals. We will create RESTful routes for these different operations.
9
+
For this wave, we want to be able to create, read, update, and delete different `Goal`s. We will create RESTful routes for these different operations.
12
10
13
11
## Writing Tests
14
12
15
-
This wave requires more test writing.
13
+
This wave requires more test writing. The tests you need to write are scaffolded in the `test_wave_05.py` file.
16
14
- As with incomplete tests in other waves, you should comment out the `Exception` when implementing a test.
17
-
-The tests you need to write are scaffolded in the `test_wave_05.py` file.
18
-
-These tests are currently skipped with `@pytest.mark.skip(reason="test to be completed by student")` and the function body has `pass` in it. Once you implement these tests you should remove the `skip` decorator and the `pass`.
19
-
- For the tests you write, use the requirements in this document to guide your test writing.
20
-
- Pay attention to the exact shape of the expected JSON. Double-check nested data structures and the names of the keys for any misspellings.
15
+
-These tests are currently skipped with `@pytest.mark.skip(reason="test to be completed by student")` and the function body has `pass` in it.
16
+
- Once you implement these tests you should remove the `skip` decorator and the `pass`.
17
+
18
+
For the tests you write, use the requirements in this document to guide your test writing.
21
19
- You can model your tests off of the Wave 1 tests for Tasks.
20
+
- Pay attention to the exact shape of the expected JSON. Double-check nested data structures and the names of the keys for any misspellings.
22
21
- Some tests use a [fixture](https://docs.pytest.org/en/6.2.x/fixture.html) named `one_goal` that is defined in `tests/conftest.py`. This fixture saves a specific goal to the test database.
23
22
24
23
@@ -38,6 +37,12 @@ Goals should contain these attributes. **The tests require the title column to b
38
37
- Don't forget to run:
39
38
-`flask db migrate` every time there's a change in models, in order to generate migrations
40
39
-`flask db upgrade` to run all generated migrations
40
+
- Similar to the Task model, we could add a class method to the Goal model that initializes a new instance from a dictionary, and use this method in relevant routes.
41
+
- If all of our models have this method, we could create a route helper method that initializes a new model instance from a dictionary, and use it in any route that creates a new model instance.
42
+
- Also like the Task model, notice that routes that return a JSON response are sending a dictionary representation of the goal that was fetched or created.
43
+
- Creating a model helper method to return this dictionary, which we can then use to help build these route responses, will improve the consistency of our endpoints.
44
+
- Further, we should remember that retrieving a model by its ID is a common operation. We should consider creating a route helper method that can retrieve a model by its ID, and use it for relevant routes.
45
+
- This method would be very similar in functionality to retrieving a Task model by its ID, so rather than making an entirely new route helper method, we could generalize any similar function to also work with a Goal (or any other model).
41
46
42
47
## CRUD for Goals
43
48
@@ -59,19 +64,13 @@ and get this response:
59
64
60
65
```json
61
66
{
62
-
"goal": {
63
-
"id": 1,
64
-
"title": "My New Goal"
65
-
}
67
+
"id": 1,
68
+
"title": "My New Goal"
66
69
}
67
70
```
68
71
69
72
so that I know I successfully created a goal that is saved in the database.
70
73
71
-
Similar to the Task model, we could add a class method to the Goal model that initializes a new instance from a dictionary, and use this method in the route. If all of our models have this method, we could create a route helper method that initializes a new model instance from a dictionary, and use it in this route and any other route that creates a new model instance.
72
-
73
-
Also like the Task model, notice that the data nested under the `"goal"` key is a dictionary representation of the goal that was created. Creating a model helper method to return this dictionary, which we can then use to help build this route response, will improve the consistency of our endpoints.
74
-
75
74
### Get Goals: Getting Saved Goals
76
75
77
76
As a client, I want to be able to make a `GET` request to `/goals` when there is at least one saved goal and get this response:
@@ -91,8 +90,6 @@ As a client, I want to be able to make a `GET` request to `/goals` when there is
91
90
]
92
91
```
93
92
94
-
Notice that each data item in the list is a dictionary representation of a goal. Creating a model helper method to return this dictionary, which we can then use to help build this route response, will improve the consistency of our endpoints.
95
-
96
93
### Get Goals: No Saved Goals
97
94
98
95
As a client, I want to be able to make a `GET` request to `/goals` when there are zero saved goals and get this response:
@@ -111,18 +108,11 @@ As a client, I want to be able to make a `GET` request to `/goals/1` when there
111
108
112
109
```json
113
110
{
114
-
"goal": {
115
-
"id": 1,
116
-
"title": "Build a habit of going outside daily"
117
-
}
111
+
"id": 1,
112
+
"title": "Build a habit of going outside daily"
118
113
}
119
114
```
120
115
121
-
Notice that the data nested under the `"goal"` key is a dictionary representation of the goal that was retrieved. Creating a model helper method to return this dictionary, which we can then use to help build this route response, will improve the consistency of our endpoints.
122
-
123
-
Further, we should remember that retrieving a model by its ID is a common operation. We should consider creating a route helper method that can retrieve a model by its ID, and use it in this route. This method would be very similar in functionality to retrieving a Task model by its ID, so rather than making an entirely new route helper method, we could generalize any similar Task model method to work also work with a Goal (or any other model).
124
-
125
-
126
116
### Update Goal
127
117
128
118
As a client, I want to be able to make a `PUT` request to `/goals/1` when there is at least one saved goal with this request body:
@@ -139,8 +129,6 @@ and get this response:
139
129
140
130
The response should have a mimetype of "application/json" to keep our API response type consistent.
141
131
142
-
We should remember that retrieving a model by its ID is a common operation. We should consider creating a route helper method that can retrieve a model by its ID, and use it in this route. This method could be written to work for Goal models, Task models, or any other model.
143
-
144
132
### Delete Goal: Deleting a Goal
145
133
146
134
As a client, I want to be able to make a `DELETE` request to `/goals/1` when there is at least one saved goal and get this response:
@@ -149,8 +137,6 @@ As a client, I want to be able to make a `DELETE` request to `/goals/1` when the
149
137
150
138
The response should have a mimetype of "application/json" to keep our API response type consistent.
151
139
152
-
We should remember that retrieving a model by its ID is a common operation. We should consider creating a route helper method that can retrieve a model by its ID, and use it in this route. This method could be written to work for Goal models, Task models, or any other model.
153
-
154
140
### No matching Goal: Get, Update, and Delete
155
141
156
142
As a client, if I make any of the following requests:
0 commit comments