feat: add membre list filter
This commit is contained in:
@@ -13,6 +13,7 @@ import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.List;
|
||||
@@ -32,6 +33,15 @@ public class LicenceService {
|
||||
return combRepository.findById(id).invoke(checkPerm).chain(combRepository -> Mutiny.fetch(combRepository.getLicences()));
|
||||
}
|
||||
|
||||
public Uni<List<LicenceModel>> getCurrentSaisonLicence(JsonWebToken idToken) {
|
||||
if (idToken == null)
|
||||
return repository.find("saison = ?1", Utils.getSaison()).list();
|
||||
|
||||
return combRepository.find("userId = ?1", idToken.getSubject()).firstResult().map(MembreModel::getClub)
|
||||
.chain(clubModel -> combRepository.find("club = ?1", clubModel).list())
|
||||
.chain(membres -> repository.find("saison = ?1 AND membre IN ?2", Utils.getSaison(), membres).list());
|
||||
}
|
||||
|
||||
public Uni<LicenceModel> setLicence(long id, LicenceForm form) {
|
||||
if (form.getId() == -1) {
|
||||
return combRepository.findById(id).chain(combRepository -> {
|
||||
@@ -58,7 +68,7 @@ public class LicenceService {
|
||||
public Uni<LicenceModel> askLicence(long id, LicenceForm form, Consumer<MembreModel> checkPerm) {
|
||||
return combRepository.findById(id).invoke(checkPerm).chain(membreModel -> {
|
||||
if (form.getId() == -1) {
|
||||
return repository.find("saison = ?1", Utils.getSaison()).count().invoke(Unchecked.consumer(count -> {
|
||||
return repository.find("saison = ?1 AND membre = ?2", Utils.getSaison(), membreModel).count().invoke(Unchecked.consumer(count -> {
|
||||
if (count > 0)
|
||||
throw new BadRequestException();
|
||||
})).chain(__ -> combRepository.findById(id).chain(combRepository -> {
|
||||
|
||||
Reference in New Issue
Block a user