Compare commits
3 commits
d51242b233
...
f3414e77ca
Author | SHA1 | Date | |
---|---|---|---|
f3414e77ca | |||
40b717745d | |||
126681dfa4 |
3 changed files with 22 additions and 2 deletions
|
@ -5,3 +5,8 @@ Content-Type: application/json
|
|||
{
|
||||
"betAmount": 1.01
|
||||
}
|
||||
|
||||
###
|
||||
POST http://localhost:8080/blackjack/52/hit
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
|
@ -35,11 +36,14 @@ public class BlackJackGameController {
|
|||
|
||||
UserEntity user = optionalUser.get();
|
||||
BlackJackGameEntity game = blackJackService.getBlackJackGame(id);
|
||||
if (game == null) {
|
||||
if (game == null || !Objects.equals(game.getUserId(), user.getId())) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
|
||||
// TODO validate that hit is a valid action
|
||||
|
||||
blackJackService.hit(game);
|
||||
return ResponseEntity.ok(game);
|
||||
}
|
||||
|
||||
@PostMapping("/blackjack/start")
|
||||
|
|
|
@ -5,6 +5,8 @@ import de.szut.casino.user.UserRepository;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -48,6 +50,15 @@ public class BlackJackService {
|
|||
return game;
|
||||
}
|
||||
|
||||
public BlackJackGameEntity hit(BlackJackGameEntity game) {
|
||||
CardEntity drawnCard = drawCardFromDeck(game);
|
||||
List<CardEntity> playerCards = game.getPlayerCards();
|
||||
|
||||
playerCards.add(drawnCard);
|
||||
blackJackGameRepository.save(game);
|
||||
return game;
|
||||
}
|
||||
|
||||
private void initializeDeck(BlackJackGameEntity game) {
|
||||
for (Suit suit : Suit.values()) {
|
||||
for (Rank rank : Rank.values()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue