diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b38cbb0 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..0baf7c3 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5e24c1c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/server.iml b/.idea/server.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/server.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/dummy/pom.xml b/dummy/pom.xml index 1ea50c3..071da9e 100644 --- a/dummy/pom.xml +++ b/dummy/pom.xml @@ -3,20 +3,56 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 3.2.5 - + com.learningpulse + server + 0.0.1 - com.learningpulse dummy - 0.0.1-SNAPSHOT + 0.0.1 dummy - Demo project for Spring Boot + A dummy project - 22 + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.cloud + spring-cloud-config-server + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + + + + + org.springframework.security.oauth + spring-security-oauth2 + 2.5.2.RELEASE + + + + + org.springframework.security + spring-security-oauth2-resource-server + + org.springframework.boot spring-boot-starter-security @@ -27,16 +63,6 @@ postgresql runtime - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - org.springframework.security spring-security-test @@ -44,21 +70,4 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - diff --git a/dummy/src/main/java/com/learningpulse/dummy/DummyApplication.java b/dummy/src/main/java/com/learningpulse/dummy/DummyApplication.java index 9f083f0..54e1e05 100644 --- a/dummy/src/main/java/com/learningpulse/dummy/DummyApplication.java +++ b/dummy/src/main/java/com/learningpulse/dummy/DummyApplication.java @@ -2,8 +2,11 @@ package com.learningpulse.dummy; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + @SpringBootApplication +@EnableDiscoveryClient public class DummyApplication { public static void main(String[] args) { diff --git a/dummy/src/main/java/com/learningpulse/dummy/Test.java b/dummy/src/main/java/com/learningpulse/dummy/Test.java new file mode 100644 index 0000000..7da105e --- /dev/null +++ b/dummy/src/main/java/com/learningpulse/dummy/Test.java @@ -0,0 +1,16 @@ +package com.learningpulse.dummy; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/dummy") +public class Test { + + @GetMapping("/test") + public ResponseEntity test() { + return ResponseEntity.ok("Hello, World!"); + } +} diff --git a/dummy/src/main/resources/application-docker.yml b/dummy/src/main/resources/application-docker.yml new file mode 100644 index 0000000..a1d77c1 --- /dev/null +++ b/dummy/src/main/resources/application-docker.yml @@ -0,0 +1,2 @@ +app: + eureka-server: eureka \ No newline at end of file diff --git a/dummy/src/main/resources/application.properties b/dummy/src/main/resources/application.properties deleted file mode 100644 index 1f1e339..0000000 --- a/dummy/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=dummy diff --git a/dummy/src/main/resources/application.yml b/dummy/src/main/resources/application.yml new file mode 100644 index 0000000..a50a127 --- /dev/null +++ b/dummy/src/main/resources/application.yml @@ -0,0 +1,36 @@ +app: + eureka-server: localhost + +server: + port: 0 + +spring: + application: + name: dummy + + # TODO remove after testing + security: + user: + name: admin + password: admin + +springdoc: + enable-native-support: true + api-docs: + enabled: true + path: /api/v1/dummy/v3/api-docs + swagger-ui: + path: /api/v1/dummy/swagger-ui.html + +management: + endpoints: + web: + exposure: + include: "*" + +eureka: + client: + service-url: + defaultZone: http://localhost:8761/eureka + # Will only work when docker is used + # defaultZone: http://${app.eureka-server}:8761/eureka diff --git a/eurika/.gitignore b/eureka/.gitignore similarity index 100% rename from eurika/.gitignore rename to eureka/.gitignore diff --git a/eurika/.mvn/wrapper/maven-wrapper.properties b/eureka/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from eurika/.mvn/wrapper/maven-wrapper.properties rename to eureka/.mvn/wrapper/maven-wrapper.properties diff --git a/eurika/mvnw b/eureka/mvnw old mode 100755 new mode 100644 similarity index 100% rename from eurika/mvnw rename to eureka/mvnw diff --git a/eurika/mvnw.cmd b/eureka/mvnw.cmd similarity index 100% rename from eurika/mvnw.cmd rename to eureka/mvnw.cmd diff --git a/eureka/pom.xml b/eureka/pom.xml new file mode 100644 index 0000000..9369e60 --- /dev/null +++ b/eureka/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.learningpulse + server + 0.0.1 + + eureka + 0.0.1 + eureka + Eureka discovery server for LearningPulse + + + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + 4.1.1 + + + + diff --git a/eureka/src/main/java/com/learningpulse/eureka/EurekaApplication.java b/eureka/src/main/java/com/learningpulse/eureka/EurekaApplication.java new file mode 100644 index 0000000..d2c27e8 --- /dev/null +++ b/eureka/src/main/java/com/learningpulse/eureka/EurekaApplication.java @@ -0,0 +1,15 @@ +package com.learningpulse.eureka; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + +@EnableEurekaServer +@SpringBootApplication +public class EurekaApplication { + + public static void main(String[] args) { + SpringApplication.run(EurekaApplication.class, args); + } + +} diff --git a/eureka/src/main/resources/application.yml b/eureka/src/main/resources/application.yml new file mode 100644 index 0000000..d0a78e1 --- /dev/null +++ b/eureka/src/main/resources/application.yml @@ -0,0 +1,18 @@ +server: + port: 8761 + +eureka: + client: + register-with-eureka: false + fetch-registry: false + instance: + hostname: localhost + +spring: + application: + name: eureka + security: + # TODO remove after testing + user: + name: admin + password: admin \ No newline at end of file diff --git a/eurika/src/test/java/com/learningpulse/eurika/EurikaApplicationTests.java b/eureka/src/test/java/com/learningpulse/eureka/EurekaApplicationTests.java similarity index 69% rename from eurika/src/test/java/com/learningpulse/eurika/EurikaApplicationTests.java rename to eureka/src/test/java/com/learningpulse/eureka/EurekaApplicationTests.java index 78314ba..ab78178 100644 --- a/eurika/src/test/java/com/learningpulse/eurika/EurikaApplicationTests.java +++ b/eureka/src/test/java/com/learningpulse/eureka/EurekaApplicationTests.java @@ -1,10 +1,10 @@ -package com.learningpulse.eurika; +package com.learningpulse.eureka; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class EurikaApplicationTests { +class EurekaApplicationTests { @Test void contextLoads() { diff --git a/eurika/pom.xml b/eurika/pom.xml deleted file mode 100644 index 763bba1..0000000 --- a/eurika/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.2.5 - - - com.learningpulse - eurika - 0.0.1-SNAPSHOT - eurika - Demo project for Spring Boot - - 22 - 2023.0.1 - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-server - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/eurika/src/main/java/com/learningpulse/eurika/EurikaApplication.java b/eurika/src/main/java/com/learningpulse/eurika/EurikaApplication.java deleted file mode 100644 index 2c9a7b4..0000000 --- a/eurika/src/main/java/com/learningpulse/eurika/EurikaApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.learningpulse.eurika; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class EurikaApplication { - - public static void main(String[] args) { - SpringApplication.run(EurikaApplication.class, args); - } - -} diff --git a/eurika/src/main/resources/application.properties b/eurika/src/main/resources/application.properties deleted file mode 100644 index 2eb1f79..0000000 --- a/eurika/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=eurika diff --git a/gateway/pom.xml b/gateway/pom.xml index fde2962..018a68c 100644 --- a/gateway/pom.xml +++ b/gateway/pom.xml @@ -3,61 +3,49 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 3.2.5 + com.learningpulse + server + 0.0.1 - com.learningpulse gateway - 0.0.1-SNAPSHOT + 0.0.1 gateway - Demo project for Spring Boot + API gateway for LearningPulse - 22 - 2023.0.1 + + + org.springframework.cloud + spring-cloud-starter-circuitbreaker-reactor-resilience4j + + + org.springframework.cloud + spring-cloud-starter-gateway + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springdoc + springdoc-openapi-starter-webflux-ui + 2.2.0 + org.springframework.boot spring-boot-starter-oauth2-resource-server org.springframework.cloud - spring-cloud-starter-gateway-mvc - - - org.springframework.cloud - spring-cloud-starter-loadbalancer - - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.restdocs - spring-restdocs-mockmvc - test + spring-cloud-starter-netflix-eureka-client - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - @@ -86,18 +74,6 @@ - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - diff --git a/gateway/src/main/java/com/learningpulse/gateway/GatewayApplication.java b/gateway/src/main/java/com/learningpulse/gateway/GatewayApplication.java index f4cdf2f..bb4e61d 100644 --- a/gateway/src/main/java/com/learningpulse/gateway/GatewayApplication.java +++ b/gateway/src/main/java/com/learningpulse/gateway/GatewayApplication.java @@ -2,12 +2,15 @@ package com.learningpulse.gateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; @SpringBootApplication +@EnableWebFluxSecurity +@EnableDiscoveryClient public class GatewayApplication { public static void main(String[] args) { SpringApplication.run(GatewayApplication.class, args); } - } diff --git a/gateway/src/main/java/com/learningpulse/gateway/config/OpenAPIConfiguration.java b/gateway/src/main/java/com/learningpulse/gateway/config/OpenAPIConfiguration.java new file mode 100644 index 0000000..a623308 --- /dev/null +++ b/gateway/src/main/java/com/learningpulse/gateway/config/OpenAPIConfiguration.java @@ -0,0 +1,25 @@ +package com.learningpulse.gateway.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + + +@Component +@Configuration +public class OpenAPIConfiguration { + @Bean + public OpenAPI gatewayOpenAPI() { + return new OpenAPI().info(new Info() + .title("Learning Pulse API documentation") + .version("0.0.1") + .description("This is the API documentation for the Learning Pulse project.") + .contact(new Contact() + .name("Learning Pulse") + .url("https://git.4o1x5.dev/LearningPulse")) + ); + } +} diff --git a/gateway/src/main/resources/application-docker.yml b/gateway/src/main/resources/application-docker.yml new file mode 100644 index 0000000..a1d77c1 --- /dev/null +++ b/gateway/src/main/resources/application-docker.yml @@ -0,0 +1,2 @@ +app: + eureka-server: eureka \ No newline at end of file diff --git a/gateway/src/main/resources/application.properties b/gateway/src/main/resources/application.properties deleted file mode 100644 index 6365994..0000000 --- a/gateway/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=gateway diff --git a/gateway/src/main/resources/application.yml b/gateway/src/main/resources/application.yml new file mode 100644 index 0000000..9b2ea0b --- /dev/null +++ b/gateway/src/main/resources/application.yml @@ -0,0 +1,81 @@ +server: + port: 8181 + +spring: + application: + name: gateway + + cloud: + gateway: + discovery: + locator: + enabled: true + routes: + # eureka service routing + - id: eureka + # Will only work when docker is used + # uri: http://${app.eureka-server}:8761 + uri: http://localhost:8761 + predicates: + - Path=/eureka/web + filters: + - SetPath=/ + - id: eureka-static + # Will only work when docker is used + # uri: http://${app.eureka-server}:8761 + uri: http://localhost:8761 + predicates: + - Path=/eureka/** + # dummy service routing + # TODO smth is wrong with this + - id: dummy + uri: lb://dummy + predicates: + - Path=/api/v1/dummy/** + filters: + - AddResponseHeader=X-Powered-By, LearningPulse Gateway Service + security: + user: + name: admin + password: admin + + +# Keycloak configuration for the future +# security: +# oauth2: +# resourceserver: +# jwt: +# issuer-uri: ${KEYCLOAK_URL}/realms/LearningPulse +management: + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: always + gateway: + enabled: true + +springdoc: + enable-native-support: true + api-docs: + enabled: true + groups: + enabled: true + swagger-ui: + path: /swagger-ui.html + config-url: /v3/api-docs/swagger-config + urls: + - name: Gateway API + url: /v3/api-docs + # TODO not working rn + - name: Dummy Service API + url: /api/v1/dummy/v3/api-docs + +eureka: + client: + service-url: + defaultZone: http://localhost:8761/eureka + # Will only work when docker is used + # defaultZone: http://${app.eureka-server}:8761/eureka diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ebd117c --- /dev/null +++ b/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.5 + + + com.learningpulse + server + 0.0.1 + pom + server + API server for LearningPulse + + gateway + eureka + dummy + + + 22 + 22 + 22 + 2023.0.1 + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.jetbrains + annotations + 24.1.0 + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + +