Skip to content

Commit 3f7eaba

Browse files
committed
[REFACTOR] 채팅방 생성 API JWT 인증 적용
1 parent 78491f4 commit 3f7eaba

3 files changed

Lines changed: 194 additions & 24 deletions

File tree

src/chat/chat.routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { authenticate } from "../middlewares/auth.middleware.js";
99
const router = express.Router();
1010

1111
// 채팅방 생성 API
12-
router.post("", createChatroom);
12+
router.post("", authenticate, createChatroom);
1313

1414
// 채팅방 삭제 API
1515
router.delete("/delete", authenticate, deleteChatrooms);
@@ -18,7 +18,7 @@ router.delete("/delete", authenticate, deleteChatrooms);
1818
router.get("/search/messages", authenticate, getMessageByKeyword);
1919

2020
// 채팅방 조회 API
21-
router.get("", authenticate, getChatroom);
21+
router.get("/list", authenticate, getChatroom);
2222

2323
// 채팅 메시지 조회 API
2424
router.get("/:chatroomId/messages", authenticate, getMessages);

src/chat/controller/chatroom.controller.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import { parseWithBigInt, stringifyWithBigInt } from "../../bigintJson.js";
77

88
export const createChatroom = async (req, res, next) => {
99
try {
10+
const consumerId = BigInt(req.user.userId);
11+
1012
const dto = new CreateChatroomDto({
11-
consumerId: BigInt(req.body.consumerId),
13+
consumerId: consumerId,
1214
artistId: BigInt(req.body.artistId),
1315
requestId: BigInt(req.body.requestId),
1416
});

src/common/swagger/chat.json

Lines changed: 189 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"post": {
55
"summary": "채팅방 생성",
66
"description": "consumerId, artistId, requestId로 채팅방을 생성합니다.",
7+
"security": [
8+
{
9+
"bearerAuth": []
10+
}
11+
],
712
"tags": ["Chat"],
813
"requestBody": {
914
"required": true,
@@ -45,28 +50,41 @@
4550
}
4651
},
4752
"404": {
48-
"description": "사용자, 작가, 요청 중 하나를 찾을 수 없음"
53+
"description": "사용자를 찾을 수 없음",
54+
"content": {
55+
"application/json": {
56+
"schema": {
57+
"type": "object",
58+
"properties": {
59+
"resultType": { "type": "string", "example": "FAIL" },
60+
"error": {
61+
"type": "object",
62+
"properties": {
63+
"errorCode": { "type": "string", "example": "U001" },
64+
"reason": { "type": "string", "example": "사용자 id를 찾을 수 없습니다." },
65+
"data": { "type": "object" }
66+
}
67+
},
68+
"success": { "type": "object", "nullable": true, "example": null }
69+
}
70+
}
71+
}
72+
}
4973
}
5074
}
5175
}
5276
},
53-
"/api/chatrooms/{consumerId}": {
77+
"/api/chatrooms/list": {
5478
"get": {
55-
"summary": "사용자 ID로 채팅방 목록 조회",
56-
"description": "사용자 ID를 바탕으로 해당 사용자가 참여한 채팅방 목록을 조회합니다.",
57-
"tags": ["Chat"],
58-
"parameters": [
79+
"summary": "채팅방 목록 조회",
80+
"description": "사용자가 참여한 채팅방 목록을 조회합니다.",
81+
"security": [
5982
{
60-
"name": "consumerId",
61-
"in": "path",
62-
"required": true,
63-
"schema": {
64-
"type": "string",
65-
"example": "1"
66-
},
67-
"description": "조회할 사용자의 ID"
83+
"bearerAuth": []
6884
}
6985
],
86+
"tags": ["Chat"],
87+
"parameters": [],
7088
"responses": {
7189
"200": {
7290
"description": "채팅방 목록 조회 성공",
@@ -132,6 +150,11 @@
132150
"delete": {
133151
"summary": "채팅방 소프트 삭제 (hidden 처리) 및 조건부 하드 삭제",
134152
"description": "사용자가 선택한 채팅방들을 hidden 처리 후, hiddenUser와 hiddenArtist가 모두 true인 경우 DB에서 삭제합니다.",
153+
"security": [
154+
{
155+
"bearerAuth": []
156+
}
157+
],
135158
"tags": ["Chat"],
136159
"requestBody": {
137160
"required": true,
@@ -163,18 +186,67 @@
163186
"description": "삭제 처리 완료 (내용 없음)"
164187
},
165188
"400": {
166-
"description": "잘못된 요청 파라미터"
189+
"description": "잘못된 요청 파라미터",
190+
"content": {
191+
"application/json": {
192+
"schema": {
193+
"type": "object",
194+
"properties": {
195+
"resultType": { "type": "string", "example": "FAIL" },
196+
"error": {
197+
"type": "object",
198+
"properties": {
199+
"errorCode": { "type": "string", "example": "C001" },
200+
"reason": { "type": "string", "example": "userType은 'consumer' 또는 'artist'여야 합니다." },
201+
"data": { "type": "object", "example": {} }
202+
}
203+
},
204+
"success": {
205+
"type": ["object", "null"],
206+
"example": null
207+
}
208+
}
209+
}
210+
}
211+
}
167212
},
168213
"404": {
169-
"description": "채팅방을 찾을 수 없음"
214+
"description": "채팅방을 찾을 수 없음",
215+
"content": {
216+
"application/json": {
217+
"schema": {
218+
"type": "object",
219+
"properties": {
220+
"resultType": { "type": "string", "example": "FAIL" },
221+
"error": {
222+
"type": "object",
223+
"properties": {
224+
"errorCode": { "type": "string", "example": "C002" },
225+
"reason": { "type": "string", "example": "요청한 채팅방을 찾을 수 없습니다." },
226+
"data": { "type": "object", "example": { "chatroomIds": [999] } }
227+
}
228+
},
229+
"success": {
230+
"type": ["object", "null"],
231+
"example": null
232+
}
233+
}
234+
}
235+
}
236+
}
170237
}
171238
}
172239
}
173240
},
174241
"/api/chatrooms/{chatroomId}/messages": {
175242
"get": {
176243
"summary": "채팅방 메시지 조회",
177-
"description": "채팅방 ID를 기반으로 해당 채팅방의 메시지를 조회합니다. 무한 스크롤을 위해 cursor(이전 페이지 마지막 메시지 id)와 limit을 query로 받습니다.",
244+
"description": "해당 채팅방의 메시지를 조회합니다. 무한 스크롤을 위해 cursor(이전 페이지 마지막 메시지 id)와 limit을 query로 받습니다.",
245+
"security": [
246+
{
247+
"bearerAuth": []
248+
}
249+
],
178250
"tags": ["Chat"],
179251
"parameters": [
180252
{
@@ -277,10 +349,57 @@
277349
}
278350
},
279351
"404": {
280-
"description": "채팅방을 찾을 수 없음"
352+
"description": "채팅방을 찾을 수 없음",
353+
"content": {
354+
"application/json": {
355+
"schema": {
356+
"type": "object",
357+
"properties": {
358+
"resultType": { "type": "string", "example": "FAIL" },
359+
"error": {
360+
"type": "object",
361+
"properties": {
362+
"errorCode": { "type": "string", "example": "C002" },
363+
"reason": { "type": "string", "example": "요청한 채팅방을 찾을 수 없습니다." },
364+
"data": {
365+
"type": "object",
366+
"example": { "chatroomIds": [999] }
367+
}
368+
}
369+
},
370+
"success": {
371+
"type": ["object", "null"],
372+
"example": null
373+
}
374+
}
375+
}
376+
}
377+
}
281378
},
282379
"500": {
283-
"description": "서버 오류"
380+
"description": "서버 오류",
381+
"content": {
382+
"application/json": {
383+
"schema": {
384+
"type": "object",
385+
"properties": {
386+
"resultType": { "type": "string", "example": "FAIL" },
387+
"error": {
388+
"type": "object",
389+
"properties": {
390+
"errorCode": { "type": "string", "example": "S001" },
391+
"reason": { "type": "string", "example": "알 수 없는 서버 오류가 발생했습니다." },
392+
"data": { "type": "object", "example": {} }
393+
}
394+
},
395+
"success": {
396+
"type": ["object", "null"],
397+
"example": null
398+
}
399+
}
400+
}
401+
}
402+
}
284403
}
285404
}
286405
}
@@ -289,6 +408,11 @@
289408
"get": {
290409
"summary": "메시지 키워드 검색",
291410
"description": "키워드가 포함된 메시지를 검색하여 반환합니다.",
411+
"security": [
412+
{
413+
"bearerAuth": []
414+
}
415+
],
292416
"tags": ["Chat"],
293417
"parameters": [
294418
{
@@ -361,10 +485,54 @@
361485
}
362486
},
363487
"400": {
364-
"description": "잘못된 요청"
488+
"description": "잘못된 요청",
489+
"content": {
490+
"application/json": {
491+
"schema": {
492+
"type": "object",
493+
"properties": {
494+
"resultType": { "type": "string", "example": "FAIL" },
495+
"error": {
496+
"type": "object",
497+
"properties": {
498+
"errorCode": { "type": "string", "example": "R001" },
499+
"reason": { "type": "string", "example": "keyword 쿼리 파라미터는 필수입니다." },
500+
"data": { "type": "object", "example": {} }
501+
}
502+
},
503+
"success": {
504+
"type": ["object", "null"],
505+
"example": null
506+
}
507+
}
508+
}
509+
}
510+
}
365511
},
366512
"500": {
367-
"description": "서버 오류"
513+
"description": "서버 오류",
514+
"content": {
515+
"application/json": {
516+
"schema": {
517+
"type": "object",
518+
"properties": {
519+
"resultType": { "type": "string", "example": "FAIL" },
520+
"error": {
521+
"type": "object",
522+
"properties": {
523+
"errorCode": { "type": "string", "example": "S001" },
524+
"reason": { "type": "string", "example": "알 수 없는 서버 오류가 발생했습니다." },
525+
"data": { "type": "object", "example": {} }
526+
}
527+
},
528+
"success": {
529+
"type": ["object", "null"],
530+
"example": null
531+
}
532+
}
533+
}
534+
}
535+
}
368536
}
369537
}
370538
}

0 commit comments

Comments
 (0)