fix: delete orhpaned blackjack games
All checks were successful
CI / Get Changed Files (pull_request) Successful in 7s
CI / eslint (pull_request) Has been skipped
CI / Docker frontend validation (pull_request) Has been skipped
CI / oxlint (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Checkstyle Main (pull_request) Successful in 57s
CI / Docker backend validation (pull_request) Successful in 1m14s
All checks were successful
CI / Get Changed Files (pull_request) Successful in 7s
CI / eslint (pull_request) Has been skipped
CI / Docker frontend validation (pull_request) Has been skipped
CI / oxlint (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Checkstyle Main (pull_request) Successful in 57s
CI / Docker backend validation (pull_request) Successful in 1m14s
This commit is contained in:
parent
61b806c048
commit
1dfdedee91
1 changed files with 30 additions and 22 deletions
|
@ -35,8 +35,8 @@ public class BlackJackService {
|
|||
|
||||
game.setState(getState(game));
|
||||
deductBetFromBalance(user, betAmount);
|
||||
|
||||
return blackJackGameRepository.save(game);
|
||||
|
||||
return processGameBasedOnState(game);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -44,12 +44,11 @@ public class BlackJackService {
|
|||
if (game.getState() != BlackJackState.IN_PROGRESS) {
|
||||
return game;
|
||||
}
|
||||
|
||||
|
||||
dealCardToPlayer(game);
|
||||
|
||||
updateGameStateAndBalance(game);
|
||||
|
||||
return blackJackGameRepository.save(game);
|
||||
|
||||
return processGameBasedOnState(game);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -57,11 +56,11 @@ public class BlackJackService {
|
|||
if (game.getState() != BlackJackState.IN_PROGRESS) {
|
||||
return game;
|
||||
}
|
||||
|
||||
|
||||
dealCardsToDealerUntilMinimumScore(game);
|
||||
determineWinnerAndUpdateBalance(game);
|
||||
|
||||
return blackJackGameRepository.save(game);
|
||||
|
||||
return processGameBasedOnState(game);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -69,50 +68,59 @@ public class BlackJackService {
|
|||
if (game.getState() != BlackJackState.IN_PROGRESS || game.getPlayerCards().size() != 2) {
|
||||
return game;
|
||||
}
|
||||
|
||||
|
||||
UserEntity user = getUserWithFreshData(game.getUser());
|
||||
BigDecimal additionalBet = game.getBet();
|
||||
|
||||
|
||||
deductBetFromBalance(user, additionalBet);
|
||||
game.setBet(game.getBet().add(additionalBet));
|
||||
|
||||
|
||||
dealCardToPlayer(game);
|
||||
updateGameStateAndBalance(game);
|
||||
|
||||
|
||||
if (game.getState() == BlackJackState.IN_PROGRESS) {
|
||||
return stand(game);
|
||||
}
|
||||
|
||||
|
||||
return game;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public BlackJackGameEntity split(BlackJackGameEntity game) {
|
||||
if (game.getState() != BlackJackState.IN_PROGRESS ||
|
||||
game.getPlayerCards().size() != 2 ||
|
||||
if (game.getState() != BlackJackState.IN_PROGRESS ||
|
||||
game.getPlayerCards().size() != 2 ||
|
||||
game.isSplit() ||
|
||||
!game.getPlayerCards().get(0).getRank().equals(game.getPlayerCards().get(1).getRank())) {
|
||||
return game;
|
||||
}
|
||||
|
||||
|
||||
UserEntity user = getUserWithFreshData(game.getUser());
|
||||
BigDecimal splitBet = game.getBet();
|
||||
|
||||
|
||||
if (user.getBalance().compareTo(splitBet) < 0) {
|
||||
return game;
|
||||
}
|
||||
|
||||
|
||||
deductBetFromBalance(user, splitBet);
|
||||
game.setSplitBet(splitBet);
|
||||
game.setSplit(true);
|
||||
|
||||
|
||||
CardEntity card = game.getPlayerCards().remove(1);
|
||||
card.setCardType(CardType.PLAYER_SPLIT);
|
||||
game.getPlayerSplitCards().add(card);
|
||||
|
||||
|
||||
dealCardToPlayer(game);
|
||||
dealCardToSplitHand(game);
|
||||
|
||||
|
||||
return blackJackGameRepository.save(game);
|
||||
}
|
||||
|
||||
private BlackJackGameEntity processGameBasedOnState(BlackJackGameEntity game) {
|
||||
if (game.getState() != BlackJackState.IN_PROGRESS) {
|
||||
this.blackJackGameRepository.delete(game);
|
||||
return game;
|
||||
}
|
||||
|
||||
return blackJackGameRepository.save(game);
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue