+++ /dev/null
-package de.juplo.kafka.chat.backend.persistence.storage.mongodb;
-
-import lombok.*;
-
-
-@AllArgsConstructor
-@NoArgsConstructor
-@Getter(AccessLevel.PACKAGE)
-@Setter(AccessLevel.PACKAGE)
-@EqualsAndHashCode
-@ToString
-public class MessageId
-{
- private String chatRoomId;
- private String user;
- private Long id;
-}
import de.juplo.kafka.chat.backend.domain.Message;
import lombok.*;
import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.LocalDateTime;
@Document
class MessageTo
{
- @Id
- private MessageId id;
+ @Indexed
+ private String chatRoomId;
+ @Indexed
+ private String user;
+ @Indexed
+ private Long id;
+ @Indexed
private Long serial;
private String time;
private String text;
Message toMessage()
{
return new Message(
- Message.MessageKey.of(id.getUser(), id.getId()),
+ Message.MessageKey.of(user, id),
serial,
LocalDateTime.parse(time),
text);
{
return
new MessageTo(
- new MessageId(
- chatRoomId.toString(),
- message.getUsername(),
- message.getId()),
+ chatRoomId.toString(),
+ message.getUsername(),
+ message.getId(),
message.getSerialNumber(),
message.getTimestamp().toString(),
message.getMessageText());
package de.juplo.kafka.chat.backend.persistence.storage.mongodb;
-import de.juplo.kafka.chat.backend.domain.ChatRoomData;
import de.juplo.kafka.chat.backend.domain.ChatRoomInfo;
import de.juplo.kafka.chat.backend.domain.Message;
import de.juplo.kafka.chat.backend.persistence.inmemory.ShardingStrategy;
public Flux<Message> readChatRoomData(UUID chatRoomId)
{
return Flux
- .fromIterable(messageRepository.findByChatRoomId(chatRoomId.toString()))
+ .fromIterable(messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString()))
.map(messageTo -> messageTo.toMessage());
}
}