From 17ba5b8b9dcb8b90c576ef257bf6ea354b3518d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Mon, 11 Nov 2024 16:29:59 +0100 Subject: [PATCH] RLH-21 - Fix Sonar --- .../beatrice/releasehive/services/UserServiceImpl.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java b/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java index b6d7460..f142008 100644 --- a/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java +++ b/src/main/java/wtf/beatrice/releasehive/services/UserServiceImpl.java @@ -35,12 +35,10 @@ public class UserServiceImpl implements UserService @Override public boolean deleteUser(UUID id) { - if (userRepository.findById(id).isEmpty()) { - throw new UsernameNotFoundException("User not found"); - } - if (userRepository.findById(id).isPresent()) { - userRepository.delete(userRepository.findById(id).get()); - } + userRepository.delete(userRepository + .findById(id) + .orElseThrow(() -> new UsernameNotFoundException("User not found"))); + return true; } }