TMP
[demos/kafka/training] / src / main / java / de / juplo / kafka / DriverController.java
index f6ff47f..5a09c1b 100644 (file)
@@ -2,6 +2,7 @@ package de.juplo.kafka;
 
 import lombok.RequiredArgsConstructor;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Map;
@@ -13,7 +14,7 @@ import java.util.concurrent.ExecutionException;
 public class DriverController
 {
   private final EndlessConsumer consumer;
-  private final KeyCountingRecordHandler keyCountingRecordHandler;
+  private final SumRecordHandler wordcount;
 
 
   @PostMapping("start")
@@ -30,9 +31,22 @@ public class DriverController
 
 
   @GetMapping("seen")
-  public Map<Integer, Map<String, Long>> seen()
+  public Map<Integer, Map<String, Map<String, Long>>> seen()
   {
-    return keyCountingRecordHandler.getSeen();
+    return wordcount.getSeen();
+  }
+
+  @GetMapping("seen/{user}")
+  public ResponseEntity<Map<String, Long>> seen(@PathVariable String user)
+  {
+    for (Map<String, Map<String, Long>> users : wordcount.getSeen().values())
+    {
+      Map<String, Long> words = users.get(user);
+      if (words != null)
+        return ResponseEntity.ok(words);
+    }
+
+    return ResponseEntity.notFound().build();
   }