Merge pull request 'feat: validate game state on hit (CAS-51)' (!103) from feat/hit-state-validation into main
All checks were successful
Release / Release (push) Successful in 41s

Reviewed-on: #103
Reviewed-by: Jan K9f <jan@kjan.email>
This commit is contained in:
Phan Huy Tran 2025-03-27 13:07:37 +00:00
commit 4fa7b63b04
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

@ -96,7 +96,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) {