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));
|
game.setState(getState(game));
|
||||||
deductBetFromBalance(user, betAmount);
|
deductBetFromBalance(user, betAmount);
|
||||||
|
|
||||||
return blackJackGameRepository.save(game);
|
return processGameBasedOnState(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -44,12 +44,11 @@ public class BlackJackService {
|
||||||
if (game.getState() != BlackJackState.IN_PROGRESS) {
|
if (game.getState() != BlackJackState.IN_PROGRESS) {
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
dealCardToPlayer(game);
|
dealCardToPlayer(game);
|
||||||
|
|
||||||
updateGameStateAndBalance(game);
|
updateGameStateAndBalance(game);
|
||||||
|
|
||||||
return blackJackGameRepository.save(game);
|
return processGameBasedOnState(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -57,11 +56,11 @@ public class BlackJackService {
|
||||||
if (game.getState() != BlackJackState.IN_PROGRESS) {
|
if (game.getState() != BlackJackState.IN_PROGRESS) {
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
dealCardsToDealerUntilMinimumScore(game);
|
dealCardsToDealerUntilMinimumScore(game);
|
||||||
determineWinnerAndUpdateBalance(game);
|
determineWinnerAndUpdateBalance(game);
|
||||||
|
|
||||||
return blackJackGameRepository.save(game);
|
return processGameBasedOnState(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -69,50 +68,59 @@ public class BlackJackService {
|
||||||
if (game.getState() != BlackJackState.IN_PROGRESS || game.getPlayerCards().size() != 2) {
|
if (game.getState() != BlackJackState.IN_PROGRESS || game.getPlayerCards().size() != 2) {
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserEntity user = getUserWithFreshData(game.getUser());
|
UserEntity user = getUserWithFreshData(game.getUser());
|
||||||
BigDecimal additionalBet = game.getBet();
|
BigDecimal additionalBet = game.getBet();
|
||||||
|
|
||||||
deductBetFromBalance(user, additionalBet);
|
deductBetFromBalance(user, additionalBet);
|
||||||
game.setBet(game.getBet().add(additionalBet));
|
game.setBet(game.getBet().add(additionalBet));
|
||||||
|
|
||||||
dealCardToPlayer(game);
|
dealCardToPlayer(game);
|
||||||
updateGameStateAndBalance(game);
|
updateGameStateAndBalance(game);
|
||||||
|
|
||||||
if (game.getState() == BlackJackState.IN_PROGRESS) {
|
if (game.getState() == BlackJackState.IN_PROGRESS) {
|
||||||
return stand(game);
|
return stand(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public BlackJackGameEntity split(BlackJackGameEntity game) {
|
public BlackJackGameEntity split(BlackJackGameEntity game) {
|
||||||
if (game.getState() != BlackJackState.IN_PROGRESS ||
|
if (game.getState() != BlackJackState.IN_PROGRESS ||
|
||||||
game.getPlayerCards().size() != 2 ||
|
game.getPlayerCards().size() != 2 ||
|
||||||
game.isSplit() ||
|
game.isSplit() ||
|
||||||
!game.getPlayerCards().get(0).getRank().equals(game.getPlayerCards().get(1).getRank())) {
|
!game.getPlayerCards().get(0).getRank().equals(game.getPlayerCards().get(1).getRank())) {
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserEntity user = getUserWithFreshData(game.getUser());
|
UserEntity user = getUserWithFreshData(game.getUser());
|
||||||
BigDecimal splitBet = game.getBet();
|
BigDecimal splitBet = game.getBet();
|
||||||
|
|
||||||
if (user.getBalance().compareTo(splitBet) < 0) {
|
if (user.getBalance().compareTo(splitBet) < 0) {
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
deductBetFromBalance(user, splitBet);
|
deductBetFromBalance(user, splitBet);
|
||||||
game.setSplitBet(splitBet);
|
game.setSplitBet(splitBet);
|
||||||
game.setSplit(true);
|
game.setSplit(true);
|
||||||
|
|
||||||
CardEntity card = game.getPlayerCards().remove(1);
|
CardEntity card = game.getPlayerCards().remove(1);
|
||||||
card.setCardType(CardType.PLAYER_SPLIT);
|
card.setCardType(CardType.PLAYER_SPLIT);
|
||||||
game.getPlayerSplitCards().add(card);
|
game.getPlayerSplitCards().add(card);
|
||||||
|
|
||||||
dealCardToPlayer(game);
|
dealCardToPlayer(game);
|
||||||
dealCardToSplitHand(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);
|
return blackJackGameRepository.save(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue