From 2ef920e220bbbb4a06988591037b3616b8189ab4 Mon Sep 17 00:00:00 2001 From: SeokGeunHo Date: Mon, 22 Sep 2025 16:13:12 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/post/controller/PostController.java | 14 ++++++++++++++ .../back/domain/post/post/service/PostService.java | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/com/back/domain/post/post/controller/PostController.java b/src/main/java/com/back/domain/post/post/controller/PostController.java index 270f5066..a7a44479 100644 --- a/src/main/java/com/back/domain/post/post/controller/PostController.java +++ b/src/main/java/com/back/domain/post/post/controller/PostController.java @@ -8,6 +8,7 @@ import jakarta.validation.Valid; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -69,4 +70,17 @@ public RsData updatePost( ) { return RsData.successOf(postService.updatePost(postId, reqBody)); // code=200, message="success" } + + /** + * 게시글 삭제 API + * @param postId 삭제할 게시글 ID + * @return 삭제 성공 메시지 + */ + @DeleteMapping("/{postId}") + public RsData deletePost( + @PathVariable Long postId + ) { + postService.deletePost(postId); + return RsData.successOf(null); // code=200, message="success" + } } diff --git a/src/main/java/com/back/domain/post/post/service/PostService.java b/src/main/java/com/back/domain/post/post/service/PostService.java index 6eedac05..7ec975d0 100644 --- a/src/main/java/com/back/domain/post/post/service/PostService.java +++ b/src/main/java/com/back/domain/post/post/service/PostService.java @@ -7,6 +7,7 @@ import com.back.domain.post.post.dto.response.PostResponseDto; import com.back.domain.post.post.entity.Post; import com.back.domain.post.post.entity.Tag; +import com.back.domain.post.post.enums.PostStatus; import com.back.domain.post.post.repository.PostRepository; import com.back.domain.post.post.repository.TagRepository; import com.back.domain.user.entity.User; @@ -107,6 +108,18 @@ public PostResponseDto updatePost(Long postId, PostUpdateRequestDto reqBody) { return new PostResponseDto(post); } + // 게시글 삭제 로직 + @Transactional + public void deletePost(Long postId) { + Post post = postRepository.findById(postId) + .orElseThrow(() -> new NoSuchElementException("해당 게시글을 찾을 수 없습니다. ID: " + postId)); + + post.updateStatus(PostStatus.DELETED); + + // soft delete를 사용하기 위해 레포지토리 삭제 작업은 진행하지 않음. +// postRepository.delete(post); + } + // 태그 추가 메서드 private void addTag(List tagNames, Post post) { for (String tagName : tagNames) {