Skip to content

Commit

Permalink
[FIX] UnsupportedOperationException 해결
Browse files Browse the repository at this point in the history
`removeLast()` 대신 인덱싱을 활용해 제거하도록 변경
  • Loading branch information
Profile-exe authored Jul 25, 2024
1 parent 0646bc6 commit 46255d3
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,35 @@ public MatchingCustomPage findMatchings(Long memberId, Integer size, LocalDateTi
.fetch();

List<MatchingResDto> matchingResDtos = matchings.stream()
.map(matching1 -> {
.map(matching -> {
ChatMessage lastMessage = queryFactory
.selectFrom(chatMessage)
.where(chatMessage.matching.id.eq(matching1.getId()))
.where(chatMessage.matching.id.eq(matching.getId()))
.orderBy(chatMessage.createdAt.desc())
.limit(1)
.fetchOne();

Long receiverId = memberId.equals(matching1.getTaker().getId()) ? matching1.getGiver().getId() : matching1.getTaker().getId();
Long receiverId = memberId.equals(matching.getTaker().getId()) ? matching.getGiver().getId() : matching.getTaker().getId();
Member receiver = queryFactory
.selectFrom(member)
.where(member.id.eq(receiverId))
.fetchOne();

return new MatchingResDto(
matching1.getId(),
matching1.getPost().getPostType(),
matching1.getPost().getId(),
matching.getId(),
matching.getPost().getPostType(),
matching.getPost().getId(),
lastMessage.getContent(),
lastMessage.getCreatedAt(),
lastMessage.getMessageType(),
matching1.getMatchingStatus(),
matching.getMatchingStatus(),
new ReceiverDto(receiver)
);
}).toList();

boolean nextPage = false;
if (matchingResDtos.size() > pageSize) {
matchingResDtos.removeLast();
matchingResDtos.remove(matchingResDtos.size() - 1);
nextPage = true;
}

Expand All @@ -90,4 +90,4 @@ private BooleanExpression buildCursorExpression(LocalDateTime cursor) {
private BooleanExpression buildMatchingStatusExpression(MatchingStatus matchingStatus) {
return matchingStatus == null ? null : matching.matchingStatus.eq(matchingStatus);
}
}
}

0 comments on commit 46255d3

Please sign in to comment.