package de.juplo.kafka;
import lombok.RequiredArgsConstructor;
-import org.apache.kafka.common.TopicPartition;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@GetMapping("seen")
- public Map<TopicPartition, PartitionStatistics> seen()
+ public Map<Integer, Map<String, Map<String, Long>>> seen()
{
return consumer.getSeen();
}
+
+ @GetMapping("seen/{user}")
+ public ResponseEntity<Map<String, Long>> seen(@PathVariable String user)
+ {
+ for (Map<String, Map<String, Long>> users : consumer.getSeen().values())
+ {
+ Map<String, Long> words = users.get(user);
+ if (words != null)
+ return ResponseEntity.ok(words);
+ }
+
+ return ResponseEntity.notFound().build();
+ }
+
+
+ @ExceptionHandler
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
+ public ErrorResponse illegalStateException(IllegalStateException e)
+ {
+ return new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value());
+ }
}