diff --git a/src/main/java/org/programmers/signalbuddy/domain/comment/repository/CommentRepository.java b/src/main/java/org/programmers/signalbuddy/domain/comment/repository/CommentRepository.java index e5ca1a06..6a992a68 100644 --- a/src/main/java/org/programmers/signalbuddy/domain/comment/repository/CommentRepository.java +++ b/src/main/java/org/programmers/signalbuddy/domain/comment/repository/CommentRepository.java @@ -2,9 +2,15 @@ import org.programmers.signalbuddy.domain.comment.entity.Comment; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository public interface CommentRepository extends JpaRepository, CustomCommentRepository { + @Modifying + @Query("DELETE FROM comments c WHERE c.feedback.feedbackId = :feedbackId") + void deleteAllByFeedbackId(@Param("feedbackId") Long feedbackId); } diff --git a/src/main/java/org/programmers/signalbuddy/domain/feedback/service/FeedbackService.java b/src/main/java/org/programmers/signalbuddy/domain/feedback/service/FeedbackService.java index f9eae0ee..a54844c7 100644 --- a/src/main/java/org/programmers/signalbuddy/domain/feedback/service/FeedbackService.java +++ b/src/main/java/org/programmers/signalbuddy/domain/feedback/service/FeedbackService.java @@ -2,6 +2,7 @@ import java.time.LocalDate; import lombok.RequiredArgsConstructor; +import org.programmers.signalbuddy.domain.comment.repository.CommentRepository; import org.programmers.signalbuddy.domain.feedback.dto.FeedbackMapper; import org.programmers.signalbuddy.domain.feedback.dto.FeedbackResponse; import org.programmers.signalbuddy.domain.feedback.dto.FeedbackWriteRequest; @@ -28,6 +29,7 @@ public class FeedbackService { private final FeedbackRepository feedbackRepository; private final MemberRepository memberRepository; private final FeedbackJdbcRepository feedbackJdbcRepository; + private final CommentRepository commentRepository; public PageResponse searchFeedbackList(Pageable pageable, Long answerStatus) { Page responsePage = feedbackRepository.findAllByActiveMembers(pageable, @@ -92,6 +94,7 @@ public void deleteFeedback(Long feedbackId, User user) { throw new BusinessException(FeedbackErrorCode.FEEDBACK_ELIMINATOR_NOT_AUTHORIZED); } + commentRepository.deleteAllByFeedbackId(feedbackId); feedbackRepository.deleteById(feedbackId); } diff --git a/src/main/resources/static/css/feedback/info.css b/src/main/resources/static/css/feedback/info.css index 21ce584b..5ec996c0 100644 --- a/src/main/resources/static/css/feedback/info.css +++ b/src/main/resources/static/css/feedback/info.css @@ -601,4 +601,15 @@ video { #menu-box { display: none; +} + +.hidden { + display: none; +} + +.comment-edit-textarea { + width: 100%; + height: 100px; + padding: 8px; + margin-top: 8px; } \ No newline at end of file diff --git a/src/main/resources/templates/feedback/info.html b/src/main/resources/templates/feedback/info.html index d41e7c94..bd2a2d5e 100644 --- a/src/main/resources/templates/feedback/info.html +++ b/src/main/resources/templates/feedback/info.html @@ -79,7 +79,9 @@

-
+
@@ -87,18 +89,40 @@

-

+ + +

이건인정;;;;;;;;;;;;;;;;;;;;;;;;

+ + + + @@ -109,9 +133,11 @@

-
@@ -125,6 +151,10 @@

{ event.stopPropagation(); @@ -144,7 +174,7 @@

{ const feedbackId = menu.getAttribute('data-feedback-id'); @@ -167,4 +197,118 @@

{ + const feedbackId = menu.getAttribute('data-feedback-id'); + const comment = document.getElementById("comment-write-box").value; + + fetch(`/api/comments/write`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + 'feedbackId': feedbackId, + 'content': comment + }) + }) + .then(response => { + if (response.ok) { + window.location.href = location.href; // 페이지 새로고침 + } else { + alert('댓글 작성에 실패했습니다.'); + response.json() + .then(data => console.log(data.message)); + } + }) + .catch(error => { + console.error('댓글 작성 요청 중 오류 발생:', error); + }); + }); + + // 댓글 삭제 요청 + function deleteComment(commentId) { + fetch(`/api/comments/${commentId}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + } + }) + .then(response => { + if (response.ok) { + window.location.href = location.href; // 페이지 새로고침 + } else { + alert('삭제에 실패했습니다.'); + response.json() + .then(data => console.log(data.message)); + } + }) + .catch(error => { + console.error('삭제 요청 중 오류 발생:', error); + }); + } + + // 댓글 수정 박스 보이게 하기 + function showEditBox(commentId) { + const commentContent = document.getElementById('comment-content-' + commentId); + const commentTextarea = document.getElementById('comment-edit-textarea-' + commentId); + const cancelButton = document.getElementById('comment-edit-cancel-btn-' + commentId); + const completeButton = document.getElementById('comment-edit-complete-btn-' + commentId); + + // 댓글을 textarea로 변환 + commentContent.classList.add('hidden'); // 기존 댓글 텍스트 숨기기 + commentTextarea.classList.remove('hidden'); // textarea 보이기 + cancelButton.classList.remove('hidden'); // 취소 버튼 보이기 + completeButton.classList.remove('hidden'); // 완료 버튼 보이기 + } + + // 댓글 수정 박스 숨기기 + function hideEditBox(commentId) { + const commentContent = document.getElementById('comment-content-' + commentId); + const commentTextarea = document.getElementById('comment-edit-textarea-' + commentId); + const cancelButton = document.getElementById('comment-edit-cancel-btn-' + commentId); + const completeButton = document.getElementById('comment-edit-complete-btn-' + commentId); + + // 댓글을 p로 변환 + commentContent.classList.remove('hidden'); // 기존 댓글 텍스트 보이기 + commentTextarea.classList.add('hidden'); // textarea 숨기기 + cancelButton.classList.add('hidden'); // 취소 버튼 숨기기 + completeButton.classList.add('hidden'); // 완료 버튼 숨기기 + } + + // 댓글 수정 요청 + function editComment(commentId) { + const feedbackId = menu.getAttribute('data-feedback-id'); + const commentEditBox = document.getElementById('comment-edit-textarea-' + commentId); + const commentContent = document.getElementById('comment-content-' + commentId); + + const updatedComment = commentEditBox.value; + + fetch(`/api/comments/${commentId}`, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + 'feedbackId': feedbackId, + 'content': updatedComment + }) + }) + .then(response => { + if (response.ok) { + // 서버 응답 후 댓글 내용 업데이트 + commentContent.innerText = updatedComment; + + hideEditBox(commentId); + } else { + alert('댓글 수정에 실패했습니다.'); + response.json() + .then(data => console.log(data.message)); + } + }) + .catch(error => { + console.error('댓글 수정 요청 중 오류 발생:', error); + }); + } \ No newline at end of file