|
@@ -6,7 +6,7 @@
|
6
|
6
|
|
7
|
7
|
|
8
|
8
|
-
|
9
|
|
-# Part 1.1 - Create class `Option`
|
|
9
|
+## Part 1.1 - Create class `Option`
|
10
|
10
|
* Create an `Option` class in the `domain` sub-package.
|
11
|
11
|
* `Option` class signature is annotated with `@Entity`
|
12
|
12
|
* `Option` has an `id` instance variable of type `Long`
|
|
@@ -26,7 +26,7 @@
|
26
|
26
|
|
27
|
27
|
|
28
|
28
|
-
|
29
|
|
-# Part 1.2 - Create class `Poll`
|
|
29
|
+## Part 1.2 - Create class `Poll`
|
30
|
30
|
* Create a `Poll` class in the `domain` sub-package.
|
31
|
31
|
* `Poll` class signature is annotated with `@Entity`
|
32
|
32
|
* `Poll` has an `id` instance variable of type `Long`
|
|
@@ -50,7 +50,7 @@
|
50
|
50
|
|
51
|
51
|
|
52
|
52
|
-
|
53
|
|
-# Part 1.3 - Create class `Vote`
|
|
53
|
+## Part 1.3 - Create class `Vote`
|
54
|
54
|
* Create a `Vote` class in the `domain` sub-package.
|
55
|
55
|
* `Vote` class signature is annotated with `@Entity`
|
56
|
56
|
* `Vote` has an `id` instance variable of type `Long`
|
|
@@ -79,17 +79,17 @@
|
79
|
79
|
|
80
|
80
|
|
81
|
81
|
-
|
82
|
|
-# Part 2.1 - Create interface `OptionRepository`
|
|
82
|
+## Part 2.1 - Create interface `OptionRepository`
|
83
|
83
|
* Create an `OptionRepository` interface in the `repositories` subpackage.
|
84
|
84
|
* `OptionRepository` extends `CrudRepository<Option, Long>`
|
85
|
85
|
|
86
|
86
|
-
|
87
|
|
-# Part 2.2 - Create interface `PollRepository`
|
|
87
|
+## Part 2.2 - Create interface `PollRepository`
|
88
|
88
|
* Create a `PollRepository` interface in the `repositories` subpackage.
|
89
|
89
|
* `PollRepository` extends `CrudRepository<Poll, Long>`
|
90
|
90
|
|
91
|
91
|
-
|
92
|
|
-# Part 2.3 - Create interface `VoteRepository`
|
|
92
|
+## Part 2.3 - Create interface `VoteRepository`
|
93
|
93
|
* Create a `VoteRepository` interface in the `repositories` subpackage.
|
94
|
94
|
* `VoteRepository` extends `CrudRepository<Vote, Long>`
|
95
|
95
|
|
|
@@ -107,7 +107,7 @@
|
107
|
107
|
|
108
|
108
|
|
109
|
109
|
-
|
110
|
|
-# Part 3.1 - Create class `PollController`
|
|
110
|
+## Part 3.1 - Create class `PollController`
|
111
|
111
|
* Create a `PollController` class in the `controller` sub package.
|
112
|
112
|
* `PollController` signature should be `annotated` with `@RestController`
|
113
|
113
|
|
|
@@ -115,7 +115,7 @@
|
115
|
115
|
* `pollRepository` should be `annotated` with `@Inject`
|
116
|
116
|
|
117
|
117
|
-
|
118
|
|
-# Part 3.1.1 - Create `GET` request method
|
|
118
|
+### Part 3.1.1 - Create `GET` request method
|
119
|
119
|
* The method definition below supplies a `GET` request on the `/polls` endpoint which provides a collection of all of the polls available in the QuickPolls application. Copy and paste this into your `PollController` class.
|
120
|
120
|
|
121
|
121
|
```java
|
|
@@ -134,7 +134,7 @@ public ResponseEntity<Iterable<Poll>> getAllPolls() {
|
134
|
134
|
|
135
|
135
|
|
136
|
136
|
-
|
137
|
|
-# Part 3.1.2 - Testing via Postman
|
|
137
|
+### Part 3.1.2 - Testing via Postman
|
138
|
138
|
* Ensure that the `start-class` tag in your `pom.xml` encapsulates `io.zipcoder.springdemo.QuickPollApplication`
|
139
|
139
|
* Open a command line and navigate to the project's root directory and run this command:
|
140
|
140
|
* `mvn spring-boot:run`
|
|
@@ -145,7 +145,7 @@ public ResponseEntity<Iterable<Poll>> getAllPolls() {
|
145
|
145
|
|
146
|
146
|
|
147
|
147
|
-
|
148
|
|
-# Part 3.1.3 - Create `POST` request method
|
|
148
|
+### Part 3.1.3 - Create `POST` request method
|
149
|
149
|
* We accomplish the capability to add new polls to the `PollController` by implementing the `POST` verb functionality in a `createPoll` method:
|
150
|
150
|
|
151
|
151
|
```java
|
|
@@ -166,7 +166,7 @@ public ResponseEntity<?> createPoll(@RequestBody Poll poll) {
|
166
|
166
|
|
167
|
167
|
|
168
|
168
|
-
|
169
|
|
-# Part 3.1.4 - Modify `createPoll`
|
|
169
|
+### Part 3.1.4 - Modify `createPoll`
|
170
|
170
|
* Best practice is to convey the URI to the newly created resource using the Location HTTP header via Spring's `ServletUriComponentsBuilder` utility class. This will ensure that the client has some way of knowing the URI of the newly created Poll.
|
171
|
171
|
|
172
|
172
|
```java
|
|
@@ -183,7 +183,7 @@ URI newPollUri = ServletUriComponentsBuilder
|
183
|
183
|
|
184
|
184
|
|
185
|
185
|
-
|
186
|
|
-# Part 3.1.5 - Create `GET` request method
|
|
186
|
+### Part 3.1.5 - Create `GET` request method
|
187
|
187
|
* The code snippet below enables us to access an individual poll.
|
188
|
188
|
* The _value attribute_ in the `@RequestMapping` takes a URI template `/polls/{pollId}`.
|
189
|
189
|
* The placeholder `{pollId}` along with `@PathVarible` annotation allows Spring to examine the request URI path and extract the `pollId` parameter value.
|
|
@@ -201,7 +201,7 @@ public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
|
201
|
201
|
|
202
|
202
|
|
203
|
203
|
-
|
204
|
|
-# Part 3.1.6 - Create `UPDATE` request method
|
|
204
|
+### Part 3.1.6 - Create `UPDATE` request method
|
205
|
205
|
* The code snippet below enables us to update a poll.
|
206
|
206
|
|
207
|
207
|
```java
|
|
@@ -216,7 +216,7 @@ public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long p
|
216
|
216
|
|
217
|
217
|
|
218
|
218
|
-
|
219
|
|
-# Part 3.1.7 - Create `DELETE` request method.
|
|
219
|
+### Part 3.1.7 - Create `DELETE` request method.
|
220
|
220
|
|
221
|
221
|
* The code snippet below enables us to delete a poll.
|
222
|
222
|
|
|
@@ -232,7 +232,7 @@ public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
|
232
|
232
|
|
233
|
233
|
|
234
|
234
|
-
|
235
|
|
-# Part 3.1.8 - Test
|
|
235
|
+### Part 3.1.8 - Test
|
236
|
236
|
* Restart the QuickPoll application.
|
237
|
237
|
* Use Postman to execute a `PUT` to `http://localhost:8080/polls/1` whose request body is the `JSON` object below.
|
238
|
238
|
* You can modify the request body in Postman by navigating to the `Body` tab, selecting the `raw` radio button, and selecting the `JSON` option from the text format dropdown.
|
|
@@ -252,7 +252,7 @@ public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
|
252
|
252
|
|
253
|
253
|
|
254
|
254
|
-
|
255
|
|
-# Part 3.2 - Create class `VoteController`
|
|
255
|
+## Part 3.2 - Create class `VoteController`
|
256
|
256
|
* Following the principles used to create `PollController`, we implement the `VoteController` class.
|
257
|
257
|
* Below is the code for the `VoteController` class along with the functionality to create a vote.
|
258
|
258
|
* The `VoteController` uses an injected instance of `VoteRepository` to perform `CRUD` operations on Vote instances.
|
|
@@ -276,7 +276,7 @@ public class VoteController {
|
276
|
276
|
}
|
277
|
277
|
```
|
278
|
278
|
|
279
|
|
-# Part 3.2.1 - Testing `VoteController`
|
|
279
|
+### Part 3.2.1 - Testing `VoteController`
|
280
|
280
|
* To test the voting capabilities, `POST` a new Vote to the `/polls/1/votes` endpoint with the option object expressed in `JSON` below.
|
281
|
281
|
* On successful request execution, you will see a Location response header with value http://localhost:8080/polls/1/votes/1.
|
282
|
282
|
|
|
@@ -290,7 +290,7 @@ public class VoteController {
|
290
|
290
|
|
291
|
291
|
|
292
|
292
|
-
|
293
|
|
-# Part 3.2.2 - Modify `VoteRepository`
|
|
293
|
+### Part 3.2.2 - Modify `VoteRepository`
|
294
|
294
|
* The method `findAll` in the `VoteRepository` retrieves all votes in a Database rather than a given poll.
|
295
|
295
|
* To ensure we can get votes for a given poll, we must add the code below to our `VoteRepository`.
|
296
|
296
|
|
|
@@ -311,7 +311,7 @@ public interface VoteRepository extends CrudRepository<Vote, Long> {
|
311
|
311
|
|
312
|
312
|
|
313
|
313
|
-
|
314
|
|
-# Part 3.2.3 - Modify `VoteController`
|
|
314
|
+### Part 3.2.3 - Modify `VoteController`
|
315
|
315
|
* Create a `getAllVotes` method in the `VoteController`
|
316
|
316
|
|
317
|
317
|
|