1 package de.juplo.kafka.chat.backend.domain;
3 import lombok.extern.slf4j.Slf4j;
4 import reactor.core.publisher.Flux;
5 import reactor.core.publisher.Mono;
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 Mono<ChatRoom> createChatroom(String name)
26 ChatRoom chatroom = service.createChatroom(UUID.randomUUID(), name);
27 chatrooms.put(chatroom.getId(), chatroom);
28 return Mono.justOrEmpty(chatroom);
31 public Mono<ChatRoom> getChatroom(UUID id)
34 .justOrEmpty(chatrooms.get(id))
35 .or(Mono.error(() -> new UnknownChatroomException(id)));
38 public Flux<ChatRoom> list()
40 return Flux.fromStream(chatrooms.values().stream());