Skip to content

Commit

Permalink
# Correção do endpoint de update e adição de um converter para o pana…
Browse files Browse the repository at this point in the history
…che.
  • Loading branch information
pauloruszel committed Oct 28, 2020
1 parent ccce052 commit 3000a00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 3000a00

Please sign in to comment.