diff --git a/src/main/java/wtf/beatrice/releasehive/services/UserService.java b/src/main/java/wtf/beatrice/releasehive/services/UserService.java index 5176b0c..2607716 100644 --- a/src/main/java/wtf/beatrice/releasehive/services/UserService.java +++ b/src/main/java/wtf/beatrice/releasehive/services/UserService.java @@ -12,4 +12,6 @@ public interface UserService User loadUserByUsername(String username) throws UsernameNotFoundException; User loadUserByEmail(String email) throws UsernameNotFoundException; + + void deleteUser(String email); } diff --git a/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java b/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java index 21b0bb1..45ef7db 100644 --- a/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java +++ b/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java @@ -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()); + } }