fixes
This commit is contained in:
parent
3a8d29e739
commit
b9f7d9e346
@ -1,27 +0,0 @@
|
||||
package dev.inmo.postssystem.core.ktor.client.content
|
||||
|
||||
import dev.inmo.postssystem.core.content.api.*
|
||||
import dev.inmo.postssystem.core.ktor.contentRootRoute
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.features.websocket.WebSockets
|
||||
|
||||
//class ContentRepoKtorClient private constructor(
|
||||
// readContentRepo: ReadContentRepo,
|
||||
// writeContentRepo: WriteContentRepo
|
||||
//) : ContentRepo, ReadContentRepo by readContentRepo, WriteContentRepo by writeContentRepo {
|
||||
// constructor(
|
||||
// baseUrl: String,
|
||||
// client: HttpClient = HttpClient {
|
||||
// install(WebSockets)
|
||||
// }
|
||||
// ) : this(
|
||||
// ReadContentRepoKtorClient(
|
||||
// "$baseUrl/$contentRootRoute",
|
||||
// client
|
||||
// ),
|
||||
// WriteContentRepoKtorClient(
|
||||
// "$baseUrl/$contentRootRoute",
|
||||
// client
|
||||
// )
|
||||
// )
|
||||
//}
|
@ -1,34 +0,0 @@
|
||||
package dev.inmo.postssystem.core.ktor.client.content
|
||||
|
||||
import dev.inmo.postssystem.core.content.ContentId
|
||||
import dev.inmo.postssystem.core.content.RegisteredContent
|
||||
import dev.inmo.postssystem.core.content.api.ReadContentRepo
|
||||
import dev.inmo.postssystem.core.ktor.*
|
||||
import dev.inmo.micro_utils.ktor.client.uniget
|
||||
import dev.inmo.micro_utils.ktor.common.includeQueryParams
|
||||
import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.get
|
||||
import kotlinx.serialization.builtins.nullable
|
||||
|
||||
//class ReadContentRepoKtorClient(
|
||||
// private val baseUrl: String,
|
||||
// private val client: HttpClient = HttpClient()
|
||||
//) : ReadContentRepo {
|
||||
// override suspend fun getContentsIds(): Set<ContentId> = client.get<ByteArray>(
|
||||
// "$baseUrl/$getContentsIdsRoute"
|
||||
// ).let {
|
||||
// standardKtorSerialFormat.decodeFromByteArray(contentIdsSerializer, it)
|
||||
// }
|
||||
//
|
||||
// override suspend fun getContentById(id: ContentId): RegisteredContent? = client.uniget(
|
||||
// "$baseUrl/$getContentByIdRoute/$id",
|
||||
// RegisteredContent.serializer().nullable
|
||||
// )
|
||||
//
|
||||
// override suspend fun getContentByPagination(pagination: Pagination): PaginationResult<RegisteredContent> = client.uniget(
|
||||
// "$baseUrl/$getContentByPaginationRoute".includeQueryParams(pagination.asUrlQueryParts),
|
||||
// registeredContentPaginationResultSerializer
|
||||
// )
|
||||
//}
|
@ -1,37 +0,0 @@
|
||||
package dev.inmo.postssystem.core.ktor.client.content
|
||||
|
||||
import dev.inmo.postssystem.core.content.*
|
||||
import dev.inmo.postssystem.core.content.api.WriteContentRepo
|
||||
import dev.inmo.postssystem.core.ktor.*
|
||||
import dev.inmo.micro_utils.ktor.client.*
|
||||
import io.ktor.client.HttpClient
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.serialization.builtins.nullable
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
//class WriteContentRepoKtorClient(
|
||||
// private val baseUrl: String,
|
||||
// private val client: HttpClient = HttpClient()
|
||||
//) : WriteContentRepo {
|
||||
// override val contentCreatedFlow: Flow<RegisteredContent> = client.createStandardWebsocketFlow(
|
||||
// "$baseUrl/$contentCreatedFlowRoute",
|
||||
// deserializer = RegisteredContent.serializer()
|
||||
// )
|
||||
//
|
||||
// override val contentDeletedFlow: Flow<RegisteredContent> = client.createStandardWebsocketFlow(
|
||||
// "$baseUrl/$contentDeletedFlowRoute",
|
||||
// deserializer = RegisteredContent.serializer()
|
||||
// )
|
||||
//
|
||||
// override suspend fun registerContent(content: Content): RegisteredContent? = client.unipost(
|
||||
// "$baseUrl/$registerContentRoute",
|
||||
// BodyPair(Content.serializer(), content),
|
||||
// RegisteredContent.serializer().nullable
|
||||
// )
|
||||
//
|
||||
// override suspend fun deleteContent(id: ContentId): Boolean = client.unipost(
|
||||
// "$baseUrl/$deleteContentRoute",
|
||||
// BodyPair(ContentId.serializer(), id),
|
||||
// Boolean.serializer()
|
||||
// )
|
||||
//}
|
@ -11,16 +11,17 @@ class PostsRepoKtorClient private constructor(
|
||||
) : PostsRepo, ReadPostsRepo by readPostsRepo, WritePostsRepo by writePostsRepo {
|
||||
constructor(
|
||||
baseUrl: String,
|
||||
rootRoute: String = postsRootRoute,
|
||||
client: HttpClient = HttpClient {
|
||||
install(WebSockets)
|
||||
}
|
||||
) : this(
|
||||
ReadPostsRepoKtorClient(
|
||||
"${baseUrl}/$postsRootRoute",
|
||||
"${baseUrl}/$rootRoute",
|
||||
client
|
||||
),
|
||||
WritePostsRepoKtorClient(
|
||||
"${baseUrl}/$postsRootRoute",
|
||||
"${baseUrl}/$rootRoute",
|
||||
client
|
||||
)
|
||||
)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.postssystem.core.ktor
|
||||
|
||||
const val postsRootRoute = "post"
|
||||
const val publishedPostsSubRoute = "published"
|
||||
|
||||
const val getPostsIdsRoute = "getPostsIds"
|
||||
const val getPostByIdRoute = "getPostById"
|
||||
|
@ -6,19 +6,25 @@ import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigur
|
||||
import io.ktor.routing.Route
|
||||
import io.ktor.routing.route
|
||||
|
||||
fun Route.configurePostsRepoRoutes(
|
||||
proxyTo: PostsRepo
|
||||
) {
|
||||
route(postsRootRoute) {
|
||||
private inline fun configurator(proxyTo: PostsRepo): Route.() -> Unit = {
|
||||
configureReadPostsRepoRoutes(proxyTo)
|
||||
configureWritePostsRepoRoutes(proxyTo)
|
||||
}
|
||||
|
||||
fun Route.configurePostsRepoRoutes(
|
||||
proxyTo: PostsRepo,
|
||||
rootRoute: String? = postsRootRoute
|
||||
) {
|
||||
rootRoute ?.also {
|
||||
route(it, configurator(proxyTo))
|
||||
} ?: configurator(proxyTo).invoke(this)
|
||||
}
|
||||
|
||||
class PostsRepoRoutingConfigurator(
|
||||
private val proxyTo: PostsRepo
|
||||
private val proxyTo: PostsRepo,
|
||||
private val rootRoute: String? = postsRootRoute
|
||||
) : ApplicationRoutingConfigurator.Element {
|
||||
override fun Route.invoke() {
|
||||
configurePostsRepoRoutes(proxyTo)
|
||||
configurePostsRepoRoutes(proxyTo, rootRoute)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user