forked from SteamWar/SteamWar
Fixes...
This commit is contained in:
@@ -154,16 +154,7 @@ fun Route.configureEventsRoute() {
|
||||
call.respond(EventFight.getEvent(event.eventID).map { ResponseEventFight(it) })
|
||||
}
|
||||
get("/csv") {
|
||||
val id = call.parameters["id"]?.toIntOrNull()
|
||||
if (id == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid ID"))
|
||||
return@get
|
||||
}
|
||||
val event = Event.get(id)
|
||||
if (event == null) {
|
||||
call.respond(HttpStatusCode.NotFound, ResponseError("Event not found"))
|
||||
return@get
|
||||
}
|
||||
val event = call.receiveEvent() ?: return@get
|
||||
|
||||
val fights = EventFight.getEvent(event.eventID)
|
||||
val csv = StringBuilder();
|
||||
@@ -195,16 +186,8 @@ fun Route.configureEventsRoute() {
|
||||
call.respondText(csv.toString())
|
||||
}
|
||||
put {
|
||||
val id = call.parameters["id"]?.toIntOrNull()
|
||||
if (id == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid ID"))
|
||||
return@put
|
||||
}
|
||||
val event = Event.get(id)
|
||||
if (event == null) {
|
||||
call.respond(HttpStatusCode.NotFound, ResponseError("Event not found"))
|
||||
return@put
|
||||
}
|
||||
val event = call.receiveEvent() ?: return@put
|
||||
|
||||
val updateEvent = call.receiveNullable<UpdateEvent>()
|
||||
if (updateEvent == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid body"))
|
||||
@@ -249,4 +232,20 @@ fun Route.configureEventsRoute() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun ApplicationCall.receiveEvent(fieldName: String = "event"): Event? {
|
||||
val eventId = parameters[fieldName]?.toIntOrNull()
|
||||
if (eventId == null) {
|
||||
respond(HttpStatusCode.BadRequest, ResponseError("Invalid event ID"))
|
||||
return null
|
||||
}
|
||||
|
||||
val event = Event.get(eventId)
|
||||
if (event == null) {
|
||||
respond(HttpStatusCode.NotFound, ResponseError("Event not found"))
|
||||
return null
|
||||
}
|
||||
|
||||
return event
|
||||
}
|
||||
Reference in New Issue
Block a user