diff --git a/src/main/java/shop/geeksasangchat/common/websocket/SocketHandler.java b/src/main/java/shop/geeksasangchat/common/websocket/SocketHandler.java index 4f253d1..f736278 100644 --- a/src/main/java/shop/geeksasangchat/common/websocket/SocketHandler.java +++ b/src/main/java/shop/geeksasangchat/common/websocket/SocketHandler.java @@ -12,6 +12,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler; import shop.geeksasangchat.dto.PostChattingRes; import shop.geeksasangchat.rabbitmq.ChattingVO; +import shop.geeksasangchat.service.PartyChattingService; import java.util.HashMap; @@ -20,6 +21,7 @@ public class SocketHandler extends TextWebSocketHandler { private final RabbitTemplate rabbitTemplate; private final String EXCHANGE = "chatting-room-exchange-test2"; + private final PartyChattingService partyChattingService; HashMap sessionMap = new HashMap<>(); //웹소켓 세션을 담아둘 맵 @@ -34,30 +36,28 @@ public void handleTextMessage(WebSocketSession session, TextMessage message) { try { // ObjectMapper mapper = new ObjectMapper(); - ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); - ChattingVO chattingVO = mapper.readValue(msg, ChattingVO.class); +// ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); +// ChattingVO chattingVO = mapper.readValue(msg, ChattingVO.class); - String exchangeName = "chatting-" + "exchange-" + chattingVO.getChattingRoomUUID(); // json 형식으로 변환 후 전송 -// ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); + ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); // PostChattingRes postChattingRes = new PostChattingRes(chattingRoomId, saveChatting.getContent(), saveChatting.getBaseEntity().getCreatedAt()); // ObjectMapper가 java8의 LocalDateTime을 지원하지 않는 에러 해결 -// PostChattingRes postChattingRes = mapper.readValue(msg, PostChattingRes.class); - String saveChattingJsonStr = null; - try { - saveChattingJsonStr = mapper.writeValueAsString(chattingVO); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } -// for(int i=0;i createPartyChattingRoom(HttpServletRequest request, @R } @PostMapping("/chatting") + public BaseResponse createPartyChatting(HttpServletRequest request, @RequestBody PostChattingReq dto){ + JwtInfo jwtInfo = (JwtInfo) request.getAttribute("jwtInfo"); + System.out.println("dto.getChattingRoomId() = " + dto.getChattingRoomId()); + partyChattingService.createChatting(jwtInfo.getUserId(), "tomas", dto.getChattingRoomId(), dto.getContent()); + return new BaseResponse("채팅송신을 성공했습니다."); + } // @NoIntercept //TODO:개발을 위해 임시로 jwt 허용되게한 것. 추후 제거 바람. // public BaseResponse createPartyChatting(HttpServletRequest request, @RequestBody PostChattingReq dto){ -// JwtInfo jwtInfo = (JwtInfo) request.getAttribute("jwtInfo"); +//// JwtInfo jwtInfo = (JwtInfo) request.getAttribute("jwtInfo"); // System.out.println("dto.getChattingRoomId() = " + dto.getChattingRoomId()); -// partyChattingService.createChatting(jwtInfo.getUserId(), dto.getChattingRoomId(), dto.getContent(), dto.getParticipantsCnt()); +// partyChattingService.createChatting(1, dto.getChattingRoomId(), dto.getContent(), dto.getParticipantsCnt()); // return new BaseResponse("채팅송신을 성공했습니다."); // } - @NoIntercept //TODO:개발을 위해 임시로 jwt 허용되게한 것. 추후 제거 바람. - public BaseResponse createPartyChatting(HttpServletRequest request, @RequestBody PostChattingReq dto){ -// JwtInfo jwtInfo = (JwtInfo) request.getAttribute("jwtInfo"); - System.out.println("dto.getChattingRoomId() = " + dto.getChattingRoomId()); - partyChattingService.createChatting(1, dto.getChattingRoomId(), dto.getContent(), dto.getParticipantsCnt()); - return new BaseResponse("채팅송신을 성공했습니다."); - } /** * @author 토마스 diff --git a/src/main/java/shop/geeksasangchat/dto/PostChattingReq.java b/src/main/java/shop/geeksasangchat/dto/PostChattingReq.java index 50f88f5..d23f930 100644 --- a/src/main/java/shop/geeksasangchat/dto/PostChattingReq.java +++ b/src/main/java/shop/geeksasangchat/dto/PostChattingReq.java @@ -15,11 +15,8 @@ public class PostChattingReq { @NotEmpty private String content; - private int participantsCnt; - - public PostChattingReq(String chattingRoomId, String content, int participantsCnt) { + public PostChattingReq(String chattingRoomId, String content) { this.chattingRoomId = chattingRoomId; this.content = content; - this.participantsCnt = participantsCnt; } } diff --git a/src/main/java/shop/geeksasangchat/dto/PostChattingRes.java b/src/main/java/shop/geeksasangchat/dto/PostChattingRes.java index db70cf7..b5aeb3b 100644 --- a/src/main/java/shop/geeksasangchat/dto/PostChattingRes.java +++ b/src/main/java/shop/geeksasangchat/dto/PostChattingRes.java @@ -12,6 +12,10 @@ @Getter public class PostChattingRes { + private String chattingId; + + private String email; + @NotEmpty private String chattingRoomId; @@ -26,4 +30,13 @@ public PostChattingRes(String chattingRoomId, String content, LocalDateTime crea this.content = content; this.createdAt = createdAt; } + + public PostChattingRes(String email, String chattingRoomId, String content, LocalDateTime createdAt) { + this.email = email; + this.chattingRoomId = chattingRoomId; + this.content = content; + this.createdAt = createdAt; + } + + } diff --git a/src/main/java/shop/geeksasangchat/rabbitmq/MQController.java b/src/main/java/shop/geeksasangchat/rabbitmq/MQController.java index 5d368c0..51b1903 100644 --- a/src/main/java/shop/geeksasangchat/rabbitmq/MQController.java +++ b/src/main/java/shop/geeksasangchat/rabbitmq/MQController.java @@ -35,7 +35,6 @@ public String createChattingRoom(@RequestParam String email, @RequestParam Strin Binding binding = new Binding(email, Binding.DestinationType.QUEUE, exchangeName, "asdf",null); //TODO: fanoutExchange는 routingKey가 필요없지만 없으면 에러나서 임시로 입력 함. admin.declareBinding(binding); - return "OK"; } diff --git a/src/main/java/shop/geeksasangchat/rabbitmq/PartyChattingQueue.java b/src/main/java/shop/geeksasangchat/rabbitmq/PartyChattingQueue.java index 3e1930a..0f53e36 100644 --- a/src/main/java/shop/geeksasangchat/rabbitmq/PartyChattingQueue.java +++ b/src/main/java/shop/geeksasangchat/rabbitmq/PartyChattingQueue.java @@ -38,10 +38,11 @@ public TopicExchange getTopicExchange() { } // publish 메소드: 큐애 메시지 보내기 - public void send(Chatting saveChatting, String chattingRoomId, int participantsCnt) { + public void send(Chatting saveChatting, String chattingRoomId) { System.out.println("====================" + chattingRoomId); System.out.println("chattingRoomId = " + chattingRoomId); System.out.println("saveChatting = " + saveChatting); + String exchangeName = "chatting-" + "exchange-" + chattingRoomId; // json 형식으로 변환 후 전송 ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); PostChattingRes postChattingRes = new PostChattingRes(chattingRoomId, saveChatting.getContent(), saveChatting.getBaseEntity().getCreatedAt()); // ObjectMapper가 java8의 LocalDateTime을 지원하지 않는 에러 해결 @@ -51,10 +52,10 @@ public void send(Chatting saveChatting, String chattingRoomId, int participantsC } catch (JsonProcessingException e) { e.printStackTrace(); } - for(int i=0;i