update update published repo
This commit is contained in:
parent
b85d4cac47
commit
2b0fccefdc
@ -4,6 +4,8 @@ import com.soywiz.klock.DateTime
|
|||||||
import dev.inmo.micro_utils.pagination.*
|
import dev.inmo.micro_utils.pagination.*
|
||||||
import dev.inmo.micro_utils.repos.*
|
import dev.inmo.micro_utils.repos.*
|
||||||
import dev.inmo.postssystem.core.UnixMillis
|
import dev.inmo.postssystem.core.UnixMillis
|
||||||
|
import dev.inmo.postssystem.core.content.Content
|
||||||
|
import dev.inmo.postssystem.core.content.RegisteredContent
|
||||||
import dev.inmo.postssystem.core.post.PostId
|
import dev.inmo.postssystem.core.post.PostId
|
||||||
import dev.inmo.postssystem.core.post.RegisteredPost
|
import dev.inmo.postssystem.core.post.RegisteredPost
|
||||||
import dev.inmo.postssystem.core.post.repo.PostsRepo
|
import dev.inmo.postssystem.core.post.repo.PostsRepo
|
||||||
@ -16,6 +18,7 @@ typealias PublishedPostId = String
|
|||||||
data class PublishedPost(
|
data class PublishedPost(
|
||||||
val id: PublishedPostId,
|
val id: PublishedPostId,
|
||||||
val post: RegisteredPost,
|
val post: RegisteredPost,
|
||||||
|
val content: List<RegisteredContent>,
|
||||||
private val publicationTime: UnixMillis
|
private val publicationTime: UnixMillis
|
||||||
) {
|
) {
|
||||||
@Transient
|
@Transient
|
||||||
|
@ -6,6 +6,7 @@ import dev.inmo.micro_utils.pagination.*
|
|||||||
import dev.inmo.micro_utils.pagination.utils.reverse
|
import dev.inmo.micro_utils.pagination.utils.reverse
|
||||||
import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo
|
import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo
|
||||||
import dev.inmo.micro_utils.repos.exposed.initTable
|
import dev.inmo.micro_utils.repos.exposed.initTable
|
||||||
|
import dev.inmo.postssystem.core.content.api.ReadContentRepo
|
||||||
import dev.inmo.postssystem.core.generateId
|
import dev.inmo.postssystem.core.generateId
|
||||||
import dev.inmo.postssystem.core.post.PostId
|
import dev.inmo.postssystem.core.post.PostId
|
||||||
import dev.inmo.postssystem.core.post.RegisteredPost
|
import dev.inmo.postssystem.core.post.RegisteredPost
|
||||||
@ -21,6 +22,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
class ExposedPublishedPostsRepo(
|
class ExposedPublishedPostsRepo(
|
||||||
override val database: Database,
|
override val database: Database,
|
||||||
private val postsRepo: ReadPostsRepo,
|
private val postsRepo: ReadPostsRepo,
|
||||||
|
private val contentRepo: ReadContentRepo,
|
||||||
tableName: String = "PublishedPostsRepo",
|
tableName: String = "PublishedPostsRepo",
|
||||||
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
) : PublishedPostsRepo,
|
) : PublishedPostsRepo,
|
||||||
@ -39,16 +41,25 @@ class ExposedPublishedPostsRepo(
|
|||||||
override fun InsertStatement<Number>.asObject(value: RegisteredPost): PublishedPost = PublishedPost(
|
override fun InsertStatement<Number>.asObject(value: RegisteredPost): PublishedPost = PublishedPost(
|
||||||
get(idColumn),
|
get(idColumn),
|
||||||
value,
|
value,
|
||||||
|
launchSynchronously(scope) { value.content.mapNotNull { contentRepo.getById(it) } },
|
||||||
get(dateTimeColumn)
|
get(dateTimeColumn)
|
||||||
)
|
)
|
||||||
|
|
||||||
override val selectById: SqlExpressionBuilder.(PublishedPostId) -> Op<Boolean> = { idColumn.eq(it) }
|
override val selectById: SqlExpressionBuilder.(PublishedPostId) -> Op<Boolean> = { idColumn.eq(it) }
|
||||||
override val ResultRow.asObject: PublishedPost
|
override val ResultRow.asObject: PublishedPost
|
||||||
get() = PublishedPost(
|
get() {
|
||||||
|
val (post, content) = launchSynchronously(scope) {
|
||||||
|
val post = requireNotNull(postsRepo.getPostById(get(postIdColumn))) {"Post with id \"${get(postIdColumn)}\" not found" }
|
||||||
|
post to post.content.mapNotNull { contentRepo.getById(it) }
|
||||||
|
}
|
||||||
|
return PublishedPost(
|
||||||
get(idColumn),
|
get(idColumn),
|
||||||
requireNotNull(launchSynchronously(scope) { postsRepo.getPostById(get(postIdColumn)) }) { "Post with id \"${get(postIdColumn)}\" not found" },
|
post,
|
||||||
|
content,
|
||||||
get(dateTimeColumn)
|
get(dateTimeColumn)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
initTable()
|
initTable()
|
||||||
|
Loading…
Reference in New Issue
Block a user