-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerRestController.java
35 lines (30 loc) · 1.35 KB
/
PlayerRestController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package dungeon.trading.player;
import net.minidev.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class PlayerRestController {
private final PlayerService playerService;
public PlayerRestController(PlayerService playerService) {
this.playerService = playerService;
}
@GetMapping("/balances")
public ResponseEntity<?> getAllPlayerBalances() {
JSONArray balances = this.playerService.getAllCurrentPlayerBalances();
return new ResponseEntity<JSONArray>(balances, HttpStatus.OK);
}
@GetMapping("/balances/{round}")
public ResponseEntity<?> getPlayerBalancesForRound(@PathVariable int round) {
try {
JSONArray balances = this.playerService.getPlayerBalancesForRound(round);
return new ResponseEntity<JSONArray>(balances, HttpStatus.OK);
} catch (Exception e) {
String errorMsg = "There are no balanceHistories for round " + round + " saved.";
return new ResponseEntity<String>(errorMsg, HttpStatus.NOT_FOUND);
}
}
}