From a31d201f1acc3b9f607221bb9fec74d802b410bb Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 8 Jan 2023 10:19:47 +0100 Subject: [PATCH] refactore: Renamed `Chatroom` to `ChatRoom` -- Rename --- .../chat/backend/api/ChatBackendController.java | 9 ++++----- .../de/juplo/kafka/chat/backend/api/ChatroomTo.java | 4 ++-- .../de/juplo/kafka/chat/backend/domain/ChatHome.java | 12 ++++++------ .../kafka/chat/backend/domain/ChatHomeService.java | 2 +- .../backend/domain/{Chatroom.java => ChatRoom.java} | 4 ++-- .../backend/persistence/InMemoryChatHomeService.java | 10 +++++----- .../persistence/LocalJsonFilesStorageStrategy.java | 6 +++--- .../chat/backend/persistence/StorageStrategy.java | 6 +++--- 8 files changed, 26 insertions(+), 27 deletions(-) rename src/main/java/de/juplo/kafka/chat/backend/domain/{Chatroom.java => ChatRoom.java} (97%) 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 12f8d67f..e7fc483c 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 @@ -1,10 +1,9 @@ package de.juplo.kafka.chat.backend.api; import de.juplo.kafka.chat.backend.domain.ChatHome; -import de.juplo.kafka.chat.backend.domain.Chatroom; +import de.juplo.kafka.chat.backend.domain.ChatRoom; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import lombok.RequiredArgsConstructor; -import org.springframework.http.MediaType; import org.springframework.http.codec.ServerSentEvent; import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Flux; @@ -70,7 +69,7 @@ public class ChatBackendController } public Mono put( - Chatroom chatroom, + ChatRoom chatroom, String username, Long messageId, String text) @@ -100,7 +99,7 @@ public class ChatBackendController } private Mono get( - Chatroom chatroom, + ChatRoom chatroom, String username, Long messageId) { @@ -119,7 +118,7 @@ public class ChatBackendController .orElseThrow(() -> new UnknownChatroomException(chatroomId)); } - private Flux> listen(Chatroom chatroom) + private Flux> listen(ChatRoom chatroom) { return chatroom .listen() 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 index c4ad7848..773c9683 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 @@ -1,6 +1,6 @@ package de.juplo.kafka.chat.backend.api; -import de.juplo.kafka.chat.backend.domain.Chatroom; +import de.juplo.kafka.chat.backend.domain.ChatRoom; import lombok.Data; import java.util.UUID; @@ -12,7 +12,7 @@ public class ChatroomTo private String name; - public static ChatroomTo from(Chatroom chatroom) + public static ChatroomTo from(ChatRoom chatroom) { ChatroomTo info = new ChatroomTo(); info.id = chatroom.getId(); diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java index 773cd4cf..b31dedee 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java @@ -10,10 +10,10 @@ import java.util.stream.Stream; @Slf4j public class ChatHome { - private final Map chatrooms; + private final Map chatrooms; private final ChatHomeService service; - public ChatHome(ChatHomeService service, Flux chatroomFlux) + public ChatHome(ChatHomeService service, Flux chatroomFlux) { log.debug("Creating ChatHome with factory: {}", service); this.service = service; @@ -21,19 +21,19 @@ public class ChatHome chatroomFlux.subscribe(chatroom -> chatrooms.put(chatroom.getId(), chatroom)); } - public Chatroom createChatroom(String name) + public ChatRoom createChatroom(String name) { - Chatroom chatroom = service.createChatroom(UUID.randomUUID(), name); + ChatRoom chatroom = service.createChatroom(UUID.randomUUID(), name); chatrooms.put(chatroom.getId(), chatroom); return chatroom; } - public Optional getChatroom(UUID id) + public Optional getChatroom(UUID id) { return Optional.ofNullable(chatrooms.get(id)); } - public Stream list() + public Stream list() { return chatrooms.values().stream(); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java index 987839cc..5508f24a 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java @@ -5,5 +5,5 @@ import java.util.UUID; public interface ChatHomeService { - Chatroom createChatroom(UUID id, String name); + ChatRoom createChatroom(UUID id, String name); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java similarity index 97% rename from src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java rename to src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java index 2261e022..bed91c76 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java @@ -11,7 +11,7 @@ import java.util.*; @Slf4j -public class Chatroom +public class ChatRoom { @Getter private final UUID id; @@ -21,7 +21,7 @@ public class Chatroom private final int bufferSize; private Sinks.Many sink; - public Chatroom( + public ChatRoom( UUID id, String name, ChatroomService chatroomService, diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java index 5c7c4b94..006f9767 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java @@ -1,6 +1,6 @@ package de.juplo.kafka.chat.backend.persistence; -import de.juplo.kafka.chat.backend.domain.Chatroom; +import de.juplo.kafka.chat.backend.domain.ChatRoom; import de.juplo.kafka.chat.backend.domain.ChatHomeService; import lombok.RequiredArgsConstructor; @@ -15,18 +15,18 @@ public class InMemoryChatHomeService implements ChatHomeService()); - return new Chatroom(id, name, chatroomService, bufferSize); + return new ChatRoom(id, name, chatroomService, bufferSize); } - public Chatroom restoreChatroom( + public ChatRoom restoreChatroom( UUID id, String name, InMemoryChatroomService chatroomService) { - return new Chatroom(id, name, chatroomService, bufferSize); + return new ChatRoom(id, name, chatroomService, bufferSize); } } 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 d2092b2b..d66c544c 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 @@ -5,7 +5,7 @@ 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.MessageTo; -import de.juplo.kafka.chat.backend.domain.Chatroom; +import de.juplo.kafka.chat.backend.domain.ChatRoom; import de.juplo.kafka.chat.backend.domain.Message; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -32,7 +32,7 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy @Override - public void writeChatrooms(Flux chatroomFlux) + public void writeChatrooms(Flux chatroomFlux) { Path path = chatroomsPath(); log.info("Writing chatrooms to {}", path); @@ -92,7 +92,7 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy } @Override - public Flux readChatrooms() + public Flux readChatrooms() { JavaType type = mapper.getTypeFactory().constructType(ChatroomTo.class); return Flux 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 38a9e98f..a337b61e 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,15 +1,15 @@ package de.juplo.kafka.chat.backend.persistence; import de.juplo.kafka.chat.backend.api.ChatroomTo; -import de.juplo.kafka.chat.backend.domain.Chatroom; +import de.juplo.kafka.chat.backend.domain.ChatRoom; import de.juplo.kafka.chat.backend.domain.Message; import reactor.core.publisher.Flux; public interface StorageStrategy { - void writeChatrooms(Flux chatroomFlux); - Flux readChatrooms(); + void writeChatrooms(Flux chatroomFlux); + Flux readChatrooms(); void writeMessages(ChatroomTo chatroomTo, Flux messageFlux); Flux readMessages(ChatroomTo chatroomTo); } -- 2.20.1