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(); 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() ); } }