Compare commits

..

No commits in common. "v1.69.1" and "v1.69.0" have entirely different histories.

3 changed files with 26 additions and 41 deletions

View file

@ -15,13 +15,6 @@ jobs:
ref: ${{ github.ref }} ref: ${{ github.ref }}
fetch-tags: true fetch-tags: true
- name: Check if last commit is from Renovate Bot
id: check-renovate
run: |
AUTHOR=$(git log -1 --pretty=format:'%an')
echo "Author is $AUTHOR"
echo "author=$AUTHOR" >> "$GITHUB_OUTPUT"
- name: Set Tea Version - name: Set Tea Version
id: tea_version id: tea_version
run: echo "version=0.9.2" >> $GITHUB_OUTPUT # Check for the latest version run: echo "version=0.9.2" >> $GITHUB_OUTPUT # Check for the latest version
@ -58,7 +51,6 @@ jobs:
run: bun i -g @anthropic-ai/claude-code run: bun i -g @anthropic-ai/claude-code
- name: Claude PR Review - name: Claude PR Review
if: steps.check-renovate.outputs.author != 'Renovate Bot'
env: env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
PR_NUMBER: ${{ github.event.number }} PR_NUMBER: ${{ github.event.number }}
@ -71,5 +63,4 @@ jobs:
tea \"<reject or approve>\" ${PR_NUMBER} \"<your review message here>\" tea \"<reject or approve>\" ${PR_NUMBER} \"<your review message here>\"
Make sure the comment is clear, professional, and helpful. Only run the tea comment command once you're finished reviewing all changes. AND MOST IMPORTANDLY ONLY REVIEW THE DIFF FROM THE CURRENT STATE TO THE MAIN BRANCH TO GET THAT USE GIT DIFF. Also if the changes are rejected be a bit mean Make sure the comment is clear, professional, and helpful. Only run the tea comment command once you're finished reviewing all changes. AND MOST IMPORTANDLY ONLY REVIEW THE DIFF FROM THE CURRENT STATE TO THE MAIN BRANCH TO GET THAT USE GIT DIFF."
You may also use the tea cli to find out various things about the pull request"

View file

@ -1,7 +1,10 @@
package de.szut.casino.blackjack; package de.szut.casino.blackjack;
import de.szut.casino.exceptionHandling.exceptions.InsufficientFundsException;
import de.szut.casino.exceptionHandling.exceptions.UserBlackJackGameMismatchException; import de.szut.casino.exceptionHandling.exceptions.UserBlackJackGameMismatchException;
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
import de.szut.casino.shared.dto.BetDto; import de.szut.casino.shared.dto.BetDto;
import de.szut.casino.shared.service.BalanceService;
import de.szut.casino.user.UserEntity; import de.szut.casino.user.UserEntity;
import de.szut.casino.user.UserService; import de.szut.casino.user.UserService;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@ -10,15 +13,18 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
@Slf4j @Slf4j
@RestController @RestController
public class BlackJackGameController { public class BlackJackGameController {
private final BalanceService balanceService;
private final UserService userService; private final UserService userService;
private final BlackJackService blackJackService; private final BlackJackService blackJackService;
public BlackJackGameController(UserService userService, BlackJackService blackJackService) { public BlackJackGameController(BalanceService balanceService, UserService userService, BlackJackService blackJackService) {
this.balanceService = balanceService;
this.blackJackService = blackJackService; this.blackJackService = blackJackService;
this.userService = userService; this.userService = userService;
} }
@ -53,7 +59,13 @@ public class BlackJackGameController {
@PostMapping("/blackjack/start") @PostMapping("/blackjack/start")
public ResponseEntity<Object> createBlackJackGame(@RequestBody @Valid BetDto betDto) { public ResponseEntity<Object> createBlackJackGame(@RequestBody @Valid BetDto betDto) {
return ResponseEntity.ok(blackJackService.createBlackJackGame(betDto)); UserEntity user = this.userService.getCurrentUser();
if (!this.balanceService.hasFunds(user, betDto)) {
throw new InsufficientFundsException();
}
return ResponseEntity.ok(blackJackService.createBlackJackGame(user, betDto.getBetAmount()));
} }
private BlackJackGameEntity getBlackJackGame(Long gameId) { private BlackJackGameEntity getBlackJackGame(Long gameId) {

View file

@ -1,11 +1,7 @@
package de.szut.casino.blackjack; package de.szut.casino.blackjack;
import de.szut.casino.exceptionHandling.exceptions.InsufficientFundsException;
import de.szut.casino.shared.dto.BetDto;
import de.szut.casino.shared.service.BalanceService;
import de.szut.casino.user.UserEntity; import de.szut.casino.user.UserEntity;
import de.szut.casino.user.UserRepository; import de.szut.casino.user.UserRepository;
import de.szut.casino.user.UserService;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -17,22 +13,11 @@ import java.util.Random;
public class BlackJackService { public class BlackJackService {
private final BlackJackGameRepository blackJackGameRepository; private final BlackJackGameRepository blackJackGameRepository;
private final UserRepository userRepository; private final UserRepository userRepository;
private final Random random; private final Random random = new Random();
private final BalanceService balanceService;
private final UserService userService;
public BlackJackService( public BlackJackService(BlackJackGameRepository blackJackGameRepository, UserRepository userRepository) {
BlackJackGameRepository blackJackGameRepository,
UserRepository userRepository,
Random random,
BalanceService balanceService,
UserService userService
) {
this.blackJackGameRepository = blackJackGameRepository; this.blackJackGameRepository = blackJackGameRepository;
this.userRepository = userRepository; this.userRepository = userRepository;
this.random = random;
this.balanceService = balanceService;
this.userService = userService;
} }
public BlackJackGameEntity getBlackJackGame(Long id) { public BlackJackGameEntity getBlackJackGame(Long id) {
@ -40,23 +25,16 @@ public class BlackJackService {
} }
@Transactional @Transactional
public BlackJackGameEntity createBlackJackGame(BetDto betDto) { public BlackJackGameEntity createBlackJackGame(UserEntity user, BigDecimal betAmount) {
UserEntity user = userService.getCurrentUser();
if (!this.balanceService.hasFunds(user, betDto)) {
throw new InsufficientFundsException();
}
this.balanceService.subtractFunds(user, betDto.getBetAmount());
BlackJackGameEntity game = new BlackJackGameEntity(); BlackJackGameEntity game = new BlackJackGameEntity();
game.setUser(user); game.setUser(user);
game.setBet(betDto.getBetAmount()); game.setBet(betAmount);
initializeDeck(game); initializeDeck(game);
dealInitialCards(game); dealInitialCards(game);
game.setState(getState(game)); game.setState(getState(game));
deductBetFromBalance(user, betAmount);
return processGameBasedOnState(game); return processGameBasedOnState(game);
} }
@ -94,8 +72,7 @@ public class BlackJackService {
UserEntity user = getUserWithFreshData(game.getUser()); UserEntity user = getUserWithFreshData(game.getUser());
BigDecimal additionalBet = game.getBet(); BigDecimal additionalBet = game.getBet();
this.balanceService.subtractFunds(user, additionalBet); deductBetFromBalance(user, additionalBet);
game.setBet(game.getBet().add(additionalBet)); game.setBet(game.getBet().add(additionalBet));
dealCardToPlayer(game); dealCardToPlayer(game);
@ -173,6 +150,11 @@ public class BlackJackService {
} }
} }
private void deductBetFromBalance(UserEntity user, BigDecimal betAmount) {
user.setBalance(user.getBalance().subtract(betAmount));
userRepository.save(user);
}
protected void updateUserBalance(BlackJackGameEntity game, boolean isWin) { protected void updateUserBalance(BlackJackGameEntity game, boolean isWin) {
UserEntity user = getUserWithFreshData(game.getUser()); UserEntity user = getUserWithFreshData(game.getUser());
BigDecimal totalBet = game.getBet(); BigDecimal totalBet = game.getBet();