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 @@ -37,7 +37,7 @@ public interface PollService {
PollDto updatePoll(Long pollId, PollUpdateDto pollUpdateDto, Long memberId);
void patchUpdatePoll(Long pollId, PollUpdateDto pollUpdateDto);
void closePoll(Long pollId);
void deletePoll(Long pollId, Long memberId);
void deletePoll(Long pollId, Long memberId);

// ===== 검증 관련 =====
void validatePollCreate(PollCreateDto dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ public ResponseEntity<ApiResponse<Void>> deletePost(@PathVariable Long postId) {
return ResponseEntity.ok(new ApiResponse<>(200, "게시글이 삭제되었습니다.", null));
}

@Operation(summary = "게시글 삭제(관리자)")
@DeleteMapping("/admin/{postId}")
public ResponseEntity<ApiResponse<Void>> deletePostAdmin(@PathVariable Long postId) {
//AuthUtil.validateAdmin(); 관리자
AuthUtil.getAuthenticatedMemberId(); // 모든 유저
postService.deletePostAdmin(postId);
return ResponseEntity.ok(new ApiResponse<>(200, "게시글이 삭제되었습니다.", null));
}

@ExceptionHandler(ResponseStatusException.class)
public ResponseEntity<ApiResponse<Void>> handleResponseStatusException(ResponseStatusException ex) {
int code = ex.getStatusCode().value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public interface PostService {
PostDto updatePost(Long postId, PostUpdateDto postUpdateDto);
void patchUpdatePost(Long postId, PostUpdateDto postUpdateDto);
void deletePost(Long postId);
void deletePostAdmin(Long postId);
PostDetailDto createPostWithPoll(PostWithPollCreateDto dto, Long memberId);

// ===== 본인 게시글 관련 =====
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public PostDetailDto getPostById(Long postId) {
public List<PostDto> getPostsByMemberId(Long memberId) {
Member member = AuthUtil.getMemberOrThrow(memberId);
List<Post> posts = postRepository.findByMember(member);
if (posts.isEmpty()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "해당 회원의 게시글이 없습니다.");
}
// if (posts.isEmpty()) {
// throw new ResponseStatusException(HttpStatus.NOT_FOUND, "해당 회원의 게시글이 없습니다.");
// }
return posts.stream()
.sorted(Comparator.comparing(Post::getUpdatedAt, Comparator.nullsLast(Comparator.naturalOrder())).reversed()) // 최신순 정렬
.map(post -> convertToDto(post, memberId))
Expand Down Expand Up @@ -145,6 +145,13 @@ public void deletePost(Long postId) {
postRepository.delete(post);
}

@Override
public void deletePostAdmin(Long postId) {
Post post = postRepository.findById(postId)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "삭제할 게시글을 찾을 수 없습니다."));
postRepository.delete(post);
}

@Override
public List<PostDetailDto> getAllPosts(Long memberId) {
return postRepository.findAll().stream()
Expand Down