Die Ergebnisse werden gespeichert und sind via REST abrufbar
[demos/kafka/training] / src / main / java / de / juplo / kafka / DriverController.java
index 63f015d..26a5bc8 100644 (file)
@@ -5,6 +5,7 @@ import org.springframework.http.HttpStatus;
 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;
@@ -17,6 +18,7 @@ public class DriverController
 {
   private final EndlessConsumer consumer;
   private final ApplicationRecordHandler recordHandler;
+  private final AdderResults results;
 
 
   @PostMapping("start")
@@ -46,7 +48,7 @@ public class DriverController
   }
 
   @GetMapping("state/{user}")
-  public ResponseEntity<Long> seen(@PathVariable String user)
+  public ResponseEntity<Long> state(@PathVariable String user)
   {
     for (AdderBusinessLogic adder : recordHandler.getState().values())
     {
@@ -58,6 +60,25 @@ public class DriverController
     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)