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/api/socket/ChatController.java b/src/main/java/com/tasksprints/auction/api/socket/ChatController.java index 9dcb732..6ce881f 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,22 @@ 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("/sub/chat/room/" + messageDto.getRoomId(), messageDto); + simpMessageSendingOperations.convertAndSend("/topic/chat/room/" + messageDto.getRoomId(), 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}" 경로를 구독해야 귓속말이 가능 + //유저가 보낼 때 받는 사람의 경로로 메시지를 전달 -> 받는 사람만 메시지를 볼 수 있음 + //답장 또한 받은 사람이 보낼 사람의 경로로 메시지를 전달해 1대 1 채팅이 되도록 함 } } 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) { 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..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,10 +12,16 @@ @EnableWebSocketMessageBroker public class WebSockConfig implements WebSocketMessageBrokerConfigurer { + /* + /topic : 채팅방 전체 메시지 (공지) 경로 + /bid : bid 메시지 (주로 bid 금액 업데이트 관련) 경로 + /whisper : 귓속말 경로 + */ + @Override public void configureMessageBroker(MessageBrokerRegistry brokerRegistry) { - brokerRegistry.enableSimpleBroker("/sub"); //server - brokerRegistry.setApplicationDestinationPrefixes("/pub"); //client + brokerRegistry.enableSimpleBroker("/topic", "/bid", "/whisper"); + brokerRegistry.setApplicationDestinationPrefixes("/app"); } @Override 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; } 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..3e885a0 --- /dev/null +++ b/src/main/java/com/tasksprints/auction/domain/socket/dto/WhisperDto.java @@ -0,0 +1,22 @@ +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; + + public void setMessage(String message) { + this.message = message; + } +} + +// email 은 unique 하기때문에 sender 와 receiver 로 사용 가능 +// 하지만 nickname 을 고유하게 설정해서 nickname 을 사용해도 좋을 것 같음 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<>(); } } 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 { -} 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 - - - - - - -
-
-
-

채팅방 리스트

-
-
-
-
- -
- -
- -
-
-
    -
-
- - - - - -