Leo/Backend #95

Merged
tonitch merged 6 commits from Leo/Backend into master 2024-03-13 18:06:35 +01:00
3 changed files with 3 additions and 9 deletions
Showing only changes of commit 2a58c335f2 - Show all commits

View File

@ -41,3 +41,4 @@ tasks.register("run") {
tasks.withType<Test> { tasks.withType<Test> {
useJUnitPlatform() useJUnitPlatform()
} }

View File

@ -1,4 +0,0 @@
package ovh.herisson.Clyde.Exceptions;
public class CouldntDeleteFileException extends Exception{
}

View File

@ -1,15 +1,12 @@
package ovh.herisson.Clyde.Services; package ovh.herisson.Clyde.Services;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import ovh.herisson.Clyde.Exceptions.CouldntDeleteFileException;
import ovh.herisson.Clyde.Repositories.FileRepository; import ovh.herisson.Clyde.Repositories.FileRepository;
import ovh.herisson.Clyde.Tables.*; import ovh.herisson.Clyde.Tables.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.springframework.core.io.Resource;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -57,13 +54,13 @@ public class StorageService {
return url; return url;
} }
public void delete(StorageFile file) throws CouldntDeleteFileException { public void delete(StorageFile file) throws SecurityException {
File f = new File(file.getUrl()); File f = new File(file.getUrl());
//Delete le fichier //Delete le fichier
try{ try{
f.delete(); f.delete();
} catch (Exception e) { } catch (Exception e) {
throw new CouldntDeleteFileException(); throw new SecurityException();
} }
tonitch marked this conversation as resolved Outdated

f.delete peut throw uniquement : SecurityException et je trouve (personnellement) que c'est assez clair comme ça. dire qu'il y a une érreur de permissions est plus clair que dire "j'ai pas réussi à supprimer lol" ^^

f.delete peut throw uniquement : [`SecurityException`](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#delete()) et je trouve (personnellement) que c'est assez clair comme ça. dire qu'il y a une érreur de permissions est plus clair que dire "j'ai pas réussi à supprimer lol" ^^
//Delete l'entité //Delete l'entité
fileRepo.delete(file); fileRepo.delete(file);