File tree Expand file tree Collapse file tree 4 files changed +21
-4
lines changed
backend/src/main/java/com/ai/lawyer/domain Expand file tree Collapse file tree 4 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public interface PollService {
3737 PollDto updatePoll (Long pollId , PollUpdateDto pollUpdateDto , Long memberId );
3838 void patchUpdatePoll (Long pollId , PollUpdateDto pollUpdateDto );
3939 void closePoll (Long pollId );
40- void deletePoll (Long pollId , Long memberId );
40+ void deletePoll (Long pollId , Long memberId );
4141
4242 // ===== 검증 관련 =====
4343 void validatePollCreate (PollCreateDto dto );
Original file line number Diff line number Diff line change @@ -114,6 +114,15 @@ public ResponseEntity<ApiResponse<Void>> deletePost(@PathVariable Long postId) {
114114 return ResponseEntity .ok (new ApiResponse <>(200 , "게시글이 삭제되었습니다." , null ));
115115 }
116116
117+ @ Operation (summary = "게시글 삭제(관리자)" )
118+ @ DeleteMapping ("/admin/{postId}" )
119+ public ResponseEntity <ApiResponse <Void >> deletePostAdmin (@ PathVariable Long postId ) {
120+ //AuthUtil.validateAdmin(); 관리자
121+ AuthUtil .getAuthenticatedMemberId (); // 모든 유저
122+ postService .deletePostAdmin (postId );
123+ return ResponseEntity .ok (new ApiResponse <>(200 , "게시글이 삭제되었습니다." , null ));
124+ }
125+
117126 @ ExceptionHandler (ResponseStatusException .class )
118127 public ResponseEntity <ApiResponse <Void >> handleResponseStatusException (ResponseStatusException ex ) {
119128 int code = ex .getStatusCode ().value ();
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public interface PostService {
2626 PostDto updatePost (Long postId , PostUpdateDto postUpdateDto );
2727 void patchUpdatePost (Long postId , PostUpdateDto postUpdateDto );
2828 void deletePost (Long postId );
29+ void deletePostAdmin (Long postId );
2930 PostDetailDto createPostWithPoll (PostWithPollCreateDto dto , Long memberId );
3031
3132 // ===== 본인 게시글 관련 =====
Original file line number Diff line number Diff line change @@ -100,9 +100,9 @@ public PostDetailDto getPostById(Long postId) {
100100 public List <PostDto > getPostsByMemberId (Long memberId ) {
101101 Member member = AuthUtil .getMemberOrThrow (memberId );
102102 List <Post > posts = postRepository .findByMember (member );
103- if (posts .isEmpty ()) {
104- throw new ResponseStatusException (HttpStatus .NOT_FOUND , "해당 회원의 게시글이 없습니다." );
105- }
103+ // if (posts.isEmpty()) {
104+ // throw new ResponseStatusException(HttpStatus.NOT_FOUND, "해당 회원의 게시글이 없습니다.");
105+ // }
106106 return posts .stream ()
107107 .sorted (Comparator .comparing (Post ::getUpdatedAt , Comparator .nullsLast (Comparator .naturalOrder ())).reversed ()) // 최신순 정렬
108108 .map (post -> convertToDto (post , memberId ))
@@ -145,6 +145,13 @@ public void deletePost(Long postId) {
145145 postRepository .delete (post );
146146 }
147147
148+ @ Override
149+ public void deletePostAdmin (Long postId ) {
150+ Post post = postRepository .findById (postId )
151+ .orElseThrow (() -> new ResponseStatusException (HttpStatus .NOT_FOUND , "삭제할 게시글을 찾을 수 없습니다." ));
152+ postRepository .delete (post );
153+ }
154+
148155 @ Override
149156 public List <PostDetailDto > getAllPosts (Long memberId ) {
150157 return postRepository .findAll ().stream ()
You can’t perform that action at this time.
0 commit comments