Skip to content

Commit c23dee2

Browse files
committed
Fix[post]:게시글 삭제, 본인 게시물 404 삭제
1 parent 2f5541e commit c23dee2

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

backend/src/main/java/com/ai/lawyer/domain/poll/service/PollService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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);

backend/src/main/java/com/ai/lawyer/domain/post/controller/PostController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

backend/src/main/java/com/ai/lawyer/domain/post/service/PostService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
// ===== 본인 게시글 관련 =====

backend/src/main/java/com/ai/lawyer/domain/post/service/PostServiceImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)