feat: The chats are stored as local json-files
[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
7
8 @RequiredArgsConstructor
9 public class ChatHome
10 {
11   private final Map<UUID, Chatroom> chatrooms;
12   private final ChatroomFactory factory;
13
14
15   public Chatroom createChatroom(String name)
16   {
17     Chatroom chatroom = factory.createChatroom(UUID.randomUUID(), name);
18     chatrooms.put(chatroom.getId(), chatroom);
19     return chatroom;
20   }
21
22   public Optional<Chatroom> getChatroom(UUID id)
23   {
24     return Optional.ofNullable(chatrooms.get(id));
25   }
26
27   public Collection<Chatroom> list()
28   {
29     return chatrooms.values();
30   }
31 }