Remove the bad link between users and file. Add a delete function for storageFile entities and clean things.
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m0s
Build and test backend / Test-backend (pull_request) Successful in 1m57s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 24s

This commit is contained in:
LeoMoulin 2024-03-12 10:48:13 +01:00
parent ab91a39a63
commit 8fbfb36958
4 changed files with 8 additions and 39 deletions

View File

@ -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<User> mockUsers;
@ -62,3 +57,4 @@ public class MockController {
userRepo.deleteAll(mockUsers);
}
}

View File

@ -23,7 +23,7 @@ public class StorageController {
@PostMapping("/upload/{fileType}")
public ResponseEntity<String> 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);

View File

@ -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;
}

View File

@ -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;
}
}