@Override public User updateUser( long userId, String username, String password, String firstName, String lastName) { User user = userRepository.findOne(userId); user.setUsername(username); user.setFirstName(firstName); user.setLastName(lastName); user.setPassword(password); return this.userRepository.save(user); }
@Override public Customer removeCustomer(long userId, long customerId) { User user = userRepository.findOne(userId); Customer customer = customerRepository.findOne(customerId); user.getCustomers().remove(customer); this.userRepository.save(user); customer.setUser(null); this.customerRepository.delete(customer); return customer; }
@Override public User removeUser(long userId) { User u = userRepository.findOne(userId); this.userRepository.delete(userId); return u; }
@Override public User findById(long userId) { User user = userRepository.findOne(userId); if (null == user) throw new UserNotFoundException(userId); return user; }