Skip to content

[Feature]: Add backend API for bulk file and folder operations #92#94

Open
IrfanSyed0721 wants to merge 3 commits into
Vault-Web:mainfrom
IrfanSyed0721:main
Open

[Feature]: Add backend API for bulk file and folder operations #92#94
IrfanSyed0721 wants to merge 3 commits into
Vault-Web:mainfrom
IrfanSyed0721:main

Conversation

@IrfanSyed0721

Copy link
Copy Markdown

Summary

Implemented the backend API contract for bulk file and folder operations to support multi-select functionality.

  • Updated the bulk delete endpoint to return an itemized success/failure status map.
  • Added inner try-catch exception handling within the loops so that individual invalid paths or missing files don't break the entire request.
  • Implemented a brand new bulk move endpoint ('/bulk/move') using existing file service logic to migrate multiple files/folders simultaneously.
  • Added contract validation coverage to 'Application Tests'.

Linked issue

Closes #92

@DenizAltunkapan DenizAltunkapan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the work here @IrfanSyed0721. The direction is good, the per-item success/failure map with an inner try-catch is exactly the right pattern for bulk operations. There are a few things I would like fixed before this can be merged. I left inline notes on each one.

fileService.renameOrMoveFile(user.getRootFolderPath(), filePath, newPath);
java.util.Map<String, String> results = new java.util.LinkedHashMap<>();
for (String filePath : filePaths) {
try {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@IrfanSyed0721 This replaces the existing single-file @PatchMapping("/move") route instead of adding the bulk one next to it. The old rename/move endpoint is now gone, which will break the frontend that still calls it. Please keep /move and add /bulk as a separate method.

} catch (Exception e) {
results.put(filePath, "FAILED: " + e.getMessage());
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@IrfanSyed0721 The catch returns e.getMessage() straight to the client. On this kind of storage service that can leak internal paths or details. Please map failures to a safe, generic message instead of exposing the raw exception text.

Files.deleteIfExists(file);
}

public java.util.Map<String, String> deleteFiles(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@IrfanSyed0721 This new deleteFiles method is never called anywhere. The bulk delete controller runs its own loop over trashService.moveToTrash instead, so we end up with two different delete paths and this one is dead code. Either wire the controller to this service method or drop it.

fileService.renameOrMoveFile(
user.getRootFolderPath(),
filePath,
targetPath + "/" + new java.io.File(filePath).getName());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@IrfanSyed0721 The target path is built by string concatenation (targetPath + "/" + ...) and only gets validated deep inside renameOrMoveFile. Please build it with Paths and rely on the existing validatePath so traversal cannot slip through. Also catch (Exception e) is too broad here, it hides real bugs as "FAILED", so narrow it to the IO case.

void contextLoads() {}

@org.junit.jupiter.api.Test
public void testBulkOperationsContract() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@IrfanSyed0721 This test builds a map by hand and then asserts on the values it just put in, so no production code runs. It always passes even if the endpoints are broken. Please turn it into a real test that calls the controller or service with a temp folder and checks the actual result. Minor: prefer the imported names over fully qualified ones like java.util.Map and org.junit.jupiter.api.Test to match the rest of the file.

@IrfanSyed0721

Copy link
Copy Markdown
Author

Thanks for the feedback, Deniz. I am currently traveling in India and won't have access to work on this for the next two weeks. I'll dive right into these fixes as soon as I get back!

@DenizAltunkapan

Copy link
Copy Markdown
Member

@IrfanSyed0721 okay no problem

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.

[Feature]: Add backend API for bulk file and folder operations

2 participants