diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 5b405fd..345e96d 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -2,9 +2,11 @@ name: Java CI with Gradle on: push: - branches: [ "main" ] + branches: + - '**' pull_request: - branches: [ "main" ] + branches: + - '**' jobs: build: diff --git a/README.md b/README.md index 7aa61ab..ca99757 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,10 @@ Open Swagger docs: http://localhost:8080/swagger-ui.html 3. **Pull Request Process** - Create a PR from your task branch to your personal feature branch - Assign the following reviewers to your PR: - - https://github.com/trioletas - - https://github.com/algorithm108 - - https://github.com/IgorGursky + - https://github.com/trioletas (Oleg) + - https://github.com/algorithm108 (Alexey) + - https://github.com/IgorGursky (Igor) + - https://github.com/Melancholic (Andrey) ### 📝 Available Tasks diff --git a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java new file mode 100644 index 0000000..2787840 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java @@ -0,0 +1,25 @@ +package lv.ctco.springboottemplate.features.greeting; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** REST controller for generation of greeting messages */ +@RestController +@RequestMapping("/api/greeting") +@Tag(name = "Greeting Controller", description = "Greeting endpoints") +public class GreetingController { + private final GreetingService greetingService; + + private GreetingController(GreetingService greetingService) { + this.greetingService = greetingService; + } + + @GetMapping + @Operation(summary = "Get greeting with pending tasks count") + public String getGreeting() { + return greetingService.greet(); + } +} diff --git a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java new file mode 100644 index 0000000..e553f46 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java @@ -0,0 +1,21 @@ +package lv.ctco.springboottemplate.features.greeting; + +import lv.ctco.springboottemplate.features.todo.TodoService; +import org.springframework.stereotype.Service; + +/** Service layer for greeting messages */ +@Service +public class GreetingService { + private final TodoService todoService; + + private GreetingService(TodoService todoService) { + this.todoService = todoService; + } + + public String greet() { + long pendingItemsCount = + todoService.getAllTodos().stream().filter(todo -> !todo.completed()).count(); + + return "Hello from Spring! You have " + pendingItemsCount + " open tasks."; + } +} diff --git a/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java b/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java index eda5f13..e49deb7 100644 --- a/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java +++ b/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java @@ -1,9 +1,20 @@ package lv.ctco.springboottemplate.features.greeting; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import java.util.List; +import lv.ctco.springboottemplate.features.todo.Todo; +import lv.ctco.springboottemplate.features.todo.TodoRepository; import lv.ctco.springboottemplate.features.todo.TodoService; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.TestConstructor; +import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -15,13 +26,10 @@ *
Initially marked {@link Disabled} to be enabled by the developer after implementation. */ @SpringBootTest -@Disabled("Enable after implementing GreetingService using TodoService") @Testcontainers @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) class GreetingServiceIntegrationTest { - /* - @Container static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:6.0.8"); @DynamicPropertySource @@ -94,5 +102,4 @@ void should_ignore_null_todos_or_null_completed_flags() { // then assertThat(message).contains("1 open task"); } - */ }