|
|
@@ -1,12 +1,12 @@
|
|
1
|
1
|
# Poll Application
|
|
2
|
2
|
* **Purpose**
|
|
3
|
|
- * to demonstrate the basic functionality of the [Spring Framework](https://spring.io/)
|
|
|
3
|
+ * to demonstrate the basic functionality of the [Spring Framework](https://spring.quickpoll.io/)
|
|
4
|
4
|
* to demonstrate API testing via [Postman](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en)
|
|
5
|
5
|
|
|
6
|
6
|
# Part 1 - Domain Implementation
|
|
7
|
7
|
|
|
8
|
8
|
* _Domain objects_ are the backbone for an application and contain the [business logic](https://en.wikipedia.org/wiki/Business_logic).
|
|
9
|
|
-* Create a sub package of `io.zipcoder.tc_spring_poll_application` named `domain`.
|
|
|
9
|
+* Create a sub package of `quickpoll.io.zipcoder.tc_spring_poll_application` named `domain`.
|
|
10
|
10
|
|
|
11
|
11
|
|
|
12
|
12
|
## Part 1.1 - Create class `Option`
|
|
|
@@ -76,7 +76,7 @@
|
|
76
|
76
|
* _Repositories_ or [Data Access Objects (DAO)](https://en.wikipedia.org/wiki/Data_access_object), provide an abstraction for interacting with _datastores_.
|
|
77
|
77
|
* 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.
|
|
78
|
78
|
* It is customary to have one `Repository` per `domain` object.
|
|
79
|
|
-* Create a sub-package of `io.zipcoder.tc_spring_poll_application` named `repositories`.
|
|
|
79
|
+* Create a sub-package of `quickpoll.io.zipcoder.tc_spring_poll_application` named `repositories`.
|
|
80
|
80
|
|
|
81
|
81
|
|
|
82
|
82
|
## Part 2.1 - Create interface `OptionRepository`
|
|
|
@@ -100,7 +100,7 @@
|
|
100
|
100
|
|
|
101
|
101
|
* _Controllers_ provides all of the necessary [endpoints](https://en.wikipedia.org/wiki/Web_API#Endpoints) to access and manipulate respective domain objects.
|
|
102
|
102
|
* REST resources are identified using URI endpoints.
|
|
103
|
|
-* Create a sub package of `io.zipcoder.tc_spring_poll_application` named `controller`.
|
|
|
103
|
+* Create a sub package of `quickpoll.io.zipcoder.tc_spring_poll_application` named `controller`.
|
|
104
|
104
|
|
|
105
|
105
|
|
|
106
|
106
|
## Part 3.1 - Create class `PollController`
|
|
|
@@ -132,7 +132,7 @@ public ResponseEntity<Iterable<Poll>> getAllPolls() {
|
|
132
|
132
|
|
|
133
|
133
|
### Part 3.1.2 - Testing via Postman
|
|
134
|
134
|
|
|
135
|
|
-* Ensure that the `start-class` tag in your `pom.xml` encapsulates `io.zipcoder.springdemo.QuickPollApplication`
|
|
|
135
|
+* Ensure that the `start-class` tag in your `pom.xml` encapsulates `quickpoll.io.zipcoder.springdemo.QuickPollApplication`
|
|
136
|
136
|
* Open a command line and navigate to the project's root directory and run this command:
|
|
137
|
137
|
* `mvn spring-boot:run`
|
|
138
|
138
|
* Launch the [Postman](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en) app and enter the URI `http://localhost:8080/polls` and hit Send.
|
|
|
@@ -347,7 +347,7 @@ public Iterable<Vote> getVote(@PathVariable Long pollId) {
|
|
347
|
347
|
|
|
348
|
348
|
* The final piece remaining for us is the implementation of the ComputeResult resource.
|
|
349
|
349
|
* 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
|
|
350
|
|
-* Create a sub package of `java` named `dtos`
|
|
|
350
|
+* Create a sub package of `java` named `quickpoll.dtos`
|
|
351
|
351
|
|
|
352
|
352
|
|
|
353
|
353
|
## Part 4.1 - Create class `OptionCount`
|
|
|
@@ -445,7 +445,7 @@ public class ComputeResultController {
|
|
445
|
445
|
|
|
446
|
446
|
## Part 5.1 - Create `ResourceNotFoundException`
|
|
447
|
447
|
|
|
448
|
|
-- Create a `exception` package inside of `io.zipcoder.springdemo.QuickPollApplication`
|
|
|
448
|
+- Create a `exception` package inside of `quickpoll.io.zipcoder.springdemo.QuickPollApplication`
|
|
449
|
449
|
- Create a `ResourceNotFoundException` class that extends `RuntimeException`. We'll use this to signal when a requested resource is not found.
|
|
450
|
450
|
- Annotate the `ResourceNotFoundException` class with `@ResponseStatus(HttpStatus.NOT_FOUND)`. This informs Spring that any request mapping that throws a `ResourceNotFoundException` should result in a `404 NOT FOUND` http status.
|
|
451
|
451
|
- Implement three constructors
|
|
|
@@ -462,7 +462,7 @@ Create a void method in `PollController` called `verifyPoll` that checks if a sp
|
|
462
|
462
|
|
|
463
|
463
|
## Part 5.3 - Create custom Error Responses
|
|
464
|
464
|
|
|
465
|
|
-Spring provides some built-in exception handling and error response, but we'll customize it a bit here. Create an `ErrorDetail` class in a new `io.zipcoder.tc_spring_poll_application.dto.error` package to hold relevant information any time an error occurs.
|
|
|
465
|
+Spring provides some built-in exception handling and error response, but we'll customize it a bit here. Create an `ErrorDetail` class in a new `quickpoll.io.zipcoder.tc_spring_poll_application.dto.error` package to hold relevant information any time an error occurs.
|
|
466
|
466
|
|
|
467
|
467
|
Fields (Don't forget to provide getters and setters):
|
|
468
|
468
|
|
|
|
@@ -501,7 +501,7 @@ Now it's time to make sure that all objects persisted to the database actually c
|
|
501
|
501
|
|
|
502
|
502
|
## Part 5.5 - Customizing validation errors
|
|
503
|
503
|
|
|
504
|
|
-In order to customize validation errors we'll need a class for error information. Create a `ValidationError` class in `io.zipcoder.tc_spring_poll_application.dto.error` with the following fields and appropriate getters and setters:
|
|
|
504
|
+In order to customize validation errors we'll need a class for error information. Create a `ValidationError` class in `quickpoll.io.zipcoder.tc_spring_poll_application.dto.error` with the following fields and appropriate getters and setters:
|
|
505
|
505
|
|
|
506
|
506
|
- `String code`
|
|
507
|
507
|
- `String message`
|