Overview
TheDELETE /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
Path Parameters
The unique identifier of the game to delete
Response
Returns a204 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 isPLAYER_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.
Canceling Active Games
If a player wants to abandon a game that is stillIN_PROGRESS, you can delete it. Note that this will not affect player statistics (no win/loss is recorded).
Cleanup Operations
For administrative or maintenance purposes, you may want to periodically clean up old game records to free up database space.Example Request
Example Response
Success (204 No Content): No response body is returned. The HTTP status code204 indicates successful deletion.
Error Responses
404 Not Found
Returned when the game doesn’t exist (either never existed or was already deleted):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
No Validation on Game Status
You can delete a game regardless of its current status:IN_PROGRESSgames 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 byDeleteGameUseCase.java:15-17:
GameNotFoundException is thrown and returned as a 404 response.
Complete Game Lifecycle Example
Best Practices
- Check game status before deletion: Use GET /game/ to verify the game state before deleting
- Clean up finished games: Regularly delete completed games to keep the database clean
- Handle 404 errors gracefully: Don’t treat “game not found” as a critical error during cleanup operations
- Consider retention policies: For audit purposes, you may want to keep game records for a certain period before deletion
Next Steps
- Create a new game to start fresh
- View your player ranking to see accumulated stats
- Learn about playing moves in active games