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
|
@ -36,7 +36,7 @@ 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
|
||||||
|
@ -46,10 +46,9 @@ public class BlackJackService {
|
||||||
}
|
}
|
||||||
|
|
||||||
dealCardToPlayer(game);
|
dealCardToPlayer(game);
|
||||||
|
|
||||||
updateGameStateAndBalance(game);
|
updateGameStateAndBalance(game);
|
||||||
|
|
||||||
return blackJackGameRepository.save(game);
|
return processGameBasedOnState(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -61,7 +60,7 @@ public class BlackJackService {
|
||||||
dealCardsToDealerUntilMinimumScore(game);
|
dealCardsToDealerUntilMinimumScore(game);
|
||||||
determineWinnerAndUpdateBalance(game);
|
determineWinnerAndUpdateBalance(game);
|
||||||
|
|
||||||
return blackJackGameRepository.save(game);
|
return processGameBasedOnState(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -116,6 +115,15 @@ public class BlackJackService {
|
||||||
return blackJackGameRepository.save(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);
|
||||||
|
}
|
||||||
|
|
||||||
private BlackJackGameEntity refreshGameState(BlackJackGameEntity game) {
|
private BlackJackGameEntity refreshGameState(BlackJackGameEntity game) {
|
||||||
return blackJackGameRepository.findById(game.getId()).orElse(game);
|
return blackJackGameRepository.findById(game.getId()).orElse(game);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue