diff --git a/src/main/java/com/hana/hanalink/chat/controller/ChatRestController.java b/src/main/java/com/hana/hanalink/chat/controller/ChatRestController.java index 5ae04ec..222e444 100644 --- a/src/main/java/com/hana/hanalink/chat/controller/ChatRestController.java +++ b/src/main/java/com/hana/hanalink/chat/controller/ChatRestController.java @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; @RestController @RequestMapping("/api/v1/chat") @@ -19,4 +20,9 @@ public class ChatRestController { public Flux getChatsByRoomId(@PathVariable String roomId) { return chatService.getChatsByRoomId(roomId); } + + @GetMapping("/last/{roomId}") + public Mono getLastChatByRoomId(@PathVariable String roomId) { + return chatService.getLastChatByRoomId(roomId); + } } diff --git a/src/main/java/com/hana/hanalink/chat/service/ChatService.java b/src/main/java/com/hana/hanalink/chat/service/ChatService.java index 8970b75..f48c055 100644 --- a/src/main/java/com/hana/hanalink/chat/service/ChatService.java +++ b/src/main/java/com/hana/hanalink/chat/service/ChatService.java @@ -24,4 +24,8 @@ public Mono saveChat(Chat chat) { public Flux getChatsByRoomId(String roomId) { return chatRepository.findByRoomId(roomId); } + + public Mono getLastChatByRoomId(String roomId) { + return chatRepository.findByRoomId(roomId).last(); + } }