forked from SteamWar/SteamWar
Fixes...
This commit is contained in:
@@ -118,16 +118,7 @@ fun Route.configureEventFightRoutes() {
|
||||
}
|
||||
route("/{fight}") {
|
||||
put {
|
||||
val fightId = call.parameters["fight"]?.toIntOrNull()
|
||||
if (fightId == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid fight ID"))
|
||||
return@put
|
||||
}
|
||||
val fight = EventFight.get(fightId)
|
||||
if (fight == null) {
|
||||
call.respond(HttpStatusCode.NotFound, ResponseError("Fight not found"))
|
||||
return@put
|
||||
}
|
||||
val fight = call.receiveFight() ?: return@put
|
||||
val updateFight = call.receiveNullable<UpdateEventFight>()
|
||||
if (updateFight == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid body"))
|
||||
@@ -143,29 +134,35 @@ fun Route.configureEventFightRoutes() {
|
||||
|
||||
if (updateFight.group != null) {
|
||||
if (updateFight.group == "null") {
|
||||
Groups.resetGroup(fightId, true)
|
||||
Groups.resetGroup(fight.fightID, true)
|
||||
} else {
|
||||
Groups.setGroup(fightId, updateFight.group)
|
||||
Groups.setGroup(fight.fightID, updateFight.group)
|
||||
}
|
||||
}
|
||||
fight.update(start, spielmodus, map, teamBlue, teamRed, spectatePort)
|
||||
call.respond(HttpStatusCode.OK, ResponseEventFight(fight))
|
||||
}
|
||||
delete {
|
||||
val fightId = call.parameters["fight"]?.toIntOrNull()
|
||||
if (fightId == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid fight ID"))
|
||||
return@delete
|
||||
}
|
||||
val fight = EventFight.get(fightId)
|
||||
if (fight == null) {
|
||||
call.respond(HttpStatusCode.NotFound, ResponseError("Fight not found"))
|
||||
return@delete
|
||||
}
|
||||
val fight = call.receiveFight() ?: return@delete
|
||||
fight.delete()
|
||||
call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun ApplicationCall.receiveFight(fieldName: String = "fight"): EventFight? {
|
||||
val fightId = parameters[fieldName]?.toIntOrNull()
|
||||
if (fightId == null) {
|
||||
respond(HttpStatusCode.BadRequest, ResponseError("Invalid fight ID"))
|
||||
return null
|
||||
}
|
||||
|
||||
val fight = EventFight.get(fightId)
|
||||
if (fight == null) {
|
||||
respond(HttpStatusCode.NotFound, ResponseError("Fight not found"))
|
||||
return null
|
||||
}
|
||||
return fight
|
||||
}
|
||||
Reference in New Issue
Block a user