wip: send competition data
This commit is contained in:
parent
4be7b28efd
commit
7f80c876d3
@ -4,10 +4,7 @@ import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
|||||||
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
|
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
|
||||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -19,6 +16,7 @@ import java.util.List;
|
|||||||
@RegisterForReflection
|
@RegisterForReflection
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@ToString
|
||||||
@Table(name = "match")
|
@Table(name = "match")
|
||||||
public class MatchModel {
|
public class MatchModel {
|
||||||
|
|
||||||
@ -30,24 +28,27 @@ public class MatchModel {
|
|||||||
CompetitionSystem system;
|
CompetitionSystem system;
|
||||||
Long systemId;
|
Long systemId;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "c1", referencedColumnName = "id")
|
@JoinColumn(name = "c1", referencedColumnName = "id")
|
||||||
MembreModel c1_id = null;
|
MembreModel c1_id = null;
|
||||||
|
|
||||||
String c1_str = null;
|
String c1_str = null;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "c2", referencedColumnName = "id")
|
@JoinColumn(name = "c2", referencedColumnName = "id")
|
||||||
MembreModel c2_id = null;
|
MembreModel c2_id = null;
|
||||||
|
|
||||||
String c2_str = null;
|
String c2_str = null;
|
||||||
|
|
||||||
@Column(name = "id_poule")
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
Long poule;
|
@JoinColumn(name = "id_poule", referencedColumnName = "id")
|
||||||
|
PouleModel poule = null;
|
||||||
|
|
||||||
long poule_ord = 0;
|
long poule_ord = 0;
|
||||||
|
|
||||||
@ElementCollection
|
boolean isEnd = true;
|
||||||
|
|
||||||
|
@ElementCollection(fetch = FetchType.EAGER)
|
||||||
@CollectionTable(name = "score", joinColumns = @JoinColumn(name = "id_match"))
|
@CollectionTable(name = "score", joinColumns = @JoinColumn(name = "id_match"))
|
||||||
List<ScoreEmbeddable> scores = new ArrayList<>();
|
List<ScoreEmbeddable> scores = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@ -33,11 +33,11 @@ public class PouleModel {
|
|||||||
@JoinColumn(name = "id_compet", referencedColumnName = "id")
|
@JoinColumn(name = "id_compet", referencedColumnName = "id")
|
||||||
CompetitionModel compet;
|
CompetitionModel compet;
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "id_poule", referencedColumnName = "id")
|
@JoinColumn(name = "id_poule", referencedColumnName = "id")
|
||||||
List<MatchModel> matchs;
|
List<MatchModel> matchs;
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "id_poule", referencedColumnName = "id")
|
@JoinColumn(name = "id_poule", referencedColumnName = "id")
|
||||||
List<TreeModel> tree;
|
List<TreeModel> tree;
|
||||||
|
|
||||||
|
|||||||
@ -25,15 +25,15 @@ public class TreeModel {
|
|||||||
|
|
||||||
Integer level;
|
Integer level;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "match_id", referencedColumnName = "id")
|
@JoinColumn(name = "match_id", referencedColumnName = "id")
|
||||||
MatchModel match;
|
MatchModel match;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
|
||||||
@JoinColumn(referencedColumnName = "id")
|
@JoinColumn(referencedColumnName = "id")
|
||||||
TreeModel left;
|
TreeModel left;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
|
||||||
@JoinColumn(referencedColumnName = "id")
|
@JoinColumn(referencedColumnName = "id")
|
||||||
TreeModel right;
|
TreeModel right;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import fr.titionfire.ffsaf.data.repository.MatchRepository;
|
|||||||
import fr.titionfire.ffsaf.data.repository.PouleRepository;
|
import fr.titionfire.ffsaf.data.repository.PouleRepository;
|
||||||
import fr.titionfire.ffsaf.rest.data.MatchData;
|
import fr.titionfire.ffsaf.rest.data.MatchData;
|
||||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||||
|
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
|
||||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
@ -32,7 +33,7 @@ public class MatchService {
|
|||||||
public Uni<MatchData> getById(Consumer<ClubModel> checkPerm, CompetitionSystem system, Long id) {
|
public Uni<MatchData> getById(Consumer<ClubModel> checkPerm, CompetitionSystem system, Long id) {
|
||||||
return repository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
return repository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||||
.onItem().ifNull().failWith(() -> new RuntimeException("Match not found"))
|
.onItem().ifNull().failWith(() -> new RuntimeException("Match not found"))
|
||||||
.call(data -> pouleRepository.findById(data.getPoule())
|
.call(data -> pouleRepository.findById(data.getPoule().getId())
|
||||||
.invoke(data2 -> checkPerm.accept(data2.getCompet().getClub())))
|
.invoke(data2 -> checkPerm.accept(data2.getCompet().getClub())))
|
||||||
.map(MatchData::fromModel);
|
.map(MatchData::fromModel);
|
||||||
}
|
}
|
||||||
@ -49,7 +50,8 @@ public class MatchService {
|
|||||||
return repository.find("systemId = ?1 AND system = ?2", data.getId(), system).firstResult()
|
return repository.find("systemId = ?1 AND system = ?2", data.getId(), system).firstResult()
|
||||||
.chain(o -> {
|
.chain(o -> {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return pouleRepository.findById(data.getPoule())
|
return pouleRepository.find("systemId = ?1 AND system = ?2", data.getPoule(), system)
|
||||||
|
.firstResult()
|
||||||
.onItem().ifNull().failWith(() -> new RuntimeException("Poule not found"))
|
.onItem().ifNull().failWith(() -> new RuntimeException("Poule not found"))
|
||||||
.invoke(data2 -> checkPerm.accept(data2.getCompet().getClub()))
|
.invoke(data2 -> checkPerm.accept(data2.getCompet().getClub()))
|
||||||
.map(pouleModel -> {
|
.map(pouleModel -> {
|
||||||
@ -58,11 +60,12 @@ public class MatchService {
|
|||||||
model.setId(null);
|
model.setId(null);
|
||||||
model.setSystem(system);
|
model.setSystem(system);
|
||||||
model.setSystemId(data.getId());
|
model.setSystemId(data.getId());
|
||||||
model.setPoule(pouleModel.getId());
|
model.setPoule(pouleModel);
|
||||||
return model;
|
return model;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return pouleRepository.findById(data.getPoule())
|
return pouleRepository.find("systemId = ?1 AND system = ?2", data.getPoule(), system)
|
||||||
|
.firstResult()
|
||||||
.onItem().ifNull().failWith(() -> new RuntimeException("Poule not found"))
|
.onItem().ifNull().failWith(() -> new RuntimeException("Poule not found"))
|
||||||
.invoke(data2 -> checkPerm.accept(data2.getCompet().getClub()))
|
.invoke(data2 -> checkPerm.accept(data2.getCompet().getClub()))
|
||||||
.map(__ -> o);
|
.map(__ -> o);
|
||||||
@ -73,7 +76,8 @@ public class MatchService {
|
|||||||
o.setC1_str(data.getC1_str());
|
o.setC1_str(data.getC1_str());
|
||||||
o.setC2_str(data.getC2_str());
|
o.setC2_str(data.getC2_str());
|
||||||
o.setPoule_ord(data.getPoule_ord());
|
o.setPoule_ord(data.getPoule_ord());
|
||||||
o.setScores(data.getScores());
|
o.getScores().clear();
|
||||||
|
o.getScores().addAll(data.getScores());
|
||||||
|
|
||||||
return Uni.createFrom().nullItem()
|
return Uni.createFrom().nullItem()
|
||||||
.chain(() -> (data.getC1_id() == null) ?
|
.chain(() -> (data.getC1_id() == null) ?
|
||||||
@ -87,11 +91,22 @@ public class MatchService {
|
|||||||
.map(MatchData::fromModel);
|
.map(MatchData::fromModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uni<?> delete(Consumer<ClubModel> checkPerm, Long id) {
|
public Uni<?> updateScore(CompetitionSystem system, Long id, List<ScoreEmbeddable> scores) {
|
||||||
return repository.findById(id)
|
return repository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||||
.onItem().ifNull().failWith(() -> new RuntimeException("Match not found"))
|
.onItem().ifNull().failWith(() -> new RuntimeException("Match not found"))
|
||||||
.call(data -> pouleRepository.findById(data.getPoule())
|
.invoke(data -> {
|
||||||
|
data.getScores().clear();
|
||||||
|
data.getScores().addAll(scores);
|
||||||
|
})
|
||||||
|
.chain(data -> Panache.withTransaction(() -> repository.persist(data)))
|
||||||
|
.map(o -> "OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Uni<?> delete(Consumer<ClubModel> checkPerm, CompetitionSystem system, Long id) {
|
||||||
|
return repository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||||
|
.onItem().ifNull().failWith(() -> new RuntimeException("Match not found"))
|
||||||
|
.chain(data -> pouleRepository.findById(data.getPoule().getId())
|
||||||
.invoke(data2 -> checkPerm.accept(data2.getCompet().getClub()))
|
.invoke(data2 -> checkPerm.accept(data2.getCompet().getClub()))
|
||||||
.chain(data2 -> Panache.withTransaction(() -> repository.delete("id", data.getId()))));
|
.chain(data2 -> Panache.withTransaction(() -> repository.delete(data))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
package fr.titionfire.ffsaf.domain.service;
|
package fr.titionfire.ffsaf.domain.service;
|
||||||
|
|
||||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
import fr.titionfire.ffsaf.data.model.*;
|
||||||
import fr.titionfire.ffsaf.data.model.PouleModel;
|
import fr.titionfire.ffsaf.data.repository.*;
|
||||||
import fr.titionfire.ffsaf.data.repository.CompetitionRepository;
|
|
||||||
import fr.titionfire.ffsaf.data.repository.PouleRepository;
|
|
||||||
import fr.titionfire.ffsaf.data.repository.TreeRepository;
|
|
||||||
import fr.titionfire.ffsaf.rest.data.PouleData;
|
import fr.titionfire.ffsaf.rest.data.PouleData;
|
||||||
|
import fr.titionfire.ffsaf.rest.data.PouleFullData;
|
||||||
|
import fr.titionfire.ffsaf.rest.data.TreeData;
|
||||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||||
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
||||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||||
@ -15,10 +14,14 @@ import io.smallrye.mutiny.Uni;
|
|||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||||
|
import org.hibernate.reactive.mutiny.Mutiny;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@WithSession
|
@WithSession
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
@ -30,9 +33,15 @@ public class PouleService {
|
|||||||
@Inject
|
@Inject
|
||||||
CompetitionRepository competRepository;
|
CompetitionRepository competRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
MatchRepository matchRepository;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
TreeRepository treeRepository;
|
TreeRepository treeRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
CombRepository combRepository;
|
||||||
|
|
||||||
public Uni<PouleData> getById(Consumer<ClubModel> checkPerm, CompetitionSystem system, Long id) {
|
public Uni<PouleData> getById(Consumer<ClubModel> checkPerm, CompetitionSystem system, Long id) {
|
||||||
return repository.find("systemId = ?1 AND system = ?2", id, system)
|
return repository.find("systemId = ?1 AND system = ?2", id, system)
|
||||||
.firstResult()
|
.firstResult()
|
||||||
@ -79,10 +88,181 @@ public class PouleService {
|
|||||||
}).map(PouleData::fromModel);
|
}).map(PouleData::fromModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uni<?> delete(Consumer<ClubModel> checkPerm, Long id) {
|
private MatchModel findMatch(List<MatchModel> matchModelList, Long id) {
|
||||||
return repository.findById(id)
|
return matchModelList.stream().filter(m -> m.getSystemId().equals(id))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TreeModel findNode(List<TreeModel> node, Long match_id) {
|
||||||
|
return node.stream().filter(m -> m.getMatch().getSystemId().equals(match_id))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flatTreeChild(TreeModel current, ArrayList<TreeModel> node) {
|
||||||
|
if (current != null) {
|
||||||
|
node.add(current);
|
||||||
|
flatTreeChild(current.getLeft(), node);
|
||||||
|
flatTreeChild(current.getRight(), node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flatTreeChild(TreeData current, ArrayList<TreeData> node) {
|
||||||
|
if (current != null) {
|
||||||
|
node.add(current);
|
||||||
|
flatTreeChild(current.getLeft(), node);
|
||||||
|
flatTreeChild(current.getRight(), node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Uni<TreeModel> persisteTree(TreeData data, List<TreeModel> node, PouleModel poule,
|
||||||
|
List<MatchModel> matchModelList) {
|
||||||
|
TreeModel mm = findNode(node, data.getMatch());
|
||||||
|
if (mm == null) {
|
||||||
|
mm = new TreeModel();
|
||||||
|
mm.setId(null);
|
||||||
|
}
|
||||||
|
mm.setLevel(data.getLevel());
|
||||||
|
mm.setPoule(poule.getId());
|
||||||
|
mm.setMatch(findMatch(matchModelList, data.getMatch()));
|
||||||
|
|
||||||
|
return Uni.createFrom().item(mm)
|
||||||
|
.call(o -> (data.getLeft() == null ? Uni.createFrom().nullItem().invoke(o1 -> o.setLeft(null)) :
|
||||||
|
persisteTree(data.getLeft(), node, poule, matchModelList).invoke(o::setLeft)))
|
||||||
|
.call(o -> (data.getRight() == null ? Uni.createFrom().nullItem().invoke(o1 -> o.setRight(null)) :
|
||||||
|
persisteTree(data.getRight(), node, poule, matchModelList).invoke(o::setRight)))
|
||||||
|
.chain(o -> Panache.withTransaction(() -> treeRepository.persist(o)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Uni<?> syncPoule(CompetitionSystem system, PouleFullData data) {
|
||||||
|
System.out.println(data);
|
||||||
|
return repository.find("systemId = ?1 AND system = ?2", data.getId(), system)
|
||||||
|
.firstResult()
|
||||||
|
.onItem().ifNull().switchTo(
|
||||||
|
() -> competRepository.findById(data.getCompet())
|
||||||
|
.onItem().ifNull().failWith(() -> new RuntimeException("Compet not found"))
|
||||||
|
.map(o -> {
|
||||||
|
PouleModel model = new PouleModel();
|
||||||
|
model.setId(null);
|
||||||
|
model.setSystem(system);
|
||||||
|
model.setSystemId(data.getId());
|
||||||
|
model.setMatchs(new ArrayList<>());
|
||||||
|
model.setTree(new ArrayList<>());
|
||||||
|
model.setCompet(o);
|
||||||
|
return model;
|
||||||
|
}))
|
||||||
|
.call(o -> Mutiny.fetch(o.getMatchs()))
|
||||||
|
.call(o -> Mutiny.fetch(o.getTree()))
|
||||||
|
.map(o -> {
|
||||||
|
o.setName(data.getName());
|
||||||
|
o.setType(data.getType());
|
||||||
|
|
||||||
|
WorkData workData = new WorkData();
|
||||||
|
workData.poule = o;
|
||||||
|
return workData;
|
||||||
|
})
|
||||||
|
.call(o -> Panache.withTransaction(() -> repository.persist(o.poule)))
|
||||||
|
.call(o -> (data.getMatches() == null || data.getMatches().isEmpty()) ? Uni.createFrom().nullItem() :
|
||||||
|
Uni.createFrom()
|
||||||
|
.item(data.getMatches().stream().flatMap(m -> Stream.of(m.getC1_id(), m.getC2_id())
|
||||||
|
.filter(Objects::nonNull)).distinct().toList())
|
||||||
|
.chain(ids -> ids.isEmpty() ? Uni.createFrom().nullItem()
|
||||||
|
: combRepository.list("id IN ?1", ids)
|
||||||
|
.invoke(o2 -> o2.forEach(m -> o.membres.put(m.getId(), m)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.invoke(in -> {
|
||||||
|
ArrayList<TreeModel> node = new ArrayList<>();
|
||||||
|
for (TreeModel treeModel : in.poule.getTree())
|
||||||
|
flatTreeChild(treeModel, node);
|
||||||
|
|
||||||
|
ArrayList<TreeData> new_node = new ArrayList<>();
|
||||||
|
for (TreeData treeModel : data.getTrees())
|
||||||
|
flatTreeChild(treeModel, new_node);
|
||||||
|
|
||||||
|
in.toRmNode = node.stream().filter(m -> new_node.stream()
|
||||||
|
.noneMatch(m2 -> m2.getMatch().equals(m.getMatch().getSystemId())))
|
||||||
|
.map(TreeModel::getId).toList();
|
||||||
|
|
||||||
|
in.unlinkNode = node;
|
||||||
|
in.unlinkNode.forEach(n -> {
|
||||||
|
n.setRight(null);
|
||||||
|
n.setLeft(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
in.toRmMatch = in.poule.getMatchs().stream()
|
||||||
|
.filter(m -> data.getMatches().stream().noneMatch(m2 -> m2.getId().equals(m.getSystemId())))
|
||||||
|
.map(MatchModel::getId).toList();
|
||||||
|
})
|
||||||
|
.call(in -> in.unlinkNode.isEmpty() ? Uni.createFrom().nullItem() :
|
||||||
|
Panache.withTransaction(() -> treeRepository.persist(in.unlinkNode)))
|
||||||
|
.call(in -> in.toRmNode.isEmpty() ? Uni.createFrom().nullItem() :
|
||||||
|
Panache.withTransaction(() -> treeRepository.delete("id IN ?1", in.toRmNode)))
|
||||||
|
.call(in -> in.toRmMatch.isEmpty() ? Uni.createFrom().nullItem() :
|
||||||
|
Panache.withTransaction(() -> Uni.join().all(
|
||||||
|
in.toRmMatch.stream().map(l -> matchRepository.deleteById(l)).toList())
|
||||||
|
.andCollectFailures()))
|
||||||
|
.call(in -> data.getMatches().isEmpty() ? Uni.createFrom().nullItem() :
|
||||||
|
Uni.join().all(
|
||||||
|
data.getMatches().stream().map(m -> {
|
||||||
|
MatchModel mm = findMatch(in.poule.getMatchs(), m.getId());
|
||||||
|
if (mm == null) {
|
||||||
|
mm = new MatchModel();
|
||||||
|
mm.setId(null);
|
||||||
|
mm.setSystem(system);
|
||||||
|
mm.setSystemId(m.getId());
|
||||||
|
}
|
||||||
|
mm.setPoule(in.poule);
|
||||||
|
mm.setPoule_ord(m.getPoule_ord());
|
||||||
|
mm.setC1_str(m.getC1_str());
|
||||||
|
mm.setC2_str(m.getC2_str());
|
||||||
|
mm.setC1_id(in.membres.getOrDefault(m.getC1_id(), null));
|
||||||
|
mm.setC2_id(in.membres.getOrDefault(m.getC2_id(), null));
|
||||||
|
mm.setEnd(m.isEnd());
|
||||||
|
mm.setGroupe(m.getGroupe());
|
||||||
|
mm.getScores().clear();
|
||||||
|
mm.getScores().addAll(m.getScores());
|
||||||
|
|
||||||
|
MatchModel finalMm = mm;
|
||||||
|
return Panache.withTransaction(() -> matchRepository.persist(finalMm)
|
||||||
|
.invoke(o -> in.match.add(o)));
|
||||||
|
}).toList())
|
||||||
|
.andCollectFailures())
|
||||||
|
.call(in -> data.getTrees().isEmpty() ? Uni.createFrom().nullItem() :
|
||||||
|
Uni.join().all(data.getTrees().stream()
|
||||||
|
.map(m -> persisteTree(m, in.poule.getTree(), in.poule, in.match)).toList())
|
||||||
|
.andCollectFailures())
|
||||||
|
.map(__ -> "OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class WorkData {
|
||||||
|
PouleModel poule;
|
||||||
|
HashMap<Long, MembreModel> membres = new HashMap<>();
|
||||||
|
List<MatchModel> match = new ArrayList<>();
|
||||||
|
List<Long> toRmMatch;
|
||||||
|
List<TreeModel> unlinkNode;
|
||||||
|
List<Long> toRmNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Uni<?> delete(Consumer<ClubModel> checkPerm, CompetitionSystem system, Long id) {
|
||||||
|
return repository.find("systemId = ?1 AND system = ?2", id, system).firstResult()
|
||||||
.onItem().ifNull().failWith(() -> new RuntimeException("Poule not found"))
|
.onItem().ifNull().failWith(() -> new RuntimeException("Poule not found"))
|
||||||
.invoke(data -> checkPerm.accept(data.getCompet().getClub()))
|
.call(o -> Mutiny.fetch(o.getMatchs()))
|
||||||
|
.call(o -> Mutiny.fetch(o.getTree())
|
||||||
|
.call(o2 -> o2.isEmpty() ? Uni.createFrom().nullItem() :
|
||||||
|
Uni.createFrom().item(o2.stream().peek(m -> {
|
||||||
|
m.setRight(null);
|
||||||
|
m.setLeft(null);
|
||||||
|
}).toList())
|
||||||
|
.call(in -> Panache.withTransaction(() -> treeRepository.persist(in)))
|
||||||
|
.map(in -> in.stream().map(TreeModel::getId).toList())
|
||||||
|
.call(in -> in.isEmpty() ? Uni.createFrom().nullItem() :
|
||||||
|
Panache.withTransaction(() -> treeRepository.delete("id IN ?1", in)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.call(o -> o.getMatchs().isEmpty() ? Uni.createFrom().nullItem() :
|
||||||
|
Panache.withTransaction(() -> Uni.join().all(
|
||||||
|
o.getMatchs().stream().map(l -> matchRepository.deleteById(l.getId())).toList())
|
||||||
|
.andCollectFailures()))
|
||||||
.chain(model -> Panache.withTransaction(() -> repository.delete("id", model.getId())));
|
.chain(model -> Panache.withTransaction(() -> repository.delete("id", model.getId())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
package fr.titionfire.ffsaf.domain.service;
|
||||||
|
|
||||||
|
public class TreeService {
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@ import fr.titionfire.ffsaf.rest.data.MatchData;
|
|||||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||||
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
||||||
|
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
|
||||||
import io.quarkus.security.Authenticated;
|
import io.quarkus.security.Authenticated;
|
||||||
import io.quarkus.security.identity.SecurityIdentity;
|
import io.quarkus.security.identity.SecurityIdentity;
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
@ -60,10 +61,17 @@ public class MatchEndpoints {
|
|||||||
return service.addOrUpdate(checkPerm, system, data);
|
return service.addOrUpdate(checkPerm, system, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("score/{id}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Uni<?> updateScore(@PathParam("id") Long id, List<ScoreEmbeddable> scores) {
|
||||||
|
return service.updateScore(system, id, scores);
|
||||||
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Uni<?> delete(@PathParam("id") Long id) {
|
public Uni<?> delete(@PathParam("id") Long id) {
|
||||||
return service.delete(checkPerm, id);
|
return service.delete(checkPerm, system, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,10 @@ package fr.titionfire.ffsaf.rest;
|
|||||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||||
import fr.titionfire.ffsaf.domain.service.PouleService;
|
import fr.titionfire.ffsaf.domain.service.PouleService;
|
||||||
import fr.titionfire.ffsaf.rest.data.PouleData;
|
import fr.titionfire.ffsaf.rest.data.PouleData;
|
||||||
|
import fr.titionfire.ffsaf.rest.data.PouleFullData;
|
||||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||||
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
import fr.titionfire.ffsaf.utils.GroupeUtils;
|
||||||
import io.quarkus.security.Authenticated;
|
|
||||||
import io.quarkus.security.identity.SecurityIdentity;
|
import io.quarkus.security.identity.SecurityIdentity;
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import io.smallrye.mutiny.unchecked.Unchecked;
|
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||||
@ -18,7 +18,7 @@ import org.eclipse.microprofile.jwt.JsonWebToken;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@Authenticated
|
// @Authenticated
|
||||||
@Path("api/poule/{system}/")
|
@Path("api/poule/{system}/")
|
||||||
public class PouleEndpoints {
|
public class PouleEndpoints {
|
||||||
|
|
||||||
@ -54,15 +54,23 @@ public class PouleEndpoints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Uni<PouleData> addOrUpdate(PouleData data) {
|
public Uni<PouleData> addOrUpdate(PouleData data) {
|
||||||
return service.addOrUpdate(checkPerm, system, data);
|
return service.addOrUpdate(checkPerm, system, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("sync")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public Uni<?> syncPoule(PouleFullData data) {
|
||||||
|
return service.syncPoule(system, data);
|
||||||
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Uni<?> delete(@PathParam("id") Long id) {
|
public Uni<?> delete(@PathParam("id") Long id) {
|
||||||
return service.delete(checkPerm, id);
|
return service.delete(checkPerm, system, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,13 +19,18 @@ public class MatchData {
|
|||||||
private String c2_str;
|
private String c2_str;
|
||||||
private Long poule;
|
private Long poule;
|
||||||
private long poule_ord;
|
private long poule_ord;
|
||||||
|
private boolean isEnd = true;
|
||||||
|
private char groupe;
|
||||||
private List<ScoreEmbeddable> scores;
|
private List<ScoreEmbeddable> scores;
|
||||||
|
|
||||||
public static MatchData fromModel(MatchModel model) {
|
public static MatchData fromModel(MatchModel model) {
|
||||||
if (model == null)
|
if (model == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new MatchData(model.getSystemId(), model.getC1_id().getId(), model.getC1_str(), model.getC2_id().getId(),
|
return new MatchData(model.getSystemId(),
|
||||||
model.getC2_str(), model.getPoule(), model.getPoule_ord(), model.getScores());
|
(model.getC1_id() == null) ? null : model.getC1_id().getId(), model.getC1_str(),
|
||||||
|
(model.getC2_id() == null) ? null : model.getC2_id().getId(), model.getC2_str(),
|
||||||
|
model.getPoule().getId(), model.getPoule_ord(), model.isEnd(), model.getGroupe(),
|
||||||
|
model.getScores());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
package fr.titionfire.ffsaf.rest.data;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PouleFullData {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Long compet;
|
||||||
|
private Integer type;
|
||||||
|
private List<MatchData> matches;
|
||||||
|
private List<TreeData> trees;
|
||||||
|
|
||||||
|
/*public static PouleFullData fromModel(PouleModel pouleModel) {
|
||||||
|
if (pouleModel == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
PouleEntity pouleEntity = PouleEntity.fromModel(pouleModel);
|
||||||
|
|
||||||
|
return new PouleFullData(pouleEntity.getId(), pouleEntity.getName(), pouleEntity.getCompet().getId(),
|
||||||
|
pouleEntity.getType(), pouleModel.getMatchs().stream().map(MatchData::fromModel).toList(),
|
||||||
|
pouleEntity.getTrees().stream().map(TreeData::fromEntity).toList());
|
||||||
|
}*/
|
||||||
|
}
|
||||||
@ -12,17 +12,15 @@ public class TreeData {
|
|||||||
private Long id;
|
private Long id;
|
||||||
private Long poule;
|
private Long poule;
|
||||||
private Integer level;
|
private Integer level;
|
||||||
private MatchData match;
|
private Long match;
|
||||||
private TreeData left;
|
private TreeData left;
|
||||||
private TreeData right;
|
private TreeData right;
|
||||||
private TreeData associatedNode;
|
|
||||||
|
|
||||||
public static TreeData fromModel(TreeModel model) {
|
public static TreeData fromModel(TreeModel model) {
|
||||||
if (model == null)
|
if (model == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new TreeData(model.getId(), model.getPoule(), model.getLevel(), MatchData.fromModel(model.getMatch()),
|
return new TreeData(model.getId(), model.getPoule(), model.getLevel(), model.getMatch().getId(),
|
||||||
fromModel(model.getLeft()),
|
fromModel(model.getLeft()), fromModel(model.getRight()));
|
||||||
fromModel(model.getRight()), null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
package fr.titionfire.ffsaf.utils;
|
package fr.titionfire.ffsaf.utils;
|
||||||
|
|
||||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
import jakarta.persistence.Embeddable;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user