feat: validate game state on hit
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
	
		
	
		
			All checks were successful
		
		
	
	
This commit is contained in:
		
					parent
					
						
							
								d7690e630e
							
						
					
				
			
			
				commit
				
					
						4764c12909
					
				
			
		
					 3 changed files with 8 additions and 2 deletions
				
			
		|  | @ -7,6 +7,6 @@ Content-Type: application/json | |||
| } | ||||
| 
 | ||||
| ### | ||||
| POST http://localhost:8080/blackjack/103/hit | ||||
| POST http://localhost:8080/blackjack/202/hit | ||||
| Authorization: Bearer {{token}} | ||||
| 
 | ||||
|  |  | |||
|  | @ -40,6 +40,12 @@ public class BlackJackGameController { | |||
|             return ResponseEntity.notFound().build(); | ||||
|         } | ||||
| 
 | ||||
|         if (game.getState() != BlackJackState.IN_PROGRESS) { | ||||
|             Map<String, String> errorResponse = new HashMap<>(); | ||||
|             errorResponse.put("error", "Invalid state"); | ||||
|             return ResponseEntity.badRequest().body(errorResponse); | ||||
|         } | ||||
| 
 | ||||
|         return ResponseEntity.ok(blackJackService.hit(game)); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -94,7 +94,7 @@ public class BlackJackService { | |||
|         return BlackJackState.IN_PROGRESS; | ||||
|     } | ||||
| 
 | ||||
|     public int calculateHandValue(List<CardEntity> hand) { | ||||
|     private int calculateHandValue(List<CardEntity> hand) { | ||||
|         int sum = 0; | ||||
|         int aceCount = 0; | ||||
|         for (CardEntity card : hand) { | ||||
|  |  | |||
		Reference in a new issue