add list user and part of user page

This commit is contained in:
2024-01-22 22:52:23 +01:00
parent 21cb673d33
commit 6f590cdaf7
44 changed files with 1469 additions and 186 deletions

View File

@@ -0,0 +1,64 @@
package fr.titionfire.ffsaf.domain.service;
import fr.titionfire.ffsaf.data.model.MembreModel;
import fr.titionfire.ffsaf.data.repository.ClubRepository;
import fr.titionfire.ffsaf.data.repository.CombRepository;
import fr.titionfire.ffsaf.net2.data.SimpleCombModel;
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
import fr.titionfire.ffsaf.utils.Pair;
import io.quarkus.hibernate.reactive.panache.Panache;
import io.quarkus.hibernate.reactive.panache.common.WithSession;
import io.quarkus.panache.common.Sort;
import io.quarkus.vertx.VertxContextSupport;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.List;
@WithSession
@ApplicationScoped
public class MembreService {
@Inject
CombRepository repository;
@Inject
ClubRepository clubRepository;
public SimpleCombModel find(int licence, String np) throws Throwable {
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
repository.find("licence = ?1 AND (lname = ?2 OR fname = ?2)", licence, np).firstResult().map(SimpleCombModel::fromModel)));
}
public SimpleCombModel findByIdOptionalComb(long id) throws Throwable {
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() -> repository.findById(id).map(SimpleCombModel::fromModel)));
}
public Uni<List<MembreModel>> getAll() {
return repository.listAll(Sort.ascending("fname", "lname"));
}
public Uni<MembreModel> getById(long id) {
return repository.findById(id);
}
public Uni<String> update(long id, FullMemberForm membre) {
return repository.findById(id)
.chain(membreModel -> clubRepository.findById(membre.getClub()).map(club -> new Pair<>(membreModel, club)))
.onItem().transformToUni(pair -> {
MembreModel m = pair.getKey();
m.setFname(membre.getFname());
m.setLname(membre.getLname());
m.setClub(pair.getValue());
m.setCountry(membre.getCountry());
m.setBirth_date(membre.getBirth_date());
m.setGenre(membre.getGenre());
m.setCategorie(membre.getCategorie());
m.setRole(membre.getRole());
m.setGrade_arbitrage(membre.getGrade_arbitrage());
m.setEmail(membre.getEmail());
return Panache.withTransaction(() -> repository.persist(m));
}).map(__ -> "OK");
}
}