api: don't return the user early
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 31s

This commit is contained in:
Lee 2024-08-01 23:50:37 +01:00
parent 0f307eb18c
commit 02fcaf19eb

@ -58,13 +58,16 @@ public class UserService {
throw new BadRequestException("Invalid steam id");
}
Optional<User> 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;
}