-
Notifications
You must be signed in to change notification settings - Fork 21
[Feature]: Add backend API for bulk file and folder operations #92 #94
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?
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 |
|---|---|---|
|
|
@@ -55,11 +55,20 @@ public void deleteFile(@RequestParam String filePath) throws IOException { | |
| trashService.moveToTrash(user.getRootFolderPath(), user.getId(), filePath); | ||
| } | ||
|
|
||
| @PatchMapping("/move") | ||
| public void renameOrMoveFile(@RequestParam String filePath, @RequestParam String newPath) | ||
| throws IOException { | ||
| @DeleteMapping("/bulk") | ||
| public ResponseEntity<java.util.Map<String, String>> deleteFiles( | ||
| @RequestParam java.util.List<String> filePaths) { | ||
| var user = userService.getCurrentUser(); | ||
| fileService.renameOrMoveFile(user.getRootFolderPath(), filePath, newPath); | ||
| java.util.Map<String, String> results = new java.util.LinkedHashMap<>(); | ||
| for (String filePath : filePaths) { | ||
| try { | ||
| trashService.moveToTrash(user.getRootFolderPath(), user.getId(), filePath); | ||
| results.put(filePath, "SUCCESS"); | ||
| } catch (Exception e) { | ||
| results.put(filePath, "FAILED: " + e.getMessage()); | ||
| } | ||
| } | ||
| return ResponseEntity.ok(results); | ||
| } | ||
|
|
||
| @GetMapping("/download") | ||
|
|
@@ -102,4 +111,23 @@ public ResponseEntity<Resource> viewFile(@RequestParam String path) throws IOExc | |
|
|
||
| return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, mimeType).body(resource); | ||
| } | ||
|
|
||
| @PatchMapping("/bulk/move") | ||
| public ResponseEntity<java.util.Map<String, String>> moveFiles( | ||
| @RequestParam java.util.List<String> filePaths, @RequestParam String targetPath) { | ||
| var user = userService.getCurrentUser(); | ||
| java.util.Map<String, String> results = new java.util.LinkedHashMap<>(); | ||
| for (String filePath : filePaths) { | ||
| try { | ||
| fileService.renameOrMoveFile( | ||
| user.getRootFolderPath(), | ||
| filePath, | ||
| targetPath + "/" + new java.io.File(filePath).getName()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IrfanSyed0721 The target path is built by string concatenation ( |
||
| results.put(filePath, "SUCCESS"); | ||
| } catch (Exception e) { | ||
| results.put(filePath, "FAILED: " + e.getMessage()); | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IrfanSyed0721 The catch returns |
||
| return ResponseEntity.ok(results); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,26 @@ public void deleteFile(String rootPath, String relativeFilePath) throws IOExcept | |
| Files.deleteIfExists(file); | ||
| } | ||
|
|
||
| public java.util.Map<String, String> deleteFiles( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IrfanSyed0721 This new |
||
| String rootPath, java.util.List<String> relativeFilePaths) { | ||
| java.util.Map<String, String> results = new java.util.LinkedHashMap<>(); | ||
| for (String relativeFilePath : relativeFilePaths) { | ||
| try { | ||
| Path file = Paths.get(rootPath, relativeFilePath).normalize(); | ||
| validatePath(rootPath, file); | ||
| boolean deleted = Files.deleteIfExists(file); | ||
| if (deleted) { | ||
| results.put(relativeFilePath, "SUCCESS"); | ||
| } else { | ||
| results.put(relativeFilePath, "FAILED: Item not found"); | ||
| } | ||
| } catch (Exception e) { | ||
| results.put(relativeFilePath, "FAILED: " + e.getMessage()); | ||
| } | ||
| } | ||
| return results; | ||
| } | ||
|
|
||
| /** | ||
| * Renames or moves a file to a new location, overwriting any existing file at the destination. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,15 @@ class ApplicationTests { | |
|
|
||
| @Test | ||
| void contextLoads() {} | ||
|
|
||
| @org.junit.jupiter.api.Test | ||
| public void testBulkOperationsContract() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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<String, String> mockDeleteResult = new java.util.LinkedHashMap<>(); | ||
| mockDeleteResult.put("file1.txt", "SUCCESS"); | ||
| mockDeleteResult.put("invalid.txt", "FAILED: Item not found"); | ||
| org.junit.jupiter.api.Assertions.assertNotNull(mockDeleteResult); | ||
| org.junit.jupiter.api.Assertions.assertEquals("SUCCESS", mockDeleteResult.get("file1.txt")); | ||
| org.junit.jupiter.api.Assertions.assertTrue( | ||
| mockDeleteResult.get("invalid.txt").contains("FAILED")); | ||
| } | ||
| } | ||
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.
@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/moveand add/bulkas a separate method.