fix: affiliation request page minor bug

This commit is contained in:
2024-07-16 14:24:52 +02:00
parent 2737e53de5
commit 6407bf44bc
4 changed files with 89 additions and 28 deletions

View File

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