feat(comp): add more register data
All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 6m25s
All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 6m25s
This commit is contained in:
@@ -2,10 +2,7 @@ package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CompetitionModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CompetitionRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.MatchRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.PouleRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.*;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleCompet;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqCompet;
|
||||
@@ -18,8 +15,9 @@ import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DNotFoundException;
|
||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||
import fr.titionfire.ffsaf.utils.RegisterEmbeddable;
|
||||
import fr.titionfire.ffsaf.data.model.RegisterModel;
|
||||
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
||||
import fr.titionfire.ffsaf.utils.Utils;
|
||||
import io.quarkus.cache.Cache;
|
||||
import io.quarkus.cache.CacheName;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
@@ -71,6 +69,8 @@ public class CompetitionService {
|
||||
@Inject
|
||||
@CacheName("safca-have-access")
|
||||
Cache cacheAccess;
|
||||
@Inject
|
||||
RegisterRepository registerRepository;
|
||||
|
||||
public Uni<CompetitionData> getById(SecurityCtx securityCtx, Long id) {
|
||||
if (id == 0) {
|
||||
@@ -205,23 +205,36 @@ public class CompetitionService {
|
||||
.chain(c -> findComb(data.getLicence(), data.getFname(), data.getLname())
|
||||
.chain(combModel -> Mutiny.fetch(c.getInsc())
|
||||
.chain(Unchecked.function(insc -> {
|
||||
Optional<RegisterEmbeddable> opt = insc.stream()
|
||||
Optional<RegisterModel> opt = insc.stream()
|
||||
.filter(m -> m.getMembre().equals(combModel)).findAny();
|
||||
|
||||
RegisterEmbeddable r;
|
||||
RegisterModel r;
|
||||
if (opt.isPresent()) {
|
||||
r = opt.get();
|
||||
r.setWeight(data.getWeight());
|
||||
r.setOverCategory(data.getOverCategory());
|
||||
r.setCategorie(
|
||||
(combModel.getBirth_date() == null) ? combModel.getCategorie() :
|
||||
Utils.getCategoryFormBirthDate(combModel.getBirth_date(),
|
||||
c.getDate()));
|
||||
int days = Utils.getDaysBeforeCompetition(c.getDate());
|
||||
if (days > -7) {
|
||||
r.setClub(combModel.getClub());
|
||||
}
|
||||
} else {
|
||||
r = new RegisterEmbeddable(combModel, data.getWeight(), data.getOverCategory());
|
||||
r = new RegisterModel(c ,combModel, data.getWeight(), data.getOverCategory(),
|
||||
(combModel.getBirth_date() == null) ? combModel.getCategorie() :
|
||||
Utils.getCategoryFormBirthDate(combModel.getBirth_date(),
|
||||
c.getDate()),
|
||||
(combModel.getClub() == null) ? null : c.getClub());
|
||||
insc.add(r);
|
||||
}
|
||||
|
||||
if (c.getSystem() == CompetitionSystem.SAFCA) {
|
||||
SReqRegister.sendIfNeed(serverCustom.clients,
|
||||
new CompetitionData.SimpleRegister(r.getMembre().getId(),
|
||||
r.getOverCategory(), r.getWeight()), c.getId());
|
||||
r.getOverCategory(), r.getWeight(), r.getCategorie(),
|
||||
(r.getClub() == null) ? null : r.getClub().getId()), c.getId());
|
||||
}
|
||||
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> r);
|
||||
}))))
|
||||
@@ -250,17 +263,17 @@ public class CompetitionService {
|
||||
|
||||
public Uni<Void> removeRegisterComb(SecurityCtx securityCtx, Long id, Long combId) {
|
||||
return permService.hasEditPerm(securityCtx, id)
|
||||
.chain(c -> Mutiny.fetch(c.getInsc())
|
||||
.chain(Unchecked.function(insc -> {
|
||||
if (insc.removeIf(m -> m.getMembre().getId().equals(combId))) {
|
||||
.chain(c -> registerRepository.delete("competition = ?1 AND membre.id = ?2", c, combId)
|
||||
.invoke(Unchecked.consumer(l -> {
|
||||
if (l != 0){
|
||||
if (c.getSystem() == CompetitionSystem.SAFCA) {
|
||||
SReqRegister.sendRmIfNeed(serverCustom.clients, combId, id);
|
||||
}
|
||||
|
||||
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> null);
|
||||
}else{
|
||||
throw new DBadRequestException("Combattant non inscrit");
|
||||
}
|
||||
throw new DBadRequestException("Combattant non inscrit");
|
||||
})));
|
||||
}))
|
||||
).replaceWithVoid();
|
||||
}
|
||||
|
||||
public Uni<?> delete(SecurityCtx securityCtx, Long id) {
|
||||
|
||||
@@ -3,9 +3,7 @@ package fr.titionfire.ffsaf.domain.service;
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.data.model.LicenceModel;
|
||||
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.data.repository.LicenceRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.*;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleCombModel;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqComb;
|
||||
@@ -37,9 +35,7 @@ import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
@@ -55,6 +51,9 @@ public class MembreService {
|
||||
@Inject
|
||||
LicenceRepository licenceRepository;
|
||||
|
||||
@Inject
|
||||
CompetitionRepository competitionRepository;
|
||||
|
||||
@Inject
|
||||
ServerCustom serverCustom;
|
||||
@Inject
|
||||
@@ -65,6 +64,8 @@ public class MembreService {
|
||||
|
||||
@ConfigProperty(name = "pdf-maker.jar-path")
|
||||
String pdfMakerJarPath;
|
||||
@Inject
|
||||
RegisterRepository registerRepository;
|
||||
|
||||
public SimpleCombModel find(int licence, String np) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
|
||||
@@ -88,7 +89,8 @@ public class MembreService {
|
||||
query = repository.find("(LOWER(lname) LIKE LOWER(?1) OR LOWER(fname) LIKE LOWER(?1))",
|
||||
Sort.ascending("fname", "lname"), search).page(Page.ofSize(limit));
|
||||
else
|
||||
query = repository.find("LOWER(club.name) LIKE LOWER(?2) AND (LOWER(lname) LIKE LOWER(?1) OR LOWER(fname) LIKE LOWER(?1))",
|
||||
query = repository.find(
|
||||
"LOWER(club.name) LIKE LOWER(?2) AND (LOWER(lname) LIKE LOWER(?1) OR LOWER(fname) LIKE LOWER(?1))",
|
||||
Sort.ascending("fname", "lname"), search, club + "%").page(Page.ofSize(limit));
|
||||
return getPageResult(query, limit, page);
|
||||
}
|
||||
@@ -100,7 +102,8 @@ public class MembreService {
|
||||
String finalSearch = search;
|
||||
return repository.find("userId = ?1", subject).firstResult()
|
||||
.chain(membreModel -> {
|
||||
PanacheQuery<MembreModel> query = repository.find("club = ?1 AND (LOWER(lname) LIKE LOWER(?2) OR LOWER(fname) LIKE LOWER(?2))",
|
||||
PanacheQuery<MembreModel> query = repository.find(
|
||||
"club = ?1 AND (LOWER(lname) LIKE LOWER(?2) OR LOWER(fname) LIKE LOWER(?2))",
|
||||
Sort.ascending("fname", "lname"), membreModel.getClub(), finalSearch)
|
||||
.page(Page.ofSize(limit));
|
||||
return getPageResult(query, limit, page);
|
||||
@@ -170,6 +173,20 @@ public class MembreService {
|
||||
.call(membreModel -> (membreModel.getUserId() != null) ?
|
||||
keycloakService.setEmail(membreModel.getUserId(), membreModel.getEmail()) : Uni.createFrom()
|
||||
.nullItem())
|
||||
.call(membreModel -> {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DAY_OF_YEAR, -7);
|
||||
Date dateLimit = calendar.getTime();
|
||||
|
||||
return competitionRepository.list("date > ?1", dateLimit)
|
||||
.call(l ->
|
||||
Uni.join().all(l.stream().map(competitionModel ->
|
||||
registerRepository.update(
|
||||
"categorie = ?1, club = ?2 where competition = ?3 AND membre = ?4",
|
||||
membreModel.getCategorie(), membreModel.getClub(), competitionModel,
|
||||
membreModel)
|
||||
).toList()).andFailFast());
|
||||
})
|
||||
.map(__ -> "OK");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user