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
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,10 @@ and get this response:
68
68
69
69
so that I know I successfully created a goal that is saved in the database.
70
70
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
+
71
75
### Get Goals: Getting Saved Goals
72
76
73
77
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:
@@ -87,6 +91,8 @@ As a client, I want to be able to make a `GET` request to `/goals` when there is
87
91
]
88
92
```
89
93
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
+
90
96
### Get Goals: No Saved Goals
91
97
92
98
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:
@@ -112,6 +118,10 @@ As a client, I want to be able to make a `GET` request to `/goals/1` when there
112
118
}
113
119
```
114
120
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
+
115
125
116
126
### Update Goal
117
127
@@ -129,6 +139,8 @@ and get this response:
129
139
130
140
The response should have a mimetype of "application/json" to keep our API response type consistent.
131
141
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
+
132
144
### Delete Goal: Deleting a Goal
133
145
134
146
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:
@@ -137,6 +149,8 @@ As a client, I want to be able to make a `DELETE` request to `/goals/1` when the
137
149
138
150
The response should have a mimetype of "application/json" to keep our API response type consistent.
139
151
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
+
140
154
### No matching Goal: Get, Update, and Delete
141
155
142
156
As a client, if I make any of the following requests:
@@ -151,7 +165,9 @@ The response code should be `404`.
151
165
152
166
You may choose the response body.
153
167
154
-
Make sure to complete the tests for non-existing tasks to check that the correct response body is returned.
168
+
Make sure to complete the tests for non-existing tasks to check that the correct response body is returned.
169
+
170
+
By using a helper method to retrieve a model by its ID, we could ensure that the response for a non-existing model is consistent across all these routes.
155
171
156
172
### Create a Goal: Invalid Goal With Missing Title
0 commit comments