Skip to content

Commit de2c131

Browse files
committed
Remove context receivers from respond
1 parent 28f5acb commit de2c131

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/main/kotlin/no/java/conf/plugins/Respond.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import io.ktor.server.response.respondRedirect
77
import io.ktor.server.routing.RoutingContext
88
import no.java.conf.model.ApiError
99

10-
context(RoutingContext)
11-
suspend inline fun <reified A : Any> Either<ApiError, A>.respond(status: HttpStatusCode = HttpStatusCode.OK) =
10+
suspend inline fun <reified A : Any> Either<ApiError, A>.respond(
11+
context: RoutingContext,
12+
status: HttpStatusCode = HttpStatusCode.OK
13+
) =
1214
when (this) {
13-
is Either.Left -> respond(value)
14-
is Either.Right -> call.respond(status, value)
15+
is Either.Left -> context.respond(value)
16+
is Either.Right -> context.call.respond(status, value)
1517
}
1618

1719
suspend fun RoutingContext.respond(error: ApiError) = call.respond(error.statusCode, error.messageMap())
1820

19-
context(RoutingContext)
20-
suspend inline fun <reified A : Any> Either<ApiError, A>.respondRedirect(url: String) =
21+
suspend inline fun <reified A : Any> Either<ApiError, A>.respondRedirect(context: RoutingContext, url: String) =
2122
when (this) {
22-
is Either.Left -> respond(value)
23-
is Either.Right -> call.respondRedirect(url)
23+
is Either.Left -> context.respond(value)
24+
is Either.Right -> context.call.respondRedirect(url)
2425
}

src/main/kotlin/no/java/conf/plugins/Search.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ fun Application.configureSearchRouting(service: SearchService) {
8686
get("/videos") {
8787
either {
8888
service.allVideos()
89-
}.respond()
89+
}.respond(this)
9090
}
9191

9292
post {
9393
either {
9494
service.textSearch(
9595
runCatching<TextSearchRequest?> { call.receiveNullable<TextSearchRequest>() }.getOrNull()
9696
)
97-
}.respond()
97+
}.respond(this)
9898
}
9999
}
100100
}

0 commit comments

Comments
 (0)