feat: validate game state on hit (CAS-51) #103

Merged
ptran merged 1 commit from feat/hit-state-validation into main 2025-03-27 13:07:37 +00:00
3 changed files with 8 additions and 2 deletions

View file

@ -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}}

View file

@ -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));
}

View file

@ -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) {