Skip to content

Commit 27229c1

Browse files
committed
fix: query 결과를 가져와서 자바에서 정렬하도록 수정
1 parent d421633 commit 27229c1

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/main/java/com/example/wini/domain/note/repository/NoteCustomRepositoryImpl.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.time.LocalDateTime;
2323
import java.time.temporal.TemporalAdjusters;
2424
import java.util.ArrayList;
25+
import java.util.Comparator;
2526
import java.util.List;
2627
import java.util.Optional;
2728
import lombok.RequiredArgsConstructor;
@@ -77,7 +78,7 @@ public ActionChange findMostIncreasedPositiveActionChange(Long memberId, Long ro
7778
NumberExpression<Long> lastMonthNotes = countLastMonthNotes(today);
7879
NumberExpression<Long> increaseCount = thisMonthNotes.subtract(lastMonthNotes);
7980

80-
return queryFactory
81+
List<ActionChange> results = queryFactory
8182
.select(new QActionChange(action, increaseCount.longValue()))
8283
.from(note)
8384
.join(note.action, action)
@@ -86,8 +87,12 @@ public ActionChange findMostIncreasedPositiveActionChange(Long memberId, Long ro
8687
.and(isReceiver(memberId))
8788
.and(actionCategory.emotionType.eq(EmotionType.POSITIVE)))
8889
.groupBy(action)
89-
.orderBy(increaseCount.desc())
90-
.fetchFirst();
90+
.fetch();
91+
92+
return results.stream()
93+
.sorted(Comparator.comparing(ActionChange::getChange).reversed())
94+
.findFirst()
95+
.orElse(null);
9196
}
9297

9398
@Override
@@ -97,7 +102,7 @@ public ActionChange findMostDecreasedNegativeActionChange(Long memberId, Long ro
97102
NumberExpression<Long> lastMonthNotes = countLastMonthNotes(today);
98103
NumberExpression<Long> decreaseCount = thisMonthNotes.subtract(lastMonthNotes);
99104

100-
return queryFactory
105+
List<ActionChange> results = queryFactory
101106
.select(new QActionChange(action, decreaseCount.longValue()))
102107
.from(note)
103108
.join(note.action, action)
@@ -106,8 +111,12 @@ public ActionChange findMostDecreasedNegativeActionChange(Long memberId, Long ro
106111
.and(isReceiver(memberId))
107112
.and(actionCategory.emotionType.eq(EmotionType.NEGATIVE)))
108113
.groupBy(action)
109-
.orderBy(decreaseCount.asc())
110-
.fetchFirst();
114+
.fetch();
115+
116+
return results.stream()
117+
.sorted(Comparator.comparing(ActionChange::getChange))
118+
.findFirst()
119+
.orElse(null);
111120
}
112121

113122
@Override

0 commit comments

Comments
 (0)