diff --git a/.gitea/workflows/claude.yml b/.gitea/workflows/claude.yml index 731226e..7bc0ffd 100644 --- a/.gitea/workflows/claude.yml +++ b/.gitea/workflows/claude.yml @@ -15,13 +15,6 @@ jobs: ref: ${{ github.ref }} 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 id: tea_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 - name: Claude PR Review - if: steps.check-renovate.outputs.author != 'Renovate Bot' env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} PR_NUMBER: ${{ github.event.number }} @@ -71,5 +63,4 @@ jobs: tea \"\" ${PR_NUMBER} \"\" - 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 - You may also use the tea cli to find out various things about the pull request" + 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." diff --git a/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameController.java b/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameController.java index 61051ad..df104dc 100644 --- a/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameController.java +++ b/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameController.java @@ -1,7 +1,10 @@ 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.UserNotFoundException; 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.UserService; import jakarta.validation.Valid; @@ -10,15 +13,18 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.Objects; +import java.util.Optional; @Slf4j @RestController public class BlackJackGameController { + private final BalanceService balanceService; private final UserService userService; 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.userService = userService; } @@ -53,7 +59,13 @@ public class BlackJackGameController { @PostMapping("/blackjack/start") public ResponseEntity 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) { diff --git a/backend/src/main/java/de/szut/casino/blackjack/BlackJackService.java b/backend/src/main/java/de/szut/casino/blackjack/BlackJackService.java index cbdbc27..2d1c08b 100644 --- a/backend/src/main/java/de/szut/casino/blackjack/BlackJackService.java +++ b/backend/src/main/java/de/szut/casino/blackjack/BlackJackService.java @@ -1,11 +1,7 @@ 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.UserRepository; -import de.szut.casino.user.UserService; import jakarta.transaction.Transactional; import org.springframework.stereotype.Service; @@ -17,22 +13,11 @@ import java.util.Random; public class BlackJackService { private final BlackJackGameRepository blackJackGameRepository; private final UserRepository userRepository; - private final Random random; - private final BalanceService balanceService; - private final UserService userService; + private final Random random = new Random(); - public BlackJackService( - BlackJackGameRepository blackJackGameRepository, - UserRepository userRepository, - Random random, - BalanceService balanceService, - UserService userService - ) { + public BlackJackService(BlackJackGameRepository blackJackGameRepository, UserRepository userRepository) { this.blackJackGameRepository = blackJackGameRepository; this.userRepository = userRepository; - this.random = random; - this.balanceService = balanceService; - this.userService = userService; } public BlackJackGameEntity getBlackJackGame(Long id) { @@ -40,23 +25,16 @@ public class BlackJackService { } @Transactional - public BlackJackGameEntity createBlackJackGame(BetDto betDto) { - UserEntity user = userService.getCurrentUser(); - - if (!this.balanceService.hasFunds(user, betDto)) { - throw new InsufficientFundsException(); - } - - this.balanceService.subtractFunds(user, betDto.getBetAmount()); - + public BlackJackGameEntity createBlackJackGame(UserEntity user, BigDecimal betAmount) { BlackJackGameEntity game = new BlackJackGameEntity(); game.setUser(user); - game.setBet(betDto.getBetAmount()); + game.setBet(betAmount); initializeDeck(game); dealInitialCards(game); game.setState(getState(game)); + deductBetFromBalance(user, betAmount); return processGameBasedOnState(game); } @@ -94,8 +72,7 @@ public class BlackJackService { UserEntity user = getUserWithFreshData(game.getUser()); BigDecimal additionalBet = game.getBet(); - this.balanceService.subtractFunds(user, additionalBet); - + deductBetFromBalance(user, additionalBet); game.setBet(game.getBet().add(additionalBet)); 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) { UserEntity user = getUserWithFreshData(game.getUser()); BigDecimal totalBet = game.getBet();