diff --git a/src/components/board/BoardComment.vue b/src/components/board/BoardComment.vue index cede771..2bdc346 100644 --- a/src/components/board/BoardComment.vue +++ b/src/components/board/BoardComment.vue @@ -23,11 +23,12 @@
{{ comment.content }}
+ {{ comment.commentId }} diff --git a/src/views/board/BoardView.vue b/src/views/board/BoardView.vue index a643347..e52126b 100644 --- a/src/views/board/BoardView.vue +++ b/src/views/board/BoardView.vue @@ -223,42 +223,64 @@ const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) = // 댓글 목록 조회 const fetchComments = async (page = 1) => { try { - const response = await axios.get(`board/${currentBoardId.value}/comments`, { - params: { - LOCBRDSEQ: currentBoardId.value, - page - } + const { data } = await axios.get(`board/${currentBoardId.value}/comments`, { + params: { LOCBRDSEQ: currentBoardId.value, page } }); - console.log("목록 API 응답 데이터:", response.data); + const { data: replyData } = await axios.get(`board/${currentBoardId.value}/reply`, { + params: { LOCBRDSEQ: currentBoardId.value } + }); + console.log("댓글:", data); + console.log("대댓글:", replyData); - let allComments = response.data.data.list.map(comment => ({ - commentId: comment.LOCCMTSEQ, // 댓글 id + if (!data?.data?.list) return; + + comments.value = data.data.list.map(comment => ({ + commentId: comment.LOCCMTSEQ, // 댓글 ID boardId: comment.LOCBRDSEQ, - parentId: comment.LOCCMTPNT, // 부모 id - author: comment.author || "익명 사용자", // 작성자 - content: comment.LOCCMTRPY, // 댓글 내용 - createdAt: formattedDate(comment.LOCCMTRDT), // 생성 날짜 - children: [] + parentId: comment.LOCCMTPNT, // 부모 ID + author: comment.author || "익명 사용자", + content: comment.LOCCMTRPY, + createdAtRaw: new Date(comment.LOCCMTRDT), // 정렬용 + createdAt: formattedDate(comment.LOCCMTRDT), // 표시용 + children: [] // 대댓글을 담을 배열 })); - allComments.sort((a, b) => b.commentId - a.commentId); + let replies = replyData.data.map(reply => ({ + commentId: reply.LOCCMTSEQ, // 대댓글 ID + boardId: reply.LOCBRDSEQ, + parentId: reply.LOCCMTPNT, // 부모 댓글 ID + author: reply.author || "익명 사용자", + content: reply.LOCCMTRPY, + createdAtRaw: new Date(reply.LOCCMTRDT), // 정렬용 + createdAt: formattedDate(reply.LOCCMTRDT) // 표시용 + })); - let commentMap = {}; - let rootComments = []; + // let commentMap = {}; + // let rootComments = []; - allComments.forEach(comment => { - commentMap[comment.commentId] = comment; - }); + // 최상위 댓글 저장 + // allComments.forEach(comment => { + // commentMap[comment.commentId] = comment; + // }); - allComments.forEach(comment => { - if (comment.parentId && commentMap[comment.parentId]) { - commentMap[comment.parentId].children.push(comment); - } else { - rootComments.push(comment); - } - }); + // 대댓글을 부모 댓글에 추가 + // replies.forEach(reply => { + // if (commentMap[reply.parentId]) { + // commentMap[reply.parentId].children.push(reply); + // } else { + // console.warn("부모 댓글을 찾을 수 없는 대댓글:", reply); + // } + // }); - comments.value = rootComments; + // rootComments = allComments.filter(comment => comment.parentId === 1); + + // 정렬 + // rootComments.sort((a, b) => b.createdAtRaw - a.createdAtRaw); + // rootComments.forEach(comment => { + // comment.children.sort((a, b) => b.createdAtRaw - a.createdAtRaw); + // }); + + // comments.value = rootComments; // console.log("변환된 comments 데이터:", comments.value);