feat(blackjack): add BlackJack game creation functionality
This commit is contained in:
parent
24ea51318f
commit
8cb045fcbe
5 changed files with 80 additions and 0 deletions
7
backend/requests/test.http
Normal file
7
backend/requests/test.http
Normal file
|
@ -0,0 +1,7 @@
|
|||
POST http://localhost:8080/blackjack/start
|
||||
Authorization: Bearer {{token}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"betAmount": 999
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
import de.szut.casino.blackjack.dto.CreateBlackJackGameDto;
|
||||
import de.szut.casino.user.UserService;
|
||||
import de.szut.casino.user.dto.CreateUserDto;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class BlackJackGameController {
|
||||
|
||||
@Autowired
|
||||
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");
|
||||
}
|
||||
|
||||
BlackJackGameEntity game = new BlackJackGameEntity();
|
||||
game.setBet(gameData.getBetAmount());
|
||||
System.out.println("Balls: ");
|
||||
System.out.println(game.getBet());
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
public class BlackJackGameEntity {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private ArrayList<Card> playerHand;
|
||||
private ArrayList<Card> dealerHand;
|
||||
private ArrayList<Card> deck;
|
||||
private String state;
|
||||
private int bet;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package de.szut.casino.blackjack.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CreateBlackJackGameDto {
|
||||
private int betAmount;
|
||||
}
|
Loading…
Add table
Reference in a new issue