|
|
|
@ -1,8 +1,10 @@
|
|
|
|
|
package de.szut.casino.blackjack;
|
|
|
|
|
|
|
|
|
|
import de.szut.casino.blackjack.dto.CreateBlackJackGameDto;
|
|
|
|
|
import de.szut.casino.user.UserEntity;
|
|
|
|
|
import de.szut.casino.user.UserService;
|
|
|
|
|
import de.szut.casino.user.dto.CreateUserDto;
|
|
|
|
|
import de.szut.casino.user.dto.GetUserDto;
|
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -13,6 +15,10 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
public class BlackJackGameController {
|
|
|
|
@ -21,15 +27,24 @@ public class BlackJackGameController {
|
|
|
|
|
private UserService userService;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/blackjack/start")
|
|
|
|
|
public ResponseEntity<?> createBlackJackGame(@RequestBody @Valid CreateBlackJackGameDto gameData, @RequestHeader("Authorization") String token) {
|
|
|
|
|
if (gameData.getBetAmount() <= 0 || gameData.getBetAmount() > userService.getCurrentUser(token).getBalance().intValue()) {
|
|
|
|
|
return ResponseEntity.badRequest().body("Invalid bet amount");
|
|
|
|
|
public ResponseEntity<?> createBlackJackGame(@RequestBody @Valid CreateBlackJackGameDto createBlackJackGameDto, @RequestHeader("Authorization") String token) {
|
|
|
|
|
GetUserDto getUserDto = userService.getCurrentUser(token);
|
|
|
|
|
BigDecimal balance = getUserDto.getBalance();
|
|
|
|
|
|
|
|
|
|
if (createBlackJackGameDto.getBetAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
Map<String, String> errorResponse = new HashMap<>();
|
|
|
|
|
errorResponse.put("error", "Invalid bet amount");
|
|
|
|
|
return ResponseEntity.badRequest().body(errorResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlackJackGameEntity game = new BlackJackGameEntity();
|
|
|
|
|
game.setBet(gameData.getBetAmount());
|
|
|
|
|
System.out.println("Balls: ");
|
|
|
|
|
System.out.println(game.getBet());
|
|
|
|
|
if (createBlackJackGameDto.getBetAmount().compareTo(balance) > 0) {
|
|
|
|
|
Map<String, String> errorResponse = new HashMap<>();
|
|
|
|
|
errorResponse.put("error", "Insufficient funds");
|
|
|
|
|
return ResponseEntity.badRequest().body(errorResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|