From 8fbfb3695811756250bceed5efc3e5ec66995d27 Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Tue, 12 Mar 2024 10:48:13 +0100 Subject: [PATCH] Remove the bad link between users and file. Add a delete function for storageFile entities and clean things. --- .../Clyde/EndPoints/MockController.java | 12 +++----- .../Clyde/EndPoints/StorageController.java | 2 +- .../Clyde/Services/StorageService.java | 4 +-- .../herisson/Clyde/Tables/StorageFile.java | 29 +------------------ 4 files changed, 8 insertions(+), 39 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index b140057..787a534 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -1,20 +1,14 @@ package ovh.herisson.Clyde.EndPoints; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Services.TokenService; -import ovh.herisson.Clyde.Tables.Role; -import ovh.herisson.Clyde.Tables.Token; -import ovh.herisson.Clyde.Tables.User; +import ovh.herisson.Clyde.Tables.*; import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; import java.util.Date; @RestController @@ -26,6 +20,7 @@ public class MockController { public final UserRepository userRepo; public final TokenRepository tokenRepo; public final TokenService tokenService; + ArrayList mockUsers; @@ -62,3 +57,4 @@ public class MockController { userRepo.deleteAll(mockUsers); } } + diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/StorageController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/StorageController.java index be58f17..2a36657 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/StorageController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/StorageController.java @@ -23,7 +23,7 @@ public class StorageController { @PostMapping("/upload/{fileType}") public ResponseEntity handleFileUpload(@RequestParam("file") MultipartFile file, @PathVariable FileType fileType) { - String path = storageServ.store(file,fileType, null, null); + String path = storageServ.store(file,fileType); if (path == null) return new ResponseEntity<>("issue with the file storage", HttpStatus.BAD_REQUEST); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java index eeea9e3..36e39ca 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java @@ -30,7 +30,7 @@ public class StorageService { } - public String store(MultipartFile file, FileType fileType, User user, InscriptionRequest request) { + public String store(MultipartFile file, FileType fileType) { if (file.getOriginalFilename().isEmpty()){return null;} @@ -52,7 +52,7 @@ public class StorageService { String url = this.rootLocation.resolve(Paths.get(Objects.requireNonNull(stringUuid))) .normalize().toString(); - fileRepo.save(new StorageFile(file.getName(),url, fileType, user, request)); + fileRepo.save(new StorageFile(file.getName(),url, fileType)); return url; } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/StorageFile.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/StorageFile.java index 4124231..afa7985 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/StorageFile.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/StorageFile.java @@ -16,22 +16,10 @@ public class StorageFile { private FileType fileType; - - //Pour lier un user ou une demande d'inscription au fichier - @ManyToOne - @JoinColumn(name = "user") - private User user; - - @ManyToOne - @JoinColumn(name = "inscriptionrequest") - private InscriptionRequest request; - - public StorageFile(String name, String url, FileType fileType, User user, InscriptionRequest request){ + public StorageFile(String name, String url, FileType fileType){ this.name = name; this.url = url; this.fileType = fileType; - this.user = user; - this.request = request; } public StorageFile(){} @@ -69,19 +57,4 @@ public class StorageFile { this.fileType = fileType; } - public void setUser(User user) { - this.user = user; - } - - public User getUser() { - return user; - } - - public void setRequest(InscriptionRequest request) { - this.request = request; - } - - public InscriptionRequest getRequest() { - return request; - } }