Skip to content

Commit ca22766

Browse files
committed
Create greeter controller
1 parent 38383e4 commit ca22766

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package tv.codely.apps.mooc.backend.controller.greeters;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.springframework.http.HttpStatus;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.RestController;
8+
import tv.codely.shared.domain.DomainError;
9+
import tv.codely.shared.domain.bus.command.CommandBus;
10+
import tv.codely.shared.domain.bus.query.QueryBus;
11+
import tv.codely.shared.infrastructure.spring.ApiController;
12+
13+
import java.util.HashMap;
14+
15+
@RestController
16+
public final class GreeterGetController extends ApiController {
17+
public GreeterGetController(
18+
QueryBus queryBus,
19+
CommandBus commandBus
20+
) {
21+
super(queryBus, commandBus);
22+
}
23+
24+
@GetMapping("/greet/{name}")
25+
public HashMap<String, String> index(@PathVariable String name) {
26+
HashMap<String, String> greeting = new HashMap<>();
27+
greeting.put("greet", String.format("Hi, %s!", StringUtils.capitalize(name)));
28+
29+
return greeting;
30+
}
31+
32+
@Override
33+
public HashMap<Class<? extends DomainError>, HttpStatus> errorMapping() {
34+
return null;
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tv.codely.apps.mooc.backend.controller.greeters;
2+
3+
import org.junit.jupiter.api.Test;
4+
import tv.codely.apps.mooc.MoocApplicationTestCase;
5+
6+
class GreeterGetControllerTestShould extends MoocApplicationTestCase {
7+
@Test
8+
void greet_a_user() throws Exception {
9+
assertResponse("/greet/octavi", 200, "{'greet':'Hi, Octavi!'}");
10+
}
11+
}

0 commit comments

Comments
 (0)