Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greeter controller #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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,41 @@
package tv.codely.apps.mooc.backend.controller.greeter;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tv.codely.shared.domain.DomainError;
import tv.codely.shared.domain.bus.command.CommandBus;
import tv.codely.shared.domain.bus.query.QueryBus;
import tv.codely.shared.infrastructure.spring.ApiController;

import java.util.HashMap;

@RestController
public final class GreeterGetController extends ApiController {
public GreeterGetController(
QueryBus queryBus,
CommandBus commandBus
) {
super(queryBus, commandBus);
}

@GetMapping("/greeter")
public HashMap<String, String> index(@RequestParam(name = "name", required = false) String name) {
HashMap<String, String> status = new HashMap<>();
status.put("message", getGreetingMessage(name));
return status;
}

private String getGreetingMessage(String name) {
if (name == null) {
name = "Unknown";
}
return "Hello " + name;
}

@Override
public HashMap<Class<? extends DomainError>, HttpStatus> errorMapping() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tv.codely.apps.mooc.backend.controller.greeter;

import org.junit.jupiter.api.Test;
import tv.codely.apps.mooc.MoocApplicationTestCase;

final class GreeterGetControllerShould extends MoocApplicationTestCase {
@Test
void greetNameMarcos() throws Exception {
assertResponse("/greeter?name=Marcos", 200, "{'message':'Hello Marcos'}");
}

@Test
void greetNameAnonymous() throws Exception {
assertResponse("/greeter", 200, "{'message':'Hello Unknown'}");
}
}