From 976b34f93d3444befcdaa65240df6488bcd4487c Mon Sep 17 00:00:00 2001 From: sungjiwoon Date: Tue, 23 Jan 2024 12:29:32 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/feign/client/MainFeignClient.java | 9 +++++-- .../chat/message/service/ChatService.java | 16 +++++++++++ .../feign/client/MainFeignClientTest.java | 27 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/catchroom/chat/feign/client/MainFeignClientTest.java diff --git a/src/main/java/com/catchroom/chat/feign/client/MainFeignClient.java b/src/main/java/com/catchroom/chat/feign/client/MainFeignClient.java index 50afa74..679ebd5 100644 --- a/src/main/java/com/catchroom/chat/feign/client/MainFeignClient.java +++ b/src/main/java/com/catchroom/chat/feign/client/MainFeignClient.java @@ -1,6 +1,7 @@ package com.catchroom.chat.feign.client; import com.catchroom.chat.chatroom.dto.ChatRoomListGetResponse; +import com.catchroom.chat.global.common.SuccessMessage; import com.catchroom.chat.global.config.FeignConfig; import com.catchroom.chat.feign.dto.AccommodationResponse; import org.springframework.cloud.openfeign.FeignClient; @@ -19,8 +20,12 @@ * * */ +//@FeignClient( +// name = "mainFeign", url = "https://catchroom.xyz/v1", +// configuration = FeignConfig.class +//) @FeignClient( - name = "mainFeign", url = "https://catchroom.xyz/v1", + name = "mainFeign", url = "http://localhost:8080/v1", configuration = FeignConfig.class ) public interface MainFeignClient { @@ -32,7 +37,7 @@ public interface MainFeignClient { List getChatRoomList(@RequestHeader("Authorization") String accessToken); @RequestMapping(method = RequestMethod.DELETE, value = "/chat/room") - String deleteChatRoom( + SuccessMessage deleteChatRoom( @RequestHeader("Authorization") String accessToken, @RequestParam(name = "roomId") String roomId ); diff --git a/src/main/java/com/catchroom/chat/message/service/ChatService.java b/src/main/java/com/catchroom/chat/message/service/ChatService.java index 09e8110..bd4b880 100644 --- a/src/main/java/com/catchroom/chat/message/service/ChatService.java +++ b/src/main/java/com/catchroom/chat/message/service/ChatService.java @@ -3,6 +3,7 @@ import com.catchroom.chat.chatroom.dto.ChatRoomListGetResponse; import com.catchroom.chat.chatroom.service.ChatRoomService; import com.catchroom.chat.feign.client.MainFeignClient; +import com.catchroom.chat.global.common.SuccessMessage; import com.catchroom.chat.message.dto.ChatMessageDto; import com.catchroom.chat.global.pubsub.RedisPublisher; import com.catchroom.chat.message.dto.MessageSubDto; @@ -21,6 +22,7 @@ public class ChatService { private final RedisPublisher redisPublisher; private final ChatRoomRepository chatRoomRepository; private final ChatRoomService chatRoomService; + private final MainFeignClient mainFeignClient; /** * destination 정보에서 roomId 추출 @@ -40,6 +42,10 @@ public void sendChatMessage(ChatMessageDto chatMessage, String accessToken) { chatMessage.setUserCount(chatRoomRepository.getUserCount(chatMessage.getRoomId())); chatRoomRepository.setLastChatMessage(chatMessage.getRoomId(), chatMessage); + if (chatMessage.getType().equals(MessageType.DELETE)) { + deleteChatRoom(accessToken, chatMessage.getRoomId()); + } + List chatRoomListGetResponseList = chatRoomService.getChatRoomList(accessToken); @@ -51,4 +57,14 @@ public void sendChatMessage(ChatMessageDto chatMessage, String accessToken) { redisPublisher.publish(messageSubDto); } + + /** + * 채팅방 삭제 로직 + * @param accessToken + * @param roomId + */ + private void deleteChatRoom(String accessToken, String roomId) { + SuccessMessage message = mainFeignClient.deleteChatRoom(accessToken, roomId); + } + } diff --git a/src/test/java/com/catchroom/chat/feign/client/MainFeignClientTest.java b/src/test/java/com/catchroom/chat/feign/client/MainFeignClientTest.java new file mode 100644 index 0000000..618d23d --- /dev/null +++ b/src/test/java/com/catchroom/chat/feign/client/MainFeignClientTest.java @@ -0,0 +1,27 @@ +package com.catchroom.chat.feign.client; + +import static org.junit.jupiter.api.Assertions.*; + +import com.catchroom.chat.global.common.SuccessMessage; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootTest(properties = {"env=test", "feign.client.config.default.loggerLevel=FULL"}) +class MainFeignClientTest { + + @Autowired + MainFeignClient mainFeignClient; + @Test + void deleteChatRoom() { + String accessToken = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJuYW1lIjoi7ISx7KeA7Jq0IiwicGhvbmVOdW1iZXIiOiIwMTAxMTExMjIyMiIsIm5pY2tOYW1lIjoi7KeA7Jq0IiwiZW1haWwiOiJ0ZXN0MTEyMkBtYWlsLmNvbSIsImlzcyI6ImNhdGNocm9vbSIsImlhdCI6MTcwNTk4MDA4NCwiZXhwIjoxNzA1OTgxODgzfQ.6Kj4Y2HPekK7S2XE5-99h3lmxiwzUmMoDLMrkM7mUaEpEJsxCB8ZVgxtYllocM9b8jRkuhYST3m5m39JFn9DMA"; + String roomId = "2678bef2-5798-45b0-b6e5-466251ecfe09"; + + SuccessMessage successMessage = mainFeignClient.deleteChatRoom( + accessToken, roomId + ); + assertEquals("SUCCESS", successMessage.Meassage()); + } +} \ No newline at end of file