@PostMapping("/criar")
public ResponseEntity criar(@RequestBody @Valid ClienteDto clienteDto) {
Endereco endereco = mapearEndereco(clienteDto.endereco);
Cliente cliente = new Cliente(clienteDto.nome, clienteDto.email, clienteDto.senha, endereco);
clienteRepository.save(cliente);
return ResponseEntity.status(HttpStatus.CREATED).body("cliente adicionado com sucesso");
}
package com.desafio.brasilPrev.dto;
import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull;
import com.desafio.brasilPrev.dto.EnderecoDto;
public class ClienteDto {
public Long id;
@NotNull @NotBlank
public String nome;
@Email
public String email;
public String senha;
public EnderecoDto endereco;
}