diff --git a/.github/workflows/catalog.yaml b/.github/workflows/catalog.yaml new file mode 100644 index 0000000..1ad834e --- /dev/null +++ b/.github/workflows/catalog.yaml @@ -0,0 +1,31 @@ +name: CI/CD pipeline for product catalog service + +on: + push: + branches: + - main + - develop + - feature/** + pull_request: + branches: + - main + - develop + - feature/** + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: oracle + java-version: 21 + - name: Setup Task + uses: arduino/setup-task@v2 + with: + version: 3.x + repo-token: ${{ secrets.GH_TOKEN }} + - name: Test product catalog service + run: task catalog:test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 62c8935..cc5909d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,40 @@ -.idea/ \ No newline at end of file +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Gradle ### +.gradle/ \ No newline at end of file diff --git a/.gradle/8.5/checksums/checksums.lock b/.gradle/8.5/checksums/checksums.lock index 5c1c766..1e855b3 100644 Binary files a/.gradle/8.5/checksums/checksums.lock and b/.gradle/8.5/checksums/checksums.lock differ diff --git a/.gradle/8.5/executionHistory/executionHistory.bin b/.gradle/8.5/executionHistory/executionHistory.bin index 9d34fd9..f150f7b 100644 Binary files a/.gradle/8.5/executionHistory/executionHistory.bin and b/.gradle/8.5/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.5/executionHistory/executionHistory.lock b/.gradle/8.5/executionHistory/executionHistory.lock index dc879bd..6202594 100644 Binary files a/.gradle/8.5/executionHistory/executionHistory.lock and b/.gradle/8.5/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.5/fileHashes/fileHashes.bin b/.gradle/8.5/fileHashes/fileHashes.bin index b1d4c35..7f91ff1 100644 Binary files a/.gradle/8.5/fileHashes/fileHashes.bin and b/.gradle/8.5/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.5/fileHashes/fileHashes.lock b/.gradle/8.5/fileHashes/fileHashes.lock index 15c401c..11f76f7 100644 Binary files a/.gradle/8.5/fileHashes/fileHashes.lock and b/.gradle/8.5/fileHashes/fileHashes.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 5f856b8..0bfebe1 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 0d70faa..8b981eb 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index deceb7b..1a50550 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/README.md b/README.md index c80ab85..d3d8d92 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # eshop + Event driven microservice-based c2c ecommerce platform + +[![Catalog Pipeline](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml) diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..e8b7501 --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,19 @@ +version: 3 + +tasks: + catalog:clean: + desc: Clean product catalog service build + cmd: ./gradlew catalog:clean + silent: true + + catalog:run: + desc: Run product catalog service + cmd: ./gradlew catalog:bootRun + silent: true + + catalog:test: + desc: Test product catalog service + cmds: + - task: catalog:clean + - ./gradlew catalog:test + silent: true \ No newline at end of file diff --git a/catalog-service/build.gradle b/catalog-service/build.gradle new file mode 100644 index 0000000..7899001 --- /dev/null +++ b/catalog-service/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.3' + id 'io.spring.dependency-management' version '1.1.6' +} + +group = 'io.dksifoua.eshop' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' + implementation 'org.springframework.boot:spring-boot-starter-webflux' + compileOnly 'org.projectlombok:lombok' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + developmentOnly 'org.springframework.boot:spring-boot-docker-compose' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.boot:spring-boot-testcontainers' + testImplementation 'io.projectreactor:reactor-test' + testImplementation 'org.testcontainers:junit-jupiter' + testImplementation 'org.testcontainers:mongodb' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/catalog-service/compose.yaml b/catalog-service/compose.yaml new file mode 100644 index 0000000..18dadeb --- /dev/null +++ b/catalog-service/compose.yaml @@ -0,0 +1,10 @@ +version: "3.8" +services: + mongodb: + image: mongo:latest + environment: + - MONGO_INITDB_DATABASE=catalog + - MONGO_INITDB_ROOT_PASSWORD=secret + - MONGO_INITDB_ROOT_USERNAME=root + ports: + - "27017:27017" diff --git a/catalog-service/settings.gradle b/catalog-service/settings.gradle new file mode 100644 index 0000000..3c9978a --- /dev/null +++ b/catalog-service/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'catalog' diff --git a/catalog-service/src/main/java/io/dksifoua/eshop/catalog/CatalogServiceApplication.java b/catalog-service/src/main/java/io/dksifoua/eshop/catalog/CatalogServiceApplication.java new file mode 100644 index 0000000..9a034d9 --- /dev/null +++ b/catalog-service/src/main/java/io/dksifoua/eshop/catalog/CatalogServiceApplication.java @@ -0,0 +1,13 @@ +package io.dksifoua.eshop.catalog; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CatalogServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(CatalogServiceApplication.class, args); + } + +} diff --git a/catalog-service/src/main/java/io/dksifoua/eshop/catalog/DefaultHandler.java b/catalog-service/src/main/java/io/dksifoua/eshop/catalog/DefaultHandler.java new file mode 100644 index 0000000..0a20e45 --- /dev/null +++ b/catalog-service/src/main/java/io/dksifoua/eshop/catalog/DefaultHandler.java @@ -0,0 +1,13 @@ +package io.dksifoua.eshop.catalog; + +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; + +@Component +public class DefaultHandler { + + public Mono handle() { + return ServerResponse.ok().body(Mono.just("Hello world!!!"), String.class); + } +} diff --git a/catalog-service/src/main/java/io/dksifoua/eshop/catalog/configuration/RouterConfiguration.java b/catalog-service/src/main/java/io/dksifoua/eshop/catalog/configuration/RouterConfiguration.java new file mode 100644 index 0000000..1f46a26 --- /dev/null +++ b/catalog-service/src/main/java/io/dksifoua/eshop/catalog/configuration/RouterConfiguration.java @@ -0,0 +1,19 @@ +package io.dksifoua.eshop.catalog.configuration; + +import io.dksifoua.eshop.catalog.DefaultHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; + +@Configuration +public class RouterConfiguration { + + @Bean + public RouterFunction handler(DefaultHandler handler) { + return RouterFunctions.route() + .path("/default", builder -> builder.GET(request -> handler.handle())) + .build(); + } +} diff --git a/catalog-service/src/main/resources/application.yaml b/catalog-service/src/main/resources/application.yaml new file mode 100644 index 0000000..7bd42b1 --- /dev/null +++ b/catalog-service/src/main/resources/application.yaml @@ -0,0 +1,3 @@ +spring: + application: + name: catalog-service diff --git a/catalog-service/src/test/java/io/dksifoua/eshop/catalog/CatalogServiceApplicationTests.java b/catalog-service/src/test/java/io/dksifoua/eshop/catalog/CatalogServiceApplicationTests.java new file mode 100644 index 0000000..0268ad2 --- /dev/null +++ b/catalog-service/src/test/java/io/dksifoua/eshop/catalog/CatalogServiceApplicationTests.java @@ -0,0 +1,15 @@ +package io.dksifoua.eshop.catalog; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; + +@Import(TestcontainersConfiguration.class) +@SpringBootTest +class CatalogServiceApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/catalog-service/src/test/java/io/dksifoua/eshop/catalog/TestCatalogServiceApplication.java b/catalog-service/src/test/java/io/dksifoua/eshop/catalog/TestCatalogServiceApplication.java new file mode 100644 index 0000000..d7fcbfc --- /dev/null +++ b/catalog-service/src/test/java/io/dksifoua/eshop/catalog/TestCatalogServiceApplication.java @@ -0,0 +1,11 @@ +package io.dksifoua.eshop.catalog; + +import org.springframework.boot.SpringApplication; + +public class TestCatalogServiceApplication { + + public static void main(String[] args) { + SpringApplication.from(CatalogServiceApplication::main).with(TestcontainersConfiguration.class).run(args); + } + +} diff --git a/catalog-service/src/test/java/io/dksifoua/eshop/catalog/TestcontainersConfiguration.java b/catalog-service/src/test/java/io/dksifoua/eshop/catalog/TestcontainersConfiguration.java new file mode 100644 index 0000000..8eaaae2 --- /dev/null +++ b/catalog-service/src/test/java/io/dksifoua/eshop/catalog/TestcontainersConfiguration.java @@ -0,0 +1,18 @@ +package io.dksifoua.eshop.catalog; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.utility.DockerImageName; + +@TestConfiguration(proxyBeanMethods = false) +class TestcontainersConfiguration { + + @Bean + @ServiceConnection + MongoDBContainer mongoDbContainer() { + return new MongoDBContainer(DockerImageName.parse("mongo:latest")); + } + +} diff --git a/settings.gradle b/settings.gradle index 6fac9fe..d85c541 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,3 @@ rootProject.name = 'eshop' + +include('catalog-service') \ No newline at end of file