WIP
[demos/kafka/training] / src / main / java / de / juplo / kafka / DriverController.java
index 5a09c1b..3aa9314 100644 (file)
@@ -5,8 +5,11 @@ 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;
+import java.util.stream.Collectors;
 
 
 @RestController
@@ -14,7 +17,7 @@ import java.util.concurrent.ExecutionException;
 public class DriverController
 {
   private final EndlessConsumer consumer;
-  private final SumRecordHandler wordcount;
+  private final SumRecordHandler sumRecordHandler;
 
 
   @PostMapping("start")
@@ -30,20 +33,27 @@ public class DriverController
   }
 
 
-  @GetMapping("seen")
-  public Map<Integer, Map<String, Map<String, Long>>> seen()
+  @GetMapping("state")
+  public Map<Integer, Map<String, Long>> state()
   {
-    return wordcount.getSeen();
+    return
+        sumRecordHandler
+            .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> seen(@PathVariable String user)
   {
-    for (Map<String, Map<String, Long>> users : wordcount.getSeen().values())
+    for (SumBusinessLogic sumBusinessLogic : sumRecordHandler.getState().values())
     {
-      Map<String, Long> words = users.get(user);
-      if (words != null)
-        return ResponseEntity.ok(words);
+      Optional<Long> sum = sumBusinessLogic.getSum(user);
+      if (sum.isPresent())
+        return ResponseEntity.ok(sum.get());
     }
 
     return ResponseEntity.notFound().build();