From 1cd3d69ea4f875a1ddcf15335ad85d5dfae5e16e Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 4 Sep 2023 22:33:31 +0200 Subject: [PATCH] refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code --- .../kafka/chat/backend/ChatBackendApplication.java | 10 +--------- .../chat/backend/api/ChatBackendController.java | 10 +--------- .../chat/backend/persistence/StorageStrategy.java | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 18 deletions(-) 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); -- 2.20.1