Update UserAccountService.java

Reverting changes
This commit is contained in:
raviavhad 2021-07-24 14:15:50 +05:30 committed by GitHub
parent d5399a7677
commit ed01815caf
1 changed files with 22 additions and 19 deletions

View File

@ -15,25 +15,28 @@ import com.baeldung.spring.servicevalidation.domain.UserAccount;
@Service
public class UserAccountService {
@Autowired
private Validator validator;
@Autowired
private UserAccountDao dao;
public String addUserAccount(UserAccount useraccount) {
Set<ConstraintViolation<UserAccount>> violations = validator.validate(useraccount);
@Autowired
private Validator validator;
if (!violations.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (ConstraintViolation<UserAccount> constraintViolation : violations) {
sb.append(constraintViolation.getMessage());
}
throw new ConstraintViolationException("Error occurred: " + sb.toString(), violations);
}
dao.addUserAccount(useraccount);
return "Account for " + useraccount.getName() + " Added!";
}
@Autowired
private UserAccountDao dao;
public String addUserAccount(UserAccount useraccount) {
Set<ConstraintViolation<UserAccount>> violations = validator.validate(useraccount);
if (!violations.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (ConstraintViolation<UserAccount> constraintViolation : violations) {
sb.append(constraintViolation.getMessage());
}
dao.addUserAccount(useraccount);
throw new ConstraintViolationException("Error occurred: " + sb.toString(), violations);
}
return "Account for " + useraccount.getName() + " Added!";
}
}