Skip to content

Commit

Permalink
refactor: 클래스 네이밍 변경
Browse files Browse the repository at this point in the history
LongTypeSortSpec -> LongTypeReviewSortSpec
  • Loading branch information
70825 committed Oct 16, 2023
1 parent e09caee commit bbd289a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,24 @@ private List<SortingReviewDto> getSortingReviews(final Member member, final Prod
final Long lastReviewId = request.getLastReviewId();
final String sortOption = request.getSort();

if (lastReviewId == START) {
final Specification<Review> specification = SortingReviewSpecification.sortingFirstPageBy(product);
final List<TestSortingReviewDto> sortingReviewsTest = reviewRepository.getSortingReview(member,
specification, sortOption);
return sortingReviewsTest.stream()
.map(SortingReviewDto::toDto)
.collect(Collectors.toList());
}

final Review lastReview = reviewRepository.findById(lastReviewId)
.orElseThrow(() -> new ReviewNotFoundException(REVIEW_NOT_FOUND, lastReviewId));
final Specification<Review> specification = SortingReviewSpecification.sortingBy(product, sortOption,
lastReview);
final Specification<Review> specification = getSortingSpecification(product, sortOption, lastReviewId);
final List<TestSortingReviewDto> sortingReviewsTest = reviewRepository.getSortingReview(member, specification,
sortOption);
return sortingReviewsTest.stream()
.map(SortingReviewDto::toDto)
.collect(Collectors.toList());
}

private Specification<Review> getSortingSpecification(final Product product, final String sortOption,
final Long lastReviewId) {
if (lastReviewId == START) {
return SortingReviewSpecification.sortingFirstPageBy(product);
}
final Review lastReview = reviewRepository.findById(lastReviewId)
.orElseThrow(() -> new ReviewNotFoundException(REVIEW_NOT_FOUND, lastReviewId));
return SortingReviewSpecification.sortingBy(product, sortOption, lastReview);
}

public RankingReviewsResponse getTopReviews() {
final List<Review> rankingReviews = reviewRepository.findTop3ByOrderByFavoriteCountDescIdDesc();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
import java.util.Arrays;
import java.util.function.Function;

public enum LongTypeSortSpec {
public enum LongTypeReviewSortSpec {

FAVORITE_COUNT("favoriteCount", Review::getFavoriteCount),
RATING("rating", Review::getRating);

private final String fieldName;
private final Function<Review, Long> function;

LongTypeSortSpec(final String fieldName, final Function<Review, Long> function) {
LongTypeReviewSortSpec(final String fieldName, final Function<Review, Long> function) {
this.fieldName = fieldName;
this.function = function;
}

public static Long find(final String fieldName, final Review lastReview) {
return Arrays.stream(LongTypeSortSpec.values())
return Arrays.stream(LongTypeReviewSortSpec.values())
.filter(reviewSortSpec -> reviewSortSpec.fieldName.equals(fieldName))
.findFirst()
.orElseThrow(IllegalArgumentException::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static Predicate checkEquals(final String fieldName,
}
if (LONG_TYPE_INCLUDE.contains(fieldName)) {
final Path<Long> reviewPath = root.get(fieldName);
final Long lastReviewField = LongTypeSortSpec.find(fieldName, lastReview);
final Long lastReviewField = LongTypeReviewSortSpec.find(fieldName, lastReview);
return criteriaBuilder.equal(reviewPath, lastReviewField);
}
throw new ReviewSortingOptionNotFoundException(REVIEW_SORTING_OPTION_NOT_FOUND, fieldName);
Expand Down Expand Up @@ -124,7 +124,7 @@ private static Predicate checkGreaterThan(final String fieldName, final Review l
}
if (LONG_TYPE_INCLUDE.contains(fieldName)) {
final Path<Long> reviewPath = root.get(fieldName);
final Long lastReviewField = LongTypeSortSpec.find(fieldName, lastReview);
final Long lastReviewField = LongTypeReviewSortSpec.find(fieldName, lastReview);
return criteriaBuilder.greaterThan(reviewPath, lastReviewField);
}
throw new ReviewSortingOptionNotFoundException(REVIEW_SORTING_OPTION_NOT_FOUND, fieldName);
Expand Down Expand Up @@ -153,7 +153,7 @@ private static Predicate checkLessThan(final String fieldName, final Review last
}
if (LONG_TYPE_INCLUDE.contains(fieldName)) {
final Path<Long> reviewPath = root.get(fieldName);
final Long lastReviewField = LongTypeSortSpec.find(fieldName, lastReview);
final Long lastReviewField = LongTypeReviewSortSpec.find(fieldName, lastReview);
return criteriaBuilder.lessThan(reviewPath, lastReviewField);
}
throw new ReviewSortingOptionNotFoundException(REVIEW_SORTING_OPTION_NOT_FOUND, fieldName);
Expand Down

0 comments on commit bbd289a

Please sign in to comment.