diff --git a/API/src/main/java/cc/fascinated/services/UserService.java b/API/src/main/java/cc/fascinated/services/UserService.java index 357b572..809271b 100644 --- a/API/src/main/java/cc/fascinated/services/UserService.java +++ b/API/src/main/java/cc/fascinated/services/UserService.java @@ -58,13 +58,16 @@ public class UserService { throw new BadRequestException("Invalid steam id"); } Optional userOptional = this.userRepository.findBySteamId(steamId); + User user; + boolean shouldUpdate = false; if (userOptional.isEmpty()) { // todo: check the steam API to see if the user exists - User user = new User(UUID.randomUUID()); + user = new User(UUID.randomUUID()); user.setSteamId(steamId); - return userRepository.save(user); + shouldUpdate = true; + } else { + user = userOptional.get(); } - User user = userOptional.get(); // Ensure the users ScoreSaber account is up-to-date ScoreSaberAccount scoresaberAccount = user.getScoresaberAccount(); @@ -76,9 +79,11 @@ public class UserService { ScoreSaberAccountToken accountToken = scoreSaberService.getAccount(user); user.setScoresaberAccount(ScoreSaberAccount.getFromToken(accountToken)); // Update the ScoreSaber account user.setUsername(accountToken.getName()); // Update the username + shouldUpdate = true; + } + if (shouldUpdate) { this.saveUser(user); // Save the user } - return user; }