feat: club remove
This commit is contained in:
@@ -55,15 +55,29 @@ public class AffiliationService {
|
||||
|
||||
public Uni<String> save(AffiliationRequestForm form) {
|
||||
AffiliationRequestModel affModel = form.toModel();
|
||||
affModel.setSaison(Utils.getSaison());
|
||||
int currentSaison = Utils.getSaison();
|
||||
|
||||
// noinspection ResultOfMethodCallIgnored
|
||||
return repositoryRequest.count("siret = ?1 and saison = ?2", affModel.getSiret(), affModel.getSaison())
|
||||
return Uni.createFrom().item(affModel)
|
||||
.invoke(Unchecked.consumer(model -> {
|
||||
if (model.getSaison() != currentSaison && model.getSaison() != currentSaison + 1) {
|
||||
throw new IllegalArgumentException("Saison not valid");
|
||||
}
|
||||
}))
|
||||
.chain(() -> 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");
|
||||
}
|
||||
}))
|
||||
.chain(() -> clubRepository.find("SIRET = ?1", affModel.getSiret()).firstResult().chain(club ->
|
||||
repository.count("club = ?1 and saison = ?2", club, affModel.getSaison())))
|
||||
.onItem().invoke(Unchecked.consumer(count -> {
|
||||
if (count != 0) {
|
||||
throw new IllegalArgumentException("Affiliation already exists");
|
||||
}
|
||||
}))
|
||||
.map(o -> affModel)
|
||||
.call(model -> ((model.getM1_lincence() != -1) ? combRepository.find("licence",
|
||||
model.getM1_lincence()).count().invoke(count -> {
|
||||
@@ -289,7 +303,12 @@ public class AffiliationService {
|
||||
|
||||
public Uni<SimpleAffiliation> setAffiliation(long id, int saison) {
|
||||
return clubRepository.findById(id)
|
||||
.onItem().ifNull().failWith(new NotFoundException("Affiliation request not found"))
|
||||
.onItem().ifNull().failWith(new NotFoundException("Club non trouver"))
|
||||
.invoke(Unchecked.consumer(club -> {
|
||||
if (club.getAffiliations().stream().anyMatch(affiliation -> affiliation.getSaison() == saison)) {
|
||||
throw new IllegalArgumentException("Affiliation deja existante");
|
||||
}
|
||||
}))
|
||||
.chain(club ->
|
||||
Panache.withTransaction(() -> repository.persist(new AffiliationModel(null, club, saison))))
|
||||
.map(SimpleAffiliation::fromModel);
|
||||
|
||||
Reference in New Issue
Block a user