From: Kai Moritz Date: Sun, 8 Jan 2023 09:20:56 +0000 (+0100) Subject: refactore: Renamed `ChatroomTo` to `ChatRoomTo` -- Rename X-Git-Tag: wip~70 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=aa01a85ce5552d7a849bc09a80cac0860e5e8c93;p=demos%2Fkafka%2Fchat refactore: Renamed `ChatroomTo` to `ChatRoomTo` -- Rename --- 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 new file mode 100644 index 00000000..859f797f --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/api/ChatRoomTo.java @@ -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 index 773c9683..00000000 --- a/src/main/java/de/juplo/kafka/chat/backend/api/ChatroomTo.java +++ /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; - } -} 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); }