RLH-3 - Implement account deletion logic

This commit is contained in:
Bea 2024-11-03 14:43:44 +01:00
parent 2f6d4a9f1b
commit c5315daf41
2 changed files with 10 additions and 0 deletions

View File

@ -12,4 +12,6 @@ public interface UserService
User loadUserByUsername(String username) throws UsernameNotFoundException;
User loadUserByEmail(String email) throws UsernameNotFoundException;
void deleteUser(String email);
}

View File

@ -31,4 +31,12 @@ public class UserServiceImpl implements UserService
public User loadUserByEmail(String email) throws UsernameNotFoundException {
return userRepository.findByEmail(email).orElseThrow(() -> new UsernameNotFoundException(email));
}
@Override
public void deleteUser(String email) {
if (userRepository.findByEmail(email).isEmpty()) {
throw new UsernameNotFoundException(email);
}
userRepository.delete(userRepository.findByEmail(email).get());
}
}