diff --git a/src/main/java/com/example/dplus/controller/post/PostMainController.java b/src/main/java/com/example/dplus/controller/post/PostMainController.java index 81773d88..a686e61f 100644 --- a/src/main/java/com/example/dplus/controller/post/PostMainController.java +++ b/src/main/java/com/example/dplus/controller/post/PostMainController.java @@ -93,10 +93,9 @@ public ResponseEntity updatePost(@AuthenticationPrincipal UserDetailsIm @DeleteMapping("/{post_id}") public ResponseEntity deletePost(@AuthenticationPrincipal UserDetailsImpl user, @PathVariable Long post_id, - @RequestParam("category") String category, @RequestParam("board") String board) { if (user != null) { - postMainPageService.deletePost(user.getUser().getId(), post_id, category, board); + postMainPageService.deletePost(user.getUser().getId(), post_id, board); return new ResponseEntity<>(new Success("디플 게시물 삭제", ""), HttpStatus.OK); } throw new ErrorCustomException(ErrorCode.NO_AUTHENTICATION_ERROR); diff --git a/src/main/java/com/example/dplus/domain/artwork/ArtWorks.java b/src/main/java/com/example/dplus/domain/artwork/ArtWorks.java index 0ba02fd6..9de32d28 100644 --- a/src/main/java/com/example/dplus/domain/artwork/ArtWorks.java +++ b/src/main/java/com/example/dplus/domain/artwork/ArtWorks.java @@ -122,7 +122,7 @@ public static ArtWorks of(Account account, ArtWorkCreate dto) { .title(dto.getTitle()) .workStart(dto.getWork_start()) .workEnd(dto.getWork_end()) - .isMaster(dto.getMaster()) + .isMaster(dto.getIs_master()) .specialty(dto.getSpecialty()) .copyright(dto.getCopyright()) .thumbnail(dto.getThumbnail()) diff --git a/src/main/java/com/example/dplus/repository/post/answer/PostAnswerRepository.java b/src/main/java/com/example/dplus/repository/post/answer/PostAnswerRepository.java index 3f6c0665..c8a1474d 100644 --- a/src/main/java/com/example/dplus/repository/post/answer/PostAnswerRepository.java +++ b/src/main/java/com/example/dplus/repository/post/answer/PostAnswerRepository.java @@ -3,6 +3,10 @@ import com.example.dplus.domain.post.PostAnswer; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface PostAnswerRepository extends JpaRepository, PostAnswerRepositoryCustom { Long countByPostId(Long postId); + void deleteAllByPostId(Long postId); + List findAllByPostId(Long postId); } diff --git a/src/main/java/com/example/dplus/repository/post/comment/PostCommentRepository.java b/src/main/java/com/example/dplus/repository/post/comment/PostCommentRepository.java index f0d37da5..0e28a8c6 100644 --- a/src/main/java/com/example/dplus/repository/post/comment/PostCommentRepository.java +++ b/src/main/java/com/example/dplus/repository/post/comment/PostCommentRepository.java @@ -3,7 +3,10 @@ import com.example.dplus.domain.post.PostComment; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface PostCommentRepository extends JpaRepository, PostCommentRepositoryCustom { Long countByPostId(Long postId); void deleteAllByPostId(Long postId); + List findAllByPostId(Long postId); } diff --git a/src/main/java/com/example/dplus/repository/post/like/PostAnswerLikesRepository.java b/src/main/java/com/example/dplus/repository/post/like/PostAnswerLikesRepository.java index 2ecf973a..bc523998 100644 --- a/src/main/java/com/example/dplus/repository/post/like/PostAnswerLikesRepository.java +++ b/src/main/java/com/example/dplus/repository/post/like/PostAnswerLikesRepository.java @@ -5,4 +5,5 @@ public interface PostAnswerLikesRepository extends JpaRepository, PostAnswerLikesRepositoryCustom { void deleteByPostAnswerIdAndAccountId(Long postAnswerId, Long accountId ); + void deleteAllByPostAnswerId(Long postAnswerId); } diff --git a/src/main/java/com/example/dplus/service/post/PostMainPageService.java b/src/main/java/com/example/dplus/service/post/PostMainPageService.java index e2d3d37b..597acc78 100644 --- a/src/main/java/com/example/dplus/service/post/PostMainPageService.java +++ b/src/main/java/com/example/dplus/service/post/PostMainPageService.java @@ -33,7 +33,7 @@ public interface PostMainPageService { Long updatePost(Long accountId, Long postId, PostRequestDto.PostUpdate dto, List imgFile); // 게시글 삭제 - void deletePost(Long accountId, Long postId, String category, String board); + void deletePost(Long accountId, Long postId, String board); // 상세 질문글 PostResponseDto.PostAnswerDetailPage detailAnswer(Long accountId, Long postId); diff --git a/src/main/java/com/example/dplus/service/post/PostMainPageServiceImpl.java b/src/main/java/com/example/dplus/service/post/PostMainPageServiceImpl.java index 75ef3c17..e32d4924 100644 --- a/src/main/java/com/example/dplus/service/post/PostMainPageServiceImpl.java +++ b/src/main/java/com/example/dplus/service/post/PostMainPageServiceImpl.java @@ -143,15 +143,31 @@ public Long updatePost(Long accountId, Long postId, PostUpdate dto, List postImages = postImageRepository.findByPostId(postId); postImages.forEach((img) -> { + // S3 이미지 삭제 fileProcessService.deleteImage(img.getPostImg()); }); - postImageRepository.deleteAllByPostId(postId); - postBookMarkRepository.deleteAllByPostId(postId); - postRepository.delete(post); + if (board.equals("QNA")){ + List postAnswerList = postAnswerRepository.findAllByPostId(postId); + postAnswerList.forEach((postAnswer) -> + postAnswerLikesRepository.deleteAllByPostAnswerId(postAnswer.getId()) + ); + postAnswerRepository.deleteAllByPostId(postId); + postImageRepository.deleteAllByPostId(postId); + postBookMarkRepository.deleteAllByPostId(postId); + postRepository.delete(post); + } else { + List postCommentList = postCommentRepository.findAllByPostId(postId); + postCommentList.forEach((postComment) -> + postCommentLikesRepository.deleteAllByPostCommentId(postComment.getId()) + ); + postImageRepository.deleteAllByPostId(postId); + postBookMarkRepository.deleteAllByPostId(postId); + postRepository.delete(post); + } } // 게시글 검색