diff --git a/src/main/java/fr/titionfire/ffsaf/domain/service/ResultService.java b/src/main/java/fr/titionfire/ffsaf/domain/service/ResultService.java index 6b7afeb..3ed9a78 100644 --- a/src/main/java/fr/titionfire/ffsaf/domain/service/ResultService.java +++ b/src/main/java/fr/titionfire/ffsaf/domain/service/ResultService.java @@ -18,7 +18,6 @@ import org.hibernate.reactive.mutiny.Mutiny; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Stream; @WithSession @@ -113,26 +112,17 @@ public class ResultService { }); } - public Uni> getCategory(String uuid, SecurityCtx securityCtx) { - AtomicReference membreModel = new AtomicReference<>(); - return hasAccess(uuid, securityCtx) - .invoke(m -> membreModel.set(m.getMembre())) - .chain(m -> matchRepository.list("category.compet.uuid = ?1", uuid)) - .map(matchModels -> { - HashMap> 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); - } + public Uni 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()))); + } - return map.values(); - }) - .onItem() - .transformToMulti(Multi.createFrom()::iterable) - .onItem().call(list -> Mutiny.fetch(list.get(0).getCategory().getTree())) - .onItem().transform(list -> getData(list, membreModel.get())) - .collect().asList(); + public Uni 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 matchModels, MembreModel membreModel) { @@ -235,12 +225,6 @@ public class ResultService { } } - public Uni 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(list -> getData(list, null)); - } - private void getTree(List treeModels, MembreModel membreModel, ResultCategoryData out) { ArrayList> trees = new ArrayList<>(); treeModels.stream().filter(t -> t.getLevel() != 0).forEach(treeModel -> { @@ -501,17 +485,11 @@ public class ResultService { ); } - public Uni getClubArray(String uuid, SecurityCtx securityCtx) { - return hasAccess(uuid, securityCtx).chain(cm_register -> - registerRepository.list("competition.uuid = ?1 AND membre.club = ?2", uuid, cm_register.getClub2()) - .chain(registers -> matchRepository.list("category.compet.uuid = ?1", uuid) - .map(matchModels -> - getClubArray2(cm_register.getClub2().getName(), - registers.stream().map(o -> (CombModel) o.getMembre()).toList(), - matchModels, registers, cm_register.getMembre())))); + public Uni getClubArray(String uuid, Long id, SecurityCtx securityCtx) { + return hasAccess(uuid, securityCtx).chain(cm_register -> getClubArray2(uuid, id, cm_register.getMembre())); } - public Uni getClubArrayPublic(String uuid, Long id) { + public Uni getClubArray2(String uuid, Long id, MembreModel membreModel) { if (id < 0) { String clubName = getClubTempId(id); if (clubName == null) { @@ -528,7 +506,7 @@ public class ResultService { "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<>(), null))); + matchModels, new ArrayList<>(), membreModel))); } else { return clubRepository.findById(id).chain(clubModel -> registerRepository.list("competition.uuid = ?1 AND membre.club = ?2", uuid, clubModel) @@ -536,7 +514,7 @@ public class ResultService { .map(matchModels -> getClubArray2(clubModel.getName(), registers.stream().map(o -> (CombModel) o.getMembre()).toList(), - matchModels, registers, null)))); + matchModels, registers, membreModel)))); } } diff --git a/src/main/java/fr/titionfire/ffsaf/rest/ExternalResultEndpoints.java b/src/main/java/fr/titionfire/ffsaf/rest/ExternalResultEndpoints.java index cd9a543..2febbd1 100644 --- a/src/main/java/fr/titionfire/ffsaf/rest/ExternalResultEndpoints.java +++ b/src/main/java/fr/titionfire/ffsaf/rest/ExternalResultEndpoints.java @@ -37,7 +37,7 @@ public class ExternalResultEndpoints { return Uni.createFrom().voidItem(); if (updateService.needUpdate(poule, rf)) { - return resultService.getCategoryPublic(id, poule); + return resultService.getCategory(id, poule); } else { return Uni.createFrom().voidItem(); } @@ -67,7 +67,6 @@ public class ExternalResultEndpoints { } - @GET @Path("/club/list") @Produces(MediaType.APPLICATION_JSON) @@ -81,6 +80,6 @@ public class ExternalResultEndpoints { public Uni getClubArray(@QueryParam("club") long club) { if (club == 0) return Uni.createFrom().item(""); - return resultService.getClubArrayPublic(id, club); + return resultService.getClubArray2(id, club, null); } } diff --git a/src/main/java/fr/titionfire/ffsaf/rest/ResultEndpoints.java b/src/main/java/fr/titionfire/ffsaf/rest/ResultEndpoints.java index 4016887..e1449fb 100644 --- a/src/main/java/fr/titionfire/ffsaf/rest/ResultEndpoints.java +++ b/src/main/java/fr/titionfire/ffsaf/rest/ResultEndpoints.java @@ -2,6 +2,7 @@ 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; @@ -10,6 +11,7 @@ import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; +import java.util.HashMap; import java.util.List; @Authenticated @@ -29,17 +31,41 @@ public class ResultEndpoints { } @GET - @Path("{uuid}") - public Uni> getCategory(@PathParam("uuid") String uuid) { - return resultService.getCategory(uuid, securityCtx); + @Path("{uuid}/category/list") + public Uni> getCategoryList(@PathParam("uuid") String uuid) { + return resultService.getCategoryList(uuid); } @GET - @Path("{uuid}/club") - public Uni getClub(@PathParam("uuid") String uuid) { - return resultService.getClubArray(uuid, securityCtx); + @Path("{uuid}/category/{id}") + public Uni getCategory(@PathParam("uuid") String uuid, @PathParam("id") long id) { + return resultService.getCategory(uuid, id, securityCtx); } + @GET + @Path("{uuid}/club/list") + public Uni> getClubList(@PathParam("uuid") String uuid) { + return resultService.getClubList(uuid); + } + + @GET + @Path("{uuid}/club/{id}") + public Uni getClub(@PathParam("uuid") String uuid, @PathParam("id") long id) { + return resultService.getClubArray(uuid, id, securityCtx); + } + + @GET + @Path("{uuid}/comb/list") + public Uni> 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 getComb(@PathParam("uuid") String uuid) { diff --git a/src/main/webapp/src/pages/result/ResultView.jsx b/src/main/webapp/src/pages/result/ResultView.jsx index 0dedb13..7f06393 100644 --- a/src/main/webapp/src/pages/result/ResultView.jsx +++ b/src/main/webapp/src/pages/result/ResultView.jsx @@ -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 {useEffect, useState} from "react"; +import React, {useEffect, useState} from "react"; import {DrawGraph} from "./DrawGraph.jsx"; import {TreeNode} from "../../utils/TreeUtils.js"; import {scoreToString} from "../../utils/CompetitionTools.js"; @@ -17,50 +17,45 @@ function CupImg() { export function ResultView() { const {uuid} = useParams() const navigate = useNavigate(); - const [resultShow, setResultShow] = useState(null) - - const setLoading = useLoadingSwitcher() - const {data, error} = useFetch(`/result/${uuid}`, setLoading, 1) + const [resultShow, setResultShow] = useState("cat") return <> - {data ? - : error - ? - : } + -
+
- {resultShow && resultShow.type !== undefined && - || resultShow && resultShow === "club" && - || resultShow && resultShow === "comb" && } + {resultShow && resultShow === "cat" && + || resultShow && resultShow === "club" && + || resultShow && resultShow === "comb" && + || resultShow && resultShow === "combs" && }
} + // || resultShow && resultShow === "club_all" && -function MenuBar({data, resultShow, setResultShow}) { +function MenuBar({resultShow, setResultShow}) { return @@ -148,13 +143,51 @@ function BuildTree({treeData}) { return } -function PouleResult({data}) { - const [type, setType] = useState(data.type === 3 ? 1 : data.type) +function CategoryList({uuid}) { + const [catId, setCatId] = useState(null) + const setLoading = useLoadingSwitcher() + const {data, error} = useFetch(`/result/${uuid}/category/list`, setLoading, 1) useEffect(() => { - setType(data.type === 3 ? 1 : data.type) + if (data && Object.keys(data).length > 0) + setCatId(data[Object.keys(data).sort()[0]]) }, [data]); + return <> + {data ?
+
Catégorie
+ +
+ : error + ? + : } + {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 + ? + : + } + return <> {data.type === 3 && <>
    @@ -184,9 +217,37 @@ function PouleResult({data}) { } -function ClubResult({uuid}) { +function ClubList({uuid}) { + const [clubId, setClubId] = useState(null) const setLoading = useLoadingSwitcher() - const {data, error} = useFetch(`/result/${uuid}/club`, setLoading, 1) + 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 ?
    +
    Club
    + +
    + : error + ? + : } + {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]); return <> {data ? <> @@ -242,25 +303,102 @@ function ClubResult({uuid}) { } -/*function ClubAllResult({uuid}) { - return
    +function CombList({uuid}) { + const [combId, setCombId] = useState(null) + const setLoading = useLoadingSwitcher() + const {data, error} = useFetch(`/result/${uuid}/comb/list`, setLoading, 1) -}*/ + useEffect(() => { + if (data && Object.keys(data).length > 0) + setCombId(data[Object.keys(data).sort()[0]]) + }, [data]); -function CombResult({uuid}) { + return <> + {data ?
    +
    Combattant
    + +
    + : error + ? + : } + {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 + ? + : + } + + return
    +

    Info :

    +
      +
    • Nom Prénom : {data.name}
    • +
    • Club : {data.club}
    • +
    • Catégorie : {data.cat}
    • +
    +

    Statistique :

    +
      +
    • Taux de victoire : {data.matchs.length === 0 ? "---" : (data.totalWin / data.matchs.length * 100).toFixed(0)}% ({data.totalWin} sur + ${data.matchs.length}) +
    • +
    • Points marqués : {data.pointMake}
    • +
    • Points reçus : {data.pointTake}
    • +
    • Ratio du score (point marqué / point reçu): {data.pointRatio.toFixed(3)}
    • +
    + +

    Liste des matchs:

    + + + + + + + + + + + + + + {data.matchs.map((match, idx) => + + + + + + )} + +
    CatégorieAdversaireScoresRatio
    {match.poule}{match.adv}{scoreToString(match.score)}{match.ratio.toFixed(3)}{match.win ? : ""}
    +
    +} + +function CombsResult({uuid}) { const setLoading = useLoadingSwitcher() const {data, error} = useFetch(`/result/${uuid}/comb`, setLoading, 1) return <> {data ? <> -

    Statistique :

    +

    Statistique :

      -
    • Nombre d'inscris : {data.nb_insc}
    • -
    • Nombre de match disputé : {data.tt_match}
    • -
    • Points marqués : {data.point}
    • +
    • Nombre d'inscris : {data.nb_insc}
    • +
    • Nombre de match disputé : {data.tt_match}
    • +
    • Points marqués : {data.point}
    -

    Liste des combattants :

    +

    Liste des combattants :