1 package de.juplo.kafka.chatroom.api;
3 import de.juplo.kafka.chatroom.domain.Chatroom;
4 import de.juplo.kafka.chatroom.domain.Message;
5 import lombok.RequiredArgsConstructor;
6 import org.springframework.web.bind.annotation.*;
8 import java.time.Clock;
9 import java.time.LocalDateTime;
10 import java.util.Collection;
11 import java.util.HashMap;
13 import java.util.UUID;
17 @RequiredArgsConstructor
18 public class ChatroomController
20 private final Map<UUID, Chatroom> chatrooms = new HashMap<>();
21 private final Clock clock;
24 @PostMapping("create")
25 public Chatroom create(@RequestBody String name)
27 Chatroom chatroom = new Chatroom(UUID.randomUUID(), name);
28 chatrooms.put(chatroom.getId(), chatroom);
33 public Collection<Chatroom> list()
35 return chatrooms.values();
38 @PutMapping("post/{chatroomId}/{username}/{messageId}")
39 public MessageTo post(
40 @PathVariable UUID chatroomId,
41 @PathVariable String username,
42 @PathVariable UUID messageId,
43 @RequestBody String message)
45 return MessageTo.from(
50 LocalDateTime.now(clock),