게시글 삭제 수정

This commit is contained in:
nevermoregb 2025-03-11 10:38:12 +09:00
parent c90220785c
commit 93f6d1f3b9

View File

@ -157,7 +157,7 @@
const toastStore = useToastStore(); const toastStore = useToastStore();
const currentBoardId = ref(Number(route.params.id)); const currentBoardId = ref(Number(route.params.id));
const unknown = computed(() => profileName.value === '익명'); const unknown = computed(() => profileName.value === '익명');
const currentUserId = computed(() => userStore.user.id); // id const currentUserId = computed(() => userStore?.user?.id); // id
const authorId = ref(''); // id const authorId = ref(''); // id
const isAuthor = computed(() => currentUserId.value === authorId.value); const isAuthor = computed(() => currentUserId.value === authorId.value);
@ -233,24 +233,20 @@
}; };
// //
const fetchBoardDetails = async () => { const fetchBoardDetails = async () => {
try { const response = await axios.get(`board/${currentBoardId.value}`);
const response = await axios.get(`board/${currentBoardId.value}`); const data = response.data.data;
const data = response.data.data;
profileName.value = data.author || '익명'; profileName.value = data.author || '익명';
authorId.value = data.authorId; authorId.value = data.authorId;
boardTitle.value = data.title || '제목 없음'; boardTitle.value = data.title || '제목 없음';
boardContent.value = data.content || ''; boardContent.value = data.content || '';
date.value = data.date || ''; date.value = data.date || '';
views.value = data.cnt || 0; views.value = data.cnt || 0;
likes.value = data.likeCount || 0; likes.value = data.likeCount || 0;
dislikes.value = data.dislikeCount || 0; dislikes.value = data.dislikeCount || 0;
attachment.value = data.hasAttachment || null; attachment.value = data.hasAttachment || null;
commentNum.value = data.commentCount || 0; commentNum.value = data.commentCount || 0;
attachments.value = data.attachments || []; attachments.value = data.attachments || [];
} catch (error) {
alert('게시물 데이터를 불러오는 중 오류가 발생했습니다.');
}
}; };
// , // ,
@ -280,97 +276,89 @@
const handleCommentReaction = async ({ boardId, commentId, isLike, isDislike }) => { const handleCommentReaction = async ({ boardId, commentId, isLike, isDislike }) => {
if (!commentId) return; // ID if (!commentId) return; // ID
try { const response = await axios.post(`/board/${boardId}/${commentId}/reaction`, {
const response = await axios.post(`/board/${boardId}/${commentId}/reaction`, { LOCBRDSEQ: boardId, // ID
LOCBRDSEQ: boardId, // ID LOCCMTSEQ: commentId, // ID
LOCCMTSEQ: commentId, // ID LOCGOBGOD: isLike ? 'T' : 'F',
LOCGOBGOD: isLike ? 'T' : 'F', LOCGOBBAD: isDislike ? 'T' : 'F',
LOCGOBBAD: isDislike ? 'T' : 'F', });
});
await fetchComments(); await fetchComments();
} catch (error) {
alert('오류가 발생했습니다.');
}
}; };
// //
const fetchComments = async (page = 1) => { const fetchComments = async (page = 1) => {
try { //
// const response = await axios.get(`board/${currentBoardId.value}/comments`, {
const response = await axios.get(`board/${currentBoardId.value}/comments`, { params: {
params: { LOCBRDSEQ: currentBoardId.value,
LOCBRDSEQ: currentBoardId.value, page,
page, },
}, });
const commentsList = response.data.data.list.map(comment => ({
commentId: comment.LOCCMTSEQ, // ID
boardId: comment.LOCBRDSEQ,
parentId: comment.LOCCMTPNT, // ID
author: comment.author || '익명',
authorId: comment.authorId,
content: comment.LOCCMTRPY,
likeCount: comment.likeCount || 0,
dislikeCount: comment.dislikeCount || 0,
likeClicked: comment.likeClicked || false,
dislikeClicked: comment.dislikeClicked || false,
createdAtRaw: new Date(comment.LOCCMTRDT), //
createdAt: formattedDate(comment.LOCCMTRDT), //
children: [], //
updateAtRaw: comment.LOCCMTUDT,
}));
commentsList.sort((a, b) => b.createdAtRaw - a.createdAtRaw);
for (const comment of commentsList) {
if (!comment.commentId) continue;
const replyResponse = await axios.get(`board/${currentBoardId.value}/reply`, {
params: { LOCCMTPNT: comment.commentId },
}); });
const commentsList = response.data.data.list.map(comment => ({
commentId: comment.LOCCMTSEQ, // ID
boardId: comment.LOCBRDSEQ,
parentId: comment.LOCCMTPNT, // ID
author: comment.author || '익명',
authorId: comment.authorId,
content: comment.LOCCMTRPY,
likeCount: comment.likeCount || 0,
dislikeCount: comment.dislikeCount || 0,
likeClicked: comment.likeClicked || false,
dislikeClicked: comment.dislikeClicked || false,
createdAtRaw: new Date(comment.LOCCMTRDT), //
createdAt: formattedDate(comment.LOCCMTRDT), //
children: [], //
updateAtRaw: comment.LOCCMTUDT,
}));
commentsList.sort((a, b) => b.createdAtRaw - a.createdAtRaw); if (replyResponse.data.data) {
comment.children = replyResponse.data.data.map(reply => ({
for (const comment of commentsList) { author: reply.author || '익명',
if (!comment.commentId) continue; authorId: reply.authorId,
commentId: reply.LOCCMTSEQ,
const replyResponse = await axios.get(`board/${currentBoardId.value}/reply`, { boardId: reply.LOCBRDSEQ,
params: { LOCCMTPNT: comment.commentId }, parentId: reply.LOCCMTPNT, // ID
}); content: reply.LOCCMTRPY || '내용 없음',
createdAtRaw: new Date(reply.LOCCMTRDT),
if (replyResponse.data.data) { createdAt: formattedDate(reply.LOCCMTRDT),
comment.children = replyResponse.data.data.map(reply => ({ likeCount: reply.likeCount || 0,
author: reply.author || '익명', dislikeCount: reply.dislikeCount || 0,
authorId: reply.authorId, likeClicked: false,
commentId: reply.LOCCMTSEQ, dislikeClicked: false,
boardId: reply.LOCBRDSEQ, }));
parentId: reply.LOCCMTPNT, // ID } else {
content: reply.LOCCMTRPY || '내용 없음', comment.children = []; //
createdAtRaw: new Date(reply.LOCCMTRDT),
createdAt: formattedDate(reply.LOCCMTRDT),
likeCount: reply.likeCount || 0,
dislikeCount: reply.dislikeCount || 0,
likeClicked: false,
dislikeClicked: false,
}));
} else {
comment.children = []; //
}
} }
//
comments.value = commentsList;
pagination.value = {
...pagination.value,
currentPage: response.data.data.pageNum, //
pages: response.data.data.pages, //
prePage: response.data.data.prePage, //
nextPage: response.data.data.nextPage, //
isFirstPage: response.data.data.isFirstPage, //
isLastPage: response.data.data.isLastPage, //
hasPreviousPage: response.data.data.hasPreviousPage, //
hasNextPage: response.data.data.hasNextPage, //
navigatePages: response.data.data.navigatePages, //
navigatepageNums: response.data.data.navigatepageNums, //
navigateFirstPage: response.data.data.navigateFirstPage, //
navigateLastPage: response.data.data.navigateLastPage, //
};
} catch (error) {
alert('오류가 발생했습니다.');
} }
//
comments.value = commentsList;
pagination.value = {
...pagination.value,
currentPage: response.data.data.pageNum, //
pages: response.data.data.pages, //
prePage: response.data.data.prePage, //
nextPage: response.data.data.nextPage, //
isFirstPage: response.data.data.isFirstPage, //
isLastPage: response.data.data.isLastPage, //
hasPreviousPage: response.data.data.hasPreviousPage, //
hasNextPage: response.data.data.hasNextPage, //
navigatePages: response.data.data.navigatePages, //
navigatepageNums: response.data.data.navigatepageNums, //
navigateFirstPage: response.data.data.navigateFirstPage, //
navigateLastPage: response.data.data.navigateLastPage, //
};
}; };
// //
@ -453,7 +441,7 @@
// //
const deleteClick = unknown => { const deleteClick = unknown => {
if (unknown) { if (unknown.value) {
togglePassword('delete'); togglePassword('delete');
} else { } else {
deletePost(); deletePost();