diff --git a/archetypes/database-se/src/main/resources/src/main/java/__pkg__/PokemonService.java.mustache b/archetypes/database-se/src/main/resources/src/main/java/__pkg__/PokemonService.java.mustache index d961f18f70f..28312cb97e0 100644 --- a/archetypes/database-se/src/main/resources/src/main/java/__pkg__/PokemonService.java.mustache +++ b/archetypes/database-se/src/main/resources/src/main/java/__pkg__/PokemonService.java.mustache @@ -74,7 +74,7 @@ public class PokemonService implements Service { .execute()) .thenAccept(maybeRow -> maybeRow .ifPresentOrElse( - row -> sendRow(row, response), + row -> response.send(row.as(Pokemon.class)), () -> sendNotFound(response, "Pokemon " + pokemonId + " not found"))) .exceptionally(throwable -> sendError(throwable, response)); } catch (NumberFormatException ex) { @@ -85,13 +85,10 @@ public class PokemonService implements Service { private void getPokemonByName(ServerRequest request, ServerResponse response) { String pokemonName = request.path().param("name"); dbClient.execute(exec -> exec.namedGet("select-pokemon-by-name", pokemonName)) - .thenAccept(it -> { - if (it.isEmpty()) { - sendNotFound(response, "Pokemon " + pokemonName + " not found"); - } else { - sendRow(it.get(), response); - } - }) + .thenAccept(maybeRow -> maybeRow + .ifPresentOrElse( + row -> response.send(row.as(Pokemon.class)), + () -> sendNotFound(response, "Pokemon " + pokemonName + " not found"))) .exceptionally(throwable -> sendError(throwable, response)); } @@ -123,10 +120,6 @@ public class PokemonService implements Service { response.send(message); } - private void sendRow(DbRow row, ServerResponse response) { - response.send(row.as(javax.json.JsonObject.class)); - } - /** * Send a 500 response code and a few details. * diff --git a/archetypes/database-se/src/main/resources/src/test/java/__pkg__/MainTest.java.mustache b/archetypes/database-se/src/main/resources/src/test/java/__pkg__/MainTest.java.mustache index a38a1ce0483..ffe5aa22b1b 100644 --- a/archetypes/database-se/src/main/resources/src/test/java/__pkg__/MainTest.java.mustache +++ b/archetypes/database-se/src/main/resources/src/test/java/__pkg__/MainTest.java.mustache @@ -79,14 +79,14 @@ public class MainTest { webClient.get() .path("/pokemon/1") .request(JsonObject.class) - .thenAccept(pokemon -> assertThat(pokemon.getString("NAME"), is("Bulbasaur"))) + .thenAccept(pokemon -> assertThat(pokemon.getString("name"), is("Bulbasaur"))) .toCompletableFuture() .get(); webClient.get() .path("/pokemon/name/Charmander") .request(JsonObject.class) - .thenAccept(pokemon -> assertThat(pokemon.getJsonNumber("ID_TYPE").intValue(), is(10))) + .thenAccept(pokemon -> assertThat(pokemon.getJsonNumber("idType").intValue(), is(10))) .toCompletableFuture() .get();