import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
public class DriverController
{
private final EndlessConsumer consumer;
- private final AdderRecordHandler adderRecordHandler;
+ private final ApplicationRecordHandler recordHandler;
+ private final AdderResults results;
@PostMapping("start")
@GetMapping("state")
- public Map<Integer, Map<String, Long>> state()
+ public Map<Integer, Map<String, AdderResult>> state()
{
return
- adderRecordHandler
+ recordHandler
.getState()
.entrySet()
.stream()
}
@GetMapping("state/{user}")
- public ResponseEntity<Long> seen(@PathVariable String user)
+ public ResponseEntity<Long> state(@PathVariable String user)
{
- for (AdderBusinessLogic adderBusinessLogic : adderRecordHandler.getState().values())
+ for (AdderBusinessLogic adder : recordHandler.getState().values())
{
- Optional<Long> sum = adderBusinessLogic.getSum(user);
+ Optional<Long> sum = adder.getSum(user);
if (sum.isPresent())
return ResponseEntity.ok(sum.get());
}
return ResponseEntity.notFound().build();
}
+ @GetMapping("results")
+ public Map<Integer, Map<String, List<AdderResult>>> results()
+ {
+ return results.getState();
+ }
+
+ @GetMapping("results/{user}")
+ public ResponseEntity<List<AdderResult>> results(@PathVariable String user)
+ {
+ for (Map<String, List<AdderResult>> resultsByUser : this.results.getState().values())
+ {
+ List<AdderResult> results = resultsByUser.get(user);
+ if (results != null)
+ return ResponseEntity.ok(results);
+ }
+
+ return ResponseEntity.notFound().build();
+ }
+
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)