Skip to main content

Overview

The DELETE /game/{id}/delete endpoint permanently removes a Blackjack game from the system. This can be used to clean up finished games or cancel active games.

Endpoint

DELETE /game/{id}/delete

Path Parameters

id
string
required
The unique identifier of the game to delete

Response

Returns a 204 No Content status on successful deletion with no response body.

When to Delete Games

You should consider deleting games in these scenarios:

After Game Completion

Once a game has ended (status is PLAYER_WINS, DEALER_WINS, or PUSH), the player stats have already been updated in the ranking system. The game record itself is no longer needed for gameplay.
# After finishing a game
curl -X DELETE http://localhost:8080/game/550e8400-e29b-41d4-a716-446655440000/delete

Canceling Active Games

If a player wants to abandon a game that is still IN_PROGRESS, you can delete it. Note that this will not affect player statistics (no win/loss is recorded).
# Cancel an ongoing game
curl -X DELETE http://localhost:8080/game/550e8400-e29b-41d4-a716-446655440000/delete

Cleanup Operations

For administrative or maintenance purposes, you may want to periodically clean up old game records to free up database space.

Example Request

curl -X DELETE http://localhost:8080/game/550e8400-e29b-41d4-a716-446655440000/delete

Example Response

Success (204 No Content): No response body is returned. The HTTP status code 204 indicates successful deletion.
HTTP/1.1 204 No Content

Error Responses

404 Not Found

Returned when the game doesn’t exist (either never existed or was already deleted):
{
  "timestamp": "2026-03-06T10:30:00Z",
  "status": 404,
  "error": "Not Found",
  "message": "Game not found: 550e8400-e29b-41d4-a716-446655440000"
}

Important Notes

Permanent Deletion

Deleting a game is permanent and cannot be undone. The game state, card history, and all associated data will be removed from the database.

Player Stats Preserved

Deleting a game does not affect player statistics. If the game was completed before deletion:
  • The player’s win/loss record remains intact
  • The player’s ranking position is unchanged
  • Historical stats are preserved
Only the specific game record itself is removed.

No Validation on Game Status

You can delete a game regardless of its current status:
  • IN_PROGRESS games can be deleted (no stats recorded)
  • Finished games (PLAYER_WINS, DEALER_WINS, PUSH) can be deleted (stats already recorded)

Implementation Details

The deletion is handled by DeleteGameUseCase.java:15-17:
public Mono<Void> execute(String gameId) {
    return gameRepo.deleteById(new GameId(gameId));
}
The repository layer handles the actual deletion from the database. If the game doesn’t exist, a GameNotFoundException is thrown and returned as a 404 response.

Complete Game Lifecycle Example

# 1. Create a new game
curl -X POST http://localhost:8080/game/new \
  -H "Content-Type: application/json" \
  -d '{"playerName": "Alice"}'

# Response: {"gameId": "550e8400-e29b-41d4-a716-446655440000", ...}

# 2. Play some moves
curl -X POST http://localhost:8080/game/550e8400-e29b-41d4-a716-446655440000/play \
  -H "Content-Type: application/json" \
  -d '{"action": "HIT"}'

curl -X POST http://localhost:8080/game/550e8400-e29b-41d4-a716-446655440000/play \
  -H "Content-Type: application/json" \
  -d '{"action": "STAND"}'

# 3. Check final state
curl -X GET http://localhost:8080/game/550e8400-e29b-41d4-a716-446655440000

# Response: {"status": "PLAYER_WINS", ...}

# 4. Delete the completed game
curl -X DELETE http://localhost:8080/game/550e8400-e29b-41d4-a716-446655440000/delete

# Response: 204 No Content

Best Practices

  1. Check game status before deletion: Use GET /game/ to verify the game state before deleting
  2. Clean up finished games: Regularly delete completed games to keep the database clean
  3. Handle 404 errors gracefully: Don’t treat “game not found” as a critical error during cleanup operations
  4. Consider retention policies: For audit purposes, you may want to keep game records for a certain period before deletion

Next Steps

Build docs developers (and LLMs) love