Skip to content

Commit

Permalink
Merge pull request #70 from Domitory-CheckMate/feature/69-post
Browse files Browse the repository at this point in the history
[feat] #69 게시물 삭제 API 추가
  • Loading branch information
OJOJIN authored Mar 22, 2024
2 parents 5ed77a6 + 1f93a37 commit e19e1fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.gachon.checkmate.domain.post.dto.request.PostRequestDto;
import org.gachon.checkmate.domain.post.dto.request.PostStateUpdateRequestDto;
import org.gachon.checkmate.domain.post.dto.response.PostDetailResponseDto;
import org.gachon.checkmate.domain.post.dto.response.PostSearchResponseDto;
import org.gachon.checkmate.domain.post.dto.response.PostStateUpdateResponseDto;
import org.gachon.checkmate.domain.post.dto.response.PostUpdateResponseDto;
import org.gachon.checkmate.domain.post.dto.response.*;
import org.gachon.checkmate.domain.post.service.PostService;
import org.gachon.checkmate.global.common.SuccessResponse;
import org.gachon.checkmate.global.config.auth.UserId;
Expand Down Expand Up @@ -54,6 +51,13 @@ public ResponseEntity<SuccessResponse<?>> getMyPosts(@UserId final Long userId,
return SuccessResponse.ok(responseDto);
}

@DeleteMapping("{id}")
public ResponseEntity<SuccessResponse<?>> deleteMyPost(@UserId final Long userId,
@PathVariable("id") final Long postId) {
PostDeleteResponseDto responseDto = postService.deleteMyPost(userId, postId);
return SuccessResponse.ok(responseDto);
}

@PatchMapping("/{id}")
public ResponseEntity<SuccessResponse<?>> updateMyPost(@UserId final Long userId,
@PathVariable("id") final Long postId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.gachon.checkmate.domain.post.dto.response;

import lombok.Builder;

@Builder
public record PostDeleteResponseDto(
Boolean isSuccess
) {
public static PostDeleteResponseDto of(Boolean isSuccess) {
return PostDeleteResponseDto.builder()
.isSuccess(isSuccess)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public PostStateUpdateResponseDto updateMyPostState(Long userId, Long postId, Po
return PostStateUpdateResponseDto.of(post);
}

public PostDeleteResponseDto deleteMyPost(Long userId, Long postId) {
User user = getUserOrThrow(userId);
Post post = getPostOrThrow(postId);
validatePostWriter(user, post);
deletePost(post);
return PostDeleteResponseDto.of(true);
}

private List<PostSearchElementResponseDto> createPostSearchResponseDto(Page<PostSearchDto> postSearchDtoList, CheckList checkList) {
return postSearchDtoList.stream()
.map(postSearchDto ->
Expand Down Expand Up @@ -181,4 +189,8 @@ private Post getPostOrThrow(Long postId) {
return postRepository.findById(postId)
.orElseThrow(() -> new EntityNotFoundException(POST_NOT_FOUND));
}

private void deletePost(Post post) {
postRepository.delete(post);
}
}

0 comments on commit e19e1fa

Please sign in to comment.