forked from SteamWar/SteamWar
Format code
This commit is contained in:
@@ -43,33 +43,48 @@ data class UpdateEventGroup(
|
||||
fun Route.configureEventGroups() {
|
||||
route("/groups") {
|
||||
get {
|
||||
val event = call.receiveEvent() ?: return@get
|
||||
val event = call.receiveEvent()
|
||||
?: return@get
|
||||
call.respond(EventGroup.get(event).map { ResponseGroups(it) })
|
||||
}
|
||||
post {
|
||||
val event = call.receiveEvent() ?: return@post
|
||||
val event = call.receiveEvent()
|
||||
?: return@post
|
||||
val createEventGroup = call.receive<CreateEventGroup>()
|
||||
val group = EventGroup.create(event, createEventGroup.name, createEventGroup.type)
|
||||
call.respond(ResponseGroups(group))
|
||||
}
|
||||
route("/{group}") {
|
||||
get {
|
||||
val group = call.receiveEventGroup() ?: return@get
|
||||
val group = call.receiveEventGroup()
|
||||
?: return@get
|
||||
call.respond(ResponseGroups(group))
|
||||
}
|
||||
put {
|
||||
val group = call.receiveEventGroup() ?: return@put
|
||||
val group = call.receiveEventGroup()
|
||||
?: return@put
|
||||
val updateEventGroup = call.receive<UpdateEventGroup>()
|
||||
val name = updateEventGroup.name ?: group.name
|
||||
val type = updateEventGroup.type ?: group.type
|
||||
val pointsPerWin = updateEventGroup.pointsPerWin ?: group.pointsPerWin
|
||||
val pointsPerLoss = updateEventGroup.pointsPerLoss ?: group.pointsPerLoss
|
||||
val pointsPerDraw = updateEventGroup.pointsPerDraw ?: group.pointsPerDraw
|
||||
val name = updateEventGroup.name
|
||||
?: group.name
|
||||
val type = updateEventGroup.type
|
||||
?: group.type
|
||||
val pointsPerWin = updateEventGroup.pointsPerWin
|
||||
?: group.pointsPerWin
|
||||
val pointsPerLoss = updateEventGroup.pointsPerLoss
|
||||
?: group.pointsPerLoss
|
||||
val pointsPerDraw = updateEventGroup.pointsPerDraw
|
||||
?: group.pointsPerDraw
|
||||
group.update(name, type, pointsPerWin, pointsPerLoss, pointsPerDraw)
|
||||
call.respond(ResponseGroups(EventGroup.byId(group.getId()).orElse(null) ?: return@put))
|
||||
call.respond(
|
||||
ResponseGroups(
|
||||
EventGroup.byId(group.getId()).orElse(null)
|
||||
?: return@put
|
||||
)
|
||||
)
|
||||
}
|
||||
delete {
|
||||
val group = call.receiveEventGroup() ?: return@delete
|
||||
val group = call.receiveEventGroup()
|
||||
?: return@delete
|
||||
group.delete()
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user