1 package de.juplo.kafka.chat.backend.domain;
3 import lombok.extern.slf4j.Slf4j;
4 import reactor.core.publisher.Flux;
7 import java.util.stream.Stream;
13 private final Map<UUID, Chatroom> chatrooms;
14 private final ChatroomFactory factory;
16 public ChatHome(ChatroomFactory factory, Flux<Chatroom> chatroomFlux)
18 log.debug("Creating ChatHome with factory: {}", factory);
19 this.factory = factory;
20 this.chatrooms = new HashMap<>();
21 chatroomFlux.subscribe(chatroom -> chatrooms.put(chatroom.getId(), chatroom));
24 public Chatroom createChatroom(String name)
26 Chatroom chatroom = factory.createChatroom(UUID.randomUUID(), name);
27 chatrooms.put(chatroom.getId(), chatroom);
31 public Optional<Chatroom> getChatroom(UUID id)
33 return Optional.ofNullable(chatrooms.get(id));
36 public Stream<Chatroom> list()
38 return chatrooms.values().stream();