/** @param toDelete list account ids to delete */ @Transactional @RequestMapping(value = "/user/delete", method = RequestMethod.PUT) public void deleteUsers(@RequestBody List<Long> toDelete) { List<Account> accountsToDelete = accountRepository.findAll(toDelete); for (Account a : accountsToDelete) { a.setFirstName(null); a.setLastName(null); // a.setStatus(AccountStatus.DELETED); } accountRepository.save(accountsToDelete); }
@RequestMapping(value = "/user/account/save", method = RequestMethod.POST) public void addNewAccount(@RequestBody AccountSaveDto accountSD) { Account account = new Account(); Boolean edited = false; if (accountSD.getId() != null) { account = accountRepository.findOne(accountSD.getId()); edited = true; } account.setLogin(accountSD.getLogin()); account.setFirstName(accountSD.getFirstName()); account.setLastName(accountSD.getLastName()); account.setEmail(accountSD.getEmail()); // //if modification account // if (accountSD.getPasswordChanged()) { // account.setPassword(accountSD.getPassword()); // } if (accountSD.getId() == null) { Role role = roleRepository.findOneByName("USER"); List<Role> roles = new ArrayList<>(); roles.add(role); account.setRoles(roles); } accountRepository.save(account); }
/** * @param id user id * @return user roles */ @RequestMapping(value = "/get/user/roles", method = RequestMethod.POST) public List<Role> getRolesById(@RequestBody Long id) { Account account = accountRepository.findOne(id); return account.getRoles(); }
@RequestMapping(value = "/email", method = RequestMethod.GET) public String index() { Account account = accountRepository.findOne(new Long(1)); return account.getEmail(); }