Skip to content

Commit

Permalink
Feat: 내가 쓴 한줄요약 API 구현 (#172)
Browse files Browse the repository at this point in the history
* #164 - feat: 내가 쓴 한줄요약 조회 API 구현

* #164 - test: 내가 쓴 한줄요약 조회 API 테스트 구현
  • Loading branch information
morenow98 authored Feb 19, 2024
1 parent f5c8f02 commit e4c3ab4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ public ResponseEntity<ReviewListResponse> searchLikeReview(
return ResponseEntity.ok(reviewService.searchLikeReview(details.getId(), pageable));
}

@GetMapping("/me")
public ResponseEntity<ReviewListResponse> getMyReviews(
@AuthenticationPrincipal AuthDetails details,
Pageable pageable
) {
return ResponseEntity.ok(reviewService.getMyReviews(details.getId(), pageable));
}

@GetMapping("/recommend")
public ResponseEntity<ReviewListResponse> getRecommendReviews(
@RequestParam RecommendType type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface ReviewRepository extends ReviewRepositoryCustom, JpaRepository<
int countPublicReviewByBook_Isbn13(String isbn13);

Optional<Review> findByIdAndMemberId(Long reviewId, Long memberId);

Page<Review> findByMemberId(Long memberId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public ReviewCountResponse getReviewCount(String isbn13) {
return ReviewCountResponse.of(reviewRepository.countPublicReviewByBook_Isbn13(isbn13));
}

@Transactional
public void increaseViewCount(Long reviewId) {
Review review = reviewRepository.getReferenceById(reviewId);
review.increaseViewCount();
Expand All @@ -95,10 +94,17 @@ public void deleteReview(Long reviewId, Long memberId) {
review.deleteReview();
}

@Transactional(readOnly = true)
public ReviewListResponse searchLikeReview(Long memberId, Pageable pageable) {
return ReviewListResponse.fromDto(reviewRepository.findLikeReviewByMemberId(memberId, pageable), memberId);
}

@Transactional(readOnly = true)
public ReviewListResponse getMyReviews(Long memberId, Pageable pageable) {
return ReviewListResponse.from(reviewRepository.findByMemberId(memberId, pageable), memberId);
}

@Transactional(readOnly = true)
public ReviewListResponse getRecommendReviews(RecommendType type, int start, Long memberId) {
return switch (type) {
case LIKE -> getMostLikeReviews(start, memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,32 @@ void givenNonLogin_whenSearchingLikeReview_thenReturnErrorResponse() throws Exce
;
}

@Test
@WithCustomMockUser
@DisplayName("유저가 본인이 작성한 한줄요약을 조회한다.")
void givenLogin_whenGettingMyReview_thenReturnReviewListResponse() throws Exception {
//given

//when & then
mockMvc.perform(get("/reviews/me")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.totalResults").value(3))
;
}

@Test
@DisplayName("로그인 없이 본인이 작성한 한줄요약을 조회하면 에러를 반환한다.")
void givenNonLogin_whenGettingMyReview_thenReturnErrorResponse() throws Exception {
//given

//when & then
mockMvc.perform(get("/reviews/me")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isUnauthorized())
;
}

@Test
@DisplayName("좋아요가 많은 순으로 한줄요약을 4개 반환한다.")
void givenPageStartAndRecommendType_whenGettingMostLikeReviews_thenReturnMostLikeReviews() throws Exception {
Expand Down

0 comments on commit e4c3ab4

Please sign in to comment.