blob: 5286d3aad18501d5044fd58e45fb36b52c999f14 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package me.imsonmia.epqapi.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import me.imsonmia.epqapi.model.Message;
import me.imsonmia.epqapi.repository.MessageRepository;
@Controller
// @RequestMapping("/api/v1")
public class MessageController {
@Autowired
private MessageRepository repository;
@MessageMapping("/chat")
@SendTo("/sub/chat")
public Message messageHandler(Message message) throws Exception {
// Add message to repository
repository.save(message);
// Forward message to subscribers of Stomp endpoint
return message;
}
// @GetMapping("/msg/{id}")
// public ChatMessage getMessageById(@PathVariable(value = "id") Long id) {
// return chatMessageRepository.findById(id).get();
// }
}
|