From 3540bdce929830ba7ca0a273bf1655b705c3564b Mon Sep 17 00:00:00 2001 From: happymink Date: Sun, 28 Jan 2024 16:48:21 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Style]=20=EC=BD=94=EB=93=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=83=80=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `#` Pageable 객체를 만들어서 Service 계층에 전달합니다. `#` Review를 저장할 때, Place 객체를 만드는 것이 아닌 전달받은 Place를 사용합니다. `#` 가독성을 높이기 위해 createReview()를 수정합니다. --- .../domain/review/controller/ReviewController.java | 5 +++-- .../app/domain/review/dto/ReviewCreateRequest.java | 4 ++-- .../be/app/domain/review/service/ReviewService.java | 13 ++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/fc/be/app/domain/review/controller/ReviewController.java b/app/src/main/java/fc/be/app/domain/review/controller/ReviewController.java index b2ee18d8..323155ec 100644 --- a/app/src/main/java/fc/be/app/domain/review/controller/ReviewController.java +++ b/app/src/main/java/fc/be/app/domain/review/controller/ReviewController.java @@ -7,6 +7,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -53,7 +54,7 @@ public ApiResponse getPlaceReviews( @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size ) { - return ApiResponse.ok(reviewService.bringReviewInfo(reviewGetRequest, - PageRequest.of(page, size, Sort.by("visitedAt").descending()))); + Pageable pageRequest = PageRequest.of(page, size, Sort.by("visitedAt").descending()); + return ApiResponse.ok(reviewService.bringReviewInfo(reviewGetRequest,pageRequest)); } } diff --git a/app/src/main/java/fc/be/app/domain/review/dto/ReviewCreateRequest.java b/app/src/main/java/fc/be/app/domain/review/dto/ReviewCreateRequest.java index 36657c23..3b39869e 100644 --- a/app/src/main/java/fc/be/app/domain/review/dto/ReviewCreateRequest.java +++ b/app/src/main/java/fc/be/app/domain/review/dto/ReviewCreateRequest.java @@ -21,10 +21,10 @@ public record ReviewCreateRequest( @PastOrPresent LocalDate visitedAt ) { - public Review to(Member member) { + public Review to(Member member, Place place) { return Review.builder() .member(member) - .place(Place.builder().id(placeId).build()) + .place(place) .visitedAt(visitedAt) .rating(rating) .content(content) diff --git a/app/src/main/java/fc/be/app/domain/review/service/ReviewService.java b/app/src/main/java/fc/be/app/domain/review/service/ReviewService.java index f7ac0e65..e0b53664 100644 --- a/app/src/main/java/fc/be/app/domain/review/service/ReviewService.java +++ b/app/src/main/java/fc/be/app/domain/review/service/ReviewService.java @@ -4,6 +4,7 @@ import fc.be.app.domain.member.exception.MemberErrorCode; import fc.be.app.domain.member.exception.MemberException; import fc.be.app.domain.member.repository.MemberRepository; +import fc.be.app.domain.place.Place; import fc.be.app.domain.place.service.PlaceService; import fc.be.app.domain.review.dto.*; import fc.be.app.domain.review.dto.response.ReviewResponse; @@ -39,10 +40,10 @@ public ReviewCreateResponse createReview(ReviewCreateRequest reviewCreateRequest Member member = memberRepository.findById(userPrincipal.id()).orElseThrow(() -> new MemberException(MemberErrorCode.MEMBER_NOT_FOUND)); - placeService.saveOrUpdatePlace(placeId, contentTypeId); + Place place = placeService.saveOrUpdatePlace(placeId, contentTypeId); + Review createdReview = reviewRepository.save(reviewCreateRequest.to(member, place)); - return ReviewCreateResponse.from(reviewRepository.save( - reviewCreateRequest.to(member))); + return ReviewCreateResponse.from(createdReview); } @Transactional @@ -76,8 +77,7 @@ public ReviewGetResponse bringReviewInfo(ReviewGetRequest reviewGetRequest, Page Integer placeId = reviewGetRequest.placeId(); final int firstPage = 0; if (pageable.getPageNumber() == firstPage) { - var response = reviewAPIService.bringReview - (reviewGetRequest.placeTitle(), reviewGetRequest.contentTypeId()); + var response = reviewAPIService.bringReview(reviewGetRequest.placeTitle(), reviewGetRequest.contentTypeId()); List reviews = ReviewGetResponse.convertToReviews(response); @@ -88,8 +88,7 @@ public ReviewGetResponse bringReviewInfo(ReviewGetRequest reviewGetRequest, Page } public ReviewRatingResponse bringReviewRatingAndCount(ReviewGetRequest reviewGetRequest) { - var googleReviewResponse = reviewAPIService.bringRatingCount - (reviewGetRequest.placeTitle(), reviewGetRequest.contentTypeId()); + var googleReviewResponse = reviewAPIService.bringRatingCount(reviewGetRequest.placeTitle(), reviewGetRequest.contentTypeId()); double googleRating = googleReviewResponse.rating(); long googleCount = googleReviewResponse.userRatingCount(); From e21ad31aa13c4fe43229515e787855ecd88beae4 Mon Sep 17 00:00:00 2001 From: happymink Date: Sun, 28 Jan 2024 16:59:08 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Refactor]=20Review=20Rating=20NPE=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=20=EB=B0=A9=EC=A7=80=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `#` Rating Response에 대한 Null 케이스를 추가합니다 --- .../fc/be/openapi/google/dto/review/APIRatingResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openapi/src/main/java/fc/be/openapi/google/dto/review/APIRatingResponse.java b/openapi/src/main/java/fc/be/openapi/google/dto/review/APIRatingResponse.java index 600b5bc5..888c1c85 100644 --- a/openapi/src/main/java/fc/be/openapi/google/dto/review/APIRatingResponse.java +++ b/openapi/src/main/java/fc/be/openapi/google/dto/review/APIRatingResponse.java @@ -13,8 +13,8 @@ public static APIRatingResponse convertToRatingResponse(GoogleRatingResponse goo } return new APIRatingResponse( - googleRatingResponse.rating(), - googleRatingResponse.reviews().size() + (googleRatingResponse.rating() == null) ? 0.0 : googleRatingResponse.rating(), + (googleRatingResponse.reviews() == null)? 0 : googleRatingResponse.reviews().size() ); } }