Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 최신순으로 리뷰를 조회하는 쿼리문 수정 #34

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ private static Predicate checkEquals(final String fieldName,
if (LOCALDATETIME_TYPE_INCLUDE.contains(fieldName)) {
final Path<LocalDateTime> createdAtPath = root.get(fieldName);
final LocalDateTime lastReviewCreatedAt = lastReview.getCreatedAt();
return criteriaBuilder.equal(createdAtPath, lastReviewCreatedAt);
final int reformatNano = Math.round((float) lastReviewCreatedAt.getNano() / 1000) * 1000;
Copy link
Member Author

@70825 70825 Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nanoseconds가 1e-9이므로 데이터베이스 형식과 동일하게 1e-6까지만 보이게하고, 나머지는 반올림하도록 변경했습니다

return criteriaBuilder.equal(createdAtPath, lastReviewCreatedAt.withNano(reformatNano));
}
if (LONG_TYPE_INCLUDE.contains(fieldName)) {
final Path<Long> reviewPath = root.get(fieldName);
Expand Down Expand Up @@ -120,7 +121,8 @@ private static Predicate checkGreaterThan(final String fieldName, final Review l
if (LOCALDATETIME_TYPE_INCLUDE.contains(fieldName)) {
final Path<LocalDateTime> createdAtPath = root.get(fieldName);
final LocalDateTime lastReviewCreatedAt = lastReview.getCreatedAt();
return criteriaBuilder.greaterThan(createdAtPath, lastReviewCreatedAt);
final int reformatNano = Math.round((float) lastReviewCreatedAt.getNano() / 1000) * 1000;
return criteriaBuilder.greaterThan(createdAtPath, lastReviewCreatedAt.withNano(reformatNano));
}
if (LONG_TYPE_INCLUDE.contains(fieldName)) {
final Path<Long> reviewPath = root.get(fieldName);
Expand Down Expand Up @@ -149,7 +151,8 @@ private static Predicate checkLessThan(final String fieldName, final Review last
if (LOCALDATETIME_TYPE_INCLUDE.contains(fieldName)) {
final Path<LocalDateTime> createdAtPath = root.get(fieldName);
final LocalDateTime lastReviewCreatedAt = lastReview.getCreatedAt();
return criteriaBuilder.lessThan(createdAtPath, lastReviewCreatedAt);
final int reformatNano = Math.round((float) lastReviewCreatedAt.getNano() / 1000) * 1000;
return criteriaBuilder.lessThan(createdAtPath, lastReviewCreatedAt.withNano(reformatNano));
}
if (LONG_TYPE_INCLUDE.contains(fieldName)) {
final Path<Long> reviewPath = root.get(fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,7 @@ class sortingReviews_성공_테스트 {
final var productId = 단일_상품_저장(product);

final var review1 = 리뷰_이미지test3_평점3점_재구매O_생성(member, product, 351L);
Thread.sleep(100);
final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member, product, 24L);
Thread.sleep(100);
final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member, product, 130L);
복수_리뷰_저장(review1, review2, review3);

Expand Down
Loading