-
Notifications
You must be signed in to change notification settings - Fork 12
feat :- folder/file pagination API #49
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?
Conversation
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.
Pull request overview
Adds a new, opt-in API to list a folder’s immediate children as a flat, paginated response with basic sorting, alongside DTOs and initial test coverage at the service layer.
Changes:
- Introduces
PageResponseDto<T>andFolderContentItemDtofor paged folder listings. - Adds
FolderService#getFolderContentPage(...)to list, sort, and paginate directory entries. - Adds
GET /api/folders/contentendpoint inFolderControllerand service-level tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/src/main/java/cloudpage/controller/FolderController.java | Adds /api/folders/content endpoint wiring pagination/sort to service. |
| backend/src/main/java/cloudpage/service/FolderService.java | Implements in-memory listing + sort + pagination for folder children. |
| backend/src/main/java/cloudpage/dto/PageResponseDto.java | New generic pagination response DTO. |
| backend/src/main/java/cloudpage/dto/FolderContentItemDto.java | New DTO representing a single file/folder entry. |
| backend/src/test/java/cloudpage/service/FolderServiceTest.java | Adds unit tests for pagination, sorting, and invalid path handling. |
| backend/src/test/java/cloudpage/controller/FolderControllerTest.java | Adds placeholder controller test file (currently problematic). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
backend/src/test/java/cloudpage/controller/FolderControllerTest.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/cloudpage/controller/FolderController.java
Outdated
Show resolved
Hide resolved
| throw new IllegalArgumentException("page must be greater than or equal to 0"); | ||
| } | ||
| if (size <= 0) { | ||
| throw new IllegalArgumentException("size must be greater than 0"); |
Copilot
AI
Feb 11, 2026
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.
The service throws IllegalArgumentException for invalid pagination params. GlobalExceptionHandler currently doesn't handle IllegalArgumentException, so this will likely return 500 from the API. Prefer throwing an exception that is already mapped to 400 (e.g., InvalidPathException) or add an exception handler for IllegalArgumentException so clients get a proper bad-request response.
| throw new IllegalArgumentException("page must be greater than or equal to 0"); | |
| } | |
| if (size <= 0) { | |
| throw new IllegalArgumentException("size must be greater than 0"); | |
| throw new InvalidPathException("page must be greater than or equal to 0"); | |
| } | |
| if (size <= 0) { | |
| throw new InvalidPathException("size must be greater than 0"); |
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.
The current implementation is correct. Using IllegalArgumentException for pagination validation is appropriate, and the handler ensures clients receive a proper 400 response.
|
@Jadev03 |
… add exception handlers, improve security
Summary
Add pagination and sorting support to the folder listing API by introducing a new endpoint that returns a flat list of folder entries (files and subfolders) instead of the full folder tree.
This change introduces:
A generic PageResponseDto for paginated responses
FolderContentItemDto to represent individual files and subfolders
A new opt-in endpoint for paged folder content with sorting support
issue-16
How to test
1.Basic pagination
GET /api/folders/content?path=&page=0&size=10
Verify:
pageNumber = 0
content.length <= 10
totalElements and totalPages are populated
2.Last page handling
GET /api/folders/content?path=&page=2&size=10
Verify:
Last page returns remaining items
totalPages = ceil(totalElements / size)
3.Sorting
GET /api/folders/content?path=&page=0&size=10&sort=name,asc
Verify:
Items in content are ordered by name ascending
4.Security – path traversal
GET /api/folders/content?path=../outside&page=0&size=10
Verify:
Request is rejected with an error
Path traversal is blocked
Notes / Risk
1.This is an additive change; existing folder tree endpoints are not affected
2.Pagination and sorting are performed in memory on folder children
3.Safe for typical directory sizes, but may be expensive for extremely large folders
4.No migrations or feature flags required