1 package de.juplo.kafka;
3 import lombok.RequiredArgsConstructor;
4 import org.springframework.http.HttpStatus;
5 import org.springframework.http.ResponseEntity;
6 import org.springframework.web.bind.annotation.*;
9 import java.util.Optional;
10 import java.util.concurrent.ExecutionException;
11 import java.util.stream.Collectors;
15 @RequiredArgsConstructor
16 public class DriverController
18 private final EndlessConsumer consumer;
19 private final AdderRecordHandler adderRecordHandler;
29 public void stop() throws ExecutionException, InterruptedException
36 public Map<Integer, Map<String, Long>> state()
43 .collect(Collectors.toMap(
44 entry -> entry.getKey(),
45 entry -> entry.getValue().getState()));
48 @GetMapping("state/{user}")
49 public ResponseEntity<Long> seen(@PathVariable String user)
51 for (AdderBusinessLogic adderBusinessLogic : adderRecordHandler.getState().values())
53 Optional<Long> sum = adderBusinessLogic.getSum(user);
55 return ResponseEntity.ok(sum.get());
58 return ResponseEntity.notFound().build();
63 @ResponseStatus(HttpStatus.BAD_REQUEST)
64 public ErrorResponse illegalStateException(IllegalStateException e)
66 return new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value());