Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ public ResponseEntity<Success> updatePost(@AuthenticationPrincipal UserDetailsIm
@DeleteMapping("/{post_id}")
public ResponseEntity<Success> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostAnswer, Long>, PostAnswerRepositoryCustom {
Long countByPostId(Long postId);
void deleteAllByPostId(Long postId);
List<PostAnswer> findAllByPostId(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostComment, Long>, PostCommentRepositoryCustom {
Long countByPostId(Long postId);
void deleteAllByPostId(Long postId);
List<PostComment> findAllByPostId(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

public interface PostAnswerLikesRepository extends JpaRepository<PostAnswerLikes, Long>, PostAnswerLikesRepositoryCustom {
void deleteByPostAnswerIdAndAccountId(Long postAnswerId, Long accountId );
void deleteAllByPostAnswerId(Long postAnswerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface PostMainPageService {
Long updatePost(Long accountId, Long postId, PostRequestDto.PostUpdate dto, List<MultipartFile> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,31 @@ public Long updatePost(Long accountId, Long postId, PostUpdate dto, List<Multipa

// 게시글 삭제
@Transactional
public void deletePost(Long accountId, Long postId, String category, String board){
public void deletePost(Long accountId, Long postId, String board){
Post post = postAuthValidation(accountId, postId);
List<PostImage> 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<com.example.dplus.domain.post.PostAnswer> 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<com.example.dplus.domain.post.PostComment> postCommentList = postCommentRepository.findAllByPostId(postId);
postCommentList.forEach((postComment) ->
postCommentLikesRepository.deleteAllByPostCommentId(postComment.getId())
);
postImageRepository.deleteAllByPostId(postId);
postBookMarkRepository.deleteAllByPostId(postId);
postRepository.delete(post);
}
}

// 게시글 검색
Expand Down