From: Kai Moritz Date: Mon, 4 Sep 2023 20:33:31 +0000 (+0200) Subject: refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code X-Git-Tag: rebase--2023-09-05--23-53~15 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=1cd3d69ea4f875a1ddcf15335ad85d5dfae5e16e;p=demos%2Fkafka%2Fchat refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java index 9fa675a0..15f8ae15 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java @@ -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) diff --git a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java index c39869cc..e2fe714b 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java +++ b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java @@ -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); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java index c4ab80a4..7d0f66d4 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java @@ -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 chatRoomInfoFlux); Flux readChatRoomInfo(); void writeChatRoomData(UUID chatRoomId, Flux messageFlux);