use of com.rafaelvieira.letmebuy.controllers.exceptions.FieldMessage in project letmebuy by rafaelrok.
the class UserUpdateValidator method isValid.
@Override
public boolean isValid(UserUpdateDTO dto, ConstraintValidatorContext context) {
@SuppressWarnings("unchecked") var uriVars = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
long userId = Long.parseLong(uriVars.get("id"));
List<FieldMessage> list = new ArrayList<>();
User user = repository.findByEmail(dto.getEmail());
if (user != null && userId != user.getId()) {
list.add(new FieldMessage("email", "Email já existe"));
}
for (FieldMessage e : list) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(e.getMessage()).addPropertyNode(e.getFieldName()).addConstraintViolation();
}
return list.isEmpty();
}
use of com.rafaelvieira.letmebuy.controllers.exceptions.FieldMessage 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();
}
Aggregations