-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
55 lines (41 loc) · 1.61 KB
/
Copy pathController.java
File metadata and controls
55 lines (41 loc) · 1.61 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.Game.chess;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@RestController
@RequestMapping("/api")
public class Controller {
@Autowired
private Service service;
@GetMapping("/cell-data")
public Map<String, String> getCellData(@RequestParam int row, @RequestParam int col) {
String info = service.getInfoForCell(row, col);
Map<String, String> response = new HashMap<>();
response.put("info", info);
return response;
}
@GetMapping("/valid-moves")
public List<Coordinate> validMoves(@RequestParam int row, @RequestParam int col) {
List<List<Integer>> coordinates = service.getValidMoves(row, col);
List<Coordinate> response = new ArrayList<>();
for (List<Integer> coordinate : coordinates) {
response.add(new Coordinate(coordinate.get(0), coordinate.get(1)));
}
return response;
}
@PostMapping("/move-piece")
public void MovePiece(@RequestBody CoordinateRequest coordinates) {
Coordinate start = coordinates.getStart();
Coordinate end = coordinates.getEnd();
service.makeMove(start, end);
}
@PostMapping("/reset")
public void reset() {
service.Reset();
}
}