├── .gitignore ├── Chapter02 ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AopDemoApplication.java │ │ │ ├── SortUtil.java │ │ │ └── aop │ │ │ ├── TimeMonitor.java │ │ │ └── TimeMonitorAspect.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ └── AopDemoApplicationTests.java ├── Chapter03 ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AppConfig.java │ │ │ ├── controllers │ │ │ └── CartsController.java │ │ │ ├── eCommerceApp.java │ │ │ └── exceptions │ │ │ ├── Error.java │ │ │ ├── ErrorCode.java │ │ │ ├── ErrorUtils.java │ │ │ └── RestApiErrorHandler.java │ └── resources │ │ ├── api │ │ ├── .openapi-generator-ignore │ │ ├── config.json │ │ └── openapi.yaml │ │ ├── application.properties │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ └── eCommerceAppTests.java ├── Chapter04 ├── .gitignore ├── Chapter04.postman_collection.json ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AppConfig.java │ │ │ ├── controller │ │ │ ├── AddressController.java │ │ │ ├── CardController.java │ │ │ ├── CartsController.java │ │ │ ├── CustomerController.java │ │ │ ├── OrderController.java │ │ │ ├── PaymentController.java │ │ │ ├── ProductController.java │ │ │ └── ShipmentController.java │ │ │ ├── eCommerceApp.java │ │ │ ├── entity │ │ │ ├── AddressEntity.java │ │ │ ├── AuthorizationEntity.java │ │ │ ├── CardEntity.java │ │ │ ├── CartEntity.java │ │ │ ├── ItemEntity.java │ │ │ ├── OrderEntity.java │ │ │ ├── OrderItemEntity.java │ │ │ ├── PaymentEntity.java │ │ │ ├── ProductEntity.java │ │ │ ├── ShipmentEntity.java │ │ │ ├── TagEntity.java │ │ │ └── UserEntity.java │ │ │ ├── exception │ │ │ ├── CustomerNotFoundException.java │ │ │ ├── Error.java │ │ │ ├── ErrorCode.java │ │ │ ├── ErrorUtils.java │ │ │ ├── GenericAlreadyExistsException.java │ │ │ ├── ItemNotFoundException.java │ │ │ ├── ResourceNotFoundException.java │ │ │ └── RestApiErrorHandler.java │ │ │ ├── hateoas │ │ │ ├── AddressRepresentationModelAssembler.java │ │ │ ├── CardRepresentationModelAssembler.java │ │ │ ├── CartRepresentationModelAssembler.java │ │ │ ├── OrderRepresentationModelAssembler.java │ │ │ ├── PaymentRepresentationModelAssembler.java │ │ │ ├── ProductRepresentationModelAssembler.java │ │ │ ├── ShipmentRepresentationModelAssembler.java │ │ │ └── UserRepresentationModelAssembler.java │ │ │ ├── repository │ │ │ ├── AddressRepository.java │ │ │ ├── AuthorizationRepository.java │ │ │ ├── CardRepository.java │ │ │ ├── CartRepository.java │ │ │ ├── ItemRepository.java │ │ │ ├── OrderItemRepository.java │ │ │ ├── OrderRepository.java │ │ │ ├── OrderRepositoryExt.java │ │ │ ├── OrderRepositoryImpl.java │ │ │ ├── PaymentRepository.java │ │ │ ├── ProductRepository.java │ │ │ ├── ShipmentRepository.java │ │ │ ├── TagRepository.java │ │ │ └── UserRepository.java │ │ │ └── service │ │ │ ├── AddressService.java │ │ │ ├── AddressServiceImpl.java │ │ │ ├── CardService.java │ │ │ ├── CardServiceImpl.java │ │ │ ├── CartService.java │ │ │ ├── CartServiceImpl.java │ │ │ ├── ItemService.java │ │ │ ├── ItemServiceImpl.java │ │ │ ├── OrderService.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── PaymentService.java │ │ │ ├── PaymentServiceImpl.java │ │ │ ├── ProductService.java │ │ │ ├── ProductServiceImpl.java │ │ │ ├── ShipmentService.java │ │ │ ├── ShipmentServiceImpl.java │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── api │ │ ├── .openapi-generator-ignore │ │ ├── config.json │ │ └── openapi.yaml │ │ ├── application.properties │ │ ├── db │ │ └── migration │ │ │ └── V1.0.0__Init.sql │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ └── eCommerceAppTests.java ├── Chapter05 ├── .gitignore ├── Chapter05.postman_collection.json ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AppConfig.java │ │ │ ├── ECommerceApp.java │ │ │ ├── H2ConsoleComponent.java │ │ │ ├── controller │ │ │ ├── AddressController.java │ │ │ ├── CardController.java │ │ │ ├── CartsController.java │ │ │ ├── CustomerController.java │ │ │ ├── OrderController.java │ │ │ ├── PaymentController.java │ │ │ ├── ProductController.java │ │ │ └── ShipmentController.java │ │ │ ├── entity │ │ │ ├── AddressEntity.java │ │ │ ├── AuthorizationEntity.java │ │ │ ├── CardEntity.java │ │ │ ├── CartEntity.java │ │ │ ├── ItemEntity.java │ │ │ ├── OrderEntity.java │ │ │ ├── OrderItemEntity.java │ │ │ ├── PaymentEntity.java │ │ │ ├── ProductEntity.java │ │ │ ├── ShipmentEntity.java │ │ │ ├── TagEntity.java │ │ │ ├── UserAddressEntity.java │ │ │ └── UserEntity.java │ │ │ ├── exception │ │ │ ├── ApiErrorAttributes.java │ │ │ ├── ApiErrorWebExceptionHandler.java │ │ │ ├── CardAlreadyExistsException.java │ │ │ ├── CustomerNotFoundException.java │ │ │ ├── Error.java │ │ │ ├── ErrorCode.java │ │ │ ├── ErrorUtils.java │ │ │ ├── GenericAlreadyExistsException.java │ │ │ ├── ItemNotFoundException.java │ │ │ └── ResourceNotFoundException.java │ │ │ ├── hateoas │ │ │ ├── AddressRepresentationModelAssembler.java │ │ │ ├── CardRepresentationModelAssembler.java │ │ │ ├── CartRepresentationModelAssembler.java │ │ │ ├── HateoasSupport.java │ │ │ ├── OrderRepresentationModelAssembler.java │ │ │ ├── PaymentRepresentationModelAssembler.java │ │ │ ├── ProductRepresentationModelAssembler.java │ │ │ ├── ShipmentRepresentationModelAssembler.java │ │ │ └── UserRepresentationModelAssembler.java │ │ │ ├── repository │ │ │ ├── AddressRepository.java │ │ │ ├── AuthorizationRepository.java │ │ │ ├── CardRepository.java │ │ │ ├── CartRepository.java │ │ │ ├── ItemRepository.java │ │ │ ├── OrderItemRepository.java │ │ │ ├── OrderRepository.java │ │ │ ├── OrderRepositoryExt.java │ │ │ ├── OrderRepositoryExtImpl.java │ │ │ ├── PaymentRepository.java │ │ │ ├── ProductRepository.java │ │ │ ├── ShipmentRepository.java │ │ │ ├── TagRepository.java │ │ │ └── UserRepository.java │ │ │ └── service │ │ │ ├── AddressService.java │ │ │ ├── AddressServiceImpl.java │ │ │ ├── CardService.java │ │ │ ├── CardServiceImpl.java │ │ │ ├── CartService.java │ │ │ ├── CartServiceImpl.java │ │ │ ├── ItemService.java │ │ │ ├── ItemServiceImpl.java │ │ │ ├── OrderService.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── PaymentService.java │ │ │ ├── PaymentServiceImpl.java │ │ │ ├── ProductService.java │ │ │ ├── ProductServiceImpl.java │ │ │ ├── ShipmentService.java │ │ │ ├── ShipmentServiceImpl.java │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── api │ │ ├── .openapi-generator-ignore │ │ ├── config.json │ │ └── openapi.yaml │ │ ├── application.properties │ │ ├── db │ │ └── migration │ │ │ └── V1.0.0__Init.sql │ │ └── logback-spring.xml │ └── test │ ├── java │ └── com │ │ └── packt │ │ └── modern │ │ └── api │ │ ├── ECommerceAppTests.java │ │ └── TestConfig.java │ └── resources │ └── application.properties ├── Chapter06 ├── .gitignore ├── Chapter06.postman_collection.json ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AppConfig.java │ │ │ ├── controller │ │ │ ├── AddressController.java │ │ │ ├── AuthController.java │ │ │ ├── CardController.java │ │ │ ├── CartsController.java │ │ │ ├── CustomerController.java │ │ │ ├── OrderController.java │ │ │ ├── PaymentController.java │ │ │ ├── ProductController.java │ │ │ └── ShipmentController.java │ │ │ ├── eCommerceApp.java │ │ │ ├── entity │ │ │ ├── AddressEntity.java │ │ │ ├── AuthorizationEntity.java │ │ │ ├── CardEntity.java │ │ │ ├── CartEntity.java │ │ │ ├── ItemEntity.java │ │ │ ├── OrderEntity.java │ │ │ ├── OrderItemEntity.java │ │ │ ├── PaymentEntity.java │ │ │ ├── ProductEntity.java │ │ │ ├── RoleEnum.java │ │ │ ├── ShipmentEntity.java │ │ │ ├── TagEntity.java │ │ │ ├── UserEntity.java │ │ │ └── UserTokenEntity.java │ │ │ ├── exception │ │ │ ├── CustomerNotFoundException.java │ │ │ ├── Error.java │ │ │ ├── ErrorCode.java │ │ │ ├── ErrorUtils.java │ │ │ ├── GenericAlreadyExistsException.java │ │ │ ├── InvalidRefreshTokenException.java │ │ │ ├── ItemNotFoundException.java │ │ │ ├── ResourceNotFoundException.java │ │ │ └── RestApiErrorHandler.java │ │ │ ├── hateoas │ │ │ ├── AddressRepresentationModelAssembler.java │ │ │ ├── CardRepresentationModelAssembler.java │ │ │ ├── CartRepresentationModelAssembler.java │ │ │ ├── OrderRepresentationModelAssembler.java │ │ │ ├── PaymentRepresentationModelAssembler.java │ │ │ ├── ProductRepresentationModelAssembler.java │ │ │ ├── ShipmentRepresentationModelAssembler.java │ │ │ └── UserRepresentationModelAssembler.java │ │ │ ├── repository │ │ │ ├── AddressRepository.java │ │ │ ├── AuthorizationRepository.java │ │ │ ├── CardRepository.java │ │ │ ├── CartRepository.java │ │ │ ├── ItemRepository.java │ │ │ ├── OrderItemRepository.java │ │ │ ├── OrderRepository.java │ │ │ ├── OrderRepositoryExt.java │ │ │ ├── OrderRepositoryImpl.java │ │ │ ├── PaymentRepository.java │ │ │ ├── ProductRepository.java │ │ │ ├── ShipmentRepository.java │ │ │ ├── TagRepository.java │ │ │ ├── UserRepository.java │ │ │ └── UserTokenRepository.java │ │ │ ├── security │ │ │ ├── Constants.java │ │ │ ├── JwtManager.java │ │ │ ├── SecurityConfig.java │ │ │ └── UNUSED │ │ │ │ ├── ApiAccessDeniedHandler.java │ │ │ │ ├── ApiAuthenticationEntryPoint.java │ │ │ │ ├── FilterChainFailureHandler.java │ │ │ │ ├── JwtAuthenticationFilter.java │ │ │ │ └── LoginFilter.java │ │ │ └── service │ │ │ ├── AddressService.java │ │ │ ├── AddressServiceImpl.java │ │ │ ├── CardService.java │ │ │ ├── CardServiceImpl.java │ │ │ ├── CartService.java │ │ │ ├── CartServiceImpl.java │ │ │ ├── ItemService.java │ │ │ ├── ItemServiceImpl.java │ │ │ ├── OrderService.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── PaymentService.java │ │ │ ├── PaymentServiceImpl.java │ │ │ ├── ProductService.java │ │ │ ├── ProductServiceImpl.java │ │ │ ├── ShipmentService.java │ │ │ ├── ShipmentServiceImpl.java │ │ │ ├── UserDetailServiceImpl.java │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── api │ │ ├── .openapi-generator-ignore │ │ ├── config.json │ │ └── openapi.yaml │ │ ├── application.properties │ │ ├── db │ │ └── migration │ │ │ └── V1.0.0__Init.sql │ │ ├── jwt-keystore.jks │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ └── eCommerceAppTests.java ├── Chapter07 └── ecomm-ui │ ├── .eslintcache │ ├── .gitignore │ ├── README.md │ ├── craco.config.js │ ├── package.json │ ├── public │ ├── favicon.ico │ ├── images │ │ ├── Antifragile.jpg │ │ ├── Hackers.jpg │ │ ├── HowToFail.jpeg │ │ ├── Influence.jpeg │ │ ├── PoorCharlie.jpeg │ │ ├── Sapiens.jpeg │ │ ├── Seeking.jpg │ │ ├── ThinkingFast.jpeg │ │ ├── ThinkingIn.jpg │ │ └── ZeroToOne.jpg │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt │ ├── src │ ├── App.js │ ├── App.test.js │ ├── api │ │ ├── Auth.js │ │ ├── CartClient.js │ │ ├── Config.js │ │ ├── CustomerClient.js │ │ ├── OrderClient.js │ │ └── ProductClient.js │ ├── components │ │ ├── Button.js │ │ ├── Cart.js │ │ ├── CartItem.js │ │ ├── Footer.js │ │ ├── Header.js │ │ ├── Login.js │ │ ├── NotFound.js │ │ ├── Orders.js │ │ ├── ProductCard.js │ │ ├── ProductDetail.js │ │ ├── ProductList.js │ │ └── Products.js │ ├── hooks │ │ ├── CartContext.js │ │ └── useToken.js │ ├── index.css │ ├── index.js │ ├── reportWebVitals.js │ └── setupTests.js │ ├── tailwind.config.js │ └── yarn.lock ├── Chapter08 ├── .gitignore ├── Chapter08.postman_collection.json ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── integration │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AuthClient.java │ │ │ ├── TestUtils.java │ │ │ └── controller │ │ │ └── AddressControllerIT.java │ └── resources │ │ ├── application.properties │ │ ├── db.migration │ │ └── V1.0.0__Init.sql │ │ └── logback-spring.xml │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AppConfig.java │ │ │ ├── controller │ │ │ ├── AddressController.java │ │ │ ├── AuthController.java │ │ │ ├── CardController.java │ │ │ ├── CartsController.java │ │ │ ├── CustomerController.java │ │ │ ├── OrderController.java │ │ │ ├── PaymentController.java │ │ │ ├── ProductController.java │ │ │ └── ShipmentController.java │ │ │ ├── eCommerceApp.java │ │ │ ├── entity │ │ │ ├── AddressEntity.java │ │ │ ├── AuthorizationEntity.java │ │ │ ├── CardEntity.java │ │ │ ├── CartEntity.java │ │ │ ├── ItemEntity.java │ │ │ ├── OrderEntity.java │ │ │ ├── OrderItemEntity.java │ │ │ ├── PaymentEntity.java │ │ │ ├── ProductEntity.java │ │ │ ├── RoleEnum.java │ │ │ ├── ShipmentEntity.java │ │ │ ├── TagEntity.java │ │ │ ├── UserEntity.java │ │ │ └── UserTokenEntity.java │ │ │ ├── exception │ │ │ ├── CustomerNotFoundException.java │ │ │ ├── Error.java │ │ │ ├── ErrorCode.java │ │ │ ├── ErrorUtils.java │ │ │ ├── GenericAlreadyExistsException.java │ │ │ ├── InvalidRefreshTokenException.java │ │ │ ├── ItemNotFoundException.java │ │ │ ├── ResourceNotFoundException.java │ │ │ └── RestApiErrorHandler.java │ │ │ ├── hateoas │ │ │ ├── AddressRepresentationModelAssembler.java │ │ │ ├── CardRepresentationModelAssembler.java │ │ │ ├── CartRepresentationModelAssembler.java │ │ │ ├── OrderRepresentationModelAssembler.java │ │ │ ├── PaymentRepresentationModelAssembler.java │ │ │ ├── ProductRepresentationModelAssembler.java │ │ │ ├── ShipmentRepresentationModelAssembler.java │ │ │ └── UserRepresentationModelAssembler.java │ │ │ ├── repository │ │ │ ├── AddressRepository.java │ │ │ ├── AuthorizationRepository.java │ │ │ ├── CardRepository.java │ │ │ ├── CartRepository.java │ │ │ ├── ItemRepository.java │ │ │ ├── OrderItemRepository.java │ │ │ ├── OrderRepository.java │ │ │ ├── OrderRepositoryExt.java │ │ │ ├── OrderRepositoryImpl.java │ │ │ ├── PaymentRepository.java │ │ │ ├── ProductRepository.java │ │ │ ├── ShipmentRepository.java │ │ │ ├── TagRepository.java │ │ │ ├── UserRepository.java │ │ │ └── UserTokenRepository.java │ │ │ ├── security │ │ │ ├── Constants.java │ │ │ ├── JwtManager.java │ │ │ ├── SecurityConfig.java │ │ │ └── UNUSED │ │ │ │ ├── ApiAccessDeniedHandler.java │ │ │ │ ├── ApiAuthenticationEntryPoint.java │ │ │ │ ├── FilterChainFailureHandler.java │ │ │ │ ├── JwtAuthenticationFilter.java │ │ │ │ └── LoginFilter.java │ │ │ └── service │ │ │ ├── AddressService.java │ │ │ ├── AddressServiceImpl.java │ │ │ ├── CardService.java │ │ │ ├── CardServiceImpl.java │ │ │ ├── CartService.java │ │ │ ├── CartServiceImpl.java │ │ │ ├── ItemService.java │ │ │ ├── ItemServiceImpl.java │ │ │ ├── OrderService.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── PaymentService.java │ │ │ ├── PaymentServiceImpl.java │ │ │ ├── ProductService.java │ │ │ ├── ProductServiceImpl.java │ │ │ ├── ShipmentService.java │ │ │ ├── ShipmentServiceImpl.java │ │ │ ├── UserDetailServiceImpl.java │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── api │ │ ├── .openapi-generator-ignore │ │ ├── config.json │ │ └── openapi.yaml │ │ ├── application.properties │ │ ├── db │ │ └── migration │ │ │ └── V1.0.0__Init.sql │ │ ├── jwt-keystore.jks │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ ├── controller │ ├── AddressControllerTest.java │ ├── ProductControllerTest.java │ └── ShipmentControllerTest.java │ ├── eCommerceAppTests.java │ └── service │ └── AddressServiceTest.java ├── Chapter09 ├── .gitignore ├── Chapter09.postman_collection.json ├── build.gradle ├── deployment.yaml ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── k8s │ └── deployment.yaml ├── settings.gradle └── src │ ├── integration │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AuthClient.java │ │ │ ├── TestUtils.java │ │ │ └── controller │ │ │ └── AddressControllerIT.java │ └── resources │ │ ├── application.properties │ │ ├── db.migration │ │ └── V1.0.0__Init.sql │ │ └── logback-spring.xml │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── AppConfig.java │ │ │ ├── controller │ │ │ ├── AddressController.java │ │ │ ├── AuthController.java │ │ │ ├── CardController.java │ │ │ ├── CartsController.java │ │ │ ├── CustomerController.java │ │ │ ├── OrderController.java │ │ │ ├── PaymentController.java │ │ │ ├── ProductController.java │ │ │ └── ShipmentController.java │ │ │ ├── eCommerceApp.java │ │ │ ├── entity │ │ │ ├── AddressEntity.java │ │ │ ├── AuthorizationEntity.java │ │ │ ├── CardEntity.java │ │ │ ├── CartEntity.java │ │ │ ├── ItemEntity.java │ │ │ ├── OrderEntity.java │ │ │ ├── OrderItemEntity.java │ │ │ ├── PaymentEntity.java │ │ │ ├── ProductEntity.java │ │ │ ├── RoleEnum.java │ │ │ ├── ShipmentEntity.java │ │ │ ├── TagEntity.java │ │ │ ├── UserEntity.java │ │ │ └── UserTokenEntity.java │ │ │ ├── exception │ │ │ ├── CustomerNotFoundException.java │ │ │ ├── Error.java │ │ │ ├── ErrorCode.java │ │ │ ├── ErrorUtils.java │ │ │ ├── GenericAlreadyExistsException.java │ │ │ ├── InvalidRefreshTokenException.java │ │ │ ├── ItemNotFoundException.java │ │ │ ├── ResourceNotFoundException.java │ │ │ └── RestApiErrorHandler.java │ │ │ ├── hateoas │ │ │ ├── AddressRepresentationModelAssembler.java │ │ │ ├── CardRepresentationModelAssembler.java │ │ │ ├── CartRepresentationModelAssembler.java │ │ │ ├── OrderRepresentationModelAssembler.java │ │ │ ├── PaymentRepresentationModelAssembler.java │ │ │ ├── ProductRepresentationModelAssembler.java │ │ │ ├── ShipmentRepresentationModelAssembler.java │ │ │ └── UserRepresentationModelAssembler.java │ │ │ ├── repository │ │ │ ├── AddressRepository.java │ │ │ ├── AuthorizationRepository.java │ │ │ ├── CardRepository.java │ │ │ ├── CartRepository.java │ │ │ ├── ItemRepository.java │ │ │ ├── OrderItemRepository.java │ │ │ ├── OrderRepository.java │ │ │ ├── OrderRepositoryExt.java │ │ │ ├── OrderRepositoryImpl.java │ │ │ ├── PaymentRepository.java │ │ │ ├── ProductRepository.java │ │ │ ├── ShipmentRepository.java │ │ │ ├── TagRepository.java │ │ │ ├── UserRepository.java │ │ │ └── UserTokenRepository.java │ │ │ ├── security │ │ │ ├── Constants.java │ │ │ ├── JwtManager.java │ │ │ ├── SecurityConfig.java │ │ │ └── UNUSED │ │ │ │ ├── ApiAccessDeniedHandler.java │ │ │ │ ├── ApiAuthenticationEntryPoint.java │ │ │ │ ├── FilterChainFailureHandler.java │ │ │ │ ├── JwtAuthenticationFilter.java │ │ │ │ └── LoginFilter.java │ │ │ └── service │ │ │ ├── AddressService.java │ │ │ ├── AddressServiceImpl.java │ │ │ ├── CardService.java │ │ │ ├── CardServiceImpl.java │ │ │ ├── CartService.java │ │ │ ├── CartServiceImpl.java │ │ │ ├── ItemService.java │ │ │ ├── ItemServiceImpl.java │ │ │ ├── OrderService.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── PaymentService.java │ │ │ ├── PaymentServiceImpl.java │ │ │ ├── ProductService.java │ │ │ ├── ProductServiceImpl.java │ │ │ ├── ShipmentService.java │ │ │ ├── ShipmentServiceImpl.java │ │ │ ├── UserDetailServiceImpl.java │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── api │ │ ├── .openapi-generator-ignore │ │ ├── config.json │ │ └── openapi.yaml │ │ ├── application.properties │ │ ├── db │ │ └── migration │ │ │ └── V1.0.0__Init.sql │ │ ├── jwt-keystore.jks │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ ├── controller │ ├── AddressControllerTest.java │ ├── ProductControllerTest.java │ └── ShipmentControllerTest.java │ ├── eCommerceAppTests.java │ └── service │ └── AddressServiceTest.java ├── Chapter11 ├── .gitignore ├── api │ ├── .gitattributes │ ├── .gitignore │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── lib │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── grpc │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── modern │ │ │ │ └── api │ │ │ │ └── grpc │ │ │ │ └── v1 │ │ │ │ ├── ChargeServiceGrpc.java │ │ │ │ └── SourceServiceGrpc.java │ │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── modern │ │ │ │ └── api │ │ │ │ └── grpc │ │ │ │ └── v1 │ │ │ │ ├── AchCreditTransfer.java │ │ │ │ ├── AchCreditTransferOrBuilder.java │ │ │ │ ├── Address.java │ │ │ │ ├── AddressOrBuilder.java │ │ │ │ ├── AttachOrDetachReq.java │ │ │ │ ├── AttachOrDetachReqOrBuilder.java │ │ │ │ ├── BillingDetails.java │ │ │ │ ├── BillingDetailsOrBuilder.java │ │ │ │ ├── CaptureChargeReq.java │ │ │ │ ├── CaptureChargeReqOrBuilder.java │ │ │ │ ├── Card.java │ │ │ │ ├── CardOrBuilder.java │ │ │ │ ├── Charge.java │ │ │ │ ├── ChargeId.java │ │ │ │ ├── ChargeIdOrBuilder.java │ │ │ │ ├── ChargeOrBuilder.java │ │ │ │ ├── CreateChargeReq.java │ │ │ │ ├── CreateChargeReqOrBuilder.java │ │ │ │ ├── CreateSourceReq.java │ │ │ │ ├── CreateSourceReqOrBuilder.java │ │ │ │ ├── CustomerId.java │ │ │ │ ├── CustomerIdOrBuilder.java │ │ │ │ ├── Flow.java │ │ │ │ ├── Owner.java │ │ │ │ ├── OwnerOrBuilder.java │ │ │ │ ├── PaymentGatewayService.java │ │ │ │ ├── PaymentMethodDetails.java │ │ │ │ ├── PaymentMethodDetailsOrBuilder.java │ │ │ │ ├── Receiver.java │ │ │ │ ├── ReceiverOrBuilder.java │ │ │ │ ├── Refund.java │ │ │ │ ├── RefundOrBuilder.java │ │ │ │ ├── Source.java │ │ │ │ ├── SourceId.java │ │ │ │ ├── SourceIdOrBuilder.java │ │ │ │ ├── SourceOrBuilder.java │ │ │ │ ├── StripeAccount.java │ │ │ │ ├── StripeAccountOrBuilder.java │ │ │ │ ├── UpdateChargeReq.java │ │ │ │ ├── UpdateChargeReqOrBuilder.java │ │ │ │ ├── UpdateSourceReq.java │ │ │ │ ├── UpdateSourceReqOrBuilder.java │ │ │ │ └── Usage.java │ │ │ └── proto │ │ │ └── PaymentGatewayService.proto │ └── settings.gradle ├── client │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── modern │ │ │ │ └── api │ │ │ │ ├── ClientApp.java │ │ │ │ ├── client │ │ │ │ ├── GrpcClient.java │ │ │ │ └── GrpcClientRunner.java │ │ │ │ └── controller │ │ │ │ └── ChargeController.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── modern │ │ └── api │ │ └── ClientAppTests.java └── server │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── ServerApp.java │ │ │ └── server │ │ │ ├── GrpcServer.java │ │ │ ├── GrpcServerRunner.java │ │ │ ├── exception │ │ │ └── ExceptionUtils.java │ │ │ ├── interceptor │ │ │ └── ExceptionInterceptor.java │ │ │ ├── repository │ │ │ ├── ChargeRepository.java │ │ │ ├── ChargeRepositoryImpl.java │ │ │ ├── DbStore.java │ │ │ ├── SourceRepository.java │ │ │ └── SourceRepositoryImpl.java │ │ │ └── service │ │ │ ├── ChargeService.java │ │ │ └── SourceService.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ └── ServerAppTests.java ├── Chapter12 ├── .gitignore ├── api │ ├── .gitattributes │ ├── .gitignore │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── lib │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── grpc │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── modern │ │ │ │ └── api │ │ │ │ └── grpc │ │ │ │ └── v1 │ │ │ │ ├── ChargeServiceGrpc.java │ │ │ │ └── SourceServiceGrpc.java │ │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── modern │ │ │ │ └── api │ │ │ │ └── grpc │ │ │ │ └── v1 │ │ │ │ ├── AchCreditTransfer.java │ │ │ │ ├── AchCreditTransferOrBuilder.java │ │ │ │ ├── Address.java │ │ │ │ ├── AddressOrBuilder.java │ │ │ │ ├── AttachOrDetachReq.java │ │ │ │ ├── AttachOrDetachReqOrBuilder.java │ │ │ │ ├── BillingDetails.java │ │ │ │ ├── BillingDetailsOrBuilder.java │ │ │ │ ├── CaptureChargeReq.java │ │ │ │ ├── CaptureChargeReqOrBuilder.java │ │ │ │ ├── Card.java │ │ │ │ ├── CardOrBuilder.java │ │ │ │ ├── Charge.java │ │ │ │ ├── ChargeId.java │ │ │ │ ├── ChargeIdOrBuilder.java │ │ │ │ ├── ChargeOrBuilder.java │ │ │ │ ├── CreateChargeReq.java │ │ │ │ ├── CreateChargeReqOrBuilder.java │ │ │ │ ├── CreateSourceReq.java │ │ │ │ ├── CreateSourceReqOrBuilder.java │ │ │ │ ├── CustomerId.java │ │ │ │ ├── CustomerIdOrBuilder.java │ │ │ │ ├── Flow.java │ │ │ │ ├── Owner.java │ │ │ │ ├── OwnerOrBuilder.java │ │ │ │ ├── PaymentGatewayService.java │ │ │ │ ├── PaymentMethodDetails.java │ │ │ │ ├── PaymentMethodDetailsOrBuilder.java │ │ │ │ ├── Receiver.java │ │ │ │ ├── ReceiverOrBuilder.java │ │ │ │ ├── Refund.java │ │ │ │ ├── RefundOrBuilder.java │ │ │ │ ├── Source.java │ │ │ │ ├── SourceId.java │ │ │ │ ├── SourceIdOrBuilder.java │ │ │ │ ├── SourceOrBuilder.java │ │ │ │ ├── StripeAccount.java │ │ │ │ ├── StripeAccountOrBuilder.java │ │ │ │ ├── UpdateChargeReq.java │ │ │ │ ├── UpdateChargeReqOrBuilder.java │ │ │ │ ├── UpdateSourceReq.java │ │ │ │ ├── UpdateSourceReqOrBuilder.java │ │ │ │ └── Usage.java │ │ │ └── proto │ │ │ └── PaymentGatewayService.proto │ └── settings.gradle ├── client │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── modern │ │ │ │ └── api │ │ │ │ ├── ClientApp.java │ │ │ │ ├── client │ │ │ │ ├── Config.java │ │ │ │ ├── GrpcClient.java │ │ │ │ └── GrpcClientRunner.java │ │ │ │ └── controller │ │ │ │ └── ChargeController.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── logback-spring.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── modern │ │ └── api │ │ └── ClientAppTests.java ├── docker-compose.yaml └── server │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── ServerApp.java │ │ │ └── server │ │ │ ├── Config.java │ │ │ ├── GrpcServer.java │ │ │ ├── GrpcServerRunner.java │ │ │ ├── exception │ │ │ └── ExceptionUtils.java │ │ │ ├── interceptor │ │ │ └── ExceptionInterceptor.java │ │ │ ├── repository │ │ │ ├── ChargeRepository.java │ │ │ ├── ChargeRepositoryImpl.java │ │ │ ├── DbStore.java │ │ │ ├── SourceRepository.java │ │ │ └── SourceRepositoryImpl.java │ │ │ └── service │ │ │ ├── ChargeService.java │ │ │ └── SourceService.java │ └── resources │ │ ├── application.properties │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ └── ServerAppTests.java ├── Chapter14 ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── modern │ │ │ └── api │ │ │ ├── Chapter14App.java │ │ │ ├── datafetchers │ │ │ ├── ProductDatafetcher.java │ │ │ └── ProductsDatafetcher.java │ │ │ ├── dataloaders │ │ │ ├── TagDataloader.java │ │ │ └── TagsDataloaderWithContext.java │ │ │ ├── instrumentation │ │ │ └── TracingInstrumentation.java │ │ │ ├── repository │ │ │ ├── InMemRepository.java │ │ │ └── Repository.java │ │ │ ├── scalar │ │ │ ├── BigDecimalScalar.java │ │ │ └── DateTimeScalar.java │ │ │ └── services │ │ │ ├── ProductService.java │ │ │ ├── ProductServiceImpl.java │ │ │ ├── TagService.java │ │ │ └── TagServiceImpl.java │ └── resources │ │ ├── application.properties │ │ └── schema │ │ └── schema.graphqls │ └── test │ └── java │ └── com │ └── packt │ └── modern │ └── api │ └── datafetchers │ └── ProductDatafetcherTest.java ├── LICENSE └── README.md /Chapter02/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | !**/src/main/**/out/ 24 | !**/src/test/**/out/ 25 | 26 | ### NetBeans ### 27 | /nbproject/private/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | 33 | ### VS Code ### 34 | .vscode/ 35 | -------------------------------------------------------------------------------- /Chapter02/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.3.4.RELEASE' 3 | id 'io.spring.dependency-management' version '1.0.10.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.packt.modern.api' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '1.14' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-web' 17 | implementation 'org.springframework.boot:spring-boot-starter-aop' 18 | 19 | testImplementation('org.springframework.boot:spring-boot-starter-test') { 20 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 21 | } 22 | } 23 | 24 | test { 25 | useJUnitPlatform() 26 | } 27 | -------------------------------------------------------------------------------- /Chapter02/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter02/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter02/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter02/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Chapter02' 2 | -------------------------------------------------------------------------------- /Chapter02/src/main/java/com/packt/modern/api/aop/TimeMonitor.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.aop; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter02 - Modern API Development with Spring and Spring Boot 11 | * @created : 10/20/2020, Tuesday 12 | **/ 13 | @Target(ElementType.METHOD) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface TimeMonitor { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter02/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter02/src/test/java/com/packt/modern/api/AopDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AopDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter03/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | **-logs/ 5 | !gradle/wrapper/gradle-wrapper.jar 6 | !**/src/main/**/build/ 7 | !**/src/test/**/build/ 8 | 9 | ### STS ### 10 | .apt_generated 11 | .classpath 12 | .factorypath 13 | .project 14 | .settings 15 | .springBeans 16 | .sts4-cache 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | out/ 24 | !**/src/main/**/out/ 25 | !**/src/test/**/out/ 26 | 27 | ### NetBeans ### 28 | /nbproject/private/ 29 | /nbbuild/ 30 | /dist/ 31 | /nbdist/ 32 | /.nb-gradle/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | -------------------------------------------------------------------------------- /Chapter03/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter03/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter03/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter03/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Chapter03' 2 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packt/modern/api/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.http.MediaType; 4 | import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter03 - Modern API Development with Spring and Spring Boot 10 | * @created : 11/10/2020, Tuesday 11 | **/ 12 | public class AppConfig implements WebMvcConfigurer { 13 | 14 | /* @Override 15 | public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { 16 | configurer.defaultContentType(MediaType.APPLICATION_JSON). 17 | mediaType("xml", MediaType.APPLICATION_XML). 18 | mediaType("json", MediaType.APPLICATION_JSON) 19 | }*/ 20 | } 21 | -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packt/modern/api/eCommerceApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class eCommerceApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(eCommerceApp.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter03/src/main/java/com/packt/modern/api/exceptions/ErrorUtils.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exceptions; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter03 - Modern API Development with Spring and Spring Boot 6 | * @created : 11/04/2020, Tuesday 7 | **/ 8 | public class ErrorUtils { 9 | 10 | private ErrorUtils() { 11 | } 12 | 13 | /** 14 | * Creates and return an error object 15 | * 16 | * @param errMsgKey 17 | * @param errorCode 18 | * @param httpStatusCode 19 | * @param url 20 | * @return error 21 | */ 22 | public static Error createError(final String errMsgKey, final String errorCode, 23 | final Integer httpStatusCode) { 24 | Error error = new Error(); 25 | error.setMessage(errMsgKey); 26 | error.setErrorCode(errorCode); 27 | error.setStatus(httpStatusCode); 28 | return error; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter03/src/main/resources/api/.openapi-generator-ignore: -------------------------------------------------------------------------------- 1 | **/*Controller.java -------------------------------------------------------------------------------- /Chapter03/src/main/resources/api/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "library": "spring-mvc", 3 | "dateLibrary": "java8", 4 | "hideGenerationTimestamp": true, 5 | "modelPackage": "com.packt.modern.api.model", 6 | "apiPackage": "com.packt.modern.api", 7 | "invokerPackage": "com.packt.modern.api", 8 | "serializableModel": true, 9 | "useTags": true, 10 | "useGzipFeature" : true, 11 | "hateoas": true, 12 | "withXml": true, 13 | "importMappings": { 14 | "ResourceSupport":"org.springframework.hateoas.RepresentationModel", 15 | "Link": "org.springframework.hateoas.Link" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter03/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=Chapter03 2 | -------------------------------------------------------------------------------- /Chapter03/src/test/java/com/packt/modern/api/eCommerceAppTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | class eCommerceAppTests { 10 | 11 | private static final Logger log = LoggerFactory.getLogger(eCommerceAppTests.class); 12 | 13 | @Test 14 | void contextLoads() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | **-logs/ 5 | !gradle/wrapper/gradle-wrapper.jar 6 | !**/src/main/**/build/ 7 | !**/src/test/**/build/ 8 | 9 | ### STS ### 10 | .apt_generated 11 | .classpath 12 | .factorypath 13 | .project 14 | .settings 15 | .springBeans 16 | .sts4-cache 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | out/ 24 | !**/src/main/**/out/ 25 | !**/src/test/**/out/ 26 | 27 | ### NetBeans ### 28 | /nbproject/private/ 29 | /nbbuild/ 30 | /dist/ 31 | /nbdist/ 32 | /.nb-gradle/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | -------------------------------------------------------------------------------- /Chapter04/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter04/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter04/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter04/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Chapter04' 2 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.filter.ShallowEtagHeaderFilter; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | @Configuration 12 | public class AppConfig { 13 | @Bean 14 | public ShallowEtagHeaderFilter shallowEtagHeaderFilter() { 15 | return new ShallowEtagHeaderFilter(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/eCommerceApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class eCommerceApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(eCommerceApp.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/exception/CustomerNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class CustomerNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public CustomerNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public CustomerNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/exception/ErrorUtils.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ErrorUtils { 8 | 9 | private ErrorUtils() { 10 | } 11 | 12 | /** 13 | * Creates and return an error object 14 | * 15 | * @param errMsgKey 16 | * @param errorCode 17 | * @param httpStatusCode 18 | * @param url 19 | * @return error 20 | */ 21 | public static Error createError(final String errMsgKey, final String errorCode, 22 | final Integer httpStatusCode) { 23 | Error error = new Error(); 24 | error.setMessage(errMsgKey); 25 | error.setErrorCode(errorCode); 26 | error.setStatus(httpStatusCode); 27 | return error; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/exception/GenericAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class GenericAlreadyExistsException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public GenericAlreadyExistsException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public GenericAlreadyExistsException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/exception/ItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ItemNotFoundException extends Throwable { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ItemNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ItemNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ResourceNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ResourceNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ResourceNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AddressRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/AuthorizationRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AuthorizationRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/CardRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface CardRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.CrudRepository; 8 | import org.springframework.data.repository.query.Param; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface CartRepository extends CrudRepository { 15 | @Query("select c from CartEntity c join c.user u where u.id = :customerId") 16 | public Optional findByCustomerId(@Param("customerId") UUID customerId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/ItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ItemEntity; 4 | import java.util.List; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Modifying; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.CrudRepository; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface ItemRepository extends CrudRepository { 15 | @Query(value = "select i.* from ecomm.cart c, ecomm.item i, ecomm.user u, ecomm.cart_item ci where u.id = :customerId and c.user_id=u.id and c.id=ci.cart_id and i.id=ci.item_id", nativeQuery=true) 16 | Iterable findByCustomerId(String customerId); 17 | 18 | @Modifying 19 | @Query(value = "delete from ecomm.cart_item where item_id in (:ids) and cart_id = :cartId", nativeQuery = true) 20 | void deleteCartItemJoinById(List ids, UUID cartId); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/OrderItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderItemEntity; 4 | import com.packt.modern.api.entity.TagEntity; 5 | import java.util.UUID; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface OrderItemRepository extends CrudRepository { 14 | } 15 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.CrudRepository; 7 | import org.springframework.data.repository.query.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Repository 15 | public interface OrderRepository extends CrudRepository, OrderRepositoryExt { 16 | 17 | @Query("select o from OrderEntity o join o.userEntity u where u.id = :customerId") 18 | public Iterable findByCustomerId(@Param("customerId") UUID customerId); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/OrderRepositoryExt.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface OrderRepositoryExt { 12 | Optional insert(NewOrder m); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/PaymentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.PaymentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface PaymentRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ProductRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/ShipmentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ShipmentRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/TagRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.TagEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface TagRepository extends CrudRepository { 13 | } 14 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.UserEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface UserRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/AddressService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import com.packt.modern.api.model.AddAddressReq; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AddressService { 12 | public Optional createAddress(AddAddressReq addAddressReq); 13 | public void deleteAddressesById(String id); 14 | public Optional getAddressesById(String id); 15 | public Iterable getAllAddresses(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/CardService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import com.packt.modern.api.model.AddCardReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface CardService { 13 | public void deleteCardById(String id); 14 | public Iterable getAllCards(); 15 | public Optional getCardById(String id); 16 | public Optional registerCard(@Valid AddCardReq addCardReq); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | import javax.validation.Valid; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface CartService { 13 | 14 | public List addCartItemsByCustomerId(String customerId, @Valid Item item); 15 | 16 | public List addOrReplaceItemsByCustomerId(String customerId, @Valid Item item); 17 | 18 | public void deleteCart(String customerId); 19 | 20 | public void deleteItemFromCart(String customerId, String itemId); 21 | 22 | public CartEntity getCartByCustomerId(String customerId); 23 | 24 | public List getCartItemsByCustomerId(String customerId); 25 | 26 | public Item getCartItemsByItemId(String customerId, String itemId); 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/ItemService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ItemEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ItemService { 12 | 13 | ItemEntity toEntity(Item m); 14 | 15 | List toEntityList(List items); 16 | 17 | Item toModel(ItemEntity e); 18 | 19 | List toModelList(List items); 20 | } 21 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface OrderService { 14 | 15 | public Optional addOrder(@Valid NewOrder newOrder); 16 | public Iterable getOrdersByCustomerId(@NotNull @Valid String customerId); 17 | public Optional getByOrderId(String id); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/PaymentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import com.packt.modern.api.model.PaymentReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface PaymentService { 14 | 15 | public Optional authorize(@Valid PaymentReq paymentReq); 16 | public Optional getOrdersPaymentAuthorization(@NotNull String orderId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.Optional; 5 | import javax.validation.constraints.Min; 6 | import javax.validation.constraints.NotNull; 7 | import org.springframework.validation.annotation.Validated; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | @Validated 14 | public interface ProductService { 15 | @NotNull Iterable getAllProducts(); 16 | Optional getProduct(@Min(value = 1L, message = "Invalid product ID.") String id); 17 | } -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import com.packt.modern.api.repository.ProductRepository; 5 | import java.util.Optional; 6 | import java.util.UUID; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Service 15 | @Transactional 16 | public class ProductServiceImpl implements ProductService { 17 | 18 | private ProductRepository repository; 19 | 20 | public ProductServiceImpl(ProductRepository repository) { 21 | this.repository = repository; 22 | } 23 | 24 | @Override 25 | public Iterable getAllProducts() { 26 | return repository.findAll(); 27 | } 28 | 29 | @Override 30 | public Optional getProduct(String id) { 31 | return repository 32 | .findById(UUID.fromString(id)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/ShipmentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import javax.validation.constraints.Min; 5 | 6 | /** 7 | * @author : github.com/sharmasourabh 8 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 9 | **/ 10 | public interface ShipmentService { 11 | public Iterable getShipmentByOrderId(@Min(value = 1L, message = "Invalid product ID.") String id); 12 | } 13 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/ShipmentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import com.packt.modern.api.repository.ShipmentRepository; 5 | import java.util.List; 6 | import java.util.UUID; 7 | import javax.validation.constraints.Min; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Service 15 | public class ShipmentServiceImpl implements ShipmentService { 16 | 17 | private ShipmentRepository repository; 18 | 19 | public ShipmentServiceImpl(ShipmentRepository repository) { 20 | this.repository = repository; 21 | } 22 | 23 | @Override 24 | public Iterable getShipmentByOrderId( 25 | @Min(value = 1L, message = "Invalid shipment ID.") String id) { 26 | return repository.findAllById(List.of(UUID.fromString(id))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter04/src/main/java/com/packt/modern/api/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import com.packt.modern.api.entity.CardEntity; 5 | import com.packt.modern.api.entity.UserEntity; 6 | import java.util.Optional; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter04 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface UserService { 13 | public void deleteCustomerById(String id); 14 | public Optional> getAddressesByCustomerId(String id); 15 | public Iterable getAllCustomers(); 16 | public Optional getCardByCustomerId(String id); 17 | public Optional getCustomerById(String id); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter04/src/main/resources/api/.openapi-generator-ignore: -------------------------------------------------------------------------------- 1 | **/*Controller.java -------------------------------------------------------------------------------- /Chapter04/src/main/resources/api/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "library": "spring-mvc", 3 | "dateLibrary": "java8", 4 | "hideGenerationTimestamp": true, 5 | "modelPackage": "com.packt.modern.api.model", 6 | "apiPackage": "com.packt.modern.api", 7 | "invokerPackage": "com.packt.modern.api", 8 | "serializableModel": true, 9 | "useTags": true, 10 | "useGzipFeature" : true, 11 | "hateoas": true, 12 | "withXml": true, 13 | "importMappings": { 14 | "ResourceSupport":"org.springframework.hateoas.RepresentationModel", 15 | "Link": "org.springframework.hateoas.Link" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=Chapter04 2 | 3 | # Datasource configuration 4 | spring.datasource.name=ecomm 5 | spring.datasource.url=jdbc:h2:mem:ecomm;DB_CLOSE_DELAY=-1;IGNORECASE=TRUE;DATABASE_TO_UPPER=false 6 | spring.datasource.driverClassName=org.h2.Driver 7 | spring.datasource.username=sa 8 | spring.datasource.password= 9 | 10 | # H2 configuration 11 | spring.h2.console.enabled=true 12 | spring.h2.console.settings.web-allow-others=false 13 | 14 | # JPA configuration 15 | spring.jpa.properties.hibernate.default_schema=ecomm 16 | spring.jpa.database-platform=org.hibernate.dialect.H2Dialect 17 | spring.jpa.show-sql=true 18 | spring.jpa.format_sql=true 19 | spring.jpa.generate-ddl=false 20 | spring.jpa.hibernate.ddl-auto=none 21 | 22 | # Flyway configuration 23 | spring.flyway.url=jdbc:h2:mem:ecomm 24 | spring.flyway.schemas=ecomm 25 | spring.flyway.user=sa 26 | spring.flyway.password= -------------------------------------------------------------------------------- /Chapter04/src/test/java/com/packt/modern/api/eCommerceAppTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | class eCommerceAppTests { 10 | 11 | private static final Logger log = LoggerFactory.getLogger(eCommerceAppTests.class); 12 | 13 | @Test 14 | void contextLoads() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter05/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | data 4 | build/ 5 | **-logs/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | !**/src/main/**/build/ 8 | !**/src/test/**/build/ 9 | 10 | ### STS ### 11 | .apt_generated 12 | .classpath 13 | .factorypath 14 | .project 15 | .settings 16 | .springBeans 17 | .sts4-cache 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | out/ 25 | !**/src/main/**/out/ 26 | !**/src/test/**/out/ 27 | 28 | ### NetBeans ### 29 | /nbproject/private/ 30 | /nbbuild/ 31 | /dist/ 32 | /nbdist/ 33 | /.nb-gradle/ 34 | 35 | ### VS Code ### 36 | .vscode/ 37 | -------------------------------------------------------------------------------- /Chapter05/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter05/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter05/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter05/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Chapter05' 2 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.http.codec.ServerCodecConfigurer; 6 | import org.springframework.web.filter.ShallowEtagHeaderFilter; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | @Configuration 13 | public class AppConfig { 14 | @Bean 15 | public ShallowEtagHeaderFilter shallowEtagHeaderFilter() { 16 | return new ShallowEtagHeaderFilter(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/ECommerceApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.WebApplicationType; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class ECommerceApp { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication app = new SpringApplication(ECommerceApp.class); 12 | app.setWebApplicationType(WebApplicationType.REACTIVE); 13 | app.run(args); 14 | } 15 | } -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/entity/TagEntity.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.entity; 2 | 3 | import java.util.UUID; 4 | import javax.validation.constraints.NotNull; 5 | import org.springframework.data.annotation.Id; 6 | import org.springframework.data.relational.core.mapping.Column; 7 | import org.springframework.data.relational.core.mapping.Table; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | 14 | @Table("ecomm.tag") 15 | public class TagEntity { 16 | 17 | @Id 18 | @Column("id") 19 | private UUID id; 20 | 21 | @NotNull(message = "Product name is required.") 22 | // @Basic(optional = false) 23 | @Column("name") 24 | private String name; 25 | 26 | public UUID getId() { 27 | return id; 28 | } 29 | 30 | public TagEntity setId(UUID id) { 31 | this.id = id; 32 | return this; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public TagEntity setName(String name) { 40 | this.name = name; 41 | return this; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/entity/UserAddressEntity.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.entity; 2 | 3 | import java.util.UUID; 4 | import org.springframework.data.relational.core.mapping.Column; 5 | import org.springframework.data.relational.core.mapping.Table; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | @Table("ecomm.user_address") 12 | public class UserAddressEntity { 13 | @Column("user_id") 14 | private UUID userId; 15 | 16 | @Column("address_id") 17 | private UUID addressID; 18 | 19 | public UUID getUserId() { 20 | return userId; 21 | } 22 | 23 | public UserAddressEntity setUserId(UUID userId) { 24 | this.userId = userId; 25 | return this; 26 | } 27 | 28 | public UUID getAddressID() { 29 | return addressID; 30 | } 31 | 32 | public UserAddressEntity setAddressID(UUID addressID) { 33 | this.addressID = addressID; 34 | return this; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/exception/CardAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class CardAlreadyExistsException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public CardAlreadyExistsException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public CardAlreadyExistsException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/exception/CustomerNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class CustomerNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public CustomerNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public CustomerNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/exception/ErrorUtils.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ErrorUtils { 8 | 9 | private ErrorUtils() { 10 | } 11 | 12 | /** 13 | * Creates and return an error object 14 | * 15 | * @param errMsgKey 16 | * @param errorCode 17 | * @param httpStatusCode 18 | * @param url 19 | * @return error 20 | */ 21 | public static Error createError(final String errMsgKey, final String errorCode, 22 | final Integer httpStatusCode) { 23 | Error error = new Error(); 24 | error.setMessage(errMsgKey); 25 | error.setErrorCode(errorCode); 26 | error.setStatus(httpStatusCode); 27 | return error; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/exception/GenericAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class GenericAlreadyExistsException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public GenericAlreadyExistsException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public GenericAlreadyExistsException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/exception/ItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ItemNotFoundException extends Throwable { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ItemNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ItemNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ResourceNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ResourceNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ResourceNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/hateoas/HateoasSupport.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.hateoas; 2 | 3 | import org.springframework.http.server.PathContainer; 4 | import org.springframework.http.server.reactive.ServerHttpRequest; 5 | import org.springframework.lang.Nullable; 6 | import org.springframework.web.server.ServerWebExchange; 7 | import org.springframework.web.util.UriComponentsBuilder; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface HateoasSupport { 14 | default UriComponentsBuilder getUriComponentBuilder(@Nullable ServerWebExchange exchange) { 15 | if (exchange == null) { 16 | return UriComponentsBuilder.fromPath("/"); 17 | } 18 | 19 | ServerHttpRequest request = exchange.getRequest(); 20 | PathContainer contextPath = request.getPath().contextPath(); 21 | 22 | return UriComponentsBuilder.fromHttpRequest(request) 23 | .replacePath(contextPath.toString()) 24 | .replaceQuery(""); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface AddressRepository extends ReactiveCrudRepository { 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/AuthorizationRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface AuthorizationRepository extends ReactiveCrudRepository { 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/CardRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.r2dbc.repository.Query; 6 | import org.springframework.data.repository.CrudRepository; 7 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface CardRepository extends ReactiveCrudRepository { 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.r2dbc.repository.Query; 6 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 7 | import reactor.core.publisher.Mono; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface CartRepository extends ReactiveCrudRepository { 14 | 15 | @Query("select c.* from ecomm.cart c join ecomm.user u on c.user_id=u.id where u.id = :customerId") 16 | Mono findByCustomerId(String customerId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/OrderItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderItemEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface OrderItemRepository extends ReactiveCrudRepository { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.r2dbc.repository.Query; 6 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 7 | import org.springframework.stereotype.Repository; 8 | import reactor.core.publisher.Flux; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Repository 15 | public interface OrderRepository extends ReactiveCrudRepository, 16 | OrderRepositoryExt { 17 | 18 | @Query("select o.* from ecomm.orders o join ecomm.user u on o.customer_id = u.id where u.id = :custId") 19 | Flux findByCustomerId(String custId); 20 | } 21 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/OrderRepositoryExt.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import reactor.core.publisher.Mono; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface OrderRepositoryExt { 12 | 13 | Mono insert(Mono m); 14 | 15 | Mono updateMapping(OrderEntity orderEntity); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/PaymentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.PaymentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface PaymentRepository extends ReactiveCrudRepository { 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.r2dbc.repository.Query; 6 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 7 | import reactor.core.publisher.Mono; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface ProductRepository extends ReactiveCrudRepository { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/ShipmentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.r2dbc.repository.Query; 6 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 7 | import reactor.core.publisher.Flux; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface ShipmentRepository extends ReactiveCrudRepository { 14 | 15 | @Query("SELECT s.* FROM ecomm.order o, ecomm.shipment s where o.shipment_id=s.id and o.id = :id") 16 | Flux getShipmentByOrderId(String id); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/repository/TagRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.TagEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.r2dbc.repository.Query; 6 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 7 | import reactor.core.publisher.Flux; 8 | 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface TagRepository extends ReactiveCrudRepository { 15 | 16 | @Query("SELECT t.* FROM ecomm.product p, ecomm.tag t, ecomm.product_tag pt where p.id = :id and p.id=pt.product_id and t.id = pt.tag_id") 17 | Flux findTagsByProductId(String id); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/AddressService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import com.packt.modern.api.model.AddAddressReq; 5 | import java.util.Optional; 6 | import java.util.UUID; 7 | import reactor.core.publisher.Flux; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface AddressService { 15 | Mono createAddress(Mono addAddressReq); 16 | Mono deleteAddressesById(String id); 17 | Mono deleteAddressesById(UUID id); 18 | Mono getAddressesById(String id); 19 | Flux getAllAddresses(); 20 | } 21 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/CardService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import com.packt.modern.api.model.AddCardReq; 5 | import java.util.Optional; 6 | import java.util.UUID; 7 | import javax.validation.Valid; 8 | import reactor.core.publisher.Flux; 9 | import reactor.core.publisher.Mono; 10 | 11 | /** 12 | * @author : github.com/sharmasourabh 13 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 14 | **/ 15 | public interface CardService { 16 | Mono deleteCardById(String id); 17 | Mono deleteCardById(UUID id); 18 | Flux getAllCards(); 19 | Mono getCardById(String id); 20 | Mono registerCard(@Valid Mono addCardReq); 21 | CardEntity toEntity(AddCardReq model); 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | import javax.validation.Valid; 7 | import reactor.core.publisher.Flux; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface CartService { 15 | 16 | Flux addCartItemsByCustomerId(CartEntity cartEntity, @Valid Mono item); 17 | 18 | Flux addOrReplaceItemsByCustomerId(CartEntity cartEntity, @Valid Mono newItem); 19 | 20 | Mono deleteCart(String customerId, String cartId); 21 | 22 | Mono deleteItemFromCart(CartEntity cartEntity, String itemId); 23 | 24 | Mono getCartByCustomerId(String customerId); 25 | } 26 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/ItemService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import com.packt.modern.api.entity.ItemEntity; 5 | import com.packt.modern.api.model.Item; 6 | import java.util.List; 7 | import reactor.core.publisher.Flux; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface ItemService { 15 | 16 | Mono toEntity(Mono e); 17 | 18 | Mono> fluxTolList(Flux items); 19 | 20 | Flux toItemFlux(Mono items); 21 | 22 | ItemEntity toEntity(Item m); 23 | 24 | List toEntityList(List items); 25 | 26 | Item toModel(ItemEntity e); 27 | 28 | List toModelList(List items); 29 | 30 | Flux toModelFlux(List items); 31 | } 32 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import javax.validation.Valid; 6 | import javax.validation.constraints.NotNull; 7 | import reactor.core.publisher.Flux; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface OrderService { 15 | 16 | Mono addOrder(@Valid Mono newOrder); 17 | 18 | Mono updateMapping(@Valid OrderEntity orderEntity); 19 | 20 | Flux getOrdersByCustomerId(@NotNull @Valid String customerId); 21 | 22 | Mono getByOrderId(String id); 23 | } 24 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/PaymentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import com.packt.modern.api.model.PaymentReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface PaymentService { 15 | 16 | Mono authorize(@Valid Mono paymentReq); 17 | Mono getOrdersPaymentAuthorization(@NotNull String orderId); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import javax.validation.constraints.Min; 5 | import javax.validation.constraints.NotNull; 6 | import org.springframework.validation.annotation.Validated; 7 | import reactor.core.publisher.Flux; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Validated 15 | public interface ProductService { 16 | @NotNull Flux getAllProducts(); 17 | Mono getProduct(@Min(value = 1L, message = "Invalid product ID.") String id); 18 | } -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/ShipmentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import javax.validation.constraints.Min; 5 | import reactor.core.publisher.Flux; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ShipmentService { 12 | Flux getShipmentByOrderId(@Min(value = 1L, message = "Invalid product ID.") String id); 13 | } 14 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/ShipmentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import com.packt.modern.api.repository.ShipmentRepository; 5 | import javax.validation.constraints.Min; 6 | import org.springframework.stereotype.Service; 7 | import reactor.core.publisher.Flux; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | @Service 14 | public class ShipmentServiceImpl implements ShipmentService { 15 | 16 | private ShipmentRepository repository; 17 | 18 | public ShipmentServiceImpl(ShipmentRepository repository) { 19 | this.repository = repository; 20 | } 21 | 22 | @Override 23 | public Flux getShipmentByOrderId( 24 | @Min(value = 1L, message = "Invalid shipment ID.") String id) { 25 | return repository.getShipmentByOrderId(id); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter05/src/main/java/com/packt/modern/api/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import com.packt.modern.api.entity.CardEntity; 5 | import com.packt.modern.api.entity.UserEntity; 6 | import java.util.Optional; 7 | import java.util.UUID; 8 | import reactor.core.publisher.Flux; 9 | import reactor.core.publisher.Mono; 10 | 11 | /** 12 | * @author : github.com/sharmasourabh 13 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 14 | **/ 15 | public interface UserService { 16 | Mono deleteCustomerById(String id); 17 | Mono deleteCustomerById(UUID id); 18 | Flux getAddressesByCustomerId(String id); 19 | Flux getAllCustomers(); 20 | Mono getCardByCustomerId(String id); 21 | Mono getCustomerById(String id); 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/src/main/resources/api/.openapi-generator-ignore: -------------------------------------------------------------------------------- 1 | **/*Controller.java -------------------------------------------------------------------------------- /Chapter05/src/main/resources/api/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "library": "spring-boot", 3 | "dateLibrary": "java8", 4 | "hideGenerationTimestamp": true, 5 | "modelPackage": "com.packt.modern.api.model", 6 | "apiPackage": "com.packt.modern.api", 7 | "invokerPackage": "com.packt.modern.api", 8 | "serializableModel": true, 9 | "useTags": true, 10 | "useGzipFeature" : true, 11 | "reactive": true, 12 | "interfaceOnly": true, 13 | "skipDefaultInterface": "true", 14 | "hateoas": true, 15 | "withXml": true, 16 | "importMappings": { 17 | "ResourceSupport":"org.springframework.hateoas.RepresentationModel", 18 | "Link": "org.springframework.hateoas.Link" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter05/src/test/java/com/packt/modern/api/ECommerceAppTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | /*@ComponentScan(basePackages = {"com.packt.modern.api"}, excludeFilters={ 10 | @ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE, value=com.packt.modern.api.H2ConsoleComponent.class)})*/ 11 | class ECommerceAppTests { 12 | 13 | private static final Logger log = LoggerFactory.getLogger(ECommerceAppTests.class); 14 | 15 | @Test 16 | void contextLoads() { 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter05/src/test/java/com/packt/modern/api/TestConfig.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.http.codec.ServerCodecConfigurer; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter05 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | @Configuration 12 | public class TestConfig { 13 | @Bean 14 | public ServerCodecConfigurer serverCodecConfigurer() { 15 | return ServerCodecConfigurer.create(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter05/src/test/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter05/src/test/resources/application.properties -------------------------------------------------------------------------------- /Chapter06/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | **-logs/ 5 | !gradle/wrapper/gradle-wrapper.jar 6 | !**/src/main/**/build/ 7 | !**/src/test/**/build/ 8 | 9 | ### STS ### 10 | .apt_generated 11 | .classpath 12 | .factorypath 13 | .project 14 | .settings 15 | .springBeans 16 | .sts4-cache 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | out/ 24 | !**/src/main/**/out/ 25 | !**/src/test/**/out/ 26 | 27 | ### NetBeans ### 28 | /nbproject/private/ 29 | /nbbuild/ 30 | /dist/ 31 | /nbdist/ 32 | /.nb-gradle/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | -------------------------------------------------------------------------------- /Chapter06/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter06/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter06/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Chapter06' 2 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/eCommerceApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class eCommerceApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(eCommerceApp.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/exception/CustomerNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class CustomerNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public CustomerNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public CustomerNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/exception/ErrorUtils.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ErrorUtils { 8 | 9 | private ErrorUtils() { 10 | } 11 | 12 | /** 13 | * Creates and return an error object 14 | * 15 | * @param errMsgKey 16 | * @param errorCode 17 | * @param httpStatusCode 18 | * @param url 19 | * @return error 20 | */ 21 | public static Error createError(final String errMsgKey, final String errorCode, 22 | final Integer httpStatusCode) { 23 | Error error = new Error(); 24 | error.setMessage(errMsgKey); 25 | error.setErrorCode(errorCode); 26 | error.setStatus(httpStatusCode); 27 | return error; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/exception/GenericAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class GenericAlreadyExistsException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public GenericAlreadyExistsException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public GenericAlreadyExistsException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/exception/ItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ItemNotFoundException extends Throwable { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ItemNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ItemNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ResourceNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ResourceNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ResourceNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AddressRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/AuthorizationRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AuthorizationRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/CardRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface CardRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.CrudRepository; 8 | import org.springframework.data.repository.query.Param; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface CartRepository extends CrudRepository { 15 | @Query("select c from CartEntity c join c.user u where u.id = :customerId") 16 | Optional findByCustomerId(@Param("customerId") UUID customerId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/ItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ItemEntity; 4 | import java.util.List; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Modifying; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.CrudRepository; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface ItemRepository extends CrudRepository { 15 | @Query(value = "select i.* from ecomm.cart c, ecomm.item i, ecomm.user u, ecomm.cart_item ci where u.id = :customerId and c.user_id=u.id and c.id=ci.cart_id and i.id=ci.item_id", nativeQuery=true) 16 | Iterable findByCustomerId(String customerId); 17 | 18 | @Modifying 19 | @Query(value = "delete from ecomm.cart_item where item_id in (:ids) and cart_id = :cartId", nativeQuery = true) 20 | void deleteCartItemJoinById(List ids, UUID cartId); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/OrderItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderItemEntity; 4 | import com.packt.modern.api.entity.TagEntity; 5 | import java.util.UUID; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface OrderItemRepository extends CrudRepository { 14 | } 15 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.CrudRepository; 7 | import org.springframework.data.repository.query.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Repository 15 | public interface OrderRepository extends CrudRepository, OrderRepositoryExt { 16 | 17 | @Query("select o from OrderEntity o join o.userEntity u where u.id = :customerId") 18 | Iterable findByCustomerId(@Param("customerId") UUID customerId); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/OrderRepositoryExt.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface OrderRepositoryExt { 12 | Optional insert(NewOrder m); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/PaymentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.PaymentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface PaymentRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ProductRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/ShipmentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ShipmentRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/TagRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.TagEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface TagRepository extends CrudRepository { 13 | } 14 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.UserEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.CrudRepository; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface UserRepository extends CrudRepository { 14 | 15 | Optional findByUsername(String username); 16 | 17 | @Query(value = "select count(u.*) from ecomm.user u where u.username = :username or u.email = :email", nativeQuery = true) 18 | Integer findByUsernameOrEmail(String username, String email); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/repository/UserTokenRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.UserTokenEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface UserTokenRepository extends CrudRepository { 13 | 14 | Optional findByRefreshToken(String refreshToken); 15 | Optional deleteByUserId(UUID userId); 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/security/Constants.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.security; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class Constants { 8 | public static final String ENCODER_ID = "bcrypt"; 9 | public static final String API_URL_PREFIX = "/api/v1/**"; 10 | public static final String H2_URL_PREFIX = "/h2-console/**"; 11 | public static final String SIGNUP_URL = "/api/v1/users"; 12 | public static final String TOKEN_URL = "/api/v1/auth/token"; 13 | public static final String REFRESH_URL = "/api/v1/auth/token/refresh"; 14 | public static final String PRODUCTS_URL = "/api/v1/products/**"; 15 | public static final String AUTHORIZATION = "Authorization"; 16 | public static final String TOKEN_PREFIX = "Bearer "; 17 | public static final String SECRET_KEY = "SECRET_KEY"; 18 | public static final long EXPIRATION_TIME = 900_000; // 15 mins 19 | public static final String ROLE_CLAIM = "roles"; 20 | public static final String AUTHORITY_PREFIX = "ROLE_"; 21 | } 22 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/AddressService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import com.packt.modern.api.model.AddAddressReq; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AddressService { 12 | public Optional createAddress(AddAddressReq addAddressReq); 13 | public void deleteAddressesById(String id); 14 | public Optional getAddressesById(String id); 15 | public Iterable getAllAddresses(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/CardService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import com.packt.modern.api.model.AddCardReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface CardService { 13 | public void deleteCardById(String id); 14 | public Iterable getAllCards(); 15 | public Optional getCardById(String id); 16 | public Optional registerCard(@Valid AddCardReq addCardReq); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | import javax.validation.Valid; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface CartService { 13 | 14 | public List addCartItemsByCustomerId(String customerId, @Valid Item item); 15 | 16 | public List addOrReplaceItemsByCustomerId(String customerId, @Valid Item item); 17 | 18 | public void deleteCart(String customerId); 19 | 20 | public void deleteItemFromCart(String customerId, String itemId); 21 | 22 | public CartEntity getCartByCustomerId(String customerId); 23 | 24 | public List getCartItemsByCustomerId(String customerId); 25 | 26 | public Item getCartItemsByItemId(String customerId, String itemId); 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/ItemService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ItemEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ItemService { 12 | 13 | ItemEntity toEntity(Item m); 14 | 15 | List toEntityList(List items); 16 | 17 | Item toModel(ItemEntity e); 18 | 19 | List toModelList(List items); 20 | } 21 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface OrderService { 14 | 15 | public Optional addOrder(@Valid NewOrder newOrder); 16 | public Iterable getOrdersByCustomerId(@NotNull @Valid String customerId); 17 | public Optional getByOrderId(String id); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/PaymentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import com.packt.modern.api.model.PaymentReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface PaymentService { 14 | 15 | public Optional authorize(@Valid PaymentReq paymentReq); 16 | public Optional getOrdersPaymentAuthorization(@NotNull String orderId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.Optional; 5 | import javax.validation.constraints.Min; 6 | import javax.validation.constraints.NotNull; 7 | import org.springframework.validation.annotation.Validated; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | @Validated 14 | public interface ProductService { 15 | @NotNull Iterable getAllProducts(); 16 | Optional getProduct(@Min(value = 1L, message = "Invalid product ID.") String id); 17 | } -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import com.packt.modern.api.repository.ProductRepository; 5 | import java.util.Optional; 6 | import java.util.UUID; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Service 15 | @Transactional 16 | public class ProductServiceImpl implements ProductService { 17 | 18 | private ProductRepository repository; 19 | 20 | public ProductServiceImpl(ProductRepository repository) { 21 | this.repository = repository; 22 | } 23 | 24 | @Override 25 | public Iterable getAllProducts() { 26 | return repository.findAll(); 27 | } 28 | 29 | @Override 30 | public Optional getProduct(String id) { 31 | return repository 32 | .findById(UUID.fromString(id)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/ShipmentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import javax.validation.constraints.Min; 5 | 6 | /** 7 | * @author : github.com/sharmasourabh 8 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 9 | **/ 10 | public interface ShipmentService { 11 | public Iterable getShipmentByOrderId(@Min(value = 1L, message = "Invalid product ID.") String id); 12 | } 13 | -------------------------------------------------------------------------------- /Chapter06/src/main/java/com/packt/modern/api/service/ShipmentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import com.packt.modern.api.repository.ShipmentRepository; 5 | import java.util.List; 6 | import java.util.UUID; 7 | import javax.validation.constraints.Min; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter06 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Service 15 | public class ShipmentServiceImpl implements ShipmentService { 16 | 17 | private ShipmentRepository repository; 18 | 19 | public ShipmentServiceImpl(ShipmentRepository repository) { 20 | this.repository = repository; 21 | } 22 | 23 | @Override 24 | public Iterable getShipmentByOrderId( 25 | @Min(value = 1L, message = "Invalid shipment ID.") String id) { 26 | return repository.findAllById(List.of(UUID.fromString(id))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter06/src/main/resources/api/.openapi-generator-ignore: -------------------------------------------------------------------------------- 1 | **/*Controller.java -------------------------------------------------------------------------------- /Chapter06/src/main/resources/api/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "library": "spring-mvc", 3 | "dateLibrary": "java8", 4 | "hideGenerationTimestamp": true, 5 | "modelPackage": "com.packt.modern.api.model", 6 | "apiPackage": "com.packt.modern.api", 7 | "invokerPackage": "com.packt.modern.api", 8 | "serializableModel": true, 9 | "useTags": true, 10 | "useGzipFeature" : true, 11 | "hateoas": true, 12 | "withXml": true, 13 | "importMappings": { 14 | "ResourceSupport":"org.springframework.hateoas.RepresentationModel", 15 | "Link": "org.springframework.hateoas.Link" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter06/src/main/resources/jwt-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter06/src/main/resources/jwt-keystore.jks -------------------------------------------------------------------------------- /Chapter06/src/test/java/com/packt/modern/api/eCommerceAppTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | class eCommerceAppTests { 10 | 11 | private static final Logger log = LoggerFactory.getLogger(eCommerceAppTests.class); 12 | 13 | @Test 14 | void contextLoads() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/craco.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | style: { 3 | postcss: { 4 | plugins: [require("tailwindcss"), require("autoprefixer")], 5 | }, 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/favicon.ico -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/Antifragile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/Antifragile.jpg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/Hackers.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/Hackers.jpg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/HowToFail.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/HowToFail.jpeg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/Influence.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/Influence.jpeg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/PoorCharlie.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/PoorCharlie.jpeg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/Sapiens.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/Sapiens.jpeg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/Seeking.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/Seeking.jpg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/ThinkingFast.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/ThinkingFast.jpeg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/ThinkingIn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/ThinkingIn.jpg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/images/ZeroToOne.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/images/ZeroToOne.jpg -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/logo192.png -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter07/ecomm-ui/public/logo512.png -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/components/Button.js: -------------------------------------------------------------------------------- 1 | const Button = (props) => { 2 | let buttonClass = 3 | " group flex items-center rounded-md font-medium text-sm px-3 py-2"; 4 | let classColor = 5 | props.color === "green" 6 | ? "hover:bg-green-200 hover:text-green-700 bg-green-500 text-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-400" 7 | : "hover:bg-red-200 hover:text-red-700 bg-red-500 text-red-100 focus:outline-none"; 8 | classColor = classColor + buttonClass; 9 | return ( 10 | 19 | ); 20 | }; 21 | 22 | export default Button; 23 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/components/Footer.js: -------------------------------------------------------------------------------- 1 | const Footer = () => { 2 | return ( 3 |
4 | 21 |
22 | ); 23 | }; 24 | 25 | export default Footer; 26 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/components/NotFound.js: -------------------------------------------------------------------------------- 1 | import { useLocation } from "react-router-dom"; 2 | 3 | const NotFound = () => { 4 | const location = useLocation(); 5 | return ( 6 |
7 |
404 - Not found
8 |

9 | No match for "{location.pathname}" 10 |

11 |
12 | ); 13 | }; 14 | 15 | export default NotFound; 16 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/components/Products.js: -------------------------------------------------------------------------------- 1 | import ProductCard from "./ProductCard"; 2 | 3 | const Products = ({ auth, productList }) => { 4 | return ( 5 | <> 6 | {productList.map((item) => ( 7 | 8 | ))} 9 | 10 | ); 11 | }; 12 | 13 | export default Products; 14 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/hooks/useToken.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | export default function useToken() { 4 | const getToken = () => { 5 | const tokenResponse = localStorage.getItem("tokenResponse"); 6 | const userInfo = tokenResponse ? JSON.parse(tokenResponse) : ""; 7 | return userInfo; 8 | }; 9 | 10 | const [token, setToken] = useState(getToken()); 11 | 12 | const saveToken = (tokenResponse) => { 13 | localStorage.setItem("tokenResponse", JSON.stringify(tokenResponse)); 14 | setToken(tokenResponse); 15 | }; 16 | 17 | return { 18 | setToken: saveToken, 19 | token, 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/index.css: -------------------------------------------------------------------------------- 1 | @import "tailwindcss/base"; 2 | 3 | /* components injects any component (reusable styles like cards and form elements, etc.) classes registered by plugins based in our config file. */ 4 | @import "tailwindcss/components"; 5 | @import "tailwindcss/utilities"; 6 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /Chapter07/ecomm-ui/tailwind.config.js: -------------------------------------------------------------------------------- 1 | const defaultTheme = require("tailwindcss/defaultTheme"); 2 | module.exports = { 3 | purge: { 4 | enabled: process.env.PURGE_CSS === "production" ? true : false, 5 | content: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"], 6 | }, 7 | darkMode: false, // or 'media' or 'class' 8 | theme: { 9 | screens: { 10 | xs: "475px", 11 | ...defaultTheme.screens, 12 | }, 13 | }, 14 | variants: { 15 | extend: {}, 16 | }, 17 | plugins: [], 18 | }; 19 | -------------------------------------------------------------------------------- /Chapter08/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | **-logs/ 5 | !gradle/wrapper/gradle-wrapper.jar 6 | !**/src/main/**/build/ 7 | !**/src/test/**/build/ 8 | 9 | ### STS ### 10 | .apt_generated 11 | .classpath 12 | .factorypath 13 | .project 14 | .settings 15 | .springBeans 16 | .sts4-cache 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | out/ 24 | !**/src/main/**/out/ 25 | !**/src/test/**/out/ 26 | 27 | ### NetBeans ### 28 | /nbproject/private/ 29 | /nbbuild/ 30 | /dist/ 31 | /nbdist/ 32 | /.nb-gradle/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | -------------------------------------------------------------------------------- /Chapter08/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter08/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter08/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter08/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Chapter08' 2 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/eCommerceApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class eCommerceApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(eCommerceApp.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/exception/CustomerNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class CustomerNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public CustomerNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public CustomerNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/exception/ErrorUtils.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ErrorUtils { 8 | 9 | private ErrorUtils() { 10 | } 11 | 12 | /** 13 | * Creates and return an error object 14 | * 15 | * @param errMsgKey 16 | * @param errorCode 17 | * @param httpStatusCode 18 | * @param url 19 | * @return error 20 | */ 21 | public static Error createError(final String errMsgKey, final String errorCode, 22 | final Integer httpStatusCode) { 23 | Error error = new Error(); 24 | error.setMessage(errMsgKey); 25 | error.setErrorCode(errorCode); 26 | error.setStatus(httpStatusCode); 27 | return error; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/exception/GenericAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class GenericAlreadyExistsException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public GenericAlreadyExistsException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public GenericAlreadyExistsException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/exception/ItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ItemNotFoundException extends Throwable { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ItemNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ItemNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ResourceNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ResourceNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ResourceNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AddressRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/AuthorizationRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AuthorizationRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/CardRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface CardRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.CrudRepository; 8 | import org.springframework.data.repository.query.Param; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface CartRepository extends CrudRepository { 15 | @Query("select c from CartEntity c join c.user u where u.id = :customerId") 16 | Optional findByCustomerId(@Param("customerId") UUID customerId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/ItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ItemEntity; 4 | import java.util.List; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Modifying; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.CrudRepository; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface ItemRepository extends CrudRepository { 15 | @Query(value = "select i.* from ecomm.cart c, ecomm.item i, ecomm.user u, ecomm.cart_item ci where u.id = :customerId and c.user_id=u.id and c.id=ci.cart_id and i.id=ci.item_id", nativeQuery=true) 16 | Iterable findByCustomerId(String customerId); 17 | 18 | @Modifying 19 | @Query(value = "delete from ecomm.cart_item where item_id in (:ids) and cart_id = :cartId", nativeQuery = true) 20 | void deleteCartItemJoinById(List ids, UUID cartId); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/OrderItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderItemEntity; 4 | import com.packt.modern.api.entity.TagEntity; 5 | import java.util.UUID; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface OrderItemRepository extends CrudRepository { 14 | } 15 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.CrudRepository; 7 | import org.springframework.data.repository.query.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Repository 15 | public interface OrderRepository extends CrudRepository, OrderRepositoryExt { 16 | 17 | @Query("select o from OrderEntity o join o.userEntity u where u.id = :customerId") 18 | Iterable findByCustomerId(@Param("customerId") UUID customerId); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/OrderRepositoryExt.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface OrderRepositoryExt { 12 | Optional insert(NewOrder m); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/PaymentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.PaymentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface PaymentRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ProductRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/ShipmentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ShipmentRepository extends CrudRepository { 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/TagRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.TagEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface TagRepository extends CrudRepository { 13 | } 14 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.UserEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.CrudRepository; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface UserRepository extends CrudRepository { 14 | 15 | Optional findByUsername(String username); 16 | 17 | @Query(value = "select count(u.*) from ecomm.user u where u.username = :username or u.email = :email", nativeQuery = true) 18 | Integer findByUsernameOrEmail(String username, String email); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/repository/UserTokenRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.UserTokenEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface UserTokenRepository extends CrudRepository { 13 | 14 | Optional findByRefreshToken(String refreshToken); 15 | Optional deleteByUserId(UUID userId); 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/security/Constants.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.security; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class Constants { 8 | public static final String ENCODER_ID = "bcrypt"; 9 | public static final String API_URL_PREFIX = "/api/v1/**"; 10 | public static final String H2_URL_PREFIX = "/h2-console/**"; 11 | public static final String SIGNUP_URL = "/api/v1/users"; 12 | public static final String TOKEN_URL = "/api/v1/auth/token"; 13 | public static final String REFRESH_URL = "/api/v1/auth/token/refresh"; 14 | public static final String PRODUCTS_URL = "/api/v1/products/**"; 15 | public static final String AUTHORIZATION = "Authorization"; 16 | public static final String TOKEN_PREFIX = "Bearer "; 17 | public static final String SECRET_KEY = "SECRET_KEY"; 18 | public static final long EXPIRATION_TIME = 900_000; // 15 mins 19 | public static final String ROLE_CLAIM = "roles"; 20 | public static final String AUTHORITY_PREFIX = "ROLE_"; 21 | } 22 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/AddressService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import com.packt.modern.api.model.AddAddressReq; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AddressService { 12 | public Optional createAddress(AddAddressReq addAddressReq); 13 | public void deleteAddressesById(String id); 14 | public Optional getAddressesById(String id); 15 | public Iterable getAllAddresses(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/CardService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import com.packt.modern.api.model.AddCardReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface CardService { 13 | public void deleteCardById(String id); 14 | public Iterable getAllCards(); 15 | public Optional getCardById(String id); 16 | public Optional registerCard(@Valid AddCardReq addCardReq); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | import javax.validation.Valid; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface CartService { 13 | 14 | public List addCartItemsByCustomerId(String customerId, @Valid Item item); 15 | 16 | public List addOrReplaceItemsByCustomerId(String customerId, @Valid Item item); 17 | 18 | public void deleteCart(String customerId); 19 | 20 | public void deleteItemFromCart(String customerId, String itemId); 21 | 22 | public CartEntity getCartByCustomerId(String customerId); 23 | 24 | public List getCartItemsByCustomerId(String customerId); 25 | 26 | public Item getCartItemsByItemId(String customerId, String itemId); 27 | } 28 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/ItemService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ItemEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ItemService { 12 | 13 | ItemEntity toEntity(Item m); 14 | 15 | List toEntityList(List items); 16 | 17 | Item toModel(ItemEntity e); 18 | 19 | List toModelList(List items); 20 | } 21 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface OrderService { 14 | 15 | public Optional addOrder(@Valid NewOrder newOrder); 16 | public Iterable getOrdersByCustomerId(@NotNull @Valid String customerId); 17 | public Optional getByOrderId(String id); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/PaymentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import com.packt.modern.api.model.PaymentReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface PaymentService { 14 | 15 | public Optional authorize(@Valid PaymentReq paymentReq); 16 | public Optional getOrdersPaymentAuthorization(@NotNull String orderId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.Optional; 5 | import javax.validation.constraints.Min; 6 | import javax.validation.constraints.NotNull; 7 | import org.springframework.validation.annotation.Validated; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | @Validated 14 | public interface ProductService { 15 | @NotNull Iterable getAllProducts(); 16 | Optional getProduct(@Min(value = 1L, message = "Invalid product ID.") String id); 17 | } -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import com.packt.modern.api.repository.ProductRepository; 5 | import java.util.Optional; 6 | import java.util.UUID; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Service 15 | @Transactional 16 | public class ProductServiceImpl implements ProductService { 17 | 18 | private ProductRepository repository; 19 | 20 | public ProductServiceImpl(ProductRepository repository) { 21 | this.repository = repository; 22 | } 23 | 24 | @Override 25 | public Iterable getAllProducts() { 26 | return repository.findAll(); 27 | } 28 | 29 | @Override 30 | public Optional getProduct(String id) { 31 | return repository 32 | .findById(UUID.fromString(id)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/ShipmentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import javax.validation.constraints.Min; 5 | 6 | /** 7 | * @author : github.com/sharmasourabh 8 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 9 | **/ 10 | public interface ShipmentService { 11 | public Iterable getShipmentByOrderId(@Min(value = 1L, message = "Invalid product ID.") String id); 12 | } 13 | -------------------------------------------------------------------------------- /Chapter08/src/main/java/com/packt/modern/api/service/ShipmentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import com.packt.modern.api.repository.ShipmentRepository; 5 | import java.util.List; 6 | import java.util.UUID; 7 | import javax.validation.constraints.Min; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter08 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Service 15 | public class ShipmentServiceImpl implements ShipmentService { 16 | 17 | private ShipmentRepository repository; 18 | 19 | public ShipmentServiceImpl(ShipmentRepository repository) { 20 | this.repository = repository; 21 | } 22 | 23 | @Override 24 | public Iterable getShipmentByOrderId( 25 | @Min(value = 1L, message = "Invalid shipment ID.") String id) { 26 | return repository.findAllById(List.of(UUID.fromString(id))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter08/src/main/resources/api/.openapi-generator-ignore: -------------------------------------------------------------------------------- 1 | **/*Controller.java -------------------------------------------------------------------------------- /Chapter08/src/main/resources/api/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "library": "spring-mvc", 3 | "dateLibrary": "java8", 4 | "hideGenerationTimestamp": true, 5 | "modelPackage": "com.packt.modern.api.model", 6 | "apiPackage": "com.packt.modern.api", 7 | "invokerPackage": "com.packt.modern.api", 8 | "serializableModel": true, 9 | "useTags": true, 10 | "useGzipFeature" : true, 11 | "hateoas": true, 12 | "withXml": true, 13 | "importMappings": { 14 | "ResourceSupport":"org.springframework.hateoas.RepresentationModel", 15 | "Link": "org.springframework.hateoas.Link" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter08/src/main/resources/jwt-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter08/src/main/resources/jwt-keystore.jks -------------------------------------------------------------------------------- /Chapter08/src/test/java/com/packt/modern/api/eCommerceAppTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | class eCommerceAppTests { 10 | 11 | private static final Logger log = LoggerFactory.getLogger(eCommerceAppTests.class); 12 | 13 | @Test 14 | void contextLoads() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | **-logs/ 5 | !gradle/wrapper/gradle-wrapper.jar 6 | !**/src/main/**/build/ 7 | !**/src/test/**/build/ 8 | 9 | ### STS ### 10 | .apt_generated 11 | .classpath 12 | .factorypath 13 | .project 14 | .settings 15 | .springBeans 16 | .sts4-cache 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | out/ 24 | !**/src/main/**/out/ 25 | !**/src/test/**/out/ 26 | 27 | ### NetBeans ### 28 | /nbproject/private/ 29 | /nbbuild/ 30 | /dist/ 31 | /nbdist/ 32 | /.nb-gradle/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | -------------------------------------------------------------------------------- /Chapter09/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter09/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter09/k8s/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | app: chapter09 7 | name: chapter09 8 | spec: 9 | replicas: 1 10 | selector: 11 | matchLabels: 12 | app: chapter09 13 | strategy: {} 14 | template: 15 | metadata: 16 | creationTimestamp: null 17 | labels: 18 | app: chapter09 19 | spec: 20 | containers: 21 | - image: 192.168.80.1:5000/packt-modern-api-development-chapter09:0.0.1-SNAPSHOT 22 | name: packt-modern-api-development-chapter09 23 | resources: {} 24 | status: {} 25 | --- 26 | apiVersion: v1 27 | kind: Service 28 | metadata: 29 | creationTimestamp: null 30 | labels: 31 | app: chapter09 32 | name: chapter09 33 | spec: 34 | ports: 35 | - name: 8080-8080 36 | port: 8080 37 | protocol: TCP 38 | targetPort: 8080 39 | selector: 40 | app: chapter09 41 | type: ClusterIP 42 | status: 43 | loadBalancer: {} 44 | -------------------------------------------------------------------------------- /Chapter09/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'packt-modern-api-development-chapter09' 2 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/eCommerceApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class eCommerceApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(eCommerceApp.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/exception/CustomerNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class CustomerNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public CustomerNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public CustomerNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/exception/ErrorUtils.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ErrorUtils { 8 | 9 | private ErrorUtils() { 10 | } 11 | 12 | /** 13 | * Creates and return an error object 14 | * 15 | * @param errMsgKey 16 | * @param errorCode 17 | * @param httpStatusCode 18 | * @param url 19 | * @return error 20 | */ 21 | public static Error createError(final String errMsgKey, final String errorCode, 22 | final Integer httpStatusCode) { 23 | Error error = new Error(); 24 | error.setMessage(errMsgKey); 25 | error.setErrorCode(errorCode); 26 | error.setStatus(httpStatusCode); 27 | return error; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/exception/GenericAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class GenericAlreadyExistsException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public GenericAlreadyExistsException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public GenericAlreadyExistsException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/exception/ItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ItemNotFoundException extends Throwable { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ItemNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ItemNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.CUSTOMER_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.CUSTOMER_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.exception; 2 | 3 | /** 4 | * @author : github.com/sharmasourabh 5 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 6 | **/ 7 | public class ResourceNotFoundException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 1L; 10 | private final String errMsgKey; 11 | private final String errorCode; 12 | 13 | public ResourceNotFoundException(ErrorCode code) { 14 | super(code.getErrMsgKey()); 15 | this.errMsgKey = code.getErrMsgKey(); 16 | this.errorCode = code.getErrCode(); 17 | } 18 | 19 | public ResourceNotFoundException(final String message) { 20 | super(message); 21 | this.errMsgKey = ErrorCode.RESOURCE_NOT_FOUND.getErrMsgKey(); 22 | this.errorCode = ErrorCode.RESOURCE_NOT_FOUND.getErrCode(); 23 | } 24 | 25 | public String getErrMsgKey() { 26 | return errMsgKey; 27 | } 28 | 29 | public String getErrorCode() { 30 | return errorCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AddressRepository extends CrudRepository { 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/AuthorizationRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AuthorizationRepository extends CrudRepository { 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/CardRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface CardRepository extends CrudRepository { 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.CrudRepository; 8 | import org.springframework.data.repository.query.Param; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface CartRepository extends CrudRepository { 15 | @Query("select c from CartEntity c join c.user u where u.id = :customerId") 16 | Optional findByCustomerId(@Param("customerId") UUID customerId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/ItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ItemEntity; 4 | import java.util.List; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Modifying; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.CrudRepository; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface ItemRepository extends CrudRepository { 15 | @Query(value = "select i.* from ecomm.cart c, ecomm.item i, ecomm.user u, ecomm.cart_item ci where u.id = :customerId and c.user_id=u.id and c.id=ci.cart_id and i.id=ci.item_id", nativeQuery=true) 16 | Iterable findByCustomerId(String customerId); 17 | 18 | @Modifying 19 | @Query(value = "delete from ecomm.cart_item where item_id in (:ids) and cart_id = :cartId", nativeQuery = true) 20 | void deleteCartItemJoinById(List ids, UUID cartId); 21 | } 22 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/OrderItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderItemEntity; 4 | import com.packt.modern.api.entity.TagEntity; 5 | import java.util.UUID; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface OrderItemRepository extends CrudRepository { 14 | } 15 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.CrudRepository; 7 | import org.springframework.data.repository.query.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Repository 15 | public interface OrderRepository extends CrudRepository, OrderRepositoryExt { 16 | 17 | @Query("select o from OrderEntity o join o.userEntity u where u.id = :customerId") 18 | Iterable findByCustomerId(@Param("customerId") UUID customerId); 19 | } 20 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/OrderRepositoryExt.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface OrderRepositoryExt { 12 | Optional insert(NewOrder m); 13 | } 14 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/PaymentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.PaymentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface PaymentRepository extends CrudRepository { 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ProductRepository extends CrudRepository { 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/ShipmentRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ShipmentRepository extends CrudRepository { 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/TagRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.TagEntity; 4 | import java.util.UUID; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface TagRepository extends CrudRepository { 13 | } 14 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.UserEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.CrudRepository; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface UserRepository extends CrudRepository { 14 | 15 | Optional findByUsername(String username); 16 | 17 | @Query(value = "select count(u.*) from ecomm.user u where u.username = :username or u.email = :email", nativeQuery = true) 18 | Integer findByUsernameOrEmail(String username, String email); 19 | } 20 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/repository/UserTokenRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.entity.UserTokenEntity; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface UserTokenRepository extends CrudRepository { 13 | 14 | Optional findByRefreshToken(String refreshToken); 15 | Optional deleteByUserId(UUID userId); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/AddressService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AddressEntity; 4 | import com.packt.modern.api.model.AddAddressReq; 5 | import java.util.Optional; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface AddressService { 12 | public Optional createAddress(AddAddressReq addAddressReq); 13 | public void deleteAddressesById(String id); 14 | public Optional getAddressesById(String id); 15 | public Iterable getAllAddresses(); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/CardService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CardEntity; 4 | import com.packt.modern.api.model.AddCardReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface CardService { 13 | public void deleteCardById(String id); 14 | public Iterable getAllCards(); 15 | public Optional getCardById(String id); 16 | public Optional registerCard(@Valid AddCardReq addCardReq); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.CartEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | import javax.validation.Valid; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface CartService { 13 | 14 | public List addCartItemsByCustomerId(String customerId, @Valid Item item); 15 | 16 | public List addOrReplaceItemsByCustomerId(String customerId, @Valid Item item); 17 | 18 | public void deleteCart(String customerId); 19 | 20 | public void deleteItemFromCart(String customerId, String itemId); 21 | 22 | public CartEntity getCartByCustomerId(String customerId); 23 | 24 | public List getCartItemsByCustomerId(String customerId); 25 | 26 | public Item getCartItemsByItemId(String customerId, String itemId); 27 | } 28 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/ItemService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ItemEntity; 4 | import com.packt.modern.api.model.Item; 5 | import java.util.List; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 10 | **/ 11 | public interface ItemService { 12 | 13 | ItemEntity toEntity(Item m); 14 | 15 | List toEntityList(List items); 16 | 17 | Item toModel(ItemEntity e); 18 | 19 | List toModelList(List items); 20 | } 21 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.OrderEntity; 4 | import com.packt.modern.api.model.NewOrder; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface OrderService { 14 | 15 | public Optional addOrder(@Valid NewOrder newOrder); 16 | public Iterable getOrdersByCustomerId(@NotNull @Valid String customerId); 17 | public Optional getByOrderId(String id); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/PaymentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.AuthorizationEntity; 4 | import com.packt.modern.api.model.PaymentReq; 5 | import java.util.Optional; 6 | import javax.validation.Valid; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface PaymentService { 14 | 15 | public Optional authorize(@Valid PaymentReq paymentReq); 16 | public Optional getOrdersPaymentAuthorization(@NotNull String orderId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import java.util.Optional; 5 | import javax.validation.constraints.Min; 6 | import javax.validation.constraints.NotNull; 7 | import org.springframework.validation.annotation.Validated; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | @Validated 14 | public interface ProductService { 15 | @NotNull Iterable getAllProducts(); 16 | Optional getProduct(@Min(value = 1L, message = "Invalid product ID.") String id); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ProductEntity; 4 | import com.packt.modern.api.repository.ProductRepository; 5 | import java.util.Optional; 6 | import java.util.UUID; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Service 15 | @Transactional 16 | public class ProductServiceImpl implements ProductService { 17 | 18 | private ProductRepository repository; 19 | 20 | public ProductServiceImpl(ProductRepository repository) { 21 | this.repository = repository; 22 | } 23 | 24 | @Override 25 | public Iterable getAllProducts() { 26 | return repository.findAll(); 27 | } 28 | 29 | @Override 30 | public Optional getProduct(String id) { 31 | return repository 32 | .findById(UUID.fromString(id)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/ShipmentService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import javax.validation.constraints.Min; 5 | 6 | /** 7 | * @author : github.com/sharmasourabh 8 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 9 | **/ 10 | public interface ShipmentService { 11 | public Iterable getShipmentByOrderId(@Min(value = 1L, message = "Invalid product ID.") String id); 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/src/main/java/com/packt/modern/api/service/ShipmentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.service; 2 | 3 | import com.packt.modern.api.entity.ShipmentEntity; 4 | import com.packt.modern.api.repository.ShipmentRepository; 5 | import java.util.List; 6 | import java.util.UUID; 7 | import javax.validation.constraints.Min; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter09 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Service 15 | public class ShipmentServiceImpl implements ShipmentService { 16 | 17 | private ShipmentRepository repository; 18 | 19 | public ShipmentServiceImpl(ShipmentRepository repository) { 20 | this.repository = repository; 21 | } 22 | 23 | @Override 24 | public Iterable getShipmentByOrderId( 25 | @Min(value = 1L, message = "Invalid shipment ID.") String id) { 26 | return repository.findAllById(List.of(UUID.fromString(id))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter09/src/main/resources/api/.openapi-generator-ignore: -------------------------------------------------------------------------------- 1 | **/*Controller.java -------------------------------------------------------------------------------- /Chapter09/src/main/resources/api/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "library": "spring-mvc", 3 | "dateLibrary": "java8", 4 | "hideGenerationTimestamp": true, 5 | "modelPackage": "com.packt.modern.api.model", 6 | "apiPackage": "com.packt.modern.api", 7 | "invokerPackage": "com.packt.modern.api", 8 | "serializableModel": true, 9 | "useTags": true, 10 | "useGzipFeature" : true, 11 | "hateoas": true, 12 | "withXml": true, 13 | "importMappings": { 14 | "ResourceSupport":"org.springframework.hateoas.RepresentationModel", 15 | "Link": "org.springframework.hateoas.Link" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter09/src/main/resources/jwt-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter09/src/main/resources/jwt-keystore.jks -------------------------------------------------------------------------------- /Chapter09/src/test/java/com/packt/modern/api/eCommerceAppTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | class eCommerceAppTests { 10 | 11 | private static final Logger log = LoggerFactory.getLogger(eCommerceAppTests.class); 12 | 13 | @Test 14 | void contextLoads() { 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter11/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /Chapter11/api/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /Chapter11/api/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | -------------------------------------------------------------------------------- /Chapter11/api/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter11/api/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter11/api/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter11/api/lib/src/main/java/com/packt/modern/api/grpc/v1/ChargeIdOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PaymentGatewayService.proto 3 | 4 | package com.packt.modern.api.grpc.v1; 5 | 6 | public interface ChargeIdOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:com.packtpub.v1.ChargeId) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | *
12 |    * unique charge ID from a charge creation request
13 |    * 
14 | * 15 | * string id = 1; 16 | * @return The id. 17 | */ 18 | java.lang.String getId(); 19 | /** 20 | *
21 |    * unique charge ID from a charge creation request
22 |    * 
23 | * 24 | * string id = 1; 25 | * @return The bytes for id. 26 | */ 27 | com.google.protobuf.ByteString 28 | getIdBytes(); 29 | } 30 | -------------------------------------------------------------------------------- /Chapter11/api/lib/src/main/java/com/packt/modern/api/grpc/v1/CustomerIdOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PaymentGatewayService.proto 3 | 4 | package com.packt.modern.api.grpc.v1; 5 | 6 | public interface CustomerIdOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:com.packtpub.v1.CustomerId) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | *
12 |    * unique customer ID
13 |    * 
14 | * 15 | * string id = 1; 16 | * @return The id. 17 | */ 18 | java.lang.String getId(); 19 | /** 20 | *
21 |    * unique customer ID
22 |    * 
23 | * 24 | * string id = 1; 25 | * @return The bytes for id. 26 | */ 27 | com.google.protobuf.ByteString 28 | getIdBytes(); 29 | } 30 | -------------------------------------------------------------------------------- /Chapter11/api/lib/src/main/java/com/packt/modern/api/grpc/v1/SourceIdOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PaymentGatewayService.proto 3 | 4 | package com.packt.modern.api.grpc.v1; 5 | 6 | public interface SourceIdOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:com.packtpub.v1.SourceId) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | *
12 |    * unique source ID from a source creation request
13 |    * 
14 | * 15 | * string id = 1; 16 | * @return The id. 17 | */ 18 | java.lang.String getId(); 19 | /** 20 | *
21 |    * unique source ID from a source creation request
22 |    * 
23 | * 24 | * string id = 1; 25 | * @return The bytes for id. 26 | */ 27 | com.google.protobuf.ByteString 28 | getIdBytes(); 29 | } 30 | -------------------------------------------------------------------------------- /Chapter11/api/lib/src/main/java/com/packt/modern/api/grpc/v1/StripeAccountOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PaymentGatewayService.proto 3 | 4 | package com.packt.modern.api.grpc.v1; 5 | 6 | public interface StripeAccountOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:com.packtpub.v1.StripeAccount) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | * string id = 1; 12 | * @return The id. 13 | */ 14 | java.lang.String getId(); 15 | /** 16 | * string id = 1; 17 | * @return The bytes for id. 18 | */ 19 | com.google.protobuf.ByteString 20 | getIdBytes(); 21 | } 22 | -------------------------------------------------------------------------------- /Chapter11/api/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/6.8.3/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'payment-gateway-api' 11 | include('lib') 12 | -------------------------------------------------------------------------------- /Chapter11/client/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /Chapter11/client/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.packt.modern.api' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = JavaVersion.VERSION_15 10 | 11 | repositories { 12 | mavenCentral() 13 | mavenLocal() 14 | } 15 | 16 | def grpcVersion = '1.37.0' 17 | dependencies { 18 | implementation 'com.packt.modern.api:payment-gateway-api:0.0.1' 19 | implementation "io.grpc:grpc-stub:${grpcVersion}" 20 | implementation "com.google.protobuf:protobuf-java-util:3.15.8" 21 | 22 | implementation 'org.springframework.boot:spring-boot-starter-web' 23 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 24 | } 25 | 26 | test { 27 | useJUnitPlatform() 28 | } 29 | -------------------------------------------------------------------------------- /Chapter11/client/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter11/client/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter11/client/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter11/client/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'chapter11-client' 2 | -------------------------------------------------------------------------------- /Chapter11/client/src/main/java/com/packt/modern/api/ClientApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ClientApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ClientApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter11/client/src/main/java/com/packt/modern/api/client/GrpcClientRunner.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.CommandLineRunner; 7 | import org.springframework.context.annotation.Profile; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter11 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Profile("!test") 15 | @Component 16 | public class GrpcClientRunner implements CommandLineRunner { 17 | private final Logger LOG = LoggerFactory.getLogger(getClass()); 18 | @Autowired 19 | GrpcClient client; 20 | 21 | @Override 22 | public void run(String... args) { 23 | client.start(); 24 | 25 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 26 | try { 27 | client.shutdown(); 28 | } catch (InterruptedException e) { 29 | LOG.error("Client stopped with error: {}", e.getMessage()); 30 | } 31 | })); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter11/client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 2 | grpc.server.host=localhost 3 | grpc.server.port=8080 4 | -------------------------------------------------------------------------------- /Chapter11/server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /Chapter11/server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.4' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.packt.modern.api' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = JavaVersion.VERSION_15 10 | 11 | repositories { 12 | mavenCentral() 13 | mavenLocal() 14 | } 15 | 16 | def grpcVersion = '1.37.0' 17 | dependencies { 18 | implementation 'com.packt.modern.api:payment-gateway-api:0.0.1' 19 | implementation "io.grpc:grpc-protobuf:${grpcVersion}" 20 | implementation "io.grpc:grpc-stub:${grpcVersion}" 21 | implementation "io.grpc:grpc-netty:${grpcVersion}" 22 | implementation 'com.google.api.grpc:googleapis-common-protos:0.0.3' 23 | 24 | implementation 'org.springframework.boot:spring-boot-starter-web' 25 | 26 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 27 | testImplementation "io.grpc:grpc-testing:${grpcVersion}" 28 | } 29 | 30 | test { 31 | useJUnitPlatform() 32 | } 33 | -------------------------------------------------------------------------------- /Chapter11/server/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter11/server/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter11/server/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter11/server/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'chapter11-server' 2 | -------------------------------------------------------------------------------- /Chapter11/server/src/main/java/com/packt/modern/api/ServerApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ServerApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ServerApp.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter11/server/src/main/java/com/packt/modern/api/server/GrpcServerRunner.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.server; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.context.annotation.Profile; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : chapter11-server - Modern API Development with Spring and Spring Boot 10 | **/ 11 | @Profile("!test") 12 | @Component 13 | public class GrpcServerRunner implements CommandLineRunner { 14 | 15 | private GrpcServer grpcServer; 16 | 17 | public GrpcServerRunner(GrpcServer grpcServer) { 18 | this.grpcServer = grpcServer; 19 | } 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | grpcServer.start(); 24 | grpcServer.block(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter11/server/src/main/java/com/packt/modern/api/server/repository/ChargeRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.server.repository; 2 | 3 | import com.packt.modern.api.grpc.v1.CaptureChargeReq; 4 | import com.packt.modern.api.grpc.v1.ChargeId; 5 | import com.packt.modern.api.grpc.v1.CreateChargeReq; 6 | import com.packt.modern.api.grpc.v1.CustomerId; 7 | import com.packt.modern.api.grpc.v1.UpdateChargeReq; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : chapter11-server - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface ChargeRepository { 14 | 15 | CreateChargeReq.Response create(CreateChargeReq req); 16 | 17 | UpdateChargeReq.Response update(UpdateChargeReq req); 18 | 19 | ChargeId.Response retrieve(String chargeId); 20 | 21 | CaptureChargeReq.Response capture(CaptureChargeReq req); 22 | 23 | CustomerId.Response retrieveAll(String customerId); 24 | } 25 | -------------------------------------------------------------------------------- /Chapter11/server/src/main/java/com/packt/modern/api/server/repository/SourceRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.server.repository; 2 | 3 | import com.packt.modern.api.grpc.v1.AttachOrDetachReq; 4 | import com.packt.modern.api.grpc.v1.CreateSourceReq; 5 | import com.packt.modern.api.grpc.v1.SourceId; 6 | import com.packt.modern.api.grpc.v1.UpdateSourceReq; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : chapter11-server - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface SourceRepository { 13 | 14 | UpdateSourceReq.Response update(UpdateSourceReq req); 15 | 16 | CreateSourceReq.Response create(CreateSourceReq req); 17 | 18 | SourceId.Response retrieve(String sourceId); 19 | 20 | AttachOrDetachReq.Response attach(AttachOrDetachReq req); 21 | 22 | AttachOrDetachReq.Response detach(AttachOrDetachReq req); 23 | } 24 | -------------------------------------------------------------------------------- /Chapter11/server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.main.web-application-type=none 2 | grpc.port=8080 3 | -------------------------------------------------------------------------------- /Chapter12/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /Chapter12/api/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /Chapter12/api/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | -------------------------------------------------------------------------------- /Chapter12/api/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter12/api/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter12/api/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter12/api/lib/src/main/java/com/packt/modern/api/grpc/v1/ChargeIdOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PaymentGatewayService.proto 3 | 4 | package com.packt.modern.api.grpc.v1; 5 | 6 | public interface ChargeIdOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:com.packtpub.v1.ChargeId) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | *
12 |    * unique charge ID from a charge creation request
13 |    * 
14 | * 15 | * string id = 1; 16 | * @return The id. 17 | */ 18 | java.lang.String getId(); 19 | /** 20 | *
21 |    * unique charge ID from a charge creation request
22 |    * 
23 | * 24 | * string id = 1; 25 | * @return The bytes for id. 26 | */ 27 | com.google.protobuf.ByteString 28 | getIdBytes(); 29 | } 30 | -------------------------------------------------------------------------------- /Chapter12/api/lib/src/main/java/com/packt/modern/api/grpc/v1/CustomerIdOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PaymentGatewayService.proto 3 | 4 | package com.packt.modern.api.grpc.v1; 5 | 6 | public interface CustomerIdOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:com.packtpub.v1.CustomerId) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | *
12 |    * unique customer ID
13 |    * 
14 | * 15 | * string id = 1; 16 | * @return The id. 17 | */ 18 | java.lang.String getId(); 19 | /** 20 | *
21 |    * unique customer ID
22 |    * 
23 | * 24 | * string id = 1; 25 | * @return The bytes for id. 26 | */ 27 | com.google.protobuf.ByteString 28 | getIdBytes(); 29 | } 30 | -------------------------------------------------------------------------------- /Chapter12/api/lib/src/main/java/com/packt/modern/api/grpc/v1/SourceIdOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PaymentGatewayService.proto 3 | 4 | package com.packt.modern.api.grpc.v1; 5 | 6 | public interface SourceIdOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:com.packtpub.v1.SourceId) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | *
12 |    * unique source ID from a source creation request
13 |    * 
14 | * 15 | * string id = 1; 16 | * @return The id. 17 | */ 18 | java.lang.String getId(); 19 | /** 20 | *
21 |    * unique source ID from a source creation request
22 |    * 
23 | * 24 | * string id = 1; 25 | * @return The bytes for id. 26 | */ 27 | com.google.protobuf.ByteString 28 | getIdBytes(); 29 | } 30 | -------------------------------------------------------------------------------- /Chapter12/api/lib/src/main/java/com/packt/modern/api/grpc/v1/StripeAccountOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PaymentGatewayService.proto 3 | 4 | package com.packt.modern.api.grpc.v1; 5 | 6 | public interface StripeAccountOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:com.packtpub.v1.StripeAccount) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | * string id = 1; 12 | * @return The id. 13 | */ 14 | java.lang.String getId(); 15 | /** 16 | * string id = 1; 17 | * @return The bytes for id. 18 | */ 19 | com.google.protobuf.ByteString 20 | getIdBytes(); 21 | } 22 | -------------------------------------------------------------------------------- /Chapter12/api/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/6.8.3/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'payment-gateway-api' 11 | include('lib') 12 | -------------------------------------------------------------------------------- /Chapter12/client/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /Chapter12/client/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter12/client/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter12/client/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter12/client/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'chapter12-client' 2 | -------------------------------------------------------------------------------- /Chapter12/client/src/main/java/com/packt/modern/api/ClientApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ClientApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ClientApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter12/client/src/main/java/com/packt/modern/api/client/GrpcClientRunner.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.client; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.CommandLineRunner; 7 | import org.springframework.context.annotation.Profile; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : Chapter12 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | @Profile("!test") 15 | @Component 16 | public class GrpcClientRunner implements CommandLineRunner { 17 | private final Logger LOG = LoggerFactory.getLogger(getClass()); 18 | @Autowired 19 | GrpcClient client; 20 | 21 | @Override 22 | public void run(String... args) { 23 | client.start(); 24 | 25 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 26 | try { 27 | client.shutdown(); 28 | } catch (InterruptedException e) { 29 | LOG.error("Client stopped with error: {}", e.getMessage()); 30 | } 31 | })); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter12/client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=grpc-client 2 | server.port=8081 3 | grpc.server.host=localhost 4 | grpc.server.port=8080 5 | 6 | logstash.destination=localhost:5002 7 | zipkin.baseUrl: localhost:9411 8 | spring.sleuth.sampler.probability: 1.0 9 | -------------------------------------------------------------------------------- /Chapter12/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3.2" 2 | services: 3 | elasticsearch: 4 | container_name: es-container 5 | image: docker.elastic.co/elasticsearch/elasticsearch:7.12.1 6 | environment: 7 | - xpack.security.enabled=false 8 | - "discovery.type=single-node" 9 | networks: 10 | - elk-net 11 | ports: 12 | - 19200:9200 13 | logstash: 14 | container_name: ls-container 15 | image: docker.elastic.co/logstash/logstash:7.12.1 16 | environment: 17 | - xpack.security.enabled=false 18 | command: logstash -e 'input { tcp { port => 5001 codec => "json" }} output { elasticsearch { hosts => "elasticsearch:9200" index => "modern-api" }}' 19 | networks: 20 | - elk-net 21 | depends_on: 22 | - elasticsearch 23 | ports: 24 | - 5002:5001 25 | kibana: 26 | container_name: kb-container 27 | image: docker.elastic.co/kibana/kibana:7.12.1 28 | environment: 29 | - ELASTICSEARCH_HOSTS=http://es-container:9200 30 | networks: 31 | - elk-net 32 | depends_on: 33 | - elasticsearch 34 | ports: 35 | - 5600:5601 36 | networks: 37 | elk-net: 38 | driver: bridge 39 | -------------------------------------------------------------------------------- /Chapter12/server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /Chapter12/server/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter12/server/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter12/server/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter12/server/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'chapter12-server' 2 | -------------------------------------------------------------------------------- /Chapter12/server/src/main/java/com/packt/modern/api/ServerApp.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ServerApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ServerApp.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter12/server/src/main/java/com/packt/modern/api/server/Config.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.server; 2 | 3 | import brave.grpc.GrpcTracing; 4 | import brave.rpc.RpcTracing; 5 | import io.grpc.ServerInterceptor; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter12 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | @Configuration 14 | public class Config { 15 | 16 | @Bean 17 | public GrpcTracing grpcTracing(RpcTracing rpcTracing) { 18 | return GrpcTracing.create(rpcTracing); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter12/server/src/main/java/com/packt/modern/api/server/GrpcServerRunner.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.server; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.context.annotation.Profile; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @author : github.com/sharmasourabh 9 | * @project : Chapter12-server - Modern API Development with Spring and Spring Boot 10 | **/ 11 | @Profile("!test") 12 | @Component 13 | public class GrpcServerRunner implements CommandLineRunner { 14 | 15 | private GrpcServer grpcServer; 16 | 17 | public GrpcServerRunner(GrpcServer grpcServer) { 18 | this.grpcServer = grpcServer; 19 | } 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | grpcServer.start(); 24 | grpcServer.block(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter12/server/src/main/java/com/packt/modern/api/server/repository/ChargeRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.server.repository; 2 | 3 | import com.packt.modern.api.grpc.v1.CaptureChargeReq; 4 | import com.packt.modern.api.grpc.v1.ChargeId; 5 | import com.packt.modern.api.grpc.v1.CreateChargeReq; 6 | import com.packt.modern.api.grpc.v1.CustomerId; 7 | import com.packt.modern.api.grpc.v1.UpdateChargeReq; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : Chapter12-server - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface ChargeRepository { 14 | 15 | CreateChargeReq.Response create(CreateChargeReq req); 16 | 17 | UpdateChargeReq.Response update(UpdateChargeReq req); 18 | 19 | ChargeId.Response retrieve(String chargeId); 20 | 21 | CaptureChargeReq.Response capture(CaptureChargeReq req); 22 | 23 | CustomerId.Response retrieveAll(String customerId); 24 | } 25 | -------------------------------------------------------------------------------- /Chapter12/server/src/main/java/com/packt/modern/api/server/repository/SourceRepository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.server.repository; 2 | 3 | import com.packt.modern.api.grpc.v1.AttachOrDetachReq; 4 | import com.packt.modern.api.grpc.v1.CreateSourceReq; 5 | import com.packt.modern.api.grpc.v1.SourceId; 6 | import com.packt.modern.api.grpc.v1.UpdateSourceReq; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : Chapter12-server - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface SourceRepository { 13 | 14 | UpdateSourceReq.Response update(UpdateSourceReq req); 15 | 16 | CreateSourceReq.Response create(CreateSourceReq req); 17 | 18 | SourceId.Response retrieve(String sourceId); 19 | 20 | AttachOrDetachReq.Response attach(AttachOrDetachReq req); 21 | 22 | AttachOrDetachReq.Response detach(AttachOrDetachReq req); 23 | } 24 | -------------------------------------------------------------------------------- /Chapter12/server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=grpc-server 2 | spring.main.web-application-type=none 3 | grpc.port=8080 4 | 5 | logstash.destination=localhost:5002 6 | zipkin.baseUrl: localhost:9411 7 | spring.sleuth.sampler.probability: 1 8 | -------------------------------------------------------------------------------- /Chapter14/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /Chapter14/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Modern-API-Development-with-Spring-and-Spring-Boot/fcfc9db95b2aeb4d1ad3a98127df3a84a6cac1c5/Chapter14/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Chapter14/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Chapter14/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'chapter14' 2 | -------------------------------------------------------------------------------- /Chapter14/src/main/java/com/packt/modern/api/Chapter14App.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Chapter14App { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Chapter14App.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter14/src/main/java/com/packt/modern/api/repository/Repository.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.repository; 2 | 3 | import com.packt.modern.api.generated.types.Product; 4 | import com.packt.modern.api.generated.types.Tag; 5 | import com.packt.modern.api.generated.types.TagInput; 6 | import java.util.List; 7 | import java.util.Map; 8 | import org.reactivestreams.Publisher; 9 | 10 | /** 11 | * @author : github.com/sharmasourabh 12 | * @project : chapter14 - Modern API Development with Spring and Spring Boot 13 | **/ 14 | public interface Repository { 15 | 16 | Product getProduct(String id); 17 | 18 | List getProducts(); 19 | 20 | Map> getProductTagMappings(List productIds); 21 | 22 | Product addTags(String productId, List tags); 23 | 24 | Product addQuantity(String productId, int qty); 25 | 26 | Publisher getProductPublisher(); 27 | } 28 | -------------------------------------------------------------------------------- /Chapter14/src/main/java/com/packt/modern/api/scalar/BigDecimalScalar.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.scalar; 2 | 3 | import com.netflix.graphql.dgs.DgsScalar; 4 | import graphql.scalar.GraphqlBigDecimalCoercing; 5 | 6 | /** 7 | * @author : github.com/sharmasourabh 8 | * @project : chapter14 - Modern API Development with Spring and Spring Boot 9 | **/ 10 | @DgsScalar(name = "BigDecimal") 11 | public class BigDecimalScalar extends GraphqlBigDecimalCoercing { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter14/src/main/java/com/packt/modern/api/scalar/DateTimeScalar.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.scalar; 2 | 3 | import com.netflix.graphql.dgs.DgsComponent; 4 | import com.netflix.graphql.dgs.DgsRuntimeWiring; 5 | import graphql.scalars.ExtendedScalars; 6 | import graphql.schema.idl.RuntimeWiring; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : chapter14 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | @DgsComponent 13 | public class DateTimeScalar { 14 | 15 | @DgsRuntimeWiring 16 | public RuntimeWiring.Builder addScalar(RuntimeWiring.Builder builder) { 17 | return builder.scalar(ExtendedScalars.DateTime); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter14/src/main/java/com/packt/modern/api/services/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.services; 2 | 3 | import com.packt.modern.api.generated.types.Product; 4 | import com.packt.modern.api.generated.types.ProductCriteria; 5 | import java.util.List; 6 | import org.reactivestreams.Publisher; 7 | 8 | /** 9 | * @author : github.com/sharmasourabh 10 | * @project : chapter14 - Modern API Development with Spring and Spring Boot 11 | **/ 12 | public interface ProductService { 13 | 14 | Product getProduct(String id); 15 | 16 | List getProducts(ProductCriteria criteria); 17 | 18 | Product addQuantity(String productId, int qty); 19 | 20 | Publisher gerProductPublisher(); 21 | } 22 | -------------------------------------------------------------------------------- /Chapter14/src/main/java/com/packt/modern/api/services/TagService.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.services; 2 | 3 | import com.packt.modern.api.generated.types.Product; 4 | import com.packt.modern.api.generated.types.Tag; 5 | import com.packt.modern.api.generated.types.TagInput; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author : github.com/sharmasourabh 11 | * @project : chapter14 - Modern API Development with Spring and Spring Boot 12 | **/ 13 | public interface TagService { 14 | Map> getTags(List productIds); 15 | Product addTags(String productId, List tags); 16 | } 17 | -------------------------------------------------------------------------------- /Chapter14/src/main/java/com/packt/modern/api/services/TagServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.packt.modern.api.services; 2 | 3 | import com.packt.modern.api.generated.types.Product; 4 | import com.packt.modern.api.generated.types.Tag; 5 | import com.packt.modern.api.generated.types.TagInput; 6 | import com.packt.modern.api.repository.Repository; 7 | import java.util.List; 8 | import java.util.Map; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @author : github.com/sharmasourabh 13 | * @project : chapter14 - Modern API Development with Spring and Spring Boot 14 | **/ 15 | @Service 16 | public class TagServiceImpl implements TagService { 17 | 18 | private final Repository repository; 19 | 20 | public TagServiceImpl(Repository repository) { 21 | this.repository = repository; 22 | } 23 | 24 | @Override 25 | public Map> getTags(List productIds) { 26 | return repository.getProductTagMappings(productIds); 27 | } 28 | 29 | @Override 30 | public Product addTags(String productId, List tags) { 31 | return repository.addTags(productId, tags); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter14/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter14/src/main/resources/schema/schema.graphqls: -------------------------------------------------------------------------------- 1 | type Query { 2 | products(filter: ProductCriteria): [Product]! 3 | product(id: ID!): Product 4 | } 5 | 6 | type Mutation { 7 | addTag(productId: ID!, tags: [TagInput!]!): Product 8 | addQuantity(productId: ID!, quantity: Int!): Product 9 | } 10 | 11 | type Subscription { 12 | quantityChanged(productId: ID!): Product 13 | } 14 | 15 | type Product { 16 | id: String 17 | name: String 18 | description: String 19 | imageUrl: String 20 | price: BigDecimal 21 | count: Int 22 | tags: [Tag] 23 | } 24 | 25 | input ProductCriteria { 26 | tags: [TagInput] = [] 27 | name: String = "" 28 | page: Int = 1 29 | size: Int = 10 30 | } 31 | 32 | input TagInput { 33 | name: String 34 | } 35 | 36 | type Tag { 37 | id: String 38 | name: String 39 | } 40 | 41 | scalar BigDecimal 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------