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.benasher44.uuid.uuid4
|
||||||
import com.soywiz.klock.DateTime
|
import com.soywiz.klock.DateTime
|
||||||
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
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.AbstractExposedCRUDRepo
|
||||||
import dev.inmo.micro_utils.repos.exposed.initTable
|
import dev.inmo.micro_utils.repos.exposed.initTable
|
||||||
import dev.inmo.plaguposter.posts.models.*
|
import dev.inmo.plaguposter.posts.models.*
|
||||||
@ -75,17 +76,20 @@ class ExposedPostsRepo(
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(id: PostId?, value: NewPost, it: UpdateBuilder<Int>) {
|
override fun update(id: PostId?, value: NewPost, it: UpdateBuilder<Int>) {}
|
||||||
id ?: error("Unable to find post id in update")
|
|
||||||
with(contentRepo) {
|
private fun updateContent(post: RegisteredPost) {
|
||||||
deleteWhere { postIdColumn.eq(id.string) }
|
transaction(database) {
|
||||||
value.content.forEach { contentInfo ->
|
with(contentRepo) {
|
||||||
insert {
|
deleteWhere { postIdColumn.eq(post.id.string) }
|
||||||
it[postIdColumn] = id.string
|
post.content.forEach { contentInfo ->
|
||||||
it[chatIdColumn] = contentInfo.chatId.chatId
|
insert {
|
||||||
it[messageIdColumn] = contentInfo.messageId
|
it[postIdColumn] = post.id.string
|
||||||
it[groupColumn] = contentInfo.group
|
it[chatIdColumn] = contentInfo.chatId.chatId
|
||||||
it[orderColumn] = contentInfo.order
|
it[messageIdColumn] = contentInfo.messageId
|
||||||
|
it[groupColumn] = contentInfo.group
|
||||||
|
it[orderColumn] = contentInfo.order
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,6 +100,20 @@ class ExposedPostsRepo(
|
|||||||
it[createdColumn] = DateTime.now().unixMillis
|
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>) {
|
override suspend fun deleteById(ids: List<PostId>) {
|
||||||
onBeforeDelete(ids)
|
onBeforeDelete(ids)
|
||||||
val posts = ids.mapNotNull {
|
val posts = ids.mapNotNull {
|
||||||
|
Loading…
Reference in New Issue
Block a user