diff --git a/src/main/java/com/spaceclub/board/controller/CommentController.java b/src/main/java/com/spaceclub/board/controller/CommentController.java index a306ee96..fcb23bbc 100644 --- a/src/main/java/com/spaceclub/board/controller/CommentController.java +++ b/src/main/java/com/spaceclub/board/controller/CommentController.java @@ -7,7 +7,6 @@ import com.spaceclub.global.Authenticated; import com.spaceclub.global.dto.PageResponse; import com.spaceclub.global.jwt.vo.JwtUser; -import com.spaceclub.global.s3.S3ImageUploader; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -35,7 +34,6 @@ public class CommentController { private final CommentService commentService; - private final S3ImageUploader s3ImageUploader; @GetMapping("/{postId}/comments") public PageResponse getCommentsByPaging( @@ -44,7 +42,7 @@ public PageResponse getCommentsByPaging( ) { Page commentPages = commentService.getComments(postId, pageable); List comments = commentPages.getContent().stream() - .map(comment -> CommentResponse.of(comment, s3ImageUploader.getBucketUrl())) + .map(CommentResponse::of) .toList(); return new PageResponse<>(comments, commentPages); @@ -56,7 +54,7 @@ public CommentResponse getSingleComment( ) { CommentInfo commentInfo = commentService.getComment(commentId); - return CommentResponse.of(commentInfo, s3ImageUploader.getBucketUrl()); + return CommentResponse.of(commentInfo); } @PostMapping("/{postId}/comments") diff --git a/src/main/java/com/spaceclub/board/controller/dto/CommentResponse.java b/src/main/java/com/spaceclub/board/controller/dto/CommentResponse.java index 6ef891d0..13a67865 100644 --- a/src/main/java/com/spaceclub/board/controller/dto/CommentResponse.java +++ b/src/main/java/com/spaceclub/board/controller/dto/CommentResponse.java @@ -15,7 +15,7 @@ public record CommentResponse( boolean isPrivate ) { - public static CommentResponse of(CommentInfo commentInfo, String bucketUrl) { + public static CommentResponse of(CommentInfo commentInfo) { return new CommentResponse( commentInfo.commentId(), commentInfo.content(), diff --git a/src/test/java/com/spaceclub/board/controller/CommentControllerTest.java b/src/test/java/com/spaceclub/board/controller/CommentControllerTest.java index 78aab7cc..8f299754 100644 --- a/src/test/java/com/spaceclub/board/controller/CommentControllerTest.java +++ b/src/test/java/com/spaceclub/board/controller/CommentControllerTest.java @@ -10,7 +10,6 @@ import com.spaceclub.global.config.WebConfig; import com.spaceclub.global.interceptor.AuthenticationInterceptor; import com.spaceclub.global.interceptor.AuthorizationInterceptor; -import com.spaceclub.global.s3.S3ImageUploader; import com.spaceclub.user.service.vo.UserProfile; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.Test; @@ -82,9 +81,6 @@ class CommentControllerTest { @MockBean private CommentService commentService; - @MockBean - private S3ImageUploader s3ImageUploader; - @MockBean private UserArgumentResolver userArgumentResolver; @@ -193,9 +189,6 @@ class CommentControllerTest { UserProfile userProfile = new UserProfile("authorName", "authorPhoneNumber", "authorEmail", "authorImageUrl"); given(commentService.getComment(any(Long.class))).willReturn(CommentInfo.of(comment, userProfile)); - String bucketUrl = "spaceclub.site/"; - given(s3ImageUploader.getBucketUrl()).willReturn(bucketUrl); - mockMvc.perform(get("/api/v1/boards/posts/comments/{commentId}", commentId) .header(AUTHORIZATION, "access token") ) diff --git a/src/test/java/com/spaceclub/board/controller/PostControllerTest.java b/src/test/java/com/spaceclub/board/controller/PostControllerTest.java index 02faddbb..35b2d7c2 100644 --- a/src/test/java/com/spaceclub/board/controller/PostControllerTest.java +++ b/src/test/java/com/spaceclub/board/controller/PostControllerTest.java @@ -130,6 +130,9 @@ class PostControllerTest { UserProfile userProfile = new UserProfile("authorName", "authorPhoneNumber", "authorEmail", "authorImageUrl"); List postInfos = posts.stream().map(post -> PostInfo.of(post, userProfile)).toList(); Page postPages = new PageImpl<>(postInfos); + + final String bucketUrl = "spaceclub.site/"; + given(imageUploader.getBucketUrl()).willReturn(bucketUrl); given(postService.getClubBoardPostsByPaging(any(), any())).willReturn(postPages); Long clubId = 1L; @@ -143,6 +146,11 @@ class PostControllerTest { .andExpect(jsonPath("$.data.size()").value(posts.size())) .andExpect(jsonPath("$.data[0].createdDate").value("2024-01-01T00:00:00")) .andExpect(jsonPath("$.data[0].lastModifiedDate").value("2024-01-01T00:00:00")) + .andExpect(jsonPath("$.data[0].postImageUrl").value(bucketUrl + posts.get(0).getPostImageUrl())) + .andExpect(jsonPath("$.data[0].authorImageUrl").value(userProfile.profileImageUrl())) + .andExpect(jsonPath("$.data[0].author").value(userProfile.username())) + .andExpect(jsonPath("$.data[1].postImageUrl").doesNotExist()) + .andExpect(jsonPath("$.data[2].postImageUrl").value(bucketUrl + posts.get(2).getPostImageUrl())) .andExpect(jsonPath("$.pageData.first").value(true)) .andExpect(jsonPath("$.pageData.last").value(true)) .andExpect(jsonPath("$.pageData.pageNumber").value(0)) @@ -165,7 +173,6 @@ class PostControllerTest { parameterWithName("sort").optional().description("정렬 방법(ex. id,desc), default id,desc") ), responseFields( - fieldWithPath("data").type(ARRAY).description("페이지 내 게시글 정보"), fieldWithPath("data[].postId").type(NUMBER).description("게시글 아이디"), fieldWithPath("data[].title").type(STRING).description("게시글 제목"),