api: don't return the user early
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 31s
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 31s
This commit is contained in:
parent
0f307eb18c
commit
02fcaf19eb
@ -58,13 +58,16 @@ public class UserService {
|
|||||||
throw new BadRequestException("Invalid steam id");
|
throw new BadRequestException("Invalid steam id");
|
||||||
}
|
}
|
||||||
Optional<User> userOptional = this.userRepository.findBySteamId(steamId);
|
Optional<User> userOptional = this.userRepository.findBySteamId(steamId);
|
||||||
|
User user;
|
||||||
|
boolean shouldUpdate = false;
|
||||||
if (userOptional.isEmpty()) {
|
if (userOptional.isEmpty()) {
|
||||||
// todo: check the steam API to see if the user exists
|
// 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);
|
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
|
// Ensure the users ScoreSaber account is up-to-date
|
||||||
ScoreSaberAccount scoresaberAccount = user.getScoresaberAccount();
|
ScoreSaberAccount scoresaberAccount = user.getScoresaberAccount();
|
||||||
@ -76,9 +79,11 @@ public class UserService {
|
|||||||
ScoreSaberAccountToken accountToken = scoreSaberService.getAccount(user);
|
ScoreSaberAccountToken accountToken = scoreSaberService.getAccount(user);
|
||||||
user.setScoresaberAccount(ScoreSaberAccount.getFromToken(accountToken)); // Update the ScoreSaber account
|
user.setScoresaberAccount(ScoreSaberAccount.getFromToken(accountToken)); // Update the ScoreSaber account
|
||||||
user.setUsername(accountToken.getName()); // Update the username
|
user.setUsername(accountToken.getName()); // Update the username
|
||||||
|
shouldUpdate = true;
|
||||||
|
}
|
||||||
|
if (shouldUpdate) {
|
||||||
this.saveUser(user); // Save the user
|
this.saveUser(user); // Save the user
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user