Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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;

@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 greeting")
public String getGreeting() {
return greetingService.greet();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lv.ctco.springboottemplate.features.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 openTasks = todoService.getAllTodos().stream().filter(todo -> !todo.completed()).count();

String suffix = openTasks == 1 ? "task" : "tasks";

return String.format("Hello from Spring! You have %d open %s.", openTasks, suffix);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package lv.ctco.springboottemplate.features.greeting;

import static org.assertj.core.api.Assertions.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 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;

/**
Expand All @@ -15,13 +25,10 @@
* <p>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
Expand Down Expand Up @@ -94,5 +101,4 @@ void should_ignore_null_todos_or_null_completed_flags() {
// then
assertThat(message).contains("1 open task");
}
*/
}