Compare commits
No commits in common. "075f01a205fb0274f2322e1dbe7328487fdce0de" and "a730384d378e602a56e9829173392397c1ab36e5" have entirely different histories.
075f01a205
...
a730384d37
@ -1,9 +0,0 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
|
||||
public interface CombModel {
|
||||
Long getCombId();
|
||||
String getName();
|
||||
String getName(MembreModel model, ResultPrivacy privacy);
|
||||
}
|
||||
@ -2,7 +2,6 @@ package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -18,7 +17,7 @@ import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "competition_guest")
|
||||
public class CompetitionGuestModel implements CombModel {
|
||||
public class CompetitionGuestModel {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Long id;
|
||||
@ -45,18 +44,7 @@ public class CompetitionGuestModel implements CombModel {
|
||||
this.lname = s.substring(s.indexOf(" ") + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCombId() {
|
||||
return this.id * -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.fname + " " + this.lname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(MembreModel model, ResultPrivacy privacy) {
|
||||
return getName();
|
||||
return fname + " " + lname;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
@ -10,7 +9,6 @@ import lombok.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ -67,35 +65,19 @@ public class MatchModel {
|
||||
@JoinColumn(name = "match", referencedColumnName = "id")
|
||||
List<CardboardModel> cardboard = new ArrayList<>();
|
||||
|
||||
public String getC1Name(MembreModel model, ResultPrivacy privacy) {
|
||||
if (c1_id != null)
|
||||
return c1_id.getName(model, privacy);
|
||||
if (c1_guest != null)
|
||||
return c1_guest.getName(model, privacy);
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getC2Name(MembreModel model, ResultPrivacy privacy) {
|
||||
if (c2_id != null)
|
||||
return c2_id.getName(model, privacy);
|
||||
if (c2_guest != null)
|
||||
return c2_guest.getName(model, privacy);
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getC1Name() {
|
||||
if (c1_id != null)
|
||||
return c1_id.getName();
|
||||
return c1_id.fname + " " + c1_id.lname;
|
||||
if (c1_guest != null)
|
||||
return c1_guest.getName();
|
||||
return c1_guest.fname + " " + c1_guest.lname;
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getC2Name() {
|
||||
if (c2_id != null)
|
||||
return c2_id.getName();
|
||||
return c2_id.fname + " " + c2_id.lname;
|
||||
if (c2_guest != null)
|
||||
return c2_guest.getName();
|
||||
return c2_guest.fname + " " + c2_guest.lname;
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -112,24 +94,4 @@ public class MatchModel {
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public boolean isC1(Object comb) {
|
||||
if (comb instanceof Long id_) {
|
||||
if (id_ >= 0)
|
||||
return Objects.equals(this.c1_id != null ? this.c1_id.getId() : null, id_);
|
||||
else
|
||||
return Objects.equals(this.c1_guest != null ? this.c1_guest.getId() : null, -id_);
|
||||
}
|
||||
return Objects.equals(this.c1_id, comb) || Objects.equals(this.c1_guest, comb);
|
||||
}
|
||||
|
||||
public boolean isC2(Object comb) {
|
||||
if (comb instanceof Long id_) {
|
||||
if (id_ >= 0)
|
||||
return Objects.equals(this.c2_id != null ? this.c2_id.getId() : null, id_);
|
||||
else
|
||||
return Objects.equals(this.c2_guest != null ? this.c2_guest.getId() : null, -id_);
|
||||
}
|
||||
return Objects.equals(this.c2_id, comb) || Objects.equals(this.c2_guest, comb);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.*;
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.GradeArbitrage;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
@ -8,7 +11,6 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ -19,23 +21,23 @@ import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "membre")
|
||||
public class MembreModel implements LoggableModel, CombModel {
|
||||
public class MembreModel implements LoggableModel {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Access(AccessType.PROPERTY)
|
||||
@Schema(description = "L'identifiant du membre.", examples = "1")
|
||||
@Schema(description = "L'identifiant du membre.", example = "1")
|
||||
Long id;
|
||||
|
||||
@Schema(description = "L'identifiant long du membre (userID).", examples = "e81d1d35-d897-421e-8086-6c5e74d13c6e")
|
||||
@Schema(description = "L'identifiant long du membre (userID).", example = "e81d1d35-d897-421e-8086-6c5e74d13c6e")
|
||||
String userId;
|
||||
|
||||
@Schema(description = "Le nom du membre.", examples = "Dupont")
|
||||
@Schema(description = "Le nom du membre.", example = "Dupont")
|
||||
String lname;
|
||||
@Schema(description = "Le prénom du membre.", examples = "Jean")
|
||||
@Schema(description = "Le prénom du membre.", example = "Jean")
|
||||
String fname;
|
||||
|
||||
@Schema(description = "La catégorie du membre.", examples = "SENIOR")
|
||||
@Schema(description = "La catégorie du membre.", example = "SENIOR")
|
||||
Categorie categorie;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@ -43,30 +45,29 @@ public class MembreModel implements LoggableModel, CombModel {
|
||||
@Schema(description = "Le club du membre.")
|
||||
ClubModel club;
|
||||
|
||||
@Schema(description = "Le genre du membre.", examples = "H")
|
||||
@Schema(description = "Le genre du membre.", example = "H")
|
||||
Genre genre;
|
||||
|
||||
@Schema(description = "Le numéro de licence du membre.", examples = "12345")
|
||||
@Schema(description = "Le numéro de licence du membre.", example = "12345")
|
||||
Integer licence;
|
||||
|
||||
@Schema(description = "Le pays du membre.", examples = "FR")
|
||||
@Schema(description = "Le pays du membre.", example = "FR")
|
||||
String country;
|
||||
|
||||
@Schema(description = "La date de naissance du membre.")
|
||||
Date birth_date;
|
||||
|
||||
@Schema(description = "L'adresse e-mail du membre.", examples = "jean.dupont@examples.com")
|
||||
@Schema(description = "L'adresse e-mail du membre.", example = "jean.dupont@example.com")
|
||||
String email;
|
||||
|
||||
@Schema(description = "Le rôle du membre dans l'association.", examples = "MEMBRE")
|
||||
@Schema(description = "Le rôle du membre dans l'association.", example = "MEMBRE")
|
||||
RoleAsso role;
|
||||
|
||||
@Schema(description = "Le grade d'arbitrage du membre.", examples = "NA")
|
||||
@Schema(description = "Le grade d'arbitrage du membre.", example = "NA")
|
||||
GradeArbitrage grade_arbitrage;
|
||||
|
||||
@Schema(description = "La confidentialité de ces résultats", examples = "PUBLIC")
|
||||
@Column(nullable = false, columnDefinition = "smallint default 0")
|
||||
ResultPrivacy resultPrivacy = ResultPrivacy.PUBLIC;
|
||||
@Schema(hidden = true)
|
||||
String url_photo;
|
||||
|
||||
@OneToMany(mappedBy = "membre", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
@Schema(description = "Les licences du membre. (optionnel)")
|
||||
@ -99,25 +100,4 @@ public class MembreModel implements LoggableModel, CombModel {
|
||||
", grade_arbitrage=" + grade_arbitrage +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCombId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.fname + " " + this.lname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(MembreModel model, ResultPrivacy privacy) {
|
||||
if (model == null || !Objects.equals(this.getId(), model.getId())) {
|
||||
if (model == null && this.getResultPrivacy() != ResultPrivacy.PUBLIC)
|
||||
return "Anonyme";
|
||||
if (this.getResultPrivacy().ordinal() > privacy.ordinal())
|
||||
return "Anonyme";
|
||||
}
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
package fr.titionfire.ffsaf.domain.entity;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.GradeArbitrage;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class MembreEntity {
|
||||
private long id;
|
||||
private String lname = "";
|
||||
private String fname = "";
|
||||
private Categorie categorie;
|
||||
private ClubEntity club;
|
||||
private Genre genre;
|
||||
private Integer licence;
|
||||
private String country;
|
||||
private Date birth_date;
|
||||
private String email;
|
||||
private RoleAsso role;
|
||||
private GradeArbitrage grade_arbitrage;
|
||||
private String url_photo;
|
||||
|
||||
|
||||
public static MembreEntity fromModel(MembreModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new MembreEntityBuilder()
|
||||
.id(model.getId())
|
||||
.lname(model.getLname())
|
||||
.fname(model.getFname())
|
||||
.categorie(model.getCategorie())
|
||||
.club(ClubEntity.fromModel(model.getClub()))
|
||||
.genre(model.getGenre())
|
||||
.licence(model.getLicence())
|
||||
.country(model.getCountry())
|
||||
.birth_date(model.getBirth_date())
|
||||
.email(model.getEmail())
|
||||
.role(model.getRole())
|
||||
.grade_arbitrage(model.getGrade_arbitrage())
|
||||
.url_photo(model.getUrl_photo())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String getFullName(MembreModel model) {
|
||||
return model.getFname() + " " + model.getLname();
|
||||
}
|
||||
public String getFullName() {
|
||||
return this.fname + " " + this.lname;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -292,8 +292,7 @@ public class ClubService {
|
||||
Uni.join().all(list.stream().filter(m -> m.getUserId() != null)
|
||||
.map(m -> keycloakService.clearUser(m.getUserId())).toList())
|
||||
.andCollectFailures())
|
||||
.chain(list -> list.isEmpty() ? Uni.createFrom().voidItem() :
|
||||
Panache.withTransaction(() -> combRepository.persist(list)))
|
||||
.chain(list -> Panache.withTransaction(() -> combRepository.persist(list)))
|
||||
.map(o -> club)
|
||||
)
|
||||
.call(clubModel -> (clubModel.getClubId() == null) ? Uni.createFrom()
|
||||
|
||||
@ -15,7 +15,6 @@ import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DInternalError;
|
||||
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
|
||||
import fr.titionfire.ffsaf.rest.from.UserSettingForm;
|
||||
import fr.titionfire.ffsaf.utils.*;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheQuery;
|
||||
@ -468,8 +467,7 @@ public class MembreService {
|
||||
.call(membreModel -> licenceRepository.update("club_id = ?1 where membre = ?2 AND saison = ?3",
|
||||
(membreModel.getClub() == null) ? null : membreModel.getClub().getId(), membreModel,
|
||||
Utils.getSaison()))
|
||||
.call(membreModel -> (membre.getPhoto_data() != null && membre.getPhoto_data()
|
||||
.size() > 0) ? ls.logAUpdate("Photo",
|
||||
.call(membreModel -> (membre.getPhoto_data() != null && membre.getPhoto_data().size() > 0) ? ls.logAUpdate("Photo",
|
||||
membreModel) : Uni.createFrom().nullItem())
|
||||
.map(__ -> "OK");
|
||||
}
|
||||
@ -595,20 +593,6 @@ public class MembreService {
|
||||
.map(__ -> meData);
|
||||
}
|
||||
|
||||
public Uni<Void> updateSettings(String subject, UserSettingForm settingForm) {
|
||||
return repository.find("userId = ?1", subject).firstResult()
|
||||
.invoke(Unchecked.consumer(membreModel -> {
|
||||
if (settingForm.getResultPrivacy() != null) {
|
||||
ls.logChange("Confidentialité des résultats", membreModel.getResultPrivacy(),
|
||||
settingForm.getResultPrivacy(), membreModel);
|
||||
membreModel.setResultPrivacy(settingForm.getResultPrivacy());
|
||||
}
|
||||
}))
|
||||
.call(membreModel -> Panache.withTransaction(() -> repository.persist(membreModel)))
|
||||
.call(membreModel -> ls.append())
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 1 1 9 ?")
|
||||
Uni<Void> everySeason() {
|
||||
return repository.list("birth_date IS NOT NULL")
|
||||
@ -618,4 +602,5 @@ public class MembreService {
|
||||
}).toList()).andCollectFailures())
|
||||
.map(__ -> null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ package fr.titionfire.ffsaf.domain.service;
|
||||
import fr.titionfire.ffsaf.data.model.*;
|
||||
import fr.titionfire.ffsaf.data.repository.*;
|
||||
import fr.titionfire.ffsaf.rest.data.ResultCategoryData;
|
||||
import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
import fr.titionfire.ffsaf.utils.*;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
@ -17,7 +16,9 @@ import lombok.Builder;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@WithSession
|
||||
@ -47,50 +48,6 @@ public class ResultService {
|
||||
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("lang.String");
|
||||
|
||||
private static final HashMap<Long, String> combTempIds = new HashMap<>();
|
||||
|
||||
private static String getCombTempId(Long key) {
|
||||
synchronized (combTempIds) {
|
||||
if (!combTempIds.containsKey(key)) {
|
||||
combTempIds.put(key, UUID.randomUUID().toString());
|
||||
}
|
||||
return combTempIds.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
private static Long getCombTempId(String value) {
|
||||
synchronized (combTempIds) {
|
||||
for (Map.Entry<Long, String> entry : combTempIds.entrySet()) {
|
||||
if (entry.getValue().equals(value)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final HashMap<String, Long> clubTempIds = new HashMap<>();
|
||||
|
||||
private static Long getClubTempId(String key) {
|
||||
synchronized (clubTempIds) {
|
||||
if (!clubTempIds.containsKey(key)) {
|
||||
clubTempIds.put(key, (System.currentTimeMillis() + clubTempIds.size()) * -1);
|
||||
}
|
||||
return clubTempIds.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getClubTempId(Long value) {
|
||||
synchronized (clubTempIds) {
|
||||
for (Map.Entry<String, Long> entry : clubTempIds.entrySet()) {
|
||||
if (entry.getValue().equals(value)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Uni<List<Object[]>> getList(SecurityCtx securityCtx) {
|
||||
return membreService.getByAccountId(securityCtx.getSubject())
|
||||
.chain(m -> registerRepository.list("membre = ?1", m))
|
||||
@ -112,20 +69,31 @@ public class ResultService {
|
||||
});
|
||||
}
|
||||
|
||||
public Uni<ResultCategoryData> getCategory(String uuid, long poule, SecurityCtx securityCtx) {
|
||||
return hasAccess(uuid, securityCtx).chain(r ->
|
||||
matchRepository.list("category.compet.uuid = ?1 AND category.id = ?2", uuid, poule)
|
||||
.call(list -> Mutiny.fetch(list.get(0).getCategory().getTree()))
|
||||
.map(list -> getData(list, r.getMembre())));
|
||||
public Uni<List<ResultCategoryData>> getCategory(String uuid, SecurityCtx securityCtx) {
|
||||
return hasAccess(uuid, securityCtx)
|
||||
.chain(m -> categoryRepository.list("compet.uuid = ?1", uuid)
|
||||
.chain(cats -> matchRepository.list(
|
||||
"(c1_id = ?1 OR c2_id = ?1 OR True) AND category IN ?2", //TODO rm OR True
|
||||
m.getMembre(), cats)))
|
||||
.map(matchModels -> {
|
||||
HashMap<Long, List<MatchModel>> map = new HashMap<>();
|
||||
for (MatchModel matchModel : matchModels) {
|
||||
if (!map.containsKey(matchModel.getCategory().getId()))
|
||||
map.put(matchModel.getCategory().getId(), new ArrayList<>());
|
||||
map.get(matchModel.getCategory().getId()).add(matchModel);
|
||||
}
|
||||
|
||||
return map.values();
|
||||
})
|
||||
.onItem()
|
||||
.transformToMulti(Multi.createFrom()::iterable)
|
||||
.onItem().call(list -> Mutiny.fetch(list.get(0).getCategory().getTree()))
|
||||
.onItem().transform(this::getData)
|
||||
.collect().asList();
|
||||
|
||||
}
|
||||
|
||||
public Uni<ResultCategoryData> getCategory(String uuid, long poule) {
|
||||
return matchRepository.list("category.compet.uuid = ?1 AND category.id = ?2", uuid, poule)
|
||||
.call(list -> Mutiny.fetch(list.get(0).getCategory().getTree()))
|
||||
.map(list -> getData(list, null));
|
||||
}
|
||||
|
||||
private ResultCategoryData getData(List<MatchModel> matchModels, MembreModel membreModel) {
|
||||
private ResultCategoryData getData(List<MatchModel> matchModels) {
|
||||
ResultCategoryData out = new ResultCategoryData();
|
||||
|
||||
CategoryModel categoryModel = matchModels.get(0).getCategory();
|
||||
@ -134,12 +102,12 @@ public class ResultService {
|
||||
out.setLiceName(categoryModel.getLiceName() == null ? new String[]{} : categoryModel.getLiceName().split(";"));
|
||||
out.setGenTime(System.currentTimeMillis());
|
||||
|
||||
getArray2(matchModels, membreModel, out);
|
||||
getTree(categoryModel.getTree(), membreModel, out);
|
||||
getArray2(matchModels, out);
|
||||
getTree(categoryModel.getTree(), out);
|
||||
return out;
|
||||
}
|
||||
|
||||
private void getArray2(List<MatchModel> matchModels_, MembreModel membreModel, ResultCategoryData out) {
|
||||
private void getArray2(List<MatchModel> matchModels_, ResultCategoryData out) {
|
||||
List<MatchModel> matchModels = matchModels_.stream().filter(o -> o.getCategory_ord() >= 0).toList();
|
||||
|
||||
HashMap<Character, List<MatchModel>> matchMap = new HashMap<>();
|
||||
@ -153,30 +121,31 @@ public class ResultService {
|
||||
matchMap.forEach((c, matchEntities) -> {
|
||||
List<ResultCategoryData.PouleArrayData> matchs = matchEntities.stream()
|
||||
.sorted(Comparator.comparing(MatchModel::getCategory_ord))
|
||||
.map(o -> ResultCategoryData.PouleArrayData.fromModel(o, membreModel,
|
||||
ResultPrivacy.REGISTERED_ONLY_NO_DETAILS))
|
||||
.map(ResultCategoryData.PouleArrayData::fromModel)
|
||||
.toList();
|
||||
|
||||
List<ResultCategoryData.RankArray> rankArray = matchEntities.stream()
|
||||
.flatMap(m -> Stream.of(m.getC1_id(), m.getC2_id(), m.getC1_guest(), m.getC2_guest()))
|
||||
.flatMap(m -> Stream.of(m.getC1Name(), m.getC2Name()))
|
||||
.distinct()
|
||||
.filter(Objects::nonNull)
|
||||
.map(comb -> {
|
||||
.map(combName -> {
|
||||
AtomicInteger w = new AtomicInteger(0);
|
||||
AtomicInteger pointMake = new AtomicInteger(0);
|
||||
AtomicInteger pointTake = new AtomicInteger(0);
|
||||
|
||||
matchEntities.stream()
|
||||
.filter(m -> m.isEnd() && (m.isC1(comb) || m.isC2(comb)))
|
||||
.filter(m -> m.isEnd() && (m.getC1Name().equals(combName) || m.getC2Name()
|
||||
.equals(combName)))
|
||||
.forEach(matchModel -> {
|
||||
int win = matchModel.win();
|
||||
if ((matchModel.isC1(comb) && win > 0) || matchModel.isC2(comb) && win < 0)
|
||||
if ((matchModel.getC1Name()
|
||||
.equals(combName) && win > 0) || matchModel.getC2Name()
|
||||
.equals(combName) && win < 0)
|
||||
w.getAndIncrement();
|
||||
|
||||
for (ScoreEmbeddable score : matchModel.getScores()) {
|
||||
if (score.getS1() <= -900 || score.getS2() <= -900)
|
||||
continue;
|
||||
if (matchModel.isC1(comb)) {
|
||||
if (matchModel.getC1Name().equals(combName)) {
|
||||
pointMake.addAndGet(score.getS1());
|
||||
pointTake.addAndGet(score.getS2());
|
||||
} else {
|
||||
@ -187,8 +156,7 @@ public class ResultService {
|
||||
});
|
||||
float pointRate = (pointTake.get() == 0) ? pointMake.get() : (float) pointMake.get() / pointTake.get();
|
||||
|
||||
return new ResultCategoryData.RankArray(0,
|
||||
comb.getName(membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS), w.get(),
|
||||
return new ResultCategoryData.RankArray(0, combName, w.get(),
|
||||
pointMake.get(), pointTake.get(), pointRate);
|
||||
})
|
||||
.sorted(Comparator
|
||||
@ -212,24 +180,29 @@ public class ResultService {
|
||||
});
|
||||
}
|
||||
|
||||
private static void convertTree(TreeModel src, TreeNode<ResultCategoryData.TreeData> dst, MembreModel membreModel,
|
||||
ResultPrivacy privacy) {
|
||||
dst.setData(ResultCategoryData.TreeData.from(src.getMatch(), membreModel, privacy));
|
||||
private static void convertTree(TreeModel src, TreeNode<ResultCategoryData.TreeData> dst) {
|
||||
dst.setData(ResultCategoryData.TreeData.from(src.getMatch()));
|
||||
if (src.getLeft() != null) {
|
||||
dst.setLeft(new TreeNode<>());
|
||||
convertTree(src.getLeft(), dst.getLeft(), membreModel, privacy);
|
||||
convertTree(src.getLeft(), dst.getLeft());
|
||||
}
|
||||
if (src.getRight() != null) {
|
||||
dst.setRight(new TreeNode<>());
|
||||
convertTree(src.getRight(), dst.getRight(), membreModel, privacy);
|
||||
convertTree(src.getRight(), dst.getRight());
|
||||
}
|
||||
}
|
||||
|
||||
private void getTree(List<TreeModel> treeModels, MembreModel membreModel, ResultCategoryData out) {
|
||||
public Uni<ResultCategoryData> getCategoryPublic(String uuid, long poule) {
|
||||
return matchRepository.list("category.compet.uuid = ?1 AND category.id = ?2", uuid, poule)
|
||||
.call(list -> Mutiny.fetch(list.get(0).getCategory().getTree()))
|
||||
.map(this::getData);
|
||||
}
|
||||
|
||||
private void getTree(List<TreeModel> treeModels, ResultCategoryData out) {
|
||||
ArrayList<TreeNode<ResultCategoryData.TreeData>> trees = new ArrayList<>();
|
||||
treeModels.stream().filter(t -> t.getLevel() != 0).forEach(treeModel -> {
|
||||
TreeNode<ResultCategoryData.TreeData> root = new TreeNode<>();
|
||||
convertTree(treeModel, root, membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS);
|
||||
convertTree(treeModel, root);
|
||||
trees.add(root);
|
||||
});
|
||||
out.setTrees(trees);
|
||||
@ -237,14 +210,14 @@ public class ResultService {
|
||||
|
||||
public Uni<CombsArrayData> getAllCombArray(String uuid, SecurityCtx securityCtx) {
|
||||
return hasAccess(uuid, securityCtx)
|
||||
.chain(r -> getAllCombArray_(uuid, r.getMembre()));
|
||||
.chain(__ -> getAllCombArray(uuid));
|
||||
}
|
||||
|
||||
public Uni<CombsArrayData> getAllCombArrayPublic(String uuid) {
|
||||
return getAllCombArray_(uuid, null);
|
||||
return getAllCombArray(uuid);
|
||||
}
|
||||
|
||||
private Uni<CombsArrayData> getAllCombArray_(String uuid, MembreModel membreModel) {
|
||||
public Uni<CombsArrayData> getAllCombArray(String uuid) {
|
||||
return registerRepository.list("competition.uuid = ?1", uuid)
|
||||
.chain(registers -> matchRepository.list("category.compet.uuid = ?1", uuid)
|
||||
.map(matchModels -> new Pair<>(registers, matchModels)))
|
||||
@ -255,42 +228,57 @@ public class ResultService {
|
||||
CombsArrayData.CombsArrayDataBuilder builder = CombsArrayData.builder();
|
||||
|
||||
List<CombsArrayData.CombsData> combs = matchModels.stream()
|
||||
.flatMap(m -> Stream.of(m.getC1_id(), m.getC2_id(), m.getC1_guest(), m.getC2_guest()))
|
||||
.flatMap(m -> Stream.of(m.getC1Name(), m.getC2Name()))
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.map(comb -> {
|
||||
.map(combName -> {
|
||||
var builder2 = CombsArrayData.CombsData.builder();
|
||||
AtomicInteger w = new AtomicInteger(0);
|
||||
AtomicInteger l = new AtomicInteger(0);
|
||||
AtomicInteger pointMake = new AtomicInteger();
|
||||
AtomicInteger pointTake = new AtomicInteger();
|
||||
|
||||
makeStat(matchModels, comb, w, l, pointMake, pointTake);
|
||||
matchModels.stream()
|
||||
.filter(m -> m.isEnd() && (m.getC1Name().equals(combName)
|
||||
|| m.getC2Name().equals(combName)))
|
||||
.forEach(matchModel -> {
|
||||
int win = matchModel.win();
|
||||
if ((combName.equals(matchModel.getC1Name()) && win > 0) ||
|
||||
combName.equals(matchModel.getC2Name()) && win < 0) {
|
||||
w.getAndIncrement();
|
||||
} else {
|
||||
l.getAndIncrement();
|
||||
}
|
||||
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
.forEach(score -> {
|
||||
if (combName.equals(matchModel.getC1Name())) {
|
||||
pointMake.addAndGet(score.getS1());
|
||||
pointTake.addAndGet(score.getS2());
|
||||
} else {
|
||||
pointMake.addAndGet(score.getS2());
|
||||
pointTake.addAndGet(score.getS1());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Categorie categorie = null;
|
||||
String clubName = null;
|
||||
ClubModel club = null;
|
||||
|
||||
Optional<RegisterModel> register = registers.stream()
|
||||
.filter(r -> Objects.equals(r.getMembre(), comb)).findFirst();
|
||||
.filter(r -> r.getName().equals(combName)).findFirst();
|
||||
if (register.isPresent()) {
|
||||
categorie = register.get().getCategorie2();
|
||||
ClubModel club = register.get().getClub2();
|
||||
clubName = (club == null) ? BUNDLE.getString("no.licence") : club.getName();
|
||||
} else if (comb instanceof CompetitionGuestModel guestModel) {
|
||||
categorie = guestModel.getCategorie();
|
||||
clubName = guestModel.getClub();
|
||||
} else if (comb instanceof MembreModel model) {
|
||||
categorie = model.getCategorie();
|
||||
clubName = (model.getClub() == null) ? BUNDLE.getString(
|
||||
"no.licence") : model.getClub().getName();
|
||||
categorie = register.get().getCategorie();
|
||||
club = register.get().getClub2();
|
||||
}
|
||||
|
||||
builder2.cat((categorie == null) ? "---" : categorie.getName(BUNDLE));
|
||||
builder2.name(comb.getName(membreModel, ResultPrivacy.REGISTERED_ONLY));
|
||||
builder2.name(combName);
|
||||
builder2.w(w.get());
|
||||
builder2.l(l.get());
|
||||
builder2.ratioVictoire((l.get() == 0) ? w.get() : (float) w.get() / l.get());
|
||||
builder2.club(clubName);
|
||||
builder2.club((club == null) ? BUNDLE.getString("no.licence") : club.getName());
|
||||
builder2.pointMake(pointMake.get());
|
||||
builder2.pointTake(pointTake.get());
|
||||
builder2.ratioPoint(
|
||||
@ -310,62 +298,62 @@ public class ResultService {
|
||||
});
|
||||
}
|
||||
|
||||
public Uni<HashMap<String, String>> getCombList(String uuid, ResultPrivacy privacy) {
|
||||
return registerRepository.list("competition.uuid = ?1 AND membre.resultPrivacy <= ?2", uuid, privacy)
|
||||
public Uni<HashMap<String, String>> getCombList(String uuid) {
|
||||
return registerRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(models -> {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
models.forEach(
|
||||
r -> map.put(Utils.getFullName(r.getMembre()), getCombTempId(r.getMembre().getId())));
|
||||
models.forEach(registerEmbeddable -> {
|
||||
map.put(Utils.getFullName(registerEmbeddable.getMembre()),
|
||||
registerEmbeddable.getMembre().getFname() + "¤" + registerEmbeddable.getMembre()
|
||||
.getLname());
|
||||
});
|
||||
return map;
|
||||
})
|
||||
.chain(map -> competitionGuestRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(models -> {
|
||||
models.forEach(guestModel -> map.put(Utils.getFullName(guestModel),
|
||||
getCombTempId(guestModel.getId() * -1)));
|
||||
guestModel.getFname() + "¤" + guestModel.getLname()));
|
||||
return map;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public Uni<?> getCombArrayPublic(String uuid, String combTempId, ResultPrivacy privacy) {
|
||||
public Uni<?> getCombArrayPublic(String uuid, String fname, String lname) {
|
||||
CombArrayData.CombArrayDataBuilder builder = CombArrayData.builder();
|
||||
AtomicBoolean guest = new AtomicBoolean(false);
|
||||
AtomicLong id = new AtomicLong(0);
|
||||
|
||||
Long id = getCombTempId(combTempId);
|
||||
if (id == null) {
|
||||
return Uni.createFrom().failure(new DForbiddenException("Comb not found"));
|
||||
}
|
||||
|
||||
Uni<List<MatchModel>> uni;
|
||||
if (id >= 0) {
|
||||
uni = registerRepository.find("membre.id = ?1 AND competition.uuid = ?2 AND membre.resultPrivacy <= ?3", id,
|
||||
uuid, privacy).firstResult()
|
||||
.chain(Unchecked.function(registerModel -> {
|
||||
if (registerModel == null)
|
||||
throw new DBadRequestException("Combattant non inscrit");
|
||||
return registerRepository.find("membre.fname = ?1 AND membre.lname = ?2 AND competition.uuid = ?3", fname,
|
||||
lname, uuid).firstResult()
|
||||
.chain(registerModel -> {
|
||||
if (registerModel == null) {
|
||||
return competitionGuestRepository.find("fname = ?1 AND lname = ?2 AND competition.uuid = ?3",
|
||||
fname, lname, uuid).firstResult()
|
||||
.chain(guestModel -> {
|
||||
builder.name(Utils.getFullName(guestModel));
|
||||
builder.club(guestModel.getClub());
|
||||
guest.set(true);
|
||||
id.set(guestModel.getId());
|
||||
builder.cat((guestModel.getCategorie() == null) ? "---" : guestModel.getCategorie()
|
||||
.getName(BUNDLE));
|
||||
|
||||
builder.name(Utils.getFullName(registerModel.getMembre()));
|
||||
builder.club((registerModel.getClub2() == null) ? BUNDLE.getString(
|
||||
"no.licence") : registerModel.getClub2().getName());
|
||||
builder.cat((registerModel.getCategorie2() == null) ? "---" : registerModel.getCategorie2()
|
||||
.getName(BUNDLE));
|
||||
return matchRepository.list(
|
||||
"category.compet.uuid = ?1 AND (c1_guest = ?2 OR c2_guest = ?2)", uuid,
|
||||
guestModel);
|
||||
});
|
||||
}
|
||||
builder.name(Utils.getFullName(registerModel.getMembre()));
|
||||
builder.club((registerModel.getClub2() == null) ? BUNDLE.getString(
|
||||
"no.licence") : registerModel.getClub2().getName());
|
||||
id.set(registerModel.getMembre().getId());
|
||||
builder.cat((registerModel.getCategorie2() == null) ? "---" : registerModel.getCategorie2()
|
||||
.getName(BUNDLE));
|
||||
|
||||
return matchRepository.list("category.compet.uuid = ?1 AND (c1_id = ?2 OR c2_id = ?2)", uuid,
|
||||
registerModel.getMembre());
|
||||
}));
|
||||
} else {
|
||||
uni = competitionGuestRepository.find("id = ?1 AND competition.uuid = ?2", -id, uuid).firstResult()
|
||||
.chain(guestModel -> {
|
||||
builder.name(Utils.getFullName(guestModel));
|
||||
builder.club(guestModel.getClub());
|
||||
builder.cat((guestModel.getCategorie() == null) ? "---" : guestModel.getCategorie()
|
||||
.getName(BUNDLE));
|
||||
|
||||
return matchRepository.list("category.compet.uuid = ?1 AND (c1_guest = ?2 OR c2_guest = ?2)",
|
||||
uuid, guestModel);
|
||||
});
|
||||
}
|
||||
|
||||
return uni.invoke(matchModels -> {
|
||||
return matchRepository.list("category.compet.uuid = ?1 AND (c1_id = ?2 OR c2_id = ?2)", uuid,
|
||||
registerModel.getMembre());
|
||||
})
|
||||
.invoke(matchModels -> {
|
||||
List<CategoryModel> pouleModels = matchModels.stream().map(MatchModel::getCategory).distinct()
|
||||
.toList();
|
||||
List<CombArrayData.MatchsData> matchs = new ArrayList<>();
|
||||
@ -387,7 +375,9 @@ public class ResultService {
|
||||
AtomicInteger pointMake = new AtomicInteger();
|
||||
AtomicInteger pointTake = new AtomicInteger();
|
||||
|
||||
if (matchModel.isC1(id)) {
|
||||
if ((!guest.get() && matchModel.getC1_id() != null && matchModel.getC1_id().getId() == id.get())
|
||||
|| (guest.get() && matchModel.getC1_guest() != null && matchModel.getC1_guest()
|
||||
.getId() == id.get())) {
|
||||
builder2.adv(Utils.getFullName(matchModel.getC2_id(), matchModel.getC2_guest()));
|
||||
if (matchModel.isEnd()) {
|
||||
matchModel.getScores().stream()
|
||||
@ -466,141 +456,105 @@ public class ResultService {
|
||||
}
|
||||
}
|
||||
|
||||
public Uni<HashMap<String, Long>> getClubList(String uuid) {
|
||||
public Uni<HashMap<String, Long>> getClubList(String uuid) { // TODO add guest club
|
||||
return registerRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(registers -> {
|
||||
HashMap<String, Long> registerMap = new HashMap<>();
|
||||
registers.stream().map(RegisterModel::getClub2).distinct().filter(Objects::nonNull)
|
||||
.forEach(registerClub -> registerMap.put(registerClub.getName(), registerClub.getId()));
|
||||
return registerMap;
|
||||
})
|
||||
.chain(map -> competitionGuestRepository.list("competition.uuid = ?1", uuid)
|
||||
.map(guests -> {
|
||||
guests.stream().map(CompetitionGuestModel::getClub).distinct()
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(guestClub -> map.putIfAbsent(guestClub,
|
||||
getClubTempId(guestClub)));
|
||||
return map;
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public Uni<ClubArrayData> getClubArray(String uuid, Long id, SecurityCtx securityCtx) {
|
||||
return hasAccess(uuid, securityCtx).chain(cm_register -> getClubArray2(uuid, id, cm_register.getMembre()));
|
||||
public Uni<ClubArrayData> getClubArray(String uuid, SecurityCtx securityCtx) {
|
||||
return hasAccess(uuid, securityCtx).chain(cm_register -> getClubArray(uuid, cm_register.getClub2()));
|
||||
}
|
||||
|
||||
public Uni<ClubArrayData> getClubArray2(String uuid, Long id, MembreModel membreModel) {
|
||||
if (id < 0) {
|
||||
String clubName = getClubTempId(id);
|
||||
if (clubName == null) {
|
||||
return Uni.createFrom().failure(new DForbiddenException("Club not found"));
|
||||
}
|
||||
|
||||
return competitionGuestRepository.list("competition.uuid = ?1 AND club = ?2", uuid, clubName)
|
||||
.call(list -> {
|
||||
if (list.isEmpty())
|
||||
return Uni.createFrom().failure(new DBadRequestException("Club not found"));
|
||||
return Uni.createFrom().voidItem();
|
||||
})
|
||||
.chain(guests -> matchRepository.list(
|
||||
"category.compet.uuid = ?1 AND (c1_guest IN ?2 OR c2_guest IN ?2)", uuid, guests)
|
||||
.map(matchModels ->
|
||||
getClubArray2(clubName, guests.stream().map(o -> (CombModel) o).toList(),
|
||||
matchModels, new ArrayList<>(), membreModel)));
|
||||
} else {
|
||||
return clubRepository.findById(id).chain(clubModel ->
|
||||
registerRepository.list("competition.uuid = ?1 AND membre.club = ?2", uuid, clubModel)
|
||||
.chain(registers -> matchRepository.list("category.compet.uuid = ?1", uuid)
|
||||
.map(matchModels ->
|
||||
getClubArray2(clubModel.getName(),
|
||||
registers.stream().map(o -> (CombModel) o.getMembre()).toList(),
|
||||
matchModels, registers, membreModel))));
|
||||
}
|
||||
public Uni<ClubArrayData> getClubArrayPublic(String uuid, Long id) {
|
||||
return clubRepository.findById(id).chain(clubModel -> getClubArray(uuid, clubModel));
|
||||
}
|
||||
|
||||
private ClubArrayData getClubArray2(String name, List<CombModel> combs, List<MatchModel> matchModels,
|
||||
List<RegisterModel> registers, MembreModel membreModel) {
|
||||
public Uni<ClubArrayData> getClubArray(String uuid, ClubModel clubModel) {
|
||||
ClubArrayData.ClubArrayDataBuilder builder = ClubArrayData.builder();
|
||||
builder.name(name);
|
||||
builder.nb_insc(combs.size());
|
||||
builder.name(clubModel.getName());
|
||||
|
||||
AtomicInteger tt_win = new AtomicInteger(0);
|
||||
AtomicInteger tt_match = new AtomicInteger(0);
|
||||
return registerRepository.list("competition.uuid = ?1 AND membre.club = ?2", uuid, clubModel)
|
||||
.chain(registers -> matchRepository.list("category.compet.uuid = ?1", uuid)
|
||||
.map(matchModels -> new Pair<>(registers, matchModels)))
|
||||
.map(pair -> {
|
||||
List<RegisterModel> registers = pair.getKey();
|
||||
List<MatchModel> matchModels = pair.getValue();
|
||||
|
||||
List<ClubArrayData.CombData> combData = combs.stream().map(comb -> {
|
||||
var builder2 = ClubArrayData.CombData.builder();
|
||||
AtomicInteger w = new AtomicInteger(0);
|
||||
AtomicInteger l = new AtomicInteger(0);
|
||||
AtomicInteger pointMake = new AtomicInteger();
|
||||
AtomicInteger pointTake = new AtomicInteger();
|
||||
builder.nb_insc(registers.size());
|
||||
|
||||
makeStat(matchModels, comb, w, l, pointMake, pointTake);
|
||||
AtomicInteger tt_win = new AtomicInteger(0);
|
||||
AtomicInteger tt_match = new AtomicInteger(0);
|
||||
|
||||
Categorie categorie = null;
|
||||
List<ClubArrayData.CombData> combData = registers.stream().map(register -> {
|
||||
var builder2 = ClubArrayData.CombData.builder();
|
||||
AtomicInteger w = new AtomicInteger(0);
|
||||
AtomicInteger l = new AtomicInteger(0);
|
||||
AtomicInteger pointMake = new AtomicInteger();
|
||||
AtomicInteger pointTake = new AtomicInteger();
|
||||
|
||||
Optional<RegisterModel> register = registers.stream()
|
||||
.filter(r -> Objects.equals(r.getMembre(), comb)).findFirst();
|
||||
if (register.isPresent()) {
|
||||
categorie = register.get().getCategorie2();
|
||||
} else if (comb instanceof CompetitionGuestModel guestModel) {
|
||||
categorie = guestModel.getCategorie();
|
||||
} else if (comb instanceof MembreModel model) {
|
||||
categorie = model.getCategorie();
|
||||
}
|
||||
matchModels.stream()
|
||||
.filter(m -> m.isEnd() && (register.getMembre().equals(m.getC1_id())
|
||||
|| register.getMembre().equals(m.getC2_id())))
|
||||
.forEach(matchModel -> {
|
||||
int win = matchModel.win();
|
||||
if ((register.getMembre().equals(matchModel.getC1_id()) && win > 0) ||
|
||||
register.getMembre().equals(matchModel.getC2_id()) && win < 0) {
|
||||
w.getAndIncrement();
|
||||
} else {
|
||||
l.getAndIncrement();
|
||||
}
|
||||
|
||||
builder2.cat((categorie == null) ? "---" : categorie.getName(BUNDLE));
|
||||
builder2.name(comb.getName(membreModel, ResultPrivacy.REGISTERED_ONLY));
|
||||
builder2.w(w.get());
|
||||
builder2.l(l.get());
|
||||
builder2.ratioVictoire((l.get() == 0) ? w.get() : (float) w.get() / l.get());
|
||||
builder2.pointMake(pointMake.get());
|
||||
builder2.pointTake(pointTake.get());
|
||||
builder2.ratioPoint((pointTake.get() == 0) ? pointMake.get() : (float) pointMake.get() / pointTake.get());
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
.forEach(score -> {
|
||||
if (register.getMembre().equals(matchModel.getC1_id())) {
|
||||
pointMake.addAndGet(score.getS1());
|
||||
pointTake.addAndGet(score.getS2());
|
||||
} else {
|
||||
pointMake.addAndGet(score.getS2());
|
||||
pointTake.addAndGet(score.getS1());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
tt_win.addAndGet(w.get());
|
||||
tt_match.addAndGet(w.get() + l.get());
|
||||
Categorie categorie = register.getCategorie();
|
||||
if (categorie == null)
|
||||
categorie = register.getMembre().getCategorie();
|
||||
|
||||
return builder2.build();
|
||||
})
|
||||
.sorted(Comparator.comparing(ClubArrayData.CombData::name))
|
||||
.toList();
|
||||
builder2.cat((categorie == null) ? "---" : categorie.getName(BUNDLE));
|
||||
builder2.name(register.getName());
|
||||
builder2.w(w.get());
|
||||
builder2.l(l.get());
|
||||
builder2.ratioVictoire((l.get() == 0) ? w.get() : (float) w.get() / l.get());
|
||||
builder2.pointMake(pointMake.get());
|
||||
builder2.pointTake(pointTake.get());
|
||||
builder2.ratioPoint(
|
||||
(pointTake.get() == 0) ? pointMake.get() : (float) pointMake.get() / pointTake.get());
|
||||
|
||||
builder.nb_match(tt_match.get());
|
||||
builder.match_w(tt_win.get());
|
||||
builder.ratioVictoire((float) combData.stream().filter(c -> c.l + c.w != 0)
|
||||
.mapToDouble(ClubArrayData.CombData::ratioVictoire).average().orElse(0L));
|
||||
builder.pointMake(combData.stream().mapToInt(ClubArrayData.CombData::pointMake).sum());
|
||||
builder.pointTake(combData.stream().mapToInt(ClubArrayData.CombData::pointTake).sum());
|
||||
builder.ratioPoint((float) combData.stream().filter(c -> c.l + c.w != 0)
|
||||
.mapToDouble(ClubArrayData.CombData::ratioPoint).average().orElse(0L));
|
||||
builder.combs(combData);
|
||||
tt_win.addAndGet(w.get());
|
||||
tt_match.addAndGet(w.get() + l.get());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
return builder2.build();
|
||||
})
|
||||
.sorted(Comparator.comparing(ClubArrayData.CombData::name))
|
||||
.toList();
|
||||
|
||||
private static void makeStat(List<MatchModel> matchModels, CombModel comb, AtomicInteger w, AtomicInteger l,
|
||||
AtomicInteger pointMake, AtomicInteger pointTake) {
|
||||
matchModels.stream()
|
||||
.filter(m -> m.isEnd() && (m.isC1(comb) || m.isC2(comb)))
|
||||
.forEach(matchModel -> {
|
||||
int win = matchModel.win();
|
||||
if ((matchModel.isC1(comb) && win > 0) || matchModel.isC2(comb) && win < 0) {
|
||||
w.getAndIncrement();
|
||||
} else {
|
||||
l.getAndIncrement();
|
||||
}
|
||||
builder.nb_match(tt_match.get());
|
||||
builder.match_w(tt_win.get());
|
||||
builder.ratioVictoire((float) combData.stream().filter(c -> c.l + c.w != 0)
|
||||
.mapToDouble(ClubArrayData.CombData::ratioVictoire).average().orElse(0L));
|
||||
builder.pointMake(combData.stream().mapToInt(ClubArrayData.CombData::pointMake).sum());
|
||||
builder.pointTake(combData.stream().mapToInt(ClubArrayData.CombData::pointTake).sum());
|
||||
builder.ratioPoint((float) combData.stream().filter(c -> c.l + c.w != 0)
|
||||
.mapToDouble(ClubArrayData.CombData::ratioPoint).average().orElse(0L));
|
||||
builder.combs(combData);
|
||||
|
||||
matchModel.getScores().stream()
|
||||
.filter(s -> s.getS1() > -900 && s.getS2() > -900)
|
||||
.forEach(score -> {
|
||||
if (matchModel.isC1(comb)) {
|
||||
pointMake.addAndGet(score.getS1());
|
||||
pointTake.addAndGet(score.getS2());
|
||||
} else {
|
||||
pointMake.addAndGet(score.getS2());
|
||||
pointTake.addAndGet(score.getS1());
|
||||
}
|
||||
});
|
||||
return builder.build();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.ResultService;
|
||||
import fr.titionfire.ffsaf.domain.service.UpdateService;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
@ -37,7 +36,7 @@ public class ExternalResultEndpoints {
|
||||
return Uni.createFrom().voidItem();
|
||||
|
||||
if (updateService.needUpdate(poule, rf)) {
|
||||
return resultService.getCategory(id, poule);
|
||||
return resultService.getCategoryPublic(id, poule);
|
||||
} else {
|
||||
return Uni.createFrom().voidItem();
|
||||
}
|
||||
@ -47,7 +46,7 @@ public class ExternalResultEndpoints {
|
||||
@Path("/comb/list")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<HashMap<String, String>> combList() {
|
||||
return resultService.getCombList(id, ResultPrivacy.PUBLIC);
|
||||
return resultService.getCombList(id);
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -56,7 +55,7 @@ public class ExternalResultEndpoints {
|
||||
public Uni<?> getArray(@QueryParam("comb") String comb) {
|
||||
if (comb.equals("0"))
|
||||
return Uni.createFrom().item("");
|
||||
return resultService.getCombArrayPublic(id, comb, ResultPrivacy.PUBLIC);
|
||||
return resultService.getCombArrayPublic(id, comb.substring(0, comb.indexOf('¤')), comb.substring(comb.indexOf('¤') + 1));
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -67,6 +66,7 @@ public class ExternalResultEndpoints {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/club/list")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ -80,6 +80,6 @@ public class ExternalResultEndpoints {
|
||||
public Uni<?> getClubArray(@QueryParam("club") long club) {
|
||||
if (club == 0)
|
||||
return Uni.createFrom().item("");
|
||||
return resultService.getClubArray2(id, club, null);
|
||||
return resultService.getClubArrayPublic(id, club);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import fr.titionfire.ffsaf.domain.service.PDFService;
|
||||
import fr.titionfire.ffsaf.rest.data.MeData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembre;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
import fr.titionfire.ffsaf.rest.from.UserSettingForm;
|
||||
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
||||
import fr.titionfire.ffsaf.utils.Utils;
|
||||
import io.quarkus.security.Authenticated;
|
||||
@ -114,21 +113,6 @@ public class MembreEndpoints {
|
||||
return pdfService.getLicencePdf(securityCtx.getSubject());
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("me/setting")
|
||||
@Authenticated
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Operation(summary = "Met à jour les paramètres du membre connecté", description = "Met à jour les paramètres du membre connecté")
|
||||
@APIResponses(value = {
|
||||
@APIResponse(responseCode = "200", description = "Les paramètres ont été mis à jour"),
|
||||
@APIResponse(responseCode = "403", description = "Accès refusé"),
|
||||
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
|
||||
})
|
||||
public Uni<Void> updateMeSettings(UserSettingForm settingForm) {
|
||||
return membreService.updateSettings(securityCtx.getSubject(), settingForm);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("me/photo")
|
||||
@Authenticated
|
||||
|
||||
@ -2,7 +2,6 @@ package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.ResultService;
|
||||
import fr.titionfire.ffsaf.rest.data.ResultCategoryData;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
||||
import io.quarkus.security.Authenticated;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
@ -11,7 +10,6 @@ import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Authenticated
|
||||
@ -31,41 +29,17 @@ public class ResultEndpoints {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{uuid}/category/list")
|
||||
public Uni<HashMap<String, Long>> getCategoryList(@PathParam("uuid") String uuid) {
|
||||
return resultService.getCategoryList(uuid);
|
||||
@Path("{uuid}")
|
||||
public Uni<List<ResultCategoryData>> getCategory(@PathParam("uuid") String uuid) {
|
||||
return resultService.getCategory(uuid, securityCtx);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{uuid}/category/{id}")
|
||||
public Uni<ResultCategoryData> getCategory(@PathParam("uuid") String uuid, @PathParam("id") long id) {
|
||||
return resultService.getCategory(uuid, id, securityCtx);
|
||||
@Path("{uuid}/club")
|
||||
public Uni<ResultService.ClubArrayData> getClub(@PathParam("uuid") String uuid) {
|
||||
return resultService.getClubArray(uuid, securityCtx);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{uuid}/club/list")
|
||||
public Uni<HashMap<String, Long>> getClubList(@PathParam("uuid") String uuid) {
|
||||
return resultService.getClubList(uuid);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{uuid}/club/{id}")
|
||||
public Uni<ResultService.ClubArrayData> getClub(@PathParam("uuid") String uuid, @PathParam("id") long id) {
|
||||
return resultService.getClubArray(uuid, id, securityCtx);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{uuid}/comb/list")
|
||||
public Uni<HashMap<String, String>> getCombList(@PathParam("uuid") String uuid) {
|
||||
return resultService.getCombList(uuid, ResultPrivacy.REGISTERED_ONLY);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{uuid}/comb/{id}")
|
||||
public Uni<?> getCombList(@PathParam("uuid") String uuid, @PathParam("id") String id) {
|
||||
return resultService.getCombArrayPublic(uuid, id, ResultPrivacy.REGISTERED_ONLY);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{uuid}/comb")
|
||||
public Uni<ResultService.CombsArrayData> getComb(@PathParam("uuid") String uuid) {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -16,32 +15,30 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class MeData {
|
||||
@Schema(description = "L'identifiant du membre.", examples = "1")
|
||||
@Schema(description = "L'identifiant du membre.", example = "1")
|
||||
private long id;
|
||||
@Schema(description = "Le nom du membre.", examples = "Dupont")
|
||||
@Schema(description = "Le nom du membre.", example = "Dupont")
|
||||
private String lname = "";
|
||||
@Schema(description = "Le prénom du membre.", examples = "Jean")
|
||||
@Schema(description = "Le prénom du membre.", example = "Jean")
|
||||
private String fname = "";
|
||||
@Schema(description = "La catégorie du membre.", examples = "SENIOR")
|
||||
@Schema(description = "La catégorie du membre.", example = "SENIOR")
|
||||
private String categorie;
|
||||
@Schema(description = "Le nom du club du membre.", examples = "Association sportive")
|
||||
@Schema(description = "Le nom du club du membre.", example = "Association sportive")
|
||||
private String club;
|
||||
@Schema(description = "Le genre du membre.", examples = "Homme")
|
||||
@Schema(description = "Le genre du membre.", example = "Homme")
|
||||
private String genre;
|
||||
@Schema(description = "Le numéro de licence du membre.", examples = "12345")
|
||||
@Schema(description = "Le numéro de licence du membre.", example = "12345")
|
||||
private int licence;
|
||||
@Schema(description = "Le pays du membre.", examples = "FR")
|
||||
@Schema(description = "Le pays du membre.", example = "FR")
|
||||
private String country;
|
||||
@Schema(description = "La date de naissance du membre.")
|
||||
private Date birth_date;
|
||||
@Schema(description = "L'adresse e-mail du membre.", examples = "jean.dupont@examples.com")
|
||||
@Schema(description = "L'adresse e-mail du membre.", example = "jean.dupont@example.com")
|
||||
private String email;
|
||||
@Schema(description = "Le rôle du membre dans l'association.", examples = "MEMBRE")
|
||||
@Schema(description = "Le rôle du membre dans l'association.", example = "MEMBRE")
|
||||
private String role;
|
||||
@Schema(description = "Le grade d'arbitrage du membre.", examples = "N/A")
|
||||
@Schema(description = "Le grade d'arbitrage du membre.", example = "N/A")
|
||||
private String grade_arbitrage;
|
||||
@Schema(description = "La confidentialité des résultats", examples = "PUBLIC")
|
||||
private ResultPrivacy resultPrivacy;
|
||||
@Schema(description = "La liste des licences du membre.")
|
||||
private List<SimpleLicence> licences;
|
||||
|
||||
@ -58,6 +55,5 @@ public class MeData {
|
||||
this.email = membreModel.getEmail();
|
||||
this.role = membreModel.getRole().str;
|
||||
this.grade_arbitrage = membreModel.getGrade_arbitrage().str;
|
||||
this.resultPrivacy = membreModel.getResultPrivacy();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MatchModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
|
||||
import fr.titionfire.ffsaf.utils.TreeNode;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
@ -40,15 +38,15 @@ public class ResultCategoryData {
|
||||
|
||||
@RegisterForReflection
|
||||
public record PouleArrayData(String red, boolean red_w, List<Integer[]> score, boolean blue_w, String blue, boolean end) {
|
||||
public static PouleArrayData fromModel(MatchModel matchModel, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
public static PouleArrayData fromModel(MatchModel matchModel) {
|
||||
return new PouleArrayData(
|
||||
matchModel.getC1Name(membreModel, privacy),
|
||||
matchModel.getC1Name(),
|
||||
matchModel.isEnd() && matchModel.win() > 0,
|
||||
matchModel.isEnd() ?
|
||||
matchModel.getScores().stream().map(s -> new Integer[]{s.getS1(), s.getS2()}).toList()
|
||||
: new ArrayList<>(),
|
||||
matchModel.isEnd() && matchModel.win() < 0,
|
||||
matchModel.getC2Name(membreModel, privacy),
|
||||
matchModel.getC2Name(),
|
||||
matchModel.isEnd());
|
||||
}
|
||||
}
|
||||
@ -56,8 +54,8 @@ public class ResultCategoryData {
|
||||
@RegisterForReflection
|
||||
public static record TreeData(long id, String c1FullName, String c2FullName, List<ScoreEmbeddable> scores,
|
||||
boolean end) {
|
||||
public static TreeData from(MatchModel match, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
return new TreeData(match.getId(), match.getC1Name(membreModel, privacy), match.getC2Name(membreModel, privacy), match.getScores(), match.isEnd());
|
||||
public static TreeData from(MatchModel match) {
|
||||
return new TreeData(match.getId(), match.getC1Name(), match.getC2Name(), match.getScores(), match.isEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,32 +19,34 @@ import java.util.Date;
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class SimpleMembre {
|
||||
@Schema(description = "L'identifiant du membre.", examples = "1")
|
||||
@Schema(description = "L'identifiant du membre.", example = "1")
|
||||
private long id;
|
||||
@Schema(description = "L'identifiant long du membre (userID).", examples = "e81d1d35-d897-421e-8086-6c5e74d13c6e")
|
||||
@Schema(description = "L'identifiant long du membre (userID).", example = "e81d1d35-d897-421e-8086-6c5e74d13c6e")
|
||||
private String userId;
|
||||
@Schema(description = "Le nom du membre.", examples = "Dupont")
|
||||
@Schema(description = "Le nom du membre.", example = "Dupont")
|
||||
private String lname = "";
|
||||
@Schema(description = "Le prénom du membre.", examples = "Jean")
|
||||
@Schema(description = "Le prénom du membre.", example = "Jean")
|
||||
private String fname = "";
|
||||
@Schema(description = "La catégorie du membre.", examples = "SENIOR")
|
||||
@Schema(description = "La catégorie du membre.", example = "SENIOR")
|
||||
private Categorie categorie;
|
||||
@Schema(description = "Le club du membre.")
|
||||
private SimpleClubModel club;
|
||||
@Schema(description = "Le genre du membre.", examples = "H")
|
||||
@Schema(description = "Le genre du membre.", example = "H")
|
||||
private Genre genre;
|
||||
@Schema(description = "Le numéro de licence du membre.", examples = "12345")
|
||||
@Schema(description = "Le numéro de licence du membre.", example = "12345")
|
||||
private Integer licence;
|
||||
@Schema(description = "Le pays du membre.", examples = "FR")
|
||||
@Schema(description = "Le pays du membre.", example = "FR")
|
||||
private String country;
|
||||
@Schema(description = "La date de naissance du membre.")
|
||||
private Date birth_date;
|
||||
@Schema(description = "L'adresse e-mail du membre.", examples = "jean.dupont@examples.com")
|
||||
@Schema(description = "L'adresse e-mail du membre.", example = "jean.dupont@example.com")
|
||||
private String email;
|
||||
@Schema(description = "Le rôle du membre dans l'association.", examples = "MEMBRE")
|
||||
@Schema(description = "Le rôle du membre dans l'association.", example = "MEMBRE")
|
||||
private RoleAsso role;
|
||||
@Schema(description = "Le grade d'arbitrage du membre.", examples = "N/A")
|
||||
@Schema(description = "Le grade d'arbitrage du membre.", example = "N/A")
|
||||
private GradeArbitrage grade_arbitrage;
|
||||
@Schema(hidden = true)
|
||||
private String url_photo;
|
||||
|
||||
public static SimpleMembre fromModel(MembreModel model) {
|
||||
if (model == null)
|
||||
@ -64,6 +66,7 @@ public class SimpleMembre {
|
||||
.email(model.getEmail())
|
||||
.role(model.getRole())
|
||||
.grade_arbitrage(model.getGrade_arbitrage())
|
||||
.url_photo(model.getUrl_photo())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
package fr.titionfire.ffsaf.rest.from;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
import jakarta.ws.rs.FormParam;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import org.eclipse.microprofile.openapi.annotations.media.Schema;
|
||||
|
||||
@ToString
|
||||
@Getter
|
||||
public class UserSettingForm {
|
||||
@FormParam("resultPrivacy")
|
||||
@Schema(description = "La confidentialité des résultats", examples = "PUBLIC", defaultValue = "PUBLIC", required = true)
|
||||
private ResultPrivacy resultPrivacy;
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
public enum ResultPrivacy {
|
||||
PUBLIC,
|
||||
REGISTERED_ONLY,
|
||||
REGISTERED_ONLY_NO_DETAILS,
|
||||
PRIVATE;
|
||||
}
|
||||
@ -44,9 +44,9 @@ function AffiliationMenu() {
|
||||
}
|
||||
|
||||
function CompMenu() {
|
||||
const {is_authenticated} = useAuth()
|
||||
const {is_authenticated, userinfo} = useAuth()
|
||||
|
||||
if (!is_authenticated)
|
||||
if (!is_authenticated || !userinfo?.roles?.includes("federation_admin"))
|
||||
return <></>
|
||||
|
||||
return <li className="nav-item dropdown">
|
||||
|
||||
@ -12,10 +12,6 @@ import {
|
||||
faUserGroup,
|
||||
faVenus
|
||||
} from "@fortawesome/free-solid-svg-icons";
|
||||
import {CheckField} from "../components/MemberCustomFiels.jsx";
|
||||
import {toast} from "react-toastify";
|
||||
import {apiAxios} from "../utils/Tools.js";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
const vite_url = import.meta.env.VITE_URL;
|
||||
|
||||
@ -34,7 +30,6 @@ export function MePage() {
|
||||
</div>
|
||||
<div className="col-lg-8">
|
||||
<InformationForm data={data}/>
|
||||
<SettingsCard data={data}/>
|
||||
<div className="row">
|
||||
<div className="col-md-6">
|
||||
<LoadingProvider><LicenceCard userData={data}/></LoadingProvider>
|
||||
@ -101,47 +96,8 @@ function SelectCard() {
|
||||
</div>;
|
||||
}
|
||||
|
||||
function SettingsCard({data}) {
|
||||
const [privacy, setPrivacy] = useState("PUBLIC");
|
||||
|
||||
useEffect(() => {
|
||||
if (data?.resultPrivacy) {
|
||||
setPrivacy(data.resultPrivacy);
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const handleChange = (e) => {
|
||||
const formData = new FormData();
|
||||
formData.append("resultPrivacy", e.target.value);
|
||||
toast.promise(apiAxios.put(`/member/me/setting`, formData),
|
||||
{
|
||||
pending: 'Mise à jours des paramètres en cours...',
|
||||
success: 'Paramètres mis à jours avec succès 🎉',
|
||||
error: 'Échec de la mise à jours des paramètres 😕'
|
||||
})
|
||||
.then(() => {
|
||||
setPrivacy(String(formData.get("resultPrivacy")));
|
||||
});
|
||||
}
|
||||
|
||||
return <div className="card mb-4">
|
||||
<div className="card-header">Paramètres du compte</div>
|
||||
<div className="card-body">
|
||||
<div className="input-group mb-3">
|
||||
<label className="input-group-text" htmlFor="email_notifications">Visibilité des résultats</label>
|
||||
<select className="form-select" id="result_visibility" name="result_visibility" required value={privacy} onChange={handleChange}>
|
||||
<option value="PUBLIC">Public (visible par tous)</option>
|
||||
<option value="REGISTERED_ONLY">Membres connectés (visibles par les membres de la fédération)</option>
|
||||
<option value="REGISTERED_ONLY_NO_DETAILS">Membres connectés - masquer les détails (visibles par les membres de la fédération)
|
||||
</option>
|
||||
<option value="PRIVATE">Privé (visible uniquement par moi)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
|
||||
function InformationForm({data}) {
|
||||
export function InformationForm({data}) {
|
||||
const style = {marginRight: '0.7em'}
|
||||
|
||||
return <div className="card mb-4">
|
||||
@ -171,4 +127,4 @@ function InformationForm({data}) {
|
||||
</div>
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@ import {useLoadingSwitcher} from "../../hooks/useLoading.jsx";
|
||||
import {useFetch} from "../../hooks/useFetch.js";
|
||||
import {AxiosError} from "../../components/AxiosError.jsx";
|
||||
import {ThreeDots} from "react-loader-spinner";
|
||||
import React, {useEffect, useState} from "react";
|
||||
import {useEffect, useState} from "react";
|
||||
import {DrawGraph} from "./DrawGraph.jsx";
|
||||
import {TreeNode} from "../../utils/TreeUtils.js";
|
||||
import {scoreToString} from "../../utils/CompetitionTools.js";
|
||||
@ -17,45 +17,50 @@ function CupImg() {
|
||||
export function ResultView() {
|
||||
const {uuid} = useParams()
|
||||
const navigate = useNavigate();
|
||||
const [resultShow, setResultShow] = useState("cat")
|
||||
const [resultShow, setResultShow] = useState(null)
|
||||
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/result/${uuid}`, setLoading, 1)
|
||||
|
||||
return <>
|
||||
<button type="button" className="btn btn-link" onClick={() => navigate("/result")}>
|
||||
« retour
|
||||
</button>
|
||||
|
||||
<MenuBar resultShow={resultShow} setResultShow={setResultShow}/>
|
||||
{data ? <MenuBar data={data} resultShow={resultShow} setResultShow={setResultShow}/>
|
||||
: error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>}
|
||||
|
||||
<div className="row" style={{marginTop: "1em"}}>
|
||||
<div className="row">
|
||||
<div className="col-auto">
|
||||
{resultShow && resultShow === "cat" && <CategoryList uuid={uuid}/>
|
||||
|| resultShow && resultShow === "club" && <ClubList uuid={uuid}/>
|
||||
|| resultShow && resultShow === "comb" && <CombList uuid={uuid}/>
|
||||
|| resultShow && resultShow === "combs" && <CombsResult uuid={uuid}/>}
|
||||
{resultShow && resultShow.type !== undefined && <PouleResult data={resultShow}/>
|
||||
|| resultShow && resultShow === "club" && <ClubResult uuid={uuid}/>
|
||||
|| resultShow && resultShow === "comb" && <CombResult uuid={uuid}/>}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
|
||||
// || resultShow && resultShow === "club_all" && <ClubAllResult uuid={uuid}/>
|
||||
|
||||
function MenuBar({resultShow, setResultShow}) {
|
||||
function MenuBar({data, resultShow, setResultShow}) {
|
||||
return <ul className="nav nav-tabs">
|
||||
<li className="nav-item">
|
||||
<a className={"nav-link my-1" + (resultShow === "cat" ? " active" : "")} aria-current={(resultShow === "cat" ? " page" : "false")}
|
||||
href="#" onClick={_ => setResultShow("cat")}>Par catégorie</a>
|
||||
<li className="nav-item dropdown">
|
||||
<a className={"nav-link dropdown-toggle my-1"} data-bs-toggle="dropdown" href="#"
|
||||
aria-current={(resultShow?.type !== undefined ? " page" : "false")} role="button" aria-expanded="false">Catégorie</a>
|
||||
<ul className="dropdown-menu">
|
||||
{data.map(item => <li><a key={item.name} className={"dropdown-item" + (resultShow === item ? " active" : "")}
|
||||
aria-current={(resultShow === item ? " page" : "false")} href="#" data-bs-toggle="collapse"
|
||||
onClick={_ => setResultShow(item)}>{item.name}</a></li>)}
|
||||
</ul>
|
||||
</li>
|
||||
<li className="nav-item">
|
||||
<a className={"nav-link my-1" + (resultShow === "club" ? " active" : "")} aria-current={(resultShow === "club" ? " page" : "false")}
|
||||
href="#" onClick={_ => setResultShow("club")}>Par club</a>
|
||||
href="#" onClick={_ => setResultShow("club")}>Mon club</a>
|
||||
</li>
|
||||
<li className="nav-item">
|
||||
<a className={"nav-link my-1" + (resultShow === "comb" ? " active" : "")} aria-current={(resultShow === "comb" ? " page" : "false")}
|
||||
href="#" onClick={_ => setResultShow("comb")}>Par combattant</a>
|
||||
</li>
|
||||
<li className="nav-item">
|
||||
<a className={"nav-link my-1" + (resultShow === "combs" ? " active" : "")} aria-current={(resultShow === "combs" ? " page" : "false")}
|
||||
href="#" onClick={_ => setResultShow("combs")}>Combattants</a>
|
||||
href="#" onClick={_ => setResultShow("comb")}>Combattants</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@ -143,51 +148,13 @@ function BuildTree({treeData}) {
|
||||
return <DrawGraph root={initTree(treeData)}/>
|
||||
}
|
||||
|
||||
function CategoryList({uuid}) {
|
||||
const [catId, setCatId] = useState(null)
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/result/${uuid}/category/list`, setLoading, 1)
|
||||
function PouleResult({data}) {
|
||||
const [type, setType] = useState(data.type === 3 ? 1 : data.type)
|
||||
|
||||
useEffect(() => {
|
||||
if (data && Object.keys(data).length > 0)
|
||||
setCatId(data[Object.keys(data).sort()[0]])
|
||||
setType(data.type === 3 ? 1 : data.type)
|
||||
}, [data]);
|
||||
|
||||
return <>
|
||||
{data ? <div className="input-group" style={{marginBottom: "1em"}}>
|
||||
<h6 style={{margin: "auto 0.5em auto 0"}}>Catégorie</h6>
|
||||
<select className="form-select" aria-label="Select Result Type" onChange={e => setCatId(e.target.value)}>
|
||||
{Object.keys(data).sort().map(key => <option key={key} value={data[key]}>{key}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
: error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>}
|
||||
{catId && <CategoryResult uuid={uuid} catId={catId}/>}
|
||||
</>
|
||||
}
|
||||
|
||||
function CategoryResult({uuid, catId}) {
|
||||
const [type, setType] = useState(1)
|
||||
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, refresh, error} = useFetch(`/result/${uuid}/category/${catId}`, setLoading, 1)
|
||||
|
||||
useEffect(() => {
|
||||
refresh(`/result/${uuid}/category/${catId}`)
|
||||
}, [catId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (data)
|
||||
setType(data.type === 3 ? 1 : data.type)
|
||||
}, [data]);
|
||||
|
||||
if (!data) {
|
||||
return error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>
|
||||
}
|
||||
|
||||
return <>
|
||||
{data.type === 3 && <>
|
||||
<ul className="nav nav-tabs">
|
||||
@ -217,37 +184,9 @@ function CategoryResult({uuid, catId}) {
|
||||
</>
|
||||
}
|
||||
|
||||
function ClubList({uuid}) {
|
||||
const [clubId, setClubId] = useState(null)
|
||||
function ClubResult({uuid}) {
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/result/${uuid}/club/list`, setLoading, 1)
|
||||
|
||||
useEffect(() => {
|
||||
if (data && Object.keys(data).length > 0)
|
||||
setClubId(data[Object.keys(data).sort()[0]])
|
||||
}, [data]);
|
||||
|
||||
return <>
|
||||
{data ? <div className="input-group" style={{marginBottom: "1em"}}>
|
||||
<h6 style={{margin: "auto 0.5em auto 0"}}>Club</h6>
|
||||
<select className="form-select" aria-label="Select Result Type" onChange={e => setClubId(e.target.value)}>
|
||||
{Object.keys(data).sort().map(key => <option key={key} value={data[key]}>{key}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
: error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>}
|
||||
{clubId && <ClubResult uuid={uuid} clubId={clubId}/>}
|
||||
</>
|
||||
}
|
||||
|
||||
function ClubResult({uuid, clubId}) {
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, refresh, error} = useFetch(`/result/${uuid}/club/${clubId}`, setLoading, 1)
|
||||
|
||||
useEffect(() => {
|
||||
refresh(`/result/${uuid}/club/${clubId}`)
|
||||
}, [clubId]);
|
||||
const {data, error} = useFetch(`/result/${uuid}/club`, setLoading, 1)
|
||||
|
||||
return <>
|
||||
{data ? <>
|
||||
@ -303,102 +242,25 @@ function ClubResult({uuid, clubId}) {
|
||||
</>
|
||||
}
|
||||
|
||||
function CombList({uuid}) {
|
||||
const [combId, setCombId] = useState(null)
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/result/${uuid}/comb/list`, setLoading, 1)
|
||||
/*function ClubAllResult({uuid}) {
|
||||
return <div></div>
|
||||
|
||||
useEffect(() => {
|
||||
if (data && Object.keys(data).length > 0)
|
||||
setCombId(data[Object.keys(data).sort()[0]])
|
||||
}, [data]);
|
||||
}*/
|
||||
|
||||
return <>
|
||||
{data ? <div className="input-group" style={{marginBottom: "1em"}}>
|
||||
<h6 style={{margin: "auto 0.5em auto 0"}}>Combattant</h6>
|
||||
<select className="form-select" aria-label="Select Result Type" onChange={e => setCombId(e.target.value)}>
|
||||
{Object.keys(data).sort().map(key => <option key={key} value={data[key]}>{key}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
: error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>}
|
||||
{combId && <CombResult uuid={uuid} combId={combId}/>}
|
||||
</>
|
||||
}
|
||||
|
||||
function CombResult({uuid, combId}) {
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, refresh, error} = useFetch(`/result/${uuid}/comb/${combId}`, setLoading, 1)
|
||||
|
||||
useEffect(() => {
|
||||
refresh(`/result/${uuid}/comb/${combId}`)
|
||||
}, [combId]);
|
||||
|
||||
|
||||
if (!data) {
|
||||
return error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>
|
||||
}
|
||||
|
||||
return <div>
|
||||
<h3>Info :</h3>
|
||||
<ul>
|
||||
<li>Nom Prénom : {data.name}</li>
|
||||
<li>Club : {data.club}</li>
|
||||
<li>Catégorie : {data.cat}</li>
|
||||
</ul>
|
||||
<h3>Statistique :</h3>
|
||||
<ul>
|
||||
<li>Taux de victoire : {data.matchs.length === 0 ? "---" : (data.totalWin / data.matchs.length * 100).toFixed(0)}% ({data.totalWin} sur
|
||||
${data.matchs.length})
|
||||
</li>
|
||||
<li>Points marqués : {data.pointMake}</li>
|
||||
<li>Points reçus : {data.pointTake}</li>
|
||||
<li>Ratio du score (point marqué / point reçu): {data.pointRatio.toFixed(3)}</li>
|
||||
</ul>
|
||||
|
||||
<h3>Liste des matchs:</h3>
|
||||
|
||||
<table className="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" style={{textAlign: "center"}}>Catégorie</th>
|
||||
<th scope="col" style={{textAlign: "center"}}>Adversaire</th>
|
||||
<th scope="col" style={{textAlign: "center"}}>Scores</th>
|
||||
<th scope="col" style={{textAlign: "center"}}>Ratio</th>
|
||||
<th scope="col" style={{textAlign: "center"}}></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{data.matchs.map((match, idx) => <tr key={idx}>
|
||||
<td style={{textAlign: "center"}}>{match.poule}</td>
|
||||
<td style={{textAlign: "center"}}>{match.adv}</td>
|
||||
<td style={{textAlign: "center"}}>{scoreToString(match.score)}</td>
|
||||
<td style={{textAlign: "center"}}>{match.ratio.toFixed(3)}</td>
|
||||
<td style={{textAlign: "left"}}>{match.win ? <CupImg/> : ""}</td>
|
||||
</tr>)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
function CombsResult({uuid}) {
|
||||
function CombResult({uuid}) {
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/result/${uuid}/comb`, setLoading, 1)
|
||||
|
||||
return <>
|
||||
{data ? <>
|
||||
<h3>Statistique :</h3>
|
||||
<h3>Statistique :</h3>
|
||||
<ul>
|
||||
<li>Nombre d'inscris : {data.nb_insc}</li>
|
||||
<li>Nombre de match disputé : {data.tt_match}</li>
|
||||
<li>Points marqués : {data.point}</li>
|
||||
<li>Nombre d'inscris : {data.nb_insc}</li>
|
||||
<li>Nombre de match disputé : {data.tt_match}</li>
|
||||
<li>Points marqués : {data.point}</li>
|
||||
</ul>
|
||||
|
||||
<h3>Liste des combattants :</h3>
|
||||
<h3>Liste des combattants :</h3>
|
||||
|
||||
<table className="table table-striped">
|
||||
<thead>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user