doForAllWithCurrentPaging and fun interface for elements in ktor server

This commit is contained in:
InsanusMokrassar 2021-06-14 22:04:39 +06:00
parent 6ff3f6ae42
commit a16815143c
6 changed files with 24 additions and 12 deletions

View File

@ -2,6 +2,12 @@
## 0.5.10 ## 0.5.10
* `Ktor`
* `Server`
* All elements in configurators became a `fun interface`
* `Pagination`
* New function `doForAllWithCurrentPaging`
## 0.5.9 ## 0.5.9
* `Repos` * `Repos`

View File

@ -8,7 +8,7 @@ import kotlinx.serialization.Contextual
data class ApplicationCachingHeadersConfigurator( data class ApplicationCachingHeadersConfigurator(
private val elements: List<@Contextual Element> private val elements: List<@Contextual Element>
) : KtorApplicationConfigurator { ) : KtorApplicationConfigurator {
interface Element { operator fun CachingHeaders.Configuration.invoke() } fun interface Element { operator fun CachingHeaders.Configuration.invoke() }
override fun Application.configure() { override fun Application.configure() {
install(CachingHeaders) { install(CachingHeaders) {

View File

@ -10,17 +10,18 @@ import kotlinx.serialization.Serializable
class ApplicationRoutingConfigurator( class ApplicationRoutingConfigurator(
private val elements: List<@Contextual Element> private val elements: List<@Contextual Element>
) : KtorApplicationConfigurator { ) : KtorApplicationConfigurator {
interface Element { operator fun Route.invoke() } fun interface Element { operator fun Route.invoke() }
private val rootInstaller = Element {
elements.forEach {
it.apply { invoke() }
}
}
override fun Application.configure() { override fun Application.configure() {
try { featureOrNull(Routing) ?.apply {
feature(Routing) rootInstaller.apply { invoke() }
} catch (e: IllegalStateException) { } ?: install(Routing) {
install(Routing) { rootInstaller.apply { invoke() }
elements.forEach {
it.apply { invoke() }
}
}
} }
} }
} }

View File

@ -8,7 +8,7 @@ import kotlinx.serialization.Contextual
class ApplicationSessionsConfigurator( class ApplicationSessionsConfigurator(
private val elements: List<@Contextual Element> private val elements: List<@Contextual Element>
) : KtorApplicationConfigurator { ) : KtorApplicationConfigurator {
interface Element { operator fun Sessions.Configuration.invoke() } fun interface Element { operator fun Sessions.Configuration.invoke() }
override fun Application.configure() { override fun Application.configure() {
install(Sessions) { install(Sessions) {

View File

@ -8,7 +8,7 @@ import kotlinx.serialization.Contextual
class StatusPagesConfigurator( class StatusPagesConfigurator(
private val elements: List<@Contextual Element> private val elements: List<@Contextual Element>
) : KtorApplicationConfigurator { ) : KtorApplicationConfigurator {
interface Element { operator fun StatusPages.Configuration.invoke() } fun interface Element { operator fun StatusPages.Configuration.invoke() }
override fun Application.configure() { override fun Application.configure() {
install(StatusPages) { install(StatusPages) {

View File

@ -33,3 +33,8 @@ suspend fun <T> doAllWithCurrentPaging(
block block
) )
} }
suspend fun <T> doForAllWithCurrentPaging(
initialPagination: Pagination = FirstPagePagination(),
block: suspend (Pagination) -> PaginationResult<T>
) = doAllWithCurrentPaging(initialPagination, block)