diff --git a/src/main/java/dev/steady/review/controller/ReviewController.java b/src/main/java/dev/steady/review/controller/ReviewController.java index b998a3a..7984466 100644 --- a/src/main/java/dev/steady/review/controller/ReviewController.java +++ b/src/main/java/dev/steady/review/controller/ReviewController.java @@ -3,8 +3,8 @@ import dev.steady.global.auth.Auth; import dev.steady.global.auth.UserInfo; import dev.steady.review.dto.request.ReviewCreateRequest; -import dev.steady.review.dto.request.ReviewUpdateRequest; import dev.steady.review.dto.response.ReviewMyResponse; +import dev.steady.review.dto.response.ReviewSwitchResponse; import dev.steady.review.service.ReviewService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -38,12 +38,11 @@ public ResponseEntity createReview(@PathVariable Long steadyId, } @PatchMapping("/reviews/{reviewId}") - public ResponseEntity updateReviewIsPublic(@PathVariable Long reviewId, - @RequestBody ReviewUpdateRequest request, - @Auth UserInfo userInfo) { - reviewService.updateReviewIsPublic(reviewId, request, userInfo); + public ResponseEntity updateReviewIsPublic(@PathVariable Long reviewId, + @Auth UserInfo userInfo) { + ReviewSwitchResponse response = reviewService.switchReviewIsPublic(reviewId, userInfo); - return ResponseEntity.ok().build(); + return ResponseEntity.ok(response); } @GetMapping("/reviews/my") diff --git a/src/main/java/dev/steady/review/service/ReviewService.java b/src/main/java/dev/steady/review/service/ReviewService.java index 531e321..d946a95 100644 --- a/src/main/java/dev/steady/review/service/ReviewService.java +++ b/src/main/java/dev/steady/review/service/ReviewService.java @@ -10,8 +10,8 @@ import dev.steady.review.domain.repository.ReviewRepository; import dev.steady.review.domain.repository.UserCardRepository; import dev.steady.review.dto.request.ReviewCreateRequest; -import dev.steady.review.dto.request.ReviewUpdateRequest; import dev.steady.review.dto.response.ReviewMyResponse; +import dev.steady.review.dto.response.ReviewSwitchResponse; import dev.steady.review.dto.response.ReviewsBySteadyResponse; import dev.steady.review.dto.response.UserCardResponse; import dev.steady.review.infrastructure.ReviewQueryRepository; @@ -85,14 +85,22 @@ public void createUserCards(ReviewCreateRequest request) { userCardRepository.saveAll(userCards); } + /** + * 리뷰의 공개 여부(isPublic)을 변경하고 그 결과를 반환한다. + * + * @param reviewId 리뷰 식별자 + * @param userInfo 사용자 정보 + * @return 리뷰 공개 여부 변경된 결과 + */ @Transactional - public void updateReviewIsPublic(Long reviewId, ReviewUpdateRequest request, UserInfo userInfo) { + public ReviewSwitchResponse switchReviewIsPublic(Long reviewId, UserInfo userInfo) { Review review = reviewRepository.getById(reviewId); Participant reviewee = review.getReviewee(); if (!Objects.equals(reviewee.getUserId(), userInfo.userId())) { throw new ForbiddenException(REVIEW_AUTH_FAILURE); } - review.updateIsPublic(request.isPublic()); + review.switchIsPublic(); + return ReviewSwitchResponse.from(review); } @Transactional(readOnly = true) diff --git a/src/test/java/dev/steady/review/controller/ReviewControllerTest.java b/src/test/java/dev/steady/review/controller/ReviewControllerTest.java index 9799a1f..3805773 100644 --- a/src/test/java/dev/steady/review/controller/ReviewControllerTest.java +++ b/src/test/java/dev/steady/review/controller/ReviewControllerTest.java @@ -11,9 +11,8 @@ import static dev.steady.global.auth.AuthFixture.createUserInfo; import static dev.steady.review.fixture.ReviewFixture.createReviewCreateRequest; import static dev.steady.review.fixture.ReviewFixture.createReviewMyResponse; -import static dev.steady.review.fixture.ReviewFixture.createReviewUpdateRequest; +import static dev.steady.review.fixture.ReviewFixture.createReviewSwitchResponse; import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.willDoNothing; import static org.springframework.http.HttpHeaders.AUTHORIZATION; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; @@ -77,24 +76,24 @@ void updateReviewIsPublicTest() throws Exception { var auth = new Authentication(userId); given(jwtResolver.getAuthentication(TOKEN)).willReturn(auth); - var request = createReviewUpdateRequest(false); var reviewId = 1L; - willDoNothing().given(reviewService).updateReviewIsPublic(reviewId, request, userInfo); + var response = createReviewSwitchResponse(true); + given(reviewService.switchReviewIsPublic(reviewId, userInfo)).willReturn(response); // when, then mockMvc.perform(patch("/api/v1/reviews/{reviewId}", reviewId) .contentType(APPLICATION_JSON) .header(AUTHORIZATION, TOKEN) - .content(objectMapper.writeValueAsString(request)) ) .andDo(document("review-v1-update", resourceDetails().tag("리뷰").description("리뷰 공개 여부 수정") - .requestSchema(Schema.schema("ReviewUpdateRequest")), - requestFields( - fieldWithPath("isPublic").type(BOOLEAN).description("수정할 리뷰 공개 상태") + .responseSchema(Schema.schema("ReviewSwitchRepsonse")), + responseFields( + fieldWithPath("isPublic").type(BOOLEAN).description("수정된 리뷰 공개 여부 상태") ) )) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(response))); } @Test diff --git a/src/test/java/dev/steady/review/fixture/ReviewFixture.java b/src/test/java/dev/steady/review/fixture/ReviewFixture.java index b9a395b..d44b50b 100644 --- a/src/test/java/dev/steady/review/fixture/ReviewFixture.java +++ b/src/test/java/dev/steady/review/fixture/ReviewFixture.java @@ -4,9 +4,9 @@ import dev.steady.review.domain.Review; import dev.steady.review.domain.UserCard; import dev.steady.review.dto.request.ReviewCreateRequest; -import dev.steady.review.dto.request.ReviewUpdateRequest; import dev.steady.review.dto.response.ReviewDetailResponse; import dev.steady.review.dto.response.ReviewMyResponse; +import dev.steady.review.dto.response.ReviewSwitchResponse; import dev.steady.review.dto.response.ReviewsBySteadyResponse; import dev.steady.review.dto.response.UserCardResponse; import dev.steady.steady.domain.Participant; @@ -63,8 +63,8 @@ public static ReviewCreateRequest createReviewCreateRequest() { ); } - public static ReviewUpdateRequest createReviewUpdateRequest(boolean isPublic) { - return new ReviewUpdateRequest(isPublic); + public static ReviewSwitchResponse createReviewSwitchResponse(boolean isPublic) { + return new ReviewSwitchResponse(isPublic); } public static ReviewMyResponse createReviewMyResponse() { diff --git a/src/test/java/dev/steady/review/service/ReviewServiceTest.java b/src/test/java/dev/steady/review/service/ReviewServiceTest.java index 0196440..e169f7c 100644 --- a/src/test/java/dev/steady/review/service/ReviewServiceTest.java +++ b/src/test/java/dev/steady/review/service/ReviewServiceTest.java @@ -8,6 +8,7 @@ import dev.steady.review.domain.repository.ReviewRepository; import dev.steady.review.domain.repository.UserCardRepository; import dev.steady.review.dto.response.ReviewMyResponse; +import dev.steady.review.dto.response.ReviewSwitchResponse; import dev.steady.review.infrastructure.ReviewQueryRepository; import dev.steady.review.infrastructure.UserCardQueryRepository; import dev.steady.steady.domain.repository.ParticipantRepository; @@ -33,7 +34,6 @@ import static dev.steady.review.fixture.ReviewFixture.createCard; import static dev.steady.review.fixture.ReviewFixture.createReview; import static dev.steady.review.fixture.ReviewFixture.createReviewCreateRequest; -import static dev.steady.review.fixture.ReviewFixture.createReviewUpdateRequest; import static dev.steady.review.fixture.ReviewFixture.createUserCard; import static dev.steady.steady.domain.Participant.createMember; import static dev.steady.steady.domain.SteadyStatus.FINISHED; @@ -187,7 +187,7 @@ void createUserCardsTest() { @Test @DisplayName("리뷰이는 본인의 리뷰 코멘트를 비공개로 설정할 수 있다.") - void updateReviewIsPublicTest() { + void switchReviewIsPublicTest() { // given var userInfo = createUserInfo(revieweeUser.getId()); var steady = steadyRepository.save(createSteady(leader, stacks, FINISHED)); @@ -195,14 +195,12 @@ void updateReviewIsPublicTest() { var reviewee = participantRepository.save(createMember(revieweeUser, steady)); var review = reviewRepository.save(createReview(reviewer, reviewee, steady)); - var request = createReviewUpdateRequest(false); - // when - reviewService.updateReviewIsPublic(review.getId(), request, userInfo); + ReviewSwitchResponse response = reviewService.switchReviewIsPublic(review.getId(), userInfo); // then Review foundReview = reviewRepository.getById(review.getId()); - assertThat(foundReview.isPublic()).isEqualTo(request.isPublic()); + assertThat(foundReview.isPublic()).isEqualTo(response.isPublic()); } @Test