From f2f71e1f7c4cf91166409e98abe783d242264682 Mon Sep 17 00:00:00 2001 From: world-dv Date: Thu, 21 Nov 2024 21:17:28 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9E=AC=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tasksprints/auction/common/config/WebSockConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tasksprints/auction/common/config/WebSockConfig.java b/src/main/java/com/tasksprints/auction/common/config/WebSockConfig.java index b2cb4ae..b41e358 100644 --- a/src/main/java/com/tasksprints/auction/common/config/WebSockConfig.java +++ b/src/main/java/com/tasksprints/auction/common/config/WebSockConfig.java @@ -14,8 +14,8 @@ public class WebSockConfig implements WebSocketMessageBrokerConfigurer { @Override public void configureMessageBroker(MessageBrokerRegistry brokerRegistry) { - brokerRegistry.enableSimpleBroker("/sub"); //server - brokerRegistry.setApplicationDestinationPrefixes("/pub"); //client + brokerRegistry.enableSimpleBroker("/topic", "/bid"); + brokerRegistry.setApplicationDestinationPrefixes("/app"); } @Override From 5b2c3e8ba483931d6ddf18ae924f51e7c5708081 Mon Sep 17 00:00:00 2001 From: world-dv Date: Thu, 21 Nov 2024 21:30:22 +0900 Subject: [PATCH 02/10] =?UTF-8?q?refactor:=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=AC=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tasksprints/auction/api/socket/ChatController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tasksprints/auction/api/socket/ChatController.java b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java index 9dcb732..586ead0 100644 --- a/src/main/java/com/tasksprints/auction/api/socket/ChatController.java +++ b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java @@ -21,6 +21,6 @@ public void message(MessageDto messageDto) { if (MessageDto.MessageType.LEAVE.equals(messageDto.getType())) { messageDto.setMessage(messageDto.getSender() + "님이 퇴장하셨습니다."); } - simpMessageSendingOperations.convertAndSend("/sub/chat/room/" + messageDto.getRoomId(), messageDto); + simpMessageSendingOperations.convertAndSend("/bid/chat/room/" + messageDto.getRoomId(), messageDto); } } From 99128b41bf787597789d92f3cf1d93d757d64907 Mon Sep 17 00:00:00 2001 From: world-dv Date: Thu, 21 Nov 2024 21:50:10 +0900 Subject: [PATCH 03/10] =?UTF-8?q?style:=20=EC=9D=98=EB=AF=B8=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EA=B3=B5=EB=B0=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tasksprints/auction/domain/socket/dto/MessageDto.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/tasksprints/auction/domain/socket/dto/MessageDto.java b/src/main/java/com/tasksprints/auction/domain/socket/dto/MessageDto.java index dafed06..89250f2 100644 --- a/src/main/java/com/tasksprints/auction/domain/socket/dto/MessageDto.java +++ b/src/main/java/com/tasksprints/auction/domain/socket/dto/MessageDto.java @@ -17,7 +17,6 @@ public enum MessageType { private String sender; private String message; - public void setMessage(String s) { this.message = s; } From a7a10e908c278fedc40ed8b3b97917f0df8c7fce Mon Sep 17 00:00:00 2001 From: world-dv Date: Thu, 21 Nov 2024 21:58:48 +0900 Subject: [PATCH 04/10] =?UTF-8?q?refactor:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20=EC=B0=B8=EA=B0=80=EC=9E=90=EB=A5=BC=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tasksprints/auction/domain/socket/model/ChatRoom.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/tasksprints/auction/domain/socket/model/ChatRoom.java b/src/main/java/com/tasksprints/auction/domain/socket/model/ChatRoom.java index 54ec2d9..f32f792 100644 --- a/src/main/java/com/tasksprints/auction/domain/socket/model/ChatRoom.java +++ b/src/main/java/com/tasksprints/auction/domain/socket/model/ChatRoom.java @@ -1,5 +1,6 @@ package com.tasksprints.auction.domain.socket.model; +import com.tasksprints.auction.domain.user.model.User; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -27,13 +28,13 @@ public class ChatRoom { private String name; @OneToMany - @Column(name = "chatterList") - private List chatters; + @Column(name = "users") + private List users; @Builder public ChatRoom(String name) { this.chatRoomId = UUID.randomUUID().toString(); this.name = name; - this.chatters = new ArrayList<>(); + this.users = new ArrayList<>(); } } From 5c6043d26fc7b65bf7d231bbbb4bc8b4e9ddecc7 Mon Sep 17 00:00:00 2001 From: world-dv Date: Thu, 21 Nov 2024 22:03:13 +0900 Subject: [PATCH 05/10] =?UTF-8?q?remove:=20chatter=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/socket/model/QChatRoom.java | 4 +- .../auction/domain/socket/model/QChatter.java | 39 ------------------- .../auction/domain/socket/model/Chatter.java | 28 ------------- .../socket/repository/ChatterRepository.java | 9 ----- 4 files changed, 2 insertions(+), 78 deletions(-) delete mode 100644 src/main/generated/com/tasksprints/auction/domain/socket/model/QChatter.java delete mode 100644 src/main/java/com/tasksprints/auction/domain/socket/model/Chatter.java delete mode 100644 src/main/java/com/tasksprints/auction/domain/socket/repository/ChatterRepository.java diff --git a/src/main/generated/com/tasksprints/auction/domain/socket/model/QChatRoom.java b/src/main/generated/com/tasksprints/auction/domain/socket/model/QChatRoom.java index c437dad..bbffb40 100644 --- a/src/main/generated/com/tasksprints/auction/domain/socket/model/QChatRoom.java +++ b/src/main/generated/com/tasksprints/auction/domain/socket/model/QChatRoom.java @@ -22,12 +22,12 @@ public class QChatRoom extends EntityPathBase { public final StringPath chatRoomId = createString("chatRoomId"); - public final ListPath chatters = this.createList("chatters", Chatter.class, QChatter.class, PathInits.DIRECT2); - public final NumberPath id = createNumber("id", Long.class); public final StringPath name = createString("name"); + public final ListPath users = this.createList("users", com.tasksprints.auction.domain.user.model.User.class, com.tasksprints.auction.domain.user.model.QUser.class, PathInits.DIRECT2); + public QChatRoom(String variable) { super(ChatRoom.class, forVariable(variable)); } diff --git a/src/main/generated/com/tasksprints/auction/domain/socket/model/QChatter.java b/src/main/generated/com/tasksprints/auction/domain/socket/model/QChatter.java deleted file mode 100644 index 0113e8f..0000000 --- a/src/main/generated/com/tasksprints/auction/domain/socket/model/QChatter.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.tasksprints.auction.domain.socket.model; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; - - -/** - * QChatter is a Querydsl query type for Chatter - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QChatter extends EntityPathBase { - - private static final long serialVersionUID = 1660492673L; - - public static final QChatter chatter = new QChatter("chatter"); - - public final StringPath chatterId = createString("chatterId"); - - public final StringPath sessionId = createString("sessionId"); - - public QChatter(String variable) { - super(Chatter.class, forVariable(variable)); - } - - public QChatter(Path path) { - super(path.getType(), path.getMetadata()); - } - - public QChatter(PathMetadata metadata) { - super(Chatter.class, metadata); - } - -} - diff --git a/src/main/java/com/tasksprints/auction/domain/socket/model/Chatter.java b/src/main/java/com/tasksprints/auction/domain/socket/model/Chatter.java deleted file mode 100644 index 8f43191..0000000 --- a/src/main/java/com/tasksprints/auction/domain/socket/model/Chatter.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tasksprints.auction.domain.socket.model; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Chatter { - - @Id - @Column(name = "chatterId") - private String chatterId; - - @Column(name = "sessionId") - private String sessionId; - - @Builder - public Chatter(String id, String sessionId) { - this.chatterId = id; - this.sessionId = sessionId; - } -} diff --git a/src/main/java/com/tasksprints/auction/domain/socket/repository/ChatterRepository.java b/src/main/java/com/tasksprints/auction/domain/socket/repository/ChatterRepository.java deleted file mode 100644 index 64b73b9..0000000 --- a/src/main/java/com/tasksprints/auction/domain/socket/repository/ChatterRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.tasksprints.auction.domain.socket.repository; - -import com.tasksprints.auction.domain.socket.model.Chatter; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ChatterRepository extends JpaRepository { -} From 73e436b656d3852545e3af8a3e8d2814266de998 Mon Sep 17 00:00:00 2001 From: world-dv Date: Thu, 21 Nov 2024 22:03:49 +0900 Subject: [PATCH 06/10] =?UTF-8?q?remove:=20view=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auction/api/socket/ChatRoomController.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/com/tasksprints/auction/api/socket/ChatRoomController.java b/src/main/java/com/tasksprints/auction/api/socket/ChatRoomController.java index a8a8828..3f3844c 100644 --- a/src/main/java/com/tasksprints/auction/api/socket/ChatRoomController.java +++ b/src/main/java/com/tasksprints/auction/api/socket/ChatRoomController.java @@ -15,11 +15,6 @@ public class ChatRoomController { private final ChatService chatService; - @GetMapping("/chat/room") - public String chatRoomList(Model model) { - return "/chat/room"; - } //채팅방 목록 화면 - @GetMapping("/chat/room/all") @ResponseBody public List chatRoomAll() { @@ -32,12 +27,6 @@ public ChatRoom createChatRoom(@RequestParam("name") String name) { return chatService.createRoom(name); } //채팅방 생성 - @GetMapping("/chat/room/enter/{chatRoomId}") - public String enterChatRoom(Model model, @PathVariable(value = "chatRoomId") String chatRoomId) { - model.addAttribute("chatRoomId", chatRoomId); - return "/chat/enter"; - } //채팅방 입장 화면 - @GetMapping("/chat/room/{chatRoomId}") @ResponseBody public ChatRoom chatRoom(@PathVariable(value = "chatRoomId") String chatRoomId) { From f085d6f9c49a3f4e0c586d3adfcc2310327aa765 Mon Sep 17 00:00:00 2001 From: world-dv Date: Thu, 21 Nov 2024 22:29:26 +0900 Subject: [PATCH 07/10] =?UTF-8?q?refactor:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=95=88=EB=82=B4=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=9E=AC=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tasksprints/auction/api/socket/ChatController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tasksprints/auction/api/socket/ChatController.java b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java index 586ead0..496515d 100644 --- a/src/main/java/com/tasksprints/auction/api/socket/ChatController.java +++ b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java @@ -21,6 +21,6 @@ public void message(MessageDto messageDto) { if (MessageDto.MessageType.LEAVE.equals(messageDto.getType())) { messageDto.setMessage(messageDto.getSender() + "님이 퇴장하셨습니다."); } - simpMessageSendingOperations.convertAndSend("/bid/chat/room/" + messageDto.getRoomId(), messageDto); + simpMessageSendingOperations.convertAndSend("/topic/chat/room/" + messageDto.getRoomId(), messageDto); } } From 565854518a3390b781dc92cf277b5f2f430369cf Mon Sep 17 00:00:00 2001 From: world-dv Date: Fri, 22 Nov 2024 01:31:38 +0900 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20=EA=B7=93=EC=86=8D=EB=A7=90=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /whisper/{받는 사람} 경로로 귓속말 메시지를 전달하는 기능을 구현합니다. - 이 기능을 사용하기 위해서는 유저가 채팅방에 입장했을 때 본인의 email 또는 nickname을 받는 사람으로 설정한 경로를 구독해야 합니다. - 경로 관련 설명을 추가합니다. --- .../auction/api/socket/ChatController.java | 14 ++++++++++++-- .../auction/common/config/WebSockConfig.java | 8 +++++++- .../auction/domain/socket/dto/WhisperDto.java | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java diff --git a/src/main/java/com/tasksprints/auction/api/socket/ChatController.java b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java index 496515d..4b9bbc8 100644 --- a/src/main/java/com/tasksprints/auction/api/socket/ChatController.java +++ b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java @@ -1,6 +1,8 @@ package com.tasksprints.auction.api.socket; import com.tasksprints.auction.domain.socket.dto.MessageDto; +import com.tasksprints.auction.domain.socket.dto.MessageDto.MessageType; +import com.tasksprints.auction.domain.socket.dto.WhisperDto; import lombok.RequiredArgsConstructor; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.simp.SimpMessageSendingOperations; @@ -14,13 +16,21 @@ public class ChatController { @MessageMapping("/chat/message") public void message(MessageDto messageDto) { - if (MessageDto.MessageType.ENTER.equals(messageDto.getType())) { + if (MessageType.ENTER.equals(messageDto.getType())) { messageDto.setMessage(messageDto.getSender() + "님이 입장하셨습니다."); } - if (MessageDto.MessageType.LEAVE.equals(messageDto.getType())) { + if (MessageType.LEAVE.equals(messageDto.getType())) { messageDto.setMessage(messageDto.getSender() + "님이 퇴장하셨습니다."); } simpMessageSendingOperations.convertAndSend("/topic/chat/room/" + messageDto.getRoomId(), messageDto); } + + @MessageMapping("/chat/message/whisper") + public void messageToOne(WhisperDto whisperDto) { + simpMessageSendingOperations.convertAndSend("/whisper/" + whisperDto.getReceiver(), whisperDto); + //유저 생성 시 "/whisper/{유저 email 또는 nickname}" 경로를 구독해야 귓속말이 가능 + //유저가 보낼 때 받는 사람의 경로로 메시지를 전달 -> 받는 사람만 메시지를 볼 수 있음 + //답장 또한 받은 사람이 보낼 사람의 경로로 메시지를 전달해 1대 1 채팅이 되도록 함 + } } diff --git a/src/main/java/com/tasksprints/auction/common/config/WebSockConfig.java b/src/main/java/com/tasksprints/auction/common/config/WebSockConfig.java index b41e358..2fd79b2 100644 --- a/src/main/java/com/tasksprints/auction/common/config/WebSockConfig.java +++ b/src/main/java/com/tasksprints/auction/common/config/WebSockConfig.java @@ -12,9 +12,15 @@ @EnableWebSocketMessageBroker public class WebSockConfig implements WebSocketMessageBrokerConfigurer { + /* + /topic : 채팅방 전체 메시지 (공지) 경로 + /bid : bid 메시지 (주로 bid 금액 업데이트 관련) 경로 + /whisper : 귓속말 경로 + */ + @Override public void configureMessageBroker(MessageBrokerRegistry brokerRegistry) { - brokerRegistry.enableSimpleBroker("/topic", "/bid"); + brokerRegistry.enableSimpleBroker("/topic", "/bid", "/whisper"); brokerRegistry.setApplicationDestinationPrefixes("/app"); } diff --git a/src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java b/src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java new file mode 100644 index 0000000..5fc0097 --- /dev/null +++ b/src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java @@ -0,0 +1,18 @@ +package com.tasksprints.auction.domain.socket.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class WhisperDto { + + private String sender; //보내는 사람 email 또는 닉네임 + private String receiver; //받는 사람 email 또는 닉네임 + private String message; +} + +// email 은 unique 하기때문에 sender 와 receiver 로 사용 가능 +// 하지만 nickname 을 고유하게 설정해서 nickname 을 사용해도 좋을 것 같음 From 4d18bdea51cdc290fa45c20d37e592fa04b583c8 Mon Sep 17 00:00:00 2001 From: world-dv Date: Fri, 22 Nov 2024 01:51:45 +0900 Subject: [PATCH 09/10] =?UTF-8?q?remove:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20view=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/chat/enter.html | 105 ------------------- src/main/resources/templates/chat/room.html | 98 ----------------- 2 files changed, 203 deletions(-) delete mode 100644 src/main/resources/templates/chat/enter.html delete mode 100644 src/main/resources/templates/chat/room.html diff --git a/src/main/resources/templates/chat/enter.html b/src/main/resources/templates/chat/enter.html deleted file mode 100644 index 09707d0..0000000 --- a/src/main/resources/templates/chat/enter.html +++ /dev/null @@ -1,105 +0,0 @@ - - - - Websocket ChatRoom - - - - - - - -
-
-

- -
-
-
- -
- -
- -
-
-
    -
-
- - - - - - - - diff --git a/src/main/resources/templates/chat/room.html b/src/main/resources/templates/chat/room.html deleted file mode 100644 index 91d78e0..0000000 --- a/src/main/resources/templates/chat/room.html +++ /dev/null @@ -1,98 +0,0 @@ - - - - Websocket Chat - - - - - - -
-
-
-

채팅방 리스트

-
-
-
-
- -
- -
- -
-
-
    -
-
- - - - - - From fb6969cdd6f69bb061f2e35a5de0de2cca901d86 Mon Sep 17 00:00:00 2001 From: world-dv Date: Fri, 22 Nov 2024 20:22:55 +0900 Subject: [PATCH 10/10] =?UTF-8?q?feat:=20=EA=B7=93=EC=86=8D=EB=A7=90=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EA=B8=B0=EB=B3=B8=20=ED=8F=AC?= =?UTF-8?q?=EB=A7=B7=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tasksprints/auction/api/socket/ChatController.java | 1 + .../com/tasksprints/auction/domain/socket/dto/WhisperDto.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/com/tasksprints/auction/api/socket/ChatController.java b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java index 4b9bbc8..6ce881f 100644 --- a/src/main/java/com/tasksprints/auction/api/socket/ChatController.java +++ b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java @@ -28,6 +28,7 @@ public void message(MessageDto messageDto) { @MessageMapping("/chat/message/whisper") public void messageToOne(WhisperDto whisperDto) { + whisperDto.setMessage("[귓속말] " + whisperDto.getSender() + " : " + whisperDto.getMessage()); simpMessageSendingOperations.convertAndSend("/whisper/" + whisperDto.getReceiver(), whisperDto); //유저 생성 시 "/whisper/{유저 email 또는 nickname}" 경로를 구독해야 귓속말이 가능 //유저가 보낼 때 받는 사람의 경로로 메시지를 전달 -> 받는 사람만 메시지를 볼 수 있음 diff --git a/src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java b/src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java index 5fc0097..3e885a0 100644 --- a/src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java +++ b/src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java @@ -12,6 +12,10 @@ public class WhisperDto { private String sender; //보내는 사람 email 또는 닉네임 private String receiver; //받는 사람 email 또는 닉네임 private String message; + + public void setMessage(String message) { + this.message = message; + } } // email 은 unique 하기때문에 sender 와 receiver 로 사용 가능