Skip to content

Commit

Permalink
Merge pull request #61 from catchroom/develop
Browse files Browse the repository at this point in the history
Feat : ์ฑ„ํŒ…๋‚ด์—ญ๋ถˆ๋Ÿฌ์˜ค๊ธฐ Paging ์ˆœ์„œ ๋ณ€๊ฒฝ
  • Loading branch information
HyemIin authored Jan 25, 2024
2 parents 973cdf2 + 824bd85 commit b4008fa
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.catchroom.chat.message.entity.ChatMessage;
import com.catchroom.chat.message.repository.ChatMessageRepository;
import com.catchroom.chat.message.type.MessageType;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -50,7 +53,7 @@ public List<ChatMessageDto> findAll(String roomId,Integer pageNumber) {


private Page<ChatMessage> findByRoomIdWithPaging(String roomId, int page, int size) {
Pageable pageable = PageRequest.of(page,size, Sort.by(Sort.Direction.ASC,"time"));
Pageable pageable = PageRequest.of(page,size,Sort.by(Sort.Direction.DESC,"time"));

Query query = new Query()
.with(pageable)
Expand All @@ -60,6 +63,7 @@ private Page<ChatMessage> findByRoomIdWithPaging(String roomId, int page, int si
query.addCriteria(Criteria.where("roomId").is(roomId));

List<ChatMessage> filteredChatMessage = mongoTemplate.find(query, ChatMessage.class, "chat");
Collections.sort(filteredChatMessage, Comparator.comparing(ChatMessage::getTime));
return PageableExecutionUtils.getPage(
filteredChatMessage,
pageable,
Expand Down

0 comments on commit b4008fa

Please sign in to comment.