Skip to content

Commit

Permalink
Merge pull request #43 from catchroom/develop
Browse files Browse the repository at this point in the history
์ฑ„ํŒ…๋ฐฉ ์‚ญ์ œ ๋ฐฐํฌ
  • Loading branch information
sungjiwoon authored Jan 23, 2024
2 parents 05cf0f2 + 9589733 commit f9dc0ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -32,7 +37,7 @@ public interface MainFeignClient {
List<ChatRoomListGetResponse> 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
);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/catchroom/chat/message/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ์ถ”์ถœ
Expand All @@ -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<ChatRoomListGetResponse> chatRoomListGetResponseList =
chatRoomService.getChatRoomList(accessToken);

Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit f9dc0ed

Please sign in to comment.