From 299e59921db2c553dba3a73ef18fdc9ac6e9873a Mon Sep 17 00:00:00 2001 From: AungKyawMyint <52407468+AungKyaw-Myint@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:37:52 -0500 Subject: [PATCH] bug fix --- .../repository/DiscussionCommentsRepository.java | 16 +++++++++++++++- .../service/DiscussionCommentsService.java | 5 ++++- .../waa/project/service/SubCommentService.java | 2 +- .../impl/DiscussionCommentsServiceImpl.java | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/waa/project/repository/DiscussionCommentsRepository.java b/backend/src/main/java/com/waa/project/repository/DiscussionCommentsRepository.java index 7dcbc80c..28d7946e 100644 --- a/backend/src/main/java/com/waa/project/repository/DiscussionCommentsRepository.java +++ b/backend/src/main/java/com/waa/project/repository/DiscussionCommentsRepository.java @@ -4,9 +4,12 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; 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; +import java.util.List; import java.util.Optional; @Repository @@ -23,4 +26,15 @@ public interface DiscussionCommentsRepository extends JpaRepository findByParentCommentId(Long parentCommentId, Pageable pageable); -} + + void deleteAllByParentCommentId(DiscussionComments id); + + List findAllByDiscussionId(Long discussionId); + + @Modifying + @Query("DELETE FROM DiscussionComments dc WHERE dc.parentCommentId.id IN :parentCommentIds") + void deleteAllByParentCommentIds(@Param("parentCommentIds") List parentCommentIds); + + void deleteByDiscussionId(Long discussionId); + +} \ No newline at end of file diff --git a/backend/src/main/java/com/waa/project/service/DiscussionCommentsService.java b/backend/src/main/java/com/waa/project/service/DiscussionCommentsService.java index a437a0c5..6c36e0f7 100644 --- a/backend/src/main/java/com/waa/project/service/DiscussionCommentsService.java +++ b/backend/src/main/java/com/waa/project/service/DiscussionCommentsService.java @@ -1,6 +1,7 @@ package com.waa.project.service; import com.waa.project.dto.DiscussionCommentsDto; +import com.waa.project.entity.Discussion; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.security.core.userdetails.User; @@ -16,4 +17,6 @@ public interface DiscussionCommentsService { DiscussionCommentsDto updateDiscussionComments(long id, DiscussionCommentsDto commentsDto, User user); DiscussionCommentsDto deleteDiscussionComments(long id, User user); -} + + void deleteAllCommentsByDiscussionId(Discussion discussion); +} \ No newline at end of file diff --git a/backend/src/main/java/com/waa/project/service/SubCommentService.java b/backend/src/main/java/com/waa/project/service/SubCommentService.java index 58aab855..ea0edd31 100644 --- a/backend/src/main/java/com/waa/project/service/SubCommentService.java +++ b/backend/src/main/java/com/waa/project/service/SubCommentService.java @@ -14,4 +14,4 @@ public interface SubCommentService { DiscussionCommentsDto updateSubDiscussionComments(long id, DiscussionCommentsDto commentsDto, User user); DiscussionCommentsDto deleteSubDiscussionComments(long id, User user); -} +} \ No newline at end of file diff --git a/backend/src/main/java/com/waa/project/service/impl/DiscussionCommentsServiceImpl.java b/backend/src/main/java/com/waa/project/service/impl/DiscussionCommentsServiceImpl.java index f55cd1b0..faba2ab8 100644 --- a/backend/src/main/java/com/waa/project/service/impl/DiscussionCommentsServiceImpl.java +++ b/backend/src/main/java/com/waa/project/service/impl/DiscussionCommentsServiceImpl.java @@ -108,4 +108,4 @@ private Long getUserId(User user) { AuthUserResponse userData = userService.findByUsername(user.getUsername()); return userData.getId(); } -} +} \ No newline at end of file