diff --git a/src/main/java/com/github/pauloruszel/converter/PokemonConverter.java b/src/main/java/com/github/pauloruszel/converter/PokemonConverter.java index 7960146..d742a6c 100644 --- a/src/main/java/com/github/pauloruszel/converter/PokemonConverter.java +++ b/src/main/java/com/github/pauloruszel/converter/PokemonConverter.java @@ -23,6 +23,16 @@ public static Pokemon converter(PokemonDTO pokemonDTO) { return pokemon; } + public static Pokemon converter(Pokemon entidade, PokemonDTO dto) { + entidade.setId(dto.getId()); + entidade.setNomePokemon(dto.getNomePokemon()); + entidade.setAltura(dto.getAltura()); + entidade.setCategoria(dto.getCategoria()); + entidade.setGenero(dto.getGenero()); + entidade.setPeso(dto.getPeso()); + return entidade; + } + public static PokemonDTO converter(Pokemon pokemon) { var pokemonDTO = new PokemonDTO(); diff --git a/src/main/java/com/github/pauloruszel/endpoint/PokemonEndPoint.java b/src/main/java/com/github/pauloruszel/endpoint/PokemonEndPoint.java index fc8eed5..7916702 100644 --- a/src/main/java/com/github/pauloruszel/endpoint/PokemonEndPoint.java +++ b/src/main/java/com/github/pauloruszel/endpoint/PokemonEndPoint.java @@ -45,9 +45,8 @@ public Response addPokemon(@RequestBody @Valid PokemonDTO dto) { public Response updatePokemon(@RequestBody @Valid PokemonDTO dto) { Pokemon pokemon = Pokemon.findById(dto.getId()); if (pokemon != null) { - Pokemon retorno = PokemonConverter.converter(dto); - retorno.getEntityManager().merge(retorno); - return Response.ok(retorno).status(Response.Status.OK).build(); + pokemon = PokemonConverter.converter(pokemon, dto); + return Response.ok(pokemon).status(Response.Status.OK).build(); } return Response.ok(pokemon).status(Response.Status.NOT_FOUND).build(); }