Various bugfixes for teams support

This commit is contained in:
Claude Brisson
2024-04-15 19:50:45 +02:00
parent 179a502bbc
commit 23a4ae37b2
8 changed files with 22 additions and 11 deletions

View File

@@ -147,12 +147,10 @@ object PairingHandler: PairgothApiHandler {
override fun delete(request: HttpServletRequest, response: HttpServletResponse): Json {
val tournament = getTournament(request)
val round = getSubSelector(request)?.toIntOrNull() ?: badRequest("invalid round number")
// only allow last round (if players have not been paired in the last round, it *may* be possible to be more laxist...)
// Nope
// if (round != tournament.lastRound()) badRequest("cannot delete games in other rounds but the last")
val payload = getArrayPayload(request)
val allPlayers = payload.size == 1 && payload[0] == "all"
if (allPlayers) {
// TODO - just remove this, it is never used ; and no check is done on whether the players are playing...
tournament.games(round).clear()
} else {
payload.forEach {

View File

@@ -161,11 +161,11 @@ ${
"${
player.getString("num")!!.padStart(4, ' ')
} ${
"${player.getString("name")} ${player.getString("firstname")}".padEnd(30, ' ').take(30)
"${player.getString("name")} ${player.getString("firstname") ?: ""}".padEnd(30, ' ').take(30)
} ${
displayRank(player.getInt("rank")!!).uppercase().padStart(3, ' ')
} ${
player.getString("country")!!.uppercase()
player.getString("country")?.uppercase() ?: ""
} ${
(player.getString("club") ?: "").padStart(4).take(4)
} ${
@@ -209,7 +209,7 @@ ${
"${
player.getString("num")!!.padStart(4, ' ')
} ${
"${player.getString("name")} ${player.getString("firstname")}".padEnd(24, ' ').take(24)
"${player.getString("name")} ${player.getString("firstname") ?: ""}".padEnd(24, ' ').take(24)
} ${
displayRank(player.getInt("rank")!!).uppercase().padStart(3, ' ')
} ${
@@ -255,7 +255,7 @@ ${
// lines
lines.forEach { line ->
writer.println("${
fields.joinToString(";") { if (it.second) "\"${line[it.first]}\"" else "${line[it.first]}" }
fields.joinToString(";") { if (it.second) "\"${line[it.first] ?: ""}\"" else "${line[it.first] ?: ""}" }
};${
line.getArray("results")!!.joinToString(";")
};${

View File

@@ -45,6 +45,9 @@ object TeamHandler: PairgothApiHandler {
val tournament = getTournament(request)
if (tournament !is TeamTournament) badRequest("tournament is not a team tournament")
val id = getSubSelector(request)?.toIntOrNull() ?: badRequest("missing or invalid team selector")
if (tournament.pairedPlayers().contains(id)) {
badRequest("team is playing");
}
tournament.teams.remove(id) ?: badRequest("invalid team id")
tournament.dispatchEvent(TeamDeleted, request, Json.Object("id" to id))
return Json.Object("success" to true)

View File

@@ -21,7 +21,7 @@ sealed class Pairable(val id: ID, val name: String, val rating: Int, val rank: I
open fun fullName(separator: String = " "): String {
return name
}
val skip = mutableSetOf<Int>() // skipped rounds
open val skip = mutableSetOf<Int>() // skipped rounds
fun equals(other: Pairable): Boolean {
return id == other.id

View File

@@ -196,6 +196,8 @@ class TeamTournament(
club?.also { json["club"] = it }
}
val teamOfIndividuals: Boolean get() = type.individual
override val skip get() = playerIds.map { players[it]!!.skip }.reduce { left, right -> (left union right) as MutableSet<Int> }
}
fun teamFromJson(json: Json.Object, default: TeamTournament.Team? = null): Team {