├── .github └── workflows │ └── docker-publish.yml ├── .gitignore ├── 00-foo-bar-spring-initializr ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ └── maven-wrapper.properties ├── HELP.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ └── BarApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── BarApplicationTests.java ├── 01-foo-bar-final ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Greeting.java │ │ │ ├── GreetingController.java │ │ │ └── Startup.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── StartupTests.java ├── 02-RESTinPracticewithSpringBootandJava ├── 05A_FirstStepsInJavawithSpringBoot │ └── rest-with-spring-boot-and-java-erudio │ │ ├── pom.xml │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── br │ │ │ │ └── com │ │ │ │ └── erudio │ │ │ │ ├── Greeting.java │ │ │ │ ├── GreetingController.java │ │ │ │ └── Startup.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── br │ │ └── com │ │ └── erudio │ │ └── StartupTests.java ├── 05B_ParametersAndExceptionHandler │ └── rest-with-spring-boot-and-java-erudio │ │ ├── pom.xml │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── br │ │ │ │ └── com │ │ │ │ └── erudio │ │ │ │ ├── Startup.java │ │ │ │ ├── controllers │ │ │ │ └── MathController.java │ │ │ │ ├── converters │ │ │ │ └── NumberConverter.java │ │ │ │ ├── exceptions │ │ │ │ ├── ExceptionResponse.java │ │ │ │ ├── UnsupportedMathOperationException.java │ │ │ │ └── handler │ │ │ │ │ └── CustomizedResponseEntityExceptionHandler.java │ │ │ │ └── math │ │ │ │ └── SimpleMath.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── br │ │ └── com │ │ └── erudio │ │ └── StartupTests.java ├── 05C_WorkingWithVerbs │ └── rest-with-spring-boot-and-java-erudio │ │ ├── pom.xml │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── br │ │ │ │ └── com │ │ │ │ └── erudio │ │ │ │ ├── Startup.java │ │ │ │ ├── controllers │ │ │ │ └── PersonController.java │ │ │ │ ├── exceptions │ │ │ │ ├── ExceptionResponse.java │ │ │ │ ├── UnsupportedMathOperationException.java │ │ │ │ └── handler │ │ │ │ │ └── CustomizedResponseEntityExceptionHandler.java │ │ │ │ ├── model │ │ │ │ └── Person.java │ │ │ │ └── services │ │ │ │ └── PersonServices.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── br │ │ └── com │ │ └── erudio │ │ └── StartupTests.java └── 05D_ConnectingToMySQL │ └── rest-with-spring-boot-and-java-erudio │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Startup.java │ │ │ ├── controllers │ │ │ └── PersonController.java │ │ │ ├── exceptions │ │ │ ├── ExceptionResponse.java │ │ │ ├── ResourceNotFoundException.java │ │ │ └── handler │ │ │ │ └── CustomizedResponseEntityExceptionHandler.java │ │ │ ├── model │ │ │ └── Person.java │ │ │ ├── repositories │ │ │ └── PersonRepository.java │ │ │ └── services │ │ │ └── PersonServices.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── StartupTests.java ├── 04-erudio-config-server ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ └── Application.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 04-greeting-service ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── GreetingConfiguration.java │ │ │ ├── controllers │ │ │ └── GreetingController.java │ │ │ └── model │ │ │ └── Greeting.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 05-book-service ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── controller │ │ │ └── BookController.java │ │ │ ├── model │ │ │ └── Book.java │ │ │ ├── proxy │ │ │ └── CambioProxy.java │ │ │ ├── repository │ │ │ └── BookRepository.java │ │ │ └── response │ │ │ └── Cambio.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Books.sql │ │ └── V2__Insert_Data_In_Books.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 05-cambio-service ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── controller │ │ │ └── CambioController.java │ │ │ ├── model │ │ │ └── Cambio.java │ │ │ └── repository │ │ │ └── CambioRepository.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Cambio.sql │ │ └── V2__Populate_Table_Cambio.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 06-api-gateway ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── ApiGatewayConfiguration.java │ │ │ └── filter │ │ │ └── LoggingFilter.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 06-book-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── controller │ │ │ └── BookController.java │ │ │ ├── model │ │ │ └── Book.java │ │ │ ├── proxy │ │ │ └── CambioProxy.java │ │ │ ├── repository │ │ │ └── BookRepository.java │ │ │ └── response │ │ │ └── Cambio.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Books.sql │ │ └── V2__Insert_Data_In_Books.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 06-cambio-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── controller │ │ │ └── CambioController.java │ │ │ ├── model │ │ │ └── Cambio.java │ │ │ └── repository │ │ │ └── CambioRepository.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Cambio.sql │ │ └── V2__Populate_Table_Cambio.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 06-naming-server ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ └── Application.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 07-api-gateway ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── ApiGatewayConfiguration.java │ │ │ └── filter │ │ │ └── LoggingFilter.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 07-book-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── controller │ │ │ ├── BookController.java │ │ │ └── FooBarController.java │ │ │ ├── model │ │ │ └── Book.java │ │ │ ├── proxy │ │ │ └── CambioProxy.java │ │ │ ├── repository │ │ │ └── BookRepository.java │ │ │ └── response │ │ │ └── Cambio.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Books.sql │ │ └── V2__Insert_Data_In_Books.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 07-cambio-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── controller │ │ │ └── CambioController.java │ │ │ ├── model │ │ │ └── Cambio.java │ │ │ └── repository │ │ │ └── CambioRepository.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Cambio.sql │ │ └── V2__Populate_Table_Cambio.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 07-naming-server ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ └── Application.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 08-api-gateway ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── OpenApiConfiguration.java │ │ │ └── filter │ │ │ └── LoggingFilter.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 08-book-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── OpenApiConfiguration.java │ │ │ ├── controller │ │ │ ├── BookController.java │ │ │ └── FooBarController.java │ │ │ ├── model │ │ │ └── Book.java │ │ │ ├── proxy │ │ │ └── CambioProxy.java │ │ │ ├── repository │ │ │ └── BookRepository.java │ │ │ └── response │ │ │ └── Cambio.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Books.sql │ │ └── V2__Insert_Data_In_Books.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 08-cambio-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── OpenApiConfiguration.java │ │ │ ├── controller │ │ │ └── CambioController.java │ │ │ ├── model │ │ │ └── Cambio.java │ │ │ └── repository │ │ │ └── CambioRepository.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Cambio.sql │ │ └── V2__Populate_Table_Cambio.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 08-naming-server ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ └── Application.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 09-api-gateway ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── OpenApiConfiguration.java │ │ │ └── filter │ │ │ └── LoggingFilter.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 09-book-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── OpenApiConfiguration.java │ │ │ ├── controller │ │ │ ├── BookController.java │ │ │ └── FooBarController.java │ │ │ ├── model │ │ │ └── Book.java │ │ │ ├── proxy │ │ │ └── CambioProxy.java │ │ │ ├── repository │ │ │ └── BookRepository.java │ │ │ └── response │ │ │ └── Cambio.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Books.sql │ │ └── V2__Insert_Data_In_Books.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 09-cambio-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ └── OpenApiConfiguration.java │ │ │ ├── controller │ │ │ └── CambioController.java │ │ │ ├── model │ │ │ └── Cambio.java │ │ │ └── repository │ │ │ └── CambioRepository.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ ├── V1__Create_Table_Cambio.sql │ │ └── V2__Populate_Table_Cambio.sql │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 09-naming-server ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ └── Application.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── ApplicationTests.java ├── 18_BONUS_ChatGPT └── chatgpt-spring-boot-java-integration │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── Startup.java │ │ │ ├── config │ │ │ └── OpenAIConfig.java │ │ │ ├── controller │ │ │ └── ChatGPTController.java │ │ │ ├── service │ │ │ └── ChatGPTService.java │ │ │ └── vo │ │ │ ├── request │ │ │ ├── ChatGptRequest.java │ │ │ └── Message.java │ │ │ └── response │ │ │ ├── ChatGptResponse.java │ │ │ └── Choice.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── StartupTests.java ├── Challenges └── 01_MathChallenge │ ├── pom.xml │ └── src │ └── main │ └── java │ └── br │ └── com │ └── erudio │ ├── Startup.java │ ├── controller │ └── MathController.java │ ├── exception │ ├── ExceptionResponse.java │ ├── UnsuportedMathOperationException.java │ └── handler │ │ └── CustomizedResponseEntityExceptionHandler.java │ ├── math │ └── SimpleMath.java │ └── request │ └── converters │ └── NumberConverter.java ├── DockerReview ├── Dockerfile ├── pom.xml └── src │ ├── main │ ├── java │ │ └── br │ │ │ └── com │ │ │ └── erudio │ │ │ ├── DockerController.java │ │ │ ├── HelloDocker.java │ │ │ └── Startup.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── br │ └── com │ └── erudio │ └── StartupTests.java ├── Dockerizing ├── 10-api-gateway │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── br │ │ │ │ └── com │ │ │ │ └── erudio │ │ │ │ ├── Application.java │ │ │ │ ├── configuration │ │ │ │ └── OpenApiConfiguration.java │ │ │ │ └── filter │ │ │ │ └── LoggingFilter.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── br │ │ └── com │ │ └── erudio │ │ └── ApplicationTests.java ├── 10-book-service │ ├── Dockerfile │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── br │ │ │ │ └── com │ │ │ │ └── erudio │ │ │ │ ├── Application.java │ │ │ │ ├── configuration │ │ │ │ └── OpenApiConfiguration.java │ │ │ │ ├── controller │ │ │ │ ├── BookController.java │ │ │ │ └── FooBarController.java │ │ │ │ ├── model │ │ │ │ └── Book.java │ │ │ │ ├── proxy │ │ │ │ └── CambioProxy.java │ │ │ │ ├── repository │ │ │ │ └── BookRepository.java │ │ │ │ └── response │ │ │ │ └── Cambio.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── db │ │ │ └── migration │ │ │ ├── V1__Create_Table_Books.sql │ │ │ └── V2__Insert_Data_In_Books.sql │ │ └── test │ │ └── java │ │ └── br │ │ └── com │ │ └── erudio │ │ └── ApplicationTests.java ├── 10-cambio-service │ ├── Dockerfile │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── br │ │ │ │ └── com │ │ │ │ └── erudio │ │ │ │ ├── Application.java │ │ │ │ ├── configuration │ │ │ │ └── OpenApiConfiguration.java │ │ │ │ ├── controller │ │ │ │ └── CambioController.java │ │ │ │ ├── model │ │ │ │ └── Cambio.java │ │ │ │ └── repository │ │ │ │ └── CambioRepository.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── db │ │ │ └── migration │ │ │ ├── V1__Create_Table_Cambio.sql │ │ │ └── V2__Populate_Table_Cambio.sql │ │ └── test │ │ └── java │ │ └── br │ │ └── com │ │ └── erudio │ │ └── ApplicationTests.java ├── 10-erudio-config-server │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── br │ │ │ │ └── com │ │ │ │ └── erudio │ │ │ │ └── Application.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── br │ │ └── com │ │ └── erudio │ │ └── ApplicationTests.java ├── 10-naming-server │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── br │ │ │ │ └── com │ │ │ │ └── erudio │ │ │ │ └── Application.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── br │ │ └── com │ │ └── erudio │ │ └── ApplicationTests.java └── docker-compose.yml ├── GithubActions ├── docker-compose.yml └── docker-publish.yml ├── README.md └── images ├── capa_curso_v5.png └── course_cover.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # SSH Keys 4 | 5 | *.pem 6 | *.ppk 7 | 8 | # Mobile Tools for Java (J2ME) 9 | .mtj.tmp/ 10 | 11 | # Package Files # 12 | *.jar 13 | *.war 14 | *.ear 15 | 16 | #Gradle temporary files 17 | target/ 18 | 19 | #Eclipse files 20 | **/.project 21 | **/.classpath 22 | **/.settings/ 23 | /bin/ 24 | blog/bin/ 25 | **/.tern-project 26 | 27 | #IntelliJ files 28 | **/*.iml 29 | **/.idea 30 | **/.gradle 31 | 32 | 33 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 34 | hs_err_pid* -------------------------------------------------------------------------------- /00-foo-bar-spring-initializr/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /00-foo-bar-spring-initializr/HELP.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | ### Reference Documentation 4 | For further reference, please consider the following sections: 5 | 6 | * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) 7 | * [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.5.0-M3/maven-plugin/reference/html/) 8 | * [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.5.0-M3/maven-plugin/reference/html/#build-image) 9 | * [Spring Web](https://docs.spring.io/spring-boot/docs/2.4.4/reference/htmlsingle/#boot-features-developing-web-applications) 10 | 11 | ### Guides 12 | The following guides illustrate how to use some features concretely: 13 | 14 | * [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) 15 | * [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) 16 | * [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/) 17 | 18 | -------------------------------------------------------------------------------- /00-foo-bar-spring-initializr/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.5.0-M3 9 | 10 | 11 | br.com.erudio 12 | foo 13 | 0.0.1-SNAPSHOT 14 | bar 15 | Demo project for Spring Boot 16 | 17 | 16 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-test 28 | test 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-maven-plugin 37 | 38 | 39 | 40 | 41 | 42 | spring-milestones 43 | Spring Milestones 44 | https://repo.spring.io/milestone 45 | 46 | 47 | 48 | 49 | spring-milestones 50 | Spring Milestones 51 | https://repo.spring.io/milestone 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /00-foo-bar-spring-initializr/src/main/java/br/com/erudio/BarApplication.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BarApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BarApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /00-foo-bar-spring-initializr/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /00-foo-bar-spring-initializr/src/test/java/br/com/erudio/BarApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BarApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /01-foo-bar-final/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.5.0-M3 9 | 10 | 11 | br.com.erudio 12 | foo 13 | 0.0.1-SNAPSHOT 14 | bar 15 | Demo project for Spring Boot 16 | 17 | 16 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-test 28 | test 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-maven-plugin 37 | 38 | 39 | 40 | 41 | 42 | spring-milestones 43 | Spring Milestones 44 | https://repo.spring.io/milestone 45 | 46 | 47 | 48 | 49 | spring-milestones 50 | Spring Milestones 51 | https://repo.spring.io/milestone 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /01-foo-bar-final/src/main/java/br/com/erudio/Greeting.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | public class Greeting { 4 | 5 | private final long id; 6 | private final String content; 7 | 8 | public Greeting(long id, String content) { 9 | this.id = id; 10 | this.content = content; 11 | } 12 | 13 | public long getId() { 14 | return id; 15 | } 16 | 17 | public String getContent() { 18 | return content; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /01-foo-bar-final/src/main/java/br/com/erudio/GreetingController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import java.util.concurrent.atomic.AtomicLong; 4 | 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public class GreetingController { 11 | 12 | private static final String template = "Hello, %s!"; 13 | private final AtomicLong counter = new AtomicLong(); 14 | 15 | @RequestMapping("/greeting") 16 | public Greeting greeting( 17 | @RequestParam(value="name", 18 | defaultValue = "World") String name) { 19 | return new Greeting( 20 | counter.incrementAndGet(), 21 | String.format(template, name) 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /01-foo-bar-final/src/main/java/br/com/erudio/Startup.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Startup { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Startup.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /01-foo-bar-final/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /01-foo-bar-final/src/test/java/br/com/erudio/StartupTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class StartupTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05A_FirstStepsInJavawithSpringBoot/rest-with-spring-boot-and-java-erudio/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.2.0 9 | 10 | 11 | br.com.erudio 12 | rest-with-spring-boot-and-java-erudio 13 | 0.0.1-SNAPSHOT 14 | rest-with-spring-boot-and-java-erudio 15 | Demo project for Spring Boot 16 | 17 | 21 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-devtools 28 | runtime 29 | true 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05A_FirstStepsInJavawithSpringBoot/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/Greeting.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | public class Greeting { 4 | 5 | private final long id; 6 | private final String content; 7 | 8 | public Greeting(long id, String content) { 9 | this.id = id; 10 | this.content = content; 11 | } 12 | 13 | public long getId() { 14 | return id; 15 | } 16 | 17 | public String getContent() { 18 | return content; 19 | } 20 | } -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05A_FirstStepsInJavawithSpringBoot/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/GreetingController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import java.util.concurrent.atomic.AtomicLong; 4 | 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public class GreetingController { 11 | 12 | private static final String template = "Hello, %s!"; 13 | private final AtomicLong counter = new AtomicLong(); 14 | 15 | @RequestMapping("/greeting") 16 | public Greeting greeting( 17 | @RequestParam(value = "name", defaultValue = "World") 18 | String name) { 19 | return new Greeting(counter.incrementAndGet(), String.format(template, name)); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05A_FirstStepsInJavawithSpringBoot/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/Startup.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Startup { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Startup.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05A_FirstStepsInJavawithSpringBoot/rest-with-spring-boot-and-java-erudio/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05A_FirstStepsInJavawithSpringBoot/rest-with-spring-boot-and-java-erudio/src/test/java/br/com/erudio/StartupTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class StartupTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.2.0 9 | 10 | 11 | br.com.erudio 12 | rest-with-spring-boot-and-java-erudio 13 | 0.0.1-SNAPSHOT 14 | rest-with-spring-boot-and-java-erudio 15 | Demo project for Spring Boot 16 | 17 | 21 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-devtools 28 | runtime 29 | true 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/Startup.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Startup { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Startup.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/converters/NumberConverter.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.converters; 2 | 3 | public class NumberConverter { 4 | 5 | public static Double convertToDouble(String strNumber) { 6 | if (strNumber == null) return 0D; 7 | // BR 10,25 US 10.25 8 | String number = strNumber.replaceAll(",", "."); 9 | if (isNumeric(number)) return Double.parseDouble(number); 10 | return 0D; 11 | } 12 | 13 | public static boolean isNumeric(String strNumber) { 14 | if (strNumber == null) return false; 15 | String number = strNumber.replaceAll(",", "."); 16 | return number.matches("[-+]?[0-9]*\\.?[0-9]+"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/ExceptionResponse.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class ExceptionResponse implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Date timestamp; 11 | private String message; 12 | private String details; 13 | 14 | public ExceptionResponse(Date timestamp, String message, String details) { 15 | this.timestamp = timestamp; 16 | this.message = message; 17 | this.details = details; 18 | } 19 | 20 | public Date getTimestamp() { 21 | return timestamp; 22 | } 23 | 24 | public String getMessage() { 25 | return message; 26 | } 27 | 28 | public String getDetails() { 29 | return details; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/UnsupportedMathOperationException.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.BAD_REQUEST) 7 | public class UnsupportedMathOperationException extends RuntimeException{ 8 | 9 | public UnsupportedMathOperationException(String ex) { 10 | super(ex); 11 | } 12 | 13 | private static final long serialVersionUID = 1L; 14 | } -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/handler/CustomizedResponseEntityExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions.handler; 2 | 3 | import java.util.Date; 4 | 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.context.request.WebRequest; 11 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 12 | 13 | import br.com.erudio.exceptions.ExceptionResponse; 14 | import br.com.erudio.exceptions.UnsupportedMathOperationException; 15 | 16 | @ControllerAdvice 17 | @RestController 18 | public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler{ 19 | 20 | @ExceptionHandler(Exception.class) 21 | public final ResponseEntity handleAllExceptions( 22 | Exception ex, WebRequest request) { 23 | 24 | ExceptionResponse exceptionResponse = new ExceptionResponse( 25 | new Date(), 26 | ex.getMessage(), 27 | request.getDescription(false)); 28 | 29 | return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); 30 | } 31 | 32 | @ExceptionHandler(UnsupportedMathOperationException.class) 33 | public final ResponseEntity handleBadRequestExceptions( 34 | Exception ex, WebRequest request) { 35 | 36 | ExceptionResponse exceptionResponse = new ExceptionResponse( 37 | new Date(), 38 | ex.getMessage(), 39 | request.getDescription(false)); 40 | 41 | return new ResponseEntity<>(exceptionResponse, HttpStatus.BAD_REQUEST); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/math/SimpleMath.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.math; 2 | 3 | public class SimpleMath { 4 | 5 | public Double sum(Double numberOne, Double numberTwo) { 6 | return numberOne + numberTwo; 7 | } 8 | 9 | public Double subtraction(Double numberOne, Double numberTwo) { 10 | return numberOne - numberTwo; 11 | } 12 | 13 | public Double multiplication(Double numberOne, Double numberTwo) { 14 | return numberOne * numberTwo; 15 | } 16 | 17 | public Double division(Double numberOne, Double numberTwo) { 18 | return numberOne / numberTwo; 19 | } 20 | 21 | public Double mean(Double numberOne, Double numberTwo) { 22 | return (numberOne + numberTwo) / 2; 23 | } 24 | 25 | public Double squareRoot(Double number) { 26 | return Math.sqrt(number); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05B_ParametersAndExceptionHandler/rest-with-spring-boot-and-java-erudio/src/test/java/br/com/erudio/StartupTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class StartupTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.2.0 9 | 10 | 11 | br.com.erudio 12 | rest-with-spring-boot-and-java-erudio 13 | 0.0.1-SNAPSHOT 14 | rest-with-spring-boot-and-java-erudio 15 | 16 | 21 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-devtools 27 | runtime 28 | true 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-maven-plugin 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/Startup.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Startup { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Startup.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/controllers/PersonController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controllers; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import br.com.erudio.model.Person; 14 | import br.com.erudio.services.PersonServices; 15 | 16 | @RestController 17 | @RequestMapping("/person") 18 | public class PersonController { 19 | 20 | @Autowired 21 | private PersonServices service; 22 | ///private PersonServices service = new PersonServices(); 23 | 24 | @RequestMapping(method=RequestMethod.GET, 25 | produces = MediaType.APPLICATION_JSON_VALUE) 26 | public List findAll() { 27 | return service.findAll(); 28 | } 29 | 30 | @RequestMapping(value = "/{id}", 31 | method=RequestMethod.GET, 32 | produces = MediaType.APPLICATION_JSON_VALUE) 33 | public Person findById(@PathVariable(value = "id") String id) { 34 | return service.findById(id); 35 | } 36 | 37 | @RequestMapping(method=RequestMethod.POST, 38 | consumes = MediaType.APPLICATION_JSON_VALUE, 39 | produces = MediaType.APPLICATION_JSON_VALUE) 40 | public Person create(@RequestBody Person person) { 41 | return service.create(person); 42 | } 43 | 44 | @RequestMapping(method=RequestMethod.PUT, 45 | consumes = MediaType.APPLICATION_JSON_VALUE, 46 | produces = MediaType.APPLICATION_JSON_VALUE) 47 | public Person update(@RequestBody Person person) { 48 | return service.update(person); 49 | } 50 | 51 | 52 | @RequestMapping(value = "/{id}", 53 | method=RequestMethod.DELETE) 54 | public void delete(@PathVariable(value = "id") String id) { 55 | service.delete(id); 56 | } 57 | } -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/ExceptionResponse.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class ExceptionResponse implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Date timestamp; 11 | private String message; 12 | private String details; 13 | 14 | public ExceptionResponse(Date timestamp, String message, String details) { 15 | this.timestamp = timestamp; 16 | this.message = message; 17 | this.details = details; 18 | } 19 | 20 | public Date getTimestamp() { 21 | return timestamp; 22 | } 23 | 24 | public String getMessage() { 25 | return message; 26 | } 27 | 28 | public String getDetails() { 29 | return details; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/UnsupportedMathOperationException.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.BAD_REQUEST) 7 | public class UnsupportedMathOperationException extends RuntimeException{ 8 | 9 | public UnsupportedMathOperationException(String ex) { 10 | super(ex); 11 | } 12 | 13 | private static final long serialVersionUID = 1L; 14 | } -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/handler/CustomizedResponseEntityExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions.handler; 2 | 3 | import java.util.Date; 4 | 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.context.request.WebRequest; 11 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 12 | 13 | import br.com.erudio.exceptions.ExceptionResponse; 14 | import br.com.erudio.exceptions.UnsupportedMathOperationException; 15 | 16 | @ControllerAdvice 17 | @RestController 18 | public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler{ 19 | 20 | @ExceptionHandler(Exception.class) 21 | public final ResponseEntity handleAllExceptions( 22 | Exception ex, WebRequest request) { 23 | 24 | ExceptionResponse exceptionResponse = new ExceptionResponse( 25 | new Date(), 26 | ex.getMessage(), 27 | request.getDescription(false)); 28 | 29 | return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); 30 | } 31 | 32 | @ExceptionHandler(UnsupportedMathOperationException.class) 33 | public final ResponseEntity handleBadRequestExceptions( 34 | Exception ex, WebRequest request) { 35 | 36 | ExceptionResponse exceptionResponse = new ExceptionResponse( 37 | new Date(), 38 | ex.getMessage(), 39 | request.getDescription(false)); 40 | 41 | return new ResponseEntity<>(exceptionResponse, HttpStatus.BAD_REQUEST); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/services/PersonServices.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.services; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.concurrent.atomic.AtomicLong; 6 | import java.util.logging.Logger; 7 | 8 | import org.springframework.stereotype.Service; 9 | 10 | import br.com.erudio.model.Person; 11 | 12 | @Service 13 | public class PersonServices { 14 | 15 | private final AtomicLong counter = new AtomicLong(); 16 | 17 | private Logger logger = Logger.getLogger(PersonServices.class.getName()); 18 | 19 | public List findAll() { 20 | 21 | logger.info("Finding all people!"); 22 | 23 | List persons = new ArrayList<>(); 24 | for (int i = 0; i < 8; i++) { 25 | Person person = mockPerson(i); 26 | persons.add(person); 27 | } 28 | return persons; 29 | } 30 | 31 | public Person findById(String id) { 32 | 33 | logger.info("Finding one person!"); 34 | 35 | Person person = new Person(); 36 | person.setId(counter.incrementAndGet()); 37 | person.setFirstName("Leandro"); 38 | person.setLastName("Costa"); 39 | person.setAddress("Uberlândia - Minas Gerais - Brasil"); 40 | person.setGender("Male"); 41 | return person; 42 | } 43 | 44 | public Person create(Person person) { 45 | 46 | logger.info("Creating one person!"); 47 | 48 | return person; 49 | } 50 | 51 | public Person update(Person person) { 52 | 53 | logger.info("Updating one person!"); 54 | 55 | return person; 56 | } 57 | 58 | public void delete(String id) { 59 | 60 | logger.info("Deleting one person!"); 61 | } 62 | 63 | private Person mockPerson(int i) { 64 | 65 | Person person = new Person(); 66 | person.setId(counter.incrementAndGet()); 67 | person.setFirstName("Person name " + i); 68 | person.setLastName("Last name " + i); 69 | person.setAddress("Some address in Brasil " + i); 70 | person.setGender("Male"); 71 | return person; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05C_WorkingWithVerbs/rest-with-spring-boot-and-java-erudio/src/test/java/br/com/erudio/StartupTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class StartupTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.2.0 9 | 10 | 11 | br.com.erudio 12 | rest-with-spring-boot-and-java-erudio 13 | 0.0.1-SNAPSHOT 14 | rest-with-spring-boot-and-java-erudio 15 | 16 | 21 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-data-jpa 26 | 27 | 28 | com.mysql 29 | mysql-connector-j 30 | runtime 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-devtools 42 | runtime 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/Startup.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Startup { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Startup.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/controllers/PersonController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controllers; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.DeleteMapping; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.PutMapping; 13 | import org.springframework.web.bind.annotation.RequestBody; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import br.com.erudio.model.Person; 18 | import br.com.erudio.services.PersonServices; 19 | 20 | @RestController 21 | @RequestMapping("/person") 22 | public class PersonController { 23 | 24 | @Autowired 25 | private PersonServices service; 26 | 27 | @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) 28 | public List findAll() { 29 | return service.findAll(); 30 | } 31 | 32 | @GetMapping(value = "/{id}", 33 | produces = MediaType.APPLICATION_JSON_VALUE) 34 | public Person findById(@PathVariable(value = "id") Long id) { 35 | return service.findById(id); 36 | } 37 | 38 | @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, 39 | produces = MediaType.APPLICATION_JSON_VALUE) 40 | public Person create(@RequestBody Person person) { 41 | return service.create(person); 42 | } 43 | 44 | @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, 45 | produces = MediaType.APPLICATION_JSON_VALUE) 46 | public Person update(@RequestBody Person person) { 47 | return service.update(person); 48 | } 49 | 50 | 51 | @DeleteMapping(value = "/{id}") 52 | public ResponseEntity delete(@PathVariable(value = "id") Long id) { 53 | service.delete(id); 54 | return ResponseEntity.noContent().build(); 55 | } 56 | } -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/ExceptionResponse.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class ExceptionResponse implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Date timestamp; 11 | private String message; 12 | private String details; 13 | 14 | public ExceptionResponse(Date timestamp, String message, String details) { 15 | this.timestamp = timestamp; 16 | this.message = message; 17 | this.details = details; 18 | } 19 | 20 | public Date getTimestamp() { 21 | return timestamp; 22 | } 23 | 24 | public String getMessage() { 25 | return message; 26 | } 27 | 28 | public String getDetails() { 29 | return details; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.NOT_FOUND) 7 | public class ResourceNotFoundException extends RuntimeException{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | public ResourceNotFoundException(String ex) { 12 | super(ex); 13 | } 14 | } -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/exceptions/handler/CustomizedResponseEntityExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exceptions.handler; 2 | 3 | import java.util.Date; 4 | 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.context.request.WebRequest; 11 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 12 | 13 | import br.com.erudio.exceptions.ExceptionResponse; 14 | import br.com.erudio.exceptions.ResourceNotFoundException; 15 | 16 | @ControllerAdvice 17 | @RestController 18 | public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler{ 19 | 20 | @ExceptionHandler(Exception.class) 21 | public final ResponseEntity handleAllExceptions( 22 | Exception ex, WebRequest request) { 23 | 24 | ExceptionResponse exceptionResponse = new ExceptionResponse( 25 | new Date(), 26 | ex.getMessage(), 27 | request.getDescription(false)); 28 | 29 | return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); 30 | } 31 | 32 | @ExceptionHandler(ResourceNotFoundException.class) 33 | public final ResponseEntity handleNotFoundExceptions( 34 | Exception ex, WebRequest request) { 35 | 36 | ExceptionResponse exceptionResponse = new ExceptionResponse( 37 | new Date(), 38 | ex.getMessage(), 39 | request.getDescription(false)); 40 | 41 | return new ResponseEntity<>(exceptionResponse, HttpStatus.NOT_FOUND); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/repositories/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Person; 6 | 7 | public interface PersonRepository extends JpaRepository {} -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/main/java/br/com/erudio/services/PersonServices.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.services; 2 | 3 | import java.util.List; 4 | import java.util.logging.Logger; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import br.com.erudio.exceptions.ResourceNotFoundException; 10 | import br.com.erudio.model.Person; 11 | import br.com.erudio.repositories.PersonRepository; 12 | 13 | @Service 14 | public class PersonServices { 15 | 16 | private Logger logger = Logger.getLogger(PersonServices.class.getName()); 17 | 18 | @Autowired 19 | PersonRepository repository; 20 | 21 | public List findAll() { 22 | 23 | logger.info("Finding all people!"); 24 | 25 | return repository.findAll(); 26 | } 27 | 28 | public Person findById(Long id) { 29 | 30 | logger.info("Finding one person!"); 31 | 32 | return repository.findById(id) 33 | .orElseThrow(() -> new ResourceNotFoundException("No records found for this ID!")); 34 | } 35 | 36 | public Person create(Person person) { 37 | 38 | logger.info("Creating one person!"); 39 | 40 | return repository.save(person); 41 | } 42 | 43 | public Person update(Person person) { 44 | 45 | logger.info("Updating one person!"); 46 | 47 | var entity = repository.findById(person.getId()) 48 | .orElseThrow(() -> new ResourceNotFoundException("No records found for this ID!")); 49 | 50 | entity.setFirstName(person.getFirstName()); 51 | entity.setLastName(person.getLastName()); 52 | entity.setAddress(person.getAddress()); 53 | entity.setGender(person.getGender()); 54 | 55 | return repository.save(person); 56 | } 57 | 58 | public void delete(Long id) { 59 | 60 | logger.info("Deleting one person!"); 61 | 62 | var entity = repository.findById(id) 63 | .orElseThrow(() -> new ResourceNotFoundException("No records found for this ID!")); 64 | repository.delete(entity); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: com.mysql.cj.jdbc.Driver 4 | url: jdbc:mysql://localhost:3306/rest_with_spring_boot_erudio?useTimezone=true&serverTimezone=UTC 5 | username: root 6 | password: admin123 7 | jpa: 8 | open-in-view: false 9 | hibernate: 10 | ddl-auto: update 11 | # properties: 12 | # hibernate: 13 | # dialect: org.hibernate.dialect.MySQLDialect 14 | show-sql: false -------------------------------------------------------------------------------- /02-RESTinPracticewithSpringBootandJava/05D_ConnectingToMySQL/rest-with-spring-boot-and-java-erudio/src/test/java/br/com/erudio/StartupTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class StartupTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04-erudio-config-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /04-erudio-config-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/04-erudio-config-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /04-erudio-config-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /04-erudio-config-server/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 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 Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /04-erudio-config-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | application: 5 | name: erudio-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://github.com/leandrocgsi/erudio-config-server 11 | #username: username 12 | #password: password 13 | default-label: main 14 | search-paths: 15 | - 'greeting-service*' -------------------------------------------------------------------------------- /04-erudio-config-server/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04-greeting-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /04-greeting-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/04-greeting-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /04-greeting-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /04-greeting-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04-greeting-service/src/main/java/br/com/erudio/configuration/GreetingConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RefreshScope 9 | @ConfigurationProperties("greeting-service") 10 | public class GreetingConfiguration { 11 | 12 | private String greeting; 13 | private String defaultValue; 14 | 15 | public GreetingConfiguration() {} 16 | 17 | public String getGreeting() { 18 | return greeting; 19 | } 20 | 21 | public void setGreeting(String greeting) { 22 | this.greeting = greeting; 23 | } 24 | 25 | public String getDefaultValue() { 26 | return defaultValue; 27 | } 28 | 29 | public void setDefaultValue(String defaultValue) { 30 | this.defaultValue = defaultValue; 31 | } 32 | } -------------------------------------------------------------------------------- /04-greeting-service/src/main/java/br/com/erudio/controllers/GreetingController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controllers; 2 | 3 | import java.util.concurrent.atomic.AtomicLong; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import br.com.erudio.configuration.GreetingConfiguration; 11 | import br.com.erudio.model.Greeting; 12 | 13 | @RestController 14 | public class GreetingController { 15 | 16 | private static final String template = "%s, %s!"; 17 | private final AtomicLong counter = new AtomicLong(); 18 | 19 | @Autowired 20 | private GreetingConfiguration configuration; 21 | 22 | @RequestMapping("/greeting") 23 | public Greeting greeting( 24 | @RequestParam(value="name", 25 | defaultValue = "") String name) { 26 | 27 | if (name.isEmpty()) name = configuration.getDefaultValue(); 28 | 29 | return new Greeting( 30 | counter.incrementAndGet(), 31 | String.format(template, configuration.getGreeting(), name) 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /04-greeting-service/src/main/java/br/com/erudio/model/Greeting.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.model; 2 | 3 | public class Greeting { 4 | 5 | private final long id; 6 | private final String content; 7 | 8 | public Greeting(long id, String content) { 9 | this.id = id; 10 | this.content = content; 11 | } 12 | 13 | public long getId() { 14 | return id; 15 | } 16 | 17 | public String getContent() { 18 | return content; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /04-greeting-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: greeting-service 6 | config: 7 | import: optional:configserver:http://localhost:8888/ 8 | cloud: 9 | config: 10 | profile: prod 11 | management: 12 | endpoints: 13 | web: 14 | exposure: 15 | include: 16 | - '*' 17 | greeting-service: 18 | greeting: "Olá" 19 | default-value: "Mundo" -------------------------------------------------------------------------------- /04-greeting-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /05-book-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /05-book-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/05-book-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /05-book-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /05-book-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /05-book-service/src/main/java/br/com/erudio/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.core.env.Environment; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import br.com.erudio.model.Book; 14 | import br.com.erudio.proxy.CambioProxy; 15 | import br.com.erudio.repository.BookRepository; 16 | import br.com.erudio.response.Cambio; 17 | 18 | @RestController 19 | @RequestMapping("book-service") 20 | public class BookController { 21 | 22 | @Autowired 23 | private Environment environment; 24 | 25 | @Autowired 26 | private BookRepository repository; 27 | 28 | @Autowired 29 | private CambioProxy proxy; 30 | 31 | @GetMapping(value = "/{id}/{currency}") 32 | public Book findBook( 33 | @PathVariable("id") Long id, 34 | @PathVariable("currency") String currency 35 | ) { 36 | 37 | var book = repository.getById(id); 38 | if (book == null) throw new RuntimeException("Book not Found"); 39 | 40 | var cambio = proxy.getCambio(book.getPrice(), "USD", currency); 41 | 42 | var port = environment.getProperty("local.server.port"); 43 | book.setEnvironment(port + " FEIGN"); 44 | book.setPrice(cambio.getConvertedValue()); 45 | return book; 46 | } 47 | 48 | @GetMapping(value = "/v1/{id}/{currency}") 49 | public Book findBookV1( 50 | @PathVariable("id") Long id, 51 | @PathVariable("currency") String currency 52 | ) { 53 | 54 | var book = repository.getById(id); 55 | if (book == null) throw new RuntimeException("Book not Found"); 56 | 57 | HashMap params = new HashMap<>(); 58 | params.put("amount", book.getPrice().toString()); 59 | params.put("from", "USD"); 60 | params.put("to", currency); 61 | 62 | var response = new RestTemplate() 63 | .getForEntity("http://localhost:8000/cambio-service/" 64 | + "{amount}/{from}/{to}", 65 | Cambio.class, 66 | params); 67 | 68 | var cambio = response.getBody(); 69 | 70 | var port = environment.getProperty("local.server.port"); 71 | book.setEnvironment(port); 72 | book.setPrice(cambio.getConvertedValue()); 73 | return book; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /05-book-service/src/main/java/br/com/erudio/proxy/CambioProxy.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.proxy; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | 7 | import br.com.erudio.response.Cambio; 8 | 9 | @FeignClient(name = "cambio-service", url = "localhost:8000") 10 | public interface CambioProxy { 11 | 12 | @GetMapping(value = "/cambio-service/{amount}/{from}/{to}") 13 | public Cambio getCambio( 14 | @PathVariable("amount") Double amount, 15 | @PathVariable("from") String from, 16 | @PathVariable("to") String to 17 | ); 18 | } -------------------------------------------------------------------------------- /05-book-service/src/main/java/br/com/erudio/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Book; 6 | 7 | public interface BookRepository extends JpaRepository{} -------------------------------------------------------------------------------- /05-book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8100 3 | spring: 4 | application: 5 | name: book-service 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/book_service?useTimezone=true&serverTimezone=UTC 9 | username: root 10 | password: admin123 11 | jackson: 12 | default-property-inclusion: NON_NULL 13 | serialization: 14 | fail-on-empty-beans: false 15 | jpa: 16 | hibernate: 17 | ddl-auto: update 18 | show-sql: true 19 | properties: 20 | hibernate: 21 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 22 | flyway: 23 | url: jdbc:mysql://localhost:3306/ 24 | schemas: book_service 25 | user: root 26 | password: admin123 27 | -------------------------------------------------------------------------------- /05-book-service/src/main/resources/db/migration/V1__Create_Table_Books.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `book` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `author` longtext, 4 | `launch_date` datetime(6) NOT NULL, 5 | `price` decimal(65,2) NOT NULL, 6 | `title` longtext 7 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 8 | -------------------------------------------------------------------------------- /05-book-service/src/main/resources/db/migration/V2__Insert_Data_In_Books.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `book` (`author`, `launch_date`, `price`, `title`) VALUES 2 | ('Michael C. Feathers', '2017-11-29 13:50:05.878000', 8.57, 'Working effectively with legacy code'), 3 | ('Ralph Johnson, Erich Gamma, John Vlissides e Richard Helm', '2017-11-29 15:15:13.636000', 7.87, 'Design Patterns'), 4 | ('Robert C. Martin', '2009-01-10 00:00:00.000000', 13.46, 'Clean Code'), 5 | ('Crockford', '2017-11-07 15:09:01.674000', 11.71, 'JavaScript'), 6 | ('Steve McConnell', '2017-11-07 15:09:01.674000', 10.14, 'Code complete'), 7 | ('Martin Fowler e Kent Beck', '2017-11-07 15:09:01.674000', 15.38, 'Refactoring'), 8 | ('Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates', '2017-11-07 15:09:01.674000', 19.23, 'Head First Design Patterns'), 9 | ('Eric Evans', '2017-11-07 15:09:01.674000', 16.09, 'Domain Driven Design'), 10 | ('Brian Goetz e Tim Peierls', '2017-11-07 15:09:01.674000', 13.99, 'Java Concurrency in Practice'), 11 | ('Susan Cain', '2017-11-07 15:09:01.674000', 21.51, 'O poder dos quietos'), 12 | ('Roger S. Pressman', '2017-11-07 15:09:01.674000', 9.79, 'Engenharia de Software: uma abordagem profissional'), 13 | ('Viktor Mayer-Schonberger e Kenneth Kukier', '2017-11-07 15:09:01.674000', 9.44, 'Big Data: como extrair volume, variedade, velocidade e valor da avalanche de informação cotidiana'), 14 | ('Richard Hunter e George Westerman', '2017-11-07 15:09:01.674000', 16.61, 'O verdadeiro valor de TI'), 15 | ('Marc J. Schiller', '2017-11-07 15:09:01.674000', 7.87, 'Os 11 segredos de líderes de TI altamente influentes'), 16 | ('Aguinaldo Aragon Fernandes e Vladimir Ferraz de Abreu', '2017-11-07 15:09:01.674000', 9.44, 'Implantando a governança de TI'); -------------------------------------------------------------------------------- /05-book-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /05-cambio-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /05-cambio-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/05-cambio-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /05-cambio-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /05-cambio-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /05-cambio-service/src/main/java/br/com/erudio/controller/CambioController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.core.env.Environment; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import br.com.erudio.model.Cambio; 14 | import br.com.erudio.repository.CambioRepository; 15 | 16 | @RestController 17 | @RequestMapping("cambio-service") 18 | public class CambioController { 19 | 20 | @Autowired 21 | private Environment environment; 22 | 23 | @Autowired 24 | private CambioRepository repository; 25 | 26 | @GetMapping(value = "/{amount}/{from}/{to}") 27 | public Cambio getCambio( 28 | @PathVariable("amount") BigDecimal amount, 29 | @PathVariable("from") String from, 30 | @PathVariable("to") String to 31 | ) { 32 | 33 | var cambio = repository.findByFromAndTo(from, to); 34 | if (cambio == null) throw new RuntimeException("Currency Unsupported"); 35 | 36 | var port = environment.getProperty("local.server.port"); 37 | BigDecimal conversionFactor = cambio.getConversionFactor(); 38 | BigDecimal convertedValue = conversionFactor.multiply(amount); 39 | cambio.setConvertedValue(convertedValue.setScale(2, RoundingMode.CEILING)); 40 | cambio.setEnvironment(port); 41 | return cambio; 42 | } 43 | } -------------------------------------------------------------------------------- /05-cambio-service/src/main/java/br/com/erudio/repository/CambioRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Cambio; 6 | 7 | public interface CambioRepository extends JpaRepository { 8 | 9 | Cambio findByFromAndTo(String from, String to); 10 | 11 | } -------------------------------------------------------------------------------- /05-cambio-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | application: 5 | name: cambio-service 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/cambio_service?useTimezone=true&serverTimezone=UTC 9 | username: root 10 | password: admin123 11 | jpa: 12 | hibernate: 13 | ddl-auto: update 14 | show-sql: true 15 | properties: 16 | hibernate: 17 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 18 | flyway: 19 | url: jdbc:mysql://localhost:3306/ 20 | schemas: cambio_service 21 | user: root 22 | password: admin123 -------------------------------------------------------------------------------- /05-cambio-service/src/main/resources/db/migration/V1__Create_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `cambio` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `from_currency` CHAR(3) NOT NULL, 4 | `to_currency` CHAR(3) NOT NULL, 5 | `conversion_factor` decimal(65,2) NOT NULL 6 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 7 | -------------------------------------------------------------------------------- /05-cambio-service/src/main/resources/db/migration/V2__Populate_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `cambio` (`from_currency`, `to_currency`, `conversion_factor`) VALUES 2 | ('USD', 'BRL', 5.73), 3 | ('USD', 'EUR', 0.84), 4 | ('USD', 'GBP', 0.73), 5 | ('USD', 'ARS', 92.56), 6 | ('USD', 'CLP', 713.30), 7 | ('USD', 'COP', 3665.00), 8 | ('USD', 'MXN', 20.15); -------------------------------------------------------------------------------- /05-cambio-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06-api-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /06-api-gateway/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/06-api-gateway/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /06-api-gateway/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /06-api-gateway/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06-api-gateway/src/main/java/br/com/erudio/configuration/ApiGatewayConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.cloud.gateway.route.RouteLocator; 4 | import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class ApiGatewayConfiguration { 10 | 11 | @Bean 12 | public RouteLocator gatewayRouter(RouteLocatorBuilder builder) { 13 | return builder.routes() 14 | .route(p -> p.path("/get") 15 | .filters(f -> f 16 | .addRequestHeader("Hello", "World") 17 | .addRequestParameter("Hello", "World")) 18 | .uri("http://httpbin.org:80")) 19 | .route(p -> p.path("/cambio-service/**") 20 | .uri("lb://cambio-service")) 21 | .route(p -> p.path("/book-service/**") 22 | .uri("lb://book-service")) 23 | .build(); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /06-api-gateway/src/main/java/br/com/erudio/filter/LoggingFilter.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 6 | import org.springframework.cloud.gateway.filter.GlobalFilter; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.server.ServerWebExchange; 9 | 10 | import reactor.core.publisher.Mono; 11 | 12 | @Component 13 | public class LoggingFilter implements GlobalFilter{ 14 | 15 | private Logger logger = LoggerFactory.getLogger(LoggingFilter.class); 16 | 17 | @Override 18 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 19 | logger.info("Original request path -> {}", exchange.getRequest().getPath()); 20 | return chain.filter(exchange); 21 | } 22 | } -------------------------------------------------------------------------------- /06-api-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8765 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: api-gateway 10 | #cloud: 11 | #gateway: 12 | #discovery: 13 | #locator: 14 | #enabled: true 15 | #lower-case-service-id: true -------------------------------------------------------------------------------- /06-api-gateway/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06-book-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /06-book-service/src/main/java/br/com/erudio/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.core.env.Environment; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import br.com.erudio.model.Book; 11 | import br.com.erudio.proxy.CambioProxy; 12 | import br.com.erudio.repository.BookRepository; 13 | 14 | @RestController 15 | @RequestMapping("book-service") 16 | public class BookController { 17 | 18 | @Autowired 19 | private Environment environment; 20 | 21 | @Autowired 22 | private BookRepository repository; 23 | 24 | @Autowired 25 | private CambioProxy proxy; 26 | 27 | @GetMapping(value = "/{id}/{currency}") 28 | public Book findBook( 29 | @PathVariable("id") Long id, 30 | @PathVariable("currency") String currency 31 | ) { 32 | 33 | var book = repository.getById(id); 34 | if (book == null) throw new RuntimeException("Book not Found"); 35 | 36 | var cambio = proxy.getCambio(book.getPrice(), "USD", currency); 37 | 38 | var port = environment.getProperty("local.server.port"); 39 | book.setEnvironment( 40 | "Book port: " + port + 41 | " Cambio Port " + cambio.getEnvironment()); 42 | book.setPrice(cambio.getConvertedValue()); 43 | return book; 44 | } 45 | 46 | /**@GetMapping(value = "/{id}/{currency}") 47 | public Book findBook( 48 | @PathVariable("id") Long id, 49 | @PathVariable("currency") String currency 50 | ) { 51 | 52 | var book = repository.getById(id); 53 | if (book == null) throw new RuntimeException("Book not Found"); 54 | 55 | HashMap params = new HashMap<>(); 56 | params.put("amount", book.getPrice().toString()); 57 | params.put("from", "USD"); 58 | params.put("to", currency); 59 | 60 | var response = new RestTemplate() 61 | .getForEntity("http://localhost:8000/cambio-service/" 62 | + "{amount}/{from}/{to}", 63 | Cambio.class, 64 | params); 65 | 66 | var cambio = response.getBody(); 67 | 68 | var port = environment.getProperty("local.server.port"); 69 | book.setEnvironment(port); 70 | book.setPrice(cambio.getConvertedValue()); 71 | return book; 72 | }*/ 73 | } 74 | -------------------------------------------------------------------------------- /06-book-service/src/main/java/br/com/erudio/proxy/CambioProxy.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.proxy; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | 7 | import br.com.erudio.response.Cambio; 8 | 9 | @FeignClient(name = "cambio-service") 10 | public interface CambioProxy { 11 | 12 | @GetMapping(value = "/cambio-service/{amount}/{from}/{to}") 13 | public Cambio getCambio( 14 | @PathVariable("amount") Double amount, 15 | @PathVariable("from") String from, 16 | @PathVariable("to") String to 17 | ); 18 | } -------------------------------------------------------------------------------- /06-book-service/src/main/java/br/com/erudio/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Book; 6 | 7 | public interface BookRepository extends JpaRepository{} -------------------------------------------------------------------------------- /06-book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8100 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: book-service 10 | datasource: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | url: jdbc:mysql://localhost:3306/book_service?useTimezone=true&serverTimezone=UTC 13 | username: root 14 | password: admin123 15 | jackson: 16 | default-property-inclusion: NON_NULL 17 | serialization: 18 | fail-on-empty-beans: false 19 | jpa: 20 | hibernate: 21 | ddl-auto: update 22 | show-sql: true 23 | properties: 24 | hibernate: 25 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 26 | flyway: 27 | url: jdbc:mysql://localhost:3306/ 28 | schemas: book_service 29 | user: root 30 | password: admin123 31 | -------------------------------------------------------------------------------- /06-book-service/src/main/resources/db/migration/V1__Create_Table_Books.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `book` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `author` longtext, 4 | `launch_date` datetime(6) NOT NULL, 5 | `price` decimal(65,2) NOT NULL, 6 | `title` longtext 7 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 8 | -------------------------------------------------------------------------------- /06-book-service/src/main/resources/db/migration/V2__Insert_Data_In_Books.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `book` (`author`, `launch_date`, `price`, `title`) VALUES 2 | ('Michael C. Feathers', '2017-11-29 13:50:05.878000', 8.57, 'Working effectively with legacy code'), 3 | ('Ralph Johnson, Erich Gamma, John Vlissides e Richard Helm', '2017-11-29 15:15:13.636000', 7.87, 'Design Patterns'), 4 | ('Robert C. Martin', '2009-01-10 00:00:00.000000', 13.46, 'Clean Code'), 5 | ('Crockford', '2017-11-07 15:09:01.674000', 11.71, 'JavaScript'), 6 | ('Steve McConnell', '2017-11-07 15:09:01.674000', 10.14, 'Code complete'), 7 | ('Martin Fowler e Kent Beck', '2017-11-07 15:09:01.674000', 15.38, 'Refactoring'), 8 | ('Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates', '2017-11-07 15:09:01.674000', 19.23, 'Head First Design Patterns'), 9 | ('Eric Evans', '2017-11-07 15:09:01.674000', 16.09, 'Domain Driven Design'), 10 | ('Brian Goetz e Tim Peierls', '2017-11-07 15:09:01.674000', 13.99, 'Java Concurrency in Practice'), 11 | ('Susan Cain', '2017-11-07 15:09:01.674000', 21.51, 'O poder dos quietos'), 12 | ('Roger S. Pressman', '2017-11-07 15:09:01.674000', 9.79, 'Engenharia de Software: uma abordagem profissional'), 13 | ('Viktor Mayer-Schonberger e Kenneth Kukier', '2017-11-07 15:09:01.674000', 9.44, 'Big Data: como extrair volume, variedade, velocidade e valor da avalanche de informação cotidiana'), 14 | ('Richard Hunter e George Westerman', '2017-11-07 15:09:01.674000', 16.61, 'O verdadeiro valor de TI'), 15 | ('Marc J. Schiller', '2017-11-07 15:09:01.674000', 7.87, 'Os 11 segredos de líderes de TI altamente influentes'), 16 | ('Aguinaldo Aragon Fernandes e Vladimir Ferraz de Abreu', '2017-11-07 15:09:01.674000', 9.44, 'Implantando a governança de TI'); -------------------------------------------------------------------------------- /06-book-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06-cambio-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06-cambio-service/src/main/java/br/com/erudio/controller/CambioController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.core.env.Environment; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import br.com.erudio.model.Cambio; 14 | import br.com.erudio.repository.CambioRepository; 15 | 16 | @RestController 17 | @RequestMapping("cambio-service") 18 | public class CambioController { 19 | 20 | @Autowired 21 | private Environment environment; 22 | 23 | @Autowired 24 | private CambioRepository repository; 25 | 26 | @GetMapping(value = "/{amount}/{from}/{to}") 27 | public Cambio getCambio( 28 | @PathVariable("amount") BigDecimal amount, 29 | @PathVariable("from") String from, 30 | @PathVariable("to") String to 31 | ) { 32 | 33 | var cambio = repository.findByFromAndTo(from, to); 34 | if (cambio == null) throw new RuntimeException("Currency Unsupported"); 35 | 36 | var port = environment.getProperty("local.server.port"); 37 | BigDecimal conversionFactor = cambio.getConversionFactor(); 38 | BigDecimal convertedValue = conversionFactor.multiply(amount); 39 | cambio.setConvertedValue(convertedValue.setScale(2, RoundingMode.CEILING)); 40 | cambio.setEnvironment(port); 41 | return cambio; 42 | } 43 | } -------------------------------------------------------------------------------- /06-cambio-service/src/main/java/br/com/erudio/repository/CambioRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Cambio; 6 | 7 | public interface CambioRepository extends JpaRepository { 8 | 9 | Cambio findByFromAndTo(String from, String to); 10 | 11 | } -------------------------------------------------------------------------------- /06-cambio-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: cambio-service 10 | datasource: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | url: jdbc:mysql://localhost:3306/cambio_service?useTimezone=true&serverTimezone=UTC 13 | username: root 14 | password: admin123 15 | jpa: 16 | hibernate: 17 | ddl-auto: update 18 | show-sql: true 19 | properties: 20 | hibernate: 21 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 22 | flyway: 23 | url: jdbc:mysql://localhost:3306/ 24 | schemas: cambio_service 25 | user: root 26 | password: admin123 -------------------------------------------------------------------------------- /06-cambio-service/src/main/resources/db/migration/V1__Create_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `cambio` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `from_currency` CHAR(3) NOT NULL, 4 | `to_currency` CHAR(3) NOT NULL, 5 | `conversion_factor` decimal(65,2) NOT NULL 6 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 7 | -------------------------------------------------------------------------------- /06-cambio-service/src/main/resources/db/migration/V2__Populate_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `cambio` (`from_currency`, `to_currency`, `conversion_factor`) VALUES 2 | ('USD', 'BRL', 5.73), 3 | ('USD', 'EUR', 0.84), 4 | ('USD', 'GBP', 0.73), 5 | ('USD', 'ARS', 92.56), 6 | ('USD', 'CLP', 713.30), 7 | ('USD', 'COP', 3665.00), 8 | ('USD', 'MXN', 20.15); -------------------------------------------------------------------------------- /06-cambio-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06-naming-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /06-naming-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/06-naming-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /06-naming-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /06-naming-server/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 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 Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /06-naming-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: naming-server 6 | eureka: 7 | client: 8 | register-with-eureka: false 9 | fetch-registry: false 10 | -------------------------------------------------------------------------------- /06-naming-server/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-api-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /07-api-gateway/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/07-api-gateway/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /07-api-gateway/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /07-api-gateway/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-api-gateway/src/main/java/br/com/erudio/configuration/ApiGatewayConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.cloud.gateway.route.RouteLocator; 4 | import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class ApiGatewayConfiguration { 10 | 11 | @Bean 12 | public RouteLocator gatewayRouter(RouteLocatorBuilder builder) { 13 | return builder.routes() 14 | .route(p -> p.path("/get") 15 | .filters(f -> f 16 | .addRequestHeader("Hello", "World") 17 | .addRequestParameter("Hello", "World")) 18 | .uri("http://httpbin.org:80")) 19 | .route(p -> p.path("/cambio-service/**") 20 | .uri("lb://cambio-service")) 21 | .route(p -> p.path("/book-service/**") 22 | .uri("lb://book-service")) 23 | .build(); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /07-api-gateway/src/main/java/br/com/erudio/filter/LoggingFilter.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 6 | import org.springframework.cloud.gateway.filter.GlobalFilter; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.server.ServerWebExchange; 9 | 10 | import reactor.core.publisher.Mono; 11 | 12 | @Component 13 | public class LoggingFilter implements GlobalFilter{ 14 | 15 | private Logger logger = LoggerFactory.getLogger(LoggingFilter.class); 16 | 17 | @Override 18 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 19 | // logger.info("Original request path -> {}", exchange.getRequest().getPath()); 20 | return chain.filter(exchange); 21 | } 22 | } -------------------------------------------------------------------------------- /07-api-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8765 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: api-gateway 10 | #cloud: 11 | #gateway: 12 | #discovery: 13 | #locator: 14 | #enabled: true 15 | #lower-case-service-id: true -------------------------------------------------------------------------------- /07-api-gateway/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-book-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /07-book-service/src/main/java/br/com/erudio/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.core.env.Environment; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import br.com.erudio.model.Book; 11 | import br.com.erudio.proxy.CambioProxy; 12 | import br.com.erudio.repository.BookRepository; 13 | 14 | @RestController 15 | @RequestMapping("book-service") 16 | public class BookController { 17 | 18 | @Autowired 19 | private Environment environment; 20 | 21 | @Autowired 22 | private BookRepository repository; 23 | 24 | @Autowired 25 | private CambioProxy proxy; 26 | 27 | @GetMapping(value = "/{id}/{currency}") 28 | public Book findBook( 29 | @PathVariable("id") Long id, 30 | @PathVariable("currency") String currency 31 | ) { 32 | 33 | var book = repository.getById(id); 34 | if (book == null) throw new RuntimeException("Book not Found"); 35 | 36 | var cambio = proxy.getCambio(book.getPrice(), "USD", currency); 37 | 38 | var port = environment.getProperty("local.server.port"); 39 | book.setEnvironment( 40 | "Book port: " + port + 41 | " Cambio Port " + cambio.getEnvironment()); 42 | book.setPrice(cambio.getConvertedValue()); 43 | return book; 44 | } 45 | 46 | /**@GetMapping(value = "/{id}/{currency}") 47 | public Book findBook( 48 | @PathVariable("id") Long id, 49 | @PathVariable("currency") String currency 50 | ) { 51 | 52 | var book = repository.getById(id); 53 | if (book == null) throw new RuntimeException("Book not Found"); 54 | 55 | HashMap params = new HashMap<>(); 56 | params.put("amount", book.getPrice().toString()); 57 | params.put("from", "USD"); 58 | params.put("to", currency); 59 | 60 | var response = new RestTemplate() 61 | .getForEntity("http://localhost:8000/cambio-service/" 62 | + "{amount}/{from}/{to}", 63 | Cambio.class, 64 | params); 65 | 66 | var cambio = response.getBody(); 67 | 68 | var port = environment.getProperty("local.server.port"); 69 | book.setEnvironment(port); 70 | book.setPrice(cambio.getConvertedValue()); 71 | return book; 72 | }*/ 73 | } 74 | -------------------------------------------------------------------------------- /07-book-service/src/main/java/br/com/erudio/controller/FooBarController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import io.github.resilience4j.bulkhead.annotation.Bulkhead; 10 | 11 | @RestController 12 | @RequestMapping("book-service") 13 | public class FooBarController { 14 | 15 | private Logger logger = LoggerFactory.getLogger(FooBarController.class); 16 | 17 | @GetMapping("/foo-bar") 18 | //@Retry(name = "foo-bar", fallbackMethod = "fallbackMethod") 19 | //@CircuitBreaker(name = "default", fallbackMethod = "fallbackMethod") 20 | //@RateLimiter(name = "default") 21 | @Bulkhead(name = "default") 22 | public String fooBar() { 23 | logger.info("Request to foo-bar is received!"); 24 | /* 25 | * var response = new RestTemplate() 26 | * .getForEntity("http://localhost:8080/foo-bar", String.class); 27 | */ 28 | return "Foo-Bar!!!"; 29 | //return response.getBody(); 30 | } 31 | 32 | public String fallbackMethod(Exception ex) { 33 | return "fallbackMethod foo-bar!!!"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /07-book-service/src/main/java/br/com/erudio/proxy/CambioProxy.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.proxy; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | 7 | import br.com.erudio.response.Cambio; 8 | 9 | @FeignClient(name = "cambio-service") 10 | public interface CambioProxy { 11 | 12 | @GetMapping(value = "/cambio-service/{amount}/{from}/{to}") 13 | public Cambio getCambio( 14 | @PathVariable("amount") Double amount, 15 | @PathVariable("from") String from, 16 | @PathVariable("to") String to 17 | ); 18 | } -------------------------------------------------------------------------------- /07-book-service/src/main/java/br/com/erudio/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Book; 6 | 7 | public interface BookRepository extends JpaRepository{} -------------------------------------------------------------------------------- /07-book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8100 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | resilience4j: 8 | bulkhead: 9 | instances: 10 | default: 11 | max-concurrent-calls: 10 12 | ratelimiter: 13 | instances: 14 | default: 15 | limit-for-period: 2 16 | limit-refresh-period: 10s 17 | retry: 18 | instances: 19 | foo-bar: 20 | max-attempts: 5 21 | wait-duration: 1s 22 | enable-exponential-backoff: true 23 | spring: 24 | application: 25 | name: book-service 26 | datasource: 27 | driver-class-name: com.mysql.cj.jdbc.Driver 28 | url: jdbc:mysql://localhost:3306/book_service?useTimezone=true&serverTimezone=UTC 29 | username: root 30 | password: admin123 31 | jackson: 32 | default-property-inclusion: NON_NULL 33 | serialization: 34 | fail-on-empty-beans: false 35 | jpa: 36 | hibernate: 37 | ddl-auto: update 38 | show-sql: true 39 | properties: 40 | hibernate: 41 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 42 | flyway: 43 | url: jdbc:mysql://localhost:3306/ 44 | schemas: book_service 45 | user: root 46 | password: admin123 47 | -------------------------------------------------------------------------------- /07-book-service/src/main/resources/db/migration/V1__Create_Table_Books.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `book` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `author` longtext, 4 | `launch_date` datetime(6) NOT NULL, 5 | `price` decimal(65,2) NOT NULL, 6 | `title` longtext 7 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 8 | -------------------------------------------------------------------------------- /07-book-service/src/main/resources/db/migration/V2__Insert_Data_In_Books.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `book` (`author`, `launch_date`, `price`, `title`) VALUES 2 | ('Michael C. Feathers', '2017-11-29 13:50:05.878000', 8.57, 'Working effectively with legacy code'), 3 | ('Ralph Johnson, Erich Gamma, John Vlissides e Richard Helm', '2017-11-29 15:15:13.636000', 7.87, 'Design Patterns'), 4 | ('Robert C. Martin', '2009-01-10 00:00:00.000000', 13.46, 'Clean Code'), 5 | ('Crockford', '2017-11-07 15:09:01.674000', 11.71, 'JavaScript'), 6 | ('Steve McConnell', '2017-11-07 15:09:01.674000', 10.14, 'Code complete'), 7 | ('Martin Fowler e Kent Beck', '2017-11-07 15:09:01.674000', 15.38, 'Refactoring'), 8 | ('Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates', '2017-11-07 15:09:01.674000', 19.23, 'Head First Design Patterns'), 9 | ('Eric Evans', '2017-11-07 15:09:01.674000', 16.09, 'Domain Driven Design'), 10 | ('Brian Goetz e Tim Peierls', '2017-11-07 15:09:01.674000', 13.99, 'Java Concurrency in Practice'), 11 | ('Susan Cain', '2017-11-07 15:09:01.674000', 21.51, 'O poder dos quietos'), 12 | ('Roger S. Pressman', '2017-11-07 15:09:01.674000', 9.79, 'Engenharia de Software: uma abordagem profissional'), 13 | ('Viktor Mayer-Schonberger e Kenneth Kukier', '2017-11-07 15:09:01.674000', 9.44, 'Big Data: como extrair volume, variedade, velocidade e valor da avalanche de informação cotidiana'), 14 | ('Richard Hunter e George Westerman', '2017-11-07 15:09:01.674000', 16.61, 'O verdadeiro valor de TI'), 15 | ('Marc J. Schiller', '2017-11-07 15:09:01.674000', 7.87, 'Os 11 segredos de líderes de TI altamente influentes'), 16 | ('Aguinaldo Aragon Fernandes e Vladimir Ferraz de Abreu', '2017-11-07 15:09:01.674000', 9.44, 'Implantando a governança de TI'); -------------------------------------------------------------------------------- /07-book-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-cambio-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-cambio-service/src/main/java/br/com/erudio/controller/CambioController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.core.env.Environment; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import br.com.erudio.model.Cambio; 14 | import br.com.erudio.repository.CambioRepository; 15 | 16 | @RestController 17 | @RequestMapping("cambio-service") 18 | public class CambioController { 19 | 20 | @Autowired 21 | private Environment environment; 22 | 23 | @Autowired 24 | private CambioRepository repository; 25 | 26 | @GetMapping(value = "/{amount}/{from}/{to}") 27 | public Cambio getCambio( 28 | @PathVariable("amount") BigDecimal amount, 29 | @PathVariable("from") String from, 30 | @PathVariable("to") String to 31 | ) { 32 | 33 | var cambio = repository.findByFromAndTo(from, to); 34 | if (cambio == null) throw new RuntimeException("Currency Unsupported"); 35 | 36 | var port = environment.getProperty("local.server.port"); 37 | BigDecimal conversionFactor = cambio.getConversionFactor(); 38 | BigDecimal convertedValue = conversionFactor.multiply(amount); 39 | cambio.setConvertedValue(convertedValue.setScale(2, RoundingMode.CEILING)); 40 | cambio.setEnvironment(port); 41 | return cambio; 42 | } 43 | } -------------------------------------------------------------------------------- /07-cambio-service/src/main/java/br/com/erudio/repository/CambioRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Cambio; 6 | 7 | public interface CambioRepository extends JpaRepository { 8 | 9 | Cambio findByFromAndTo(String from, String to); 10 | 11 | } -------------------------------------------------------------------------------- /07-cambio-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: cambio-service 10 | datasource: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | url: jdbc:mysql://localhost:3306/cambio_service?useTimezone=true&serverTimezone=UTC 13 | username: root 14 | password: admin123 15 | jpa: 16 | hibernate: 17 | ddl-auto: update 18 | show-sql: true 19 | properties: 20 | hibernate: 21 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 22 | flyway: 23 | url: jdbc:mysql://localhost:3306/ 24 | schemas: cambio_service 25 | user: root 26 | password: admin123 -------------------------------------------------------------------------------- /07-cambio-service/src/main/resources/db/migration/V1__Create_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `cambio` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `from_currency` CHAR(3) NOT NULL, 4 | `to_currency` CHAR(3) NOT NULL, 5 | `conversion_factor` decimal(65,2) NOT NULL 6 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 7 | -------------------------------------------------------------------------------- /07-cambio-service/src/main/resources/db/migration/V2__Populate_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `cambio` (`from_currency`, `to_currency`, `conversion_factor`) VALUES 2 | ('USD', 'BRL', 5.73), 3 | ('USD', 'EUR', 0.84), 4 | ('USD', 'GBP', 0.73), 5 | ('USD', 'ARS', 92.56), 6 | ('USD', 'CLP', 713.30), 7 | ('USD', 'COP', 3665.00), 8 | ('USD', 'MXN', 20.15); -------------------------------------------------------------------------------- /07-cambio-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07-naming-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /07-naming-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/07-naming-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /07-naming-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /07-naming-server/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 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 Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /07-naming-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: naming-server 6 | eureka: 7 | client: 8 | register-with-eureka: false 9 | fetch-registry: false 10 | -------------------------------------------------------------------------------- /07-naming-server/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-api-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /08-api-gateway/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/08-api-gateway/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /08-api-gateway/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /08-api-gateway/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-api-gateway/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springdoc.core.GroupedOpenApi; 7 | import org.springdoc.core.SwaggerUiConfigParameters; 8 | import org.springframework.cloud.gateway.route.RouteDefinitionLocator; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.context.annotation.Lazy; 12 | 13 | @Configuration 14 | public class OpenApiConfiguration { 15 | 16 | @Bean 17 | @Lazy(false) 18 | public List apis( 19 | SwaggerUiConfigParameters config, 20 | RouteDefinitionLocator locator) { 21 | 22 | var definitions = locator.getRouteDefinitions().collectList().block(); 23 | 24 | definitions.stream().filter( 25 | routeDefinition -> routeDefinition.getId() 26 | .matches(".*-service")) 27 | .forEach(routeDefinition -> { 28 | String name = routeDefinition.getId(); 29 | config.addGroup(name); 30 | GroupedOpenApi.builder() 31 | .pathsToMatch("/" + name + "/**") 32 | .group(name).build(); 33 | } 34 | ); 35 | return new ArrayList<>(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /08-api-gateway/src/main/java/br/com/erudio/filter/LoggingFilter.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 6 | import org.springframework.cloud.gateway.filter.GlobalFilter; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.server.ServerWebExchange; 9 | 10 | import reactor.core.publisher.Mono; 11 | 12 | @Component 13 | public class LoggingFilter implements GlobalFilter{ 14 | 15 | private Logger logger = LoggerFactory.getLogger(LoggingFilter.class); 16 | 17 | @Override 18 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 19 | logger.debug("Original request path -> {}", exchange.getRequest().getPath()); 20 | return chain.filter(exchange); 21 | } 22 | } -------------------------------------------------------------------------------- /08-api-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8765 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: api-gateway 10 | cloud: 11 | gateway: 12 | discovery: 13 | locator: 14 | enabled: true 15 | routes: 16 | - id: cambio-service 17 | uri: lb://cambio-service 18 | predicates: 19 | - Path=/cambio-service/** 20 | - id: book-service 21 | uri: lb://book-service 22 | predicates: 23 | - Path=/book-service/** 24 | - id: openapi 25 | uri: lb://api-gateway 26 | predicates: 27 | - Path=/v3/api-docs/** 28 | filters: 29 | - RewritePath=/v3/api-docs/(?.*), /$\{path}/v3/api-docs -------------------------------------------------------------------------------- /08-api-gateway/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-book-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /08-book-service/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import io.swagger.v3.oas.annotations.OpenAPIDefinition; 6 | import io.swagger.v3.oas.annotations.info.Info; 7 | import io.swagger.v3.oas.models.Components; 8 | import io.swagger.v3.oas.models.OpenAPI; 9 | import io.swagger.v3.oas.models.info.License; 10 | 11 | @OpenAPIDefinition(info = 12 | @Info(title = "Book Service API", 13 | version = "v1", 14 | description = "Documentation of Book Service API")) 15 | public class OpenApiConfiguration { 16 | 17 | @Bean 18 | public OpenAPI customOpenAPI() { 19 | return new OpenAPI() 20 | .components(new Components()) 21 | .info( 22 | new io.swagger.v3.oas.models.info.Info() 23 | .title("Book Service API") 24 | .version("v1") 25 | .license( 26 | new License() 27 | .name("Apache 2.0") 28 | .url("http://springdoc.org") 29 | ) 30 | ); 31 | } 32 | } -------------------------------------------------------------------------------- /08-book-service/src/main/java/br/com/erudio/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.core.env.Environment; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import br.com.erudio.model.Book; 11 | import br.com.erudio.proxy.CambioProxy; 12 | import br.com.erudio.repository.BookRepository; 13 | import io.swagger.v3.oas.annotations.Operation; 14 | import io.swagger.v3.oas.annotations.tags.Tag; 15 | 16 | @Tag(name = "Book endpoint") 17 | @RestController 18 | @RequestMapping("book-service") 19 | public class BookController { 20 | 21 | @Autowired 22 | private Environment environment; 23 | 24 | @Autowired 25 | private BookRepository repository; 26 | 27 | @Autowired 28 | private CambioProxy proxy; 29 | 30 | @Operation(summary = "Find a specific book by your ID") 31 | @GetMapping(value = "/{id}/{currency}") 32 | public Book findBook( 33 | @PathVariable("id") Long id, 34 | @PathVariable("currency") String currency 35 | ) { 36 | 37 | var book = repository.getById(id); 38 | if (book == null) throw new RuntimeException("Book not Found"); 39 | 40 | var cambio = proxy.getCambio(book.getPrice(), "USD", currency); 41 | 42 | var port = environment.getProperty("local.server.port"); 43 | book.setEnvironment( 44 | "Book port: " + port + 45 | " Cambio Port " + cambio.getEnvironment()); 46 | book.setPrice(cambio.getConvertedValue()); 47 | return book; 48 | } 49 | 50 | /**@GetMapping(value = "/{id}/{currency}") 51 | public Book findBook( 52 | @PathVariable("id") Long id, 53 | @PathVariable("currency") String currency 54 | ) { 55 | 56 | var book = repository.getById(id); 57 | if (book == null) throw new RuntimeException("Book not Found"); 58 | 59 | HashMap params = new HashMap<>(); 60 | params.put("amount", book.getPrice().toString()); 61 | params.put("from", "USD"); 62 | params.put("to", currency); 63 | 64 | var response = new RestTemplate() 65 | .getForEntity("http://localhost:8000/cambio-service/" 66 | + "{amount}/{from}/{to}", 67 | Cambio.class, 68 | params); 69 | 70 | var cambio = response.getBody(); 71 | 72 | var port = environment.getProperty("local.server.port"); 73 | book.setEnvironment(port); 74 | book.setPrice(cambio.getConvertedValue()); 75 | return book; 76 | }*/ 77 | } 78 | -------------------------------------------------------------------------------- /08-book-service/src/main/java/br/com/erudio/controller/FooBarController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import io.github.resilience4j.bulkhead.annotation.Bulkhead; 10 | import io.swagger.v3.oas.annotations.Operation; 11 | import io.swagger.v3.oas.annotations.tags.Tag; 12 | 13 | @Tag(name = "Foo bar") 14 | @RestController 15 | @RequestMapping("book-service") 16 | public class FooBarController { 17 | 18 | private Logger logger = LoggerFactory.getLogger(FooBarController.class); 19 | 20 | @GetMapping("/foo-bar") 21 | @Operation(summary = "Foo bar") 22 | //@Retry(name = "foo-bar", fallbackMethod = "fallbackMethod") 23 | //@CircuitBreaker(name = "default", fallbackMethod = "fallbackMethod") 24 | //@RateLimiter(name = "default") 25 | @Bulkhead(name = "default") 26 | public String fooBar() { 27 | logger.info("Request to foo-bar is received!"); 28 | /* 29 | * var response = new RestTemplate() 30 | * .getForEntity("http://localhost:8080/foo-bar", String.class); 31 | */ 32 | return "Foo-Bar!!!"; 33 | //return response.getBody(); 34 | } 35 | 36 | public String fallbackMethod(Exception ex) { 37 | return "fallbackMethod foo-bar!!!"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /08-book-service/src/main/java/br/com/erudio/proxy/CambioProxy.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.proxy; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | 7 | import br.com.erudio.response.Cambio; 8 | 9 | @FeignClient(name = "cambio-service") 10 | public interface CambioProxy { 11 | 12 | @GetMapping(value = "/cambio-service/{amount}/{from}/{to}") 13 | public Cambio getCambio( 14 | @PathVariable("amount") Double amount, 15 | @PathVariable("from") String from, 16 | @PathVariable("to") String to 17 | ); 18 | } -------------------------------------------------------------------------------- /08-book-service/src/main/java/br/com/erudio/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Book; 6 | 7 | public interface BookRepository extends JpaRepository{} -------------------------------------------------------------------------------- /08-book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8100 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | resilience4j: 8 | bulkhead: 9 | instances: 10 | default: 11 | max-concurrent-calls: 10 12 | ratelimiter: 13 | instances: 14 | default: 15 | limit-for-period: 2 16 | limit-refresh-period: 10s 17 | retry: 18 | instances: 19 | foo-bar: 20 | max-attempts: 5 21 | wait-duration: 1s 22 | enable-exponential-backoff: true 23 | spring: 24 | application: 25 | name: book-service 26 | datasource: 27 | driver-class-name: com.mysql.cj.jdbc.Driver 28 | url: jdbc:mysql://localhost:3306/book_service?useTimezone=true&serverTimezone=UTC 29 | username: root 30 | password: admin123 31 | jackson: 32 | default-property-inclusion: NON_NULL 33 | serialization: 34 | fail-on-empty-beans: false 35 | jpa: 36 | hibernate: 37 | ddl-auto: update 38 | show-sql: true 39 | properties: 40 | hibernate: 41 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 42 | flyway: 43 | url: jdbc:mysql://localhost:3306/ 44 | schemas: book_service 45 | user: root 46 | password: admin123 47 | springdoc: 48 | show-actuator: true 49 | api-docs: 50 | path: book-service/v3/api-docs 51 | -------------------------------------------------------------------------------- /08-book-service/src/main/resources/db/migration/V1__Create_Table_Books.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `book` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `author` longtext, 4 | `launch_date` datetime(6) NOT NULL, 5 | `price` decimal(65,2) NOT NULL, 6 | `title` longtext 7 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 8 | -------------------------------------------------------------------------------- /08-book-service/src/main/resources/db/migration/V2__Insert_Data_In_Books.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `book` (`author`, `launch_date`, `price`, `title`) VALUES 2 | ('Michael C. Feathers', '2017-11-29 13:50:05.878000', 8.57, 'Working effectively with legacy code'), 3 | ('Ralph Johnson, Erich Gamma, John Vlissides e Richard Helm', '2017-11-29 15:15:13.636000', 7.87, 'Design Patterns'), 4 | ('Robert C. Martin', '2009-01-10 00:00:00.000000', 13.46, 'Clean Code'), 5 | ('Crockford', '2017-11-07 15:09:01.674000', 11.71, 'JavaScript'), 6 | ('Steve McConnell', '2017-11-07 15:09:01.674000', 10.14, 'Code complete'), 7 | ('Martin Fowler e Kent Beck', '2017-11-07 15:09:01.674000', 15.38, 'Refactoring'), 8 | ('Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates', '2017-11-07 15:09:01.674000', 19.23, 'Head First Design Patterns'), 9 | ('Eric Evans', '2017-11-07 15:09:01.674000', 16.09, 'Domain Driven Design'), 10 | ('Brian Goetz e Tim Peierls', '2017-11-07 15:09:01.674000', 13.99, 'Java Concurrency in Practice'), 11 | ('Susan Cain', '2017-11-07 15:09:01.674000', 21.51, 'O poder dos quietos'), 12 | ('Roger S. Pressman', '2017-11-07 15:09:01.674000', 9.79, 'Engenharia de Software: uma abordagem profissional'), 13 | ('Viktor Mayer-Schonberger e Kenneth Kukier', '2017-11-07 15:09:01.674000', 9.44, 'Big Data: como extrair volume, variedade, velocidade e valor da avalanche de informação cotidiana'), 14 | ('Richard Hunter e George Westerman', '2017-11-07 15:09:01.674000', 16.61, 'O verdadeiro valor de TI'), 15 | ('Marc J. Schiller', '2017-11-07 15:09:01.674000', 7.87, 'Os 11 segredos de líderes de TI altamente influentes'), 16 | ('Aguinaldo Aragon Fernandes e Vladimir Ferraz de Abreu', '2017-11-07 15:09:01.674000', 9.44, 'Implantando a governança de TI'); -------------------------------------------------------------------------------- /08-book-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-cambio-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-cambio-service/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import io.swagger.v3.oas.annotations.OpenAPIDefinition; 6 | import io.swagger.v3.oas.annotations.info.Info; 7 | import io.swagger.v3.oas.models.Components; 8 | import io.swagger.v3.oas.models.OpenAPI; 9 | import io.swagger.v3.oas.models.info.License; 10 | 11 | @OpenAPIDefinition(info = 12 | @Info(title = "Cambio Service API", 13 | version = "v1", 14 | description = "Documentation of Cambio Service API")) 15 | public class OpenApiConfiguration { 16 | 17 | @Bean 18 | public OpenAPI customOpenAPI() { 19 | return new OpenAPI() 20 | .components(new Components()) 21 | .info( 22 | new io.swagger.v3.oas.models.info.Info() 23 | .title("Cambio Service API") 24 | .version("v1") 25 | .license( 26 | new License() 27 | .name("Apache 2.0") 28 | .url("http://springdoc.org") 29 | ) 30 | ); 31 | } 32 | } -------------------------------------------------------------------------------- /08-cambio-service/src/main/java/br/com/erudio/controller/CambioController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.core.env.Environment; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import br.com.erudio.model.Cambio; 14 | import br.com.erudio.repository.CambioRepository; 15 | import io.swagger.v3.oas.annotations.Operation; 16 | import io.swagger.v3.oas.annotations.tags.Tag; 17 | 18 | @Tag(name = "Cambio Service API") 19 | @RestController 20 | @RequestMapping("cambio-service") 21 | public class CambioController { 22 | 23 | @Autowired 24 | private Environment environment; 25 | 26 | @Autowired 27 | private CambioRepository repository; 28 | 29 | @Operation(description = "Get cambio from currency!") 30 | @GetMapping(value = "/{amount}/{from}/{to}") 31 | public Cambio getCambio( 32 | @PathVariable("amount") BigDecimal amount, 33 | @PathVariable("from") String from, 34 | @PathVariable("to") String to 35 | ) { 36 | 37 | var cambio = repository.findByFromAndTo(from, to); 38 | if (cambio == null) throw new RuntimeException("Currency Unsupported"); 39 | 40 | var port = environment.getProperty("local.server.port"); 41 | BigDecimal conversionFactor = cambio.getConversionFactor(); 42 | BigDecimal convertedValue = conversionFactor.multiply(amount); 43 | cambio.setConvertedValue(convertedValue.setScale(2, RoundingMode.CEILING)); 44 | cambio.setEnvironment(port); 45 | return cambio; 46 | } 47 | } -------------------------------------------------------------------------------- /08-cambio-service/src/main/java/br/com/erudio/repository/CambioRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Cambio; 6 | 7 | public interface CambioRepository extends JpaRepository { 8 | 9 | Cambio findByFromAndTo(String from, String to); 10 | 11 | } -------------------------------------------------------------------------------- /08-cambio-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: cambio-service 10 | datasource: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | url: jdbc:mysql://localhost:3306/cambio_service?useTimezone=true&serverTimezone=UTC 13 | username: root 14 | password: admin123 15 | jpa: 16 | hibernate: 17 | ddl-auto: update 18 | show-sql: true 19 | properties: 20 | hibernate: 21 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 22 | flyway: 23 | url: jdbc:mysql://localhost:3306/ 24 | schemas: cambio_service 25 | user: root 26 | password: admin123 27 | springdoc: 28 | api-docs: 29 | path: cambio-service/v3/api-docs -------------------------------------------------------------------------------- /08-cambio-service/src/main/resources/db/migration/V1__Create_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `cambio` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `from_currency` CHAR(3) NOT NULL, 4 | `to_currency` CHAR(3) NOT NULL, 5 | `conversion_factor` decimal(65,2) NOT NULL 6 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 7 | -------------------------------------------------------------------------------- /08-cambio-service/src/main/resources/db/migration/V2__Populate_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `cambio` (`from_currency`, `to_currency`, `conversion_factor`) VALUES 2 | ('USD', 'BRL', 5.73), 3 | ('USD', 'EUR', 0.84), 4 | ('USD', 'GBP', 0.73), 5 | ('USD', 'ARS', 92.56), 6 | ('USD', 'CLP', 713.30), 7 | ('USD', 'COP', 3665.00), 8 | ('USD', 'MXN', 20.15); -------------------------------------------------------------------------------- /08-cambio-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /08-naming-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /08-naming-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/08-naming-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /08-naming-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /08-naming-server/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 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 Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /08-naming-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: naming-server 6 | eureka: 7 | client: 8 | register-with-eureka: false 9 | fetch-registry: false 10 | -------------------------------------------------------------------------------- /08-naming-server/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09-api-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /09-api-gateway/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/09-api-gateway/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /09-api-gateway/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /09-api-gateway/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09-api-gateway/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springdoc.core.GroupedOpenApi; 7 | import org.springdoc.core.SwaggerUiConfigParameters; 8 | import org.springframework.cloud.gateway.route.RouteDefinitionLocator; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.context.annotation.Lazy; 12 | 13 | @Configuration 14 | public class OpenApiConfiguration { 15 | 16 | @Bean 17 | @Lazy(false) 18 | public List apis( 19 | SwaggerUiConfigParameters config, 20 | RouteDefinitionLocator locator) { 21 | 22 | var definitions = locator.getRouteDefinitions().collectList().block(); 23 | 24 | definitions.stream().filter( 25 | routeDefinition -> routeDefinition.getId() 26 | .matches(".*-service")) 27 | .forEach(routeDefinition -> { 28 | String name = routeDefinition.getId(); 29 | config.addGroup(name); 30 | GroupedOpenApi.builder() 31 | .pathsToMatch("/" + name + "/**") 32 | .group(name).build(); 33 | } 34 | ); 35 | return new ArrayList<>(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /09-api-gateway/src/main/java/br/com/erudio/filter/LoggingFilter.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 6 | import org.springframework.cloud.gateway.filter.GlobalFilter; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.server.ServerWebExchange; 9 | 10 | import reactor.core.publisher.Mono; 11 | 12 | @Component 13 | public class LoggingFilter implements GlobalFilter{ 14 | 15 | private Logger logger = LoggerFactory.getLogger(LoggingFilter.class); 16 | 17 | @Override 18 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 19 | logger.debug("Original request path -> {}", exchange.getRequest().getPath()); 20 | return chain.filter(exchange); 21 | } 22 | } -------------------------------------------------------------------------------- /09-api-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8765 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: api-gateway 10 | cloud: 11 | gateway: 12 | discovery: 13 | locator: 14 | enabled: true 15 | routes: 16 | - id: cambio-service 17 | uri: lb://cambio-service 18 | predicates: 19 | - Path=/cambio-service/** 20 | - id: book-service 21 | uri: lb://book-service 22 | predicates: 23 | - Path=/book-service/** 24 | - id: openapi 25 | uri: lb://api-gateway 26 | predicates: 27 | - Path=/v3/api-docs/** 28 | filters: 29 | - RewritePath=/v3/api-docs/(?.*), /$\{path}/v3/api-docs 30 | sleuth: 31 | sampler: 32 | probability: 1.0 -------------------------------------------------------------------------------- /09-api-gateway/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09-book-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /09-book-service/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import io.swagger.v3.oas.annotations.OpenAPIDefinition; 6 | import io.swagger.v3.oas.annotations.info.Info; 7 | import io.swagger.v3.oas.models.Components; 8 | import io.swagger.v3.oas.models.OpenAPI; 9 | import io.swagger.v3.oas.models.info.License; 10 | 11 | @OpenAPIDefinition(info = 12 | @Info(title = "Book Service API", 13 | version = "v1", 14 | description = "Documentation of Book Service API")) 15 | public class OpenApiConfiguration { 16 | 17 | @Bean 18 | public OpenAPI customOpenAPI() { 19 | return new OpenAPI() 20 | .components(new Components()) 21 | .info( 22 | new io.swagger.v3.oas.models.info.Info() 23 | .title("Book Service API") 24 | .version("v1") 25 | .license( 26 | new License() 27 | .name("Apache 2.0") 28 | .url("http://springdoc.org") 29 | ) 30 | ); 31 | } 32 | } -------------------------------------------------------------------------------- /09-book-service/src/main/java/br/com/erudio/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.core.env.Environment; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import br.com.erudio.model.Book; 11 | import br.com.erudio.proxy.CambioProxy; 12 | import br.com.erudio.repository.BookRepository; 13 | import io.swagger.v3.oas.annotations.Operation; 14 | import io.swagger.v3.oas.annotations.tags.Tag; 15 | 16 | @Tag(name = "Book endpoint") 17 | @RestController 18 | @RequestMapping("book-service") 19 | public class BookController { 20 | 21 | @Autowired 22 | private Environment environment; 23 | 24 | @Autowired 25 | private BookRepository repository; 26 | 27 | @Autowired 28 | private CambioProxy proxy; 29 | 30 | @Operation(summary = "Find a specific book by your ID") 31 | @GetMapping(value = "/{id}/{currency}") 32 | public Book findBook( 33 | @PathVariable("id") Long id, 34 | @PathVariable("currency") String currency 35 | ) { 36 | 37 | var book = repository.getById(id); 38 | if (book == null) throw new RuntimeException("Book not Found"); 39 | 40 | var cambio = proxy.getCambio(book.getPrice(), "USD", currency); 41 | 42 | var port = environment.getProperty("local.server.port"); 43 | book.setEnvironment( 44 | "Book port: " + port + 45 | " Cambio Port " + cambio.getEnvironment()); 46 | book.setPrice(cambio.getConvertedValue()); 47 | return book; 48 | } 49 | 50 | /**@GetMapping(value = "/{id}/{currency}") 51 | public Book findBook( 52 | @PathVariable("id") Long id, 53 | @PathVariable("currency") String currency 54 | ) { 55 | 56 | var book = repository.getById(id); 57 | if (book == null) throw new RuntimeException("Book not Found"); 58 | 59 | HashMap params = new HashMap<>(); 60 | params.put("amount", book.getPrice().toString()); 61 | params.put("from", "USD"); 62 | params.put("to", currency); 63 | 64 | var response = new RestTemplate() 65 | .getForEntity("http://localhost:8000/cambio-service/" 66 | + "{amount}/{from}/{to}", 67 | Cambio.class, 68 | params); 69 | 70 | var cambio = response.getBody(); 71 | 72 | var port = environment.getProperty("local.server.port"); 73 | book.setEnvironment(port); 74 | book.setPrice(cambio.getConvertedValue()); 75 | return book; 76 | }*/ 77 | } 78 | -------------------------------------------------------------------------------- /09-book-service/src/main/java/br/com/erudio/controller/FooBarController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import io.github.resilience4j.bulkhead.annotation.Bulkhead; 10 | import io.swagger.v3.oas.annotations.Operation; 11 | import io.swagger.v3.oas.annotations.tags.Tag; 12 | 13 | @Tag(name = "Foo bar") 14 | @RestController 15 | @RequestMapping("book-service") 16 | public class FooBarController { 17 | 18 | private Logger logger = LoggerFactory.getLogger(FooBarController.class); 19 | 20 | @GetMapping("/foo-bar") 21 | @Operation(summary = "Foo bar") 22 | //@Retry(name = "foo-bar", fallbackMethod = "fallbackMethod") 23 | //@CircuitBreaker(name = "default", fallbackMethod = "fallbackMethod") 24 | //@RateLimiter(name = "default") 25 | @Bulkhead(name = "default") 26 | public String fooBar() { 27 | logger.info("Request to foo-bar is received!"); 28 | /* 29 | * var response = new RestTemplate() 30 | * .getForEntity("http://localhost:8080/foo-bar", String.class); 31 | */ 32 | return "Foo-Bar!!!"; 33 | //return response.getBody(); 34 | } 35 | 36 | public String fallbackMethod(Exception ex) { 37 | return "fallbackMethod foo-bar!!!"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /09-book-service/src/main/java/br/com/erudio/proxy/CambioProxy.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.proxy; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | 7 | import br.com.erudio.response.Cambio; 8 | 9 | @FeignClient(name = "cambio-service") 10 | public interface CambioProxy { 11 | 12 | @GetMapping(value = "/cambio-service/{amount}/{from}/{to}") 13 | public Cambio getCambio( 14 | @PathVariable("amount") Double amount, 15 | @PathVariable("from") String from, 16 | @PathVariable("to") String to 17 | ); 18 | } -------------------------------------------------------------------------------- /09-book-service/src/main/java/br/com/erudio/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Book; 6 | 7 | public interface BookRepository extends JpaRepository{} -------------------------------------------------------------------------------- /09-book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8100 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | resilience4j: 8 | bulkhead: 9 | instances: 10 | default: 11 | max-concurrent-calls: 10 12 | ratelimiter: 13 | instances: 14 | default: 15 | limit-for-period: 2 16 | limit-refresh-period: 10s 17 | retry: 18 | instances: 19 | foo-bar: 20 | max-attempts: 5 21 | wait-duration: 1s 22 | enable-exponential-backoff: true 23 | spring: 24 | application: 25 | name: book-service 26 | datasource: 27 | driver-class-name: com.mysql.cj.jdbc.Driver 28 | url: jdbc:mysql://localhost:3306/book_service?useTimezone=true&serverTimezone=UTC 29 | username: root 30 | password: admin123 31 | jackson: 32 | default-property-inclusion: NON_NULL 33 | serialization: 34 | fail-on-empty-beans: false 35 | jpa: 36 | hibernate: 37 | ddl-auto: update 38 | show-sql: true 39 | properties: 40 | hibernate: 41 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 42 | flyway: 43 | url: jdbc:mysql://localhost:3306/ 44 | schemas: book_service 45 | user: root 46 | password: admin123 47 | sleuth: 48 | sampler: 49 | probability: 1.0 50 | springdoc: 51 | show-actuator: true 52 | api-docs: 53 | path: book-service/v3/api-docs 54 | -------------------------------------------------------------------------------- /09-book-service/src/main/resources/db/migration/V1__Create_Table_Books.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `book` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `author` longtext, 4 | `launch_date` datetime(6) NOT NULL, 5 | `price` decimal(65,2) NOT NULL, 6 | `title` longtext 7 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 8 | -------------------------------------------------------------------------------- /09-book-service/src/main/resources/db/migration/V2__Insert_Data_In_Books.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `book` (`author`, `launch_date`, `price`, `title`) VALUES 2 | ('Michael C. Feathers', '2017-11-29 13:50:05.878000', 8.57, 'Working effectively with legacy code'), 3 | ('Ralph Johnson, Erich Gamma, John Vlissides e Richard Helm', '2017-11-29 15:15:13.636000', 7.87, 'Design Patterns'), 4 | ('Robert C. Martin', '2009-01-10 00:00:00.000000', 13.46, 'Clean Code'), 5 | ('Crockford', '2017-11-07 15:09:01.674000', 11.71, 'JavaScript'), 6 | ('Steve McConnell', '2017-11-07 15:09:01.674000', 10.14, 'Code complete'), 7 | ('Martin Fowler e Kent Beck', '2017-11-07 15:09:01.674000', 15.38, 'Refactoring'), 8 | ('Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates', '2017-11-07 15:09:01.674000', 19.23, 'Head First Design Patterns'), 9 | ('Eric Evans', '2017-11-07 15:09:01.674000', 16.09, 'Domain Driven Design'), 10 | ('Brian Goetz e Tim Peierls', '2017-11-07 15:09:01.674000', 13.99, 'Java Concurrency in Practice'), 11 | ('Susan Cain', '2017-11-07 15:09:01.674000', 21.51, 'O poder dos quietos'), 12 | ('Roger S. Pressman', '2017-11-07 15:09:01.674000', 9.79, 'Engenharia de Software: uma abordagem profissional'), 13 | ('Viktor Mayer-Schonberger e Kenneth Kukier', '2017-11-07 15:09:01.674000', 9.44, 'Big Data: como extrair volume, variedade, velocidade e valor da avalanche de informação cotidiana'), 14 | ('Richard Hunter e George Westerman', '2017-11-07 15:09:01.674000', 16.61, 'O verdadeiro valor de TI'), 15 | ('Marc J. Schiller', '2017-11-07 15:09:01.674000', 7.87, 'Os 11 segredos de líderes de TI altamente influentes'), 16 | ('Aguinaldo Aragon Fernandes e Vladimir Ferraz de Abreu', '2017-11-07 15:09:01.674000', 9.44, 'Implantando a governança de TI'); -------------------------------------------------------------------------------- /09-book-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09-cambio-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09-cambio-service/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import io.swagger.v3.oas.annotations.OpenAPIDefinition; 6 | import io.swagger.v3.oas.annotations.info.Info; 7 | import io.swagger.v3.oas.models.Components; 8 | import io.swagger.v3.oas.models.OpenAPI; 9 | import io.swagger.v3.oas.models.info.License; 10 | 11 | @OpenAPIDefinition(info = 12 | @Info(title = "Cambio Service API", 13 | version = "v1", 14 | description = "Documentation of Cambio Service API")) 15 | public class OpenApiConfiguration { 16 | 17 | @Bean 18 | public OpenAPI customOpenAPI() { 19 | return new OpenAPI() 20 | .components(new Components()) 21 | .info( 22 | new io.swagger.v3.oas.models.info.Info() 23 | .title("Cambio Service API") 24 | .version("v1") 25 | .license( 26 | new License() 27 | .name("Apache 2.0") 28 | .url("http://springdoc.org") 29 | ) 30 | ); 31 | } 32 | } -------------------------------------------------------------------------------- /09-cambio-service/src/main/java/br/com/erudio/controller/CambioController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.core.env.Environment; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import br.com.erudio.model.Cambio; 16 | import br.com.erudio.repository.CambioRepository; 17 | import io.swagger.v3.oas.annotations.Operation; 18 | import io.swagger.v3.oas.annotations.tags.Tag; 19 | 20 | @Tag(name = "Cambio Service API") 21 | @RestController 22 | @RequestMapping("cambio-service") 23 | public class CambioController { 24 | 25 | private Logger logger = LoggerFactory.getLogger(CambioController.class); 26 | 27 | @Autowired 28 | private Environment environment; 29 | 30 | @Autowired 31 | private CambioRepository repository; 32 | 33 | @Operation(description = "Get cambio from currency!") 34 | @GetMapping(value = "/{amount}/{from}/{to}") 35 | public Cambio getCambio( 36 | @PathVariable("amount") BigDecimal amount, 37 | @PathVariable("from") String from, 38 | @PathVariable("to") String to 39 | ) { 40 | 41 | logger.info("getCambio is called with -> {}, {} and {}", amount, from, to); 42 | var cambio = repository.findByFromAndTo(from, to); 43 | if (cambio == null) throw new RuntimeException("Currency Unsupported"); 44 | 45 | var port = environment.getProperty("local.server.port"); 46 | BigDecimal conversionFactor = cambio.getConversionFactor(); 47 | BigDecimal convertedValue = conversionFactor.multiply(amount); 48 | cambio.setConvertedValue(convertedValue.setScale(2, RoundingMode.CEILING)); 49 | cambio.setEnvironment(port); 50 | return cambio; 51 | } 52 | } -------------------------------------------------------------------------------- /09-cambio-service/src/main/java/br/com/erudio/repository/CambioRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Cambio; 6 | 7 | public interface CambioRepository extends JpaRepository { 8 | 9 | Cambio findByFromAndTo(String from, String to); 10 | 11 | } -------------------------------------------------------------------------------- /09-cambio-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: cambio-service 10 | datasource: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | url: jdbc:mysql://localhost:3306/cambio_service?useTimezone=true&serverTimezone=UTC 13 | username: root 14 | password: admin123 15 | jpa: 16 | hibernate: 17 | ddl-auto: update 18 | show-sql: true 19 | properties: 20 | hibernate: 21 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 22 | flyway: 23 | url: jdbc:mysql://localhost:3306/ 24 | schemas: cambio_service 25 | user: root 26 | password: admin123 27 | sleuth: 28 | sampler: 29 | probability: 1.0 30 | #zipkin: 31 | #base-url: http://localhost:9411/ 32 | springdoc: 33 | api-docs: 34 | path: cambio-service/v3/api-docs -------------------------------------------------------------------------------- /09-cambio-service/src/main/resources/db/migration/V1__Create_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `cambio` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `from_currency` CHAR(3) NOT NULL, 4 | `to_currency` CHAR(3) NOT NULL, 5 | `conversion_factor` decimal(65,2) NOT NULL 6 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 7 | -------------------------------------------------------------------------------- /09-cambio-service/src/main/resources/db/migration/V2__Populate_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `cambio` (`from_currency`, `to_currency`, `conversion_factor`) VALUES 2 | ('USD', 'BRL', 5.73), 3 | ('USD', 'EUR', 0.84), 4 | ('USD', 'GBP', 0.73), 5 | ('USD', 'ARS', 92.56), 6 | ('USD', 'CLP', 713.30), 7 | ('USD', 'COP', 3665.00), 8 | ('USD', 'MXN', 20.15); -------------------------------------------------------------------------------- /09-cambio-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09-naming-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /09-naming-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/09-naming-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /09-naming-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /09-naming-server/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 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 Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /09-naming-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: naming-server 6 | eureka: 7 | client: 8 | register-with-eureka: false 9 | fetch-registry: false 10 | -------------------------------------------------------------------------------- /09-naming-server/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 3 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.1.5 9 | 10 | 11 | br.com.erudio 12 | chatgpt-spring-boot-java-integration 13 | 0.0.1-SNAPSHOT 14 | chatgpt-spring-boot-java-integration 15 | Demo project for Spring Boot 16 | 17 | 20 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-devtools 28 | runtime 29 | true 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/java/br/com/erudio/Startup.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Startup { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Startup.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/java/br/com/erudio/config/OpenAIConfig.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.config; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @Configuration 11 | public class OpenAIConfig { 12 | 13 | private Logger logger = Logger.getLogger 14 | (OpenAIConfig.class.getName()); 15 | 16 | @Value("${openai.api.key}") 17 | String openApiKey; 18 | 19 | @Bean 20 | RestTemplate template() { 21 | logger.info("Initializing RestTemplate"); 22 | 23 | RestTemplate restTemplate = new RestTemplate(); 24 | restTemplate.getInterceptors().add((request, body, execution) -> { 25 | request.getHeaders().add("Authorization", "Bearer " + openApiKey); 26 | return execution.execute(request, body); 27 | }); 28 | return restTemplate; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/java/br/com/erudio/controller/ChatGPTController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import br.com.erudio.service.ChatGPTService; 10 | 11 | @RestController 12 | @RequestMapping("/bot") 13 | public class ChatGPTController { 14 | 15 | @Autowired 16 | private ChatGPTService service; 17 | 18 | // HOST/bot/chat 19 | @GetMapping("/chat") 20 | public String chat(@RequestParam("prompt") String prompt) {// throws JsonProcessingException { 21 | return service.chat(prompt); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/java/br/com/erudio/service/ChatGPTService.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.service; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | // import com.fasterxml.jackson.core.JsonProcessingException; 11 | // import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import br.com.erudio.vo.request.ChatGptRequest; 14 | import br.com.erudio.vo.response.ChatGptResponse; 15 | 16 | @Service 17 | public class ChatGPTService { 18 | 19 | private Logger logger = Logger.getLogger 20 | (ChatGPTService.class.getName()); 21 | 22 | @Value("${openai.model}") 23 | private String model; 24 | 25 | @Value("${openai.api.url}") 26 | private String url; 27 | 28 | @Autowired 29 | private RestTemplate template; 30 | 31 | public String chat(String prompt) { // throws JsonProcessingException { 32 | 33 | logger.info("Starting Prompt"); 34 | 35 | ChatGptRequest request = new ChatGptRequest(model, prompt); 36 | 37 | // String json = new ObjectMapper().writeValueAsString(request); 38 | 39 | // logger.info(json); 40 | 41 | logger.info("Processing Prompt"); 42 | ChatGptResponse response = 43 | template.postForObject(url, request, ChatGptResponse.class); 44 | 45 | return response.getChoices().get(0).getMessage().getContent(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/java/br/com/erudio/vo/request/ChatGptRequest.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.vo.request; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class ChatGptRequest implements Serializable{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | private String model; 12 | private List messages; 13 | 14 | public ChatGptRequest() {} 15 | 16 | public ChatGptRequest( 17 | String model, 18 | String prompt) { 19 | this.model = model; 20 | this.messages = new ArrayList<>(); 21 | this.messages.add(new Message("user", prompt)); 22 | } 23 | 24 | public String getModel() { 25 | return model; 26 | } 27 | 28 | public void setModel(String model) { 29 | this.model = model; 30 | } 31 | 32 | public List getMessages() { 33 | return messages; 34 | } 35 | 36 | public void setMessages(List messages) { 37 | this.messages = messages; 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | final int prime = 31; 43 | int result = 1; 44 | result = prime * result + ((messages == null) ? 0 : messages.hashCode()); 45 | result = prime * result + ((model == null) ? 0 : model.hashCode()); 46 | return result; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object obj) { 51 | if (this == obj) 52 | return true; 53 | if (obj == null) 54 | return false; 55 | if (getClass() != obj.getClass()) 56 | return false; 57 | ChatGptRequest other = (ChatGptRequest) obj; 58 | if (messages == null) { 59 | if (other.messages != null) 60 | return false; 61 | } else if (!messages.equals(other.messages)) 62 | return false; 63 | if (model == null) { 64 | if (other.model != null) 65 | return false; 66 | } else if (!model.equals(other.model)) 67 | return false; 68 | return true; 69 | } 70 | } -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/java/br/com/erudio/vo/request/Message.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.vo.request; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Message implements Serializable{ 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String role; 10 | private String content;//prompt 11 | 12 | public Message() {} 13 | 14 | public Message(String role, String content) { 15 | this.role = role; 16 | this.content = content; 17 | } 18 | 19 | public String getRole() { 20 | return role; 21 | } 22 | 23 | public void setRole(String role) { 24 | this.role = role; 25 | } 26 | 27 | public String getContent() { 28 | return content; 29 | } 30 | 31 | public void setContent(String content) { 32 | this.content = content; 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | final int prime = 31; 38 | int result = 1; 39 | result = prime * result + ((content == null) ? 0 : content.hashCode()); 40 | result = prime * result + ((role == null) ? 0 : role.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (obj == null) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | Message other = (Message) obj; 53 | if (content == null) { 54 | if (other.content != null) 55 | return false; 56 | } else if (!content.equals(other.content)) 57 | return false; 58 | if (role == null) { 59 | if (other.role != null) 60 | return false; 61 | } else if (!role.equals(other.role)) 62 | return false; 63 | return true; 64 | } 65 | } -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/java/br/com/erudio/vo/response/ChatGptResponse.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.vo.response; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class ChatGptResponse implements Serializable{ 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private List choices; 11 | 12 | public ChatGptResponse() {} 13 | 14 | public List getChoices() { 15 | return choices; 16 | } 17 | 18 | public void setChoices(List choices) { 19 | this.choices = choices; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | final int prime = 31; 25 | int result = 1; 26 | result = prime * result + ((choices == null) ? 0 : choices.hashCode()); 27 | return result; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | if (this == obj) 33 | return true; 34 | if (obj == null) 35 | return false; 36 | if (getClass() != obj.getClass()) 37 | return false; 38 | ChatGptResponse other = (ChatGptResponse) obj; 39 | if (choices == null) { 40 | if (other.choices != null) 41 | return false; 42 | } else if (!choices.equals(other.choices)) 43 | return false; 44 | return true; 45 | } 46 | } -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/java/br/com/erudio/vo/response/Choice.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.vo.response; 2 | 3 | import java.io.Serializable; 4 | 5 | import br.com.erudio.vo.request.Message; 6 | 7 | public class Choice implements Serializable{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | private int index; 12 | private Message message; 13 | 14 | public Choice() {} 15 | 16 | public int getIndex() { 17 | return index; 18 | } 19 | 20 | public void setIndex(int index) { 21 | this.index = index; 22 | } 23 | 24 | public Message getMessage() { 25 | return message; 26 | } 27 | 28 | public void setMessage(Message message) { 29 | this.message = message; 30 | } 31 | 32 | @Override 33 | public int hashCode() { 34 | final int prime = 31; 35 | int result = 1; 36 | result = prime * result + index; 37 | result = prime * result + ((message == null) ? 0 : message.hashCode()); 38 | return result; 39 | } 40 | 41 | @Override 42 | public boolean equals(Object obj) { 43 | if (this == obj) 44 | return true; 45 | if (obj == null) 46 | return false; 47 | if (getClass() != obj.getClass()) 48 | return false; 49 | Choice other = (Choice) obj; 50 | if (index != other.index) 51 | return false; 52 | if (message == null) { 53 | if (other.message != null) 54 | return false; 55 | } else if (!message.equals(other.message)) 56 | return false; 57 | return true; 58 | } 59 | } -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | openai: 2 | model: gpt-3.5-turbo 3 | api: 4 | key: ${OPENAI_API_KEY} 5 | url: https://api.openai.com/v1/chat/completions 6 | -------------------------------------------------------------------------------- /18_BONUS_ChatGPT/chatgpt-spring-boot-java-integration/src/test/java/br/com/erudio/StartupTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class StartupTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Challenges/01_MathChallenge/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.springframework.boot 6 | spring-boot-starter-parent 7 | 2.1.3.RELEASE 8 | 9 | 10 | br.com.erudio 11 | rest-with-springboot-udemy 12 | 0.0.1-SNAPSHOT 13 | jar 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 11 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-rest 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | test 31 | 32 | 33 | 34 | junit 35 | junit 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Challenges/01_MathChallenge/src/main/java/br/com/erudio/Startup.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Startup { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Startup.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Challenges/01_MathChallenge/src/main/java/br/com/erudio/exception/ExceptionResponse.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exception; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class ExceptionResponse implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Date timestamp; 11 | private String message; 12 | private String details; 13 | 14 | public ExceptionResponse(Date timestamp, String message, String details) { 15 | super(); 16 | this.timestamp = timestamp; 17 | this.message = message; 18 | this.details = details; 19 | } 20 | 21 | public Date getTimestamp() { 22 | return timestamp; 23 | } 24 | 25 | public String getMessage() { 26 | return message; 27 | } 28 | 29 | public String getDetails() { 30 | return details; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Challenges/01_MathChallenge/src/main/java/br/com/erudio/exception/UnsuportedMathOperationException.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.BAD_REQUEST) 7 | public class UnsuportedMathOperationException extends RuntimeException{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | public UnsuportedMathOperationException(String exception) { 12 | super(exception); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Challenges/01_MathChallenge/src/main/java/br/com/erudio/exception/handler/CustomizedResponseEntityExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.exception.handler; 2 | 3 | import java.util.Date; 4 | 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.context.request.WebRequest; 11 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 12 | 13 | import br.com.erudio.exception.ExceptionResponse; 14 | import br.com.erudio.exception.UnsuportedMathOperationException; 15 | 16 | @ControllerAdvice 17 | @RestController 18 | public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExceptionHandler{ 19 | 20 | @ExceptionHandler(Exception.class) 21 | public final ResponseEntity handleAllExceptions(Exception ex, WebRequest request) { 22 | ExceptionResponse exceptionResponse = 23 | new ExceptionResponse( 24 | new Date(), 25 | ex.getMessage(), 26 | request.getDescription(false)); 27 | return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); 28 | } 29 | 30 | 31 | @ExceptionHandler(UnsuportedMathOperationException.class) 32 | public final ResponseEntity handleBadRequestExceptions(Exception ex, WebRequest request) { 33 | ExceptionResponse exceptionResponse = 34 | new ExceptionResponse( 35 | new Date(), 36 | ex.getMessage(), 37 | request.getDescription(false)); 38 | return new ResponseEntity<>(exceptionResponse, HttpStatus.BAD_REQUEST); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Challenges/01_MathChallenge/src/main/java/br/com/erudio/math/SimpleMath.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.math; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class SimpleMath { 7 | 8 | public Double sum(Double firstNumber, Double secondNumber) { 9 | return firstNumber + secondNumber; 10 | } 11 | 12 | public Double subtraction(Double firstNumber, Double secondNumber) { 13 | return firstNumber - secondNumber; 14 | } 15 | 16 | public Double multiplication(Double firstNumber, Double secondNumber) { 17 | return firstNumber * secondNumber; 18 | } 19 | 20 | public Double division(Double firstNumber, Double secondNumber) { 21 | return firstNumber / secondNumber; 22 | } 23 | 24 | public Double mean(Double firstNumber, Double secondNumber) { 25 | return (firstNumber + secondNumber) / 2; 26 | } 27 | 28 | public Double squareRoot(Double number) { 29 | return (Double) Math.sqrt(number); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Challenges/01_MathChallenge/src/main/java/br/com/erudio/request/converters/NumberConverter.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.request.converters; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class NumberConverter { 7 | 8 | public Double covertToDouble(String strNumber) { 9 | if (strNumber == null) return 0d; 10 | String number = strNumber.replaceAll(",", "."); 11 | if (isNumeric(number)) return Double.parseDouble(number); 12 | return 0d; 13 | } 14 | 15 | public boolean isNumeric(String strNumber) { 16 | if (strNumber == null) return false; 17 | String number = strNumber.replaceAll(",", "."); 18 | return number.matches("[-+]?[0-9]*\\.?[0-9]+"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DockerReview/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:16-jdk-slim 2 | ARG JAR_FILE=target/*.jar 3 | COPY ${JAR_FILE} app.jar 4 | RUN bash -c 'touch /app.jar' 5 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /DockerReview/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.5.0-M3 9 | 10 | 11 | br.com.erudio 12 | hello-docker 13 | 0.0.1-SNAPSHOT 14 | hello-docker 15 | Demo project for Spring Boot 16 | 17 | 16 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-test 28 | test 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-maven-plugin 37 | 38 | 39 | 40 | 41 | 42 | spring-milestones 43 | Spring Milestones 44 | https://repo.spring.io/milestone 45 | 46 | 47 | 48 | 49 | spring-milestones 50 | Spring Milestones 51 | https://repo.spring.io/milestone 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /DockerReview/src/main/java/br/com/erudio/DockerController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class DockerController { 10 | 11 | Logger logger = LoggerFactory.getLogger(DockerController.class); 12 | 13 | @RequestMapping("/hello-docker") 14 | public HelloDocker greeting() { 15 | 16 | logger.info("Endpoint /hello-docker is called!!!"); 17 | 18 | //var hostName = System.getenv("COMPUTERNAME"); 19 | var hostName = System.getenv("HOSTNAME"); 20 | 21 | return new HelloDocker( 22 | "Hello Docker", 23 | hostName 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DockerReview/src/main/java/br/com/erudio/HelloDocker.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | public class HelloDocker { 4 | 5 | private final String content; 6 | private final String environment; 7 | 8 | public HelloDocker(String content, String environment) { 9 | this.content = content; 10 | this.environment = environment; 11 | } 12 | 13 | public String getContent() { 14 | return content; 15 | } 16 | 17 | public String getEnvironment() { 18 | return environment; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DockerReview/src/main/java/br/com/erudio/Startup.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Startup { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Startup.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /DockerReview/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 80 -------------------------------------------------------------------------------- /DockerReview/src/test/java/br/com/erudio/StartupTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class StartupTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Dockerizing/10-api-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /Dockerizing/10-api-gateway/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/Dockerizing/10-api-gateway/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Dockerizing/10-api-gateway/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /Dockerizing/10-api-gateway/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Dockerizing/10-api-gateway/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springdoc.core.GroupedOpenApi; 7 | import org.springdoc.core.SwaggerUiConfigParameters; 8 | import org.springframework.cloud.gateway.route.RouteDefinitionLocator; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.context.annotation.Lazy; 12 | 13 | @Configuration 14 | public class OpenApiConfiguration { 15 | 16 | @Bean 17 | @Lazy(false) 18 | public List apis( 19 | SwaggerUiConfigParameters config, 20 | RouteDefinitionLocator locator) { 21 | 22 | var definitions = locator.getRouteDefinitions().collectList().block(); 23 | 24 | definitions.stream().filter( 25 | routeDefinition -> routeDefinition.getId() 26 | .matches(".*-service")) 27 | .forEach(routeDefinition -> { 28 | String name = routeDefinition.getId(); 29 | config.addGroup(name); 30 | GroupedOpenApi.builder() 31 | .pathsToMatch("/" + name + "/**") 32 | .group(name).build(); 33 | } 34 | ); 35 | return new ArrayList<>(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Dockerizing/10-api-gateway/src/main/java/br/com/erudio/filter/LoggingFilter.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 6 | import org.springframework.cloud.gateway.filter.GlobalFilter; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.server.ServerWebExchange; 9 | 10 | import reactor.core.publisher.Mono; 11 | 12 | @Component 13 | public class LoggingFilter implements GlobalFilter{ 14 | 15 | private Logger logger = LoggerFactory.getLogger(LoggingFilter.class); 16 | 17 | @Override 18 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 19 | logger.debug("Original request path -> {}", exchange.getRequest().getPath()); 20 | return chain.filter(exchange); 21 | } 22 | } -------------------------------------------------------------------------------- /Dockerizing/10-api-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8765 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: api-gateway 10 | cloud: 11 | gateway: 12 | discovery: 13 | locator: 14 | enabled: true 15 | routes: 16 | - id: cambio-service 17 | uri: lb://cambio-service 18 | predicates: 19 | - Path=/cambio-service/** 20 | - id: book-service 21 | uri: lb://book-service 22 | predicates: 23 | - Path=/book-service/** 24 | - id: openapi 25 | uri: lb://api-gateway 26 | predicates: 27 | - Path=/v3/api-docs/** 28 | filters: 29 | - RewritePath=/v3/api-docs/(?.*), /$\{path}/v3/api-docs 30 | sleuth: 31 | sampler: 32 | probability: 1.0 -------------------------------------------------------------------------------- /Dockerizing/10-api-gateway/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Dockerizing/10-book-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:16-jdk-slim 2 | ARG JAR_FILE=10-book-service/target/*.jar 3 | COPY ${JAR_FILE} app.jar 4 | RUN bash -c 'touch /app.jar' 5 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import io.swagger.v3.oas.annotations.OpenAPIDefinition; 6 | import io.swagger.v3.oas.annotations.info.Info; 7 | import io.swagger.v3.oas.models.Components; 8 | import io.swagger.v3.oas.models.OpenAPI; 9 | import io.swagger.v3.oas.models.info.License; 10 | 11 | @OpenAPIDefinition(info = 12 | @Info(title = "Book Service API", 13 | version = "v1", 14 | description = "Documentation of Book Service API")) 15 | public class OpenApiConfiguration { 16 | 17 | @Bean 18 | public OpenAPI customOpenAPI() { 19 | return new OpenAPI() 20 | .components(new Components()) 21 | .info( 22 | new io.swagger.v3.oas.models.info.Info() 23 | .title("Book Service API") 24 | .version("v1") 25 | .license( 26 | new License() 27 | .name("Apache 2.0") 28 | .url("http://springdoc.org") 29 | ) 30 | ); 31 | } 32 | } -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/main/java/br/com/erudio/controller/FooBarController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import io.github.resilience4j.bulkhead.annotation.Bulkhead; 10 | import io.swagger.v3.oas.annotations.Operation; 11 | import io.swagger.v3.oas.annotations.tags.Tag; 12 | 13 | @Tag(name = "Foo bar") 14 | @RestController 15 | @RequestMapping("book-service") 16 | public class FooBarController { 17 | 18 | private Logger logger = LoggerFactory.getLogger(FooBarController.class); 19 | 20 | @GetMapping("/foo-bar") 21 | @Operation(summary = "Foo bar") 22 | //@Retry(name = "foo-bar", fallbackMethod = "fallbackMethod") 23 | //@CircuitBreaker(name = "default", fallbackMethod = "fallbackMethod") 24 | //@RateLimiter(name = "default") 25 | @Bulkhead(name = "default") 26 | public String fooBar() { 27 | logger.info("Request to foo-bar is received!"); 28 | /* 29 | * var response = new RestTemplate() 30 | * .getForEntity("http://localhost:8080/foo-bar", String.class); 31 | */ 32 | return "Foo-Bar!!!"; 33 | //return response.getBody(); 34 | } 35 | 36 | public String fallbackMethod(Exception ex) { 37 | return "fallbackMethod foo-bar!!!"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/main/java/br/com/erudio/proxy/CambioProxy.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.proxy; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | 7 | import br.com.erudio.response.Cambio; 8 | 9 | @FeignClient(name = "cambio-service") 10 | public interface CambioProxy { 11 | 12 | @GetMapping(value = "/cambio-service/{amount}/{from}/{to}") 13 | public Cambio getCambio( 14 | @PathVariable("amount") Double amount, 15 | @PathVariable("from") String from, 16 | @PathVariable("to") String to 17 | ); 18 | } -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/main/java/br/com/erudio/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Book; 6 | 7 | public interface BookRepository extends JpaRepository{} -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8100 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | resilience4j: 8 | bulkhead: 9 | instances: 10 | default: 11 | max-concurrent-calls: 10 12 | ratelimiter: 13 | instances: 14 | default: 15 | limit-for-period: 2 16 | limit-refresh-period: 10s 17 | retry: 18 | instances: 19 | foo-bar: 20 | max-attempts: 5 21 | wait-duration: 1s 22 | enable-exponential-backoff: true 23 | spring: 24 | application: 25 | name: book-service 26 | datasource: 27 | driver-class-name: com.mysql.cj.jdbc.Driver 28 | url: jdbc:mysql://localhost:3306/book_service?useTimezone=true&serverTimezone=UTC 29 | username: root 30 | password: admin123 31 | jackson: 32 | default-property-inclusion: NON_NULL 33 | serialization: 34 | fail-on-empty-beans: false 35 | jpa: 36 | hibernate: 37 | ddl-auto: update 38 | show-sql: true 39 | properties: 40 | hibernate: 41 | dialect: org.hibernate.dialect.MySQL57Dialect 42 | flyway: 43 | url: jdbc:mysql://localhost:3306/book_service?useTimezone=true&serverTimezone=UTC 44 | user: root 45 | password: admin123 46 | sleuth: 47 | sampler: 48 | probability: 1.0 49 | springdoc: 50 | show-actuator: true 51 | api-docs: 52 | path: book-service/v3/api-docs 53 | -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/main/resources/db/migration/V1__Create_Table_Books.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `book` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `author` longtext, 4 | `launch_date` datetime(6) NOT NULL, 5 | `price` decimal(65,2) NOT NULL, 6 | `title` longtext 7 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 8 | -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/main/resources/db/migration/V2__Insert_Data_In_Books.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `book` (`author`, `launch_date`, `price`, `title`) VALUES 2 | ('Michael C. Feathers', '2017-11-29 13:50:05.878000', 8.57, 'Working effectively with legacy code'), 3 | ('Ralph Johnson, Erich Gamma, John Vlissides e Richard Helm', '2017-11-29 15:15:13.636000', 7.87, 'Design Patterns'), 4 | ('Robert C. Martin', '2009-01-10 00:00:00.000000', 13.46, 'Clean Code'), 5 | ('Crockford', '2017-11-07 15:09:01.674000', 11.71, 'JavaScript'), 6 | ('Steve McConnell', '2017-11-07 15:09:01.674000', 10.14, 'Code complete'), 7 | ('Martin Fowler e Kent Beck', '2017-11-07 15:09:01.674000', 15.38, 'Refactoring'), 8 | ('Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates', '2017-11-07 15:09:01.674000', 19.23, 'Head First Design Patterns'), 9 | ('Eric Evans', '2017-11-07 15:09:01.674000', 16.09, 'Domain Driven Design'), 10 | ('Brian Goetz e Tim Peierls', '2017-11-07 15:09:01.674000', 13.99, 'Java Concurrency in Practice'), 11 | ('Susan Cain', '2017-11-07 15:09:01.674000', 21.51, 'O poder dos quietos'), 12 | ('Roger S. Pressman', '2017-11-07 15:09:01.674000', 9.79, 'Engenharia de Software: uma abordagem profissional'), 13 | ('Viktor Mayer-Schonberger e Kenneth Kukier', '2017-11-07 15:09:01.674000', 9.44, 'Big Data: como extrair volume, variedade, velocidade e valor da avalanche de informação cotidiana'), 14 | ('Richard Hunter e George Westerman', '2017-11-07 15:09:01.674000', 16.61, 'O verdadeiro valor de TI'), 15 | ('Marc J. Schiller', '2017-11-07 15:09:01.674000', 7.87, 'Os 11 segredos de líderes de TI altamente influentes'), 16 | ('Aguinaldo Aragon Fernandes e Vladimir Ferraz de Abreu', '2017-11-07 15:09:01.674000', 9.44, 'Implantando a governança de TI'); -------------------------------------------------------------------------------- /Dockerizing/10-book-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:16-jdk-slim 2 | ARG JAR_FILE=10-cambio-service/target/*.jar 3 | COPY ${JAR_FILE} app.jar 4 | RUN bash -c 'touch /app.jar' 5 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/src/main/java/br/com/erudio/configuration/OpenApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import io.swagger.v3.oas.annotations.OpenAPIDefinition; 6 | import io.swagger.v3.oas.annotations.info.Info; 7 | import io.swagger.v3.oas.models.Components; 8 | import io.swagger.v3.oas.models.OpenAPI; 9 | import io.swagger.v3.oas.models.info.License; 10 | 11 | @OpenAPIDefinition(info = 12 | @Info(title = "Cambio Service API", 13 | version = "v1", 14 | description = "Documentation of Cambio Service API")) 15 | public class OpenApiConfiguration { 16 | 17 | @Bean 18 | public OpenAPI customOpenAPI() { 19 | return new OpenAPI() 20 | .components(new Components()) 21 | .info( 22 | new io.swagger.v3.oas.models.info.Info() 23 | .title("Cambio Service API") 24 | .version("v1") 25 | .license( 26 | new License() 27 | .name("Apache 2.0") 28 | .url("http://springdoc.org") 29 | ) 30 | ); 31 | } 32 | } -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/src/main/java/br/com/erudio/controller/CambioController.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.controller; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.core.env.Environment; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import br.com.erudio.model.Cambio; 16 | import br.com.erudio.repository.CambioRepository; 17 | import io.swagger.v3.oas.annotations.Operation; 18 | import io.swagger.v3.oas.annotations.tags.Tag; 19 | 20 | @Tag(name = "Cambio Service API") 21 | @RestController 22 | @RequestMapping("cambio-service") 23 | public class CambioController { 24 | 25 | private Logger logger = LoggerFactory.getLogger(CambioController.class); 26 | 27 | @Autowired 28 | private Environment environment; 29 | 30 | @Autowired 31 | private CambioRepository repository; 32 | 33 | @Operation(description = "Get cambio from currency!") 34 | @GetMapping(value = "/{amount}/{from}/{to}") 35 | public Cambio getCambio( 36 | @PathVariable("amount") BigDecimal amount, 37 | @PathVariable("from") String from, 38 | @PathVariable("to") String to 39 | ) { 40 | 41 | logger.info("getCambio is called with -> {}, {} and {}", amount, from, to); 42 | var cambio = repository.findByFromAndTo(from, to); 43 | if (cambio == null) throw new RuntimeException("Currency Unsupported"); 44 | 45 | var port = environment.getProperty("local.server.port"); 46 | BigDecimal conversionFactor = cambio.getConversionFactor(); 47 | BigDecimal convertedValue = conversionFactor.multiply(amount); 48 | cambio.setConvertedValue(convertedValue.setScale(2, RoundingMode.CEILING)); 49 | cambio.setEnvironment(port); 50 | return cambio; 51 | } 52 | } -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/src/main/java/br/com/erudio/repository/CambioRepository.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import br.com.erudio.model.Cambio; 6 | 7 | public interface CambioRepository extends JpaRepository { 8 | 9 | Cambio findByFromAndTo(String from, String to); 10 | 11 | } -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | eureka: 4 | client: 5 | service-url: 6 | defaultZone: http://localhost:8761/eureka 7 | spring: 8 | application: 9 | name: cambio-service 10 | datasource: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | url: jdbc:mysql://localhost:3306/cambio_service?useTimezone=true&serverTimezone=UTC 13 | username: root 14 | password: admin123 15 | jpa: 16 | hibernate: 17 | ddl-auto: update 18 | show-sql: true 19 | properties: 20 | hibernate: 21 | dialect: org.hibernate.dialect.MySQL57Dialect 22 | flyway: 23 | url: jdbc:mysql://localhost:3306/cambio_service?useTimezone=true&serverTimezone=UTC 24 | user: root 25 | password: admin123 26 | sleuth: 27 | sampler: 28 | probability: 1.0 29 | #zipkin: 30 | #base-url: http://localhost:9411/ 31 | springdoc: 32 | api-docs: 33 | path: cambio-service/v3/api-docs -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/src/main/resources/db/migration/V1__Create_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `cambio` ( 2 | `id` INT(10) AUTO_INCREMENT PRIMARY KEY, 3 | `from_currency` CHAR(3) NOT NULL, 4 | `to_currency` CHAR(3) NOT NULL, 5 | `conversion_factor` decimal(65,2) NOT NULL 6 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 7 | -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/src/main/resources/db/migration/V2__Populate_Table_Cambio.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `cambio` (`from_currency`, `to_currency`, `conversion_factor`) VALUES 2 | ('USD', 'BRL', 5.73), 3 | ('USD', 'EUR', 0.84), 4 | ('USD', 'GBP', 0.73), 5 | ('USD', 'ARS', 92.56), 6 | ('USD', 'CLP', 713.30), 7 | ('USD', 'COP', 3665.00), 8 | ('USD', 'MXN', 20.15); -------------------------------------------------------------------------------- /Dockerizing/10-cambio-service/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Dockerizing/10-erudio-config-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /Dockerizing/10-erudio-config-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/Dockerizing/10-erudio-config-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Dockerizing/10-erudio-config-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /Dockerizing/10-erudio-config-server/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 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 Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Dockerizing/10-erudio-config-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | application: 5 | name: erudio-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://github.com/leandrocgsi/erudio-config-server 11 | #username: username 12 | #password: password 13 | default-label: main 14 | search-paths: 15 | - 'greeting-service*' -------------------------------------------------------------------------------- /Dockerizing/10-erudio-config-server/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Dockerizing/10-naming-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 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 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /Dockerizing/10-naming-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/Dockerizing/10-naming-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Dockerizing/10-naming-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /Dockerizing/10-naming-server/src/main/java/br/com/erudio/Application.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 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 Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Dockerizing/10-naming-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: naming-server 6 | eureka: 7 | client: 8 | register-with-eureka: false 9 | fetch-registry: false 10 | -------------------------------------------------------------------------------- /Dockerizing/10-naming-server/src/test/java/br/com/erudio/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package br.com.erudio; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /images/capa_curso_v5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/images/capa_curso_v5.png -------------------------------------------------------------------------------- /images/course_cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leandrocgsi/erudio-microservices/9e0e9b0a6281df27b30eff3fa8bff1481a8aed25/images/course_cover.png --------------------------------------------------------------------------------