Add manual pairing API call
This commit is contained in:
@@ -4,6 +4,7 @@ import com.republicate.kson.Json
|
||||
import com.republicate.kson.toJsonArray
|
||||
import org.jeudego.pairgoth.api.ApiHandler.Companion.badRequest
|
||||
import org.jeudego.pairgoth.model.Pairing
|
||||
import org.jeudego.pairgoth.model.getID
|
||||
import org.jeudego.pairgoth.model.toID
|
||||
import org.jeudego.pairgoth.model.toJson
|
||||
import org.jeudego.pairgoth.web.Event
|
||||
@@ -49,6 +50,20 @@ object PairingHandler: PairgothApiHandler {
|
||||
return ret
|
||||
}
|
||||
|
||||
override fun put(request: HttpServletRequest): 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...)
|
||||
if (round != tournament.lastRound()) badRequest("cannot edit pairings in other rounds but the last")
|
||||
val payload = getObjectPayload(request)
|
||||
val game = tournament.games(round)[payload.getInt("id")] ?: badRequest("invalid game id")
|
||||
game.black = payload.getID("b") ?: badRequest("missing black player id")
|
||||
game.white = payload.getID("w") ?: badRequest("missing white player id")
|
||||
if (payload.containsKey("h")) game.handicap = payload.getString("h")?.toIntOrNull() ?: badRequest("invalid handicap")
|
||||
Event.dispatch(gameUpdated, Json.Object("tournament" to tournament.id, "round" to round, "data" to game.toJson()))
|
||||
return Json.Object("success" to true)
|
||||
}
|
||||
|
||||
override fun delete(request: HttpServletRequest): Json {
|
||||
val tournament = getTournament(request)
|
||||
val round = getSubSelector(request)?.toIntOrNull() ?: badRequest("invalid round number")
|
||||
|
@@ -1,6 +1,10 @@
|
||||
package org.jeudego.pairgoth.model
|
||||
|
||||
import com.republicate.kson.Json
|
||||
|
||||
typealias ID = Int
|
||||
|
||||
fun String.toID() = toInt()
|
||||
fun Number.toID() = toInt()
|
||||
fun Number.toID() = toInt()
|
||||
fun Json.Object.getID(key: String) = getInt(key)
|
||||
fun Json.Array.getID(index: Int) = getInt(index)
|
@@ -6,9 +6,9 @@ import java.util.*
|
||||
|
||||
data class Game(
|
||||
val id: ID,
|
||||
val white: ID,
|
||||
val black: ID,
|
||||
val handicap: Int = 0,
|
||||
var white: ID,
|
||||
var black: ID,
|
||||
var handicap: Int = 0,
|
||||
var result: Result = UNKNOWN
|
||||
) {
|
||||
enum class Result(val symbol: Char) {
|
||||
|
@@ -15,6 +15,7 @@ enum class Event {
|
||||
teamDeleted,
|
||||
gamesAdded,
|
||||
gamesDeleted,
|
||||
gameUpdated,
|
||||
resultUpdated,
|
||||
;
|
||||
|
||||
|
Reference in New Issue
Block a user