From 5d770d1ca6cc147e36d21599a4df168855eee752 Mon Sep 17 00:00:00 2001 From: parkheeddong Date: Sun, 6 Oct 2024 17:13:26 +0900 Subject: [PATCH] =?UTF-8?q?#520=20[feat]=20=EA=B8=80=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=9D=B8=EA=B0=80=EC=B2=B4=EC=A0=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mile/controller/post/PostController.java | 4 ++-- .../com/mile/controller/post/PostControllerSwagger.java | 1 - .../main/java/com/mile/moim/service/MoimRetriever.java | 7 +++++++ .../src/main/java/com/mile/post/service/PostService.java | 9 +++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/module-api/src/main/java/com/mile/controller/post/PostController.java b/module-api/src/main/java/com/mile/controller/post/PostController.java index f56bb1d1..48596e16 100644 --- a/module-api/src/main/java/com/mile/controller/post/PostController.java +++ b/module-api/src/main/java/com/mile/controller/post/PostController.java @@ -130,12 +130,12 @@ public ResponseEntity putPost( @DeleteMapping("/{postId}") @Override + @UserAuthAnnotation(UserAuthenticationType.WRITER_NAME) public ResponseEntity 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)); } diff --git a/module-api/src/main/java/com/mile/controller/post/PostControllerSwagger.java b/module-api/src/main/java/com/mile/controller/post/PostControllerSwagger.java index bd2c9f80..8a6fd560 100644 --- a/module-api/src/main/java/com/mile/controller/post/PostControllerSwagger.java +++ b/module-api/src/main/java/com/mile/controller/post/PostControllerSwagger.java @@ -196,7 +196,6 @@ ResponseEntity deleteTemporaryPost( ) ResponseEntity 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 ); diff --git a/module-domain/src/main/java/com/mile/moim/service/MoimRetriever.java b/module-domain/src/main/java/com/mile/moim/service/MoimRetriever.java index f5b3be0f..b27dc5ba 100644 --- a/module-domain/src/main/java/com/mile/moim/service/MoimRetriever.java +++ b/module-domain/src/main/java/com/mile/moim/service/MoimRetriever.java @@ -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 findBestMoims() { LocalDateTime endOfWeek = LocalDateTime.now(); LocalDateTime startOfWeek = endOfWeek.minusDays(7); diff --git a/module-domain/src/main/java/com/mile/post/service/PostService.java b/module-domain/src/main/java/com/mile/post/service/PostService.java index 85a66f2c..f54ea219 100644 --- a/module-domain/src/main/java/com/mile/post/service/PostService.java +++ b/module-domain/src/main/java/com/mile/post/service/PostService.java @@ -171,17 +171,18 @@ public PostAuthenticateResponse getAuthenticateWriter( @Transactional public void deletePost( final Long postId, - final Long userId + final HashMap 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,