Skip to content
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

IMU Feature #142

Merged
merged 25 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.bin filter=lfs diff=lfs merge=lfs -text
*.csv filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text
23 changes: 21 additions & 2 deletions backend/src/main/java/com/mcmasterbaja/FileFetchResource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mcmasterbaja;

import com.mcmasterbaja.exceptions.FileNotFoundException;
import com.mcmasterbaja.model.FileInformation;
import com.mcmasterbaja.model.FileTimespan;
import com.mcmasterbaja.services.FileMetadataService;
Expand All @@ -10,6 +11,7 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -39,13 +41,14 @@ public List<String> getAllFiles() {
return fileNames;
}

// TODO: What exception is thrown when it can't find the file?
@GET
@jakarta.ws.rs.Path("/{filekey}")
public File getFile(@PathParam("filekey") String filekey) {
logger.info("Getting file: " + filekey);

Path targetPath = addTypeFolder(filekey);
if (!Files.exists(targetPath)) {
throw new FileNotFoundException("File not found: " + filekey);
}
File file = storageService.load(targetPath).toFile();

return file;
Expand Down Expand Up @@ -107,6 +110,22 @@ public List<FileInformation> getInformationForFolder(@PathParam("folderkey") Str
return fileInformationList;
}

@GET
@jakarta.ws.rs.Path("/listBins")
public List<String> getFolders() {
logger.info("Getting all folders");

Path dir = Paths.get("csv");

List<String> folderNames =
storageService
.loadDirectories(dir)
.map(path -> path.toString().replace("\\", "/"))
.collect(Collectors.toList());

return folderNames;
}

@GET
@jakarta.ws.rs.Path("/timespan/folder/{folderkey}")
public List<FileTimespan> getTimespan(@PathParam("folderkey") String folderkey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ public Stream<Path> loadAll() {
return loadAll(rootLocation);
}

public Stream<Path> loadDirectories(Path dir) {
Path directory = rootLocation.resolve(dir);
try {
return Files.walk(rootLocation.resolve(dir), 1)
.filter(path -> Files.isDirectory(path) && !path.equals(rootLocation.resolve(dir)))
.map(directory::relativize);
} catch (IOException e) {
throw new FileNotFoundException(
"Could not list directories inside directory: " + dir.toString(), e);
}
}

public void delete(Path targetPath) {
try {
Files.delete(rootLocation.resolve(targetPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public interface StorageService {
*/
Stream<Path> loadAll(Path dir);

/**
* Loads all directories in the root location.
*
* @param dir The directory to load directories from.
* @return A Stream of Paths representing the directories.
*/
Stream<Path> loadDirectories(Path dir);

/**
* Deletes a file.
*
Expand Down
3 changes: 2 additions & 1 deletion front-end/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default tseslint.config(
'error',
2,
{ 'SwitchCase': 1 }
]
],
'unused-vars': 'warn',
}}
);
Loading
Loading