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;
+import java.util.stream.Collectors;
@RestController
public class DriverController
{
private final EndlessConsumer consumer;
- private final WordcountRecordHandler wordcount;
+ private final ApplicationRecordHandler recordHandler;
+ private final AdderResults results;
@PostMapping("start")
}
- @GetMapping("seen")
- public Map<Integer, Map<String, Map<String, Long>>> seen()
+ @GetMapping("state")
+ public Map<Integer, Map<String, AdderResult>> state()
{
- return wordcount.getSeen();
+ return
+ recordHandler
+ .getState()
+ .entrySet()
+ .stream()
+ .collect(Collectors.toMap(
+ entry -> entry.getKey(),
+ entry -> entry.getValue().getState()));
}
- @GetMapping("seen/{user}")
- public ResponseEntity<Map<String, Long>> seen(@PathVariable String user)
+ @GetMapping("state/{user}")
+ public ResponseEntity<Long> state(@PathVariable String user)
{
- for (Map<String, Map<String, Long>> users : wordcount.getSeen().values())
+ for (AdderBusinessLogic adder : recordHandler.getState().values())
{
- Map<String, Long> words = users.get(user);
- if (words != null)
- return ResponseEntity.ok(words);
+ 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();