feat: Added a POST-mapping to force the storing of the data
authorKai Moritz <kai@juplo.de>
Fri, 6 Jan 2023 00:33:51 +0000 (01:33 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 15 Jan 2023 18:35:59 +0000 (19:35 +0100)
src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java

index 8fccaa9..4aaf4f5 100644 (file)
@@ -2,6 +2,7 @@ package de.juplo.kafka.chat.backend.api;
 
 import de.juplo.kafka.chat.backend.domain.ChatHome;
 import de.juplo.kafka.chat.backend.domain.Chatroom;
+import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
 import lombok.RequiredArgsConstructor;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
@@ -10,7 +11,6 @@ import reactor.core.publisher.Mono;
 
 import java.time.Clock;
 import java.time.LocalDateTime;
-import java.util.Collection;
 import java.util.Optional;
 import java.util.UUID;
 import java.util.stream.Stream;
@@ -22,6 +22,7 @@ public class ChatBackendController
 {
   private final ChatHome chatHome;
   private final Clock clock;
+  private final StorageStrategy storageStrategy;
 
 
   @PostMapping("create")
@@ -115,4 +116,10 @@ public class ChatBackendController
         .log()
         .map(message -> MessageTo.from(message));
   }
+
+  @PostMapping("/store")
+  public void store()
+  {
+    storageStrategy.writeChatrooms(Flux.fromStream(chatHome.list()));
+  }
 }