-
Notifications
You must be signed in to change notification settings - Fork 5
Added Pagination #32
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
base: main
Are you sure you want to change the base?
Added Pagination #32
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||
| package com.fredmaina.chatapp.core.DTOs; | ||||||
|
|
||||||
| import lombok.AllArgsConstructor; | ||||||
| import lombok.Data; | ||||||
|
|
||||||
| import java.util.List; | ||||||
|
|
||||||
| @Data | ||||||
| @AllArgsConstructor | ||||||
| public class PaginationDto { | ||||||
|
||||||
| public class PaginationDto { | |
| public class ChatHistoryPageDto { |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |||||||||||||||
|
|
||||||||||||||||
| import com.fredmaina.chatapp.Auth.Models.User; | ||||||||||||||||
| import com.fredmaina.chatapp.core.models.ChatMessage; | ||||||||||||||||
| import org.springframework.data.domain.Page; | ||||||||||||||||
| import org.springframework.data.domain.Pageable; | ||||||||||||||||
| import org.springframework.data.jpa.repository.JpaRepository; | ||||||||||||||||
| import org.springframework.data.jpa.repository.Modifying; | ||||||||||||||||
| import org.springframework.data.jpa.repository.Query; | ||||||||||||||||
|
|
@@ -24,8 +26,9 @@ public interface ChatMessageRepository extends JpaRepository<ChatMessage, UUID> | |||||||||||||||
| "OR " + | ||||||||||||||||
| "(m.toSessionId = :sessionId AND m.fromUser.id = :recipientId) " + | ||||||||||||||||
| "ORDER BY m.timestamp") | ||||||||||||||||
|
Comment on lines
27
to
28
|
||||||||||||||||
| "(m.toSessionId = :sessionId AND m.fromUser.id = :recipientId) " + | |
| "ORDER BY m.timestamp") | |
| "(m.toSessionId = :sessionId AND m.fromUser.id = :recipientId)") |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent parameter formatting. The Pageable pageable parameter should be on the same line as the previous parameter or consistently indented. The comma-space before Pageable should follow the same pattern as line 30.
| Page<ChatMessage> findFullChatHistory(@Param("sessionId") String sessionId, | |
| @Param("recipientId") UUID recipientId | |
| , Pageable pageable); | |
| Page<ChatMessage> findFullChatHistory( | |
| @Param("sessionId") String sessionId, | |
| @Param("recipientId") UUID recipientId, | |
| Pageable pageable); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,11 +5,16 @@ | |||||||||||||||||||||||||
| import com.fredmaina.chatapp.core.DTOs.ChatMessageDto; | ||||||||||||||||||||||||||
| import com.fredmaina.chatapp.core.DTOs.ChatMessageMapper; | ||||||||||||||||||||||||||
| import com.fredmaina.chatapp.core.DTOs.ChatSessionDto; | ||||||||||||||||||||||||||
| import com.fredmaina.chatapp.core.DTOs.PaginationDto; | ||||||||||||||||||||||||||
| import com.fredmaina.chatapp.core.Repositories.ChatMessageRepository; | ||||||||||||||||||||||||||
| import com.fredmaina.chatapp.core.models.ChatMessage; | ||||||||||||||||||||||||||
| import lombok.extern.slf4j.Slf4j; | ||||||||||||||||||||||||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||||||||||||||||||||||||
| import org.springframework.cache.annotation.Cacheable; | ||||||||||||||||||||||||||
| import org.springframework.data.domain.Page; | ||||||||||||||||||||||||||
| import org.springframework.data.domain.PageRequest; | ||||||||||||||||||||||||||
| import org.springframework.data.domain.Pageable; | ||||||||||||||||||||||||||
| import org.springframework.data.domain.Sort; | ||||||||||||||||||||||||||
| import org.springframework.stereotype.Service; | ||||||||||||||||||||||||||
| import org.springframework.transaction.annotation.Transactional; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -73,17 +78,27 @@ public List<ChatSessionDto> getUserChatSessions(UUID userId) { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Transactional | ||||||||||||||||||||||||||
| public List<ChatMessageDto> getChatHistoryForAnonymous(String sessionId, String recipientUsername) { | ||||||||||||||||||||||||||
| public PaginationDto getChatHistoryForAnonymous(String sessionId, String recipientUsername, | ||||||||||||||||||||||||||
| int page,int size) { | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| int page,int size) { | |
| int page,int size) { | |
| // Validate page and size parameters | |
| if (page < 0) { | |
| throw new IllegalArgumentException("Page index must not be negative: " + page); | |
| } | |
| int MAX_PAGE_SIZE = 100; | |
| if (size <= 0 || size > MAX_PAGE_SIZE) { | |
| throw new IllegalArgumentException("Page size must be between 1 and " + MAX_PAGE_SIZE + ": " + size); | |
| } |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after comma in the parameter list. Should be int page, int size instead of int page,int size for consistency with Java formatting conventions.
| int page,int size) { | |
| int page, int size) { |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after commas in method call. Should be findFullChatHistory(sessionId, recipient.getId(), pageable) instead of findFullChatHistory(sessionId,recipient.getId(),pageable) for consistency with Java formatting conventions.
| Page<ChatMessage> messages = chatMessageRepository.findFullChatHistory(sessionId,recipient.getId(),pageable); | |
| Page<ChatMessage> messages = chatMessageRepository.findFullChatHistory(sessionId, recipient.getId(), pageable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation. The
@RequestParamannotation on line 68 has extra leading spaces compared to the@RequestParamon line 69, making the parameter list formatting inconsistent.