From c5315daf41a9402983fe221dbf1ba54de2992e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Sun, 3 Nov 2024 14:43:44 +0100 Subject: [PATCH] RLH-3 - Implement account deletion logic --- .../wtf/beatrice/releasehive/services/UserService.java | 2 ++ .../beatrice/releasehive/services/UserServiceImpl.java | 8 ++++++++ 2 files changed, 10 insertions(+) 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()); + } }