Change pairing API GET call

This commit is contained in:
Claude Brisson
2023-12-21 22:33:04 +01:00
parent 68177932b9
commit 844f7aa699
2 changed files with 9 additions and 2 deletions

View File

@@ -20,7 +20,14 @@ object PairingHandler: PairgothApiHandler {
val playing = tournament.games(round).values.flatMap { val playing = tournament.games(round).values.flatMap {
listOf(it.black, it.white) listOf(it.black, it.white)
}.toSet() }.toSet()
return tournament.pairables.values.filter { !it.skip.contains(round) && !playing.contains(it.id) }.sortedByDescending { it.rating }.map { it.id }.toJsonArray() val unpairables = tournament.pairables.values.filter { it.skip.contains(round) }.sortedByDescending { it.rating }.map { it.id }.toJsonArray()
val pairables = tournament.pairables.values.filter { !it.skip.contains(round) && !playing.contains(it.id) }.sortedByDescending { it.rating }.map { it.id }.toJsonArray()
val games = tournament.games(round).values
return Json.Object(
"games" to games.map { it.toJson() }.toCollection(Json.MutableArray()),
"pairables" to pairables,
"unpairables" to unpairables
)
} }
override fun post(request: HttpServletRequest): Json { override fun post(request: HttpServletRequest): Json {

View File

@@ -155,7 +155,7 @@ class BasicTests: TestBase() {
"""[{"id":$aTournamentGameID,"w":$anotherPlayerID,"b":$aPlayerID,"h":0,"r":"?","dd":0}]""" """[{"id":$aTournamentGameID,"w":$anotherPlayerID,"b":$aPlayerID,"h":0,"r":"?","dd":0}]"""
) )
assertTrue(possibleResults.contains(games.toString()), "pairing differs") assertTrue(possibleResults.contains(games.toString()), "pairing differs")
games = TestAPI.get("/api/tour/$aTournamentID/res/1").asArray() games = TestAPI.get("/api/tour/$aTournamentID/res/1").asObject().getArray("games")!!
assertTrue(possibleResults.contains(games.toString()), "results differs") assertTrue(possibleResults.contains(games.toString()), "results differs")
val empty = TestAPI.get("/api/tour/$aTournamentID/pair/1").asArray() val empty = TestAPI.get("/api/tour/$aTournamentID/pair/1").asArray()
assertEquals("[]", empty.toString(), "no more pairables for round 1") assertEquals("[]", empty.toString(), "no more pairables for round 1")