Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…server into develop
  • Loading branch information
5jisoo committed Jan 9, 2024
2 parents d0049a1 + 6eac39b commit 1d21a0a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public enum BaseResponseStatus {
// post (3600 ~ 3699)
INVALID_POST_STATUS(false, 3600, "접근 불가능한 게시물 입니다."),
BLOCKED_POST(false, 3601, "차단한 게시글입니다."),
DELETED_POST(false, 3602, "삭제된 게시글입니다."),
NOT_YOUR_POST(false, 3603, "게시글 수정 및 삭제 권한이 없습니다."),

/**
* 4000: DB Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ public BaseResponse<?> getDetailCommunityPosts(@RequestHeader("Authorization") L
return new BaseResponse<>(e.getStatus());
}
}

@DeleteMapping("/{postId}")
public BaseResponse<?> deleteCommunityPosts(@RequestHeader("Authorization") Long loginId,
@PathVariable("postId") Long postId) {
try {
return new BaseResponse<>(postService.deletePost(postId));
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.unibond.unibond.comment.domain.Comment;
import com.unibond.unibond.comment.repository.CommentRepository;
import com.unibond.unibond.common.BaseException;
import com.unibond.unibond.common.BaseResponseStatus;
import com.unibond.unibond.common.service.LoginInfoService;
import com.unibond.unibond.common.service.S3Uploader;
import com.unibond.unibond.member.domain.Member;
Expand All @@ -21,6 +22,7 @@
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import static com.unibond.unibond.common.BaseEntityStatus.DELETED;
import static com.unibond.unibond.common.BaseResponseStatus.*;
import static com.unibond.unibond.post.domain.BoardType.EXPERIENCE;

Expand Down Expand Up @@ -102,6 +104,24 @@ public GetCommunityContentDetailResDto getDetailCommunityContent(Long postId, Pa
}
}

@Transactional
public BaseResponseStatus deletePost(Long postId) throws BaseException {
try {
Long loginMemberId = loginInfoService.getLoginMemberId();
Post post = findPost(postId);
if (!post.getOwner().getId().equals(loginMemberId)) {
throw new BaseException(NOT_YOUR_POST);
}
post.setStatus(DELETED);
deleteComments(post);
return SUCCESS;
} catch (BaseException e) {
throw e;
} catch (Exception e) {
throw new BaseException(DATABASE_ERROR);
}
}

private void checkBlockedMember(Long reporterId, Long respondentId) throws BaseException {
Boolean isBlocked = memberBlockRepository.existsByReporterIdAndRespondentId(reporterId, respondentId);
if (isBlocked) {
Expand All @@ -115,4 +135,16 @@ private void checkBlockedPost(Long reporterId, Long reportedPostId) throws BaseE
throw new BaseException(BLOCKED_POST);
}
}

private Post findPost(Long postId) throws BaseException {
Post post = postRepository.findById(postId).orElseThrow(() -> new BaseException(INVALID_POST_ID));
if (post.getStatus().equals(DELETED)) {
throw new BaseException(DELETED_POST);
}
return post;
}

private void deleteComments(Post post) throws BaseException {
commentRepository.bulkDeleteByPost(post);
}
}

0 comments on commit 1d21a0a

Please sign in to comment.