Skip to content

add last modified at#58

Open
nikser871 wants to merge 8 commits intoVault-Web:mainfrom
nikser871:feature/add-last-modified-at
Open

add last modified at#58
nikser871 wants to merge 8 commits intoVault-Web:mainfrom
nikser871:feature/add-last-modified-at

Conversation

@nikser871
Copy link
Copy Markdown

@nikser871 nikser871 commented Mar 24, 2026

fix PR from JoaoCosme:add-last-modified-at

Resolves #14

# Conflicts:
#	backend/src/main/java/cloudpage/dto/FileDto.java
#	backend/src/main/java/cloudpage/dto/FolderDto.java
#	backend/src/main/java/cloudpage/exceptions/FileDeletionException.java
#	backend/src/main/java/cloudpage/service/FolderService.java
Copy link
Copy Markdown

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 lastModifiedAt timestamp field to file/folder DTOs so the backend can expose “last modified” information via the API for frontend display (Issue #14).

Changes:

  • Added lastModifiedAt to FolderDto, FileDto, and FolderContentItemDto.
  • Populated lastModifiedAt from filesystem BasicFileAttributes in FolderService (folder tree + content listing).
  • Updated controller tests to construct updated DTOs with the new field.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
backend/src/main/java/cloudpage/service/FolderService.java Computes and returns lastModifiedAt when building folder trees and folder content pages.
backend/src/main/java/cloudpage/dto/FolderDto.java Adds lastModifiedAt to folder tree responses.
backend/src/main/java/cloudpage/dto/FileDto.java Adds lastModifiedAt to file entries inside folder trees.
backend/src/main/java/cloudpage/dto/FolderContentItemDto.java Adds lastModifiedAt to folder content listing items.
backend/src/main/java/cloudpage/exceptions/FileDeletionException.java Refactors exception class metadata/formatting (adds @Serial).
backend/src/test/java/cloudpage/controller/FolderControllerTest.java Updates test DTO construction to include lastModifiedAt.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +280 to +291
try {
BasicFileAttributes folderAttrs = Files.readAttributes(path, BasicFileAttributes.class);
return new FolderDto(
path.getFileName().toString(),
folderRelativePath,
subfolders,
files,
folderAttrs.lastModifiedTime().toMillis()
);
} catch (IOException e) {
throw new FileAccessException("Failed to read folder attributes: " + path + " with exception: " + e.getMessage());
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added try/catch block is indented inconsistently compared to the rest of this class, which makes the control flow harder to read and suggests an accidental extra nesting level. Please reformat this block to match the file’s existing indentation/style.

Suggested change
try {
BasicFileAttributes folderAttrs = Files.readAttributes(path, BasicFileAttributes.class);
return new FolderDto(
path.getFileName().toString(),
folderRelativePath,
subfolders,
files,
folderAttrs.lastModifiedTime().toMillis()
);
} catch (IOException e) {
throw new FileAccessException("Failed to read folder attributes: " + path + " with exception: " + e.getMessage());
}
try {
BasicFileAttributes folderAttrs = Files.readAttributes(path, BasicFileAttributes.class);
return new FolderDto(
path.getFileName().toString(),
folderRelativePath,
subfolders,
files,
folderAttrs.lastModifiedTime().toMillis()
);
} catch (IOException e) {
throw new FileAccessException("Failed to read folder attributes: " + path + " with exception: " + e.getMessage());
}

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +17
private String name;
private String path;
private List<FolderDto> folders;
private List<FileDto> files;
private long lastModifiedAt;
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation in this DTO is inconsistent with the rest of cloudpage.dto (e.g., PageResponseDto and FileResource use 2-space indents). Please reformat to match the established style for readability and consistency.

Suggested change
private String name;
private String path;
private List<FolderDto> folders;
private List<FileDto> files;
private long lastModifiedAt;
private String name;
private String path;
private List<FolderDto> folders;
private List<FileDto> files;
private long lastModifiedAt;

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +15
private String name;
private String path;
private long size;
private String mimeType;
private long lastModifiedAt;
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation in this DTO is inconsistent with the rest of cloudpage.dto (e.g., PageResponseDto and FileResource use 2-space indents). Please reformat to match the established style for readability and consistency.

Suggested change
private String name;
private String path;
private long size;
private String mimeType;
private long lastModifiedAt;
private String name;
private String path;
private long size;
private String mimeType;
private long lastModifiedAt;

Copilot uses AI. Check for mistakes.
@AutoConfigureMockMvc(addFilters = false)
class FolderControllerTest {

static long FIXED_TIME = 1742824800000L;
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXED_TIME is used as a constant but isn’t declared final (and could be private). Making it private static final prevents accidental mutation and clarifies intent.

Suggested change
static long FIXED_TIME = 1742824800000L;
private static final long FIXED_TIME = 1742824800000L;

Copilot uses AI. Check for mistakes.
Comment on lines 165 to 171
@Test
void getFolderContent_validRequest_returnsPageResponse() throws Exception {
List<FolderContentItemDto> content =
Arrays.asList(
new FolderContentItemDto("file1.txt", "file1.txt", false, 100L, "text/plain"),
new FolderContentItemDto("file2.txt", "file2.txt", false, 200L, "text/plain"));
new FolderContentItemDto("file1.txt", "file1.txt", false, 100L, "text/plain", FIXED_TIME),
new FolderContentItemDto("file2.txt", "file2.txt", false, 200L, "text/plain", FIXED_TIME));
PageResponseDto<FolderContentItemDto> pageResponse = new PageResponseDto<>(content, 2L, 1, 0);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests were updated to construct DTOs with lastModifiedAt, but the controller JSON assertions don’t validate that this new field is present/serialized (or has the expected value). Add jsonPath assertions for lastModifiedAt on representative responses so regressions are caught.

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +17
/**
* class to handle File Deletion Exception
*/
public class FileDeletionException extends RuntimeException {
private static final long serialVersionUID = 1L;

FileDeletionException() {}
@Serial
private static final long serialVersionUID = 1L;

FileDeletionException() {}

public FileDeletionException(String message) {
super(message);
}
public FileDeletionException(String message) {
super(message);
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation in this exception class is inconsistent with the other exceptions in cloudpage.exceptions (they use 2-space indents, e.g., FileAccessException). Please reformat to match the established style.

Copilot uses AI. Check for mistakes.
Comment on lines 122 to +147
boolean isDirectory = Files.isDirectory(path);
long sizeValue = 0L;
String mimeType = null;
long lastModifiedAt = 0L;
if (!isDirectory) {
try {
BasicFileAttributes attrs =
Files.readAttributes(path, BasicFileAttributes.class);
sizeValue = attrs.size();
mimeType = Files.probeContentType(path);
lastModifiedAt = attrs.lastModifiedTime().toMillis();
} catch (IOException e) {
throw new FileAccessException(
"Failed to read file attributes: "
+ path
+ " with exception: "
+ e.getMessage());
}
}
return new FolderContentItemDto(
path.getFileName().toString(),
itemRelativePath,
isDirectory,
sizeValue,
mimeType);
mimeType,
lastModifiedAt);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastModifiedAt is only populated for non-directories. For directory entries returned by getFolderContentPage, it will always be 0, which doesn’t satisfy the “folders last modified” requirement and can mislead the frontend. Read attributes for directories too (and set lastModifiedAt regardless of isDirectory).

Copilot uses AI. Check for mistakes.
@DenizAltunkapan
Copy link
Copy Markdown
Member

@nikser871 please format your code and review copilots comments

@DenizAltunkapan DenizAltunkapan force-pushed the main branch 2 times, most recently from d8a0ddc to ba26f56 Compare March 27, 2026 09:55
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.

Add last modified date field to files and folders

3 participants