From cf0a609fc42b2356f50f32e03f02e2ace0d46e35 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 1 Feb 2019 11:28:13 +0100 Subject: Refactor KVController --- .../src/main/kotlin/pl/treksoft/kvision/remote/KVController.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'kvision-modules/kvision-server-spring-boot/src/main/kotlin') diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVController.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVController.kt index 128933f2..50544dc1 100644 --- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVController.kt +++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVController.kt @@ -39,17 +39,16 @@ open class KVController { method = [RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.OPTIONS] ) open fun kVMapping(req: HttpServletRequest, res: HttpServletResponse) { - val method = req.method val routeUrl = req.requestURI - val route = kvServer.services.map { - when (method) { + val route = kvServer.services.mapNotNull { + when (req.method) { "POST" -> it.postRequests[routeUrl] "PUT" -> it.putRequests[routeUrl] "DELETE" -> it.deleteRequests[routeUrl] "OPTIONS" -> it.optionsRequests[routeUrl] else -> null } - }.find { it != null } + }.firstOrNull() if (route != null) { route.invoke(req, res) } else { -- cgit