From 4e8bb9b7f630400185967f650fc9259dbb1b3219 Mon Sep 17 00:00:00 2001 From: bkw535 Date: Mon, 18 Aug 2025 21:34:33 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[REFACTOR]=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8D=B8=EB=84=A4=EC=9D=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/dto/chatroom.dto.js | 1 + src/chat/service/chatroom.service.js | 15 +++++-- src/commission/service/commission.service.js | 45 +++++++++----------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/chat/dto/chatroom.dto.js b/src/chat/dto/chatroom.dto.js index 383a96f..64584e6 100644 --- a/src/chat/dto/chatroom.dto.js +++ b/src/chat/dto/chatroom.dto.js @@ -21,6 +21,7 @@ export class ChatroomListResponseDto { this.artist_profile_image = room.artist.profileImage; this.commission_id = room.commission.id; this.commission_title = room.commission.title; + this.commission_thumbnail = room.commission.thumbnail || null; // 이미지가 있으면 이미지 URL, 없으면 텍스트 content const lastMsg = room.chatMessages[0]; this.last_message = lastMsg?.imageUrl || lastMsg?.content || null; diff --git a/src/chat/service/chatroom.service.js b/src/chat/service/chatroom.service.js index b4480bb..ef8e260 100644 --- a/src/chat/service/chatroom.service.js +++ b/src/chat/service/chatroom.service.js @@ -49,16 +49,23 @@ export const ChatroomService = { async getChatroomsByUserId(dto) { const user = await UserRepository.findUserById(dto.userId); - if (!user) { - throw new UserNotFoundError({ userId: dto.userId }); - } + if (!user) throw new UserNotFoundError({ userId: dto.userId }); const chatrooms = await ChatroomRepository.findChatroomsByUser(dto.userId); - console.log(dto.accountId) + // thumbnail 한 번에 조회 + const commissionIds = chatrooms.map(r => r.commission.id); + const images = await CommissionRepository.findImagesByCommissionId(commissionIds); + const thumbnailMap = Object.fromEntries(images.map(img => [img.targetId.toString(), img.imageUrl])); + + // DTO 생성 const result = []; for (const room of chatrooms) { + room.commission.thumbnail = thumbnailMap[room.commission.id.toString()] || null; + + // 방마다 unreadCount 조회 const unreadCount = await ChatRepository.countUnreadMessages(room.id, dto.accountId); + result.push(new ChatroomListResponseDto(room, unreadCount)); } diff --git a/src/commission/service/commission.service.js b/src/commission/service/commission.service.js index 8a64840..88f9337 100644 --- a/src/commission/service/commission.service.js +++ b/src/commission/service/commission.service.js @@ -56,35 +56,30 @@ export const CommissionService = { * S3 이미지 업로드 처리 */ async uploadRequestImage(file) { - try { - // 1. 파일 존재 여부 확인 - if (!file) { - throw new ImageUploadFailedError({ reason: '파일이 업로드되지 않았습니다' }); - } - - // 2. 파일 크기 검증 - if (file.size > 10 * 1024 * 1024) { - throw new FileSizeExceededError({ fileSize: file.size }); - } + // 1. 파일 존재 여부 확인 + if (!file) { + throw new ImageUploadFailedError({ reason: '파일이 업로드되지 않았습니다' }); + } - // 3. 파일 확장자 검증 - const ext = path.extname(file.originalname).toLowerCase().replace('.', ''); - if (!['jpeg', 'jpg', 'png'].includes(ext)) { - throw new UnsupportedImageFormatError({ fileType: file.mimetype }); - } + // 2. 파일 크기 검증 + if (file.size > 10 * 1024 * 1024) { + throw new FileSizeExceededError({ fileSize: file.size }); + } - // 4. S3 업로드 (requests 폴더에 저장) - const imageUrl = await uploadToS3(file.buffer, 'requests', ext); + // 3. 파일 확장자 검증 + const ext = path.extname(file.originalname).toLowerCase().replace('.', ''); + if (!['jpeg', 'jpg', 'png'].includes(ext)) { + throw new UnsupportedImageFormatError({ fileType: file.mimetype }); + } - return { - image_url: imageUrl, - file_size: file.size, - file_type: file.mimetype - }; + // 4. S3 업로드 + const imageUrl = await uploadToS3(file.buffer, 'requests', ext); - } catch (error) { - throw error; - } + return { + image_url: imageUrl, + file_size: file.size, + file_type: file.mimetype + }; }, /** From 0d7220d6ccaf1240f984a320d6482c7c83d00abb Mon Sep 17 00:00:00 2001 From: bkw535 Date: Mon, 18 Aug 2025 21:36:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[REFACTOR]=20swagger=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/swagger/chat.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/swagger/chat.json b/src/common/swagger/chat.json index 0ecc87b..9e237e1 100644 --- a/src/common/swagger/chat.json +++ b/src/common/swagger/chat.json @@ -115,6 +115,7 @@ "artist_profile_image": { "type": "string", "example": "https://example.com/artist1.png" }, "commission_id": { "type": "string", "example": "1" }, "commission_title": { "type": "string", "example": "테스트 커미션 글" }, + "commission_thumbnail": { "type": ["string", "null"], "example": "https://example.com/sample-thumbnail.png" }, "last_message": { "type": ["string", "null"], "example": null }, "last_message_time": { "type": ["string", "null"], "format": "date-time", "example": null }, "has_unread": { "type": "integer", "example": 0 }