refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code
authorKai Moritz <kai@juplo.de>
Mon, 4 Sep 2023 20:33:31 +0000 (22:33 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 4 Sep 2023 20:33:31 +0000 (22:33 +0200)
src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java
src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java
src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java

index 9fa675a..15f8ae1 100644 (file)
@@ -32,15 +32,7 @@ public class ChatBackendApplication implements WebFluxConfigurer
        @PreDestroy
        public void onExit()
        {
-               storageStrategy.writeChatRoomInfo(
-                               chatHome
-                                               .getChatRoomInfo()
-                                               .doOnNext(chatRoomInfo ->
-                                                               storageStrategy.writeChatRoomData(
-                                                                               chatRoomInfo.getId(),
-                                                                               chatHome
-                                                                                               .getChatRoomData(chatRoomInfo.getId())
-                                                                                               .flatMapMany(chatRoomData -> chatRoomData.getMessages()))));
+               storageStrategy.write(chatHome);
        }
 
        public static void main(String[] args)
index c39869c..e2fe714 100644 (file)
@@ -131,14 +131,6 @@ public class ChatBackendController
   @PostMapping("/store")
   public void store()
   {
-    storageStrategy.writeChatRoomInfo(
-        chatHome
-            .getChatRoomInfo()
-            .doOnNext(chatRoomInfo ->
-                storageStrategy.writeChatRoomData(
-                    chatRoomInfo.getId(),
-                    chatHome
-                        .getChatRoomData(chatRoomInfo.getId())
-                        .flatMapMany(chatRoomData -> chatRoomData.getMessages()))));
+    storageStrategy.write(chatHome);
   }
 }
index c4ab80a..7d0f66d 100644 (file)
@@ -1,5 +1,6 @@
 package de.juplo.kafka.chat.backend.persistence;
 
+import de.juplo.kafka.chat.backend.domain.ChatHome;
 import de.juplo.kafka.chat.backend.domain.ChatRoomInfo;
 import de.juplo.kafka.chat.backend.domain.Message;
 import reactor.core.publisher.Flux;
@@ -9,6 +10,19 @@ import java.util.UUID;
 
 public interface StorageStrategy
 {
+  default void write(ChatHome chatHome)
+  {
+    writeChatRoomInfo(
+        chatHome
+            .getChatRoomInfo()
+            .doOnNext(chatRoomInfo ->
+                writeChatRoomData(
+                    chatRoomInfo.getId(),
+                    chatHome
+                        .getChatRoomData(chatRoomInfo.getId())
+                        .flatMapMany(chatRoomData -> chatRoomData.getMessages()))));
+  }
+
   void writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux);
   Flux<ChatRoomInfo> readChatRoomInfo();
   void writeChatRoomData(UUID chatRoomId, Flux<Message> messageFlux);