refactor: Cleaned up code
authorKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 14:04:30 +0000 (15:04 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 14:04:30 +0000 (15:04 +0100)
src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java

index ad57da5..4c0f1df 100644 (file)
@@ -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);
   }
 }
index 95b1dd6..c3ec099 100644 (file)
@@ -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<ChatRoomInfo> 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<Message> readChatRoomData(UUID chatRoomId)
   {
-    return messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString())
+    return messageRepository
+        .findByChatRoomIdOrderBySerialAsc(chatRoomId.toString())
         .map(messageTo -> messageTo.toMessage());
   }
 }
index 43a0900..48f32ff 100644 (file)
@@ -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