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 d3d65f33..1bcc03c1 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 @@ -8,6 +8,7 @@ import com.mile.post.service.dto.CommentCreateRequest; import com.mile.post.service.dto.CommentListResponse; import com.mile.post.service.dto.ModifyPostGetResponse; +import com.mile.post.service.dto.PostAuthenticateResponse; import com.mile.post.service.dto.PostCreateRequest; import com.mile.post.service.dto.PostCuriousResponse; import com.mile.post.service.dto.PostGetResponse; @@ -96,7 +97,7 @@ public SuccessResponse deleteCurious( @GetMapping("/{postId}/authenticate") @Override - public ResponseEntity getAuthenticateWrite( + public ResponseEntity> getAuthenticateWrite( @PostIdPathVariable final Long postId, @UserId final Long userId, @PathVariable("postId") final String postUrl 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 6892e4ee..e5d0669e 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 @@ -7,6 +7,7 @@ import com.mile.post.service.dto.CommentCreateRequest; import com.mile.post.service.dto.CommentListResponse; import com.mile.post.service.dto.ModifyPostGetResponse; +import com.mile.post.service.dto.PostAuthenticateResponse; import com.mile.post.service.dto.PostCreateRequest; import com.mile.post.service.dto.PostCuriousResponse; import com.mile.post.service.dto.PostGetResponse; @@ -134,7 +135,7 @@ SuccessResponse deleteCurious( } ) - ResponseEntity getAuthenticateWrite( + ResponseEntity> getAuthenticateWrite( @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/post/service/PostService.java b/module-domain/src/main/java/com/mile/post/service/PostService.java index 03247647..ee980c93 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 @@ -17,7 +17,7 @@ import com.mile.post.service.dto.PostPutRequest; import com.mile.post.service.dto.TemporaryPostCreateRequest; import com.mile.post.service.dto.TemporaryPostGetResponse; -import com.mile.post.service.dto.WriterAuthenticateResponse; +import com.mile.post.service.dto.PostAuthenticateResponse; import com.mile.topic.domain.Topic; import com.mile.topic.service.TopicRetriever; import com.mile.topic.service.TopicService; @@ -52,6 +52,11 @@ public class PostService { private static final boolean CURIOUS_FALSE = false; private static final boolean CURIOUS_TRUE = true; + private static final String ROLE_WRITER = "writer"; + private static final String ROLE_ANONYMOUS = "anonymous"; + private static final String ROLE_MEMBER = "member"; + private static final String ROLE_OWNER = "owner"; + @Transactional public void createCommentOnPost( @@ -119,12 +124,28 @@ public void updatePost( } - public WriterAuthenticateResponse getAuthenticateWriter( + public PostAuthenticateResponse getAuthenticateWriter( final Long postId, final Long userId ) { - return WriterAuthenticateResponse.of(postRetriever.existsPostByWriterWithPost(postId, - writerNameRetriever.getWriterNameByPostAndUserId(postRetriever.findById(postId), userId).getId())); + Post post = postRetriever.findById(postId); + Moim moim = post.getTopic().getMoim(); + WriterName postWriterName = post.getWriterName(); + + if (!writerNameRetriever.isUserInMoim(moim.getId(), userId)) { + return PostAuthenticateResponse.of(ROLE_ANONYMOUS); + } + + WriterName userWriterName = writerNameRetriever.findByMoimAndUser(moim.getId(), userId); + if (postWriterName.equals(userWriterName)) { + return PostAuthenticateResponse.of(ROLE_WRITER); + } + + if (moim.getOwner().equals(userWriterName)) { + return PostAuthenticateResponse.of(ROLE_OWNER); + } + + return PostAuthenticateResponse.of(ROLE_MEMBER); } @Transactional diff --git a/module-domain/src/main/java/com/mile/post/service/dto/PostAuthenticateResponse.java b/module-domain/src/main/java/com/mile/post/service/dto/PostAuthenticateResponse.java new file mode 100644 index 00000000..5013e6ea --- /dev/null +++ b/module-domain/src/main/java/com/mile/post/service/dto/PostAuthenticateResponse.java @@ -0,0 +1,11 @@ +package com.mile.post.service.dto; + +public record PostAuthenticateResponse( + String role +) { + public static PostAuthenticateResponse of( + final String role + ) { + return new PostAuthenticateResponse(role); + } +} diff --git a/module-domain/src/main/java/com/mile/post/service/dto/WriterAuthenticateResponse.java b/module-domain/src/main/java/com/mile/post/service/dto/WriterAuthenticateResponse.java deleted file mode 100644 index b29161fd..00000000 --- a/module-domain/src/main/java/com/mile/post/service/dto/WriterAuthenticateResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mile.post.service.dto; - -public record WriterAuthenticateResponse( - boolean canEdit -) { - public static WriterAuthenticateResponse of( - final boolean canEdit - ) { - return new WriterAuthenticateResponse(canEdit); - } -}