Refactor authentication and user service. Adding Tests for UserService.java and AuthenticationService.java
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2025-12-22 23:53:38 +01:00
parent 60fdd3e507
commit 432a720370
11 changed files with 538 additions and 39 deletions
@@ -99,17 +99,18 @@ public class AuthenticationService {
new UsernamePasswordAuthenticationToken(authPairDTO.getEmail(), authPairDTO.getPassword())
);
User user = userRepository.findByEmail(authPairDTO.getEmail()).get();
System.out.println(user.getEmail());
User user = userRepository.findByEmail(authPairDTO.getEmail())
.orElseThrow(() -> new RuntimeException("User not found"));
UserDTO userDTO = userMapper.toUserDTO(user);
// TODO patch, commented out
//UserDTO userDTO = new UserDTO(user.getId(), user.getUsername(), user.getRoles());
String token = tokenService.generateUserJwt(auth, userDTO);
return new LoginResponseDTO(userDTO, token);
} catch (AuthenticationException e) {
System.out.println("AuthenticationException: " + e.getMessage());
//System.out.println("AuthenticationException: " + e.getMessage());
return new LoginResponseDTO(null, "");
} catch ( RuntimeException e) {
return new LoginResponseDTO(null, "");
}
}