refactore: Renamed `ChatroomTo` to `ChatRoomTo` -- Rename
authorKai Moritz <kai@juplo.de>
Sun, 8 Jan 2023 09:20:56 +0000 (10:20 +0100)
committerKai Moritz <kai@juplo.de>
Mon, 9 Jan 2023 19:55:49 +0000 (20:55 +0100)
src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java
src/main/java/de/juplo/kafka/chat/backend/api/ChatRoomTo.java [new file with mode: 0644]
src/main/java/de/juplo/kafka/chat/backend/api/ChatroomTo.java [deleted file]
src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java
src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java

index e7fc483..68c53d5 100644 (file)
@@ -26,15 +26,15 @@ public class ChatBackendController
 
 
   @PostMapping("create")
-  public ChatroomTo create(@RequestBody String name)
+  public ChatRoomTo create(@RequestBody String name)
   {
-    return ChatroomTo.from(chatHome.createChatroom(name));
+    return ChatRoomTo.from(chatHome.createChatroom(name));
   }
 
   @GetMapping("list")
-  public Stream<ChatroomTo> list()
+  public Stream<ChatRoomTo> list()
   {
-    return chatHome.list().map(chatroom -> ChatroomTo.from(chatroom));
+    return chatHome.list().map(chatroom -> ChatRoomTo.from(chatroom));
   }
 
   @GetMapping("list/{chatroomId}")
@@ -49,9 +49,9 @@ public class ChatBackendController
   }
 
   @GetMapping("get/{chatroomId}")
-  public Optional<ChatroomTo> get(@PathVariable UUID chatroomId)
+  public Optional<ChatRoomTo> get(@PathVariable UUID chatroomId)
   {
-    return chatHome.getChatroom(chatroomId).map(chatroom -> ChatroomTo.from(chatroom));
+    return chatHome.getChatroom(chatroomId).map(chatroom -> ChatRoomTo.from(chatroom));
   }
 
   @PutMapping("put/{chatroomId}/{username}/{messageId}")
diff --git a/src/main/java/de/juplo/kafka/chat/backend/api/ChatRoomTo.java b/src/main/java/de/juplo/kafka/chat/backend/api/ChatRoomTo.java
new file mode 100644 (file)
index 0000000..859f797
--- /dev/null
@@ -0,0 +1,22 @@
+package de.juplo.kafka.chat.backend.api;
+
+import de.juplo.kafka.chat.backend.domain.ChatRoom;
+import lombok.Data;
+
+import java.util.UUID;
+
+@Data
+public class ChatRoomTo
+{
+  private UUID id;
+  private String name;
+
+
+  public static ChatRoomTo from(ChatRoom chatroom)
+  {
+    ChatRoomTo info = new ChatRoomTo();
+    info.id = chatroom.getId();
+    info.name = chatroom.getName();
+    return info;
+  }
+}
diff --git a/src/main/java/de/juplo/kafka/chat/backend/api/ChatroomTo.java b/src/main/java/de/juplo/kafka/chat/backend/api/ChatroomTo.java
deleted file mode 100644 (file)
index 773c968..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-package de.juplo.kafka.chat.backend.api;
-
-import de.juplo.kafka.chat.backend.domain.ChatRoom;
-import lombok.Data;
-
-import java.util.UUID;
-
-@Data
-public class ChatroomTo
-{
-  private UUID id;
-  private String name;
-
-
-  public static ChatroomTo from(ChatRoom chatroom)
-  {
-    ChatroomTo info = new ChatroomTo();
-    info.id = chatroom.getId();
-    info.name = chatroom.getName();
-    return info;
-  }
-}
index d66c544..038ab7a 100644 (file)
@@ -3,7 +3,7 @@ package de.juplo.kafka.chat.backend.persistence;
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.JavaType;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import de.juplo.kafka.chat.backend.api.ChatroomTo;
+import de.juplo.kafka.chat.backend.api.ChatRoomTo;
 import de.juplo.kafka.chat.backend.api.MessageTo;
 import de.juplo.kafka.chat.backend.domain.ChatRoom;
 import de.juplo.kafka.chat.backend.domain.Message;
@@ -75,7 +75,7 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy
           {
             try
             {
-              ChatroomTo chatroomTo = ChatroomTo.from(chatroom);
+              ChatRoomTo chatroomTo = ChatRoomTo.from(chatroom);
               generator.writeObject(chatroomTo);
               writeMessages(chatroomTo, chatroom.getMessages());
             }
@@ -94,23 +94,23 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy
   @Override
   public Flux<ChatRoom> readChatrooms()
   {
-    JavaType type = mapper.getTypeFactory().constructType(ChatroomTo.class);
+    JavaType type = mapper.getTypeFactory().constructType(ChatRoomTo.class);
     return Flux
-        .from(new JsonFilePublisher<ChatroomTo>(chatroomsPath(), mapper, type))
+        .from(new JsonFilePublisher<ChatRoomTo>(chatroomsPath(), mapper, type))
         .log()
-        .map(chatroomTo ->
+        .map(chatRoomTo ->
         {
           InMemoryChatroomService chatroomService =
-              new InMemoryChatroomService(readMessages(chatroomTo));
+              new InMemoryChatroomService(readMessages(chatRoomTo));
           return service.restoreChatroom(
-              chatroomTo.getId(),
-              chatroomTo.getName(),
+              chatRoomTo.getId(),
+              chatRoomTo.getName(),
               chatroomService);
         });
   }
 
   @Override
-  public void writeMessages(ChatroomTo chatroomTo, Flux<Message> messageFlux)
+  public void writeMessages(ChatRoomTo chatroomTo, Flux<Message> messageFlux)
   {
     Path path = chatroomPath(chatroomTo);
     log.info("Writing messages for {} to {}", chatroomTo, path);
@@ -169,7 +169,7 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy
   }
 
   @Override
-  public Flux<Message> readMessages(ChatroomTo chatroomTo)
+  public Flux<Message> readMessages(ChatRoomTo chatroomTo)
   {
     JavaType type = mapper.getTypeFactory().constructType(MessageTo.class);
     return Flux
@@ -183,7 +183,7 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy
     return storagePath.resolve(Path.of(CHATROOMS_FILENAME));
   }
 
-  Path chatroomPath(ChatroomTo chatroomTo)
+  Path chatroomPath(ChatRoomTo chatroomTo)
   {
     return storagePath.resolve(Path.of(chatroomTo.getId().toString() + ".json"));
   }
index a337b61..4355f9f 100644 (file)
@@ -1,6 +1,6 @@
 package de.juplo.kafka.chat.backend.persistence;
 
-import de.juplo.kafka.chat.backend.api.ChatroomTo;
+import de.juplo.kafka.chat.backend.api.ChatRoomTo;
 import de.juplo.kafka.chat.backend.domain.ChatRoom;
 import de.juplo.kafka.chat.backend.domain.Message;
 import reactor.core.publisher.Flux;
@@ -10,6 +10,6 @@ public interface StorageStrategy
 {
   void writeChatrooms(Flux<ChatRoom> chatroomFlux);
   Flux<ChatRoom> readChatrooms();
-  void writeMessages(ChatroomTo chatroomTo, Flux<Message> messageFlux);
-  Flux<Message> readMessages(ChatroomTo chatroomTo);
+  void writeMessages(ChatRoomTo chatroomTo, Flux<Message> messageFlux);
+  Flux<Message> readMessages(ChatRoomTo chatroomTo);
 }