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

Typescript Refactor (V2) #127

Merged
merged 20 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
10 changes: 6 additions & 4 deletions backend/src/main/java/com/mcmasterbaja/FileAnalyzeResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mcmasterbaja.exceptions.InvalidArgumentException;
import com.mcmasterbaja.live.Serial;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.MinMax;
import com.mcmasterbaja.services.FileMetadataService;
import com.mcmasterbaja.services.StorageService;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -67,21 +68,22 @@ public RestResponse<File> runAnalyzer(@BeanParam AnalyzerParams params) {

@GET
@jakarta.ws.rs.Path("minMax/{filekey}")
public Double[] getMinMax(
public MinMax getMinMax(
@PathParam("filekey") String filekey, @QueryParam("column") String column) {
logger.info("Getting min and max for file: " + filekey);

String typeFolder = fileMetadataService.getTypeFolder(Paths.get(filekey));
Path targetPath = storageService.load(Paths.get(typeFolder)).resolve(filekey);
Double[] minMax = fileMetadataService.getMinMax(targetPath, column);
MinMax minMax = fileMetadataService.getMinMax(targetPath, column);

return minMax;
}

@PATCH
@jakarta.ws.rs.Path("togglelive")
public String toggleLive() {
public Boolean toggleLive() {
logger.info("Toggling live data to: " + Serial.exit);
Boolean exit = Serial.exit;

if (!Serial.exit) {
Serial.exit = true;
Expand All @@ -93,6 +95,6 @@ public String toggleLive() {
.start();
}

return "Live data toggled to " + Serial.exit;
return exit;
}
}
12 changes: 6 additions & 6 deletions backend/src/main/java/com/mcmasterbaja/FileDeleteResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ public class FileDeleteResource {

@DELETE
@jakarta.ws.rs.Path("/file/{filekey}")
public String deleteFile(@PathParam("filekey") String filekey) {
public void deleteFile(@PathParam("filekey") String filekey) {
logger.info("Deleting file: " + filekey);

Path targetPath = Paths.get(filekey);
storageService.delete(targetPath);

return "File deleted successfully";
return;
}

@DELETE
@jakarta.ws.rs.Path("/folder/{folderkey}")
public String deleteFolder(@PathParam("folderkey") String folderkey) {
public void deleteFolder(@PathParam("folderkey") String folderkey) {
logger.info("Deleting folder: " + folderkey);

Path targetPath = Paths.get(folderkey);
storageService.deleteAll(targetPath);

return "All files deleted successfully";
return;
}

@DELETE
@jakarta.ws.rs.Path("/all")
public String deleteAllFiles() {
public void deleteAllFiles() {
logger.info("Deleting all files");

storageService.deleteAll();
storageService.init();

return "All files deleted successfully";
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FileUploadResource {
@POST
@jakarta.ws.rs.Path("/file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String uploadFile(
public void uploadFile(
@RestForm("fileName") String fileName,
@RestForm("fileData") @PartType(MediaType.APPLICATION_OCTET_STREAM) InputStream fileData) {

Expand Down Expand Up @@ -71,7 +71,5 @@ public String uploadFile(
}
throw new IllegalArgumentException("Invalid filetype: " + fileExtension);
}

return "File uploaded successfully";
}
}
16 changes: 16 additions & 0 deletions backend/src/main/java/com/mcmasterbaja/model/MinMax.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mcmasterbaja.model;

import lombok.Getter;
import lombok.ToString;

@ToString
@Getter
public class MinMax {
private final Double min;
private final Double max;

public MinMax(Double min, Double max) {
this.min = min;
this.max = max;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mcmasterbaja.exceptions.FileNotFoundException;
import com.mcmasterbaja.exceptions.MalformedCsvException;
import com.mcmasterbaja.exceptions.StorageException;
import com.mcmasterbaja.model.MinMax;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.io.BufferedReader;
Expand Down Expand Up @@ -49,7 +50,7 @@ public long getSize(Path targetPath) {
}
}

public Double[] getMinMax(Path targetPath, String column) {
public MinMax getMinMax(Path targetPath, String column) {
int columnIndex = -1;
Double min = Double.MAX_VALUE;
Double max = Double.MIN_VALUE;
Expand Down Expand Up @@ -92,7 +93,7 @@ public Double[] getMinMax(Path targetPath, String column) {
"Failed to get min max of file: " + targetPath.toString(), targetPath.toString(), e);
}

return new Double[] {min, max};
return new MinMax(min, max);
}

public String getLast(Path targetPath, int columnIndex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mcmasterbaja.services;

import com.mcmasterbaja.model.MinMax;
import java.nio.file.Path;
import java.time.LocalDateTime;

Expand All @@ -26,9 +27,9 @@ public interface FileMetadataService {
*
* @param targetPath The Path of the file to read.
* @param column The column to analyze.
* @return A double[] containing the minimum and maximum values.
* @return A MinMax object containing the minimum and maximum values.
*/
Double[] getMinMax(Path targetPath, String column);
MinMax getMinMax(Path targetPath, String column);

/**
* Gets the last value of the column in the file.
Expand Down
51 changes: 0 additions & 51 deletions front-end/.eslintrc.js

This file was deleted.

12 changes: 12 additions & 0 deletions front-end/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

// TODO: Consider linting with type information
// https://typescript-eslint.io/getting-started/typed-linting
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strict,
...tseslint.configs.stylistic,
);
Loading
Loading