package de.juplo.kafka.chat.backend.api;
import de.juplo.kafka.chat.backend.domain.Chatroom;
-import de.juplo.kafka.chat.backend.domain.PersistenceStrategy;
+import de.juplo.kafka.chat.backend.domain.ChatroomFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
public class ChatBackendController
{
private final Map<UUID, Chatroom> chatrooms = new HashMap<>();
- private final PersistenceStrategy persistenceStrategy;
+ private final ChatroomFactory factory;
private final Clock clock;
@PostMapping("create")
public Chatroom create(@RequestBody String name)
{
- Chatroom chatroom = new Chatroom(UUID.randomUUID(), name, persistenceStrategy);
+ Chatroom chatroom = factory.createChatroom(UUID.randomUUID(), name);
chatrooms.put(chatroom.getId(), chatroom);
return chatroom;
}
--- /dev/null
+package de.juplo.kafka.chat.backend.persistence;
+
+import de.juplo.kafka.chat.backend.domain.Chatroom;
+import de.juplo.kafka.chat.backend.domain.ChatroomFactory;
+import de.juplo.kafka.chat.backend.domain.PersistenceStrategy;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import java.util.UUID;
+
+@Component
+@RequiredArgsConstructor
+public class InMemoryChatroomFactory implements ChatroomFactory
+{
+ private final PersistenceStrategy persistenceStrategy;
+
+
+ @Override
+ public Chatroom createChatroom(UUID id, String name)
+ {
+ return new Chatroom(id, name, persistenceStrategy);
+ }
+}