WIP
[demos/kafka/training] / src / main / java / de / juplo / kafka / DriverController.java
index fdae76f..3aa9314 100644 (file)
@@ -7,7 +7,9 @@ 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
@@ -31,20 +33,27 @@ public class DriverController
   }
 
 
-  @GetMapping("seen")
-  public Map<Integer, Map<String, List<Long>>> seen()
+  @GetMapping("state")
+  public Map<Integer, Map<String, Long>> state()
   {
-    return sumRecordHandler.getSeen();
+    return
+        sumRecordHandler
+            .getState()
+            .entrySet()
+            .stream()
+            .collect(Collectors.toMap(
+                entry -> entry.getKey(),
+                entry -> entry.getValue().getState()));
   }
 
-  @GetMapping("seen/{user}")
-  public ResponseEntity<List<Long>> seen(@PathVariable String user)
+  @GetMapping("state/{user}")
+  public ResponseEntity<Long> seen(@PathVariable String user)
   {
-    for (Map<String, List<Long>> users : sumRecordHandler.getSeen().values())
+    for (SumBusinessLogic sumBusinessLogic : sumRecordHandler.getState().values())
     {
-      List<Long> results = users.get(user);
-      if (results != null)
-        return ResponseEntity.ok(results);
+      Optional<Long> sum = sumBusinessLogic.getSum(user);
+      if (sum.isPresent())
+        return ResponseEntity.ok(sum.get());
     }
 
     return ResponseEntity.notFound().build();