Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #226 from Strong-Potato/bugfix/#221-rating-npe-and…
Browse files Browse the repository at this point in the history
…-code-style-fix

[Bugfix/Style] Review Rating NPE 케이스 추가 및 코드 스타일 수정
  • Loading branch information
happymink authored Jan 28, 2024
2 parents 2e7232d + e21ad31 commit 2bad142
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +54,7 @@ public ApiResponse<ReviewGetResponse> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Review> reviews = ReviewGetResponse.convertToReviews(response);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}

0 comments on commit 2bad142

Please sign in to comment.