├── .github └── FUNDING.yml ├── .gitignore ├── README.md ├── primary-config-store ├── application.yml ├── mem-service │ ├── membership-dev.yml │ ├── membership-prod.yml │ ├── membership-qa.yml │ └── membership.yml ├── rpt-service │ ├── reporting-dev.yml │ ├── reporting-prod.yml │ ├── reporting-qa.yml │ └── reporting.yml └── search-service │ ├── search-dev.yml │ ├── search-prod.yml │ ├── search-qa.yml │ └── search.yml ├── summer-config-store ├── application.yml ├── mem-service │ ├── membership-dev.yml │ ├── membership-prod.yml │ ├── membership-qa.yml │ └── membership.yml ├── rpt-service │ ├── reporting-dev.yml │ ├── reporting-prod.yml │ ├── reporting-qa.yml │ └── reporting.yml └── search-service │ ├── search-dev.yml │ ├── search-prod.yml │ ├── search-qa.yml │ └── search.yml ├── video_001-to-video_004-demo-service ├── demo-application │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentacar │ │ │ │ └── demoapplication │ │ │ │ ├── DemoApplication.java │ │ │ │ ├── StageEndpoint.java │ │ │ │ ├── controller │ │ │ │ └── MainController.java │ │ │ │ ├── model │ │ │ │ └── Student.java │ │ │ │ ├── repository │ │ │ │ └── StudentRepository.java │ │ │ │ └── service │ │ │ │ ├── StudentService.java │ │ │ │ └── StudentServiceImpl.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentacar │ │ └── demoapplication │ │ └── DemoApplicationTests.java └── readme.txt ├── video_005-config-server-local ├── config-local │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── configlocal │ │ │ │ └── ConfigLocalApplication.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── config │ │ │ ├── service1.yml │ │ │ └── service2.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── configlocal │ │ └── ConfigLocalApplicationTests.java └── readme.txt ├── video_006-git-backed-config-server-and-consumer ├── config-consumer │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── configconsumer │ │ │ │ └── configconsumer │ │ │ │ ├── ConfigConsumerApplication.java │ │ │ │ ├── ProfileController.java │ │ │ │ └── model │ │ │ │ └── MemberProfileConfiguration.java │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── bootstrap.yml │ │ │ └── templates │ │ │ └── mprofile.html │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── configconsumer │ │ └── configconsumer │ │ └── ConfigConsumerApplicationTests.java ├── config-server │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── configserver │ │ │ │ └── ConfigServerApplication.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── configserver │ │ └── ConfigServerApplicationTests.java └── readme.txt ├── video_007-production-ready-service ├── profile-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── profileservice │ │ │ │ ├── ProfileServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── ProfileController.java │ │ │ │ ├── repository │ │ │ │ └── CustomerRepository.java │ │ │ │ └── service │ │ │ │ ├── CustomerService.java │ │ │ │ └── CustomerServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── profileservice │ │ └── ProfileServiceApplicationTests.java ├── readme.txt └── rentcloudcommons │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── krishantha │ └── rentcloud │ └── commons │ └── model │ ├── Customer.java │ └── Vehicle.java ├── video_008-basic-oAuth2-server ├── auth-server │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── auth │ │ │ │ └── authserver │ │ │ │ ├── AuthServerApplication.java │ │ │ │ └── conf │ │ │ │ ├── AuthServerConfigurations.java │ │ │ │ └── UserConfiguration.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── auth │ │ └── authserver │ │ └── AuthServerApplicationTests.java └── readme.txt ├── video_009-authorization-server-with-mysql ├── authorization-server │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── authorizationserver │ │ │ │ ├── AuthorizationServerApplication.java │ │ │ │ ├── config │ │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ │ └── WebSecurityConfiguration.java │ │ │ │ ├── model │ │ │ │ ├── AuthUserDetail.java │ │ │ │ ├── Permission.java │ │ │ │ ├── Role.java │ │ │ │ └── User.java │ │ │ │ ├── repository │ │ │ │ └── UserDetailRepository.java │ │ │ │ └── service │ │ │ │ └── UserDetailServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── data.txt │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── authorizationserver │ │ └── AuthorizationServerApplicationTests.java └── readme.txt ├── video_010-secure-microservices-with-resourceserver-and-oauth2 ├── authorization-server │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── authorizationserver │ │ │ │ ├── AuthorizationServerApplication.java │ │ │ │ ├── config │ │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ │ └── WebSecurityConfiguration.java │ │ │ │ ├── model │ │ │ │ ├── AuthUserDetail.java │ │ │ │ ├── Permission.java │ │ │ │ ├── Role.java │ │ │ │ └── User.java │ │ │ │ ├── repository │ │ │ │ └── UserDetailRepository.java │ │ │ │ └── service │ │ │ │ └── UserDetailServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── data.txt │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── authorizationserver │ │ └── AuthorizationServerApplicationTests.java ├── profile-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── profileservice │ │ │ │ ├── ProfileServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── ProfileController.java │ │ │ │ ├── repository │ │ │ │ └── CustomerRepository.java │ │ │ │ └── service │ │ │ │ ├── CustomerService.java │ │ │ │ └── CustomerServiceImpl.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── profileservice │ │ └── ProfileServiceApplicationTests.java └── readme.txt ├── video_011-rolebased-permission-to-microservices ├── authorization-server │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── authorizationserver │ │ │ │ ├── AuthorizationServerApplication.java │ │ │ │ ├── config │ │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ │ └── WebSecurityConfiguration.java │ │ │ │ ├── model │ │ │ │ ├── AuthUserDetail.java │ │ │ │ ├── Permission.java │ │ │ │ ├── Role.java │ │ │ │ └── User.java │ │ │ │ ├── repository │ │ │ │ └── UserDetailRepository.java │ │ │ │ └── service │ │ │ │ └── UserDetailServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── data.txt │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── authorizationserver │ │ └── AuthorizationServerApplicationTests.java ├── profile-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── profileservice │ │ │ │ ├── ProfileServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── ProfileController.java │ │ │ │ ├── repository │ │ │ │ └── CustomerRepository.java │ │ │ │ └── service │ │ │ │ ├── CustomerService.java │ │ │ │ └── CustomerServiceImpl.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── profileservice │ │ └── ProfileServiceApplicationTests.java ├── readme.txt └── rentcloudcommons │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── krishantha │ └── rentcloud │ └── commons │ └── model │ ├── Customer.java │ └── Vehicle.java ├── video_012-springboot-springsecurity-oauthcode-flow ├── authorization-server │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── authorizationserver │ │ │ │ ├── AuthorizationServerApplication.java │ │ │ │ ├── config │ │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ │ └── WebSecurityConfiguration.java │ │ │ │ ├── model │ │ │ │ ├── AuthUserDetail.java │ │ │ │ ├── Permission.java │ │ │ │ ├── Role.java │ │ │ │ └── User.java │ │ │ │ ├── repository │ │ │ │ └── UserDetailRepository.java │ │ │ │ └── service │ │ │ │ └── UserDetailServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── data.sql │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── authorizationserver │ │ └── AuthorizationServerApplicationTests.java ├── readme.txt └── rent-ui │ ├── .gitignore │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── rentui │ │ │ ├── RentUiApplication.java │ │ │ └── controller │ │ │ └── UIController.java │ └── resources │ │ ├── application.yml │ │ └── templates │ │ ├── home.html │ │ └── secure.html │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── rentui │ └── RentUiApplicationTests.java ├── video_013-sso-remote-service-call-and-error-handling ├── authorization-server │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── authorizationserver │ │ │ │ ├── AuthorizationServerApplication.java │ │ │ │ ├── config │ │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ │ └── WebSecurityConfiguration.java │ │ │ │ ├── model │ │ │ │ ├── AuthUserDetail.java │ │ │ │ ├── Permission.java │ │ │ │ ├── Role.java │ │ │ │ └── User.java │ │ │ │ ├── repository │ │ │ │ └── UserDetailRepository.java │ │ │ │ └── service │ │ │ │ └── UserDetailServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── data.txt │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── authorizationserver │ │ └── AuthorizationServerApplicationTests.java ├── profile-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── krishantha │ │ │ │ └── rentcloud │ │ │ │ └── profileservice │ │ │ │ ├── ProfileServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── ProfileController.java │ │ │ │ ├── repository │ │ │ │ └── CustomerRepository.java │ │ │ │ └── service │ │ │ │ ├── CustomerService.java │ │ │ │ └── CustomerServiceImpl.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── krishantha │ │ └── rentcloud │ │ └── profileservice │ │ └── ProfileServiceApplicationTests.java ├── readme.txt └── rent-ui │ ├── .gitignore │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── rentui │ │ │ ├── RentUiApplication.java │ │ │ ├── config │ │ │ ├── AccessToken.java │ │ │ └── RestTemplateConfiguration.java │ │ │ └── controller │ │ │ └── UIController.java │ └── resources │ │ ├── application.yml │ │ └── templates │ │ ├── home.html │ │ └── secure.html │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── rentui │ └── RentUiApplicationTests.java ├── video_014-Async-services-with-spring-task ├── readme.txt └── rent-process-task │ ├── .gitignore │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── rentprocesstask │ │ │ ├── RentProcessTaskApplication.java │ │ │ └── service │ │ │ ├── RentProcessService.java │ │ │ ├── RentProcessServiceImpl.java │ │ │ └── RentProcessTaskRunner.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── rentprocesstask │ └── RentProcessTaskApplicationTests.java ├── video_015-service-chaining ├── customer-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── lk │ │ │ │ └── codelabs │ │ │ │ └── rentcloud │ │ │ │ └── customerservice │ │ │ │ ├── CustomerServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── CustomerServiceController.java │ │ │ │ ├── repository │ │ │ │ └── CustomerRepository.java │ │ │ │ └── service │ │ │ │ ├── CustomerService.java │ │ │ │ └── CustomerServiceImpl.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── customerservice │ │ └── CustomerServiceApplicationTests.java ├── readme.txt ├── rent-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── lk │ │ │ │ └── codelabs │ │ │ │ └── rentcloud │ │ │ │ └── rentservice │ │ │ │ ├── RentServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── RentController.java │ │ │ │ ├── model │ │ │ │ ├── DetailResponse.java │ │ │ │ ├── Response.java │ │ │ │ └── SimpleResponse.java │ │ │ │ ├── repository │ │ │ │ └── RentRepository.java │ │ │ │ └── service │ │ │ │ ├── RentService.java │ │ │ │ └── RentServiceImpl.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── rentservice │ │ └── RentServiceApplicationTests.java ├── rentcloud-model │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── model │ │ ├── customer │ │ ├── Customer.java │ │ └── Loyality.java │ │ ├── rent │ │ └── Rent.java │ │ └── vehicle │ │ └── Vehicle.java ├── rest-client-insomnia-project │ └── Insomnia_2019-10-23.json └── vehicle-service │ ├── .gitignore │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── vehicleservice │ │ │ ├── VehicleServiceApplication.java │ │ │ ├── controller │ │ │ └── VehicleController.java │ │ │ ├── repository │ │ │ └── VehicleRepository.java │ │ │ └── service │ │ │ ├── VehicleService.java │ │ │ └── VehicleServiceImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── vehicleservice │ └── VehicleServiceApplicationTests.java ├── video_016-service-discovery ├── customer-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── lk │ │ │ │ └── codelabs │ │ │ │ └── rentcloud │ │ │ │ └── customerservice │ │ │ │ ├── CustomerServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── CustomerServiceController.java │ │ │ │ ├── repository │ │ │ │ └── CustomerRepository.java │ │ │ │ └── service │ │ │ │ ├── CustomerService.java │ │ │ │ └── CustomerServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── customerservice │ │ └── CustomerServiceApplicationTests.java ├── discovery-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── lk │ │ │ │ └── codelabs │ │ │ │ └── rentcloud │ │ │ │ └── discoveryservice │ │ │ │ └── DiscoveryServiceApplication.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── discoveryservice │ │ └── DiscoveryServiceApplicationTests.java ├── readme.txt ├── rent-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── lk │ │ │ │ └── codelabs │ │ │ │ └── rentcloud │ │ │ │ └── rentservice │ │ │ │ ├── RentServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── RentController.java │ │ │ │ ├── model │ │ │ │ ├── DetailResponse.java │ │ │ │ ├── Response.java │ │ │ │ └── SimpleResponse.java │ │ │ │ ├── repository │ │ │ │ └── RentRepository.java │ │ │ │ └── service │ │ │ │ ├── RentService.java │ │ │ │ └── RentServiceImpl.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── rentservice │ │ └── RentServiceApplicationTests.java └── vehicle-service │ ├── .gitignore │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── vehicleservice │ │ │ ├── VehicleServiceApplication.java │ │ │ ├── controller │ │ │ └── VehicleController.java │ │ │ ├── repository │ │ │ └── VehicleRepository.java │ │ │ └── service │ │ │ ├── VehicleService.java │ │ │ └── VehicleServiceImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── vehicleservice │ └── VehicleServiceApplicationTests.java ├── video_017-service-discovery-with-discovery-clients ├── customer-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── lk │ │ │ │ └── codelabs │ │ │ │ └── rentcloud │ │ │ │ └── customerservice │ │ │ │ ├── CustomerServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── CustomerServiceController.java │ │ │ │ ├── repository │ │ │ │ └── CustomerRepository.java │ │ │ │ └── service │ │ │ │ ├── CustomerService.java │ │ │ │ └── CustomerServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── customerservice │ │ └── CustomerServiceApplicationTests.java ├── discovery-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── lk │ │ │ │ └── codelabs │ │ │ │ └── rentcloud │ │ │ │ └── discoveryservice │ │ │ │ └── DiscoveryServiceApplication.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── discoveryservice │ │ └── DiscoveryServiceApplicationTests.java ├── readme.txt ├── rent-service │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── lk │ │ │ │ └── codelabs │ │ │ │ └── rentcloud │ │ │ │ └── rentservice │ │ │ │ ├── RentServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── RentController.java │ │ │ │ ├── model │ │ │ │ ├── DetailResponse.java │ │ │ │ ├── Response.java │ │ │ │ └── SimpleResponse.java │ │ │ │ ├── repository │ │ │ │ └── RentRepository.java │ │ │ │ └── service │ │ │ │ ├── RentService.java │ │ │ │ └── RentServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── rentservice │ │ └── RentServiceApplicationTests.java └── vehicle-service │ ├── .gitignore │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── vehicleservice │ │ │ ├── VehicleServiceApplication.java │ │ │ ├── controller │ │ │ └── VehicleController.java │ │ │ ├── repository │ │ │ └── VehicleRepository.java │ │ │ └── service │ │ │ ├── VehicleService.java │ │ │ └── VehicleServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── vehicleservice │ └── VehicleServiceApplicationTests.java └── video_018-circuit-breaker-pattern ├── customer-service ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── customerservice │ │ │ ├── CustomerServiceApplication.java │ │ │ ├── controller │ │ │ └── CustomerServiceController.java │ │ │ ├── repository │ │ │ └── CustomerRepository.java │ │ │ └── service │ │ │ ├── CustomerService.java │ │ │ └── CustomerServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── customerservice │ └── CustomerServiceApplicationTests.java ├── discovery-service ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── discoveryservice │ │ │ └── DiscoveryServiceApplication.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── discoveryservice │ └── DiscoveryServiceApplicationTests.java ├── readme.txt ├── rent-service ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── lk │ │ │ └── codelabs │ │ │ └── rentcloud │ │ │ └── rentservice │ │ │ ├── RentServiceApplication.java │ │ │ ├── controller │ │ │ └── RentController.java │ │ │ ├── hystrix │ │ │ ├── CommonHysctrixCommand.java │ │ │ ├── HystrixConfig.java │ │ │ └── VehicleCommand.java │ │ │ ├── model │ │ │ ├── DetailResponse.java │ │ │ ├── Response.java │ │ │ └── SimpleResponse.java │ │ │ ├── repository │ │ │ └── RentRepository.java │ │ │ └── service │ │ │ ├── RentService.java │ │ │ └── RentServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml │ └── test │ └── java │ └── lk │ └── codelabs │ └── rentcloud │ └── rentservice │ └── RentServiceApplicationTests.java └── vehicle-service ├── .gitignore ├── pom.xml └── src ├── main ├── java │ └── lk │ │ └── codelabs │ │ └── rentcloud │ │ └── vehicleservice │ │ ├── VehicleServiceApplication.java │ │ ├── controller │ │ └── VehicleController.java │ │ ├── repository │ │ └── VehicleRepository.java │ │ └── service │ │ ├── VehicleService.java │ │ └── VehicleServiceImpl.java └── resources │ ├── application.yml │ └── bootstrap.yml └── test └── java └── lk └── codelabs └── rentcloud └── vehicleservice └── VehicleServiceApplicationTests.java /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: #[krish] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.paypal.com/paypalme/helloKrish'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ 25 | .mvn/ 26 | mvnw 27 | mvnw.cmd 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # microservices-course-on-youtube -------------------------------------------------------------------------------- /primary-config-store/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8191 3 | spring: 4 | cloud: 5 | config: 6 | server: 7 | git: 8 | uri: https://github.com/krish/spring-cloud-config 9 | search-paths: 10 | - '*service' 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /primary-config-store/mem-service/membership-dev.yml: -------------------------------------------------------------------------------- 1 | member: 2 | rent: 3 | min: 8 4 | max: 31 5 | price: 6 | discount: 3 7 | vehicle: 8 | default: 9 | model: cross over 10 | duration: all -------------------------------------------------------------------------------- /primary-config-store/mem-service/membership-prod.yml: -------------------------------------------------------------------------------- 1 | member: 2 | rent: 3 | min: 5 4 | max: 40 5 | price: 6 | discount: 3.5 7 | vehicle: 8 | default: 9 | model: cross over 10 | duration: all -------------------------------------------------------------------------------- /primary-config-store/mem-service/membership-qa.yml: -------------------------------------------------------------------------------- 1 | member: 2 | rent: 3 | min: 10 4 | max: 33 5 | price: 6 | discount: 3 7 | vehicle: 8 | default: 9 | model: cross over 10 | duration: all -------------------------------------------------------------------------------- /primary-config-store/mem-service/membership.yml: -------------------------------------------------------------------------------- 1 | member: 2 | rent: 3 | min: 7 4 | max: 30 5 | price: 6 | discount: 3 7 | vehicle: 8 | default: 9 | model: cross over 10 | duration: all -------------------------------------------------------------------------------- /primary-config-store/rpt-service/reporting-dev.yml: -------------------------------------------------------------------------------- 1 | report: 2 | export: 3 | type: pdf 4 | border: 2 5 | page: 6 | color: yellow 7 | size: A4 8 | duration: all -------------------------------------------------------------------------------- /primary-config-store/rpt-service/reporting-prod.yml: -------------------------------------------------------------------------------- 1 | report: 2 | export: 3 | type: pdf,doc 4 | border: 1 5 | page: 6 | color: white 7 | size: A4 8 | duration: all -------------------------------------------------------------------------------- /primary-config-store/rpt-service/reporting-qa.yml: -------------------------------------------------------------------------------- 1 | report: 2 | export: 3 | type: pdf 4 | border: none 5 | page: 6 | color: white 7 | size: A4 8 | duration: all -------------------------------------------------------------------------------- /primary-config-store/rpt-service/reporting.yml: -------------------------------------------------------------------------------- 1 | report: 2 | export: 3 | type: pdf 4 | border: none 5 | page: 6 | color: white 7 | size: A4 8 | duration: all -------------------------------------------------------------------------------- /primary-config-store/search-service/search-dev.yml: -------------------------------------------------------------------------------- 1 | search: 2 | result: 3 | perpage: 10 4 | canexport: true 5 | render: false 6 | duration: all -------------------------------------------------------------------------------- /primary-config-store/search-service/search-prod.yml: -------------------------------------------------------------------------------- 1 | search: 2 | result: 3 | perpage: 200 4 | canexport: true 5 | render: false 6 | duration: all -------------------------------------------------------------------------------- /primary-config-store/search-service/search-qa.yml: -------------------------------------------------------------------------------- 1 | search: 2 | result: 3 | perpage: 500 4 | canexport: true 5 | render: false 6 | duration: all -------------------------------------------------------------------------------- /primary-config-store/search-service/search.yml: -------------------------------------------------------------------------------- 1 | search: 2 | result: 3 | perpage: 100 4 | canexport: true 5 | render: false 6 | duration: all -------------------------------------------------------------------------------- /summer-config-store/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8191 3 | spring: 4 | cloud: 5 | config: 6 | server: 7 | git: 8 | uri: https://github.com/krish/spring-cloud-config 9 | search-paths: 10 | - '*service' 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /summer-config-store/mem-service/membership-dev.yml: -------------------------------------------------------------------------------- 1 | member: 2 | rent: 3 | min: 8 4 | max: 31 5 | price: 6 | discount: 3 7 | vehicle: 8 | default: 9 | model: cross over 10 | duration: summer -------------------------------------------------------------------------------- /summer-config-store/mem-service/membership-prod.yml: -------------------------------------------------------------------------------- 1 | member: 2 | rent: 3 | min: 5 4 | max: 40 5 | price: 6 | discount: 3.5 7 | vehicle: 8 | default: 9 | model: cross over 10 | duration: summer -------------------------------------------------------------------------------- /summer-config-store/mem-service/membership-qa.yml: -------------------------------------------------------------------------------- 1 | member: 2 | rent: 3 | min: 10 4 | max: 33 5 | price: 6 | discount: 3 7 | vehicle: 8 | default: 9 | model: cross over 10 | duration: summer -------------------------------------------------------------------------------- /summer-config-store/mem-service/membership.yml: -------------------------------------------------------------------------------- 1 | member: 2 | rent: 3 | min: 7 4 | max: 30 5 | price: 6 | discount: 3 7 | vehicle: 8 | default: 9 | model: cross over 10 | duration: summer -------------------------------------------------------------------------------- /summer-config-store/rpt-service/reporting-dev.yml: -------------------------------------------------------------------------------- 1 | report: 2 | export: 3 | type: pdf 4 | border: 2 5 | page: 6 | color: yellow 7 | size: A4 8 | duration: all -------------------------------------------------------------------------------- /summer-config-store/rpt-service/reporting-prod.yml: -------------------------------------------------------------------------------- 1 | report: 2 | export: 3 | type: pdf,doc 4 | border: 1 5 | page: 6 | color: white 7 | size: A4 8 | duration: all -------------------------------------------------------------------------------- /summer-config-store/rpt-service/reporting-qa.yml: -------------------------------------------------------------------------------- 1 | report: 2 | export: 3 | type: pdf 4 | border: none 5 | page: 6 | color: white 7 | size: A4 8 | duration: all -------------------------------------------------------------------------------- /summer-config-store/rpt-service/reporting.yml: -------------------------------------------------------------------------------- 1 | report: 2 | export: 3 | type: pdf 4 | border: none 5 | page: 6 | color: white 7 | size: A4 8 | duration: summer -------------------------------------------------------------------------------- /summer-config-store/search-service/search-dev.yml: -------------------------------------------------------------------------------- 1 | search: 2 | result: 3 | perpage: 10 4 | canexport: true 5 | render: false 6 | duration: all -------------------------------------------------------------------------------- /summer-config-store/search-service/search-prod.yml: -------------------------------------------------------------------------------- 1 | search: 2 | result: 3 | perpage: 200 4 | canexport: true 5 | render: false 6 | duration: all -------------------------------------------------------------------------------- /summer-config-store/search-service/search-qa.yml: -------------------------------------------------------------------------------- 1 | search: 2 | result: 3 | perpage: 500 4 | canexport: true 5 | render: false 6 | duration: all -------------------------------------------------------------------------------- /summer-config-store/search-service/search.yml: -------------------------------------------------------------------------------- 1 | search: 2 | result: 3 | perpage: 100 4 | canexport: true 5 | render: false 6 | duration: summer -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/demo-application/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/demo-application/src/main/java/com/krishantha/rentacar/demoapplication/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentacar.demoapplication; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/demo-application/src/main/java/com/krishantha/rentacar/demoapplication/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentacar.demoapplication.model; 2 | 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.Id; 6 | import javax.persistence.Table; 7 | 8 | @Entity 9 | @Table(name = "student") 10 | public class Student { 11 | 12 | 13 | @Id 14 | private int id; 15 | 16 | private String firstName; 17 | private String lastName; 18 | 19 | 20 | public int getId() { 21 | return id; 22 | } 23 | 24 | public void setId(int id) { 25 | this.id = id; 26 | } 27 | 28 | public String getFirstName() { 29 | return firstName; 30 | } 31 | 32 | public void setFirstName(String firstName) { 33 | this.firstName = firstName; 34 | } 35 | 36 | public String getLastName() { 37 | return lastName; 38 | } 39 | 40 | public void setLastName(String lastName) { 41 | this.lastName = lastName; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/demo-application/src/main/java/com/krishantha/rentacar/demoapplication/repository/StudentRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentacar.demoapplication.repository; 2 | 3 | import com.krishantha.rentacar.demoapplication.model.Student; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.repository.Repository; 6 | 7 | public interface StudentRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/demo-application/src/main/java/com/krishantha/rentacar/demoapplication/service/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentacar.demoapplication.service; 2 | 3 | import com.krishantha.rentacar.demoapplication.model.Student; 4 | 5 | public interface StudentService { 6 | 7 | 8 | Student save(Student student); 9 | public Student fetchStudentById(int id); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/demo-application/src/main/java/com/krishantha/rentacar/demoapplication/service/StudentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentacar.demoapplication.service; 2 | 3 | import com.krishantha.rentacar.demoapplication.model.Student; 4 | import com.krishantha.rentacar.demoapplication.repository.StudentRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.Optional; 9 | 10 | @Service 11 | public class StudentServiceImpl implements StudentService { 12 | 13 | @Autowired 14 | StudentRepository studentRepository; 15 | 16 | public Student save(Student student) { 17 | 18 | return studentRepository.save(student); 19 | } 20 | 21 | 22 | public Student fetchStudentById(int id){ 23 | 24 | 25 | Optional student= studentRepository.findById( id); 26 | if(student.isPresent()){ 27 | return student.get(); 28 | } 29 | return null; 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/demo-application/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | management: 2 | endpoints: 3 | web: 4 | exposure: 5 | include: '*' 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/sample?createDatabaseIfNotExist=true 9 | username: root 10 | password: password 11 | driver-class-name: com.mysql.jdbc.Driver 12 | jpa: 13 | hibernate: 14 | naming: 15 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 16 | 17 | 18 | -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/demo-application/src/test/java/com/krishantha/rentacar/demoapplication/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentacar.demoapplication; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_001-to-video_004-demo-service/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_005-config-server-local/config-local/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /video_005-config-server-local/config-local/src/main/java/com/krishantha/rentcloud/configlocal/ConfigLocalApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.configlocal; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigLocalApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ConfigLocalApplication.class, args); 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /video_005-config-server-local/config-local/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8191 3 | spring: 4 | profiles: 5 | active: native -------------------------------------------------------------------------------- /video_005-config-server-local/config-local/src/main/resources/config/service1.yml: -------------------------------------------------------------------------------- 1 | service: 2 | greeting: Hello from from service 1 3 | id: 1223455 -------------------------------------------------------------------------------- /video_005-config-server-local/config-local/src/main/resources/config/service2.yml: -------------------------------------------------------------------------------- 1 | service: 2 | greeting: Hello from from service 2 3 | id: 888888888 -------------------------------------------------------------------------------- /video_005-config-server-local/config-local/src/test/java/com/krishantha/rentcloud/configlocal/ConfigLocalApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.configlocal; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ConfigLocalApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_005-config-server-local/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-consumer/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-consumer/src/main/java/com/krishantha/configconsumer/configconsumer/ConfigConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.configconsumer.configconsumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ConfigConsumerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ConfigConsumerApplication.class, args); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-consumer/src/main/java/com/krishantha/configconsumer/configconsumer/ProfileController.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.configconsumer.configconsumer; 2 | 3 | import com.krishantha.configconsumer.configconsumer.model.MemberProfileConfiguration; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @Controller 11 | public class ProfileController { 12 | 13 | 14 | @Autowired 15 | MemberProfileConfiguration memberProfileConfiguration; 16 | 17 | 18 | @RequestMapping("/profile") 19 | public String getConfig(Model model){ 20 | 21 | model.addAttribute("model",memberProfileConfiguration.getDefaultModel()); 22 | model.addAttribute("min",memberProfileConfiguration.getMinRentPeriod()); 23 | return "mprofile"; 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-consumer/src/main/java/com/krishantha/configconsumer/configconsumer/model/MemberProfileConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.configconsumer.configconsumer.model; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.core.env.Environment; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class MemberProfileConfiguration { 10 | 11 | 12 | @Autowired 13 | Environment environment; 14 | 15 | 16 | public String getDefaultModel(){ 17 | return environment.getProperty("vehicle.default.model"); 18 | } 19 | public String getMinRentPeriod(){ 20 | return environment.getProperty("member.rent.min"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: membership -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-consumer/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | uri: http://localhost:8191 -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-consumer/src/main/resources/templates/mprofile.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 |

7 | 8 | 9 | -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-consumer/src/test/java/com/krishantha/configconsumer/configconsumer/ConfigConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.configconsumer.configconsumer; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ConfigConsumerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-server/src/main/java/com/krishantha/rentcloud/configserver/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.configserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ConfigServerApplication.class, args); 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8191 3 | spring: 4 | cloud: 5 | config: 6 | server: 7 | git: 8 | uri: https://github.com/krish/microservices-course-on-youtube-config-store 9 | search-paths: 10 | - 'service-config/*service' 11 | #username: root 12 | #passphrase: 12345 -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/config-server/src/test/java/com/krishantha/rentcloud/configserver/ConfigServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.configserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ConfigServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_006-git-backed-config-server-and-consumer/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/ProfileServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | 7 | @SpringBootApplication 8 | @EntityScan(basePackages = "com.krishantha.rentcloud.commons.model") 9 | public class ProfileServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ProfileServiceApplication.class, args); 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/controller/ProfileController.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.controller; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | import com.krishantha.rentcloud.profileservice.service.CustomerService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.util.List; 9 | 10 | @RestController 11 | @RequestMapping(value = "/services") 12 | public class ProfileController { 13 | 14 | 15 | @Autowired 16 | CustomerService customerService; 17 | 18 | @RequestMapping(value = "/profile", method = RequestMethod.POST) 19 | public Customer save(@RequestBody Customer customer) { 20 | return customerService.save(customer); 21 | } 22 | 23 | @RequestMapping(value = "/profile", method = RequestMethod.GET) 24 | public Customer fetch(@RequestParam int profileId) { 25 | return customerService.fetchById(profileId); 26 | } 27 | 28 | @RequestMapping(value = "/profiles", method = RequestMethod.GET) 29 | public List fetch() { 30 | return customerService.fetchAllProfiles(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.repository; 2 | 3 | 4 | import com.krishantha.rentcloud.commons.model.Customer; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | public interface CustomerRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.service; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | 5 | import java.util.List; 6 | 7 | public interface CustomerService { 8 | 9 | 10 | Customer save(Customer customer); 11 | 12 | Customer fetchById(int profileId); 13 | 14 | List fetchAllProfiles(); 15 | } 16 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.service; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | import com.krishantha.rentcloud.profileservice.repository.CustomerRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | @Service 12 | public class CustomerServiceImpl implements CustomerService { 13 | 14 | @Autowired 15 | CustomerRepository customerRepository; 16 | 17 | @Override 18 | public Customer save(Customer customer) { 19 | return customerRepository.save(customer); 20 | } 21 | 22 | @Override 23 | public Customer fetchById(int profileId) { 24 | Optional customer = customerRepository.findById(profileId); 25 | if (customer.isPresent()) { 26 | return customer.get(); 27 | } else { 28 | return null; 29 | } 30 | } 31 | 32 | @Override 33 | public List fetchAllProfiles() { 34 | return customerRepository.findAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: profile 4 | jpa: 5 | hibernate: 6 | ddl-auto: update 7 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | uri: http://localhost:8191 5 | -------------------------------------------------------------------------------- /video_007-production-ready-service/profile-service/src/test/java/com/krishantha/rentcloud/profileservice/ProfileServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProfileServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_007-production-ready-service/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_007-production-ready-service/rentcloudcommons/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.krishantha.rentcloud 8 | rentcloud-commons 9 | 1.0-SNAPSHOT 10 | 11 | 12 | javax.persistence 13 | javax.persistence-api 14 | 2.2 15 | 16 | 17 | 18 | mysql 19 | mysql-connector-java 20 | 5.1.44 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /video_007-production-ready-service/rentcloudcommons/src/main/java/com/krishantha/rentcloud/commons/model/Customer.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.commons.model; 2 | 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import javax.persistence.Table; 8 | 9 | @Entity 10 | @Table(name = "customer") 11 | public class Customer { 12 | 13 | @Id 14 | @GeneratedValue 15 | int id; 16 | 17 | String firstName; 18 | String lastName; 19 | String dlNumber; 20 | String zipcode; 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getFirstName() { 31 | return firstName; 32 | } 33 | 34 | public void setFirstName(String firstName) { 35 | this.firstName = firstName; 36 | } 37 | 38 | public String getLastName() { 39 | return lastName; 40 | } 41 | 42 | public void setLastName(String lastName) { 43 | this.lastName = lastName; 44 | } 45 | 46 | public String getDlNumber() { 47 | return dlNumber; 48 | } 49 | 50 | public void setDlNumber(String dlNumber) { 51 | this.dlNumber = dlNumber; 52 | } 53 | 54 | public String getZipcode() { 55 | return zipcode; 56 | } 57 | 58 | public void setZipcode(String zipcode) { 59 | this.zipcode = zipcode; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /video_007-production-ready-service/rentcloudcommons/src/main/java/com/krishantha/rentcloud/commons/model/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.commons.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | import javax.persistence.Table; 7 | 8 | @Entity 9 | @Table(name = "vehicle") 10 | public class Vehicle { 11 | 12 | @Id 13 | @GeneratedValue 14 | int id; 15 | 16 | String make; 17 | String model; 18 | String type; 19 | int year; 20 | 21 | public int getId() { 22 | return id; 23 | } 24 | 25 | public void setId(int id) { 26 | this.id = id; 27 | } 28 | 29 | public String getMake() { 30 | return make; 31 | } 32 | 33 | public void setMake(String make) { 34 | this.make = make; 35 | } 36 | 37 | public String getModel() { 38 | return model; 39 | } 40 | 41 | public void setModel(String model) { 42 | this.model = model; 43 | } 44 | 45 | public String getType() { 46 | return type; 47 | } 48 | 49 | public void setType(String type) { 50 | this.type = type; 51 | } 52 | 53 | public int getYear() { 54 | return year; 55 | } 56 | 57 | public void setYear(int year) { 58 | this.year = year; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /video_008-basic-oAuth2-server/auth-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_008-basic-oAuth2-server/auth-server/src/main/java/com/krishantha/rentcloud/auth/authserver/AuthServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.auth.authserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | 7 | @SpringBootApplication 8 | @EnableAuthorizationServer 9 | public class AuthServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AuthServerApplication.class, args); 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /video_008-basic-oAuth2-server/auth-server/src/main/java/com/krishantha/rentcloud/auth/authserver/conf/UserConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.auth.authserver.conf; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 5 | import org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter; 6 | import org.springframework.security.crypto.factory.PasswordEncoderFactories; 7 | import org.springframework.security.crypto.password.PasswordEncoder; 8 | 9 | @Configuration 10 | public class UserConfiguration extends GlobalAuthenticationConfigurerAdapter { 11 | 12 | PasswordEncoder passwordEncoder=PasswordEncoderFactories.createDelegatingPasswordEncoder(); 13 | 14 | 15 | @Override 16 | public void init(AuthenticationManagerBuilder auth) throws Exception { 17 | 18 | auth.inMemoryAuthentication().withUser("krish").password(passwordEncoder.encode("krishpass")).roles("USER","ADMIN","MANAGER").authorities("CAN_READ","CAN_WRITE","CAN_DELETE").and() 19 | .withUser("suranga").password(passwordEncoder.encode("surpass")).roles("USER").authorities("CAN_READ","CAN_WRITE"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /video_008-basic-oAuth2-server/auth-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8282 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /video_008-basic-oAuth2-server/auth-server/src/test/java/com/krishantha/rentcloud/auth/authserver/AuthServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.auth.authserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AuthServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_008-basic-oAuth2-server/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_009-authorization-server-with-mysql/authorization-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_009-authorization-server-with-mysql/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | 7 | @SpringBootApplication 8 | @EnableAuthorizationServer 9 | public class AuthorizationServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AuthorizationServerApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_009-authorization-server-with-mysql/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Permission.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.io.Serializable; 7 | 8 | @Entity 9 | @Table(name = "permission") 10 | @Data 11 | public class Permission implements Serializable { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.AUTO) 14 | private Integer id; 15 | @Column(name = "name") 16 | private String name; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /video_009-authorization-server-with-mysql/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Role.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | 4 | import lombok.Data; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | @Entity 11 | @Table(name = "role") 12 | @Data 13 | public class Role implements Serializable { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.AUTO) 17 | private Integer id; 18 | @Column(name = "name") 19 | private String name; 20 | 21 | @ManyToMany(fetch = FetchType.EAGER) 22 | @JoinTable(name = "permission_role", joinColumns = { 23 | @JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = { 24 | @JoinColumn(name = "permission_id", referencedColumnName = "id")}) 25 | private List permissions; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /video_009-authorization-server-with-mysql/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/repository/UserDetailRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.repository; 2 | 3 | import com.krishantha.rentcloud.authorizationserver.model.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.jws.soap.SOAPBinding; 7 | import java.util.Optional; 8 | 9 | public interface UserDetailRepository extends JpaRepository { 10 | 11 | 12 | Optional findByUsername(String name); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video_009-authorization-server-with-mysql/authorization-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9191 3 | spring: 4 | datasource: 5 | url: jdbc:mysql://localhost:3306/authDB?createDatabaseIfNotExist=true 6 | username: root 7 | password: 1qazxsw2# 8 | driver-class-name: com.mysql.jdbc.Driver 9 | initialization-mode: always 10 | jpa: 11 | hibernate: 12 | naming: 13 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 14 | properties: 15 | hibernate: 16 | show_sql: true 17 | format_sql: true 18 | logging: 19 | level: 20 | org: 21 | hibernate: 22 | type: trace -------------------------------------------------------------------------------- /video_009-authorization-server-with-mysql/authorization-server/src/test/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AuthorizationServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_009-authorization-server-with-mysql/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/authorization-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | 7 | @SpringBootApplication 8 | @EnableAuthorizationServer 9 | public class AuthorizationServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AuthorizationServerApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Permission.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.io.Serializable; 7 | 8 | @Entity 9 | @Table(name = "permission") 10 | @Data 11 | public class Permission implements Serializable { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.AUTO) 14 | private Integer id; 15 | @Column(name = "name") 16 | private String name; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Role.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | 4 | import lombok.Data; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | @Entity 11 | @Table(name = "role") 12 | @Data 13 | public class Role implements Serializable { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.AUTO) 17 | private Integer id; 18 | @Column(name = "name") 19 | private String name; 20 | 21 | @ManyToMany(fetch = FetchType.EAGER) 22 | @JoinTable(name = "permission_role", joinColumns = { 23 | @JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = { 24 | @JoinColumn(name = "permission_id", referencedColumnName = "id")}) 25 | private List permissions; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/repository/UserDetailRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.repository; 2 | 3 | import com.krishantha.rentcloud.authorizationserver.model.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.jws.soap.SOAPBinding; 7 | import java.util.Optional; 8 | 9 | public interface UserDetailRepository extends JpaRepository { 10 | 11 | 12 | Optional findByUsername(String name); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/authorization-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9191 3 | spring: 4 | datasource: 5 | url: jdbc:mysql://localhost:3306/authDB?createDatabaseIfNotExist=true 6 | username: root 7 | password: 1qazxsw2# 8 | driver-class-name: com.mysql.jdbc.Driver 9 | initialization-mode: always 10 | jpa: 11 | hibernate: 12 | naming: 13 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 14 | properties: 15 | hibernate: 16 | show_sql: true 17 | format_sql: true 18 | logging: 19 | level: 20 | org: 21 | hibernate: 22 | type: trace -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/authorization-server/src/test/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AuthorizationServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/profile-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/ProfileServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "com.krishantha.rentcloud.commons.model") 10 | @EnableResourceServer 11 | public class ProfileServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ProfileServiceApplication.class, args); 15 | } 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/controller/ProfileController.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.controller; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | import com.krishantha.rentcloud.profileservice.service.CustomerService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.util.List; 9 | 10 | @RestController 11 | @RequestMapping(value = "/services") 12 | public class ProfileController { 13 | 14 | 15 | @Autowired 16 | CustomerService customerService; 17 | 18 | @RequestMapping(value = "/profile", method = RequestMethod.POST) 19 | public Customer save(@RequestBody Customer customer) { 20 | return customerService.save(customer); 21 | } 22 | 23 | @RequestMapping(value = "/profile", method = RequestMethod.GET) 24 | public Customer fetch(@RequestParam int profileId) { 25 | return customerService.fetchById(profileId); 26 | } 27 | 28 | @RequestMapping(value = "/profiles", method = RequestMethod.GET) 29 | public List fetch() { 30 | return customerService.fetchAllProfiles(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.repository; 2 | 3 | 4 | import com.krishantha.rentcloud.commons.model.Customer; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | public interface CustomerRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.service; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | 5 | import java.util.List; 6 | 7 | public interface CustomerService { 8 | 9 | 10 | Customer save(Customer customer); 11 | 12 | Customer fetchById(int profileId); 13 | 14 | List fetchAllProfiles(); 15 | } 16 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.service; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | import com.krishantha.rentcloud.profileservice.repository.CustomerRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | @Service 12 | public class CustomerServiceImpl implements CustomerService { 13 | 14 | @Autowired 15 | CustomerRepository customerRepository; 16 | 17 | @Override 18 | public Customer save(Customer customer) { 19 | return customerRepository.save(customer); 20 | } 21 | 22 | @Override 23 | public Customer fetchById(int profileId) { 24 | Optional customer = customerRepository.findById(profileId); 25 | if (customer.isPresent()) { 26 | return customer.get(); 27 | } else { 28 | return null; 29 | } 30 | } 31 | 32 | @Override 33 | public List fetchAllProfiles() { 34 | return customerRepository.findAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/profile-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentDB?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | application: 13 | name: profile 14 | security: 15 | oauth2: 16 | resource: 17 | token-info-uri: http://localhost:9191/oauth/check_token 18 | client: 19 | client-id: mobile 20 | client-secret: pin 21 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/profile-service/src/test/java/com/krishantha/rentcloud/profileservice/ProfileServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProfileServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_010-secure-microservices-with-resourceserver-and-oauth2/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/authorization-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | 7 | @SpringBootApplication 8 | @EnableAuthorizationServer 9 | public class AuthorizationServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AuthorizationServerApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Permission.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.io.Serializable; 7 | 8 | @Entity 9 | @Table(name = "permission") 10 | @Data 11 | public class Permission implements Serializable { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.AUTO) 14 | private Integer id; 15 | @Column(name = "name") 16 | private String name; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Role.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | 4 | import lombok.Data; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | @Entity 11 | @Table(name = "role") 12 | @Data 13 | public class Role implements Serializable { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.AUTO) 17 | private Integer id; 18 | @Column(name = "name") 19 | private String name; 20 | 21 | @ManyToMany(fetch = FetchType.EAGER) 22 | @JoinTable(name = "permission_role", joinColumns = { 23 | @JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = { 24 | @JoinColumn(name = "permission_id", referencedColumnName = "id")}) 25 | private List permissions; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/repository/UserDetailRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.repository; 2 | 3 | import com.krishantha.rentcloud.authorizationserver.model.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.jws.soap.SOAPBinding; 7 | import java.util.Optional; 8 | 9 | public interface UserDetailRepository extends JpaRepository { 10 | 11 | 12 | Optional findByUsername(String name); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/authorization-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9191 3 | spring: 4 | datasource: 5 | url: jdbc:mysql://localhost:3306/authDB?createDatabaseIfNotExist=true 6 | username: root 7 | password: 1qazxsw2# 8 | driver-class-name: com.mysql.jdbc.Driver 9 | initialization-mode: always 10 | jpa: 11 | hibernate: 12 | naming: 13 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 14 | properties: 15 | hibernate: 16 | show_sql: true 17 | format_sql: true 18 | logging: 19 | level: 20 | org: 21 | hibernate: 22 | type: trace -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/authorization-server/src/test/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AuthorizationServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/profile-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/ProfileServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 8 | 9 | @SpringBootApplication 10 | @EntityScan(basePackages = "com.krishantha.rentcloud.commons.model") 11 | @EnableResourceServer 12 | @EnableGlobalMethodSecurity(prePostEnabled = true) 13 | public class ProfileServiceApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ProfileServiceApplication.class, args); 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/controller/ProfileController.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.controller; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | import com.krishantha.rentcloud.profileservice.service.CustomerService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.access.prepost.PreAuthorize; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.List; 10 | 11 | @RestController 12 | @RequestMapping(value = "/services") 13 | public class ProfileController { 14 | 15 | 16 | @Autowired 17 | CustomerService customerService; 18 | 19 | @RequestMapping(value = "/profile", method = RequestMethod.POST) 20 | @PreAuthorize("hasAuthority('create_profile')") 21 | public Customer save(@RequestBody Customer customer) { 22 | return customerService.save(customer); 23 | } 24 | 25 | @RequestMapping(value = "/profile", method = RequestMethod.GET) 26 | public Customer fetch(@RequestParam int profileId) { 27 | return customerService.fetchById(profileId); 28 | } 29 | 30 | @RequestMapping(value = "/profiles", method = RequestMethod.GET) 31 | @PreAuthorize("hasRole('ROLE_operator')") 32 | public List fetch() { 33 | return customerService.fetchAllProfiles(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.repository; 2 | 3 | 4 | import com.krishantha.rentcloud.commons.model.Customer; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | public interface CustomerRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.service; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | 5 | import java.util.List; 6 | 7 | public interface CustomerService { 8 | 9 | 10 | Customer save(Customer customer); 11 | 12 | Customer fetchById(int profileId); 13 | 14 | List fetchAllProfiles(); 15 | } 16 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.service; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | import com.krishantha.rentcloud.profileservice.repository.CustomerRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | @Service 12 | public class CustomerServiceImpl implements CustomerService { 13 | 14 | @Autowired 15 | CustomerRepository customerRepository; 16 | 17 | @Override 18 | public Customer save(Customer customer) { 19 | return customerRepository.save(customer); 20 | } 21 | 22 | @Override 23 | public Customer fetchById(int profileId) { 24 | Optional customer = customerRepository.findById(profileId); 25 | if (customer.isPresent()) { 26 | return customer.get(); 27 | } else { 28 | return null; 29 | } 30 | } 31 | 32 | @Override 33 | public List fetchAllProfiles() { 34 | return customerRepository.findAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/profile-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentDB?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | application: 13 | name: profile 14 | security: 15 | oauth2: 16 | resource: 17 | token-info-uri: http://localhost:9191/oauth/check_token 18 | client: 19 | client-id: mobile 20 | client-secret: pin 21 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/profile-service/src/test/java/com/krishantha/rentcloud/profileservice/ProfileServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProfileServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/rentcloudcommons/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.krishantha.rentcloud 8 | rentcloud-commons 9 | 1.0-SNAPSHOT 10 | 11 | 12 | javax.persistence 13 | javax.persistence-api 14 | 2.2 15 | 16 | 17 | 18 | mysql 19 | mysql-connector-java 20 | 5.1.44 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/rentcloudcommons/src/main/java/com/krishantha/rentcloud/commons/model/Customer.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.commons.model; 2 | 3 | 4 | import javax.persistence.*; 5 | 6 | @Entity 7 | @Table(name = "customer") 8 | public class Customer { 9 | 10 | @Id 11 | @GeneratedValue(strategy = GenerationType.IDENTITY) 12 | int id; 13 | 14 | String firstName; 15 | String lastName; 16 | String dlNumber; 17 | String zipcode; 18 | 19 | public int getId() { 20 | return id; 21 | } 22 | 23 | public void setId(int id) { 24 | this.id = id; 25 | } 26 | 27 | public String getFirstName() { 28 | return firstName; 29 | } 30 | 31 | public void setFirstName(String firstName) { 32 | this.firstName = firstName; 33 | } 34 | 35 | public String getLastName() { 36 | return lastName; 37 | } 38 | 39 | public void setLastName(String lastName) { 40 | this.lastName = lastName; 41 | } 42 | 43 | public String getDlNumber() { 44 | return dlNumber; 45 | } 46 | 47 | public void setDlNumber(String dlNumber) { 48 | this.dlNumber = dlNumber; 49 | } 50 | 51 | public String getZipcode() { 52 | return zipcode; 53 | } 54 | 55 | public void setZipcode(String zipcode) { 56 | this.zipcode = zipcode; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /video_011-rolebased-permission-to-microservices/rentcloudcommons/src/main/java/com/krishantha/rentcloud/commons/model/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.commons.model; 2 | 3 | import javax.persistence.*; 4 | 5 | @Entity 6 | @Table(name = "vehicle") 7 | public class Vehicle { 8 | 9 | @Id 10 | @GeneratedValue(strategy = GenerationType.IDENTITY) 11 | int id; 12 | 13 | String make; 14 | String model; 15 | String type; 16 | int year; 17 | 18 | public int getId() { 19 | return id; 20 | } 21 | 22 | public void setId(int id) { 23 | this.id = id; 24 | } 25 | 26 | public String getMake() { 27 | return make; 28 | } 29 | 30 | public void setMake(String make) { 31 | this.make = make; 32 | } 33 | 34 | public String getModel() { 35 | return model; 36 | } 37 | 38 | public void setModel(String model) { 39 | this.model = model; 40 | } 41 | 42 | public String getType() { 43 | return type; 44 | } 45 | 46 | public void setType(String type) { 47 | this.type = type; 48 | } 49 | 50 | public int getYear() { 51 | return year; 52 | } 53 | 54 | public void setYear(int year) { 55 | this.year = year; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/authorization-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | 7 | @SpringBootApplication 8 | @EnableAuthorizationServer 9 | public class AuthorizationServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AuthorizationServerApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Permission.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.io.Serializable; 7 | 8 | @Entity 9 | @Table(name = "permission") 10 | @Data 11 | public class Permission implements Serializable { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.AUTO) 14 | private Integer id; 15 | @Column(name = "name") 16 | private String name; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Role.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | 4 | import lombok.Data; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | @Entity 11 | @Table(name = "role") 12 | @Data 13 | public class Role implements Serializable { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.AUTO) 17 | private Integer id; 18 | @Column(name = "name") 19 | private String name; 20 | 21 | @ManyToMany(fetch = FetchType.EAGER) 22 | @JoinTable(name = "permission_role", joinColumns = { 23 | @JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = { 24 | @JoinColumn(name = "permission_id", referencedColumnName = "id")}) 25 | private List permissions; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/repository/UserDetailRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.repository; 2 | 3 | import com.krishantha.rentcloud.authorizationserver.model.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.jws.soap.SOAPBinding; 7 | import java.util.Optional; 8 | 9 | public interface UserDetailRepository extends JpaRepository { 10 | 11 | 12 | Optional findByUsername(String name); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/authorization-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9191 3 | spring: 4 | datasource: 5 | url: jdbc:mysql://localhost:3306/authDB?createDatabaseIfNotExist=true 6 | username: root 7 | password: 1qazxsw2# 8 | driver-class-name: com.mysql.jdbc.Driver 9 | initialization-mode: always 10 | jpa: 11 | hibernate: 12 | naming: 13 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 14 | properties: 15 | hibernate: 16 | show_sql: true 17 | format_sql: true 18 | logging: 19 | level: 20 | org: 21 | hibernate: 22 | type: trace -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/authorization-server/src/test/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AuthorizationServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/rent-ui/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/rent-ui/src/main/java/lk/codelabs/rentcloud/rentui/RentUiApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentui; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RentUiApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RentUiApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/rent-ui/src/main/java/lk/codelabs/rentcloud/rentui/controller/UIController.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentui.controller; 2 | 3 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @EnableOAuth2Sso 11 | public class UIController extends WebSecurityConfigurerAdapter { 12 | 13 | 14 | @Override 15 | protected void configure(HttpSecurity http) throws Exception { 16 | 17 | http.authorizeRequests() 18 | .antMatchers("/") 19 | .permitAll() 20 | .anyRequest() 21 | .authenticated(); 22 | 23 | 24 | 25 | } 26 | 27 | @RequestMapping(value = "/") 28 | public String loadUI(){ 29 | return "home"; 30 | } 31 | @RequestMapping(value = "/secure") 32 | public String loadSecuredUI(){ 33 | return "secure"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/rent-ui/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | security: 3 | oauth2: 4 | client: 5 | client-id: mobile 6 | client-secret: pin 7 | user-authorization-uri: http://localhost:9191/oauth/authorize 8 | access-token-uri: http://localhost:9191/oauth/token 9 | resource: 10 | token-info-uri: http://localhost:9191/oauth/check_token 11 | server: 12 | servlet: 13 | session: 14 | cookie: 15 | name: KSESSION 16 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/rent-ui/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Hello, world! 12 | 13 | 14 | 15 |
16 | 17 |
18 |

Welcome to Rent Cloud (public)

19 |
20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/rent-ui/src/main/resources/templates/secure.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Hello, world! 12 | 13 | 14 | 15 |
16 | 17 |
18 |

secured page

19 |
20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /video_012-springboot-springsecurity-oauthcode-flow/rent-ui/src/test/java/lk/codelabs/rentcloud/rentui/RentUiApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentui; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RentUiApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/authorization-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | 7 | @SpringBootApplication 8 | @EnableAuthorizationServer 9 | public class AuthorizationServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AuthorizationServerApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Permission.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.io.Serializable; 7 | 8 | @Entity 9 | @Table(name = "permission") 10 | @Data 11 | public class Permission implements Serializable { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.AUTO) 14 | private Integer id; 15 | @Column(name = "name") 16 | private String name; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/model/Role.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.model; 2 | 3 | 4 | import lombok.Data; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | @Entity 11 | @Table(name = "role") 12 | @Data 13 | public class Role implements Serializable { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.AUTO) 17 | private Integer id; 18 | @Column(name = "name") 19 | private String name; 20 | 21 | @ManyToMany(fetch = FetchType.EAGER) 22 | @JoinTable(name = "permission_role", joinColumns = { 23 | @JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = { 24 | @JoinColumn(name = "permission_id", referencedColumnName = "id")}) 25 | private List permissions; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/authorization-server/src/main/java/com/krishantha/rentcloud/authorizationserver/repository/UserDetailRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver.repository; 2 | 3 | import com.krishantha.rentcloud.authorizationserver.model.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.jws.soap.SOAPBinding; 7 | import java.util.Optional; 8 | 9 | public interface UserDetailRepository extends JpaRepository { 10 | 11 | 12 | Optional findByUsername(String name); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/authorization-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9191 3 | spring: 4 | datasource: 5 | url: jdbc:mysql://localhost:3306/authDB?createDatabaseIfNotExist=true 6 | username: root 7 | password: 1qazxsw2# 8 | driver-class-name: com.mysql.jdbc.Driver 9 | initialization-mode: always 10 | jpa: 11 | hibernate: 12 | naming: 13 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 14 | properties: 15 | hibernate: 16 | show_sql: true 17 | format_sql: true 18 | logging: 19 | level: 20 | org: 21 | hibernate: 22 | type: trace -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/authorization-server/src/test/java/com/krishantha/rentcloud/authorizationserver/AuthorizationServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.authorizationserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AuthorizationServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/profile-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/ProfileServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 8 | 9 | @SpringBootApplication 10 | @EntityScan(basePackages = "com.krishantha.rentcloud.commons.model") 11 | @EnableResourceServer 12 | @EnableGlobalMethodSecurity(prePostEnabled = true) 13 | public class ProfileServiceApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ProfileServiceApplication.class, args); 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/controller/ProfileController.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.controller; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | import com.krishantha.rentcloud.profileservice.service.CustomerService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.access.prepost.PreAuthorize; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.List; 10 | 11 | @RestController 12 | @RequestMapping(value = "/services") 13 | public class ProfileController { 14 | 15 | 16 | @Autowired 17 | CustomerService customerService; 18 | 19 | @RequestMapping(value = "/customers", method = RequestMethod.POST) 20 | @PreAuthorize("hasAuthority('create_profile')") 21 | public Customer save(@RequestBody Customer customer) { 22 | return customerService.save(customer); 23 | } 24 | 25 | @RequestMapping(value = "/customers/{id}", method = RequestMethod.GET) 26 | public Customer fetch(@PathVariable(value = "id") int customerid) { 27 | return customerService.fetchById(customerid); 28 | } 29 | 30 | @RequestMapping(value = "/customers", method = RequestMethod.GET) 31 | @PreAuthorize("hasRole('ROLE_admin')") 32 | public List fetch() { 33 | return customerService.fetchAllProfiles(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.repository; 2 | 3 | 4 | import com.krishantha.rentcloud.commons.model.Customer; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | public interface CustomerRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.service; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | 5 | import java.util.List; 6 | 7 | public interface CustomerService { 8 | 9 | 10 | Customer save(Customer customer); 11 | 12 | Customer fetchById(int profileId); 13 | 14 | List fetchAllProfiles(); 15 | } 16 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/profile-service/src/main/java/com/krishantha/rentcloud/profileservice/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice.service; 2 | 3 | import com.krishantha.rentcloud.commons.model.Customer; 4 | import com.krishantha.rentcloud.profileservice.repository.CustomerRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | @Service 12 | public class CustomerServiceImpl implements CustomerService { 13 | 14 | @Autowired 15 | CustomerRepository customerRepository; 16 | 17 | @Override 18 | public Customer save(Customer customer) { 19 | return customerRepository.save(customer); 20 | } 21 | 22 | @Override 23 | public Customer fetchById(int profileId) { 24 | Optional customer = customerRepository.findById(profileId); 25 | if (customer.isPresent()) { 26 | return customer.get(); 27 | } else { 28 | return null; 29 | } 30 | } 31 | 32 | @Override 33 | public List fetchAllProfiles() { 34 | return customerRepository.findAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/profile-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentDB?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | application: 13 | name: profile 14 | security: 15 | oauth2: 16 | resource: 17 | token-info-uri: http://localhost:9191/oauth/check_token 18 | client: 19 | client-id: mobile 20 | client-secret: pin 21 | server: 22 | port: 8181 23 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/profile-service/src/test/java/com/krishantha/rentcloud/profileservice/ProfileServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.krishantha.rentcloud.profileservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProfileServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/rent-ui/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/rent-ui/src/main/java/lk/codelabs/rentcloud/rentui/RentUiApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentui; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RentUiApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RentUiApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/rent-ui/src/main/java/lk/codelabs/rentcloud/rentui/config/AccessToken.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentui.config; 2 | 3 | import org.springframework.security.core.context.SecurityContextHolder; 4 | import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; 5 | 6 | public class AccessToken { 7 | 8 | 9 | 10 | public static String getAccessToken(){ 11 | 12 | OAuth2AuthenticationDetails authenticationDetails=(OAuth2AuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails(); 13 | return authenticationDetails.getTokenType().concat(" ").concat(authenticationDetails.getTokenValue()); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/rent-ui/src/main/java/lk/codelabs/rentcloud/rentui/config/RestTemplateConfiguration.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentui.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | @Configuration 8 | public class RestTemplateConfiguration { 9 | 10 | @Bean 11 | RestTemplate getRestTemplate() { 12 | return new RestTemplate(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/rent-ui/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | security: 3 | oauth2: 4 | client: 5 | client-id: mobile 6 | client-secret: pin 7 | user-authorization-uri: http://localhost:9191/oauth/authorize 8 | access-token-uri: http://localhost:9191/oauth/token 9 | resource: 10 | token-info-uri: http://localhost:9191/oauth/check_token 11 | server: 12 | servlet: 13 | session: 14 | cookie: 15 | name: KSESSION 16 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/rent-ui/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Hello, world! 12 | 13 | 14 | 15 |
16 | 17 |
18 |

Welcome to Rent Cloud (public)

19 |
20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /video_013-sso-remote-service-call-and-error-handling/rent-ui/src/test/java/lk/codelabs/rentcloud/rentui/RentUiApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentui; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RentUiApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_014-Async-services-with-spring-task/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_014-Async-services-with-spring-task/rent-process-task/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_014-Async-services-with-spring-task/rent-process-task/src/main/java/lk/codelabs/rentcloud/rentprocesstask/RentProcessTaskApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentprocesstask; 2 | 3 | import lk.codelabs.rentcloud.rentprocesstask.service.RentProcessTaskRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.task.configuration.EnableTask; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | @SpringBootApplication 10 | @EnableTask 11 | public class RentProcessTaskApplication { 12 | 13 | @Bean 14 | RentProcessTaskRunner getRentProcessTaskRunner() { 15 | return new RentProcessTaskRunner(); 16 | } 17 | 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(RentProcessTaskApplication.class, args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /video_014-Async-services-with-spring-task/rent-process-task/src/main/java/lk/codelabs/rentcloud/rentprocesstask/service/RentProcessService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentprocesstask.service; 2 | 3 | /** 4 | * @author Krishantha Dinesh 5 | * krishantha@krishantha.com 6 | * www.krishantha.com 7 | * twitter @krishantha 8 | * on 17-October-2019 01:24 9 | * @Project rent-process-task 10 | */ 11 | public interface RentProcessService { 12 | boolean validateDL(String dlNumber); 13 | } 14 | -------------------------------------------------------------------------------- /video_014-Async-services-with-spring-task/rent-process-task/src/main/java/lk/codelabs/rentcloud/rentprocesstask/service/RentProcessServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentprocesstask.service; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 17-October-2019 01:22 12 | * @Project rent-process-task 13 | */ 14 | @Service 15 | public class RentProcessServiceImpl implements RentProcessService { 16 | 17 | 18 | 19 | @Override 20 | public boolean validateDL(String dlNumber) { 21 | return dlNumber.length() > 5; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /video_014-Async-services-with-spring-task/rent-process-task/src/main/java/lk/codelabs/rentcloud/rentprocesstask/service/RentProcessTaskRunner.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentprocesstask.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.CommandLineRunner; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 17-October-2019 01:23 12 | * @Project rent-process-task 13 | */ 14 | 15 | public class RentProcessTaskRunner implements CommandLineRunner { 16 | 17 | @Autowired 18 | RentProcessService rentProcessService; 19 | 20 | @Override 21 | public void run(String... args) throws Exception { 22 | 23 | if(args.length>0) { 24 | System.out.println("task running with arguments"); 25 | 26 | if (rentProcessService.validateDL(args[0])) { 27 | System.out.println("valid driving license"); 28 | } else 29 | System.out.println("invalid driving license"); 30 | }else 31 | System.out.println("task running without arguments"); 32 | 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /video_014-Async-services-with-spring-task/rent-process-task/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/taskdb?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | application: 8 | name: task 9 | -------------------------------------------------------------------------------- /video_014-Async-services-with-spring-task/rent-process-task/src/test/java/lk/codelabs/rentcloud/rentprocesstask/RentProcessTaskApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentprocesstask; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RentProcessTaskApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_015-service-chaining/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_015-service-chaining/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | 7 | @SpringBootApplication 8 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.customer") 9 | public class CustomerServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(CustomerServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_015-service-chaining/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/controller/CustomerServiceController.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.controller; 2 | 3 | import lk.codelabs.rentcloud.customerservice.service.CustomerService; 4 | import lk.codelabs.rentcloud.model.customer.Customer; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 04:09 17 | * @Project rentcloudmodel 18 | */ 19 | 20 | @RestController 21 | @RequestMapping("/services/customers") 22 | public class CustomerServiceController { 23 | 24 | 25 | @Autowired 26 | CustomerService customerService; 27 | 28 | @PostMapping 29 | public Customer save(@RequestBody Customer customer) { 30 | return customerService.save(customer); 31 | } 32 | 33 | @GetMapping(value = "/{id}") 34 | public Customer getCustomer(@PathVariable int id) { 35 | 36 | System.out.println("request came on "+LocalDateTime.now() + " ++++++++++++++++++++++"); 37 | return customerService.findById(id); 38 | } 39 | 40 | @GetMapping 41 | public List getAllCustomers() { 42 | return customerService.findAll(); 43 | } 44 | 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /video_015-service-chaining/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 15-October-2019 04:17 12 | * @Project rentcloudmodel 13 | */ 14 | public interface CustomerRepository extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /video_015-service-chaining/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 15-October-2019 04:28 13 | * @Project rentcloudmodel 14 | */ 15 | public interface CustomerService { 16 | Customer save(Customer customer); 17 | 18 | Customer findById(int id); 19 | 20 | List findAll(); 21 | } 22 | -------------------------------------------------------------------------------- /video_015-service-chaining/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.service; 2 | 3 | import lk.codelabs.rentcloud.customerservice.repository.CustomerRepository; 4 | import lk.codelabs.rentcloud.model.customer.Customer; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 04:15 17 | * @Project rentcloudmodel 18 | */ 19 | @Service 20 | public class CustomerServiceImpl implements CustomerService { 21 | 22 | @Autowired 23 | CustomerRepository customerRepository; 24 | 25 | @Override 26 | public Customer save(Customer customer) { 27 | return customerRepository.save(customer); 28 | } 29 | 30 | @Override 31 | public Customer findById(int id) { 32 | Optional customer = customerRepository.findById(id); 33 | 34 | if (customer.isPresent()) 35 | return customer.get(); 36 | else 37 | return new Customer(); 38 | 39 | } 40 | 41 | @Override 42 | public List findAll() { 43 | return customerRepository.findAll(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /video_015-service-chaining/customer-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentcloud_customer?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | # properties: 13 | # hibernate: 14 | # dialect: org.hibernate.dialect.MySQL55Dialect 15 | application: 16 | name: customer -------------------------------------------------------------------------------- /video_015-service-chaining/customer-service/src/test/java/lk/codelabs/rentcloud/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_015-service-chaining/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/RentServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | 7 | @SpringBootApplication 8 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.rent") 9 | public class RentServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(RentServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/DetailResponse.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | import lk.codelabs.rentcloud.model.rent.Rent; 5 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 22-October-2019 23:24 13 | * @Project rent-service 14 | */ 15 | public class DetailResponse implements Response { 16 | 17 | Rent rent; 18 | Customer customer; 19 | Vehicle vehicle; 20 | 21 | public DetailResponse(Rent rent, Customer customer, Vehicle vehicle) { 22 | this.rent = rent; 23 | this.customer = customer; 24 | this.vehicle = vehicle; 25 | } 26 | 27 | public Rent getRent() { 28 | return rent; 29 | } 30 | 31 | public void setRent(Rent rent) { 32 | this.rent = rent; 33 | } 34 | 35 | public Customer getCustomer() { 36 | return customer; 37 | } 38 | 39 | public void setCustomer(Customer customer) { 40 | this.customer = customer; 41 | } 42 | 43 | public Vehicle getVehicle() { 44 | return vehicle; 45 | } 46 | 47 | public void setVehicle(Vehicle vehicle) { 48 | this.vehicle = vehicle; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/Response.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | /** 4 | * @author Krishantha Dinesh 5 | * krishantha@krishantha.com 6 | * www.krishantha.com 7 | * twitter @krishantha 8 | * on 22-October-2019 23:24 9 | * @Project rent-service 10 | */ 11 | public interface Response { 12 | } 13 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/SimpleResponse.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | 5 | /** 6 | * @author Krishantha Dinesh 7 | * krishantha@krishantha.com 8 | * www.krishantha.com 9 | * twitter @krishantha 10 | * on 22-October-2019 23:25 11 | * @Project rent-service 12 | */ 13 | public class SimpleResponse implements Response { 14 | 15 | Rent rent; 16 | 17 | 18 | public SimpleResponse(Rent rent) { 19 | this.rent = rent; 20 | } 21 | 22 | public Rent getRent() { 23 | return rent; 24 | } 25 | 26 | public void setRent(Rent rent) { 27 | this.rent = rent; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/repository/RentRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.persistence.criteria.CriteriaBuilder; 7 | 8 | /** 9 | * @author Krishantha Dinesh 10 | * krishantha@krishantha.com 11 | * www.krishantha.com 12 | * twitter @krishantha 13 | * on 15-October-2019 06:32 14 | * @Project rentcloudmodel 15 | */ 16 | public interface RentRepository extends JpaRepository { 17 | } 18 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/service/RentService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | import lk.codelabs.rentcloud.rentservice.model.DetailResponse; 5 | import lk.codelabs.rentcloud.rentservice.model.Response; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author Krishantha Dinesh 11 | * krishantha@krishantha.com 12 | * www.krishantha.com 13 | * twitter @krishantha 14 | * on 15-October-2019 06:34 15 | * @Project rentcloudmodel 16 | */ 17 | public interface RentService { 18 | Rent save(Rent customer); 19 | 20 | Rent findById(int id); 21 | 22 | List findAll(); 23 | 24 | DetailResponse findDetailResponse(int id); 25 | } 26 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | datasource: 4 | url: jdbc:mysql://localhost:3306/rentcloud_rent?createDatabaseIfNotExist=true 5 | username: root 6 | password: 1qazxsw2# 7 | driver-class-name: com.mysql.jdbc.Driver 8 | jpa: 9 | hibernate: 10 | naming: 11 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 12 | ddl-auto: none 13 | application: 14 | name: rent 15 | server: 16 | port: 8181 17 | -------------------------------------------------------------------------------- /video_015-service-chaining/rent-service/src/test/java/lk/codelabs/rentcloud/rentservice/RentServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RentServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_015-service-chaining/rentcloud-model/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | lk.codelabs.rentcloud 8 | rentcloud-model 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | javax.persistence 14 | javax.persistence-api 15 | 2.2 16 | 17 | 18 | 19 | mysql 20 | mysql-connector-java 21 | 5.1.44 22 | 23 | 24 | 25 | org.projectlombok 26 | lombok 27 | 1.18.10 28 | provided 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /video_015-service-chaining/rentcloud-model/src/main/java/lk/codelabs/rentcloud/model/customer/Customer.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.model.customer; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.util.List; 7 | 8 | 9 | /** 10 | * @author Krishantha Dinesh 11 | * krishantha@krishantha.com 12 | * www.krishantha.com 13 | * twitter @krishantha 14 | * on 14-October-2019 16:24 15 | * @Project rentcloudmodel 16 | */ 17 | 18 | 19 | @Entity 20 | @Table(name = "customer") 21 | @Data 22 | public class Customer { 23 | 24 | @Id 25 | @GeneratedValue(strategy = GenerationType.IDENTITY) 26 | int id; 27 | 28 | private String firstName; 29 | private String lastName; 30 | private String dlNumber; 31 | private String zipcode; 32 | @OneToMany(mappedBy = "customer") 33 | private List loyalities; 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /video_015-service-chaining/rentcloud-model/src/main/java/lk/codelabs/rentcloud/model/customer/Loyality.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.model.customer; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.time.LocalDateTime; 7 | 8 | /** 9 | * @author Krishantha Dinesh 10 | * krishantha@krishantha.com 11 | * www.krishantha.com 12 | * twitter @krishantha 13 | * on 14-October-2019 16:41 14 | * @Project rentcloudmodel 15 | */ 16 | 17 | @Entity 18 | @Table(name = "loyalityPoint") 19 | @Data 20 | public class Loyality { 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | int transactionId; 24 | @ManyToOne 25 | @JoinColumn 26 | Customer customer; 27 | int point; 28 | LocalDateTime expireDate; 29 | } 30 | -------------------------------------------------------------------------------- /video_015-service-chaining/rentcloud-model/src/main/java/lk/codelabs/rentcloud/model/rent/Rent.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.model.rent; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.time.LocalDateTime; 7 | 8 | /** 9 | * @author Krishantha Dinesh 10 | * krishantha@krishantha.com 11 | * www.krishantha.com 12 | * twitter @krishantha 13 | * on 15-October-2019 04:00 14 | * @Project rentcloudmodel 15 | */ 16 | @Entity 17 | @Table(name = "rent") 18 | @Data 19 | public class Rent { 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | int rentId; 23 | int customerId; 24 | int vehicleId; 25 | LocalDateTime rentFrom; 26 | LocalDateTime rentTill; 27 | int currentOdometer; 28 | String returnLocation; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /video_015-service-chaining/rentcloud-model/src/main/java/lk/codelabs/rentcloud/model/vehicle/Vehicle.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.model.vehicle; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.util.List; 7 | 8 | /** 9 | * @author Krishantha Dinesh 10 | * krishantha@krishantha.com 11 | * www.krishantha.com 12 | * twitter @krishantha 13 | * on 14-October-2019 16:32 14 | * @Project rentcloudmodel 15 | */ 16 | 17 | @Entity 18 | @Table(name="vehicle") 19 | @Data 20 | public class Vehicle { 21 | 22 | @Id 23 | @GeneratedValue(strategy = GenerationType.IDENTITY) 24 | int id; 25 | 26 | String make; 27 | String model; 28 | String type; 29 | int year; 30 | int odometerValueOnRegister; 31 | String color; 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /video_015-service-chaining/vehicle-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_015-service-chaining/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/VehicleServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | 7 | @SpringBootApplication 8 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.vehicle") 9 | public class VehicleServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(VehicleServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_015-service-chaining/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/controller/VehicleController.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.controller; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import lk.codelabs.rentcloud.vehicleservice.service.VehicleService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 06:10 17 | * @Project rentcloudmodel 18 | */ 19 | 20 | @RestController 21 | @RequestMapping("/services/vehicles") 22 | public class VehicleController { 23 | 24 | @Autowired 25 | VehicleService vehicleService; 26 | 27 | @PostMapping 28 | public Vehicle save(@RequestBody Vehicle vehicle) { 29 | return vehicleService.save(vehicle); 30 | } 31 | 32 | @GetMapping(value = "/{id}") 33 | public Vehicle getVehicle(@PathVariable int id) 34 | { 35 | System.out.println("request came on "+LocalDateTime.now() + " ++++++++++++++++++++++"); 36 | return vehicleService.findById(id); 37 | } 38 | 39 | @GetMapping 40 | public List getAllVehicles() { 41 | return vehicleService.findAll(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /video_015-service-chaining/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/repository/VehicleRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 15-October-2019 06:08 12 | * @Project rentcloudmodel 13 | */ 14 | public interface VehicleRepository extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /video_015-service-chaining/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/service/VehicleService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 15-October-2019 06:10 13 | * @Project rentcloudmodel 14 | */ 15 | public interface VehicleService { 16 | Vehicle save(Vehicle customer); 17 | 18 | Vehicle findById(int id); 19 | 20 | List findAll(); 21 | } 22 | -------------------------------------------------------------------------------- /video_015-service-chaining/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/service/VehicleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import lk.codelabs.rentcloud.vehicleservice.repository.VehicleRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 06:08 17 | * @Project rentcloudmodel 18 | */ 19 | @Service 20 | public class VehicleServiceImpl implements VehicleService { 21 | @Autowired 22 | VehicleRepository vehicleRepository; 23 | 24 | 25 | @Override 26 | public Vehicle save(Vehicle customer) { 27 | return vehicleRepository.save(customer); 28 | } 29 | 30 | 31 | @Override 32 | public Vehicle findById(int id) { 33 | Optional vehicle = vehicleRepository.findById(id); 34 | 35 | if (vehicle.isPresent()) 36 | return vehicle.get(); 37 | else 38 | return new Vehicle(); 39 | 40 | } 41 | 42 | 43 | @Override 44 | public List findAll() { 45 | return vehicleRepository.findAll(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /video_015-service-chaining/vehicle-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentcloud_vehicle?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | application: 13 | name: vehicle 14 | server: 15 | port: 9191 -------------------------------------------------------------------------------- /video_015-service-chaining/vehicle-service/src/test/java/lk/codelabs/rentcloud/vehicleservice/VehicleServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class VehicleServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.customer") 10 | @EnableEurekaClient 11 | public class CustomerServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(CustomerServiceApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/controller/CustomerServiceController.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.controller; 2 | 3 | import lk.codelabs.rentcloud.customerservice.service.CustomerService; 4 | import lk.codelabs.rentcloud.model.customer.Customer; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 04:09 17 | * @Project rentcloudmodel 18 | */ 19 | 20 | @RestController 21 | @RequestMapping("/services/customers") 22 | public class CustomerServiceController { 23 | 24 | 25 | @Autowired 26 | CustomerService customerService; 27 | 28 | @PostMapping 29 | public Customer save(@RequestBody Customer customer) { 30 | return customerService.save(customer); 31 | } 32 | 33 | @GetMapping(value = "/{id}") 34 | public Customer getCustomer(@PathVariable int id) { 35 | 36 | System.out.println("request came on "+LocalDateTime.now() + " ++++++++++++++++++++++"); 37 | return customerService.findById(id); 38 | } 39 | 40 | @GetMapping 41 | public List getAllCustomers() { 42 | return customerService.findAll(); 43 | } 44 | 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 15-October-2019 04:17 12 | * @Project rentcloudmodel 13 | */ 14 | public interface CustomerRepository extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 15-October-2019 04:28 13 | * @Project rentcloudmodel 14 | */ 15 | public interface CustomerService { 16 | Customer save(Customer customer); 17 | 18 | Customer findById(int id); 19 | 20 | List findAll(); 21 | } 22 | -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.service; 2 | 3 | import lk.codelabs.rentcloud.customerservice.repository.CustomerRepository; 4 | import lk.codelabs.rentcloud.model.customer.Customer; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 04:15 17 | * @Project rentcloudmodel 18 | */ 19 | @Service 20 | public class CustomerServiceImpl implements CustomerService { 21 | 22 | @Autowired 23 | CustomerRepository customerRepository; 24 | 25 | @Override 26 | public Customer save(Customer customer) { 27 | return customerRepository.save(customer); 28 | } 29 | 30 | @Override 31 | public Customer findById(int id) { 32 | Optional customer = customerRepository.findById(id); 33 | 34 | if (customer.isPresent()) 35 | return customer.get(); 36 | else 37 | return new Customer(); 38 | 39 | } 40 | 41 | @Override 42 | public List findAll() { 43 | return customerRepository.findAll(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentcloud_customer?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | # properties: 13 | # hibernate: 14 | # dialect: org.hibernate.dialect.MySQL55Dialect 15 | -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: customer 4 | server: 5 | port: 0 6 | eureka: 7 | client: 8 | register-with-eureka: true 9 | fetch-registry: true 10 | instance: 11 | instance-id: ${spring.application.name}-${random.int} 12 | hostname: localhost -------------------------------------------------------------------------------- /video_016-service-discovery/customer-service/src/test/java/lk/codelabs/rentcloud/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_016-service-discovery/discovery-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_016-service-discovery/discovery-service/src/main/java/lk/codelabs/rentcloud/discoveryservice/DiscoveryServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.discoveryservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class DiscoveryServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DiscoveryServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_016-service-discovery/discovery-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | client: 4 | register-with-eureka: false 5 | fetch-registry: false 6 | datacenter: Colombo-SriLanka 7 | environment: production 8 | server: 9 | port: 8761 -------------------------------------------------------------------------------- /video_016-service-discovery/discovery-service/src/test/java/lk/codelabs/rentcloud/discoveryservice/DiscoveryServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.discoveryservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DiscoveryServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_016-service-discovery/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/RentServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | 7 | @SpringBootApplication 8 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.rent") 9 | public class RentServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(RentServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/DetailResponse.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | import lk.codelabs.rentcloud.model.rent.Rent; 5 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 22-October-2019 23:24 13 | * @Project rent-service 14 | */ 15 | public class DetailResponse implements Response { 16 | 17 | Rent rent; 18 | Customer customer; 19 | Vehicle vehicle; 20 | 21 | public DetailResponse(Rent rent, Customer customer, Vehicle vehicle) { 22 | this.rent = rent; 23 | this.customer = customer; 24 | this.vehicle = vehicle; 25 | } 26 | 27 | public Rent getRent() { 28 | return rent; 29 | } 30 | 31 | public void setRent(Rent rent) { 32 | this.rent = rent; 33 | } 34 | 35 | public Customer getCustomer() { 36 | return customer; 37 | } 38 | 39 | public void setCustomer(Customer customer) { 40 | this.customer = customer; 41 | } 42 | 43 | public Vehicle getVehicle() { 44 | return vehicle; 45 | } 46 | 47 | public void setVehicle(Vehicle vehicle) { 48 | this.vehicle = vehicle; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/Response.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | /** 4 | * @author Krishantha Dinesh 5 | * krishantha@krishantha.com 6 | * www.krishantha.com 7 | * twitter @krishantha 8 | * on 22-October-2019 23:24 9 | * @Project rent-service 10 | */ 11 | public interface Response { 12 | } 13 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/SimpleResponse.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | 5 | /** 6 | * @author Krishantha Dinesh 7 | * krishantha@krishantha.com 8 | * www.krishantha.com 9 | * twitter @krishantha 10 | * on 22-October-2019 23:25 11 | * @Project rent-service 12 | */ 13 | public class SimpleResponse implements Response { 14 | 15 | Rent rent; 16 | 17 | 18 | public SimpleResponse(Rent rent) { 19 | this.rent = rent; 20 | } 21 | 22 | public Rent getRent() { 23 | return rent; 24 | } 25 | 26 | public void setRent(Rent rent) { 27 | this.rent = rent; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/repository/RentRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.persistence.criteria.CriteriaBuilder; 7 | 8 | /** 9 | * @author Krishantha Dinesh 10 | * krishantha@krishantha.com 11 | * www.krishantha.com 12 | * twitter @krishantha 13 | * on 15-October-2019 06:32 14 | * @Project rentcloudmodel 15 | */ 16 | public interface RentRepository extends JpaRepository { 17 | } 18 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/service/RentService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | import lk.codelabs.rentcloud.rentservice.model.DetailResponse; 5 | import lk.codelabs.rentcloud.rentservice.model.Response; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author Krishantha Dinesh 11 | * krishantha@krishantha.com 12 | * www.krishantha.com 13 | * twitter @krishantha 14 | * on 15-October-2019 06:34 15 | * @Project rentcloudmodel 16 | */ 17 | public interface RentService { 18 | Rent save(Rent customer); 19 | 20 | Rent findById(int id); 21 | 22 | List findAll(); 23 | 24 | DetailResponse findDetailResponse(int id); 25 | } 26 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | datasource: 4 | url: jdbc:mysql://localhost:3306/rentcloud_rent?createDatabaseIfNotExist=true 5 | username: root 6 | password: 1qazxsw2# 7 | driver-class-name: com.mysql.jdbc.Driver 8 | jpa: 9 | hibernate: 10 | naming: 11 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 12 | ddl-auto: none 13 | application: 14 | name: rent 15 | server: 16 | port: 8181 17 | -------------------------------------------------------------------------------- /video_016-service-discovery/rent-service/src/test/java/lk/codelabs/rentcloud/rentservice/RentServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RentServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_016-service-discovery/vehicle-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_016-service-discovery/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/VehicleServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | 7 | @SpringBootApplication 8 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.vehicle") 9 | public class VehicleServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(VehicleServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_016-service-discovery/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/controller/VehicleController.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.controller; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import lk.codelabs.rentcloud.vehicleservice.service.VehicleService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 06:10 17 | * @Project rentcloudmodel 18 | */ 19 | 20 | @RestController 21 | @RequestMapping("/services/vehicles") 22 | public class VehicleController { 23 | 24 | @Autowired 25 | VehicleService vehicleService; 26 | 27 | @PostMapping 28 | public Vehicle save(@RequestBody Vehicle vehicle) { 29 | return vehicleService.save(vehicle); 30 | } 31 | 32 | @GetMapping(value = "/{id}") 33 | public Vehicle getVehicle(@PathVariable int id) 34 | { 35 | System.out.println("request came on "+LocalDateTime.now() + " ++++++++++++++++++++++"); 36 | return vehicleService.findById(id); 37 | } 38 | 39 | @GetMapping 40 | public List getAllVehicles() { 41 | return vehicleService.findAll(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /video_016-service-discovery/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/repository/VehicleRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 15-October-2019 06:08 12 | * @Project rentcloudmodel 13 | */ 14 | public interface VehicleRepository extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /video_016-service-discovery/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/service/VehicleService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 15-October-2019 06:10 13 | * @Project rentcloudmodel 14 | */ 15 | public interface VehicleService { 16 | Vehicle save(Vehicle customer); 17 | 18 | Vehicle findById(int id); 19 | 20 | List findAll(); 21 | } 22 | -------------------------------------------------------------------------------- /video_016-service-discovery/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/service/VehicleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import lk.codelabs.rentcloud.vehicleservice.repository.VehicleRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 06:08 17 | * @Project rentcloudmodel 18 | */ 19 | @Service 20 | public class VehicleServiceImpl implements VehicleService { 21 | @Autowired 22 | VehicleRepository vehicleRepository; 23 | 24 | 25 | @Override 26 | public Vehicle save(Vehicle customer) { 27 | return vehicleRepository.save(customer); 28 | } 29 | 30 | 31 | @Override 32 | public Vehicle findById(int id) { 33 | Optional vehicle = vehicleRepository.findById(id); 34 | 35 | if (vehicle.isPresent()) 36 | return vehicle.get(); 37 | else 38 | return new Vehicle(); 39 | 40 | } 41 | 42 | 43 | @Override 44 | public List findAll() { 45 | return vehicleRepository.findAll(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /video_016-service-discovery/vehicle-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentcloud_vehicle?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | application: 13 | name: vehicle 14 | server: 15 | port: 9191 -------------------------------------------------------------------------------- /video_016-service-discovery/vehicle-service/src/test/java/lk/codelabs/rentcloud/vehicleservice/VehicleServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class VehicleServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.customer") 10 | @EnableEurekaClient 11 | public class CustomerServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(CustomerServiceApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 15-October-2019 04:17 12 | * @Project rentcloudmodel 13 | */ 14 | public interface CustomerRepository extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 15-October-2019 04:28 13 | * @Project rentcloudmodel 14 | */ 15 | public interface CustomerService { 16 | Customer save(Customer customer); 17 | 18 | Customer findById(int id); 19 | 20 | List findAll(); 21 | } 22 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.service; 2 | 3 | import lk.codelabs.rentcloud.customerservice.repository.CustomerRepository; 4 | import lk.codelabs.rentcloud.model.customer.Customer; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 04:15 17 | * @Project rentcloudmodel 18 | */ 19 | @Service 20 | public class CustomerServiceImpl implements CustomerService { 21 | 22 | @Autowired 23 | CustomerRepository customerRepository; 24 | 25 | @Override 26 | public Customer save(Customer customer) { 27 | return customerRepository.save(customer); 28 | } 29 | 30 | @Override 31 | public Customer findById(int id) { 32 | Optional customer = customerRepository.findById(id); 33 | 34 | if (customer.isPresent()) 35 | return customer.get(); 36 | else 37 | return new Customer(); 38 | 39 | } 40 | 41 | @Override 42 | public List findAll() { 43 | return customerRepository.findAll(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/customer-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentcloud_customer?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | # properties: 13 | # hibernate: 14 | # dialect: org.hibernate.dialect.MySQL55Dialect 15 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/customer-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: customer 4 | server: 5 | port: 0 6 | eureka: 7 | client: 8 | register-with-eureka: true 9 | fetch-registry: true 10 | instance: 11 | instance-id: ${spring.application.name}-${random.int} 12 | hostname: localhost -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/customer-service/src/test/java/lk/codelabs/rentcloud/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/discovery-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/discovery-service/src/main/java/lk/codelabs/rentcloud/discoveryservice/DiscoveryServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.discoveryservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class DiscoveryServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DiscoveryServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/discovery-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | client: 4 | register-with-eureka: false 5 | fetch-registry: false 6 | datacenter: Colombo-SriLanka 7 | environment: production 8 | server: 9 | port: 8761 -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/discovery-service/src/test/java/lk/codelabs/rentcloud/discoveryservice/DiscoveryServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.discoveryservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DiscoveryServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/RentServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.rent") 10 | @EnableEurekaClient 11 | public class RentServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(RentServiceApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/DetailResponse.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | import lk.codelabs.rentcloud.model.rent.Rent; 5 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 22-October-2019 23:24 13 | * @Project rent-service 14 | */ 15 | public class DetailResponse implements Response { 16 | 17 | Rent rent; 18 | Customer customer; 19 | Vehicle vehicle; 20 | 21 | public DetailResponse(Rent rent, Customer customer, Vehicle vehicle) { 22 | this.rent = rent; 23 | this.customer = customer; 24 | this.vehicle = vehicle; 25 | } 26 | 27 | public Rent getRent() { 28 | return rent; 29 | } 30 | 31 | public void setRent(Rent rent) { 32 | this.rent = rent; 33 | } 34 | 35 | public Customer getCustomer() { 36 | return customer; 37 | } 38 | 39 | public void setCustomer(Customer customer) { 40 | this.customer = customer; 41 | } 42 | 43 | public Vehicle getVehicle() { 44 | return vehicle; 45 | } 46 | 47 | public void setVehicle(Vehicle vehicle) { 48 | this.vehicle = vehicle; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/Response.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | /** 4 | * @author Krishantha Dinesh 5 | * krishantha@krishantha.com 6 | * www.krishantha.com 7 | * twitter @krishantha 8 | * on 22-October-2019 23:24 9 | * @Project rent-service 10 | */ 11 | public interface Response { 12 | } 13 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/SimpleResponse.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | 5 | /** 6 | * @author Krishantha Dinesh 7 | * krishantha@krishantha.com 8 | * www.krishantha.com 9 | * twitter @krishantha 10 | * on 22-October-2019 23:25 11 | * @Project rent-service 12 | */ 13 | public class SimpleResponse implements Response { 14 | 15 | Rent rent; 16 | 17 | 18 | public SimpleResponse(Rent rent) { 19 | this.rent = rent; 20 | } 21 | 22 | public Rent getRent() { 23 | return rent; 24 | } 25 | 26 | public void setRent(Rent rent) { 27 | this.rent = rent; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/repository/RentRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.persistence.criteria.CriteriaBuilder; 7 | 8 | /** 9 | * @author Krishantha Dinesh 10 | * krishantha@krishantha.com 11 | * www.krishantha.com 12 | * twitter @krishantha 13 | * on 15-October-2019 06:32 14 | * @Project rentcloudmodel 15 | */ 16 | public interface RentRepository extends JpaRepository { 17 | } 18 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/service/RentService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | import lk.codelabs.rentcloud.rentservice.model.DetailResponse; 5 | import lk.codelabs.rentcloud.rentservice.model.Response; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author Krishantha Dinesh 11 | * krishantha@krishantha.com 12 | * www.krishantha.com 13 | * twitter @krishantha 14 | * on 15-October-2019 06:34 15 | * @Project rentcloudmodel 16 | */ 17 | public interface RentService { 18 | Rent save(Rent customer); 19 | 20 | Rent findById(int id); 21 | 22 | List findAll(); 23 | 24 | DetailResponse findDetailResponse(int id); 25 | } 26 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | datasource: 4 | url: jdbc:mysql://localhost:3306/rentcloud_rent?createDatabaseIfNotExist=true 5 | username: root 6 | password: 1qazxsw2# 7 | driver-class-name: com.mysql.jdbc.Driver 8 | jpa: 9 | hibernate: 10 | naming: 11 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 12 | ddl-auto: none 13 | 14 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: rent 4 | server: 5 | port: 8191 6 | eureka: 7 | client: 8 | register-with-eureka: true 9 | fetch-registry: true 10 | instance: 11 | instance-id: ${spring.application.name}-${random.int} 12 | hostname: localhost -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/rent-service/src/test/java/lk/codelabs/rentcloud/rentservice/RentServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RentServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/VehicleServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.vehicle") 10 | @EnableEurekaClient 11 | public class VehicleServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(VehicleServiceApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/controller/VehicleController.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.controller; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import lk.codelabs.rentcloud.vehicleservice.service.VehicleService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 06:10 17 | * @Project rentcloudmodel 18 | */ 19 | 20 | @RestController 21 | @RequestMapping("/services/vehicles") 22 | public class VehicleController { 23 | 24 | @Autowired 25 | VehicleService vehicleService; 26 | 27 | @PostMapping 28 | public Vehicle save(@RequestBody Vehicle vehicle) { 29 | return vehicleService.save(vehicle); 30 | } 31 | 32 | @GetMapping(value = "/{id}") 33 | public Vehicle getVehicle(@PathVariable int id) 34 | { 35 | System.out.println("request came on "+LocalDateTime.now() + " ++++++++++++++++++++++"); 36 | return vehicleService.findById(id); 37 | } 38 | 39 | @GetMapping 40 | public List getAllVehicles() { 41 | return vehicleService.findAll(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/repository/VehicleRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 15-October-2019 06:08 12 | * @Project rentcloudmodel 13 | */ 14 | public interface VehicleRepository extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/service/VehicleService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 15-October-2019 06:10 13 | * @Project rentcloudmodel 14 | */ 15 | public interface VehicleService { 16 | Vehicle save(Vehicle customer); 17 | 18 | Vehicle findById(int id); 19 | 20 | List findAll(); 21 | } 22 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/service/VehicleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import lk.codelabs.rentcloud.vehicleservice.repository.VehicleRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 06:08 17 | * @Project rentcloudmodel 18 | */ 19 | @Service 20 | public class VehicleServiceImpl implements VehicleService { 21 | @Autowired 22 | VehicleRepository vehicleRepository; 23 | 24 | 25 | @Override 26 | public Vehicle save(Vehicle customer) { 27 | return vehicleRepository.save(customer); 28 | } 29 | 30 | 31 | @Override 32 | public Vehicle findById(int id) { 33 | Optional vehicle = vehicleRepository.findById(id); 34 | 35 | if (vehicle.isPresent()) 36 | return vehicle.get(); 37 | else 38 | return new Vehicle(); 39 | 40 | } 41 | 42 | 43 | @Override 44 | public List findAll() { 45 | return vehicleRepository.findAll(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentcloud_vehicle?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 0 3 | spring: 4 | application: 5 | name: vehicle 6 | eureka: 7 | client: 8 | register-with-eureka: true 9 | fetch-registry: true 10 | instance: 11 | instance-id: ${spring.application.name}-${random.int} 12 | hostname: localhost -------------------------------------------------------------------------------- /video_017-service-discovery-with-discovery-clients/vehicle-service/src/test/java/lk/codelabs/rentcloud/vehicleservice/VehicleServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class VehicleServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/CustomerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.customer") 10 | @EnableEurekaClient 11 | public class CustomerServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(CustomerServiceApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/controller/CustomerServiceController.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.controller; 2 | 3 | import lk.codelabs.rentcloud.customerservice.service.CustomerService; 4 | import lk.codelabs.rentcloud.model.customer.Customer; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 04:09 17 | * @Project rentcloudmodel 18 | */ 19 | 20 | @RestController 21 | @RequestMapping("/services/customers") 22 | public class CustomerServiceController { 23 | 24 | 25 | @Autowired 26 | CustomerService customerService; 27 | 28 | @PostMapping 29 | public Customer save(@RequestBody Customer customer) { 30 | return customerService.save(customer); 31 | } 32 | 33 | @GetMapping(value = "/{id}") 34 | public Customer getCustomer(@PathVariable int id) { 35 | 36 | System.out.println("request came on "+LocalDateTime.now() + " 5 ++++++++++++++++++++++"); 37 | return customerService.findById(id); 38 | } 39 | 40 | @GetMapping 41 | public List getAllCustomers() { 42 | return customerService.findAll(); 43 | } 44 | 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 15-October-2019 04:17 12 | * @Project rentcloudmodel 13 | */ 14 | public interface CustomerRepository extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 15-October-2019 04:28 13 | * @Project rentcloudmodel 14 | */ 15 | public interface CustomerService { 16 | Customer save(Customer customer); 17 | 18 | Customer findById(int id); 19 | 20 | List findAll(); 21 | } 22 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/src/main/java/lk/codelabs/rentcloud/customerservice/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice.service; 2 | 3 | import lk.codelabs.rentcloud.customerservice.repository.CustomerRepository; 4 | import lk.codelabs.rentcloud.model.customer.Customer; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 04:15 17 | * @Project rentcloudmodel 18 | */ 19 | @Service 20 | public class CustomerServiceImpl implements CustomerService { 21 | 22 | @Autowired 23 | CustomerRepository customerRepository; 24 | 25 | @Override 26 | public Customer save(Customer customer) { 27 | return customerRepository.save(customer); 28 | } 29 | 30 | @Override 31 | public Customer findById(int id) { 32 | Optional customer = customerRepository.findById(id); 33 | 34 | if (customer.isPresent()) 35 | return customer.get(); 36 | else 37 | return new Customer(); 38 | 39 | } 40 | 41 | @Override 42 | public List findAll() { 43 | return customerRepository.findAll(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentcloud_customer?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none 12 | # properties: 13 | # hibernate: 14 | # dialect: org.hibernate.dialect.MySQL55Dialect 15 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: customer 4 | server: 5 | port: 0 6 | eureka: 7 | client: 8 | register-with-eureka: true 9 | fetch-registry: true 10 | instance: 11 | instance-id: ${spring.application.name}-${random.int} 12 | hostname: localhost -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/customer-service/src/test/java/lk/codelabs/rentcloud/customerservice/CustomerServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.customerservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CustomerServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/discovery-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/discovery-service/src/main/java/lk/codelabs/rentcloud/discoveryservice/DiscoveryServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.discoveryservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class DiscoveryServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DiscoveryServiceApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/discovery-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | client: 4 | register-with-eureka: false 5 | fetch-registry: false 6 | datacenter: Colombo-SriLanka 7 | environment: production 8 | server: 9 | port: 8761 -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/discovery-service/src/test/java/lk/codelabs/rentcloud/discoveryservice/DiscoveryServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.discoveryservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DiscoveryServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/readme.txt: -------------------------------------------------------------------------------- 1 | Youtube: https://www.youtube.com/krish 2 | LinkedIn: https://www.linkedin.com/in/krish-din/ 3 | Instagram: https://www.instagram.com/krish.din/ 4 | facebook: https://www.facebook.com/krish.page 5 | facebook: https://www.facebook.com/capturedDreams 6 | twitter: https://twitter.com/krishantha (@Krishantha) 7 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/RentServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | 9 | @SpringBootApplication 10 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.rent") 11 | @EnableEurekaClient 12 | @EnableCircuitBreaker 13 | public class RentServiceApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(RentServiceApplication.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/hystrix/HystrixConfig.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.hystrix; 2 | 3 | import com.netflix.hystrix.HystrixCommand; 4 | import com.netflix.hystrix.HystrixCommandGroupKey; 5 | import com.netflix.hystrix.HystrixCommandProperties; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.core.env.Environment; 10 | 11 | @Configuration 12 | public class HystrixConfig { 13 | 14 | @Autowired 15 | Environment environment; 16 | 17 | @Bean 18 | public HystrixCommand.Setter config() { 19 | HystrixCommand.Setter config = HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory 20 | .asKey("rentcloud")); 21 | HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties.Setter(); 22 | String timeout=environment.getProperty("hystrix.timeout"); 23 | if(timeout==null) 24 | timeout="500"; 25 | commandProperties.withExecutionTimeoutInMilliseconds(Integer.parseInt(timeout)); 26 | config.andCommandPropertiesDefaults(commandProperties); 27 | return config; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/hystrix/VehicleCommand.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.hystrix; 2 | 3 | import com.netflix.hystrix.HystrixCommand; 4 | import com.netflix.hystrix.HystrixCommandGroupKey; 5 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | /** 9 | * @author Krishantha Dinesh 10 | * krishantha@krishantha.com 11 | * www.krishantha.com 12 | * twitter @krishantha 13 | * on 13-November-2019 02:32 14 | * @Project vehicle-service 15 | */ 16 | public class VehicleCommand extends HystrixCommand { 17 | 18 | 19 | RestTemplate restTemplate; 20 | int vehicleId; 21 | 22 | 23 | 24 | public VehicleCommand(RestTemplate restTemplate, int vehicleId){ 25 | 26 | super(HystrixCommandGroupKey.Factory.asKey("default")); 27 | this.restTemplate=restTemplate; 28 | this.vehicleId=vehicleId; 29 | } 30 | 31 | 32 | @Override 33 | protected Vehicle run() throws Exception { 34 | return restTemplate.getForObject("http://vehicle/services/vehicles/"+vehicleId,Vehicle.class); 35 | } 36 | 37 | @Override 38 | protected Vehicle getFallback() { 39 | System.out.println("hit on fallback"); 40 | return new Vehicle(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/DetailResponse.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | import lk.codelabs.rentcloud.model.customer.Customer; 4 | import lk.codelabs.rentcloud.model.rent.Rent; 5 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 22-October-2019 23:24 13 | * @Project rent-service 14 | */ 15 | public class DetailResponse implements Response { 16 | 17 | Rent rent; 18 | Customer customer; 19 | Vehicle vehicle; 20 | 21 | public DetailResponse(Rent rent, Customer customer, Vehicle vehicle) { 22 | this.rent = rent; 23 | this.customer = customer; 24 | this.vehicle = vehicle; 25 | } 26 | 27 | public Rent getRent() { 28 | return rent; 29 | } 30 | 31 | public void setRent(Rent rent) { 32 | this.rent = rent; 33 | } 34 | 35 | public Customer getCustomer() { 36 | return customer; 37 | } 38 | 39 | public void setCustomer(Customer customer) { 40 | this.customer = customer; 41 | } 42 | 43 | public Vehicle getVehicle() { 44 | return vehicle; 45 | } 46 | 47 | public void setVehicle(Vehicle vehicle) { 48 | this.vehicle = vehicle; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/Response.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | /** 4 | * @author Krishantha Dinesh 5 | * krishantha@krishantha.com 6 | * www.krishantha.com 7 | * twitter @krishantha 8 | * on 22-October-2019 23:24 9 | * @Project rent-service 10 | */ 11 | public interface Response { 12 | } 13 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/model/SimpleResponse.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.model; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | 5 | /** 6 | * @author Krishantha Dinesh 7 | * krishantha@krishantha.com 8 | * www.krishantha.com 9 | * twitter @krishantha 10 | * on 22-October-2019 23:25 11 | * @Project rent-service 12 | */ 13 | public class SimpleResponse implements Response { 14 | 15 | Rent rent; 16 | 17 | 18 | public SimpleResponse(Rent rent) { 19 | this.rent = rent; 20 | } 21 | 22 | public Rent getRent() { 23 | return rent; 24 | } 25 | 26 | public void setRent(Rent rent) { 27 | this.rent = rent; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/repository/RentRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import javax.persistence.criteria.CriteriaBuilder; 7 | 8 | /** 9 | * @author Krishantha Dinesh 10 | * krishantha@krishantha.com 11 | * www.krishantha.com 12 | * twitter @krishantha 13 | * on 15-October-2019 06:32 14 | * @Project rentcloudmodel 15 | */ 16 | public interface RentRepository extends JpaRepository { 17 | } 18 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/java/lk/codelabs/rentcloud/rentservice/service/RentService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.rent.Rent; 4 | import lk.codelabs.rentcloud.rentservice.model.DetailResponse; 5 | import lk.codelabs.rentcloud.rentservice.model.Response; 6 | 7 | import java.util.List; 8 | import java.util.concurrent.ExecutionException; 9 | 10 | /** 11 | * @author Krishantha Dinesh 12 | * krishantha@krishantha.com 13 | * www.krishantha.com 14 | * twitter @krishantha 15 | * on 15-October-2019 06:34 16 | * @Project rentcloudmodel 17 | */ 18 | public interface RentService { 19 | Rent save(Rent customer); 20 | 21 | Rent findById(int id); 22 | 23 | List findAll(); 24 | 25 | DetailResponse findDetailResponse(int id) throws ExecutionException, InterruptedException; 26 | } 27 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | datasource: 4 | url: jdbc:mysql://localhost:3306/rentcloud_rent?createDatabaseIfNotExist=true 5 | username: root 6 | password: 1qazxsw2# 7 | driver-class-name: com.mysql.jdbc.Driver 8 | jpa: 9 | hibernate: 10 | naming: 11 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 12 | ddl-auto: none 13 | hystrix: 14 | timeout: 1000 15 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: rent 4 | server: 5 | port: 8191 6 | eureka: 7 | client: 8 | register-with-eureka: true 9 | fetch-registry: true 10 | instance: 11 | instance-id: ${spring.application.name}-${random.int} 12 | hostname: localhost -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/rent-service/src/test/java/lk/codelabs/rentcloud/rentservice/RentServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.rentservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RentServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/VehicleServiceApplication.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "lk.codelabs.rentcloud.model.vehicle") 10 | @EnableEurekaClient 11 | public class VehicleServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(VehicleServiceApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/controller/VehicleController.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.controller; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import lk.codelabs.rentcloud.vehicleservice.service.VehicleService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 06:10 17 | * @Project rentcloudmodel 18 | */ 19 | 20 | @RestController 21 | @RequestMapping("/services/vehicles") 22 | public class VehicleController { 23 | 24 | @Autowired 25 | VehicleService vehicleService; 26 | 27 | @PostMapping 28 | public Vehicle save(@RequestBody Vehicle vehicle) { 29 | return vehicleService.save(vehicle); 30 | } 31 | 32 | @GetMapping(value = "/{id}") 33 | public Vehicle getVehicle(@PathVariable int id) 34 | { 35 | System.out.println("request came on "+LocalDateTime.now() + " ++++++++++++++++++++++"); 36 | return vehicleService.findById(id); 37 | } 38 | 39 | @GetMapping 40 | public List getAllVehicles() { 41 | return vehicleService.findAll(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/repository/VehicleRepository.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.repository; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Krishantha Dinesh 8 | * krishantha@krishantha.com 9 | * www.krishantha.com 10 | * twitter @krishantha 11 | * on 15-October-2019 06:08 12 | * @Project rentcloudmodel 13 | */ 14 | public interface VehicleRepository extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/service/VehicleService.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Krishantha Dinesh 9 | * krishantha@krishantha.com 10 | * www.krishantha.com 11 | * twitter @krishantha 12 | * on 15-October-2019 06:10 13 | * @Project rentcloudmodel 14 | */ 15 | public interface VehicleService { 16 | Vehicle save(Vehicle customer); 17 | 18 | Vehicle findById(int id); 19 | 20 | List findAll(); 21 | } 22 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/src/main/java/lk/codelabs/rentcloud/vehicleservice/service/VehicleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice.service; 2 | 3 | import lk.codelabs.rentcloud.model.vehicle.Vehicle; 4 | import lk.codelabs.rentcloud.vehicleservice.repository.VehicleRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | /** 12 | * @author Krishantha Dinesh 13 | * krishantha@krishantha.com 14 | * www.krishantha.com 15 | * twitter @krishantha 16 | * on 15-October-2019 06:08 17 | * @Project rentcloudmodel 18 | */ 19 | @Service 20 | public class VehicleServiceImpl implements VehicleService { 21 | @Autowired 22 | VehicleRepository vehicleRepository; 23 | 24 | 25 | @Override 26 | public Vehicle save(Vehicle customer) { 27 | return vehicleRepository.save(customer); 28 | } 29 | 30 | 31 | @Override 32 | public Vehicle findById(int id) { 33 | Optional vehicle = vehicleRepository.findById(id); 34 | 35 | if (vehicle.isPresent()) 36 | return vehicle.get(); 37 | else 38 | return new Vehicle(); 39 | 40 | } 41 | 42 | 43 | @Override 44 | public List findAll() { 45 | return vehicleRepository.findAll(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://localhost:3306/rentcloud_vehicle?createDatabaseIfNotExist=true 4 | username: root 5 | password: 1qazxsw2# 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | naming: 10 | physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 11 | ddl-auto: none -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 0 3 | spring: 4 | application: 5 | name: vehicle 6 | eureka: 7 | client: 8 | register-with-eureka: true 9 | fetch-registry: true 10 | instance: 11 | instance-id: ${spring.application.name}-${random.int} 12 | hostname: localhost -------------------------------------------------------------------------------- /video_018-circuit-breaker-pattern/vehicle-service/src/test/java/lk/codelabs/rentcloud/vehicleservice/VehicleServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package lk.codelabs.rentcloud.vehicleservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class VehicleServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------