From cd43f111c45b8bcda124cc2874472cfed1d54f90 Mon Sep 17 00:00:00 2001 From: jank Date: Wed, 28 May 2025 11:00:29 +0200 Subject: [PATCH 1/6] fix: Dont run on renovate --- .gitea/workflows/claude.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitea/workflows/claude.yml b/.gitea/workflows/claude.yml index 7bc0ffd..0bb0431 100644 --- a/.gitea/workflows/claude.yml +++ b/.gitea/workflows/claude.yml @@ -15,6 +15,13 @@ 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 @@ -51,6 +58,7 @@ 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 }} From efd744261dec23a8ee372d7ba1d4cde6934188fd Mon Sep 17 00:00:00 2001 From: jank Date: Wed, 28 May 2025 11:12:06 +0200 Subject: [PATCH 2/6] fix: Make claude better --- .gitea/workflows/claude.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/claude.yml b/.gitea/workflows/claude.yml index 0bb0431..efca6e7 100644 --- a/.gitea/workflows/claude.yml +++ b/.gitea/workflows/claude.yml @@ -71,4 +71,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." + 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" From 9553c66f119d3bfe01c1b4ab16fd235271a88535 Mon Sep 17 00:00:00 2001 From: jank Date: Wed, 28 May 2025 11:33:48 +0200 Subject: [PATCH 3/6] chore: Update the claude instructions --- .gitea/workflows/claude.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/claude.yml b/.gitea/workflows/claude.yml index efca6e7..7d34565 100644 --- a/.gitea/workflows/claude.yml +++ b/.gitea/workflows/claude.yml @@ -71,4 +71,5 @@ 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" + 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 clie to find out various things about the pull request" From 903ca20e9d9896c24d5e08c41727e4e6210d89ea Mon Sep 17 00:00:00 2001 From: jank Date: Wed, 28 May 2025 11:36:56 +0200 Subject: [PATCH 4/6] fix: Fix typo --- .gitea/workflows/claude.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/claude.yml b/.gitea/workflows/claude.yml index 7d34565..731226e 100644 --- a/.gitea/workflows/claude.yml +++ b/.gitea/workflows/claude.yml @@ -72,4 +72,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 clie to find out various things about the pull request" + You may also use the tea cli to find out various things about the pull request" From 3cbffba14f16019ea30ba139843e95656ee15f24 Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 28 May 2025 11:41:32 +0200 Subject: [PATCH 5/6] refactor: use userservice and balance service inside blackjack service --- .../blackjack/BlackJackGameController.java | 8 +--- .../casino/blackjack/BlackJackService.java | 40 ++++++++++++++----- 2 files changed, 30 insertions(+), 18 deletions(-) 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 df104dc..eb5bb79 100644 --- a/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameController.java +++ b/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameController.java @@ -59,13 +59,7 @@ public class BlackJackGameController { @PostMapping("/blackjack/start") public ResponseEntity createBlackJackGame(@RequestBody @Valid BetDto betDto) { - UserEntity user = this.userService.getCurrentUser(); - - if (!this.balanceService.hasFunds(user, betDto)) { - throw new InsufficientFundsException(); - } - - return ResponseEntity.ok(blackJackService.createBlackJackGame(user, betDto.getBetAmount())); + return ResponseEntity.ok(blackJackService.createBlackJackGame(betDto)); } 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 2d1c08b..cbdbc27 100644 --- a/backend/src/main/java/de/szut/casino/blackjack/BlackJackService.java +++ b/backend/src/main/java/de/szut/casino/blackjack/BlackJackService.java @@ -1,7 +1,11 @@ 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; @@ -13,11 +17,22 @@ import java.util.Random; public class BlackJackService { private final BlackJackGameRepository blackJackGameRepository; private final UserRepository userRepository; - private final Random random = new Random(); + private final Random random; + private final BalanceService balanceService; + private final UserService userService; - public BlackJackService(BlackJackGameRepository blackJackGameRepository, UserRepository userRepository) { + public BlackJackService( + BlackJackGameRepository blackJackGameRepository, + UserRepository userRepository, + Random random, + BalanceService balanceService, + UserService userService + ) { this.blackJackGameRepository = blackJackGameRepository; this.userRepository = userRepository; + this.random = random; + this.balanceService = balanceService; + this.userService = userService; } public BlackJackGameEntity getBlackJackGame(Long id) { @@ -25,16 +40,23 @@ public class BlackJackService { } @Transactional - public BlackJackGameEntity createBlackJackGame(UserEntity user, BigDecimal betAmount) { + public BlackJackGameEntity createBlackJackGame(BetDto betDto) { + UserEntity user = userService.getCurrentUser(); + + if (!this.balanceService.hasFunds(user, betDto)) { + throw new InsufficientFundsException(); + } + + this.balanceService.subtractFunds(user, betDto.getBetAmount()); + BlackJackGameEntity game = new BlackJackGameEntity(); game.setUser(user); - game.setBet(betAmount); + game.setBet(betDto.getBetAmount()); initializeDeck(game); dealInitialCards(game); game.setState(getState(game)); - deductBetFromBalance(user, betAmount); return processGameBasedOnState(game); } @@ -72,7 +94,8 @@ public class BlackJackService { UserEntity user = getUserWithFreshData(game.getUser()); BigDecimal additionalBet = game.getBet(); - deductBetFromBalance(user, additionalBet); + this.balanceService.subtractFunds(user, additionalBet); + game.setBet(game.getBet().add(additionalBet)); dealCardToPlayer(game); @@ -150,11 +173,6 @@ 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(); From e78fc58aaa293fb080e5cf8022e5aaec8625dfb5 Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 28 May 2025 11:50:10 +0200 Subject: [PATCH 6/6] refactor: remove dependency --- .../de/szut/casino/blackjack/BlackJackGameController.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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 eb5bb79..61051ad 100644 --- a/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameController.java +++ b/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameController.java @@ -1,10 +1,7 @@ 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; @@ -13,18 +10,15 @@ 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(BalanceService balanceService, UserService userService, BlackJackService blackJackService) { - this.balanceService = balanceService; + public BlackJackGameController(UserService userService, BlackJackService blackJackService) { this.blackJackService = blackJackService; this.userService = userService; }