use of com.rafaelvieira.letmebuy.entities.User in project letmebuy by rafaelrok.
the class UserInsertValidator method isValid.
@Override
public boolean isValid(UserInsertDTO dto, ConstraintValidatorContext context) {
List<FieldMessage> list = new ArrayList<>();
// Area onde efetua os testes de validação
User user = repository.findByEmail(dto.getEmail());
if (user != null) {
list.add(new FieldMessage("email", "Email já existe"));
}
// Implementa no fieldmensage os erros de validação
for (FieldMessage e : list) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(e.getMessage()).addPropertyNode(e.getFieldName()).addConstraintViolation();
}
return list.isEmpty();
}
use of com.rafaelvieira.letmebuy.entities.User in project letmebuy by rafaelrok.
the class UserService method save.
@Transactional
public UserDTO save(UserInsertDTO dto) {
User entity = new User();
copyDtoToEntity(dto, entity);
entity.setPassword(passwordEncoder.encode(dto.getPassword()));
entity = repository.save(entity);
return new UserDTO(entity);
}
Aggregations