Overview
ThePOST /game/new endpoint creates a new Blackjack game for a player. If the player doesn’t exist, they will be automatically created with the provided name.
Endpoint
Request Body
The name of the player. Must not be blank and must be 30 characters or less.
Response
Returns a201 Created status with the following fields:
Unique identifier for the newly created game
Unique identifier for the player
Current game status. Possible values:
IN_PROGRESS- Game is active and waiting for player movesPLAYER_WINS- Player has a natural blackjack and dealer doesn’tDEALER_WINS- Dealer has a natural blackjack and player doesn’tPUSH- Both player and dealer have natural blackjacks
How It Works
TheCreateNewGameUseCase handles the game creation logic:
- Player validation: The player name is validated (must not be blank, max 30 characters)
- Player lookup/creation: The system searches for an existing player with that name. If not found, a new player is created
- Game initialization: A new game is created with:
- A shuffled standard 52-card deck
- Two cards dealt to the player
- Two cards dealt to the dealer
- Natural blackjack check: The game immediately checks if either player or dealer has a natural blackjack (21 with two cards) and sets the status accordingly
Example Request
Example Response
Error Responses
400 Bad Request
Returned when validation fails:- Player name is blank or missing
- Player name exceeds 30 characters
Implementation Details
The game creation process (fromCreateNewGameUseCase.java:22-40):
Next Steps
After creating a game:- Use GET /game/ to view the initial game state
- Use POST /game//play to make your first move (HIT or STAND)