diff --git a/src/main/java/com/beotkkot/qtudy/repository/quiz/QuizRepository.java b/src/main/java/com/beotkkot/qtudy/repository/quiz/QuizRepository.java index 5cf133f..7142e67 100644 --- a/src/main/java/com/beotkkot/qtudy/repository/quiz/QuizRepository.java +++ b/src/main/java/com/beotkkot/qtudy/repository/quiz/QuizRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -17,4 +18,6 @@ public interface QuizRepository extends JpaRepository { @Query("SELECT q FROM Quiz q WHERE q.tags LIKE %:tagName% ORDER BY q.quizId ASC, RAND() LIMIT 10") List findByTagName(@Param("tagName") String tagName); + @Transactional + void deleteByPostId(Long postId); } diff --git a/src/main/java/com/beotkkot/qtudy/repository/quiz/ReviewRepository.java b/src/main/java/com/beotkkot/qtudy/repository/quiz/ReviewRepository.java index 5901e8c..0595f6f 100644 --- a/src/main/java/com/beotkkot/qtudy/repository/quiz/ReviewRepository.java +++ b/src/main/java/com/beotkkot/qtudy/repository/quiz/ReviewRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -29,4 +30,7 @@ public interface ReviewRepository extends JpaRepository { @Query("SELECT r FROM Review r " + "WHERE r.reviewId = :reviewId") List findReviewByReviewId(@Param("reviewId") String reviewId); + + @Transactional + void deleteByPostId(Long postId); } diff --git a/src/main/java/com/beotkkot/qtudy/service/posts/PostsService.java b/src/main/java/com/beotkkot/qtudy/service/posts/PostsService.java index 26bcda4..9d21497 100644 --- a/src/main/java/com/beotkkot/qtudy/service/posts/PostsService.java +++ b/src/main/java/com/beotkkot/qtudy/service/posts/PostsService.java @@ -10,6 +10,8 @@ import com.beotkkot.qtudy.dto.response.posts.*; import com.beotkkot.qtudy.repository.comments.CommentsRepository; import com.beotkkot.qtudy.repository.posts.PostsRepository; +import com.beotkkot.qtudy.repository.quiz.QuizRepository; +import com.beotkkot.qtudy.repository.quiz.ReviewRepository; import com.beotkkot.qtudy.repository.scrap.ScrapRepository; import com.beotkkot.qtudy.repository.tags.TagsRepository; import com.beotkkot.qtudy.repository.user.UserRepository; @@ -36,6 +38,9 @@ public class PostsService { private final ScrapRepository scrapRepo; private final SummaryService summaryService; private final CommentsRepository commentsRepo; + private final ReviewRepository reviewRepo; + private final QuizRepository quizRepo; + @Transactional public ResponseEntity savePost(Long kakao_uid, PostsRequestDto dto) { @@ -230,6 +235,8 @@ public ResponseEntity deletePost(Long postId, Long kak scrapRepo.deleteByPostId(postId); commentsRepo.deleteByPostId(postId); + reviewRepo.deleteByPostId(postId); + quizRepo.deleteByPostId(postId); // 관련된 hash tag -1 List tagNameList = Arrays.asList(post.getTag().split("\\s*,\\s*"));