Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Account save(Account account) throws Exception {
- if (StringUtils.isEmpty(account.getServiceName())) {
- throw new Exception("Service name is required");
- }
- if (StringUtils.isEmpty(account.getEmail())) {
- throw new Exception("Email is required");
- }
- if (account.getId() != null && existsById(account.getId())) {
- throw new Exception("Account with id: " + account.getId() + " already exists");
- }
- return accountRepository.save(account);
- }
- /with DTO
- public AccountDto save(Account account) throws Exception {
- if (StringUtils.isEmpty(account.getServiceName())) {
- throw new Exception("Service name is required");
- }
- if (StringUtils.isEmpty(account.getEmail())) {
- throw new Exception("Email is required");
- }
- if (account.getId() != null && existsById(account.getId())) {
- throw new Exception("Account with id: " + account.getId() + " already exists");
- }
- AccountDto accountDto = new AccountDto();
- accountDto.setServiceName(account.getServiceName());
- accountDto.setEmail(account.getEmail());
- accountDto.setPassword(account.getPassword());
- accountDto.setCreatedOn(account.getCreatedOn());
- account.setUpdatedOn(account.getUpdatedOn());
- accountRepository.save(account);
- return accountDto;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement