Skip to content

Conversation

@Jadev03
Copy link

@Jadev03 Jadev03 commented Feb 10, 2026

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

Copy link

Copilot AI left a 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> and FolderContentItemDto for paged folder listings.
  • Adds FolderService#getFolderContentPage(...) to list, sort, and paginate directory entries.
  • Adds GET /api/folders/content endpoint in FolderController and 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.

Comment on lines +73 to +76
throw new IllegalArgumentException("page must be greater than or equal to 0");
}
if (size <= 0) {
throw new IllegalArgumentException("size must be greater than 0");
Copy link

Copilot AI Feb 11, 2026

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.

Suggested change
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");

Copilot uses AI. Check for mistakes.
Copy link
Author

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.

@DenizAltunkapan
Copy link
Member

@Jadev03
Please resolve the merge conflicts on the branch and fix the failing workflows.
Also review Copilot’s comments and apply the suggestions where they make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants