Skip to content

Commit 4ab686c

Browse files
Update Wave 5 doc
1 parent 439e8f9 commit 4ab686c

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

ada-project-docs/wave_05.md

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
## Goal
44

55
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.
68

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

1311
## Writing Tests
1412

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.
1614
- 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.
2119
- 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.
2221
- 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.
2322

2423

@@ -38,6 +37,12 @@ Goals should contain these attributes. **The tests require the title column to b
3837
- Don't forget to run:
3938
- `flask db migrate` every time there's a change in models, in order to generate migrations
4039
- `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).
4146

4247
## CRUD for Goals
4348

@@ -59,19 +64,13 @@ and get this response:
5964

6065
```json
6166
{
62-
"goal": {
63-
"id": 1,
64-
"title": "My New Goal"
65-
}
67+
"id": 1,
68+
"title": "My New Goal"
6669
}
6770
```
6871

6972
so that I know I successfully created a goal that is saved in the database.
7073

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-
7574
### Get Goals: Getting Saved Goals
7675

7776
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
9190
]
9291
```
9392

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-
9693
### Get Goals: No Saved Goals
9794

9895
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
111108

112109
```json
113110
{
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"
118113
}
119114
```
120115

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-
126116
### Update Goal
127117

128118
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:
139129

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

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-
144132
### Delete Goal: Deleting a Goal
145133

146134
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
149137

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

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-
154140
### No matching Goal: Get, Update, and Delete
155141

156142
As a client, if I make any of the following requests:

0 commit comments

Comments
 (0)