Skip to content

Commit c80ba9b

Browse files
committed
[EA3-111] feature : data.sql comment 문 주석처리 및 그룹채팅 테스트 위한 html 파일 생성
1 parent 29a8eda commit c80ba9b

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed

src/main/resources/data.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ INSERT INTO study_post (study_id, user_id, title, category, content) VALUES (4,
1616
INSERT INTO study_post (study_id, user_id, title, category, content) VALUES (2, 2, '개발 유튜브 공유', 'FREE', '재미니의 개발실무 ( 토스 ); 개발바닥');
1717
INSERT INTO study_post (study_id, user_id, title, category, content) VALUES (5, 5, '점심 메뉴 추천', 'FREE', '오늘 점심 뭐먹을지 추천 받습니다!');
1818

19-
INSERT INTO comment (post_id, user_id, content) VALUES (5, 4, '확인 했습니다!');
20-
INSERT INTO comment (post_id, user_id, content) VALUES (5, 4, '좋은 정보 감사합니다!');
21-
INSERT INTO comment (post_id, user_id, content) VALUES (3, 2, '관련된 블로그 공유 드립니다!');
22-
INSERT INTO comment (post_id, user_id, content) VALUES (2, 5, '정보 감사합니다!');
23-
INSERT INTO comment (post_id, user_id, content) VALUES (4, 1, '제육 돈까스');
19+
-- INSERT INTO comment (post_id, user_id, content) VALUES (5, 4, '확인 했습니다!');
20+
-- INSERT INTO comment (post_id, user_id, content) VALUES (5, 4, '좋은 정보 감사합니다!');
21+
-- INSERT INTO comment (post_id, user_id, content) VALUES (3, 2, '관련된 블로그 공유 드립니다!');
22+
-- INSERT INTO comment (post_id, user_id, content) VALUES (2, 5, '정보 감사합니다!');
23+
-- INSERT INTO comment (post_id, user_id, content) VALUES (4, 1, '제육 돈까스');
2424

2525
INSERT INTO study_member (study_id, user_id, role, participated) VALUES (1, 3, 'LEADER', FALSE);
2626
INSERT INTO study_member (study_id, user_id, role, participated) VALUES (1, 4, 'MEMBER', FALSE);
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html>
2+
<html lang="ko">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>그룹 채팅 로컬 테스트</title>
6+
<script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.5.1/sockjs.min.js"></script>
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"></script>
8+
</head>
9+
<body>
10+
<h2>그룹 채팅 테스트 (로컬 서버)</h2>
11+
12+
<div>
13+
<label>Room ID: </label>
14+
<input type="number" id="roomId" value="1">
15+
<label>Sender ID: </label>
16+
<input type="number" id="senderId" value="10">
17+
<button onclick="connect()">연결하기</button>
18+
<button onclick="disconnect()">연결 해제</button>
19+
</div>
20+
21+
<hr>
22+
23+
<div>
24+
<input type="text" id="messageInput" placeholder="메시지를 입력하세요" style="width: 300px;">
25+
<button onclick="sendMessage()">전송</button>
26+
</div>
27+
28+
<h3>채팅 로그</h3>
29+
<ul id="chatList"></ul>
30+
31+
<script>
32+
let stompClient = null;
33+
let currentRoomId = null;
34+
35+
function connect() {
36+
const roomId = document.getElementById("roomId").value || 1;
37+
currentRoomId = roomId;
38+
39+
// 로컬 서버용 WebSocket 엔드포인트
40+
const socket = new SockJS("http://localhost:8083/ws-stomp");
41+
stompClient = Stomp.over(socket);
42+
43+
stompClient.connect({}, function (frame) {
44+
console.log("WebSocket 연결 성공:", frame);
45+
alert("채팅방 " + roomId + "에 연결되었습니다!");
46+
47+
// 채팅방 구독
48+
stompClient.subscribe(`/sub/chat/room/${roomId}`, function (message) {
49+
const chat = JSON.parse(message.body);
50+
showMessage(chat.senderNickname + ": " + chat.message);
51+
});
52+
});
53+
}
54+
55+
function sendMessage() {
56+
const messageContent = document.getElementById("messageInput").value;
57+
const senderId = document.getElementById("senderId").value || 10;
58+
59+
if (stompClient && stompClient.connected) {
60+
stompClient.send("/pub/chat/message", {}, JSON.stringify({
61+
roomId: currentRoomId,
62+
senderId: senderId,
63+
message: messageContent
64+
}));
65+
document.getElementById("messageInput").value = "";
66+
} else {
67+
alert("WebSocket이 연결되지 않았습니다.");
68+
}
69+
}
70+
71+
function disconnect() {
72+
if (stompClient) {
73+
stompClient.disconnect(() => {
74+
alert("연결이 해제되었습니다.");
75+
});
76+
}
77+
}
78+
79+
function showMessage(message) {
80+
const li = document.createElement("li");
81+
li.textContent = message;
82+
document.getElementById("chatList").appendChild(li);
83+
}
84+
</script>
85+
</body>
86+
</html>

0 commit comments

Comments
 (0)