From: Kai Moritz Date: Tue, 20 Feb 2024 14:04:30 +0000 (+0100) Subject: refactor: Cleaned up code X-Git-Tag: rebase--2024-02-20--15-07~1 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=fa85a5271af68a3cb86785a4ece85b6809839266;p=demos%2Fkafka%2Fchat refactor: Cleaned up code --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java index ad57da5c..4c0f1df7 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java @@ -17,12 +17,10 @@ public class MongoDbStorageConfiguration @Bean public StorageStrategy storageStrategy( ChatRoomRepository chatRoomRepository, - MessageRepository messageRepository, - ShardingStrategy shardingStrategy) + MessageRepository messageRepository) { return new MongoDbStorageStrategy( chatRoomRepository, - messageRepository, - shardingStrategy); + messageRepository); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java index 95b1dd6c..c3ec0996 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java @@ -2,7 +2,6 @@ package de.juplo.kafka.chat.backend.storage.mongodb; import de.juplo.kafka.chat.backend.domain.ChatRoomInfo; import de.juplo.kafka.chat.backend.domain.Message; -import de.juplo.kafka.chat.backend.implementation.ShardingStrategy; import de.juplo.kafka.chat.backend.implementation.StorageStrategy; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -17,7 +16,6 @@ public class MongoDbStorageStrategy implements StorageStrategy { private final ChatRoomRepository chatRoomRepository; private final MessageRepository messageRepository; - private final ShardingStrategy shardingStrategy; @Override @@ -25,14 +23,15 @@ public class MongoDbStorageStrategy implements StorageStrategy { return chatRoomInfoFlux .map(ChatRoomTo::from) - .map(chatroomTo -> chatRoomRepository.save(chatroomTo)) + .map(chatRoomTo -> chatRoomRepository.save(chatRoomTo)) .map(ChatRoomTo::toChatRoomInfo); } @Override public Flux readChatRoomInfo() { - return chatRoomRepository.findAll() + return chatRoomRepository + .findAll() .map(chatRoomTo -> { UUID chatRoomId = UUID.fromString(chatRoomTo.getId()); @@ -45,14 +44,15 @@ public class MongoDbStorageStrategy implements StorageStrategy { return messageFlux .map(message -> MessageTo.from(chatRoomId, message)) - .map(messageTo -> messageRepository.save(messageTo)) + .flatMap(messageTo -> messageRepository.save(messageTo)) .map(MessageTo::toMessage); } @Override public Flux readChatRoomData(UUID chatRoomId) { - return messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString()) + return messageRepository + .findByChatRoomIdOrderBySerialAsc(chatRoomId.toString()) .map(messageTo -> messageTo.toMessage()); } } diff --git a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java index 43a09003..48f32ff5 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java @@ -60,13 +60,11 @@ public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT @Bean MongoDbStorageStrategy storageStrategy( ChatRoomRepository chatRoomRepository, - MessageRepository messageRepository, - Clock clock) + MessageRepository messageRepository) { return new MongoDbStorageStrategy( chatRoomRepository, - messageRepository, - chatRoomId -> 0); + messageRepository); } @Bean