Skip to content

Commit 51affcd

Browse files
authored
[#3985] Refactor Routes with non returning methods (#3989)
* [#3985] Refactor Routes with non returning methods * [#3985] Refactor Routes with non returning methods
1 parent 3db5857 commit 51affcd

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

backend/app/src/main/kotlin/com/oztechan/ccc/backend/app/routes/CurrencyRoute.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ private const val PARAMETER_BASE = "base"
1717

1818
internal fun Route.getCurrencyByName(
1919
apiController: APIController
20-
) = get(PATH_BY_BASE) {
21-
Logger.v { "GET Request $PATH_BY_BASE" }
20+
) {
21+
get(PATH_BY_BASE) {
22+
Logger.v { "GET Request $PATH_BY_BASE" }
2223

23-
call.parameters[PARAMETER_BASE]?.let { base ->
24-
Logger.v { "Parameter: $PARAMETER_BASE $base" }
24+
call.parameters[PARAMETER_BASE]?.let { base ->
25+
Logger.v { "Parameter: $PARAMETER_BASE $base" }
2526

26-
apiController.getExchangeRateByBase(base)
27-
?.let { call.respond(HttpStatusCode.OK, it) }
28-
?: call.respond(HttpStatusCode.NotFound)
29-
} ?: call.respond(HttpStatusCode.BadRequest)
27+
apiController.getExchangeRateByBase(base)
28+
?.let { call.respond(HttpStatusCode.OK, it) }
29+
?: call.respond(HttpStatusCode.NotFound)
30+
} ?: call.respond(HttpStatusCode.BadRequest)
31+
}
3032
}

backend/app/src/main/kotlin/com/oztechan/ccc/backend/app/routes/ErrorRoute.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import io.ktor.server.routing.get
1616
private const val PATH_ERROR = "/error"
1717
private const val ERROR_HTML = "error.html"
1818

19-
internal fun Route.getError() = get(PATH_ERROR) {
20-
Logger.v { "GET Request $PATH_ERROR" }
19+
internal fun Route.getError() {
20+
get(PATH_ERROR) {
21+
Logger.v { "GET Request $PATH_ERROR" }
2122

22-
javaClass.classLoader?.getResource(ERROR_HTML)?.readText()?.let { resource ->
23-
call.respondText(
24-
text = resource,
25-
contentType = ContentType.Text.Html,
26-
status = HttpStatusCode.OK
27-
)
28-
} ?: call.respond(HttpStatusCode.NotFound)
23+
javaClass.classLoader?.getResource(ERROR_HTML)?.readText()?.let { resource ->
24+
call.respondText(
25+
text = resource,
26+
contentType = ContentType.Text.Html,
27+
status = HttpStatusCode.OK
28+
)
29+
} ?: call.respond(HttpStatusCode.NotFound)
30+
}
2931
}

backend/app/src/main/kotlin/com/oztechan/ccc/backend/app/routes/RootRoute.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import io.ktor.server.routing.get
1616
private const val PATH_ROOT = "/"
1717
private const val INDEX_HTML = "index.html"
1818

19-
internal fun Route.getRoot() = get(PATH_ROOT) {
20-
Logger.v { "GET Request $PATH_ROOT" }
19+
internal fun Route.getRoot() {
20+
get(PATH_ROOT) {
21+
Logger.v { "GET Request $PATH_ROOT" }
2122

22-
javaClass.classLoader?.getResource(INDEX_HTML)?.readText()?.let { resource ->
23-
call.respondText(
24-
text = resource,
25-
contentType = ContentType.Text.Html,
26-
status = HttpStatusCode.OK
27-
)
28-
} ?: call.respond(HttpStatusCode.NotFound)
23+
javaClass.classLoader?.getResource(INDEX_HTML)?.readText()?.let { resource ->
24+
call.respondText(
25+
text = resource,
26+
contentType = ContentType.Text.Html,
27+
status = HttpStatusCode.OK
28+
)
29+
} ?: call.respond(HttpStatusCode.NotFound)
30+
}
2931
}

backend/app/src/main/kotlin/com/oztechan/ccc/backend/app/routes/VersionRoute.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import io.ktor.server.routing.get
1010

1111
private const val PATH_VERSION = "/version"
1212

13-
internal fun Route.getVersion() = get(PATH_VERSION) {
14-
Logger.v { "GET Request $PATH_VERSION" }
13+
internal fun Route.getVersion() {
14+
get(PATH_VERSION) {
15+
Logger.v { "GET Request $PATH_VERSION" }
1516

16-
call.respondText(
17-
text = "Version: ${javaClass.`package`?.implementationVersion}",
18-
contentType = ContentType.Text.Plain,
19-
status = HttpStatusCode.OK
20-
)
17+
call.respondText(
18+
text = "Version: ${javaClass.`package`?.implementationVersion}",
19+
contentType = ContentType.Text.Plain,
20+
status = HttpStatusCode.OK
21+
)
22+
}
2123
}

0 commit comments

Comments
 (0)