Skip to content

Commit 4d937df

Browse files
committed
adds similar helper method recommendations for the Goal model
1 parent 67ce103 commit 4d937df

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ada-project-docs/wave_05.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ and get this response:
6868

6969
so that I know I successfully created a goal that is saved in the database.
7070

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+
7175
### Get Goals: Getting Saved Goals
7276

7377
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
8791
]
8892
```
8993

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+
9096
### Get Goals: No Saved Goals
9197

9298
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
112118
}
113119
```
114120

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+
115125

116126
### Update Goal
117127

@@ -129,6 +139,8 @@ and get this response:
129139

130140
The response should have a mimetype of "application/json" to keep our API response type consistent.
131141

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+
132144
### Delete Goal: Deleting a Goal
133145

134146
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
137149

138150
The response should have a mimetype of "application/json" to keep our API response type consistent.
139151

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+
140154
### No matching Goal: Get, Update, and Delete
141155

142156
As a client, if I make any of the following requests:
@@ -151,7 +165,9 @@ The response code should be `404`.
151165

152166
You may choose the response body.
153167

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.
155171

156172
### Create a Goal: Invalid Goal With Missing Title
157173

0 commit comments

Comments
 (0)