fix: affiliation request page minor bug
This commit is contained in:
@@ -11,6 +11,7 @@ import fr.titionfire.ffsaf.utils.Utils;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
@@ -57,7 +58,13 @@ public class AffiliationService {
|
||||
affModel.setSaison(Utils.getSaison());
|
||||
|
||||
// noinspection ResultOfMethodCallIgnored
|
||||
return Uni.createFrom().item(affModel)
|
||||
return repositoryRequest.count("siret = ?1 and saison = ?2", affModel.getSiret(), affModel.getSaison())
|
||||
.onItem().invoke(Unchecked.consumer(count -> {
|
||||
if (count != 0) {
|
||||
throw new IllegalArgumentException("Affiliation request already exists");
|
||||
}
|
||||
}))
|
||||
.map(o -> affModel)
|
||||
.call(model -> ((model.getM1_lincence() != -1) ? combRepository.find("licence",
|
||||
model.getM1_lincence()).count().invoke(count -> {
|
||||
if (count == 0) {
|
||||
@@ -293,6 +300,8 @@ public class AffiliationService {
|
||||
}
|
||||
|
||||
public Uni<?> deleteReqAffiliation(long id) {
|
||||
return Panache.withTransaction(() -> repositoryRequest.deleteById(id));
|
||||
return Panache.withTransaction(() -> repositoryRequest.deleteById(id))
|
||||
.call(__ -> Utils.deleteMedia(id, media, "aff_request/logo"))
|
||||
.call(__ -> Utils.deleteMedia(id, media, "aff_request/status"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
import jakarta.ws.rs.ForbiddenException;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
|
||||
import java.util.List;
|
||||
@@ -46,6 +47,9 @@ public class MembreService {
|
||||
@Inject
|
||||
KeycloakService keycloakService;
|
||||
|
||||
@ConfigProperty(name = "upload_dir")
|
||||
String media;
|
||||
|
||||
public SimpleCombModel find(int licence, String np) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
|
||||
repository.find("licence = ?1 AND (lname ILIKE ?2 OR fname ILIKE ?2)",
|
||||
@@ -217,6 +221,7 @@ public class MembreService {
|
||||
keycloakService.removeAccount(membreModel.getUserId()) : Uni.createFrom().nullItem())
|
||||
.call(membreModel -> Panache.withTransaction(() -> repository.delete(membreModel)))
|
||||
.invoke(membreModel -> SReqComb.sendRm(serverCustom.clients, id))
|
||||
.call(__ -> Utils.deleteMedia(id, media, "ppMembre"))
|
||||
.map(__ -> "Ok");
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static Uni<String> moveMedia(long idSrc, long idDest, String media, String dirSrc, String dirDst) {
|
||||
System.out.println("moveMedia: " + idSrc + " -> " + idDest + " " + media + " " + dirSrc + " " + dirDst);
|
||||
return Uni.createFrom().nullItem().map(__ -> {
|
||||
File dirFile = new File(media, dirSrc);
|
||||
if (!dirFile.exists())
|
||||
@@ -51,12 +50,12 @@ public class Utils {
|
||||
if (!dirDestFile.mkdirs())
|
||||
return "Fail to create directory " + dirDestFile;
|
||||
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(idSrc));
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(idSrc + ".");
|
||||
File[] files = dirFile.listFiles(filter);
|
||||
if (files == null || files.length == 0)
|
||||
return "Not found";
|
||||
|
||||
FilenameFilter filter2 = (directory, filename) -> filename.startsWith(String.valueOf(idDest));
|
||||
FilenameFilter filter2 = (directory, filename) -> filename.startsWith(idDest + ".");
|
||||
File[] files2 = dirDestFile.listFiles(filter2);
|
||||
if (files2 != null) {
|
||||
for (File file : files2) {
|
||||
@@ -96,7 +95,7 @@ public class Utils {
|
||||
if (!dirFile.mkdirs())
|
||||
throw new IOException("Fail to create directory " + dir);
|
||||
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(id));
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(id +".");
|
||||
File[] files = dirFile.listFiles(filter);
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
@@ -122,7 +121,7 @@ public class Utils {
|
||||
public static Uni<Response> getMediaFile(long id, String media, String dirname, String out_filename,
|
||||
Uni<?> uniBase) throws URISyntaxException {
|
||||
Future<Pair<File, byte[]>> future = CompletableFuture.supplyAsync(() -> {
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(id));
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(id + ".");
|
||||
File[] files = new File(media, dirname).listFiles(filter);
|
||||
if (files != null && files.length > 0) {
|
||||
File file = files[0];
|
||||
@@ -150,9 +149,25 @@ public class Utils {
|
||||
resp.header(HttpHeaders.CONTENT_TYPE, mimeType);
|
||||
resp.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"inline; " + ((out_filename == null) ? "" : "filename=\"" + out_filename + "\""));
|
||||
|
||||
System.out.println("getMediaFile: " + mimeType);
|
||||
return resp.build();
|
||||
}));
|
||||
}
|
||||
|
||||
public static Uni<?> deleteMedia(long id, String media, String dir) {
|
||||
return Uni.createFrom().nullItem().map(__ -> {
|
||||
File dirFile = new File(media, dir);
|
||||
if (!dirFile.exists())
|
||||
return "OK";
|
||||
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(id + ".");
|
||||
File[] files = dirFile.listFiles(filter);
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
return "Ok";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user