@PostMapping("create")
- public ChatroomTo create(@RequestBody String name)
+ public ChatRoomTo create(@RequestBody String name)
{
- return ChatroomTo.from(chatHome.createChatroom(name));
+ return ChatRoomTo.from(chatHome.createChatroom(name));
}
@GetMapping("list")
- public Stream<ChatroomTo> list()
+ public Stream<ChatRoomTo> list()
{
- return chatHome.list().map(chatroom -> ChatroomTo.from(chatroom));
+ return chatHome.list().map(chatroom -> ChatRoomTo.from(chatroom));
}
@GetMapping("list/{chatroomId}")
}
@GetMapping("get/{chatroomId}")
- public Optional<ChatroomTo> get(@PathVariable UUID chatroomId)
+ public Optional<ChatRoomTo> get(@PathVariable UUID chatroomId)
{
- return chatHome.getChatroom(chatroomId).map(chatroom -> ChatroomTo.from(chatroom));
+ return chatHome.getChatroom(chatroomId).map(chatroom -> ChatRoomTo.from(chatroom));
}
@PutMapping("put/{chatroomId}/{username}/{messageId}")
--- /dev/null
+package de.juplo.kafka.chat.backend.api;
+
+import de.juplo.kafka.chat.backend.domain.ChatRoom;
+import lombok.Data;
+
+import java.util.UUID;
+
+@Data
+public class ChatRoomTo
+{
+ private UUID id;
+ private String name;
+
+
+ public static ChatRoomTo from(ChatRoom chatroom)
+ {
+ ChatRoomTo info = new ChatRoomTo();
+ info.id = chatroom.getId();
+ info.name = chatroom.getName();
+ return info;
+ }
+}
+++ /dev/null
-package de.juplo.kafka.chat.backend.api;
-
-import de.juplo.kafka.chat.backend.domain.ChatRoom;
-import lombok.Data;
-
-import java.util.UUID;
-
-@Data
-public class ChatroomTo
-{
- private UUID id;
- private String name;
-
-
- public static ChatroomTo from(ChatRoom chatroom)
- {
- ChatroomTo info = new ChatroomTo();
- info.id = chatroom.getId();
- info.name = chatroom.getName();
- return info;
- }
-}
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
-import de.juplo.kafka.chat.backend.api.ChatroomTo;
+import de.juplo.kafka.chat.backend.api.ChatRoomTo;
import de.juplo.kafka.chat.backend.api.MessageTo;
import de.juplo.kafka.chat.backend.domain.ChatRoom;
import de.juplo.kafka.chat.backend.domain.Message;
{
try
{
- ChatroomTo chatroomTo = ChatroomTo.from(chatroom);
+ ChatRoomTo chatroomTo = ChatRoomTo.from(chatroom);
generator.writeObject(chatroomTo);
writeMessages(chatroomTo, chatroom.getMessages());
}
@Override
public Flux<ChatRoom> readChatrooms()
{
- JavaType type = mapper.getTypeFactory().constructType(ChatroomTo.class);
+ JavaType type = mapper.getTypeFactory().constructType(ChatRoomTo.class);
return Flux
- .from(new JsonFilePublisher<ChatroomTo>(chatroomsPath(), mapper, type))
+ .from(new JsonFilePublisher<ChatRoomTo>(chatroomsPath(), mapper, type))
.log()
- .map(chatroomTo ->
+ .map(chatRoomTo ->
{
InMemoryChatroomService chatroomService =
- new InMemoryChatroomService(readMessages(chatroomTo));
+ new InMemoryChatroomService(readMessages(chatRoomTo));
return service.restoreChatroom(
- chatroomTo.getId(),
- chatroomTo.getName(),
+ chatRoomTo.getId(),
+ chatRoomTo.getName(),
chatroomService);
});
}
@Override
- public void writeMessages(ChatroomTo chatroomTo, Flux<Message> messageFlux)
+ public void writeMessages(ChatRoomTo chatroomTo, Flux<Message> messageFlux)
{
Path path = chatroomPath(chatroomTo);
log.info("Writing messages for {} to {}", chatroomTo, path);
}
@Override
- public Flux<Message> readMessages(ChatroomTo chatroomTo)
+ public Flux<Message> readMessages(ChatRoomTo chatroomTo)
{
JavaType type = mapper.getTypeFactory().constructType(MessageTo.class);
return Flux
return storagePath.resolve(Path.of(CHATROOMS_FILENAME));
}
- Path chatroomPath(ChatroomTo chatroomTo)
+ Path chatroomPath(ChatRoomTo chatroomTo)
{
return storagePath.resolve(Path.of(chatroomTo.getId().toString() + ".json"));
}
package de.juplo.kafka.chat.backend.persistence;
-import de.juplo.kafka.chat.backend.api.ChatroomTo;
+import de.juplo.kafka.chat.backend.api.ChatRoomTo;
import de.juplo.kafka.chat.backend.domain.ChatRoom;
import de.juplo.kafka.chat.backend.domain.Message;
import reactor.core.publisher.Flux;
{
void writeChatrooms(Flux<ChatRoom> chatroomFlux);
Flux<ChatRoom> readChatrooms();
- void writeMessages(ChatroomTo chatroomTo, Flux<Message> messageFlux);
- Flux<Message> readMessages(ChatroomTo chatroomTo);
+ void writeMessages(ChatRoomTo chatroomTo, Flux<Message> messageFlux);
+ Flux<Message> readMessages(ChatRoomTo chatroomTo);
}