forked from SteamWar/SteamWar
Format code
This commit is contained in:
@@ -41,18 +41,23 @@ data class UpdateFromRelation(val fromType: EventRelation.FromType, val fromId:
|
||||
fun Route.configureEventRelations() {
|
||||
route("/relations") {
|
||||
get {
|
||||
val event = call.receiveEvent() ?: return@get
|
||||
val event = call.receiveEvent()
|
||||
?: return@get
|
||||
|
||||
call.respond(EventRelation.get(event).map { ResponseRelation(it) })
|
||||
}
|
||||
post {
|
||||
val create = call.receive<CreateEventRelation>()
|
||||
|
||||
val fight = EventFight.byId(create.fightId) ?: return@post call.respond(HttpStatusCode.NotFound)
|
||||
val fight = EventFight.byId(create.fightId)
|
||||
?: return@post call.respond(HttpStatusCode.NotFound)
|
||||
|
||||
when (create.fromType) {
|
||||
EventRelation.FromType.FIGHT -> EventFight.byId(create.fromId) ?: return@post call.respond(HttpStatusCode.BadRequest)
|
||||
EventRelation.FromType.GROUP -> EventGroup.byId(create.fromId) ?: return@post call.respond(HttpStatusCode.BadRequest)
|
||||
EventRelation.FromType.FIGHT -> EventFight.byId(create.fromId)
|
||||
?: return@post call.respond(HttpStatusCode.BadRequest)
|
||||
|
||||
EventRelation.FromType.GROUP -> EventGroup.byId(create.fromId)
|
||||
?: return@post call.respond(HttpStatusCode.BadRequest)
|
||||
}
|
||||
|
||||
val relation = EventRelation.create(fight, create.team, create.fromType, create.fromId, create.fromPlace)
|
||||
@@ -61,19 +66,26 @@ fun Route.configureEventRelations() {
|
||||
}
|
||||
route("/{relation}") {
|
||||
get {
|
||||
val relation = call.receiveEventRelation() ?: return@get
|
||||
val relation = call.receiveEventRelation()
|
||||
?: return@get
|
||||
call.respond(ResponseRelation(relation))
|
||||
}
|
||||
put {
|
||||
val relation = call.receiveEventRelation() ?: return@put
|
||||
val relation = call.receiveEventRelation()
|
||||
?: return@put
|
||||
val update = call.receive<UpdateEventRelation>()
|
||||
|
||||
update.from?.let {
|
||||
when(it.fromType) {
|
||||
EventRelation.FromType.FIGHT -> relation.setFromFight(EventFight.byId(it.fromId) ?: return@put call.respond(HttpStatusCode.BadRequest),
|
||||
when (it.fromType) {
|
||||
EventRelation.FromType.FIGHT -> relation.setFromFight(
|
||||
EventFight.byId(it.fromId)
|
||||
?: return@put call.respond(HttpStatusCode.BadRequest),
|
||||
it.fromPlace
|
||||
)
|
||||
EventRelation.FromType.GROUP -> relation.setFromGroup(EventGroup.byId(it.fromId).orElse(null) ?: return@put call.respond(HttpStatusCode.BadRequest),
|
||||
|
||||
EventRelation.FromType.GROUP -> relation.setFromGroup(
|
||||
EventGroup.byId(it.fromId).orElse(null)
|
||||
?: return@put call.respond(HttpStatusCode.BadRequest),
|
||||
it.fromPlace
|
||||
)
|
||||
}
|
||||
@@ -84,7 +96,8 @@ fun Route.configureEventRelations() {
|
||||
call.respond(ResponseRelation(EventRelation.get(relation.id)))
|
||||
}
|
||||
delete {
|
||||
val relation = call.receiveEventRelation() ?: return@delete
|
||||
val relation = call.receiveEventRelation()
|
||||
?: return@delete
|
||||
relation.delete()
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user