IMPL server-side recover message history API
This commit is contained in:
parent
f2d3c948bf
commit
fdedd75807
2 changed files with 19 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
package me.imsonmia.epqapi.controller;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
|
@ -24,9 +25,16 @@ public class MessageController {
|
|||
// Forward message to subscribers of Stomp endpoint
|
||||
return message;
|
||||
}
|
||||
@GetMapping("/chat/history/{from}")
|
||||
public ArrayList<Message> getMessagesFromTimestamp(@PathVariable(value = "from") Long fromTimestamp) {
|
||||
return new ArrayList<Message>();
|
||||
@GetMapping("/api/v1/chat/history/{from}")
|
||||
public ArrayList<Message> getMessagesFromTimestamp(@PathVariable(value = "from") long fromTimestamp) {
|
||||
ArrayList<Message> messages = new ArrayList<>();
|
||||
Instant targetInstant = Instant.ofEpochMilli(fromTimestamp);
|
||||
for (Message msg : repository.findAll()) {
|
||||
Instant t = Instant.ofEpochMilli(msg.getTimestamp());
|
||||
if (t.isBefore(targetInstant)) {continue;}
|
||||
messages.add(msg);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
// @GetMapping("/msg/{id}")
|
||||
// public ChatMessage getMessageById(@PathVariable(value = "id") Long id) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.imsonmia.epqapi.model;
|
||||
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
|
@ -14,6 +15,7 @@ public class Message {
|
|||
private String from;
|
||||
private String to;
|
||||
private String content;
|
||||
private Long timestamp;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -35,4 +37,10 @@ public class Message {
|
|||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
public Long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
public void setTimestamp(Long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue