refactor: Fixed return-types of the controller
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / domain / ChatHome.java
1 package de.juplo.kafka.chat.backend.domain;
2
3 import lombok.RequiredArgsConstructor;
4
5 import java.util.*;
6 import java.util.stream.Stream;
7
8
9 @RequiredArgsConstructor
10 public class ChatHome
11 {
12   private final Map<UUID, Chatroom> chatrooms;
13   private final ChatroomFactory factory;
14
15
16   public Chatroom createChatroom(String name)
17   {
18     Chatroom chatroom = factory.createChatroom(UUID.randomUUID(), name);
19     chatrooms.put(chatroom.getId(), chatroom);
20     return chatroom;
21   }
22
23   public Optional<Chatroom> getChatroom(UUID id)
24   {
25     return Optional.ofNullable(chatrooms.get(id));
26   }
27
28   public Stream<Chatroom> list()
29   {
30     return chatrooms.values().stream();
31   }
32 }