From ac18cee94d9a2f12c59194556b0ffe679fde0dbd Mon Sep 17 00:00:00 2001 From: khw18 Date: Sun, 7 Jul 2024 22:52:20 +0900 Subject: [PATCH] Feat: get last chat #104 --- .../hana/hanalink/chat/controller/ChatRestController.java | 6 ++++++ .../java/com/hana/hanalink/chat/service/ChatService.java | 4 ++++ 2 files changed, 10 insertions(+) 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(); + } }