Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
b34b12cfc7 |
|||
|
e78fc58aaa | ||
|
3cbffba14f | ||
fe0bc9d556 |
|||
903ca20e9d | |||
9553c66f11 | |||
d5f4bcee05 |
|||
efd744261d | |||
89c6be5345 |
|||
cd43f111c4 |
3 changed files with 41 additions and 26 deletions
|
@ -15,6 +15,13 @@ 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
|
||||||
|
@ -51,6 +58,7 @@ 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 }}
|
||||||
|
@ -63,4 +71,5 @@ 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."
|
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"
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
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;
|
||||||
|
@ -13,18 +10,15 @@ 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(BalanceService balanceService, UserService userService, BlackJackService blackJackService) {
|
public BlackJackGameController(UserService userService, BlackJackService blackJackService) {
|
||||||
this.balanceService = balanceService;
|
|
||||||
this.blackJackService = blackJackService;
|
this.blackJackService = blackJackService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
@ -59,13 +53,7 @@ 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) {
|
||||||
UserEntity user = this.userService.getCurrentUser();
|
return ResponseEntity.ok(blackJackService.createBlackJackGame(betDto));
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -13,11 +17,22 @@ 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 = 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.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) {
|
||||||
|
@ -25,16 +40,23 @@ public class BlackJackService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@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();
|
BlackJackGameEntity game = new BlackJackGameEntity();
|
||||||
game.setUser(user);
|
game.setUser(user);
|
||||||
game.setBet(betAmount);
|
game.setBet(betDto.getBetAmount());
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +94,8 @@ public class BlackJackService {
|
||||||
UserEntity user = getUserWithFreshData(game.getUser());
|
UserEntity user = getUserWithFreshData(game.getUser());
|
||||||
BigDecimal additionalBet = game.getBet();
|
BigDecimal additionalBet = game.getBet();
|
||||||
|
|
||||||
deductBetFromBalance(user, additionalBet);
|
this.balanceService.subtractFunds(user, additionalBet);
|
||||||
|
|
||||||
game.setBet(game.getBet().add(additionalBet));
|
game.setBet(game.getBet().add(additionalBet));
|
||||||
|
|
||||||
dealCardToPlayer(game);
|
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) {
|
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();
|
||||||
|
|
Reference in a new issue