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 ChatHomeService service;
16 public ChatHome(ChatHomeService service, Flux<ChatRoom> chatroomFlux)
18 log.debug("Creating ChatHome with factory: {}", service);
19 this.service = service;
20 this.chatrooms = new HashMap<>();
21 chatroomFlux.subscribe(chatroom -> chatrooms.put(chatroom.getId(), chatroom));
24 public ChatRoom createChatroom(String name)
26 ChatRoom chatroom = service.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();