1
0
forked from PGL/Clyde

Remove the bad link between users and file. Add a delete function for storageFile entities and clean things.

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; package ovh.herisson.Clyde.EndPoints;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Repositories.TokenRepository;
import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Services.TokenService; import ovh.herisson.Clyde.Services.TokenService;
import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.*;
import ovh.herisson.Clyde.Tables.Token;
import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
@RestController @RestController
@ -26,6 +20,7 @@ public class MockController {
public final UserRepository userRepo; public final UserRepository userRepo;
public final TokenRepository tokenRepo; public final TokenRepository tokenRepo;
public final TokenService tokenService; public final TokenService tokenService;
ArrayList<User> mockUsers; ArrayList<User> mockUsers;
@ -62,3 +57,4 @@ public class MockController {
userRepo.deleteAll(mockUsers); userRepo.deleteAll(mockUsers);
} }
} }

View File

@ -23,7 +23,7 @@ public class StorageController {
@PostMapping("/upload/{fileType}") @PostMapping("/upload/{fileType}")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file, @PathVariable FileType 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); 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;} if (file.getOriginalFilename().isEmpty()){return null;}
@ -52,7 +52,7 @@ public class StorageService {
String url = this.rootLocation.resolve(Paths.get(Objects.requireNonNull(stringUuid))) String url = this.rootLocation.resolve(Paths.get(Objects.requireNonNull(stringUuid)))
.normalize().toString(); .normalize().toString();
fileRepo.save(new StorageFile(file.getName(),url, fileType, user, request)); fileRepo.save(new StorageFile(file.getName(),url, fileType));
return url; return url;
} }

View File

@ -16,22 +16,10 @@ public class StorageFile {
private FileType fileType; private FileType fileType;
public StorageFile(String name, String url, 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){
this.name = name; this.name = name;
this.url = url; this.url = url;
this.fileType = fileType; this.fileType = fileType;
this.user = user;
this.request = request;
} }
public StorageFile(){} public StorageFile(){}
@ -69,19 +57,4 @@ public class StorageFile {
this.fileType = fileType; 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;
}
} }