diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/lv/ctco/springboottemplate/greeting/GreetingController.java b/src/main/java/lv/ctco/springboottemplate/greeting/GreetingController.java new file mode 100644 index 0000000..15c371d --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/greeting/GreetingController.java @@ -0,0 +1,23 @@ +package lv.ctco.springboottemplate.greeting; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/greeting") +@Tag(name = "Greeting Controller", description = "Greeting management endpoints") +public class GreetingController { + + private final GreetingService greetingService; + + public GreetingController(GreetingService greetingService) { + this.greetingService = greetingService; + } + + @GetMapping + @Operation(summary = "Get a greeting with a count of todos") + public String getGreeting() { + return greetingService.greet(); + } +} diff --git a/src/main/java/lv/ctco/springboottemplate/greeting/GreetingService.java b/src/main/java/lv/ctco/springboottemplate/greeting/GreetingService.java new file mode 100644 index 0000000..c405f63 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/greeting/GreetingService.java @@ -0,0 +1,19 @@ +package lv.ctco.springboottemplate.greeting; + +import lv.ctco.springboottemplate.features.todo.TodoService; +import org.springframework.stereotype.Service; + +@Service +public class GreetingService { + private final TodoService todoService; + + public GreetingService(TodoService todoService) { + this.todoService = todoService; + } + + public String greet() { + long pendingCount = todoService.getAllTodos().stream().filter(t -> !t.completed()).count(); + + return "Hello from Spring! You have " + pendingCount + " 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..f4defe1 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.Disabled; +import lv.ctco.springboottemplate.greeting.GreetingService; +import org.junit.jupiter.api.BeforeEach; +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; /** @@ -11,17 +22,12 @@ * *

This test verifies that GreetingService correctly interacts with {@link TodoService} and * reflects the number of open (not completed) todos in the message. - * - *

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 +100,4 @@ void should_ignore_null_todos_or_null_completed_flags() { // then assertThat(message).contains("1 open task"); } - */ }