70cac5084de2649b1be805cc93878a67547ebc9d
[demos/kafka/chat] /
1 package de.juplo.kafka.chat.backend.implementation.kafka.messages;
2
3 import de.juplo.kafka.chat.backend.domain.Message;
4 import lombok.*;
5
6 import java.time.LocalDateTime;
7
8
9 @Getter
10 @Setter
11 @EqualsAndHashCode
12 @ToString
13 public class EventChatMessageReceivedTo extends AbstractMessageTo
14 {
15   private String user;
16   private Long id;
17   private String text;
18
19
20   public EventChatMessageReceivedTo()
21   {
22     super(ToType.EVENT_CHATMESSAGE_RECEIVED);
23   }
24
25
26   public Message toMessage(long offset, LocalDateTime timestamp)
27   {
28     return new Message(Message.MessageKey.of(user, id), offset, timestamp, text);
29   }
30
31   public static EventChatMessageReceivedTo from(Message message)
32   {
33     return EventChatMessageReceivedTo.of(
34         message.getUsername(),
35         message.getId(),
36         message.getMessageText());
37   }
38
39
40   public static EventChatMessageReceivedTo of(String user, Long id, String text)
41   {
42     EventChatMessageReceivedTo to = new EventChatMessageReceivedTo();
43     to.user = user;
44     to.id = id;
45     to.text = text;
46     return to;
47   }
48 }