Skip to content

Commit c4aaeee

Browse files
committed
file service
1 parent 0005b13 commit c4aaeee

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

rsa-backend/src/main/java/com/example/rsa/controller/FileController.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.example.rsa.controller;
22

3+
import com.example.rsa.model.RsaFile;
34
import com.example.rsa.service.FileService;
5+
import io.swagger.v3.oas.annotations.Operation;
46
import org.springframework.beans.factory.annotation.Autowired;
57
import org.springframework.http.ResponseEntity;
68
import org.springframework.web.bind.annotation.*;
79
import org.springframework.web.multipart.MultipartFile;
810

11+
import java.math.BigInteger;
12+
import java.util.List;
13+
914
@RestController
10-
@RequestMapping("/upload")
15+
@RequestMapping("/file")
1116
public class FileController {
1217

1318

@@ -24,4 +29,10 @@ public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFi
2429
return ResponseEntity.status(500).body("Error during file encryption: " + e.getMessage());
2530
}
2631
}
32+
33+
@Operation(summary = "Get public key")
34+
@GetMapping("/all")
35+
public List<RsaFile> allFiles() {
36+
return fileService.getAllFiles();
37+
}
2738
}

rsa-backend/src/main/java/com/example/rsa/model/RsaFile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public class RsaFile {
99
private String name;
1010
private Integer ownerId;
1111
private Integer recipientId;
12+
private Long size;
13+
1214
}

rsa-backend/src/main/java/com/example/rsa/service/FileService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public void saveFile(MultipartFile file,Integer userId,Integer recipientId) thro
2626

2727

2828
//byte[] encryptedFile = encryptionService.encryptFile(file.getBytes());
29+
long fileSize = file.getSize();
2930
String directory = "encrypted_files/";
3031
String filename = file.getOriginalFilename();
3132
Path filePath = Paths.get(directory + filename);
@@ -34,10 +35,11 @@ public void saveFile(MultipartFile file,Integer userId,Integer recipientId) thro
3435
Files.write(filePath, file.getBytes());
3536
System.out.println("Encrypted file saved: " + file.getOriginalFilename());
3637

37-
RsaFile newFile = null;
38+
RsaFile newFile = new RsaFile();
3839
newFile.setId(files.size()+1);
3940
newFile.setName(file.getOriginalFilename());
4041
newFile.setOwnerId(userId);
42+
newFile.setSize(fileSize);
4143
newFile.setRecipientId(recipientId);
4244
files.add(newFile);
4345
System.out.println(getAllFiles());

0 commit comments

Comments
 (0)