From aa01a85ce5552d7a849bc09a80cac0860e5e8c93 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 8 Jan 2023 10:20:56 +0100 Subject: [PATCH] refactore: Renamed `ChatroomTo` to `ChatRoomTo` -- Rename --- .../backend/api/ChatBackendController.java | 12 +++++----- .../api/{ChatroomTo.java => ChatRoomTo.java} | 6 ++--- .../LocalJsonFilesStorageStrategy.java | 22 +++++++++---------- .../backend/persistence/StorageStrategy.java | 6 ++--- 4 files changed, 23 insertions(+), 23 deletions(-) rename src/main/java/de/juplo/kafka/chat/backend/api/{ChatroomTo.java => ChatRoomTo.java} (71%) 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 e7fc483c..68c53d55 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 @@ -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 list() + public Stream 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 get(@PathVariable UUID chatroomId) + public Optional 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 similarity index 71% rename from src/main/java/de/juplo/kafka/chat/backend/api/ChatroomTo.java rename to src/main/java/de/juplo/kafka/chat/backend/api/ChatRoomTo.java index 773c9683..859f797f 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/api/ChatroomTo.java +++ b/src/main/java/de/juplo/kafka/chat/backend/api/ChatRoomTo.java @@ -6,15 +6,15 @@ import lombok.Data; import java.util.UUID; @Data -public class ChatroomTo +public class ChatRoomTo { private UUID id; private String name; - public static ChatroomTo from(ChatRoom chatroom) + public static ChatRoomTo from(ChatRoom chatroom) { - ChatroomTo info = new ChatroomTo(); + 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/persistence/LocalJsonFilesStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java index d66c544c..038ab7a3 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java @@ -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 readChatrooms() { - JavaType type = mapper.getTypeFactory().constructType(ChatroomTo.class); + JavaType type = mapper.getTypeFactory().constructType(ChatRoomTo.class); return Flux - .from(new JsonFilePublisher(chatroomsPath(), mapper, type)) + .from(new JsonFilePublisher(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 messageFlux) + public void writeMessages(ChatRoomTo chatroomTo, Flux 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 readMessages(ChatroomTo chatroomTo) + public Flux 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")); } 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 a337b61e..4355f9fc 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,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 chatroomFlux); Flux readChatrooms(); - void writeMessages(ChatroomTo chatroomTo, Flux messageFlux); - Flux readMessages(ChatroomTo chatroomTo); + void writeMessages(ChatRoomTo chatroomTo, Flux messageFlux); + Flux readMessages(ChatRoomTo chatroomTo); } -- 2.20.1