From f505706873c2d03e463870f74f32cca0e758d0db Mon Sep 17 00:00:00 2001 From: morenow98 <112200350+morenow98@users.noreply.github.com> Date: Tue, 20 Feb 2024 13:47:10 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20private=20=ED=95=9C=EC=A4=84=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EC=83=81=EC=84=B8=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84=20(#173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #165 - refactor: private 게시글도 찾을 수 있는 메소드에 public 이 들어간 메소드명 변경 * #165 - test: private 한줄요약 상세조회 API 테스트 구현 --- .../querydsl/ReviewRepositoryCustom.java | 2 +- .../querydsl/ReviewRepositoryCustomImpl.java | 2 +- .../review/service/ReviewService.java | 2 +- .../post/controller/PostControllerTest.java | 2 +- .../controller/ReviewControllerTest.java | 47 +++++++++++++++++-- src/test/resources/data.sql | 2 +- 6 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/main/java/cotato/bookitlist/review/repository/querydsl/ReviewRepositoryCustom.java b/src/main/java/cotato/bookitlist/review/repository/querydsl/ReviewRepositoryCustom.java index c108202..175e722 100644 --- a/src/main/java/cotato/bookitlist/review/repository/querydsl/ReviewRepositoryCustom.java +++ b/src/main/java/cotato/bookitlist/review/repository/querydsl/ReviewRepositoryCustom.java @@ -10,7 +10,7 @@ public interface ReviewRepositoryCustom { Page findPublicReviewWithLikedByIsbn13(String isbn13, Long memberId, Long loginMemberId, Pageable pageable); - Optional findPublicReviewDetailByReviewId(Long reviewId, Long memberId); + Optional findReviewDetailByReviewId(Long reviewId, Long memberId); Page findLikeReviewByMemberId(Long memberId, Pageable pageable); } diff --git a/src/main/java/cotato/bookitlist/review/repository/querydsl/ReviewRepositoryCustomImpl.java b/src/main/java/cotato/bookitlist/review/repository/querydsl/ReviewRepositoryCustomImpl.java index f56201c..1bf2e87 100644 --- a/src/main/java/cotato/bookitlist/review/repository/querydsl/ReviewRepositoryCustomImpl.java +++ b/src/main/java/cotato/bookitlist/review/repository/querydsl/ReviewRepositoryCustomImpl.java @@ -66,7 +66,7 @@ public Page findPublicReviewWithLikedByIsbn13(String isbn13, Long mem } @Override - public Optional findPublicReviewDetailByReviewId(Long reviewId, Long memberId) { + public Optional findReviewDetailByReviewId(Long reviewId, Long memberId) { return Optional.ofNullable(queryFactory .select( Projections.constructor( diff --git a/src/main/java/cotato/bookitlist/review/service/ReviewService.java b/src/main/java/cotato/bookitlist/review/service/ReviewService.java index 09adb52..0afb3fb 100644 --- a/src/main/java/cotato/bookitlist/review/service/ReviewService.java +++ b/src/main/java/cotato/bookitlist/review/service/ReviewService.java @@ -60,7 +60,7 @@ public void updateReview(Long reviewId, ReviewUpdateRequest reviewUpdateRequest, @Transactional(readOnly = true) public ReviewDetailDto getReview(Long reviewId, Long memberId) { - return reviewRepository.findPublicReviewDetailByReviewId(reviewId, memberId) + return reviewRepository.findReviewDetailByReviewId(reviewId, memberId) .orElseThrow(() -> new EntityNotFoundException("한줄요약을 찾을 수 없습니다.")); } diff --git a/src/test/java/cotato/bookitlist/post/controller/PostControllerTest.java b/src/test/java/cotato/bookitlist/post/controller/PostControllerTest.java index fd5e18a..82e34bc 100644 --- a/src/test/java/cotato/bookitlist/post/controller/PostControllerTest.java +++ b/src/test/java/cotato/bookitlist/post/controller/PostControllerTest.java @@ -310,7 +310,7 @@ void givenPostIdWithLogin_whenGettingPrivatePost_thenReturnErrorResponse() throw } @Test - @DisplayName("로그인 안된 유저가 다른사람 private 게시글을 조회하면 에러를 반환한다.") + @DisplayName("로그인 안된 유저가 private 게시글을 조회하면 에러를 반환한다.") void givenPostId_whenGettingPrivatePost_thenReturnErrorResponse() throws Exception { //given diff --git a/src/test/java/cotato/bookitlist/review/controller/ReviewControllerTest.java b/src/test/java/cotato/bookitlist/review/controller/ReviewControllerTest.java index 7b9f0a8..dd5c822 100644 --- a/src/test/java/cotato/bookitlist/review/controller/ReviewControllerTest.java +++ b/src/test/java/cotato/bookitlist/review/controller/ReviewControllerTest.java @@ -232,6 +232,47 @@ void givenReviewIdWithLogin_whenGettingAnotherPersonReview_thenReviewResponse() .andExpect(jsonPath("$.isMine").value(false)); } + @Test + @WithCustomMockUser + @DisplayName("로그인 된 유저가 본인의 private 게시글을 조회한다.") + void givenReviewIdWithLogin_whenGettingMyPrivateReview_thenReturnReviewResponse() throws Exception { + //given + + //when & then + mockMvc.perform(get("/reviews/8") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.reviewStatus").value("PRIVATE")) + ; + } + + @Test + @WithCustomMockUser + @DisplayName("로그인 된 유저가 다른 사람 private 한줄요약을 조회하면 에러를 반환한다.") + void givenReviewIdWithLogin_whenGettingPrivateReview_thenReturnErrorResponse() throws Exception { + //given + + //when & then + mockMvc.perform(get("/reviews/6") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(jsonPath("$.message").value("한줄요약을 찾을 수 없습니다.")) + ; + } + + @Test + @DisplayName("로그인 안된 유저가 private 한줄요약을 조회하면 에러를 반환한다.") + void givenReviewId_whenGettingPrivateReview_thenReturnErrorResponse() throws Exception { + //given + + //when & then + mockMvc.perform(get("/reviews/8") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(jsonPath("$.message").value("한줄요약을 찾을 수 없습니다.")) + ; + } + @Test @DisplayName("없는 한줄요약 id로 조회하면 에러를 반환한다.") void givenNonExistedReviewId_whenGettingReview_thenErrorResponse() throws Exception { @@ -286,7 +327,7 @@ void givenNothing_whenSearchingReview_thenReturnReviewListResponse() throws Exce mockMvc.perform(get("/reviews/all") .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.totalResults").value(7)) + .andExpect(jsonPath("$.totalResults").value(6)) ; } @@ -356,7 +397,7 @@ void givenMemberIdWithLogin_whenSearchingReview_thenReturnReviewListResponse() t .param("member-id", String.valueOf(memberId)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.totalResults").value(5)) + .andExpect(jsonPath("$.totalResults").value(4)) .andExpect(jsonPath("$.reviewList[0].liked").value(true)) ; } @@ -371,7 +412,7 @@ void givenMemberId_whenSearchingReview_thenReturnReviewListResponse() throws Exc mockMvc.perform(get("/reviews") .param("member-id", String.valueOf(memberId)) .contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.totalResults").value(5)) + .andExpect(jsonPath("$.totalResults").value(4)) .andExpect(jsonPath("$.reviewList[0].liked").value(false)) ; } diff --git a/src/test/resources/data.sql b/src/test/resources/data.sql index e1a8587..00eff2f 100644 --- a/src/test/resources/data.sql +++ b/src/test/resources/data.sql @@ -71,7 +71,7 @@ VALUES (1, 1, 'reviewContent', 'PUBLIC', 2, 0, false, TIMESTAMP '2024-02-15 00:0 (2, 1, 'rContent', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-13 00:00:00', CURRENT_TIMESTAMP), (2, 1, 'rContent2', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP), (2, 2, 'rContent3', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP), - (2, 2, 'reContent2', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP), + (2, 2, 'reContent2', 'PRIVATE', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP), (1, 2, 'rContent', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP), (1, 2, 'rContent', 'PRIVATE', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP);