Added message database support in repo
Started on history fetching with getMapping
This commit is contained in:
parent
82229cb32b
commit
f2d3c948bf
4 changed files with 35 additions and 9 deletions
|
@ -1,19 +1,33 @@
|
||||||
package me.imsonmia.epqapi.controller;
|
package me.imsonmia.epqapi.controller;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||||
import org.springframework.messaging.handler.annotation.SendTo;
|
import org.springframework.messaging.handler.annotation.SendTo;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
import me.imsonmia.epqapi.model.Message;
|
import me.imsonmia.epqapi.model.Message;
|
||||||
|
import me.imsonmia.epqapi.repository.MessageRepository;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
// @RequestMapping("/api/v1")
|
// @RequestMapping("/api/v1")
|
||||||
public class ChatMessageController {
|
public class MessageController {
|
||||||
|
private MessageRepository repository;
|
||||||
@MessageMapping("/chat")
|
@MessageMapping("/chat")
|
||||||
@SendTo("/sub/chat")
|
@SendTo("/sub/chat")
|
||||||
public Message messageHandler(Message message) throws Exception {
|
public Message messageHandler(Message message) throws Exception {
|
||||||
|
// Add message to repository
|
||||||
|
repository.save(message);
|
||||||
|
|
||||||
|
// Forward message to subscribers of Stomp endpoint
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
@GetMapping("/chat/history/{from}")
|
||||||
|
public ArrayList<Message> getMessagesFromTimestamp(@PathVariable(value = "from") Long fromTimestamp) {
|
||||||
|
return new ArrayList<Message>();
|
||||||
|
}
|
||||||
// @GetMapping("/msg/{id}")
|
// @GetMapping("/msg/{id}")
|
||||||
// public ChatMessage getMessageById(@PathVariable(value = "id") Long id) {
|
// public ChatMessage getMessageById(@PathVariable(value = "id") Long id) {
|
||||||
// return chatMessageRepository.findById(id).get();
|
// return chatMessageRepository.findById(id).get();
|
|
@ -1,9 +1,22 @@
|
||||||
package me.imsonmia.epqapi.model;
|
package me.imsonmia.epqapi.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "message")
|
||||||
public class Message {
|
public class Message {
|
||||||
|
@GeneratedValue
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
private String from;
|
private String from;
|
||||||
private String to;
|
private String to;
|
||||||
private String content;
|
private String content;
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
public String getFrom() {
|
public String getFrom() {
|
||||||
return this.from;
|
return this.from;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package me.imsonmia.epqapi.repository;
|
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
|
|
||||||
import me.imsonmia.epqapi.model.ChatMessage;
|
|
||||||
|
|
||||||
public interface ChatMessageRepository extends CrudRepository<ChatMessage, Long> {
|
|
||||||
}
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package me.imsonmia.epqapi.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import me.imsonmia.epqapi.model.Message;
|
||||||
|
|
||||||
|
public interface MessageRepository extends CrudRepository<Message, Long> {
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue