Skip to content

Commit

Permalink
#520 [feat] 글 삭제 인가체제 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
parkheeddong committed Oct 6, 2024
1 parent 37aa76a commit 5d770d1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ public ResponseEntity<SuccessResponse> putPost(

@DeleteMapping("/{postId}")
@Override
@UserAuthAnnotation(UserAuthenticationType.WRITER_NAME)
public ResponseEntity<SuccessResponse> deletePost(
@PostIdPathVariable final Long postId,
@UserId final Long userId,
@PathVariable("postId") final String postUrl
) {
postService.deletePost(postId, userId);
postService.deletePost(postId, WriterNameContextUtil.getMoimWriterNameMapContext());
return ResponseEntity.status(HttpStatus.OK).body(SuccessResponse.of(SuccessMessage.POST_DELETE_SUCCESS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ ResponseEntity<SuccessResponse> deleteTemporaryPost(
)
ResponseEntity<SuccessResponse> deletePost(
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) final Long postId,
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) @UserId final Long userId,
@PathVariable("postId") final String postUrl
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public boolean isMoimOwnerEqualsUser(
return moim.getOwner().getWriter().getId().equals(userId);
}

public boolean isMoimOwnerEqualsWriterName(
final Moim moim,
final Long writerNameId
) {
return moim.getOwner().getId().equals(writerNameId);
}

public List<Moim> findBestMoims() {
LocalDateTime endOfWeek = LocalDateTime.now();
LocalDateTime startOfWeek = endOfWeek.minusDays(7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,18 @@ public PostAuthenticateResponse getAuthenticateWriter(
@Transactional
public void deletePost(
final Long postId,
final Long userId
final HashMap<Long, WriterNameInfo> moimWriteNameMap
) {
Post post = postRetriever.findById(postId);
Long moimId = post.getTopic().getMoim().getId();
WriterName writerName = writerNameRetriever.findByMoimAndUser(moimId, userId);
if (!postRetriever.isWriterOfPost(post, writerName) && !moimRetriever.isMoimOwnerEqualsUser(post.getTopic().getMoim(), userId)) {
Moim moim = post.getTopic().getMoim();
final Long writerNameId = MoimWriterNameMapUtil.getWriterNameIdMoimWriterNameMap(moim.getId(), moimWriteNameMap);
if (!postRetriever.existsPostByWriterWithPost(postId, writerNameId) && !moimRetriever.isMoimOwnerEqualsWriterName(moim, writerNameId)) {
throw new ForbiddenException(ErrorMessage.WRITER_AUTHENTICATE_ERROR);
}
postRemover.delete(post);
}


@Transactional(readOnly = true)
public TemporaryPostGetResponse getTemporaryPost(
final Long postId,
Expand Down

0 comments on commit 5d770d1

Please sign in to comment.