├── 9781484274767.jpg
├── Chapter10
├── Chapter_10_Postman_Collection.json
└── quick-poll-ch10-final
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── runConfigurations.xml
│ ├── pom.xml
│ ├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── apress
│ │ │ ├── QuickPollApplication.java
│ │ │ ├── controller
│ │ │ ├── ComputeResultController.java
│ │ │ ├── PollController.java
│ │ │ └── VoteController.java
│ │ │ ├── domain
│ │ │ ├── Option.java
│ │ │ ├── Poll.java
│ │ │ └── Vote.java
│ │ │ ├── dto
│ │ │ ├── OptionCount.java
│ │ │ └── VoteResult.java
│ │ │ └── repository
│ │ │ ├── OptionRepository.java
│ │ │ ├── PollRepository.java
│ │ │ └── VoteRepository.java
│ │ └── resources
│ │ ├── application.properties
│ │ ├── import.sql
│ │ ├── static
│ │ └── .keep
│ │ └── templates
│ │ └── .keep
│ └── target
│ └── classes
│ ├── application.properties
│ ├── com
│ └── apress
│ │ ├── QuickPollApplication.class
│ │ ├── controller
│ │ ├── ComputeResultController.class
│ │ ├── PollController.class
│ │ └── VoteController.class
│ │ ├── domain
│ │ ├── Option.class
│ │ ├── Poll.class
│ │ └── Vote.class
│ │ ├── dto
│ │ ├── OptionCount.class
│ │ └── VoteResult.class
│ │ └── repository
│ │ ├── OptionRepository.class
│ │ ├── PollRepository.class
│ │ └── VoteRepository.class
│ ├── import.sql
│ ├── static
│ └── .keep
│ └── templates
│ └── .keep
├── Chapter3
└── hello-rest-ch3-final
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── runConfigurations.xml
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ └── com
│ │ └── apress
│ │ └── hellorest
│ │ └── HelloWorldRestApplication.java
│ └── resources
│ ├── application.properties
│ ├── static
│ └── .keep
│ └── templates
│ └── .keep
├── Chapter4
├── Chapter4_Postman_Collection.json
└── quick-poll-ch4-final
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── runConfigurations.xml
│ ├── pom.xml
│ ├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── apress
│ │ │ ├── QuickPollApplication.java
│ │ │ ├── controller
│ │ │ ├── ComputeResultController.java
│ │ │ ├── PollController.java
│ │ │ └── VoteController.java
│ │ │ ├── domain
│ │ │ ├── Option.java
│ │ │ ├── Poll.java
│ │ │ └── Vote.java
│ │ │ ├── dto
│ │ │ ├── OptionCount.java
│ │ │ └── VoteResult.java
│ │ │ └── repository
│ │ │ ├── OptionRepository.java
│ │ │ ├── PollRepository.java
│ │ │ └── VoteRepository.java
│ │ └── resources
│ │ ├── application.properties
│ │ ├── static
│ │ └── .keep
│ │ └── templates
│ │ └── .keep
│ └── target
│ └── classes
│ ├── application.properties
│ ├── com
│ └── apress
│ │ ├── QuickPollApplication.class
│ │ ├── controller
│ │ ├── ComputeResultController.class
│ │ ├── PollController.class
│ │ └── VoteController.class
│ │ ├── domain
│ │ ├── Option.class
│ │ ├── Poll.class
│ │ └── Vote.class
│ │ ├── dto
│ │ ├── OptionCount.class
│ │ └── VoteResult.class
│ │ └── repository
│ │ ├── OptionRepository.class
│ │ ├── PollRepository.class
│ │ └── VoteRepository.class
│ ├── static
│ └── .keep
│ └── templates
│ └── .keep
├── Chapter5
├── Chapter_5_Postman_Collection.json
└── quick-poll-ch5-final
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── runConfigurations.xml
│ ├── pom.xml
│ ├── quick-poll-ch4-final.iml
│ ├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── apress
│ │ │ ├── QuickPollApplication.java
│ │ │ ├── controller
│ │ │ ├── ComputeResultController.java
│ │ │ ├── PollController.java
│ │ │ └── VoteController.java
│ │ │ ├── domain
│ │ │ ├── Option.java
│ │ │ ├── Poll.java
│ │ │ └── Vote.java
│ │ │ ├── dto
│ │ │ ├── OptionCount.java
│ │ │ ├── VoteResult.java
│ │ │ └── error
│ │ │ │ ├── ErrorDetail.java
│ │ │ │ └── ValidationError.java
│ │ │ ├── exception
│ │ │ └── ResourceNotFoundException.java
│ │ │ ├── handler
│ │ │ └── RestExceptionHandler.java
│ │ │ └── repository
│ │ │ ├── OptionRepository.java
│ │ │ ├── PollRepository.java
│ │ │ └── VoteRepository.java
│ │ └── resources
│ │ ├── application.properties
│ │ ├── messages.properties
│ │ ├── static
│ │ └── .keep
│ │ └── templates
│ │ └── .keep
│ └── target
│ ├── classes
│ ├── application.properties
│ ├── messages.properties
│ ├── static
│ │ └── .keep
│ └── templates
│ │ └── .keep
│ └── maven-status
│ └── maven-compiler-plugin
│ └── compile
│ └── default-compile
│ ├── createdFiles.lst
│ └── inputFiles.lst
├── Chapter6
└── quick-poll-ch6-final
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ ├── runConfigurations.xml
│ └── uiDesigner.xml
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── apress
│ │ │ ├── QuickPollApplication.java
│ │ │ ├── SwaggerConfiguration.java
│ │ │ ├── controller
│ │ │ ├── ComputeResultController.java
│ │ │ ├── PollController.java
│ │ │ └── VoteController.java
│ │ │ ├── domain
│ │ │ ├── Option.java
│ │ │ ├── Poll.java
│ │ │ └── Vote.java
│ │ │ ├── dto
│ │ │ ├── OptionCount.java
│ │ │ ├── VoteResult.java
│ │ │ └── error
│ │ │ │ ├── ErrorDetail.java
│ │ │ │ └── ValidationError.java
│ │ │ ├── exception
│ │ │ └── ResourceNotFoundException.java
│ │ │ ├── handler
│ │ │ └── RestExceptionHandler.java
│ │ │ └── repository
│ │ │ ├── OptionRepository.java
│ │ │ ├── PollRepository.java
│ │ │ └── VoteRepository.java
│ └── resources
│ │ ├── application.properties
│ │ ├── messages.properties
│ │ ├── static
│ │ ├── .keep
│ │ └── swagger-ui
│ │ │ ├── css
│ │ │ ├── reset.css
│ │ │ └── screen.css
│ │ │ ├── images
│ │ │ ├── explorer_icons.png
│ │ │ ├── logo_small.png
│ │ │ ├── pet_store_api.png
│ │ │ ├── throbber.gif
│ │ │ └── wordnik_api.png
│ │ │ ├── index.html
│ │ │ ├── lib
│ │ │ ├── backbone-min.js
│ │ │ ├── handlebars-1.0.0.js
│ │ │ ├── highlight.7.3.pack.js
│ │ │ ├── jquery-1.8.0.min.js
│ │ │ ├── jquery.ba-bbq.min.js
│ │ │ ├── jquery.slideto.min.js
│ │ │ ├── jquery.wiggle.min.js
│ │ │ ├── shred.bundle.js
│ │ │ ├── shred
│ │ │ │ └── content.js
│ │ │ ├── swagger-oauth.js
│ │ │ ├── swagger.js
│ │ │ └── underscore-min.js
│ │ │ ├── o2c.html
│ │ │ ├── swagger-ui.js
│ │ │ └── swagger-ui.min.js
│ │ └── templates
│ │ └── .keep
│ └── test
│ └── java
│ └── com
│ └── apress
│ └── QuickPollApplicationTests.java
├── Chapter7
├── Chapter7_Postman_Collection.json
├── import.sql
└── quick-poll-ch7-final
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── runConfigurations.xml
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── apress
│ │ │ ├── QuickPollApplication.java
│ │ │ ├── QuickPollMvcConfigAdapter.java
│ │ │ ├── SwaggerConfiguration.java
│ │ │ ├── domain
│ │ │ ├── Option.java
│ │ │ ├── Poll.java
│ │ │ └── Vote.java
│ │ │ ├── dto
│ │ │ ├── OptionCount.java
│ │ │ ├── VoteResult.java
│ │ │ └── error
│ │ │ │ ├── ErrorDetail.java
│ │ │ │ └── ValidationError.java
│ │ │ ├── exception
│ │ │ └── ResourceNotFoundException.java
│ │ │ ├── handler
│ │ │ └── RestExceptionHandler.java
│ │ │ ├── repository
│ │ │ ├── OptionRepository.java
│ │ │ ├── PollRepository.java
│ │ │ └── VoteRepository.java
│ │ │ ├── v1
│ │ │ └── controller
│ │ │ │ ├── ComputeResultController.java
│ │ │ │ ├── PollController.java
│ │ │ │ └── VoteController.java
│ │ │ └── v2
│ │ │ └── controller
│ │ │ ├── ComputeResultController.java
│ │ │ ├── PollController.java
│ │ │ └── VoteController.java
│ └── resources
│ │ ├── application.properties
│ │ ├── import.sql
│ │ ├── messages.properties
│ │ ├── static
│ │ ├── .keep
│ │ └── swagger-ui
│ │ │ ├── css
│ │ │ ├── reset.css
│ │ │ └── screen.css
│ │ │ ├── images
│ │ │ ├── explorer_icons.png
│ │ │ ├── logo_small.png
│ │ │ ├── pet_store_api.png
│ │ │ ├── throbber.gif
│ │ │ └── wordnik_api.png
│ │ │ ├── index.html
│ │ │ ├── lib
│ │ │ ├── backbone-min.js
│ │ │ ├── handlebars-1.0.0.js
│ │ │ ├── highlight.7.3.pack.js
│ │ │ ├── jquery-1.8.0.min.js
│ │ │ ├── jquery.ba-bbq.min.js
│ │ │ ├── jquery.slideto.min.js
│ │ │ ├── jquery.wiggle.min.js
│ │ │ ├── shred.bundle.js
│ │ │ ├── shred
│ │ │ │ └── content.js
│ │ │ ├── swagger-oauth.js
│ │ │ ├── swagger.js
│ │ │ └── underscore-min.js
│ │ │ ├── o2c.html
│ │ │ ├── swagger-ui.js
│ │ │ └── swagger-ui.min.js
│ │ └── templates
│ │ └── .keep
│ └── test
│ └── java
│ └── com
│ └── apress
│ └── QuickPollApplicationTests.java
├── Chapter8
├── Chapter8_Postman_Collection.json
├── import.sql
└── quick-poll-ch8-final-basic-auth
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── runConfigurations.xml
│ ├── pom.xml
│ ├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── apress
│ │ │ │ ├── QuickPollApplication.java
│ │ │ │ ├── QuickPollMvcConfigAdapter.java
│ │ │ │ ├── SecurityConfig.java
│ │ │ │ ├── SwaggerConfiguration.java
│ │ │ │ ├── domain
│ │ │ │ ├── Option.java
│ │ │ │ ├── Poll.java
│ │ │ │ ├── User.java
│ │ │ │ └── Vote.java
│ │ │ │ ├── dto
│ │ │ │ ├── OptionCount.java
│ │ │ │ ├── VoteResult.java
│ │ │ │ └── error
│ │ │ │ │ ├── ErrorDetail.java
│ │ │ │ │ └── ValidationError.java
│ │ │ │ ├── exception
│ │ │ │ └── ResourceNotFoundException.java
│ │ │ │ ├── handler
│ │ │ │ └── RestExceptionHandler.java
│ │ │ │ ├── repository
│ │ │ │ ├── OptionRepository.java
│ │ │ │ ├── PollRepository.java
│ │ │ │ ├── UserRepository.java
│ │ │ │ └── VoteRepository.java
│ │ │ │ ├── security
│ │ │ │ └── QuickPollUserDetailsService.java
│ │ │ │ ├── v1
│ │ │ │ └── controller
│ │ │ │ │ ├── ComputeResultController.java
│ │ │ │ │ ├── PollController.java
│ │ │ │ │ └── VoteController.java
│ │ │ │ ├── v2
│ │ │ │ └── controller
│ │ │ │ │ ├── ComputeResultController.java
│ │ │ │ │ ├── PollController.java
│ │ │ │ │ └── VoteController.java
│ │ │ │ └── v3
│ │ │ │ └── controller
│ │ │ │ ├── ComputeResultController.java
│ │ │ │ ├── PollController.java
│ │ │ │ └── VoteController.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ ├── import.sql
│ │ │ ├── messages.properties
│ │ │ ├── static
│ │ │ ├── .keep
│ │ │ └── swagger-ui
│ │ │ │ ├── css
│ │ │ │ ├── reset.css
│ │ │ │ └── screen.css
│ │ │ │ ├── images
│ │ │ │ ├── explorer_icons.png
│ │ │ │ ├── logo_small.png
│ │ │ │ ├── pet_store_api.png
│ │ │ │ ├── throbber.gif
│ │ │ │ └── wordnik_api.png
│ │ │ │ ├── index.html
│ │ │ │ ├── lib
│ │ │ │ ├── backbone-min.js
│ │ │ │ ├── handlebars-1.0.0.js
│ │ │ │ ├── highlight.7.3.pack.js
│ │ │ │ ├── jquery-1.8.0.min.js
│ │ │ │ ├── jquery.ba-bbq.min.js
│ │ │ │ ├── jquery.slideto.min.js
│ │ │ │ ├── jquery.wiggle.min.js
│ │ │ │ ├── shred.bundle.js
│ │ │ │ ├── shred
│ │ │ │ │ └── content.js
│ │ │ │ ├── swagger-oauth.js
│ │ │ │ ├── swagger.js
│ │ │ │ └── underscore-min.js
│ │ │ │ ├── o2c.html
│ │ │ │ ├── swagger-ui.js
│ │ │ │ └── swagger-ui.min.js
│ │ │ └── templates
│ │ │ └── .keep
│ └── test
│ │ └── java
│ │ └── com
│ │ └── apress
│ │ └── UserGenerator.java
│ └── target
│ ├── classes
│ ├── application.properties
│ ├── com
│ │ └── apress
│ │ │ ├── QuickPollApplication.class
│ │ │ ├── QuickPollMvcConfigAdapter.class
│ │ │ ├── SecurityConfig.class
│ │ │ ├── SwaggerConfiguration.class
│ │ │ ├── domain
│ │ │ ├── Option.class
│ │ │ ├── Poll.class
│ │ │ ├── User.class
│ │ │ └── Vote.class
│ │ │ ├── dto
│ │ │ ├── OptionCount.class
│ │ │ ├── VoteResult.class
│ │ │ └── error
│ │ │ │ ├── ErrorDetail.class
│ │ │ │ └── ValidationError.class
│ │ │ ├── exception
│ │ │ └── ResourceNotFoundException.class
│ │ │ ├── handler
│ │ │ └── RestExceptionHandler.class
│ │ │ ├── repository
│ │ │ ├── OptionRepository.class
│ │ │ ├── PollRepository.class
│ │ │ ├── UserRepository.class
│ │ │ └── VoteRepository.class
│ │ │ ├── security
│ │ │ └── QuickPollUserDetailsService.class
│ │ │ ├── v1
│ │ │ └── controller
│ │ │ │ ├── ComputeResultController.class
│ │ │ │ ├── PollController.class
│ │ │ │ └── VoteController.class
│ │ │ ├── v2
│ │ │ └── controller
│ │ │ │ ├── ComputeResultController.class
│ │ │ │ ├── PollController.class
│ │ │ │ └── VoteController.class
│ │ │ └── v3
│ │ │ └── controller
│ │ │ ├── ComputeResultController.class
│ │ │ ├── PollController.class
│ │ │ └── VoteController.class
│ ├── import.sql
│ ├── messages.properties
│ ├── static
│ │ ├── .keep
│ │ └── swagger-ui
│ │ │ ├── css
│ │ │ ├── reset.css
│ │ │ └── screen.css
│ │ │ ├── images
│ │ │ ├── explorer_icons.png
│ │ │ ├── logo_small.png
│ │ │ ├── pet_store_api.png
│ │ │ ├── throbber.gif
│ │ │ └── wordnik_api.png
│ │ │ ├── index.html
│ │ │ ├── lib
│ │ │ ├── backbone-min.js
│ │ │ ├── handlebars-1.0.0.js
│ │ │ ├── highlight.7.3.pack.js
│ │ │ ├── jquery-1.8.0.min.js
│ │ │ ├── jquery.ba-bbq.min.js
│ │ │ ├── jquery.slideto.min.js
│ │ │ ├── jquery.wiggle.min.js
│ │ │ ├── shred.bundle.js
│ │ │ ├── shred
│ │ │ │ └── content.js
│ │ │ ├── swagger-oauth.js
│ │ │ ├── swagger.js
│ │ │ └── underscore-min.js
│ │ │ ├── o2c.html
│ │ │ ├── swagger-ui.js
│ │ │ └── swagger-ui.min.js
│ └── templates
│ │ └── .keep
│ └── test-classes
│ └── com
│ └── apress
│ └── UserGenerator.class
├── Chapter9
└── quick-poll-ch9-final
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── runConfigurations.xml
│ ├── pom.xml
│ ├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── apress
│ │ │ │ ├── QuickPollApplication.java
│ │ │ │ ├── QuickPollMvcConfigAdapter.java
│ │ │ │ ├── SecurityConfig.java
│ │ │ │ ├── SwaggerConfiguration.java
│ │ │ │ ├── client
│ │ │ │ ├── PageWrapper.java
│ │ │ │ ├── QuickPollClient.java
│ │ │ │ ├── QuickPollClientJdk.java
│ │ │ │ ├── QuickPollClientV2.java
│ │ │ │ └── QuickPollClientV3BasicAuth.java
│ │ │ │ ├── domain
│ │ │ │ ├── Option.java
│ │ │ │ ├── Poll.java
│ │ │ │ ├── User.java
│ │ │ │ └── Vote.java
│ │ │ │ ├── dto
│ │ │ │ ├── OptionCount.java
│ │ │ │ ├── VoteResult.java
│ │ │ │ └── error
│ │ │ │ │ ├── ErrorDetail.java
│ │ │ │ │ └── ValidationError.java
│ │ │ │ ├── exception
│ │ │ │ └── ResourceNotFoundException.java
│ │ │ │ ├── handler
│ │ │ │ └── RestExceptionHandler.java
│ │ │ │ ├── repository
│ │ │ │ ├── OptionRepository.java
│ │ │ │ ├── PollRepository.java
│ │ │ │ ├── UserRepository.java
│ │ │ │ └── VoteRepository.java
│ │ │ │ ├── security
│ │ │ │ └── QuickPollUserDetailsService.java
│ │ │ │ ├── v1
│ │ │ │ └── controller
│ │ │ │ │ ├── ComputeResultController.java
│ │ │ │ │ ├── PollController.java
│ │ │ │ │ └── VoteController.java
│ │ │ │ ├── v2
│ │ │ │ └── controller
│ │ │ │ │ ├── ComputeResultController.java
│ │ │ │ │ ├── PollController.java
│ │ │ │ │ └── VoteController.java
│ │ │ │ └── v3
│ │ │ │ └── controller
│ │ │ │ ├── ComputeResultController.java
│ │ │ │ ├── PollController.java
│ │ │ │ └── VoteController.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ ├── import.sql
│ │ │ ├── messages.properties
│ │ │ ├── static
│ │ │ ├── .keep
│ │ │ └── swagger-ui
│ │ │ │ ├── css
│ │ │ │ ├── reset.css
│ │ │ │ └── screen.css
│ │ │ │ ├── images
│ │ │ │ ├── explorer_icons.png
│ │ │ │ ├── logo_small.png
│ │ │ │ ├── pet_store_api.png
│ │ │ │ ├── throbber.gif
│ │ │ │ └── wordnik_api.png
│ │ │ │ ├── index.html
│ │ │ │ ├── lib
│ │ │ │ ├── backbone-min.js
│ │ │ │ ├── handlebars-1.0.0.js
│ │ │ │ ├── highlight.7.3.pack.js
│ │ │ │ ├── jquery-1.8.0.min.js
│ │ │ │ ├── jquery.ba-bbq.min.js
│ │ │ │ ├── jquery.slideto.min.js
│ │ │ │ ├── jquery.wiggle.min.js
│ │ │ │ ├── shred.bundle.js
│ │ │ │ ├── shred
│ │ │ │ │ └── content.js
│ │ │ │ ├── swagger-oauth.js
│ │ │ │ ├── swagger.js
│ │ │ │ └── underscore-min.js
│ │ │ │ ├── o2c.html
│ │ │ │ ├── swagger-ui.js
│ │ │ │ └── swagger-ui.min.js
│ │ │ └── templates
│ │ │ └── .keep
│ └── test
│ │ └── java
│ │ └── com
│ │ └── apress
│ │ ├── ExampleTest.java
│ │ ├── QuickPollApplicationTests.java
│ │ ├── UserGenerator.java
│ │ ├── it
│ │ └── PollControllerIT.java
│ │ └── unit
│ │ ├── PollControllerTest.java
│ │ └── PollControllerTestMock.java
│ └── target
│ ├── classes
│ ├── application.properties
│ ├── com
│ │ └── apress
│ │ │ ├── QuickPollApplication.class
│ │ │ ├── QuickPollMvcConfigAdapter.class
│ │ │ ├── SecurityConfig.class
│ │ │ ├── SwaggerConfiguration.class
│ │ │ ├── client
│ │ │ ├── PageWrapper.class
│ │ │ ├── QuickPollClient$1.class
│ │ │ ├── QuickPollClient.class
│ │ │ ├── QuickPollClientJdk.class
│ │ │ ├── QuickPollClientV2$1.class
│ │ │ ├── QuickPollClientV2.class
│ │ │ └── QuickPollClientV3BasicAuth.class
│ │ │ ├── domain
│ │ │ ├── Option.class
│ │ │ ├── Poll.class
│ │ │ ├── User.class
│ │ │ └── Vote.class
│ │ │ ├── dto
│ │ │ ├── OptionCount.class
│ │ │ ├── VoteResult.class
│ │ │ └── error
│ │ │ │ ├── ErrorDetail.class
│ │ │ │ └── ValidationError.class
│ │ │ ├── exception
│ │ │ └── ResourceNotFoundException.class
│ │ │ ├── handler
│ │ │ └── RestExceptionHandler.class
│ │ │ ├── repository
│ │ │ ├── OptionRepository.class
│ │ │ ├── PollRepository.class
│ │ │ ├── UserRepository.class
│ │ │ └── VoteRepository.class
│ │ │ ├── security
│ │ │ └── QuickPollUserDetailsService.class
│ │ │ ├── v1
│ │ │ └── controller
│ │ │ │ ├── ComputeResultController.class
│ │ │ │ ├── PollController.class
│ │ │ │ └── VoteController.class
│ │ │ ├── v2
│ │ │ └── controller
│ │ │ │ ├── ComputeResultController.class
│ │ │ │ ├── PollController.class
│ │ │ │ └── VoteController.class
│ │ │ └── v3
│ │ │ └── controller
│ │ │ ├── ComputeResultController.class
│ │ │ ├── PollController.class
│ │ │ └── VoteController.class
│ ├── import.sql
│ ├── messages.properties
│ ├── static
│ │ ├── .keep
│ │ └── swagger-ui
│ │ │ ├── css
│ │ │ ├── reset.css
│ │ │ └── screen.css
│ │ │ ├── images
│ │ │ ├── explorer_icons.png
│ │ │ ├── logo_small.png
│ │ │ ├── pet_store_api.png
│ │ │ ├── throbber.gif
│ │ │ └── wordnik_api.png
│ │ │ ├── index.html
│ │ │ ├── lib
│ │ │ ├── backbone-min.js
│ │ │ ├── handlebars-1.0.0.js
│ │ │ ├── highlight.7.3.pack.js
│ │ │ ├── jquery-1.8.0.min.js
│ │ │ ├── jquery.ba-bbq.min.js
│ │ │ ├── jquery.slideto.min.js
│ │ │ ├── jquery.wiggle.min.js
│ │ │ ├── shred.bundle.js
│ │ │ ├── shred
│ │ │ │ └── content.js
│ │ │ ├── swagger-oauth.js
│ │ │ ├── swagger.js
│ │ │ └── underscore-min.js
│ │ │ ├── o2c.html
│ │ │ ├── swagger-ui.js
│ │ │ └── swagger-ui.min.js
│ └── templates
│ │ └── .keep
│ ├── maven-status
│ └── maven-compiler-plugin
│ │ ├── compile
│ │ └── default-compile
│ │ │ ├── createdFiles.lst
│ │ │ └── inputFiles.lst
│ │ └── testCompile
│ │ └── default-testCompile
│ │ ├── createdFiles.lst
│ │ └── inputFiles.lst
│ └── test-classes
│ └── com
│ └── apress
│ ├── ExampleTest.class
│ ├── QuickPollApplicationTests.class
│ ├── UserGenerator.class
│ ├── it
│ └── PollControllerIT.class
│ └── unit
│ ├── PollControllerTest.class
│ └── PollControllerTestMock.class
├── Contributing.md
├── LICENSE.txt
├── README.md
└── errata.md
/9781484274767.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/9781484274767.jpg
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/QuickPollApplication.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class QuickPollApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(QuickPollApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/controller/VoteController.java:
--------------------------------------------------------------------------------
1 | package com.apress.controller;
2 |
3 | import javax.inject.Inject;
4 |
5 | import org.springframework.http.HttpHeaders;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.http.ResponseEntity;
8 | import org.springframework.web.bind.annotation.PathVariable;
9 | import org.springframework.web.bind.annotation.RequestBody;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.bind.annotation.RequestMethod;
12 | import org.springframework.web.bind.annotation.RestController;
13 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
14 |
15 | import com.apress.domain.Vote;
16 | import com.apress.repository.VoteRepository;
17 |
18 | @RestController
19 | public class VoteController {
20 |
21 | @Inject
22 | private VoteRepository voteRepository;
23 |
24 | @RequestMapping(value="/polls/{pollId}/votes", method=RequestMethod.POST)
25 | public ResponseEntity> createVote(@PathVariable Long pollId, @RequestBody Vote vote) {
26 | vote = voteRepository.save(vote);
27 |
28 | // Set the headers for the newly created resource
29 | HttpHeaders responseHeaders = new HttpHeaders();
30 | responseHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
31 |
32 | return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
33 | }
34 |
35 | @RequestMapping(value="/polls/{pollId}/votes", method=RequestMethod.GET)
36 | public Iterable getAllVotes(@PathVariable Long pollId) {
37 | return voteRepository.findByPoll(pollId);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/domain/Option.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class Option {
10 |
11 | @Id
12 | @GeneratedValue
13 | @Column(name="OPTION_ID")
14 | private Long id;
15 |
16 | @Column(name="OPTION_VALUE")
17 | private String value;
18 |
19 | public Long getId() {
20 | return id;
21 | }
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 | public String getValue() {
26 | return value;
27 | }
28 | public void setValue(String value) {
29 | this.value = value;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return getId() + "," + getValue();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/domain/Poll.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import org.springframework.hateoas.RepresentationModel;
4 |
5 | import java.util.Set;
6 |
7 | import javax.persistence.CascadeType;
8 | import javax.persistence.Column;
9 | import javax.persistence.Entity;
10 | import javax.persistence.GeneratedValue;
11 | import javax.persistence.Id;
12 | import javax.persistence.JoinColumn;
13 | import javax.persistence.OneToMany;
14 | import javax.persistence.OrderBy;
15 |
16 |
17 | @Entity
18 | public class Poll extends RepresentationModel {
19 |
20 | @Id
21 | @GeneratedValue
22 | @Column(name="POLL_ID")
23 | private Long id;
24 |
25 | @Column(name="QUESTION")
26 | private String question;
27 |
28 | @OneToMany(cascade=CascadeType.ALL)
29 | @JoinColumn(name="POLL_ID")
30 | @OrderBy
31 | private Set options;
32 |
33 | public Long getPollId() {
34 | return id;
35 | }
36 | public void setPollId(Long id) {
37 | this.id = id;
38 | }
39 | public String getQuestion() {
40 | return question;
41 | }
42 | public void setQuestion(String question) {
43 | this.question = question;
44 | }
45 | public Set getOptions() {
46 | return options;
47 | }
48 | public void setOptions(Set options) {
49 | this.options = options;
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return getPollId() + ", " + getQuestion() + ", " + getOptions();
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/domain/Vote.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 | import javax.persistence.JoinColumn;
8 | import javax.persistence.ManyToOne;
9 |
10 | @Entity
11 | public class Vote {
12 |
13 | @Id
14 | @GeneratedValue
15 | @Column(name="VOTE_ID")
16 | private Long id;
17 |
18 | @ManyToOne
19 | @JoinColumn(name="OPTION_ID")
20 | private Option option;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 | public void setId(Long id) {
26 | this.id = id;
27 | }
28 | public Option getOption() {
29 | return option;
30 | }
31 | public void setOption(Option option) {
32 | this.option = option;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return getId() + ", " + getOption();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/dto/OptionCount.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | public class OptionCount {
4 | private Long optionId;
5 | private int count;
6 |
7 | public Long getOptionId() {
8 | return optionId;
9 | }
10 | public void setOptionId(Long optionId) {
11 | this.optionId = optionId;
12 | }
13 | public int getCount() {
14 | return count;
15 | }
16 | public void setCount(int count) {
17 | this.count = count;
18 | }
19 | }
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/dto/VoteResult.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | import java.util.Collection;
4 |
5 | public class VoteResult {
6 |
7 | private int totalVotes;
8 | private Collection results;
9 |
10 | public int getTotalVotes() {
11 | return totalVotes;
12 | }
13 | public void setTotalVotes(int totalVotes) {
14 | this.totalVotes = totalVotes;
15 | }
16 | public Collection getResults() {
17 | return results;
18 | }
19 | public void setResults(Collection results) {
20 | this.results = results;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/repository/OptionRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Option;
6 |
7 | public interface OptionRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/repository/PollRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Poll;
6 |
7 | public interface PollRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/java/com/apress/repository/VoteRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 |
4 | import org.springframework.data.jpa.repository.Query;
5 | import org.springframework.data.repository.CrudRepository;
6 |
7 | import com.apress.domain.Vote;
8 |
9 | public interface VoteRepository extends CrudRepository {
10 |
11 | @Query(value="select v.* from Option o, Vote v where o.POLL_ID = ?1 and v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12 | public Iterable findByPoll(Long pollId);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/src/main/resources/application.properties
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/resources/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/src/main/resources/static/.keep
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/src/main/resources/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/src/main/resources/templates/.keep
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/application.properties
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/QuickPollApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/QuickPollApplication.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/controller/ComputeResultController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/controller/ComputeResultController.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/controller/PollController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/controller/PollController.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/controller/VoteController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/controller/VoteController.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/domain/Option.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/domain/Option.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/domain/Poll.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/domain/Poll.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/domain/Vote.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/domain/Vote.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/dto/OptionCount.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/dto/OptionCount.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/dto/VoteResult.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/dto/VoteResult.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/repository/OptionRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/repository/OptionRepository.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/repository/PollRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/repository/PollRepository.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/com/apress/repository/VoteRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/com/apress/repository/VoteRepository.class
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/static/.keep
--------------------------------------------------------------------------------
/Chapter10/quick-poll-ch10-final/target/classes/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter10/quick-poll-ch10-final/target/classes/templates/.keep
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.5.3
9 |
10 |
11 | com.appress
12 | hello-rest
13 | 0.0.1-SNAPSHOT
14 | Hello World REST
15 | Hello World REST Application Using Spring Boot
16 |
17 | 1.8
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-test
27 | test
28 |
29 |
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-maven-plugin
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/src/main/java/com/apress/hellorest/HelloWorldRestApplication.java:
--------------------------------------------------------------------------------
1 | package com.apress.hellorest;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.web.bind.annotation.RestController;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 |
8 | @SpringBootApplication
9 | @RestController
10 | public class HelloWorldRestApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(HelloWorldRestApplication.class, args);
14 | }
15 |
16 | @RequestMapping("/greet")
17 | public String helloGreeting() {
18 | return "Hello REST";
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter3/hello-rest-ch3-final/src/main/resources/application.properties
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/src/main/resources/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter3/hello-rest-ch3-final/src/main/resources/static/.keep
--------------------------------------------------------------------------------
/Chapter3/hello-rest-ch3-final/src/main/resources/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter3/hello-rest-ch3-final/src/main/resources/templates/.keep
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/QuickPollApplication.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class QuickPollApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(QuickPollApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/controller/ComputeResultController.java:
--------------------------------------------------------------------------------
1 | package com.apress.controller;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import javax.inject.Inject;
7 |
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.web.bind.annotation.GetMapping;
11 | import org.springframework.web.bind.annotation.RequestParam;
12 | import org.springframework.web.bind.annotation.RestController;
13 |
14 | import com.apress.domain.Vote;
15 | import com.apress.dto.OptionCount;
16 | import com.apress.dto.VoteResult;
17 | import com.apress.repository.VoteRepository;
18 |
19 | @RestController
20 | public class ComputeResultController {
21 |
22 | @Inject
23 | private VoteRepository voteRepository;
24 |
25 |
26 | @GetMapping("/computeresult")
27 | public ResponseEntity> computeResult(@RequestParam Long pollId) {
28 | VoteResult voteResult = new VoteResult();
29 | Iterable allVotes = voteRepository.findByPoll(pollId);
30 |
31 | // Algorithm to count votes
32 | int totalVotes = 0;
33 | Map tempMap = new HashMap();
34 | for(Vote v : allVotes) {
35 | totalVotes ++;
36 | // Get the OptionCount corresponding to this Option
37 | OptionCount optionCount = tempMap.get(v.getOption().getId());
38 | if(optionCount == null) {
39 | optionCount = new OptionCount();
40 | optionCount.setOptionId(v.getOption().getId());
41 | tempMap.put(v.getOption().getId(), optionCount);
42 | }
43 | optionCount.setCount(optionCount.getCount()+1);
44 | }
45 |
46 | voteResult.setTotalVotes(totalVotes);
47 | voteResult.setResults(tempMap.values());
48 |
49 | return new ResponseEntity<>(voteResult, HttpStatus.OK);
50 | }
51 | }
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/controller/VoteController.java:
--------------------------------------------------------------------------------
1 | package com.apress.controller;
2 |
3 | import javax.inject.Inject;
4 |
5 | import org.springframework.http.HttpHeaders;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.http.ResponseEntity;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.PostMapping;
11 | import org.springframework.web.bind.annotation.RequestBody;
12 | import org.springframework.web.bind.annotation.RestController;
13 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
14 |
15 | import com.apress.domain.Vote;
16 | import com.apress.repository.VoteRepository;
17 |
18 | @RestController
19 | public class VoteController {
20 |
21 | @Inject
22 | private VoteRepository voteRepository;
23 |
24 | @PostMapping("/polls/{pollId}/votes")
25 | public ResponseEntity> createVote(@PathVariable Long pollId, @RequestBody Vote vote) {
26 | vote = voteRepository.save(vote);
27 |
28 | // Set the headers for the newly created resource
29 | HttpHeaders responseHeaders = new HttpHeaders();
30 | responseHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
31 |
32 | return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
33 | }
34 |
35 | @GetMapping("/polls/{pollId}/votes")
36 | public Iterable getAllVotes(@PathVariable Long pollId) {
37 | return voteRepository.findByPoll(pollId);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/domain/Option.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class Option {
10 |
11 | @Id
12 | @GeneratedValue
13 | @Column(name="OPTION_ID")
14 | private Long id;
15 |
16 | @Column(name="OPTION_VALUE")
17 | private String value;
18 |
19 | public Long getId() {
20 | return id;
21 | }
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 | public String getValue() {
26 | return value;
27 | }
28 | public void setValue(String value) {
29 | this.value = value;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return getId() + "," + getValue();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/domain/Poll.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.CascadeType;
6 | import javax.persistence.Column;
7 | import javax.persistence.Entity;
8 | import javax.persistence.GeneratedValue;
9 | import javax.persistence.Id;
10 | import javax.persistence.JoinColumn;
11 | import javax.persistence.OneToMany;
12 | import javax.persistence.OrderBy;
13 |
14 | @Entity
15 | public class Poll {
16 |
17 | @Id
18 | @GeneratedValue
19 | @Column(name="POLL_ID")
20 | private Long id;
21 |
22 | @Column(name="QUESTION")
23 | private String question;
24 |
25 | @OneToMany(cascade=CascadeType.ALL)
26 | @JoinColumn(name="POLL_ID")
27 | @OrderBy
28 | private Set options;
29 |
30 | public Long getId() {
31 | return id;
32 | }
33 | public void setId(Long id) {
34 | this.id = id;
35 | }
36 | public String getQuestion() {
37 | return question;
38 | }
39 | public void setQuestion(String question) {
40 | this.question = question;
41 | }
42 | public Set getOptions() {
43 | return options;
44 | }
45 | public void setOptions(Set options) {
46 | this.options = options;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return getId() + ", " + getQuestion() + ", " + getOptions();
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/domain/Vote.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 | import javax.persistence.JoinColumn;
8 | import javax.persistence.ManyToOne;
9 |
10 | @Entity
11 | public class Vote {
12 |
13 | @Id
14 | @GeneratedValue
15 | @Column(name="VOTE_ID")
16 | private Long id;
17 |
18 | @ManyToOne
19 | @JoinColumn(name="OPTION_ID")
20 | private Option option;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 | public void setId(Long id) {
26 | this.id = id;
27 | }
28 | public Option getOption() {
29 | return option;
30 | }
31 | public void setOption(Option option) {
32 | this.option = option;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return getId() + ", " + getOption();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/dto/OptionCount.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | public class OptionCount {
4 | private Long optionId;
5 | private int count;
6 |
7 | public Long getOptionId() {
8 | return optionId;
9 | }
10 | public void setOptionId(Long optionId) {
11 | this.optionId = optionId;
12 | }
13 | public int getCount() {
14 | return count;
15 | }
16 | public void setCount(int count) {
17 | this.count = count;
18 | }
19 | }
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/dto/VoteResult.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | import java.util.Collection;
4 |
5 | public class VoteResult {
6 |
7 | private int totalVotes;
8 | private Collection results;
9 |
10 | public int getTotalVotes() {
11 | return totalVotes;
12 | }
13 | public void setTotalVotes(int totalVotes) {
14 | this.totalVotes = totalVotes;
15 | }
16 | public Collection getResults() {
17 | return results;
18 | }
19 | public void setResults(Collection results) {
20 | this.results = results;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/repository/OptionRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Option;
6 |
7 | public interface OptionRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/repository/PollRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Poll;
6 |
7 | public interface PollRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/java/com/apress/repository/VoteRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 |
4 | import org.springframework.data.jpa.repository.Query;
5 | import org.springframework.data.repository.CrudRepository;
6 |
7 | import com.apress.domain.Vote;
8 |
9 | public interface VoteRepository extends CrudRepository {
10 |
11 | @Query(value="select v.* from Option o, Vote v where o.POLL_ID = ?1 and v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12 | public Iterable findByPoll(Long pollId);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/src/main/resources/application.properties
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/resources/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/src/main/resources/static/.keep
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/src/main/resources/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/src/main/resources/templates/.keep
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/application.properties
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/QuickPollApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/QuickPollApplication.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/controller/ComputeResultController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/controller/ComputeResultController.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/controller/PollController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/controller/PollController.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/controller/VoteController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/controller/VoteController.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/domain/Option.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/domain/Option.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/domain/Poll.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/domain/Poll.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/domain/Vote.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/domain/Vote.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/dto/OptionCount.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/dto/OptionCount.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/dto/VoteResult.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/dto/VoteResult.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/repository/OptionRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/repository/OptionRepository.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/repository/PollRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/repository/PollRepository.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/com/apress/repository/VoteRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/com/apress/repository/VoteRepository.class
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/static/.keep
--------------------------------------------------------------------------------
/Chapter4/quick-poll-ch4-final/target/classes/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter4/quick-poll-ch4-final/target/classes/templates/.keep
--------------------------------------------------------------------------------
/Chapter5/Chapter_5_Postman_Collection.json:
--------------------------------------------------------------------------------
1 | {"id":"80fe1be8-912d-b703-9d3a-9d459ce7c086","name":"Chapter 5","timestamp":1422334412764,"requests":[{"collectionId":"80fe1be8-912d-b703-9d3a-9d459ce7c086","id":"65becda4-5075-c8d9-b960-1e81946ee3a8","name":"Create Poll - Missing Question","description":"","url":"http://localhost:8080/polls","method":"POST","headers":"Content-Type: application/json\n","data":"{\n\t\"options\" : [ \n {\"value\" : \"New England Patriots\"}, \n {\"value\" : \"Seattle Seahawks\"}, \n \t\t\t {\"value\" : \"Green Bay Packers\"}, \n \t\t\t {\"value\" : \"Denver Broncos\"} \n ]\n}","dataMode":"raw","timestamp":0,"version":2},{"collectionId":"80fe1be8-912d-b703-9d3a-9d459ce7c086","id":"88beea9b-5638-9c9b-c452-f2517ad0e80a","name":"Non Existent Poll","description":"","url":"http://localhost:8080/polls/100","method":"GET","headers":"","data":"{\n \"option\": { \"id\": 1, \"value\": \"Yes\" }\n}\n","dataMode":"raw","timestamp":0,"version":2},{"collectionId":"80fe1be8-912d-b703-9d3a-9d459ce7c086","id":"eb0598c7-502a-1814-e6a6-85f33fde4a3e","name":"Malformed Request","description":"Request with a missing ,","url":"http://localhost:8080/polls","method":"POST","headers":"Content-Type: application/json\n","data":"{\n\t\"question\" : \"Who will win SuperBowl this year?\",\n\t\"options\" : [ \n {\"value\" : \"New England Patriots\"}, \n {\"value\" : \"Seattle Seahawks\"}\n \t\t\t {\"value\" : \"Green Bay Packers\"}, \n \t\t\t {\"value\" : \"Denver Broncos\"} \n ]\n}","dataMode":"raw","timestamp":0,"version":2}]}
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/quick-poll-ch4-final.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/QuickPollApplication.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class QuickPollApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(QuickPollApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/controller/ComputeResultController.java:
--------------------------------------------------------------------------------
1 | package com.apress.controller;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import javax.inject.Inject;
7 |
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.web.bind.annotation.GetMapping;
11 | import org.springframework.web.bind.annotation.RequestParam;
12 | import org.springframework.web.bind.annotation.RestController;
13 |
14 | import com.apress.domain.Vote;
15 | import com.apress.dto.OptionCount;
16 | import com.apress.dto.VoteResult;
17 | import com.apress.repository.VoteRepository;
18 |
19 | @RestController
20 | public class ComputeResultController {
21 |
22 | @Inject
23 | private VoteRepository voteRepository;
24 |
25 |
26 | @GetMapping("/computeresult")
27 | public ResponseEntity> computeResult(@RequestParam Long pollId) {
28 | VoteResult voteResult = new VoteResult();
29 | Iterable allVotes = voteRepository.findByPoll(pollId);
30 |
31 | // Algorithm to count votes
32 | int totalVotes = 0;
33 | Map tempMap = new HashMap();
34 | for(Vote v : allVotes) {
35 | totalVotes ++;
36 | // Get the OptionCount corresponding to this Option
37 | OptionCount optionCount = tempMap.get(v.getOption().getId());
38 | if(optionCount == null) {
39 | optionCount = new OptionCount();
40 | optionCount.setOptionId(v.getOption().getId());
41 | tempMap.put(v.getOption().getId(), optionCount);
42 | }
43 | optionCount.setCount(optionCount.getCount()+1);
44 | }
45 |
46 | voteResult.setTotalVotes(totalVotes);
47 | voteResult.setResults(tempMap.values());
48 |
49 | return new ResponseEntity<>(voteResult, HttpStatus.OK);
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/controller/VoteController.java:
--------------------------------------------------------------------------------
1 | package com.apress.controller;
2 |
3 | import javax.inject.Inject;
4 |
5 | import org.springframework.http.HttpHeaders;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.http.ResponseEntity;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.PostMapping;
11 | import org.springframework.web.bind.annotation.RequestBody;
12 | import org.springframework.web.bind.annotation.RestController;
13 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
14 |
15 | import com.apress.domain.Vote;
16 | import com.apress.repository.VoteRepository;
17 |
18 | @RestController
19 | public class VoteController {
20 |
21 | @Inject
22 | private VoteRepository voteRepository;
23 |
24 |
25 | @PostMapping("/polls/{pollId}/votes")
26 | public ResponseEntity> createVote(@PathVariable Long pollId, @RequestBody Vote vote) {
27 | vote = voteRepository.save(vote);
28 |
29 | // Set the headers for the newly created resource
30 | HttpHeaders responseHeaders = new HttpHeaders();
31 | responseHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
32 |
33 | return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
34 | }
35 |
36 | @GetMapping("/polls/{pollId}/votes")
37 | public Iterable getAllVotes(@PathVariable Long pollId) {
38 | return voteRepository.findByPoll(pollId);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/domain/Option.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class Option {
10 |
11 | @Id
12 | @GeneratedValue
13 | @Column(name="OPTION_ID")
14 | private Long id;
15 |
16 | @Column(name="OPTION_VALUE")
17 | private String value;
18 |
19 | public Long getId() {
20 | return id;
21 | }
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 | public String getValue() {
26 | return value;
27 | }
28 | public void setValue(String value) {
29 | this.value = value;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return getId() + "," + getValue();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/domain/Poll.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.CascadeType;
6 | import javax.persistence.Column;
7 | import javax.persistence.Entity;
8 | import javax.persistence.GeneratedValue;
9 | import javax.persistence.Id;
10 | import javax.persistence.JoinColumn;
11 | import javax.persistence.OneToMany;
12 | import javax.persistence.OrderBy;
13 | import javax.validation.constraints.NotEmpty;
14 | import javax.validation.constraints.Size;
15 |
16 |
17 | @Entity
18 | public class Poll {
19 |
20 | @Id
21 | @GeneratedValue
22 | @Column(name="POLL_ID")
23 | private Long id;
24 |
25 | @Column(name="QUESTION")
26 | @NotEmpty
27 | private String question;
28 |
29 | @OneToMany(cascade=CascadeType.ALL)
30 | @JoinColumn(name="POLL_ID")
31 | @OrderBy
32 | @Size(min=2, max = 6)
33 | private Set options;
34 |
35 | public Long getId() {
36 | return id;
37 | }
38 | public void setId(Long id) {
39 | this.id = id;
40 | }
41 | public String getQuestion() {
42 | return question;
43 | }
44 | public void setQuestion(String question) {
45 | this.question = question;
46 | }
47 | public Set getOptions() {
48 | return options;
49 | }
50 | public void setOptions(Set options) {
51 | this.options = options;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return getId() + ", " + getQuestion() + ", " + getOptions();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/domain/Vote.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 | import javax.persistence.JoinColumn;
8 | import javax.persistence.ManyToOne;
9 |
10 | @Entity
11 | public class Vote {
12 |
13 | @Id
14 | @GeneratedValue
15 | @Column(name="VOTE_ID")
16 | private Long id;
17 |
18 | @ManyToOne
19 | @JoinColumn(name="OPTION_ID")
20 | private Option option;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 | public void setId(Long id) {
26 | this.id = id;
27 | }
28 | public Option getOption() {
29 | return option;
30 | }
31 | public void setOption(Option option) {
32 | this.option = option;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return getId() + ", " + getOption();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/dto/OptionCount.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | public class OptionCount {
4 | private Long optionId;
5 | private int count;
6 |
7 | public Long getOptionId() {
8 | return optionId;
9 | }
10 | public void setOptionId(Long optionId) {
11 | this.optionId = optionId;
12 | }
13 | public int getCount() {
14 | return count;
15 | }
16 | public void setCount(int count) {
17 | this.count = count;
18 | }
19 | }
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/dto/VoteResult.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | import java.util.Collection;
4 |
5 | public class VoteResult {
6 |
7 | private int totalVotes;
8 | private Collection results;
9 |
10 | public int getTotalVotes() {
11 | return totalVotes;
12 | }
13 | public void setTotalVotes(int totalVotes) {
14 | this.totalVotes = totalVotes;
15 | }
16 | public Collection getResults() {
17 | return results;
18 | }
19 | public void setResults(Collection results) {
20 | this.results = results;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/dto/error/ErrorDetail.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class ErrorDetail {
8 |
9 | private String title;
10 | private int status;
11 | private String detail;
12 | private long timeStamp;
13 | private String developerMessage;
14 | private Map> errors = new HashMap>();
15 |
16 | public Map> getErrors() {
17 | return errors;
18 | }
19 | public void setErrors(Map> errors) {
20 | this.errors = errors;
21 | }
22 | public String getTitle() {
23 | return title;
24 | }
25 | public void setTitle(String title) {
26 | this.title = title;
27 | }
28 | public int getStatus() {
29 | return status;
30 | }
31 | public void setStatus(int status) {
32 | this.status = status;
33 | }
34 | public String getDetail() {
35 | return detail;
36 | }
37 | public void setDetail(String detail) {
38 | this.detail = detail;
39 | }
40 | public long getTimeStamp() {
41 | return timeStamp;
42 | }
43 | public void setTimeStamp(long timeStamp) {
44 | this.timeStamp = timeStamp;
45 | }
46 | public String getDeveloperMessage() {
47 | return developerMessage;
48 | }
49 | public void setDeveloperMessage(String developerMessage) {
50 | this.developerMessage = developerMessage;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/dto/error/ValidationError.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | public class ValidationError {
4 |
5 | private String code;
6 | private String message;
7 |
8 | public String getCode() {
9 | return code;
10 | }
11 | public void setCode(String code) {
12 | this.code = code;
13 | }
14 | public String getMessage() {
15 | return message;
16 | }
17 | public void setMessage(String message) {
18 | this.message = message;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/exception/ResourceNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.apress.exception;
2 |
3 | import org.springframework.http.HttpStatus;
4 | import org.springframework.web.bind.annotation.ResponseStatus;
5 |
6 | @ResponseStatus(HttpStatus.NOT_FOUND)
7 | public class ResourceNotFoundException extends RuntimeException {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | public ResourceNotFoundException() {}
12 |
13 | public ResourceNotFoundException(String message) {
14 | super(message);
15 | }
16 |
17 | public ResourceNotFoundException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/repository/OptionRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Option;
6 |
7 | public interface OptionRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/repository/PollRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Poll;
6 |
7 | public interface PollRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/java/com/apress/repository/VoteRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 |
4 | import org.springframework.data.jpa.repository.Query;
5 | import org.springframework.data.repository.CrudRepository;
6 |
7 | import com.apress.domain.Vote;
8 |
9 | public interface VoteRepository extends CrudRepository {
10 |
11 | @Query(value="select v.* from Option o, Vote v where o.POLL_ID = ?1 and v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12 | public Iterable findByPoll(Long pollId);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.messages.basename=messages
2 | spring.messages.cache-seconds=-1
3 | spring.messages.encoding=UTF-8
4 |
5 | #logging.level.org.springframework.web: DEBUG
6 | #logging.level.org.springframework: DEBUG
7 | #logging.level.org.hibernate: DEBUG
8 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | NotEmpty.poll.question=Question is a required field
2 | Size.poll.options=Options must be greater than {2} and less than {1}
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/resources/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter5/quick-poll-ch5-final/src/main/resources/static/.keep
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/src/main/resources/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter5/quick-poll-ch5-final/src/main/resources/templates/.keep
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/target/classes/application.properties:
--------------------------------------------------------------------------------
1 | spring.messages.basename=messages
2 | spring.messages.cache-seconds=-1
3 | spring.messages.encoding=UTF-8
4 |
5 | #logging.level.org.springframework.web: DEBUG
6 | #logging.level.org.springframework: DEBUG
7 | #logging.level.org.hibernate: DEBUG
8 |
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/target/classes/messages.properties:
--------------------------------------------------------------------------------
1 | NotEmpty.poll.question=Question is a required field
2 | Size.poll.options=Options must be greater than {2} and less than {1}
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/target/classes/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter5/quick-poll-ch5-final/target/classes/static/.keep
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/target/classes/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter5/quick-poll-ch5-final/target/classes/templates/.keep
--------------------------------------------------------------------------------
/Chapter5/quick-poll-ch5-final/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter5/quick-poll-ch5-final/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/QuickPollApplication.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class QuickPollApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(QuickPollApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/SwaggerConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import springfox.documentation.builders.PathSelectors;
6 | import springfox.documentation.builders.RequestHandlerSelectors;
7 | import springfox.documentation.service.ApiInfo;
8 | import springfox.documentation.service.Contact;
9 | import springfox.documentation.spi.DocumentationType;
10 | import springfox.documentation.spring.web.plugins.Docket;
11 | import java.util.Collections;
12 |
13 |
14 | @Configuration
15 | public class SwaggerConfiguration {
16 |
17 | @Bean
18 | public Docket api() {
19 | return new Docket(DocumentationType.SWAGGER_2)
20 | .select()
21 | .apis(RequestHandlerSelectors.basePackage("com.apress.controller"))
22 | .paths(PathSelectors.regex("/polls/*.*|/votes/*.*|/computeresult/*.*"))
23 | .build()
24 | .apiInfo(apiInfo());
25 | }
26 |
27 | private ApiInfo apiInfo() {
28 | return new ApiInfo(
29 | "QuickPoll REST API",
30 | "QuickPoll Api for creating and managing polls",
31 | "http://example.com/terms-of-service",
32 | "Terms of service",
33 | new Contact("Maxim Bartkov", "www.example.com", "info@example.com"),
34 | "MIT License", "http://opensource.org/licenses/MIT", Collections.emptyList());
35 | }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/domain/Option.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class Option {
10 |
11 | @Id
12 | @GeneratedValue
13 | @Column(name="OPTION_ID")
14 | private Long id;
15 |
16 | @Column(name="OPTION_VALUE")
17 | private String value;
18 |
19 | public Long getId() {
20 | return id;
21 | }
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 | public String getValue() {
26 | return value;
27 | }
28 | public void setValue(String value) {
29 | this.value = value;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return getId() + "," + getValue();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/domain/Poll.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.CascadeType;
6 | import javax.persistence.Column;
7 | import javax.persistence.Entity;
8 | import javax.persistence.GeneratedValue;
9 | import javax.persistence.Id;
10 | import javax.persistence.JoinColumn;
11 | import javax.persistence.OneToMany;
12 | import javax.persistence.OrderBy;
13 | import javax.validation.constraints.NotEmpty;
14 | import javax.validation.constraints.Size;
15 |
16 | @Entity
17 | public class Poll {
18 |
19 | @Id
20 | @GeneratedValue
21 | @Column(name="POLL_ID")
22 | private Long id;
23 |
24 | @Column(name="QUESTION")
25 | @NotEmpty
26 | private String question;
27 |
28 | @OneToMany(cascade=CascadeType.ALL)
29 | @JoinColumn(name="POLL_ID")
30 | @OrderBy
31 | @Size(min=2, max = 6)
32 | private Set options;
33 |
34 | public Long getId() {
35 | return id;
36 | }
37 | public void setId(Long id) {
38 | this.id = id;
39 | }
40 | public String getQuestion() {
41 | return question;
42 | }
43 | public void setQuestion(String question) {
44 | this.question = question;
45 | }
46 | public Set getOptions() {
47 | return options;
48 | }
49 | public void setOptions(Set options) {
50 | this.options = options;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return getId() + ", " + getQuestion() + ", " + getOptions();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/domain/Vote.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 | import javax.persistence.JoinColumn;
8 | import javax.persistence.ManyToOne;
9 |
10 | @Entity
11 | public class Vote {
12 |
13 | @Id
14 | @GeneratedValue
15 | @Column(name="VOTE_ID")
16 | private Long id;
17 |
18 | @ManyToOne
19 | @JoinColumn(name="OPTION_ID")
20 | private Option option;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 | public void setId(Long id) {
26 | this.id = id;
27 | }
28 | public Option getOption() {
29 | return option;
30 | }
31 | public void setOption(Option option) {
32 | this.option = option;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return getId() + ", " + getOption();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/dto/OptionCount.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | public class OptionCount {
4 | private Long optionId;
5 | private int count;
6 |
7 | public Long getOptionId() {
8 | return optionId;
9 | }
10 | public void setOptionId(Long optionId) {
11 | this.optionId = optionId;
12 | }
13 | public int getCount() {
14 | return count;
15 | }
16 | public void setCount(int count) {
17 | this.count = count;
18 | }
19 | }
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/dto/VoteResult.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | import java.util.Collection;
4 |
5 | public class VoteResult {
6 |
7 | private int totalVotes;
8 | private Collection results;
9 |
10 | public int getTotalVotes() {
11 | return totalVotes;
12 | }
13 | public void setTotalVotes(int totalVotes) {
14 | this.totalVotes = totalVotes;
15 | }
16 | public Collection getResults() {
17 | return results;
18 | }
19 | public void setResults(Collection results) {
20 | this.results = results;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/dto/error/ErrorDetail.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class ErrorDetail {
8 |
9 | private String title;
10 | private int status;
11 | private String detail;
12 | private long timeStamp;
13 | private String developerMessage;
14 | private Map> errors = new HashMap>();
15 |
16 | public Map> getErrors() {
17 | return errors;
18 | }
19 | public void setErrors(Map> errors) {
20 | this.errors = errors;
21 | }
22 | public String getTitle() {
23 | return title;
24 | }
25 | public void setTitle(String title) {
26 | this.title = title;
27 | }
28 | public int getStatus() {
29 | return status;
30 | }
31 | public void setStatus(int status) {
32 | this.status = status;
33 | }
34 | public String getDetail() {
35 | return detail;
36 | }
37 | public void setDetail(String detail) {
38 | this.detail = detail;
39 | }
40 | public long getTimeStamp() {
41 | return timeStamp;
42 | }
43 | public void setTimeStamp(long timeStamp) {
44 | this.timeStamp = timeStamp;
45 | }
46 | public String getDeveloperMessage() {
47 | return developerMessage;
48 | }
49 | public void setDeveloperMessage(String developerMessage) {
50 | this.developerMessage = developerMessage;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/dto/error/ValidationError.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | public class ValidationError {
4 |
5 | private String code;
6 | private String message;
7 |
8 | public String getCode() {
9 | return code;
10 | }
11 | public void setCode(String code) {
12 | this.code = code;
13 | }
14 | public String getMessage() {
15 | return message;
16 | }
17 | public void setMessage(String message) {
18 | this.message = message;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/exception/ResourceNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.apress.exception;
2 |
3 | import org.springframework.http.HttpStatus;
4 | import org.springframework.web.bind.annotation.ResponseStatus;
5 |
6 | @ResponseStatus(HttpStatus.NOT_FOUND)
7 | public class ResourceNotFoundException extends RuntimeException {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | public ResourceNotFoundException() {}
12 |
13 | public ResourceNotFoundException(String message) {
14 | super(message);
15 | }
16 |
17 | public ResourceNotFoundException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/repository/OptionRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Option;
6 |
7 | public interface OptionRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/repository/PollRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Poll;
6 |
7 | public interface PollRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/java/com/apress/repository/VoteRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 |
4 | import org.springframework.data.jpa.repository.Query;
5 | import org.springframework.data.repository.CrudRepository;
6 |
7 | import com.apress.domain.Vote;
8 |
9 | public interface VoteRepository extends CrudRepository {
10 |
11 | @Query(value="select v.* from Option o, Vote v where o.POLL_ID = ?1 and v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12 | public Iterable findByPoll(Long pollId);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.messages.basename=messages
2 | spring.messages.cache-seconds=-1
3 | spring.messages.encoding=UTF-8
4 |
5 | #logging.level.org.springframework.web: DEBUG
6 | #logging.level.org.springframework: DEBUG
7 | #logging.level.org.hibernate: DEBUG
8 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | NotEmpty.poll.question=Question is a required field
2 | Size.poll.options=Options must be greater than {2} and less than {1}
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter6/quick-poll-ch6-final/src/main/resources/static/.keep
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/css/reset.css:
--------------------------------------------------------------------------------
1 | /* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 */
2 | html,
3 | body,
4 | div,
5 | span,
6 | applet,
7 | object,
8 | iframe,
9 | h1,
10 | h2,
11 | h3,
12 | h4,
13 | h5,
14 | h6,
15 | p,
16 | blockquote,
17 | pre,
18 | a,
19 | abbr,
20 | acronym,
21 | address,
22 | big,
23 | cite,
24 | code,
25 | del,
26 | dfn,
27 | em,
28 | img,
29 | ins,
30 | kbd,
31 | q,
32 | s,
33 | samp,
34 | small,
35 | strike,
36 | strong,
37 | sub,
38 | sup,
39 | tt,
40 | var,
41 | b,
42 | u,
43 | i,
44 | center,
45 | dl,
46 | dt,
47 | dd,
48 | ol,
49 | ul,
50 | li,
51 | fieldset,
52 | form,
53 | label,
54 | legend,
55 | table,
56 | caption,
57 | tbody,
58 | tfoot,
59 | thead,
60 | tr,
61 | th,
62 | td,
63 | article,
64 | aside,
65 | canvas,
66 | details,
67 | embed,
68 | figure,
69 | figcaption,
70 | footer,
71 | header,
72 | hgroup,
73 | menu,
74 | nav,
75 | output,
76 | ruby,
77 | section,
78 | summary,
79 | time,
80 | mark,
81 | audio,
82 | video {
83 | margin: 0;
84 | padding: 0;
85 | border: 0;
86 | font-size: 100%;
87 | font: inherit;
88 | vertical-align: baseline;
89 | }
90 | /* HTML5 display-role reset for older browsers */
91 | article,
92 | aside,
93 | details,
94 | figcaption,
95 | figure,
96 | footer,
97 | header,
98 | hgroup,
99 | menu,
100 | nav,
101 | section {
102 | display: block;
103 | }
104 | body {
105 | line-height: 1;
106 | }
107 | ol,
108 | ul {
109 | list-style: none;
110 | }
111 | blockquote,
112 | q {
113 | quotes: none;
114 | }
115 | blockquote:before,
116 | blockquote:after,
117 | q:before,
118 | q:after {
119 | content: '';
120 | content: none;
121 | }
122 | table {
123 | border-collapse: collapse;
124 | border-spacing: 0;
125 | }
126 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/explorer_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/explorer_icons.png
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/logo_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/logo_small.png
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/pet_store_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/pet_store_api.png
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/throbber.gif
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/wordnik_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/images/wordnik_api.png
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/lib/jquery.slideto.min.js:
--------------------------------------------------------------------------------
1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery);
2 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/lib/jquery.wiggle.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | jQuery Wiggle
3 | Author: WonderGroup, Jordan Thomas
4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html
5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License)
6 | */
7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);}
8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});};
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/static/swagger-ui/o2c.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/main/resources/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter6/quick-poll-ch6-final/src/main/resources/templates/.keep
--------------------------------------------------------------------------------
/Chapter6/quick-poll-ch6-final/src/test/java/com/apress/QuickPollApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.SpringApplicationConfiguration;
6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7 | import org.springframework.test.context.web.WebAppConfiguration;
8 |
9 | @RunWith(SpringJUnit4ClassRunner.class)
10 | @SpringApplicationConfiguration(classes = QuickPollApplication.class)
11 | @WebAppConfiguration
12 | public class QuickPollApplicationTests {
13 |
14 | @Test
15 | public void contextLoads() {
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/QuickPollApplication.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class QuickPollApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(QuickPollApplication.class, args);
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/QuickPollMvcConfigAdapter.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import java.util.List;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.data.domain.PageRequest;
6 | import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
7 | import org.springframework.web.method.support.HandlerMethodArgumentResolver;
8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
9 |
10 | @Configuration
11 | public class QuickPollMvcConfigAdapter implements WebMvcConfigurer {
12 | @Override
13 |
14 | public void addArgumentResolvers(List argumentResolvers) {
15 |
16 | PageableHandlerMethodArgumentResolver phmar = new PageableHandlerMethodArgumentResolver();
17 | // Set the default size to 5
18 | phmar.setFallbackPageable(PageRequest.of(0, 5));
19 | argumentResolvers.add(phmar);
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/SwaggerConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import springfox.documentation.builders.PathSelectors;
6 | import springfox.documentation.builders.RequestHandlerSelectors;
7 | import springfox.documentation.service.ApiInfo;
8 | import springfox.documentation.service.Contact;
9 | import springfox.documentation.spi.DocumentationType;
10 | import springfox.documentation.spring.web.plugins.Docket;
11 | import java.util.Collections;
12 |
13 |
14 | @Configuration
15 | public class SwaggerConfiguration {
16 |
17 | @Bean
18 | public Docket apiV1() {
19 | return new Docket(DocumentationType.SWAGGER_2)
20 | .select()
21 | .apis(RequestHandlerSelectors.any())
22 | .paths(PathSelectors.regex("/v1/*.*"))
23 | .build()
24 | .apiInfo(apiInfo("v1"))
25 | .groupName("v1")
26 | .useDefaultResponseMessages(false);
27 | }
28 |
29 | @Bean
30 | public Docket apiV2() {
31 | return new Docket(DocumentationType.SWAGGER_2)
32 | .select()
33 | .apis(RequestHandlerSelectors.any())
34 | .paths(PathSelectors.regex("/v2/*.*"))
35 | .build()
36 | .apiInfo(apiInfo("v2"))
37 | .groupName("v2")
38 | .useDefaultResponseMessages(false);
39 | }
40 |
41 | private ApiInfo apiInfo(String version) {
42 | return new ApiInfo(
43 | "QuickPoll REST API",
44 | "QuickPoll Api for creating and managing polls",
45 | version,
46 | "Terms of service",
47 | new Contact("Maxim Bartkov", "www.linkedin.com/in/bartkov-maxim", "maxgalayoutop@gmail.com"),
48 | "MIT License", "http://opensource.org/licenses/MIT", Collections.emptyList());
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/domain/Option.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class Option {
10 |
11 | @Id
12 | @GeneratedValue
13 | @Column(name="OPTION_ID")
14 | private Long id;
15 |
16 | @Column(name="OPTION_VALUE")
17 | private String value;
18 |
19 | public Long getId() {
20 | return id;
21 | }
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 | public String getValue() {
26 | return value;
27 | }
28 | public void setValue(String value) {
29 | this.value = value;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return getId() + "," + getValue();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/domain/Poll.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.CascadeType;
6 | import javax.persistence.Column;
7 | import javax.persistence.Entity;
8 | import javax.persistence.GeneratedValue;
9 | import javax.persistence.Id;
10 | import javax.persistence.JoinColumn;
11 | import javax.persistence.OneToMany;
12 | import javax.persistence.OrderBy;
13 | import javax.validation.constraints.NotEmpty;
14 | import javax.validation.constraints.Size;
15 |
16 | @Entity
17 | public class Poll {
18 |
19 | @Id
20 | @GeneratedValue
21 | @Column(name="POLL_ID")
22 | private Long id;
23 |
24 | @Column(name="QUESTION")
25 | @NotEmpty
26 | private String question;
27 |
28 | @OneToMany(cascade=CascadeType.ALL)
29 | @JoinColumn(name="POLL_ID")
30 | @OrderBy
31 | @Size(min=2, max = 6)
32 | private Set options;
33 |
34 | public Long getId() {
35 | return id;
36 | }
37 | public void setId(Long id) {
38 | this.id = id;
39 | }
40 | public String getQuestion() {
41 | return question;
42 | }
43 | public void setQuestion(String question) {
44 | this.question = question;
45 | }
46 | public Set getOptions() {
47 | return options;
48 | }
49 | public void setOptions(Set options) {
50 | this.options = options;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return getId() + ", " + getQuestion() + ", " + getOptions();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/domain/Vote.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 | import javax.persistence.JoinColumn;
8 | import javax.persistence.ManyToOne;
9 |
10 | @Entity
11 | public class Vote {
12 |
13 | @Id
14 | @GeneratedValue
15 | @Column(name="VOTE_ID")
16 | private Long id;
17 |
18 | @ManyToOne
19 | @JoinColumn(name="OPTION_ID")
20 | private Option option;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 | public void setId(Long id) {
26 | this.id = id;
27 | }
28 | public Option getOption() {
29 | return option;
30 | }
31 | public void setOption(Option option) {
32 | this.option = option;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return getId() + ", " + getOption();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/dto/OptionCount.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | public class OptionCount {
4 | private Long optionId;
5 | private int count;
6 |
7 | public Long getOptionId() {
8 | return optionId;
9 | }
10 | public void setOptionId(Long optionId) {
11 | this.optionId = optionId;
12 | }
13 | public int getCount() {
14 | return count;
15 | }
16 | public void setCount(int count) {
17 | this.count = count;
18 | }
19 | }
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/dto/VoteResult.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | import java.util.Collection;
4 |
5 | public class VoteResult {
6 |
7 | private int totalVotes;
8 | private Collection results;
9 |
10 | public int getTotalVotes() {
11 | return totalVotes;
12 | }
13 | public void setTotalVotes(int totalVotes) {
14 | this.totalVotes = totalVotes;
15 | }
16 | public Collection getResults() {
17 | return results;
18 | }
19 | public void setResults(Collection results) {
20 | this.results = results;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/dto/error/ErrorDetail.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class ErrorDetail {
8 |
9 | private String title;
10 | private int status;
11 | private String detail;
12 | private long timeStamp;
13 | private String developerMessage;
14 | private Map> errors = new HashMap>();
15 |
16 | public Map> getErrors() {
17 | return errors;
18 | }
19 | public void setErrors(Map> errors) {
20 | this.errors = errors;
21 | }
22 | public String getTitle() {
23 | return title;
24 | }
25 | public void setTitle(String title) {
26 | this.title = title;
27 | }
28 | public int getStatus() {
29 | return status;
30 | }
31 | public void setStatus(int status) {
32 | this.status = status;
33 | }
34 | public String getDetail() {
35 | return detail;
36 | }
37 | public void setDetail(String detail) {
38 | this.detail = detail;
39 | }
40 | public long getTimeStamp() {
41 | return timeStamp;
42 | }
43 | public void setTimeStamp(long timeStamp) {
44 | this.timeStamp = timeStamp;
45 | }
46 | public String getDeveloperMessage() {
47 | return developerMessage;
48 | }
49 | public void setDeveloperMessage(String developerMessage) {
50 | this.developerMessage = developerMessage;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/dto/error/ValidationError.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | public class ValidationError {
4 |
5 | private String code;
6 | private String message;
7 |
8 | public String getCode() {
9 | return code;
10 | }
11 | public void setCode(String code) {
12 | this.code = code;
13 | }
14 | public String getMessage() {
15 | return message;
16 | }
17 | public void setMessage(String message) {
18 | this.message = message;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/exception/ResourceNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.apress.exception;
2 |
3 | import org.springframework.http.HttpStatus;
4 | import org.springframework.web.bind.annotation.ResponseStatus;
5 |
6 | @ResponseStatus(HttpStatus.NOT_FOUND)
7 | public class ResourceNotFoundException extends RuntimeException {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | public ResourceNotFoundException() {}
12 |
13 | public ResourceNotFoundException(String message) {
14 | super(message);
15 | }
16 |
17 | public ResourceNotFoundException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/repository/OptionRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Option;
6 |
7 | public interface OptionRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/repository/PollRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.PagingAndSortingRepository;
4 |
5 | import com.apress.domain.Poll;
6 |
7 | public interface PollRepository extends PagingAndSortingRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/java/com/apress/repository/VoteRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 |
4 | import org.springframework.data.jpa.repository.Query;
5 | import org.springframework.data.repository.CrudRepository;
6 |
7 | import com.apress.domain.Vote;
8 |
9 | public interface VoteRepository extends CrudRepository {
10 |
11 | @Query(value="select v.* from Option o, Vote v where o.POLL_ID = ?1 and v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12 | public Iterable findByPoll(Long pollId);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.messages.basename=messages
2 | spring.messages.cache-seconds=-1
3 | spring.messages.encoding=UTF-8
4 |
5 | #logging.level.org.springframework.web: DEBUG
6 | #logging.level.org.springframework: DEBUG
7 | #logging.level.org.hibernate: DEBUG
8 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | NotEmpty.poll.question=Question is a required field
2 | Size.poll.options=Options must be greater than {2} and less than {1}
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter7/quick-poll-ch7-final/src/main/resources/static/.keep
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/css/reset.css:
--------------------------------------------------------------------------------
1 | /* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 */
2 | html,
3 | body,
4 | div,
5 | span,
6 | applet,
7 | object,
8 | iframe,
9 | h1,
10 | h2,
11 | h3,
12 | h4,
13 | h5,
14 | h6,
15 | p,
16 | blockquote,
17 | pre,
18 | a,
19 | abbr,
20 | acronym,
21 | address,
22 | big,
23 | cite,
24 | code,
25 | del,
26 | dfn,
27 | em,
28 | img,
29 | ins,
30 | kbd,
31 | q,
32 | s,
33 | samp,
34 | small,
35 | strike,
36 | strong,
37 | sub,
38 | sup,
39 | tt,
40 | var,
41 | b,
42 | u,
43 | i,
44 | center,
45 | dl,
46 | dt,
47 | dd,
48 | ol,
49 | ul,
50 | li,
51 | fieldset,
52 | form,
53 | label,
54 | legend,
55 | table,
56 | caption,
57 | tbody,
58 | tfoot,
59 | thead,
60 | tr,
61 | th,
62 | td,
63 | article,
64 | aside,
65 | canvas,
66 | details,
67 | embed,
68 | figure,
69 | figcaption,
70 | footer,
71 | header,
72 | hgroup,
73 | menu,
74 | nav,
75 | output,
76 | ruby,
77 | section,
78 | summary,
79 | time,
80 | mark,
81 | audio,
82 | video {
83 | margin: 0;
84 | padding: 0;
85 | border: 0;
86 | font-size: 100%;
87 | font: inherit;
88 | vertical-align: baseline;
89 | }
90 | /* HTML5 display-role reset for older browsers */
91 | article,
92 | aside,
93 | details,
94 | figcaption,
95 | figure,
96 | footer,
97 | header,
98 | hgroup,
99 | menu,
100 | nav,
101 | section {
102 | display: block;
103 | }
104 | body {
105 | line-height: 1;
106 | }
107 | ol,
108 | ul {
109 | list-style: none;
110 | }
111 | blockquote,
112 | q {
113 | quotes: none;
114 | }
115 | blockquote:before,
116 | blockquote:after,
117 | q:before,
118 | q:after {
119 | content: '';
120 | content: none;
121 | }
122 | table {
123 | border-collapse: collapse;
124 | border-spacing: 0;
125 | }
126 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/explorer_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/explorer_icons.png
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/logo_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/logo_small.png
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/pet_store_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/pet_store_api.png
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/throbber.gif
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/wordnik_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/images/wordnik_api.png
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/lib/jquery.slideto.min.js:
--------------------------------------------------------------------------------
1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery);
2 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/lib/jquery.wiggle.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | jQuery Wiggle
3 | Author: WonderGroup, Jordan Thomas
4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html
5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License)
6 | */
7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);}
8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});};
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/static/swagger-ui/o2c.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/main/resources/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter7/quick-poll-ch7-final/src/main/resources/templates/.keep
--------------------------------------------------------------------------------
/Chapter7/quick-poll-ch7-final/src/test/java/com/apress/QuickPollApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.SpringApplicationConfiguration;
6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7 | import org.springframework.test.context.web.WebAppConfiguration;
8 |
9 | @RunWith(SpringJUnit4ClassRunner.class)
10 | @SpringApplicationConfiguration(classes = QuickPollApplication.class)
11 | @WebAppConfiguration
12 | public class QuickPollApplicationTests {
13 |
14 | @Test
15 | public void contextLoads() {
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/QuickPollApplication.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class QuickPollApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(QuickPollApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/QuickPollMvcConfigAdapter.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import java.util.List;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.data.domain.PageRequest;
6 | import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
7 | import org.springframework.web.method.support.HandlerMethodArgumentResolver;
8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
9 |
10 | @Configuration
11 | public class QuickPollMvcConfigAdapter implements WebMvcConfigurer {
12 | @Override
13 |
14 | public void addArgumentResolvers(List argumentResolvers) {
15 |
16 | PageableHandlerMethodArgumentResolver phmar = new PageableHandlerMethodArgumentResolver();
17 | // Set the default size to 5
18 | phmar.setFallbackPageable(PageRequest.of(0, 5));
19 | argumentResolvers.add(phmar);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/domain/Option.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class Option {
10 |
11 | @Id
12 | @GeneratedValue
13 | @Column(name="OPTION_ID")
14 | private Long id;
15 |
16 | @Column(name="OPTION_VALUE")
17 | private String value;
18 |
19 | public Long getId() {
20 | return id;
21 | }
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 | public String getValue() {
26 | return value;
27 | }
28 | public void setValue(String value) {
29 | this.value = value;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return getId() + "," + getValue();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/domain/Poll.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.CascadeType;
6 | import javax.persistence.Column;
7 | import javax.persistence.Entity;
8 | import javax.persistence.GeneratedValue;
9 | import javax.persistence.Id;
10 | import javax.persistence.JoinColumn;
11 | import javax.persistence.OneToMany;
12 | import javax.persistence.OrderBy;
13 | import javax.validation.constraints.NotEmpty;
14 | import javax.validation.constraints.Size;
15 |
16 |
17 | @Entity
18 | public class Poll {
19 |
20 | @Id
21 | @GeneratedValue
22 | @Column(name="POLL_ID")
23 | private Long id;
24 |
25 | @Column(name="QUESTION")
26 | @NotEmpty
27 | private String question;
28 |
29 | @OneToMany(cascade=CascadeType.ALL)
30 | @JoinColumn(name="POLL_ID")
31 | @OrderBy
32 | @Size(min=2, max = 6)
33 | private Set options;
34 |
35 | public Long getId() {
36 | return id;
37 | }
38 | public void setId(Long id) {
39 | this.id = id;
40 | }
41 | public String getQuestion() {
42 | return question;
43 | }
44 | public void setQuestion(String question) {
45 | this.question = question;
46 | }
47 | public Set getOptions() {
48 | return options;
49 | }
50 | public void setOptions(Set options) {
51 | this.options = options;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return getId() + ", " + getQuestion() + ", " + getOptions();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/domain/Vote.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 | import javax.persistence.JoinColumn;
8 | import javax.persistence.ManyToOne;
9 |
10 | @Entity
11 | public class Vote {
12 |
13 | @Id
14 | @GeneratedValue
15 | @Column(name="VOTE_ID")
16 | private Long id;
17 |
18 | @ManyToOne
19 | @JoinColumn(name="OPTION_ID")
20 | private Option option;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 | public void setId(Long id) {
26 | this.id = id;
27 | }
28 | public Option getOption() {
29 | return option;
30 | }
31 | public void setOption(Option option) {
32 | this.option = option;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return getId() + ", " + getOption();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/dto/OptionCount.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | public class OptionCount {
4 | private Long optionId;
5 | private int count;
6 |
7 | public Long getOptionId() {
8 | return optionId;
9 | }
10 | public void setOptionId(Long optionId) {
11 | this.optionId = optionId;
12 | }
13 | public int getCount() {
14 | return count;
15 | }
16 | public void setCount(int count) {
17 | this.count = count;
18 | }
19 | }
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/dto/VoteResult.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | import java.util.Collection;
4 |
5 | public class VoteResult {
6 |
7 | private int totalVotes;
8 | private Collection results;
9 |
10 | public int getTotalVotes() {
11 | return totalVotes;
12 | }
13 | public void setTotalVotes(int totalVotes) {
14 | this.totalVotes = totalVotes;
15 | }
16 | public Collection getResults() {
17 | return results;
18 | }
19 | public void setResults(Collection results) {
20 | this.results = results;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/dto/error/ErrorDetail.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class ErrorDetail {
8 |
9 | private String title;
10 | private int status;
11 | private String detail;
12 | private long timeStamp;
13 | private String developerMessage;
14 | private Map> errors = new HashMap>();
15 |
16 | public Map> getErrors() {
17 | return errors;
18 | }
19 | public void setErrors(Map> errors) {
20 | this.errors = errors;
21 | }
22 | public String getTitle() {
23 | return title;
24 | }
25 | public void setTitle(String title) {
26 | this.title = title;
27 | }
28 | public int getStatus() {
29 | return status;
30 | }
31 | public void setStatus(int status) {
32 | this.status = status;
33 | }
34 | public String getDetail() {
35 | return detail;
36 | }
37 | public void setDetail(String detail) {
38 | this.detail = detail;
39 | }
40 | public long getTimeStamp() {
41 | return timeStamp;
42 | }
43 | public void setTimeStamp(long timeStamp) {
44 | this.timeStamp = timeStamp;
45 | }
46 | public String getDeveloperMessage() {
47 | return developerMessage;
48 | }
49 | public void setDeveloperMessage(String developerMessage) {
50 | this.developerMessage = developerMessage;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/dto/error/ValidationError.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | public class ValidationError {
4 |
5 | private String code;
6 | private String message;
7 |
8 | public String getCode() {
9 | return code;
10 | }
11 | public void setCode(String code) {
12 | this.code = code;
13 | }
14 | public String getMessage() {
15 | return message;
16 | }
17 | public void setMessage(String message) {
18 | this.message = message;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/exception/ResourceNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.apress.exception;
2 |
3 | import org.springframework.http.HttpStatus;
4 | import org.springframework.web.bind.annotation.ResponseStatus;
5 |
6 | @ResponseStatus(HttpStatus.NOT_FOUND)
7 | public class ResourceNotFoundException extends RuntimeException {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | public ResourceNotFoundException() {}
12 |
13 | public ResourceNotFoundException(String message) {
14 | super(message);
15 | }
16 |
17 | public ResourceNotFoundException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/repository/OptionRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.Option;
6 |
7 | public interface OptionRepository extends CrudRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/repository/PollRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.PagingAndSortingRepository;
4 |
5 | import com.apress.domain.Poll;
6 |
7 | public interface PollRepository extends PagingAndSortingRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.apress.domain.User;
6 |
7 | public interface UserRepository extends CrudRepository {
8 |
9 | User findByUsername(String username);
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/repository/VoteRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 |
4 | import org.springframework.data.jpa.repository.Query;
5 | import org.springframework.data.repository.CrudRepository;
6 |
7 | import com.apress.domain.Vote;
8 |
9 | public interface VoteRepository extends CrudRepository {
10 |
11 | @Query(value="select v.* from Option o, Vote v where o.POLL_ID = ?1 and v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12 | Iterable findByPoll(Long pollId);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/java/com/apress/security/QuickPollUserDetailsService.java:
--------------------------------------------------------------------------------
1 | package com.apress.security;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.inject.Inject;
7 |
8 | import org.springframework.security.core.GrantedAuthority;
9 | import org.springframework.security.core.authority.AuthorityUtils;
10 | import org.springframework.security.core.userdetails.UserDetails;
11 | import org.springframework.security.core.userdetails.UserDetailsService;
12 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
13 | import org.springframework.stereotype.Component;
14 |
15 | import com.apress.domain.User;
16 | import com.apress.repository.UserRepository;
17 |
18 | @Component
19 | public class QuickPollUserDetailsService implements UserDetailsService {
20 |
21 | @Inject
22 | private UserRepository userRepository;
23 |
24 | @Override
25 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
26 |
27 | User user = userRepository.findByUsername(username);
28 |
29 | if(user == null) {
30 | throw new UsernameNotFoundException(String.format("User with the username %s doesn't exist", username));
31 | }
32 |
33 | // Create a granted authority based on user's role.
34 | // Can't pass null authorities to user. Hence initialize with an empty arraylist
35 | List authorities = new ArrayList<>();
36 | if(user.isAdmin()) {
37 | authorities = AuthorityUtils.createAuthorityList("ROLE_ADMIN");
38 | }
39 |
40 | // Create a UserDetails object from the data
41 | UserDetails userDetails = new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), authorities);
42 |
43 | return userDetails;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.messages.basename=messages
2 | spring.messages.cache-seconds=-1
3 | spring.messages.encoding=UTF-8
4 |
5 | logging.level.org.springframework.web: DEBUG
6 | logging.level.org.springframework.security: DEBUG
7 | #logging.level.org.springframework: DEBUG
8 | #logging.level.org.hibernate: DEBUG
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | NotEmpty.poll.question=Question is a required field
2 | Size.poll.options=Options must be greater than {2} and less than {1}
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/.keep
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/explorer_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/explorer_icons.png
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/logo_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/logo_small.png
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/pet_store_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/pet_store_api.png
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/throbber.gif
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/wordnik_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/images/wordnik_api.png
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/lib/jquery.slideto.min.js:
--------------------------------------------------------------------------------
1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery);
2 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/lib/jquery.wiggle.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | jQuery Wiggle
3 | Author: WonderGroup, Jordan Thomas
4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html
5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License)
6 | */
7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);}
8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});};
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/static/swagger-ui/o2c.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/src/main/resources/templates/.keep
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/src/test/java/com/apress/UserGenerator.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
4 |
5 | /**
6 | * Generates the user data along with encrypted password.
7 | */
8 | public class UserGenerator {
9 |
10 | public static void main(String[] args) {
11 |
12 | BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
13 |
14 | String[][] users = {
15 | {"1", "mickey", "cheese", "Mickey", "Mouse", "no"},
16 | {"2", "minnie", "red01", "Minnie", "Mouse", "no"},
17 | {"3", "donald", "quack", "Donald", "Duck", "no"},
18 | {"4", "daisy", "quack2", "Daisy", "Duck", "no"},
19 | {"5", "clarabelle", "moo", "Clarabelle", "Cow", "no"},
20 | {"6", "admin", "admin", "Super", "Admin", "yes"}
21 | };
22 |
23 | String sql = "insert into users (user_id, username, password, first_name, last_name, admin) values (%s, '%s', '%s', '%s', '%s', '%s');";
24 |
25 | for(String[] user : users) {
26 |
27 | System.out.println(String.format(sql, user[0], user[1], passwordEncoder.encode(user[2]) , user[3], user[4], user[5]));
28 |
29 | }
30 |
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/application.properties:
--------------------------------------------------------------------------------
1 | spring.messages.basename=messages
2 | spring.messages.cache-seconds=-1
3 | spring.messages.encoding=UTF-8
4 |
5 | logging.level.org.springframework.web: DEBUG
6 | logging.level.org.springframework.security: DEBUG
7 | #logging.level.org.springframework: DEBUG
8 | #logging.level.org.hibernate: DEBUG
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/QuickPollApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/QuickPollApplication.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/QuickPollMvcConfigAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/QuickPollMvcConfigAdapter.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/SecurityConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/SecurityConfig.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/SwaggerConfiguration.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/SwaggerConfiguration.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/domain/Option.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/domain/Option.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/domain/Poll.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/domain/Poll.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/domain/User.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/domain/User.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/domain/Vote.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/domain/Vote.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/dto/OptionCount.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/dto/OptionCount.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/dto/VoteResult.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/dto/VoteResult.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/dto/error/ErrorDetail.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/dto/error/ErrorDetail.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/dto/error/ValidationError.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/dto/error/ValidationError.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/exception/ResourceNotFoundException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/exception/ResourceNotFoundException.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/handler/RestExceptionHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/handler/RestExceptionHandler.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/repository/OptionRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/repository/OptionRepository.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/repository/PollRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/repository/PollRepository.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/repository/UserRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/repository/UserRepository.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/repository/VoteRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/repository/VoteRepository.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/security/QuickPollUserDetailsService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/security/QuickPollUserDetailsService.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v1/controller/ComputeResultController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v1/controller/ComputeResultController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v1/controller/PollController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v1/controller/PollController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v1/controller/VoteController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v1/controller/VoteController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v2/controller/ComputeResultController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v2/controller/ComputeResultController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v2/controller/PollController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v2/controller/PollController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v2/controller/VoteController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v2/controller/VoteController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v3/controller/ComputeResultController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v3/controller/ComputeResultController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v3/controller/PollController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v3/controller/PollController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v3/controller/VoteController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/com/apress/v3/controller/VoteController.class
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/messages.properties:
--------------------------------------------------------------------------------
1 | NotEmpty.poll.question=Question is a required field
2 | Size.poll.options=Options must be greater than {2} and less than {1}
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/.keep
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/explorer_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/explorer_icons.png
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/logo_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/logo_small.png
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/pet_store_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/pet_store_api.png
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/throbber.gif
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/wordnik_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/images/wordnik_api.png
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/lib/jquery.slideto.min.js:
--------------------------------------------------------------------------------
1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery);
2 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/lib/jquery.wiggle.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | jQuery Wiggle
3 | Author: WonderGroup, Jordan Thomas
4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html
5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License)
6 | */
7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);}
8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});};
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/static/swagger-ui/o2c.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/classes/templates/.keep
--------------------------------------------------------------------------------
/Chapter8/quick-poll-ch8-final-basic-auth/target/test-classes/com/apress/UserGenerator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter8/quick-poll-ch8-final-basic-auth/target/test-classes/com/apress/UserGenerator.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/QuickPollApplication.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class QuickPollApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(QuickPollApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/QuickPollMvcConfigAdapter.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import java.util.List;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.data.domain.PageRequest;
6 | import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
7 | import org.springframework.web.method.support.HandlerMethodArgumentResolver;
8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
9 |
10 | @Configuration
11 | public class QuickPollMvcConfigAdapter implements WebMvcConfigurer {
12 | @Override
13 |
14 | public void addArgumentResolvers(List argumentResolvers) {
15 |
16 | PageableHandlerMethodArgumentResolver phmar = new PageableHandlerMethodArgumentResolver();
17 | // Set the default size to 5
18 | phmar.setFallbackPageable(PageRequest.of(0, 5));
19 | argumentResolvers.add(phmar);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/client/QuickPollClientJdk.java:
--------------------------------------------------------------------------------
1 | package com.apress.client;
2 |
3 | import org.apache.tomcat.util.http.fileupload.IOUtils;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.InputStreamReader;
7 | import java.net.HttpURLConnection;
8 | import java.net.URL;
9 |
10 | public class QuickPollClientJdk {
11 |
12 | public void readPoll() {
13 | HttpURLConnection connection = null;
14 | BufferedReader reader = null;
15 | try {
16 | URL restAPIUrl = new URL("http://localhost:8080/v1/polls/1");
17 | connection = (HttpURLConnection) restAPIUrl.openConnection();
18 | connection.setRequestMethod("GET");
19 |
20 | // Read the response
21 | reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
22 | StringBuilder jsonData = new StringBuilder();
23 | String line;
24 | while ((line = reader.readLine()) != null) {
25 | jsonData.append(line);
26 | }
27 |
28 | System.out.println(jsonData.toString());
29 | }
30 | catch(Exception e) {
31 | e.printStackTrace();
32 | }
33 | finally {
34 | // Clean up
35 | IOUtils.closeQuietly(reader);
36 | if(connection != null)
37 | connection.disconnect();
38 | }
39 | }
40 |
41 | public static void main(String[] args) throws Exception {
42 | QuickPollClientJdk client = new QuickPollClientJdk();
43 | client.readPoll();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/client/QuickPollClientV3BasicAuth.java:
--------------------------------------------------------------------------------
1 | package com.apress.client;
2 |
3 | import org.apache.tomcat.util.codec.binary.Base64;
4 | import org.springframework.http.HttpEntity;
5 | import org.springframework.http.HttpHeaders;
6 | import org.springframework.http.HttpMethod;
7 | import org.springframework.web.client.RestTemplate;
8 |
9 | public class QuickPollClientV3BasicAuth {
10 |
11 | private static final String QUICK_POLL_URI_V3 = "http://localhost:8080/v3/polls";
12 | private RestTemplate restTemplate = new RestTemplate();
13 |
14 | public void deletePoll(Long pollId) {
15 | HttpHeaders authenticationHeaders = getAuthenticationHeader("admin", "admin");
16 | restTemplate.exchange(QUICK_POLL_URI_V3 + "/{pollId}",
17 | HttpMethod.DELETE, new HttpEntity(authenticationHeaders), Void.class, pollId);
18 | }
19 |
20 | // Basic Authentication
21 | private HttpHeaders getAuthenticationHeader(String username, String password) {
22 |
23 | String credentials = username + ":" + password;
24 | byte[] base64CredentialData = Base64.encodeBase64(credentials.getBytes());
25 |
26 | HttpHeaders headers = new HttpHeaders();
27 | headers.set("Authorization", "Basic " + new String(base64CredentialData));
28 |
29 | return headers;
30 | }
31 |
32 | public static void main(String[] args) {
33 | QuickPollClientV3BasicAuth client = new QuickPollClientV3BasicAuth();
34 | client.deletePoll(4L);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/domain/Option.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class Option {
10 |
11 | @Id
12 | @GeneratedValue
13 | @Column(name="OPTION_ID")
14 | private Long id;
15 |
16 | @Column(name="OPTION_VALUE")
17 | private String value;
18 |
19 | public Long getId() {
20 | return id;
21 | }
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 | public String getValue() {
26 | return value;
27 | }
28 | public void setValue(String value) {
29 | this.value = value;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return getId() + "," + getValue();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/domain/Poll.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.CascadeType;
4 | import javax.persistence.Column;
5 | import javax.persistence.Entity;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.Id;
8 | import javax.persistence.JoinColumn;
9 | import javax.persistence.OneToMany;
10 | import javax.persistence.OrderBy;
11 | import javax.validation.constraints.NotEmpty;
12 | import javax.validation.constraints.Size;
13 | import java.util.Set;
14 |
15 |
16 | @Entity
17 | public class Poll {
18 |
19 | @Id
20 | @GeneratedValue
21 | @Column(name="POLL_ID")
22 | private Long id;
23 |
24 | @Column(name="QUESTION")
25 | @NotEmpty
26 | private String question;
27 |
28 | @OneToMany(cascade=CascadeType.ALL)
29 | @JoinColumn(name="POLL_ID")
30 | @OrderBy
31 | @Size(min=2, max = 6)
32 | private Set options;
33 |
34 | public Long getId() {
35 | return id;
36 | }
37 | public void setId(Long id) {
38 | this.id = id;
39 | }
40 | public String getQuestion() {
41 | return question;
42 | }
43 | public void setQuestion(String question) {
44 | this.question = question;
45 | }
46 | public Set getOptions() {
47 | return options;
48 | }
49 | public void setOptions(Set options) {
50 | this.options = options;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return getId() + ", " + getQuestion() + ", " + getOptions();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/domain/Vote.java:
--------------------------------------------------------------------------------
1 | package com.apress.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 | import javax.persistence.JoinColumn;
8 | import javax.persistence.ManyToOne;
9 |
10 | @Entity
11 | public class Vote {
12 |
13 | @Id
14 | @GeneratedValue
15 | @Column(name="VOTE_ID")
16 | private Long id;
17 |
18 | @ManyToOne
19 | @JoinColumn(name="OPTION_ID")
20 | private Option option;
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 | public void setId(Long id) {
26 | this.id = id;
27 | }
28 | public Option getOption() {
29 | return option;
30 | }
31 | public void setOption(Option option) {
32 | this.option = option;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return getId() + ", " + getOption();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/dto/OptionCount.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | public class OptionCount {
4 | private Long optionId;
5 | private int count;
6 |
7 | public Long getOptionId() {
8 | return optionId;
9 | }
10 | public void setOptionId(Long optionId) {
11 | this.optionId = optionId;
12 | }
13 | public int getCount() {
14 | return count;
15 | }
16 | public void setCount(int count) {
17 | this.count = count;
18 | }
19 | }
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/dto/VoteResult.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto;
2 |
3 | import java.util.Collection;
4 |
5 | public class VoteResult {
6 |
7 | private int totalVotes;
8 | private Collection results;
9 |
10 | public int getTotalVotes() {
11 | return totalVotes;
12 | }
13 | public void setTotalVotes(int totalVotes) {
14 | this.totalVotes = totalVotes;
15 | }
16 | public Collection getResults() {
17 | return results;
18 | }
19 | public void setResults(Collection results) {
20 | this.results = results;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/dto/error/ErrorDetail.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class ErrorDetail {
8 |
9 | private String title;
10 | private int status;
11 | private String detail;
12 | private long timeStamp;
13 | private String developerMessage;
14 | private Map> errors = new HashMap>();
15 |
16 | public Map> getErrors() {
17 | return errors;
18 | }
19 | public void setErrors(Map> errors) {
20 | this.errors = errors;
21 | }
22 | public String getTitle() {
23 | return title;
24 | }
25 | public void setTitle(String title) {
26 | this.title = title;
27 | }
28 | public int getStatus() {
29 | return status;
30 | }
31 | public void setStatus(int status) {
32 | this.status = status;
33 | }
34 | public String getDetail() {
35 | return detail;
36 | }
37 | public void setDetail(String detail) {
38 | this.detail = detail;
39 | }
40 | public long getTimeStamp() {
41 | return timeStamp;
42 | }
43 | public void setTimeStamp(long timeStamp) {
44 | this.timeStamp = timeStamp;
45 | }
46 | public String getDeveloperMessage() {
47 | return developerMessage;
48 | }
49 | public void setDeveloperMessage(String developerMessage) {
50 | this.developerMessage = developerMessage;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/dto/error/ValidationError.java:
--------------------------------------------------------------------------------
1 | package com.apress.dto.error;
2 |
3 | public class ValidationError {
4 |
5 | private String code;
6 | private String message;
7 |
8 | public String getCode() {
9 | return code;
10 | }
11 | public void setCode(String code) {
12 | this.code = code;
13 | }
14 | public String getMessage() {
15 | return message;
16 | }
17 | public void setMessage(String message) {
18 | this.message = message;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/exception/ResourceNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.apress.exception;
2 |
3 | import org.springframework.http.HttpStatus;
4 | import org.springframework.web.bind.annotation.ResponseStatus;
5 |
6 | @ResponseStatus(HttpStatus.NOT_FOUND)
7 | public class ResourceNotFoundException extends RuntimeException {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | public ResourceNotFoundException() {}
12 |
13 | public ResourceNotFoundException(String message) {
14 | super(message);
15 | }
16 |
17 | public ResourceNotFoundException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/repository/OptionRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import com.apress.domain.Option;
4 | import org.springframework.data.repository.CrudRepository;
5 |
6 | public interface OptionRepository extends CrudRepository {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/repository/PollRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import com.apress.domain.Poll;
4 | import org.springframework.data.repository.PagingAndSortingRepository;
5 |
6 | public interface PollRepository extends PagingAndSortingRepository {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 | import com.apress.domain.User;
4 | import org.springframework.data.repository.CrudRepository;
5 |
6 | public interface UserRepository extends CrudRepository {
7 |
8 | User findByUsername(String username);
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/repository/VoteRepository.java:
--------------------------------------------------------------------------------
1 | package com.apress.repository;
2 |
3 |
4 | import com.apress.domain.Vote;
5 | import org.springframework.data.jpa.repository.Query;
6 | import org.springframework.data.repository.CrudRepository;
7 |
8 | public interface VoteRepository extends CrudRepository {
9 |
10 | @Query(value="select v.* from Option o, Vote v where o.POLL_ID = ?1 and v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
11 | Iterable findByPoll(Long pollId);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/java/com/apress/security/QuickPollUserDetailsService.java:
--------------------------------------------------------------------------------
1 | package com.apress.security;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.inject.Inject;
7 |
8 | import com.apress.domain.User;
9 | import org.springframework.security.core.GrantedAuthority;
10 | import org.springframework.security.core.authority.AuthorityUtils;
11 | import org.springframework.security.core.userdetails.UserDetails;
12 | import org.springframework.security.core.userdetails.UserDetailsService;
13 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
14 | import org.springframework.stereotype.Component;
15 |
16 | import com.apress.repository.UserRepository;
17 |
18 | @Component
19 | public class QuickPollUserDetailsService implements UserDetailsService {
20 |
21 | @Inject
22 | private UserRepository userRepository;
23 |
24 | @Override
25 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
26 |
27 | User user = userRepository.findByUsername(username);
28 |
29 | if(user == null) {
30 | throw new UsernameNotFoundException(String.format("User with the username %s doesn't exist", username));
31 | }
32 |
33 | // Create a granted authority based on user's role.
34 | // Can't pass null authorities to user. Hence initialize with an empty arraylist
35 | List authorities = new ArrayList<>();
36 | if(user.isAdmin()) {
37 | authorities = AuthorityUtils.createAuthorityList("ROLE_ADMIN");
38 | }
39 |
40 | // Create a UserDetails object from the data
41 | UserDetails userDetails = new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), authorities);
42 |
43 | return userDetails;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.messages.basename=messages
2 | spring.messages.cache-seconds=-1
3 | spring.messages.encoding=UTF-8
4 |
5 | logging.level.org.springframework.web: DEBUG
6 | logging.level.org.springframework.security: DEBUG
7 | #logging.level.org.springframework: DEBUG
8 | #logging.level.org.hibernate: DEBUG
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | NotEmpty.poll.question=Question is a required field
2 | Size.poll.options=Options must be greater than {2} and less than {1}
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/src/main/resources/static/.keep
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/css/reset.css:
--------------------------------------------------------------------------------
1 | /* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 */
2 | html,
3 | body,
4 | div,
5 | span,
6 | applet,
7 | object,
8 | iframe,
9 | h1,
10 | h2,
11 | h3,
12 | h4,
13 | h5,
14 | h6,
15 | p,
16 | blockquote,
17 | pre,
18 | a,
19 | abbr,
20 | acronym,
21 | address,
22 | big,
23 | cite,
24 | code,
25 | del,
26 | dfn,
27 | em,
28 | img,
29 | ins,
30 | kbd,
31 | q,
32 | s,
33 | samp,
34 | small,
35 | strike,
36 | strong,
37 | sub,
38 | sup,
39 | tt,
40 | var,
41 | b,
42 | u,
43 | i,
44 | center,
45 | dl,
46 | dt,
47 | dd,
48 | ol,
49 | ul,
50 | li,
51 | fieldset,
52 | form,
53 | label,
54 | legend,
55 | table,
56 | caption,
57 | tbody,
58 | tfoot,
59 | thead,
60 | tr,
61 | th,
62 | td,
63 | article,
64 | aside,
65 | canvas,
66 | details,
67 | embed,
68 | figure,
69 | figcaption,
70 | footer,
71 | header,
72 | hgroup,
73 | menu,
74 | nav,
75 | output,
76 | ruby,
77 | section,
78 | summary,
79 | time,
80 | mark,
81 | audio,
82 | video {
83 | margin: 0;
84 | padding: 0;
85 | border: 0;
86 | font-size: 100%;
87 | font: inherit;
88 | vertical-align: baseline;
89 | }
90 | /* HTML5 display-role reset for older browsers */
91 | article,
92 | aside,
93 | details,
94 | figcaption,
95 | figure,
96 | footer,
97 | header,
98 | hgroup,
99 | menu,
100 | nav,
101 | section {
102 | display: block;
103 | }
104 | body {
105 | line-height: 1;
106 | }
107 | ol,
108 | ul {
109 | list-style: none;
110 | }
111 | blockquote,
112 | q {
113 | quotes: none;
114 | }
115 | blockquote:before,
116 | blockquote:after,
117 | q:before,
118 | q:after {
119 | content: '';
120 | content: none;
121 | }
122 | table {
123 | border-collapse: collapse;
124 | border-spacing: 0;
125 | }
126 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/explorer_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/explorer_icons.png
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/logo_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/logo_small.png
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/pet_store_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/pet_store_api.png
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/throbber.gif
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/wordnik_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/images/wordnik_api.png
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/lib/jquery.slideto.min.js:
--------------------------------------------------------------------------------
1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery);
2 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/lib/jquery.wiggle.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | jQuery Wiggle
3 | Author: WonderGroup, Jordan Thomas
4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html
5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License)
6 | */
7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);}
8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});};
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/static/swagger-ui/o2c.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/main/resources/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/src/main/resources/templates/.keep
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/test/java/com/apress/ExampleTest.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.junit.After;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 | import org.springframework.test.context.web.WebAppConfiguration;
10 |
11 | @RunWith(SpringJUnit4ClassRunner.class)
12 | @SpringBootTest(classes = QuickPollApplication.class)
13 | @WebAppConfiguration
14 | public class ExampleTest {
15 | @Before
16 | public void setup() { }
17 |
18 | @Test
19 | public void testSomeThing() {}
20 |
21 |
22 | @After
23 | public void teardown() { }
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/test/java/com/apress/QuickPollApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
7 | import org.springframework.test.context.web.WebAppConfiguration;
8 |
9 | @RunWith(SpringJUnit4ClassRunner.class)
10 | @SpringBootTest(classes = QuickPollApplication.class)
11 | @WebAppConfiguration
12 | public class QuickPollApplicationTests {
13 |
14 | @Test
15 | public void contextLoads() {
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/test/java/com/apress/UserGenerator.java:
--------------------------------------------------------------------------------
1 | package com.apress;
2 |
3 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
4 |
5 | /**
6 | * Generates the user data along with encrypted password.
7 | */
8 | public class UserGenerator {
9 |
10 | public static void main(String[] args) {
11 |
12 | BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
13 |
14 | String[][] users = {
15 | {"1", "mickey", "cheese", "Mickey", "Mouse", "no"},
16 | {"2", "minnie", "red01", "Minnie", "Mouse", "no"},
17 | {"3", "donald", "quack", "Donald", "Duck", "no"},
18 | {"4", "daisy", "quack2", "Daisy", "Duck", "no"},
19 | {"5", "clarabelle", "moo", "Clarabelle", "Cow", "no"},
20 | {"6", "admin", "admin", "Super", "Admin", "yes"}
21 | };
22 |
23 | String sql = "insert into users (user_id, username, password, first_name, last_name, admin) values (%s, '%s', '%s', '%s', '%s', '%s');";
24 |
25 | for(String[] user : users) {
26 |
27 | System.out.println(String.format(sql, user[0], user[1], passwordEncoder.encode(user[2]) , user[3], user[4], user[5]));
28 |
29 | }
30 |
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/test/java/com/apress/it/PollControllerIT.java:
--------------------------------------------------------------------------------
1 | package com.apress.it;
2 |
3 | import static org.hamcrest.Matchers.hasSize;
4 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
5 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
6 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
7 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
8 |
9 | import javax.inject.Inject;
10 |
11 | import org.junit.Before;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.springframework.boot.test.context.SpringBootTest;
15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16 | import org.springframework.test.context.web.WebAppConfiguration;
17 | import org.springframework.test.web.servlet.MockMvc;
18 | import org.springframework.web.context.WebApplicationContext;
19 |
20 | import com.apress.QuickPollApplication;
21 |
22 | @RunWith(SpringJUnit4ClassRunner.class)
23 | @SpringBootTest(classes = QuickPollApplication.class)
24 | @WebAppConfiguration
25 | public class PollControllerIT {
26 |
27 | @Inject
28 | private WebApplicationContext webApplicationContext;
29 |
30 | private MockMvc mockMvc;
31 |
32 | @Before
33 | public void setup() {
34 | mockMvc = webAppContextSetup(webApplicationContext).build();
35 | }
36 |
37 | @Test
38 | public void testGetAllPolls() throws Exception {
39 | mockMvc.perform(get("/v1/polls"))
40 | .andExpect(status().isOk())
41 | .andExpect(jsonPath("$", hasSize(20)));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/src/test/java/com/apress/unit/PollControllerTestMock.java:
--------------------------------------------------------------------------------
1 | package com.apress.unit;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.mockito.Mockito.when;
5 | import static org.mockito.Mockito.times;
6 | import static org.mockito.Mockito.verify;
7 |
8 | import java.util.ArrayList;
9 |
10 | import com.apress.domain.Poll;
11 | import com.apress.v1.controller.PollController;
12 | import org.assertj.core.util.Lists;
13 | import org.junit.Before;
14 | import org.junit.Test;
15 | import org.mockito.Mock;
16 | import org.mockito.MockitoAnnotations;
17 | import org.springframework.http.HttpStatus;
18 | import org.springframework.http.ResponseEntity;
19 | import org.springframework.test.util.ReflectionTestUtils;
20 |
21 | import com.apress.repository.PollRepository;
22 |
23 | public class PollControllerTestMock {
24 |
25 | @Mock
26 | private PollRepository pollRepository;
27 |
28 | @Before
29 | public void setUp() throws Exception {
30 | MockitoAnnotations.initMocks(this);
31 | }
32 |
33 | @Test
34 | public void testGetAllPolls() {
35 | PollController pollController = new PollController();
36 | ReflectionTestUtils.setField(pollController, "pollRepository", pollRepository);
37 |
38 | when(pollRepository.findAll()).thenReturn(new ArrayList());
39 | ResponseEntity> allPollsEntity = pollController.getAllPolls();
40 | verify(pollRepository, times(1)).findAll();
41 | assertEquals(HttpStatus.OK, allPollsEntity.getStatusCode());
42 | assertEquals(0, Lists.newArrayList(allPollsEntity.getBody()).size());
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/application.properties:
--------------------------------------------------------------------------------
1 | spring.messages.basename=messages
2 | spring.messages.cache-seconds=-1
3 | spring.messages.encoding=UTF-8
4 |
5 | logging.level.org.springframework.web: DEBUG
6 | logging.level.org.springframework.security: DEBUG
7 | #logging.level.org.springframework: DEBUG
8 | #logging.level.org.hibernate: DEBUG
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/QuickPollApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/QuickPollApplication.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/QuickPollMvcConfigAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/QuickPollMvcConfigAdapter.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/SecurityConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/SecurityConfig.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/SwaggerConfiguration.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/SwaggerConfiguration.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/PageWrapper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/PageWrapper.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClient$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClient$1.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClient.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClient.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClientJdk.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClientJdk.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClientV2$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClientV2$1.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClientV2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClientV2.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClientV3BasicAuth.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/client/QuickPollClientV3BasicAuth.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/domain/Option.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/domain/Option.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/domain/Poll.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/domain/Poll.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/domain/User.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/domain/User.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/domain/Vote.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/domain/Vote.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/dto/OptionCount.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/dto/OptionCount.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/dto/VoteResult.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/dto/VoteResult.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/dto/error/ErrorDetail.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/dto/error/ErrorDetail.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/dto/error/ValidationError.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/dto/error/ValidationError.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/exception/ResourceNotFoundException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/exception/ResourceNotFoundException.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/handler/RestExceptionHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/handler/RestExceptionHandler.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/repository/OptionRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/repository/OptionRepository.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/repository/PollRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/repository/PollRepository.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/repository/UserRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/repository/UserRepository.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/repository/VoteRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/repository/VoteRepository.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/security/QuickPollUserDetailsService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/security/QuickPollUserDetailsService.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v1/controller/ComputeResultController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v1/controller/ComputeResultController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v1/controller/PollController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v1/controller/PollController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v1/controller/VoteController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v1/controller/VoteController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v2/controller/ComputeResultController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v2/controller/ComputeResultController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v2/controller/PollController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v2/controller/PollController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v2/controller/VoteController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v2/controller/VoteController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v3/controller/ComputeResultController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v3/controller/ComputeResultController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v3/controller/PollController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v3/controller/PollController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v3/controller/VoteController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/com/apress/v3/controller/VoteController.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/messages.properties:
--------------------------------------------------------------------------------
1 | NotEmpty.poll.question=Question is a required field
2 | Size.poll.options=Options must be greater than {2} and less than {1}
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/static/.keep
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/explorer_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/explorer_icons.png
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/logo_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/logo_small.png
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/pet_store_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/pet_store_api.png
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/throbber.gif
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/wordnik_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/images/wordnik_api.png
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/lib/jquery.slideto.min.js:
--------------------------------------------------------------------------------
1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery);
2 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/lib/jquery.wiggle.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | jQuery Wiggle
3 | Author: WonderGroup, Jordan Thomas
4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html
5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License)
6 | */
7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);}
8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});};
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/static/swagger-ui/o2c.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/classes/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/classes/templates/.keep
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst:
--------------------------------------------------------------------------------
1 | C:\Users\makus\OneDrive\Desktop\book\springrest-book-master\Chapter9\final\quick-poll-ch9-final\src\test\java\com\apress\QuickPollApplicationTests.java
2 | C:\Users\makus\OneDrive\Desktop\book\springrest-book-master\Chapter9\final\quick-poll-ch9-final\src\test\java\com\apress\unit\PollControllerTestMock.java
3 | C:\Users\makus\OneDrive\Desktop\book\springrest-book-master\Chapter9\final\quick-poll-ch9-final\src\test\java\com\apress\it\PollControllerIT.java
4 | C:\Users\makus\OneDrive\Desktop\book\springrest-book-master\Chapter9\final\quick-poll-ch9-final\src\test\java\com\apress\ExampleTest.java
5 | C:\Users\makus\OneDrive\Desktop\book\springrest-book-master\Chapter9\final\quick-poll-ch9-final\src\test\java\com\apress\unit\PollControllerTest.java
6 | C:\Users\makus\OneDrive\Desktop\book\springrest-book-master\Chapter9\final\quick-poll-ch9-final\src\test\java\com\apress\UserGenerator.java
7 |
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/ExampleTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/ExampleTest.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/QuickPollApplicationTests.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/QuickPollApplicationTests.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/UserGenerator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/UserGenerator.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/it/PollControllerIT.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/it/PollControllerIT.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/unit/PollControllerTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/unit/PollControllerTest.class
--------------------------------------------------------------------------------
/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/unit/PollControllerTestMock.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/spring-rest-2e/ef1ddc4da88194adc49d2cfe78b1269968247c03/Chapter9/quick-poll-ch9-final/target/test-classes/com/apress/unit/PollControllerTestMock.class
--------------------------------------------------------------------------------
/Contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing to Apress Source Code
2 |
3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.
4 |
5 | ## How to Contribute
6 |
7 | 1. Make sure you have a GitHub account.
8 | 2. Fork the repository for the relevant book.
9 | 3. Create a new branch on which to make your change, e.g.
10 | `git checkout -b my_code_contribution`
11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
12 | 5. Submit a pull request.
13 |
14 | Thank you for your contribution!
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Freeware License, some rights reserved
2 |
3 | Copyright (c) 2022 Balaji Varanasi and Maxim Bartkov
4 |
5 | Permission is hereby granted, free of charge, to anyone obtaining a copy
6 | of this software and associated documentation files (the "Software"),
7 | to work with the Software within the limits of freeware distribution and fair use.
8 | This includes the rights to use, copy, and modify the Software for personal use.
9 | Users are also allowed and encouraged to submit corrections and modifications
10 | to the Software for the benefit of other users.
11 |
12 | It is not allowed to reuse, modify, or redistribute the Software for
13 | commercial use in any way, or for a user’s educational materials such as books
14 | or blog articles without prior permission from the copyright holder.
15 |
16 | The above copyright notice and this permission notice need to be included
17 | in all copies or substantial portions of the software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | SOFTWARE.
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Apress Source Code
2 |
3 | This repository accompanies [*Spring REST*](https://link.springer.com/book/10.1007/978-1-4842-7477-4) by Balaji Varanasi and Maxim Bartkov (Apress, 2022).
4 |
5 | [comment]: #cover
6 | 
7 |
8 | Download the files as a zip using the green button, or clone the repository to your machine using Git.
9 |
10 | ## Releases
11 |
12 | Release v1.0 corresponds to the code in the published book, without corrections or updates.
13 |
14 | ## Contributions
15 |
16 | See the file Contributing.md for more information on how you can contribute to this repository.
--------------------------------------------------------------------------------
/errata.md:
--------------------------------------------------------------------------------
1 | # Errata for *Spring REST, 2nd Edition*
2 |
3 | On **page xx** [Summary of error]:
4 |
5 | Details of error here. Highlight key pieces in **bold**.
6 |
7 | ***
8 |
9 | On **page xx** [Summary of error]:
10 |
11 | Details of error here. Highlight key pieces in **bold**.
12 |
13 | ***
--------------------------------------------------------------------------------