import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.ResponseStatus;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
@RestController
public class DriverController
{
private final EndlessConsumer consumer;
+ private final AdderRecordHandler adderRecordHandler;
@PostMapping("start")
consumer.stop();
}
+
+ @GetMapping("state")
+ public Map<Integer, Map<String, Long>> state()
+ {
+ return
+ adderRecordHandler
+ .getState()
+ .entrySet()
+ .stream()
+ .collect(Collectors.toMap(
+ entry -> entry.getKey(),
+ entry -> entry.getValue().getState()));
+ }
+
+ @GetMapping("state/{user}")
+ public ResponseEntity<Long> seen(@PathVariable String user)
+ {
+ for (AdderBusinessLogic adderBusinessLogic : adderRecordHandler.getState().values())
+ {
+ Optional<Long> sum = adderBusinessLogic.getSum(user);
+ if (sum.isPresent())
+ return ResponseEntity.ok(sum.get());
+ }
+
+ return ResponseEntity.notFound().build();
+ }
+
+
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse illegalStateException(IllegalStateException e)