Skip to content

Commit 109facd

Browse files
committed
clean up readme formatting
1 parent f90e25a commit 109facd

File tree

1 file changed

+44
-52
lines changed

1 file changed

+44
-52
lines changed

README.md

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11

22

3-
# Part 1 - Domain Implementation<br>
3+
# Part 1 - Domain Implementation
4+
45
* _Domain objects_ are the backbone for an application and contain the [business logic](https://en.wikipedia.org/wiki/Business_logic).
56
* Create a sub package of `io.zipcoder.tc_spring_poll_application` named `domain`.
67

78

8-
-
99
## Part 1.1 - Create class `Option`
10+
1011
* Create an `Option` class in the `domain` sub-package.
1112
* `Option` class signature is annotated with `@Entity`
1213
* `Option` has an `id` instance variable of type `Long`
@@ -25,8 +26,8 @@
2526
* Create a `getter` and `setter` for each of the respective instance variables.
2627

2728

28-
-
2929
## Part 1.2 - Create class `Poll`
30+
3031
* Create a `Poll` class in the `domain` sub-package.
3132
* `Poll` class signature is annotated with `@Entity`
3233
* `Poll` has an `id` instance variable of type `Long`
@@ -48,9 +49,8 @@
4849
* Create a `getter` and `setter` for each of the respective instance variables.
4950

5051

51-
52-
-
5352
## Part 1.3 - Create class `Vote`
53+
5454
* Create a `Vote` class in the `domain` sub-package.
5555
* `Vote` class signature is annotated with `@Entity`
5656
* `Vote` has an `id` instance variable of type `Long`
@@ -67,55 +67,49 @@
6767
* Create a `getter` and `setter` for each of the respective instance variables.
6868

6969

70-
71-
72-
-
73-
-
7470
# Part 2 - Repository Implementation
71+
7572
* _Repositories_ or [Data Access Objects (DAO)](https://en.wikipedia.org/wiki/Data_access_object), provide an abstraction for interacting with _datastores_.
7673
* Typically DAOs include an interface that provides a set of finder methods such as `findById`, `findAll`, for retrieving data, and methods to persist and delete data.
7774
* It is customary to have one `Repository` per `domain` object.
7875
* Create a sub-package of `io.zipcoder.tc_spring_poll_application` named `repositories`.
7976

8077

81-
-
8278
## Part 2.1 - Create interface `OptionRepository`
79+
8380
* Create an `OptionRepository` interface in the `repositories` subpackage.
8481
* `OptionRepository` extends `CrudRepository<Option, Long>`
8582

86-
-
83+
8784
## Part 2.2 - Create interface `PollRepository`
85+
8886
* Create a `PollRepository` interface in the `repositories` subpackage.
8987
* `PollRepository` extends `CrudRepository<Poll, Long>`
9088

91-
-
89+
9290
## Part 2.3 - Create interface `VoteRepository`
91+
9392
* Create a `VoteRepository` interface in the `repositories` subpackage.
9493
* `VoteRepository` extends `CrudRepository<Vote, Long>`
9594

96-
97-
98-
99-
100-
101-
-
102-
-
10395
# Part 3 - Controller Implementation
96+
10497
* _Controllers_ provides all of the necessary [endpoints](https://en.wikipedia.org/wiki/Web_API#Endpoints) to access and manipulate respective domain objects.
10598
* REST resources are identified using URI endpoints.
10699
* Create a sub package of `io.zipcoder.tc_spring_poll_application` named `controller`.
107100

108101

109-
-
110102
## Part 3.1 - Create class `PollController`
103+
111104
* Create a `PollController` class in the `controller` sub package.
112105
* `PollController` signature should be `annotated` with `@RestController`
113106

114107
* `PollController` has a `pollRepository` instance variable of type `PollRepository`
115108
* `pollRepository` should be `annotated` with `@Inject`
116109

117-
-
110+
118111
### Part 3.1.1 - Create `GET` request method
112+
119113
* 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.
120114

121115
```java
@@ -132,9 +126,8 @@ public ResponseEntity<Iterable<Poll>> getAllPolls() {
132126

133127

134128

135-
136-
-
137129
### Part 3.1.2 - Testing via Postman
130+
138131
* Ensure that the `start-class` tag in your `pom.xml` encapsulates `io.zipcoder.springdemo.QuickPollApplication`
139132
* Open a command line and navigate to the project's root directory and run this command:
140133
* `mvn spring-boot:run`
@@ -143,9 +136,8 @@ public ResponseEntity<Iterable<Poll>> getAllPolls() {
143136

144137

145138

146-
147-
-
148139
### Part 3.1.3 - Create `POST` request method
140+
149141
* We accomplish the capability to add new polls to the `PollController` by implementing the `POST` verb functionality in a `createPoll` method:
150142

151143
```java
@@ -164,9 +156,8 @@ public ResponseEntity<?> createPoll(@RequestBody Poll poll) {
164156

165157

166158

167-
168-
-
169159
### Part 3.1.4 - Modify `createPoll`
160+
170161
* 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.
171162

172163
```java
@@ -181,9 +172,8 @@ URI newPollUri = ServletUriComponentsBuilder
181172

182173

183174

184-
185-
-
186175
### Part 3.1.5 - Create `GET` request method
176+
187177
* The code snippet below enables us to access an individual poll.
188178
* The _value attribute_ in the `@RequestMapping` takes a URI template `/polls/{pollId}`.
189179
* The placeholder `{pollId}` along with `@PathVarible` annotation allows Spring to examine the request URI path and extract the `pollId` parameter value.
@@ -198,10 +188,8 @@ public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
198188
```
199189

200190

201-
202-
203-
-
204191
### Part 3.1.6 - Create `UPDATE` request method
192+
205193
* The code snippet below enables us to update a poll.
206194

207195
```java
@@ -214,8 +202,6 @@ public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long p
214202
```
215203

216204

217-
218-
-
219205
### Part 3.1.7 - Create `DELETE` request method.
220206

221207
* The code snippet below enables us to delete a poll.
@@ -229,10 +215,8 @@ public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
229215
```
230216

231217

232-
233-
234-
-
235218
### Part 3.1.8 - Test
219+
236220
* Restart the QuickPoll application.
237221
* Use Postman to execute a `POST` to `http://localhost:8080/polls/` whose request body is the `JSON` object below.
238222
* 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.
@@ -251,8 +235,8 @@ public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
251235
```
252236

253237

254-
-
255238
## Part 3.2 - Create class `VoteController`
239+
256240
* Following the principles used to create `PollController`, we implement the `VoteController` class.
257241
* Below is the code for the `VoteController` class along with the functionality to create a vote.
258242
* The `VoteController` uses an injected instance of `VoteRepository` to perform `CRUD` operations on Vote instances.
@@ -277,6 +261,7 @@ public class VoteController {
277261
```
278262

279263
### Part 3.2.1 - Testing `VoteController`
264+
280265
* To test the voting capabilities, `POST` a new Vote to the `/polls/1/votes` endpoint with the option object expressed in `JSON` below.
281266
* On successful request execution, you will see a Location response header with value http://localhost:8080/polls/1/votes/1.
282267

@@ -287,10 +272,8 @@ public class VoteController {
287272
```
288273

289274

290-
291-
292-
-
293275
### Part 3.2.2 - Modify `VoteRepository`
276+
294277
* The method `findAll` in the `VoteRepository` retrieves all votes in a Database rather than a given poll.
295278
* To ensure we can get votes for a given poll, we must add the code below to our `VoteRepository`.
296279

@@ -309,9 +292,8 @@ public interface VoteRepository extends CrudRepository<Vote, Long> {
309292
* At runtime, Spring Data JPA replaces the `?1` placeholder with the passed-in `pollId` parameter value.
310293

311294

312-
313-
-
314295
### Part 3.2.3 - Modify `VoteController`
296+
315297
* Create a `getAllVotes` method in the `VoteController`
316298

317299

@@ -322,15 +304,16 @@ public Iterable<Vote> getAllVotes(@PathVariable Long pollId) {
322304
}
323305
```
324306

325-
-
326-
-
307+
327308
# Part 4 - Data Transfer Object (DTO) Implementation
309+
328310
* The final piece remaining for us is the implementation of the ComputeResult resource.
329311
* Because we don’t have any domain objects that can directly help generate this resource representation, we implement two Data Transfer Objects or DTOs—OptionCount and VoteResult
330312
* Create a sub package of `java` named `dtos`
331313

332-
-
314+
333315
## Part 4.1 - Create class `OptionCount`
316+
334317
* The `OptionCount` DTO contains the `ID` of the option and a count of votes casted for that option.
335318

336319
```java
@@ -356,7 +339,9 @@ public class OptionCount {
356339
}
357340
```
358341

342+
359343
## Part 4.2 - Create class `VoteResult`
344+
360345
* The `VoteResult` DTO contains the total votes cast and a collection of `OptionCount` instances.
361346

362347
```java
@@ -385,6 +370,7 @@ public class VoteResult {
385370

386371

387372
## Part 4.3 - Create class `ComputeResultController`
373+
388374
* Following the principles used in creating the `PollController` and `VoteController`, we create a new `ComputeResultController` class
389375

390376
```java
@@ -411,6 +397,7 @@ public class ComputeResultController {
411397

412398

413399
## Part 4.4 - Test via Postman
400+
414401
* Start/restart the `QuickPoll` application.
415402
* Using the earlier Postman requests, create a poll and cast votes on its options.
416403
* Ensure a JSON file with a `status` of `200` is returned by executing a `GET` request of `http://localhost:8080/computeresults?pollId=1` via Postman
@@ -538,24 +525,27 @@ Size.poll.options=Options must be greater than {2} and less than {1}
538525
```
539526
540527
541-
542528
# Part 6 - Pagination
529+
543530
* To optimize performance, it is important to limit the amount of data returned, especially in the case of a mobile client.
544531
* REST services have the ability to give clients access large datasets in manageable chunks, by splitting the data into discrete pages or _paging data_.
545532
* For this lab, we will approach this by implementing the _page number pagination pattern_.
546533
547-
-
534+
548535
### Get Data From Page
536+
549537
* For example, a client wanting a blog post in page 3 of a hypothetical blog service can use a `GET` method resembling the following:
550538
`http://blog.example.com/posts?page=3`
551539
552-
-
540+
553541
### Limit Data Retrieved From Page
542+
554543
* It is possible for the client to override the default page size by passing in a page-size parameter:
555544
`http://blog.example.com/posts?page=3&size=20`
556545
557-
-
546+
558547
### Pagination Data
548+
559549
* Pagination-specific information includes
560550
* total number of records
561551
* total number of pages
@@ -574,10 +564,11 @@ Size.poll.options=Options must be greater than {2} and less than {1}
574564
"totalRecords": 90
575565
}
576566
```
567+
577568
* Read more about REST pagination in Spring by clicking [here](https://dzone.com/articles/rest-pagination-spring).
578569
579570
580-
-
571+
581572
## Part 6.1 - Load Dummy Poll Data
582573
583574
* Create a `src/main/resource/import.sql` file with _DML statements_ for populating the database upon bootstrap. The `import.sql` should insert at least 15 polls, each with 3 or more options.
@@ -597,8 +588,9 @@ Size.poll.options=Options must be greater than {2} and less than {1}
597588
* Restart your application.
598589
* Use Postman to ensure database is populated by `import.sql`.
599590
600-
-
591+
601592
## Part 6.2 - Spring's Built-in Pagination
593+
602594
* Make use of Spring's built-in page number pagination support by researching `org.springframework.data.repository.PagingAndSortingRepository`.
603595
* Modify respective `Controller` methods to handle `Pageable` arguments.
604596
* Send a `GET` request to `http://localhost:8080/polls?page=0&size=2` via Postman.

0 commit comments

Comments
 (0)