mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-12-22 14:07:14 +00:00
fixes in exposed posts repo
This commit is contained in:
parent
65f613fd97
commit
6673b6c69b
@ -3,6 +3,7 @@ package dev.inmo.plaguposter.posts.exposed
|
||||
import com.benasher44.uuid.uuid4
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.UpdatedValuePair
|
||||
import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.initTable
|
||||
import dev.inmo.plaguposter.posts.models.*
|
||||
@ -75,13 +76,15 @@ class ExposedPostsRepo(
|
||||
return id
|
||||
}
|
||||
|
||||
override fun update(id: PostId?, value: NewPost, it: UpdateBuilder<Int>) {
|
||||
id ?: error("Unable to find post id in update")
|
||||
override fun update(id: PostId?, value: NewPost, it: UpdateBuilder<Int>) {}
|
||||
|
||||
private fun updateContent(post: RegisteredPost) {
|
||||
transaction(database) {
|
||||
with(contentRepo) {
|
||||
deleteWhere { postIdColumn.eq(id.string) }
|
||||
value.content.forEach { contentInfo ->
|
||||
deleteWhere { postIdColumn.eq(post.id.string) }
|
||||
post.content.forEach { contentInfo ->
|
||||
insert {
|
||||
it[postIdColumn] = id.string
|
||||
it[postIdColumn] = post.id.string
|
||||
it[chatIdColumn] = contentInfo.chatId.chatId
|
||||
it[messageIdColumn] = contentInfo.messageId
|
||||
it[groupColumn] = contentInfo.group
|
||||
@ -90,12 +93,27 @@ class ExposedPostsRepo(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun insert(value: NewPost, it: InsertStatement<Number>) {
|
||||
super.insert(value, it)
|
||||
it[createdColumn] = DateTime.now().unixMillis
|
||||
}
|
||||
|
||||
override suspend fun onAfterCreate(values: List<Pair<NewPost, RegisteredPost>>): List<RegisteredPost> {
|
||||
values.forEach {
|
||||
updateContent(it.second)
|
||||
}
|
||||
return super.onAfterCreate(values)
|
||||
}
|
||||
|
||||
override suspend fun onAfterUpdate(value: List<UpdatedValuePair<NewPost, RegisteredPost>>): List<RegisteredPost> {
|
||||
value.forEach {
|
||||
updateContent(it.second)
|
||||
}
|
||||
return super.onAfterUpdate(value)
|
||||
}
|
||||
|
||||
override suspend fun deleteById(ids: List<PostId>) {
|
||||
onBeforeDelete(ids)
|
||||
val posts = ids.mapNotNull {
|
||||
|
Loading…
Reference in New Issue
Block a user